Wip bon de livraison

This commit is contained in:
Barnabé 2021-09-13 18:36:21 +02:00
parent 2a540f292a
commit 6751e34f29
3 changed files with 283 additions and 196 deletions

View File

@ -670,4 +670,84 @@ class Admin::PriceDocumentsController < ApplicationController
redirect_to admin_price_document_path(@price_document) redirect_to admin_price_document_path(@price_document)
end end
end end
def bon_de_reception
@past_price_document = PriceDocument.find(params[:id])
@p_customer_sheet = @past_price_document.ref_element
if @p_customer_sheet
price_document = @p_customer_sheet.price_documents.new(:price_document_type => PriceDocumentType.find_by_label("Bon de réception achat"), :demande_de_prix_id => @past_price_document.id, :date => Date.today)
else
price_document = PriceDocument.new(:price_document_type => PriceDocumentType.find_by_label("Bon de réception achat"), :date => Date.today)
end
price_document.doc_ref_id = @past_price_document.id
price_document.p_fournisseur = @past_price_document.p_fournisseur
price_document.price_line_block = @past_price_document.price_line_block.dup
if @past_price_document.cc_label == "Commande achat"
price_document.bon_de_commande_achat_id = @past_price_document.id
price_document.reliquat = true if PriceDocument.where(:bon_de_commande_achat_id => @past_price_document.id, :price_document_type_id => [5]).count > 0
end
if @past_price_document.cc_label == "Facture achat"
price_document.facture_achat_id = @past_price_document.id
end
price_document.price_line_block.ac_bon_de_commande_id = nil
price_document.price_line_block.ac_bon_de_livraison_id = nil
price_document.price_line_block.ac_facture_id = nil
price_document.price_line_block.ac_block_type = nil
price_document.price_line_block.ac_reliquat = nil
@past_price_document.price_line_block.price_lines.each do |pl|
new_pl = pl.dup
new_pl.price_line_ref_id = pl.id
new_pl.ac_block_type = nil
if price_document.reliquat and @p_customer_sheet
bls = PriceDocument.where(:bon_de_commande_achat_id => @past_price_document.id, :price_document_type_id => [5])
qte_ok = PriceLine.where(:price_line_ref_id => new_pl.price_line_ref_id).where(:price_line_block_id => PriceLineBlock.where(:price_lineable_type => "PriceDocument", :price_lineable_id => bls.ids)).sum(:qte)
new_pl.qte = new_pl.qte - qte_ok
end
price_document.price_line_block.price_lines << new_pl
end
if price_document.save
#price_document.reset_for_update
#price_document.archive_now
if @p_customer_sheet
@p_customer_sheet.state = "Bon de réception achat"
@p_customer_sheet.save
end
if price_document.ref_element
redirect_to [:admin, price_document.ref_element]
else
redirect_to [:admin, price_document]
end
else
render :inline => price_document.errors.messages.to_s
end
end
end end

View File

@ -5,25 +5,25 @@
-if @price_document.price_document_type_id == 6 and !@price_document.stock_ok -if @price_document.price_document_type_id == 6 and !@price_document.stock_ok
= link_to i(:pencil), edit_admin_price_document_path(:id => @price_document.id, :public_edit => true) if !@price_document.stock_ok = link_to i(:pencil), edit_admin_price_document_path(:id => @price_document.id, :public_edit => true) if !@price_document.stock_ok
= diag do = diag do
= link_to i(:pencil), edit_admin_price_document_path(@price_document) = link_to i(:pencil), edit_admin_price_document_path(@price_document)
= link_to i(:eye), admin_price_document_path(@price_document.id), :remote => false, :target => "_blank" = link_to i(:eye), admin_price_document_path(@price_document.id), :remote => false, :target => "_blank"
= link_to i(:download), print_admin_price_document_path(@price_document.token), :remote => false, :target => "_blank" if !PriceLineBlock::PURCHASE_BLOCKS.include?(@price_document.block_type) = link_to i(:download), print_admin_price_document_path(@price_document.token), :remote => false, :target => "_blank" if !PriceLineBlock::PURCHASE_BLOCKS.include?(@price_document.block_type)
%h1 %h1
Documents Documents
%span %span
=@price_document.price_document_type.label =@price_document.price_document_type.label
%span %span
="##{@price_document.id}" ="##{@price_document.id}"
%span %span
=@price_document.d_number =@price_document.d_number
.qi_row .qi_row
@ -35,16 +35,21 @@
Nom fournisseur saisi Nom fournisseur saisi
%td %td
=@price_document.public_fournisseur_name =@price_document.public_fournisseur_name
-if @price_document.p_fournisseur -if @price_document.p_fournisseur
%tr %tr
%td %td
Fournisseur Fournisseur
%td %td
=link_to @price_document.p_fournisseur.name, [:admin, @price_document.p_fournisseur] if @price_document.p_fournisseur =link_to @price_document.p_fournisseur.name, [:admin, @price_document.p_fournisseur] if @price_document.p_fournisseur
-if @price_document.d_number?
%tr
%td Numéro
%td=@price_document.d_number
%tr
%td Date
%td=l @price_document.date, :format => :date
-if @price_document.label == "Demande prix" -if @price_document.label == "Demande prix"
%tr %tr
@ -57,23 +62,23 @@
Désignation Désignation
%td %td
=@price_document.list_designaton =@price_document.list_designaton
%tr %tr
%td Date de fin de consultation : %td Date de fin de consultation :
%td %td
=l @price_document.end_date if @price_document.end_date =l @price_document.end_date if @price_document.end_date
%tr %tr
%td Commentaire %td Commentaire
%td %td
=simple_format @price_document.dp_comment =simple_format @price_document.dp_comment
%tr %tr
%td %td
Envoyé à Envoyé à
%td %td
=simple_format @price_document.acheteur_text =simple_format @price_document.acheteur_text
%tr %tr
%td %td
Lien pour consultation Lien pour consultation
@ -86,20 +91,20 @@
.qi_pannel.qi_plain.padding .qi_pannel.qi_plain.padding
-if false -if false
=debug @price_document =debug @price_document
-if true -if true
-price_line_block = @price_document.price_line_block -price_line_block = @price_document.price_line_block
=#render price_line_block =#render price_line_block
-else -else
-params[:search][:per_page] = params[:search][:per_page] || 5000 -params[:search][:per_page] = params[:search][:per_page] || 5000
-per_page = params[:search][:per_page] -per_page = params[:search][:per_page]
-page = (params[:page] and params[:page] != "") ? params[:page] : 1 -page = (params[:page] and params[:page] != "") ? params[:page] : 1
-@price_lines = @price_document.price_line_block.price_lines -@price_lines = @price_document.price_line_block.price_lines
@ -112,85 +117,86 @@
.clear .clear
=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @price_lines, :key => "reponses-prix-show"} =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @price_lines, :key => "reponses-prix-show"}
-if @price_document.label != "Demande prix" and @price_document.label != "Réponse fournisseur" -if @price_document.label != "Demande prix" and @price_document.label != "Réponse fournisseur"
-if current_admin and current_admin.id == 1 -if current_admin and current_admin.id == 1
%table.table -enable_stat = false
%tr -if enable_stat
%th Archivé ? %table.table
%td %tr
= diag do %th Archivé ?
-if @price_document.archived %td
Oui = diag do
=link_to "Désarchiver", unarchive_now_admin_price_document_path(@price_document.id) -if @price_document.archived
-else Oui
=link_to "Archiver", archive_now_admin_price_document_path(@price_document.id) =link_to "Désarchiver", unarchive_now_admin_price_document_path(@price_document.id)
%tr -else
%th Id bloc =link_to "Archiver", archive_now_admin_price_document_path(@price_document.id)
%td=price_line_block.id %tr
%th Id bloc
%td=price_line_block.id
%tr
%th Cout block
%td=price_line_block.cc_cost_ht
-params[:search][:per_page] = params[:search][:per_page] || 5000
-per_page = params[:search][:per_page]
-page = (params[:page] and params[:page] != "") ? params[:page] : 1
-@stat_lines = @price_document.stat_lines.order("date DESC, created_at DESC")
-@stat_lines = sort_by_sorting(@stat_lines, "created_at DESC")
-@stat_lines = @stat_lines.page(page).per(per_page)
%br
=link_to "Générer les stats", generate_stat_lines_admin_price_document_path(@price_document), :class => "btn btn-primary"
%table.table
%tr
%th
HT
%td
=number_to_currency @stat_lines.sum(:tot_amount_ht)
%tr
%th
TTC
%td
=number_to_currency @stat_lines.sum(:tot_amount_ttc)
%tr
%th
Coût HT
%td
=number_to_currency @stat_lines.sum(:cost_ht)
.clear %tr
=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @stat_lines} %th Cout block
%td=price_line_block.cc_cost_ht
-params[:search][:per_page] = params[:search][:per_page] || 5000
-per_page = params[:search][:per_page]
-page = (params[:page] and params[:page] != "") ? params[:page] : 1
-@stat_lines = @price_document.stat_lines.order("date DESC, created_at DESC")
-@stat_lines = sort_by_sorting(@stat_lines, "created_at DESC")
-@stat_lines = @stat_lines.page(page).per(per_page)
%br
=link_to "Générer les stats", generate_stat_lines_admin_price_document_path(@price_document), :class => "btn btn-primary"
%table.table
%tr
%th
HT
%td
=number_to_currency @stat_lines.sum(:tot_amount_ht)
%tr
%th
TTC
%td
=number_to_currency @stat_lines.sum(:tot_amount_ttc)
%tr
%th
Coût HT
%td
=number_to_currency @stat_lines.sum(:cost_ht)
.clear
=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @stat_lines}
%h3 Lignes de produits
%table.table %table.table
%thead %thead
%tr %tr
%th %th
%th Référence %th Référence
%th Produit %th Marque
%th Désignation %th Désignation
%th Qté %th Qté
%th P.U. HT %th P.U. HT
@ -204,131 +210,130 @@
="##{price_line.id}" ="##{price_line.id}"
%td %td
=price_line.ref =price_line.ref
%td %td
=link_to price_line.p_product_ref.p_product.name, edit_admin_p_product_path(price_line.p_product_ref.p_product) if price_line.p_product_ref and price_line.p_product_ref.p_product =price_line.p_product_ref.p_product.s_brand.name
%td %td
=price_line.title =link_to price_line.p_product_ref.cc_name, edit_admin_p_product_path(price_line.p_product_ref.p_product) if price_line.p_product_ref and price_line.p_product_ref.p_product
%td.numeraire %td.numeraire
=price_line.qte =price_line.qte
%td.numeraire %td.numeraire
=number_to_currency price_line.price_u_ht =number_to_currency price_line.price_u_ht
%td.numeraire %td.numeraire
=price_line.tva_account_value.to_s+"%" =price_line.tva_account_value.to_s+"%"
%td.numeraire %td.numeraire
=number_to_currency price_line.tot_amount_ht =number_to_currency price_line.tot_amount_ht
%td / %td=# price_line.line_stocks.sum(:price_ht)
= price_line.line_stocks.sum(:price_ht)
.qi_row
-if current_admin.has_permission?("show-costs") -if current_admin.has_permission?("show-costs")
%br %p
%br -if @price_document.price_document_type_id == 6
%p =link_to "Générer les stocks", generate_stocks_admin_price_document_path(@price_document), :class => "btn btn-primary" if !@price_document.stock_ok
-if @price_document.price_document_type_id == 6 -elsif @price_document.price_document_type_id == 4 or @price_document.price_document_type_id == 5
=link_to "Générer les stocks", generate_stocks_admin_price_document_path(@price_document), :class => "btn btn-primary" if !@price_document.stock_ok %p
-elsif @price_document.price_document_type_id == 4 or @price_document.price_document_type_id == 5 Coût :
%p =number_to_currency @price_document.cost_ht
Coût : %p
=number_to_currency @price_document.cost_ht Marge :
%p =number_to_currency @price_document.marge_ht
Marge :
=number_to_currency @price_document.marge_ht -if !@price_document.cost_ok
=link_to "Mettre à jour les stocks, calculer la marge", update_stocks_admin_price_document_path(@price_document), :class => "btn btn-primary"
-if !@price_document.cost_ok -if @price_document.d_number
=link_to "Mettre à jour les stocks, calculer la marge", update_stocks_admin_price_document_path(@price_document), :class => "btn btn-primary" -if @price_document.cc_label == "Commande achat"
%p=link_to "Générer un bon de réception", bon_de_reception_admin_price_document_path(@price_document), :class => "btn btn-primary"
-if false
-if false
-if @price_document.price_document_type_id == 4 or @price_document.price_document_type_id == 5 and !@price_document.cost_ok
%table.table.table-striped.table-hover.table-bordered -if @price_document.price_document_type_id == 4 or @price_document.price_document_type_id == 5 and !@price_document.cost_ok
%thead %table.table.table-striped.table-hover.table-bordered
%tr %thead
%th Produit %tr
%th Quantité dans cette pièce comptable %th Produit
%th Quantité restante %th Quantité dans cette pièce comptable
%th %th Quantité restante
-@price_document.price_line_block.price_lines.all.each do |pl| %th
-if pl.p_product_ref -@price_document.price_line_block.price_lines.all.each do |pl|
-if pl.p_product_ref
-if pl.p_product_ref.assembled
-pl.p_product_ref.p_product_assembleds.all.each do |ppa| -if pl.p_product_ref.assembled
%tr -pl.p_product_ref.p_product_assembleds.all.each do |ppa|
%td
=ppa.p_product_ref.cc_name
%td
=@a = (pl.qte.to_f * ppa.qte.to_f).to_f
%td
=link_to admin_line_stocks_path(:p_product_ref_id => ppa.p_product_ref.id) do
=@b = LineStock.where(:p_product_ref_id => ppa.p_product_ref_id).sum(:qte_available).to_f
%td
-if @a > @b
.red=ic :warning
-else
%tr %tr
%td %td
=pl.p_product_ref.cc_name =ppa.p_product_ref.cc_name
%td %td
=@a = pl.qte.to_f =@a = (pl.qte.to_f * ppa.qte.to_f).to_f
%td %td
=link_to admin_line_stocks_path(:p_product_ref_id => pl.p_product_ref.id) do =link_to admin_line_stocks_path(:p_product_ref_id => ppa.p_product_ref.id) do
=@b = LineStock.where(:p_product_ref_id => pl.p_product_ref_id).sum(:qte_available).to_f =@b = LineStock.where(:p_product_ref_id => ppa.p_product_ref_id).sum(:qte_available).to_f
%td %td
-if pl.p_product_ref.stocked and @a > @b -if @a > @b
.red=ic :warning .red=ic :warning
-if @price_document.price_document_type_id == 6 or @price_document.price_document_type_id == 4 or @price_document.price_document_type_id == 5
%h3 Stocks générés
#bills
-params[:search][:per_page] = params[:search][:per_page] || 5000
-per_page = params[:search][:per_page]
-page = (params[:page] and params[:page] != "") ? params[:page] : 1
-@line_stocks = @price_document.line_stocks.order("date DESC, created_at DESC")
-if params[:price_document_ids]
-@line_stocks = @line_stocks.where(:id => params[:price_document_ids])
-@line_stocks = sort_by_sorting(@line_stocks, "created_at DESC") -else
-@line_stocks = @line_stocks.page(page).per(per_page) %tr
%br %td
=pl.p_product_ref.cc_name
%td
=@a = pl.qte.to_f
%td
=link_to admin_line_stocks_path(:p_product_ref_id => pl.p_product_ref.id) do
=@b = LineStock.where(:p_product_ref_id => pl.p_product_ref_id).sum(:qte_available).to_f
%td
-if pl.p_product_ref.stocked and @a > @b
.red=ic :warning
.clear
=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @line_stocks} -if @price_document.price_document_type_id == 6 or @price_document.price_document_type_id == 4 or @price_document.price_document_type_id == 5
%h3 Stocks générés
#bills
-params[:search][:per_page] = params[:search][:per_page] || 5000
-per_page = params[:search][:per_page]
-page = (params[:page] and params[:page] != "") ? params[:page] : 1
-@line_stocks = @price_document.line_stocks.order("date DESC, created_at DESC")
-if params[:price_document_ids]
-@line_stocks = @line_stocks.where(:id => params[:price_document_ids])
-@line_stocks = sort_by_sorting(@line_stocks, "created_at DESC")
-@line_stocks = @line_stocks.page(page).per(per_page)
%br
.clear
=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @line_stocks}
-if @price_document.label == "Demande prix" -if @price_document.label == "Demande prix"
%h3.ml-2 Réponses fournisseur %h3.ml-2 Réponses fournisseur
#bills #bills
-params[:search][:per_page] = params[:search][:per_page] || 5000 -params[:search][:per_page] = params[:search][:per_page] || 5000
-per_page = params[:search][:per_page] -per_page = params[:search][:per_page]
-page = (params[:page] and params[:page] != "") ? params[:page] : 1 -page = (params[:page] and params[:page] != "") ? params[:page] : 1
-@price_documents = PriceDocument.where(:doc_ref_id => @price_document.id, :price_document_type_id => PriceDocumentType.find_by_label("Réponse fournisseur").id) -@price_documents = PriceDocument.where(:doc_ref_id => @price_document.id, :price_document_type_id => PriceDocumentType.find_by_label("Réponse fournisseur").id)
-@price_documents = sort_by_sorting(@price_documents, "created_at DESC") -@price_documents = sort_by_sorting(@price_documents, "created_at DESC")
@ -337,19 +342,19 @@
.clear .clear
=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @price_documents, :key => "reponses-prix-show"} =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @price_documents, :key => "reponses-prix-show"}
%h3.ml-2 Consultations fournisseur %h3.ml-2 Consultations fournisseur
#consult #consult
-params[:search][:per_page] = params[:search][:per_page] || 5000 -params[:search][:per_page] = params[:search][:per_page] || 5000
-per_page = params[:search][:per_page] -per_page = params[:search][:per_page]
-page = (params[:page] and params[:page] != "") ? params[:page] : 1 -page = (params[:page] and params[:page] != "") ? params[:page] : 1
-@price_documents = PriceDocument.where(:doc_ref_id => @price_document.id, :price_document_type_id => PriceDocumentType.find_by_label("Consultation fournisseur").id) -@price_documents = PriceDocument.where(:doc_ref_id => @price_document.id, :price_document_type_id => PriceDocumentType.find_by_label("Consultation fournisseur").id)
-@price_documents = sort_by_sorting(@price_documents, "created_at DESC") -@price_documents = sort_by_sorting(@price_documents, "created_at DESC")
@ -358,7 +363,7 @@
.clear .clear
=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @price_documents, :key => "reponses-prix-show"} =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @price_documents, :key => "reponses-prix-show"}
-if @price_documents.empty? -if @price_documents.empty?
.qi_pannel.qi_plain.padding .qi_pannel.qi_plain.padding

View File

@ -632,6 +632,8 @@ Rails.application.routes.draw do
post :analyse_reponses_save post :analyse_reponses_save
get :generate_final_consult get :generate_final_consult
get :buy_order_create get :buy_order_create
get :bon_de_reception
end end
collection do collection do
get :search_to_affect get :search_to_affect