54 lines
1.1 KiB
Ruby
54 lines
1.1 KiB
Ruby
# -*- encoding : utf-8 -*-
|
|
|
|
class Public::PSheetLinesController < ApplicationController
|
|
layout "public"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create
|
|
@p_customer_sheet = current_p_customer_sheet
|
|
|
|
@p_sheet_line = current_p_customer_sheet.p_sheet_lines.new(params.require(:p_sheet_line).permit!)
|
|
|
|
|
|
if @l_sheet_line = current_p_customer_sheet.p_sheet_lines.where(:p_product_id => @p_sheet_line.p_product_id).first
|
|
|
|
@p_sheet_line.p_sheet_line_lines.each do |p_sheet_line_line|
|
|
|
|
if p_sheet_line_line.qte.to_f > 0.0
|
|
psll = @l_sheet_line.p_sheet_line_lines.where(:p_product_stock_id => p_sheet_line_line.p_product_stock_id).first
|
|
|
|
if psll
|
|
psll.qte = p_sheet_line_line.qte.to_f + psll.qte.to_f
|
|
|
|
psll.save
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
redirect_to cart_public_p_orders_path()
|
|
|
|
|
|
|
|
|
|
else
|
|
if @p_sheet_line.save
|
|
|
|
redirect_to cart_public_p_orders_path()
|
|
else
|
|
render :inline => @p_sheet_line.errors.messages
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|