This commit is contained in:
Nicolas Bally 2019-03-27 16:28:05 +01:00
parent 2dba5e96b5
commit 03a728c372
11 changed files with 372 additions and 66 deletions

View File

@ -9,8 +9,12 @@
qte += parseFloat($(this).val()) if parseFloat($(this).val())
price_color = qte * price
$(this).find(".price_color_tot").html(accounting.formatMoney(price_color))
$(this).find(".qte_color_tot").html(qte)
qte_tot += qte
$(this).find(".qte_tot").html(qte_tot)
$(this).find(".price_tot").html(accounting.formatMoney(qte_tot*price))
$(this).find(".price_tot").attr("data-price",qte_tot*price)
$(this).find(".price_tot").data("price",qte_tot*price)

View File

@ -66,11 +66,29 @@ class Admin::PDocumentsController < ApplicationController
def create_avoir
@p_document = PDocument.find(params[:id])
if @p_document.create_avoir
@p_document.element.restock if @p_document.element and @p_document.element_type == "PCustomerSheet"
end
redirect_to :back
@avoir = @p_document.create_avoir
# @p_document.element.restock if @p_document.element and @p_document.element_type == "PCustomerSheet"
#end
#redirect_to :back
render :layout => "admin"
end
def save_avoir
@avoir = PDocument.new(params.require(:p_document).permit!)
if @avoir.save
redirect_to admin_p_customer_sheet_path(@avoir.element)
else
render action: "create_avoir"
end
end
end

View File

@ -8,8 +8,8 @@ class PDocument < ActiveRecord::Base
belongs_to :particular_bill, :class_name => "Particular"
belongs_to :particular_send, :class_name => "Particular"
accepts_nested_attributes_for :p_sheet_lines, allow_destroy: true
has_many :relative_docs, :class_name => "PDocument", :foreign_key => :doc_ref_id
@ -47,7 +47,7 @@ class PDocument < ActiveRecord::Base
archive_sheet_line if self.p_document_type.label != "Avoir"
end
before_create do
self.fdp_force_price = self.element.fdp_force_price
self.fdp_force_price = self.element.fdp_force_price if self.p_document_type.label != "Avoir"
self.acompte_percent = self.element.acompte_percent
if self.element_type == "PCustomerSheet" and self.element.particular_bill
@ -322,21 +322,9 @@ class PDocument < ActiveRecord::Base
def create_avoir
p_document = self
avoir = PDocument.create(:cache_fdp => ((self.cache_fdp * -1) if self.cache_fdp),:fdp_force_price => ((self.fdp_force_price * -1) if self.fdp_force_price),:label => "Avoir", :doc_ref_id => self.id, :doc_ref_number => self.d_number, :p_document_type => PDocumentType.find_by_label("Avoir"), :element_type => self.element_type, :element_id => self.element_id, :p_customer_id => self.p_customer_id, :particular_bill_id => self.particular_bill_id, :particular_send_id => self.particular_send_id)
avoir = PDocument.new(:cache_fdp => ((self.cache_fdp * -1) if self.cache_fdp),:fdp_force_price => ((self.fdp_force_price * -1) if self.fdp_force_price),:label => "Avoir", :doc_ref_id => self.id, :doc_ref_number => self.d_number, :p_document_type => PDocumentType.find_by_label("Avoir"), :element_type => self.element_type, :element_id => self.element_id, :p_customer_id => self.p_customer_id, :particular_bill_id => self.particular_bill_id, :particular_send_id => self.particular_send_id)
if false
self.p_sheet_lines.each do |p_sheet_line|
new_psl = p_sheet_line.dup
new_psl.qte = (new_psl.qte*-1)
avoir.p_sheet_lines << new_psl
end
end
self.p_sheet_lines.joins(:p_product).each do |p_sheet_line|
#fddsf = sfsf
@ -363,39 +351,40 @@ class PDocument < ActiveRecord::Base
#new_psll.fige ########
if false
if new_psll.p_product_stock.p_color
if p_color = p_colors_archiveds[new_psll.p_product_stock.p_color_id]
else
p_color = new_psll.p_product_stock.p_color.dup
p_color.archived = true
p_colors_archiveds[new_psll.p_product_stock.p_color_id] = p_color
end
new_psll.p_color = p_color
end
if new_psll.p_product_stock.p_size
if p_size = p_sizes_archiveds[new_psll.p_product_stock.p_size_id]
else
p_size = new_psll.p_product_stock.p_size.dup
p_size.archived = true
p_sizes_archiveds[new_psll.p_product_stock.p_size_id] = p_size
end
new_psll.p_size = p_size
end
end
if new_psll.p_product_stock.p_color
if p_color = p_colors_archiveds[new_psll.p_product_stock.p_color_id]
else
p_color = new_psll.p_product_stock.p_color.dup
p_color.archived = true
p_colors_archiveds[new_psll.p_product_stock.p_color_id] = p_color
end
new_psll.p_color = p_color
end
if new_psll.p_product_stock.p_size
if p_size = p_sizes_archiveds[new_psll.p_product_stock.p_size_id]
else
p_size = new_psll.p_product_stock.p_size.dup
p_size.archived = true
p_sizes_archiveds[new_psll.p_product_stock.p_size_id] = p_size
end
new_psll.p_size = p_size
end
new_psll.ok_code = new_psll.p_product_stock.code
@ -435,14 +424,18 @@ class PDocument < ActiveRecord::Base
r = avoir.save
#r = avoir.save
if avoir.element and avoir.element_type == "PCustomerSheet"
avoir.element.state = "remboursée"
avoir.element.save
end
return r
#if avoir.element and avoir.element_type == "PCustomerSheet"
# avoir.element.state = "remboursée"
# avoir.element.save
#end
#return r
return avoir
end

View File

@ -304,7 +304,7 @@ class PSheetLine < ActiveRecord::Base
end
elsif self.p_document
elsif self.p_document and self.p_document.particular_bill
if self.p_document.particular_bill.country != "FR"
t = true
end

View File

@ -0,0 +1,162 @@
=semantic_form_for [:admin, @avoir], :url => save_avoir_admin_p_document_path() ,:remote => false, :html => {:id => "cart_form"} do |form|
= form.hidden_field :label
= form.hidden_field :doc_ref_id
= form.hidden_field :doc_ref_number
= form.hidden_field :p_document_type_id
= form.hidden_field :element_type
= form.hidden_field :element_id
.content
%h3 Client
=form.inputs do
= form.hidden_field :p_customer_id, :class => "p_customer_id"
.addresses.row
.columns.span_6
%h3 Adresse de facturation
-if @avoir.p_customer
=form.inputs do
= form.input :particular_bill_id, :collection => @avoir.p_customer.particulars.all, :as => :select, :member_label => :address_line, :include_blank => false, :label => "Adresse de facturation"
-else
=form.inputs do
= form.input :particular_bill_id, :collection => [], :as => :select, :include_blank => false, :label => "Adresse de facturation"
.columns.span_6
%h3 Adresse de livraison
-if @avoir.p_customer
=form.inputs do
= form.input :particular_send_id, :collection => @avoir.p_customer.particulars.all, :as => :select, :member_label => :address_line, :include_blank => false, :label => "Adresse de livraison"
-else
=form.inputs do
= form.input :particular_send_id, :collection => [], :as => :select, :include_blank => false, :label => "Adresse de facturation"
.clear
= form.input :cust_ref, :label => "Référence commande client :"
.p_sheet_lines_form
=form.semantic_fields_for :p_sheet_lines do |form|
=render :partial => "admin/p_sheet_lines/avoir_form", :locals => {:form => form}
=#%p= link_to_add_fields "Ajouter une ligne", form, :p_sheet_lines
%table{:style => "width:100%;"}
%td{:style => "text-align:right;"}
Total HT articles :
%td.price_td
.price_emp.p_sheet_lines_tot_ht
= form.input :fdp_force_price, :label => "Frais de port :" , :input_html => {:id => "fdp_value"}
-if true
%p
%strong Totaux
%table{:style => "width:100%;"}
%td{:style => "text-align:right;"}
Total HT :
%td.price_td
.price_emp.p_sheet_lines_tot_ht_fdp
%table{:style => "width:100%;"}
%td{:style => "text-align:right;"}
TVA :
%td.price_td
.price_emp.p_sheet_lines_tot_tva
%table{:style => "width:100%;"}
%td{:style => "text-align:right;"}
Total TTC :
%td.price_td
.price_emp.p_sheet_lines_tot_ttc
.right.actions=form.submit "sauvegarder", :class => "btn btn-primary"
.clear
:scss
.price_emp{
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857;
color: #555555;
height:34px;
}
.price_td{
width:170px;
text-align:right;
}
:scss
.product_stock_form{
td{
vertical-align:top;
.form-control, .form-group{
margin-bottom:0}
}
}
:coffeescript
tva = 1.2
@update_sheet_line_tot = ->
tot_sheet = 0.0
$(".p_sheet_lines_form").find(".product_stock_form").each ->
tot = 0.0
tot = parseFloat($(this).find(".price_tot").data("price"))
tot_sheet += tot
$(".p_sheet_lines_tot_ht").html(accounting.formatMoney(tot_sheet))
tot_sheet_fdp = (tot_sheet + parseFloat($("#fdp_value").val()))
$(".p_sheet_lines_tot_ht_fdp").html(accounting.formatMoney(tot_sheet_fdp))
$(".p_sheet_lines_tot_tva").html(accounting.formatMoney(tot_sheet_fdp*(tva-1.0)))
$(".p_sheet_lines_tot_ttc").html(accounting.formatMoney(tot_sheet_fdp*tva))
#alert(tot_sheet)
:coffeescript
udpate_sheet_lines()
update_sheet_line_tot()
$("#cart_form").change ->
udpate_sheet_lines()
update_sheet_line_tot()
$("#cart_form").keyup ->
udpate_sheet_lines()
update_sheet_line_tot()

View File

@ -57,7 +57,7 @@
%td.actions
-if p_document.label == "Facture" and !@relances
-if p_document.relative_docs.where(:label => "Avoir").count == 0
=link_to "Créer un avoir", create_avoir_admin_p_document_path(p_document), :data => {:confirm => "Voulez-vous vraiment créer un avoir ?"}
&nbsp;&nbsp;
-#if p_document.relative_docs.where(:label => "Avoir").count == 0
=link_to "Créer un avoir", create_avoir_admin_p_document_path(p_document) #, :data => {:confirm => "Voulez-vous vraiment créer un avoir ?"}
&nbsp;&nbsp;

View File

@ -0,0 +1,11 @@
.qi_header
%h1
Documents
%span
Créer un avoir
.qi_row
.qi_pannel.qi_plain.padding
= render 'form'

View File

@ -0,0 +1,116 @@
-if true
#p_sheet_line.product_stock_form.field.p_sheet_line_field{:id => form.object.id}
%table{:style => "width:100%;"}
%tr
%td{:style => "width:70%;"}
-if form.object.lock != true
=#link_to_remove_fields ic(:"trash-o"), form
%label Produit :
%input.p_product_autocomplete_input.form-control{:type => "text", :value => ("#{form.object.p_product.code} #{form.object.p_product.name}" if form.object.p_product), :readonly => ("true")}
= form.hidden_field :p_product_id, :class => "p_product_id"
= form.hidden_field :ok_price
= form.hidden_field :price
%td{:style => "width:30%;"}
=form.input :cust_ref, :label => "Référence client :"
-p_product = form.object.p_product if form.object.p_product
%table.table.order_table
-if p_product and p_product.p_sizes.count > 0
%tr
%th
-if form.object.p_product
-p_product.p_sizes.order("p_sizes.position ASC, p_sizes.id ASC").all.each do |p_size|
%th.size_th
=p_size.name
%th.price_td Qte
%th.price_td PU
%th.price_td
Prix tot.
-if form.object.p_product
-p_product.p_colors.all.each do |p_color|
%tr.color_line
%td=p_color.name
-p_product.p_sizes.order("p_sizes.position ASC, p_sizes.id ASC").all.each do |p_size|
%td
-ps = p_product.p_product_stocks.where(:p_size_id => p_size.id, :p_color_id => p_color.id).first
-if ps
-p_sheet_line_line = nil
-form.object.p_sheet_line_lines.each do |a|
-if a.p_product_stock_id == ps.id
-p_sheet_line_line = a
-#p_sheet_line_line = form.object.p_sheet_line_lines.where(:p_product_stock_id => ps.id).first
-if p_sheet_line_line
=form.fields_for(:p_sheet_line_lines, p_sheet_line_line) do |builder|
=builder.hidden_field :p_product_stock_id,:label => false, :as => :string
=builder.hidden_field :p_size_id
=builder.hidden_field :p_color_id
=builder.hidden_field :ok_code
=builder.input :qte,:label => false, :input_html => {:class => "qte"}
%td.qte_color_tot.price_td
%td.price.price_td{:data => {:price => form.object.price}}
=number_to_currency form.object.price
%td.price_color_tot.price_td
-elsif form.object.p_product
%tr.color_line
%td
-p_product.p_product_stocks.each do |ps|
%td
-if ps
-p_sheet_line_line = form.object.p_sheet_line_lines.where(:p_product_stock_id => ps.id).first
-if p_sheet_line_line
=form.fields_for(:p_sheet_line_lines, p_sheet_line_line) do |builder|
=builder.hidden_field :p_product_stock_id,:label => false, :as => :string
=builder.input :qte,:label => false, :input_html => {:class => "qte"}
%td.qte_tot.price_td
%td.price.price_td{:data => {:price => form.object.price}}
=number_to_currency form.object.price
%td.price_color_tot.price_td
-if form.object.p_product
%table{:style => "width:100%"}
%tr
%td
&nbsp
%td
%td.qte_tot.price_td{:style => "font-weight:bold;"}
%strong=form.object.qte
%td.price.price_td{:style => "font-weight:bold;", :data => {:price => form.object.price}}
%strong=number_to_currency form.object.price
%td.price_tot.price_td{:style => "font-weight:bold;"}
=number_to_currency form.object.price_tot
%br

View File

@ -95,7 +95,7 @@
=builder.hidden_field :p_product_stock_id,:label => false, :as => :string
=builder.input :qte,:label => false, :input_html => {:class => "qte"}
%td.qte_tot.price_td
%td.qte_color_tot.price_td
%td.price.price_td{:data => {:price => form.object.price}}
=number_to_currency form.object.price

View File

@ -23,7 +23,7 @@
-sheet_lines.each do |sheet_line|
-p_sheet_line_lines = sheet_line.p_sheet_line_lines.where("qte > 0")
-p_sheet_line_lines = sheet_line.p_sheet_line_lines.where("qte != 0")
-nbr_lines = p_sheet_line_lines.count
-ok = true if sheet_line.shiped
@ -31,6 +31,7 @@
%tr
%td{:colspan => 3, :style => "text-align:right;"}
=#debug p_sheet_line_lines
%table.size_table
%tr
%th{:style => "text-align:left !important;"}

View File

@ -147,6 +147,7 @@ Rails.application.routes.draw do
resources :p_documents do
member do
get :create_avoir
post :save_avoir
get :detail
end
collection do