facture achat

This commit is contained in:
Barnabé 2021-09-15 18:37:59 +02:00
parent d28ad68e99
commit 084e71905f
6 changed files with 86 additions and 23 deletions

View File

@ -731,8 +731,8 @@ class Admin::PriceDocumentsController < ApplicationController
@p_customer_sheet.save
end
if price_document.ref_element
redirect_to [:admin, price_document.ref_element]
if price_document.doc_ref_id
redirect_to [:admin, @past_price_document]
else
redirect_to [:admin, price_document]
end
@ -740,4 +740,60 @@ class Admin::PriceDocumentsController < ApplicationController
render :inline => price_document.errors.messages.to_s
end
end
def facture_achat
@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("Facture achat"), :demande_de_prix_id => @past_price_document.id, :date => Date.today)
else
price_document = PriceDocument.new(:price_document_type => PriceDocumentType.find_by_label("Facture 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
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
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 = "Facture"
@p_customer_sheet.save
end
if price_document.doc_ref_id
redirect_to [:admin, @past_price_document]
else
redirect_to [:admin, price_document]
end
else
render :inline => price_document.errors.messages.to_s
end
end
end

View File

@ -53,6 +53,8 @@ class PriceLine < ApplicationRecord
BON_DE_LIVRAISON_TO_RESET = %w(block_type weight_tot tot_line_ht tot_line_tva tot_line_ttc tot_discount_ht tot_discount_tva tot_discount_ttc tot_amount_ht tot_amount_tva tot_amount_ttc)
FACTURE_DACHAT_TO_RESET = %w(devise_rate local_tot_amount_ht block_type product_no_remise price_calc weight_u weight_tot tva_account_id tva_account_value ref title description price_u_ht price_u_tva price_u_ttc tot_line_ht tot_line_tva tot_line_ttc tot_discount_ht tot_discount_tva tot_discount_ttc tot_amount_ht tot_amount_tva tot_amount_ttc discount_market_percent discount_qte_percent discount_delay_percent discount_enrobage_percent discount_ecole_percent discount_comptant_percent product_remise_enrobage_ok uv p_product_specific_customer_id)
BON_DE_RECEPTION_ACHAT_TO_RESET = %w(devise_rate local_tot_amount_ht block_type product_no_remise price_calc weight_u weight_tot tva_account_id tva_account_value ref title description price_u_ht price_u_tva price_u_ttc tot_line_ht tot_line_tva tot_line_ttc tot_discount_ht tot_discount_tva tot_discount_ttc tot_amount_ht tot_amount_tva tot_amount_ttc discount_market_percent discount_qte_percent discount_delay_percent discount_enrobage_percent discount_ecole_percent discount_comptant_percent product_remise_enrobage_ok uv p_product_specific_customer_id)
COMMANDE_ACHAT_TO_RESET = %w(block_type product_no_remise price_calc weight_u weight_tot tva_account_id tva_account_value ref title description price_u_ht price_u_tva price_u_ttc tot_line_ht tot_line_tva tot_line_ttc tot_discount_ht tot_discount_tva tot_discount_ttc tot_amount_ht tot_amount_tva tot_amount_ttc discount_market_percent discount_qte_percent discount_delay_percent discount_enrobage_percent discount_ecole_percent discount_comptant_percent product_remise_enrobage_ok uv p_product_specific_customer_id)

View File

@ -325,6 +325,8 @@ class PriceLineBlock < ApplicationRecord
BON_DE_LIVRAISON_TO_RESET = %w(weight_tot tot_lines_ht tot_lines_tva tot_lines_ttc tot_fdp_ht tot_fdp_tva tot_fdp_ttc tot_discount_ht tot_discount_tva tot_discount_ttc tot_amount_af_discount_ht tot_amount_af_discount_tva tot_amount_af_discount_ttc gen_discount_percent tot_gen_discount_ht tot_gen_discount_tva tot_gen_discount_ttc tot_amount_ht tot_amount_tva tot_amount_ttc nbr_ship)
FACTURE_DACHAT_TO_RESET = %w(devise_rate weight_tot tot_lines_ht tot_lines_tva tot_lines_ttc tot_fdp_ht tot_fdp_tva tot_fdp_ttc tot_discount_ht tot_discount_tva tot_discount_ttc tot_amount_af_discount_ht tot_amount_af_discount_tva tot_amount_af_discount_ttc gen_discount_percent tot_gen_discount_ht tot_gen_discount_tva tot_gen_discount_ttc tot_amount_ht tot_amount_tva tot_amount_ttc nbr_ship)
BON_DE_RECEPTION_ACHAT_TO_RESET = %w(devise_rate weight_tot tot_lines_ht tot_lines_tva tot_lines_ttc tot_fdp_ht tot_fdp_tva tot_fdp_ttc tot_discount_ht tot_discount_tva tot_discount_ttc tot_amount_af_discount_ht tot_amount_af_discount_tva tot_amount_af_discount_ttc gen_discount_percent tot_gen_discount_ht tot_gen_discount_tva tot_gen_discount_ttc tot_amount_ht tot_amount_tva tot_amount_ttc nbr_ship)
COMMANDE_ACHAT_TO_RESET = %w(weight_tot tot_lines_ht tot_lines_tva tot_lines_ttc tot_fdp_ht tot_fdp_tva tot_fdp_ttc tot_discount_ht tot_discount_tva tot_discount_ttc tot_amount_af_discount_ht tot_amount_af_discount_tva tot_amount_af_discount_ttc gen_discount_percent tot_gen_discount_ht tot_gen_discount_tva tot_gen_discount_ttc tot_amount_ht tot_amount_tva tot_amount_ttc nbr_ship)
@ -346,12 +348,12 @@ class PriceLineBlock < ApplicationRecord
eval("self.ac_#{qid} = nil")
end
self.archive_now(:skip_personalised_archive => true)
self.archive_now()
self.price_lines.each do |pl|
pl.archive_now(:skip_personalised_archive => true)
pl.archive_now()
end

View File

@ -20,8 +20,8 @@
=hidden_field_tag :public_edit, params[:public_edit]
= @price_document.price_line_block.block_type
%h3
= @price_document.price_line_block.block_type
-if @price_document.label == "Demande prix"
.row

View File

@ -186,7 +186,6 @@
=# link_to i(:eye), admin_price_document_path(price_document), :remote => true
= link_to i(:eye), admin_price_document_path(price_document.id), :remote => false
-if PriceLineBlock::PURCHASE_BLOCKS.include?(price_document.block_type)
=# link_to i(:eye), admin_price_document_path(price_document.id), :remote => false
@ -201,6 +200,9 @@
= 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"
-if price_document.cc_label == "Bon de réception achat"
%br
=link_to "Générer la facture", facture_achat_admin_price_document_path(price_document)
=render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => price_document}

View File

@ -251,7 +251,7 @@
=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"
=#link_to "Mettre à jour les stocks, calculer la marge", update_stocks_admin_price_document_path(@price_document), :class => "btn btn-primary"
-if @price_document.d_number
-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"
@ -304,25 +304,26 @@
-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
-if @price_document.price_line_block.stock_ok
%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 = @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
-@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}
.clear
=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @line_stocks}
-if @price_document.label == "Demande prix"
@ -379,7 +380,7 @@
%h4.ml-2= price_document_consult.p_fournisseur.name
= semantic_form_for [:admin, price_document_consult], :html => {:class => "qi_price_form"}, :remote => false do |form|
= form.button "Valider modifications)", type: :submit, class: "btn btn-primary m-2"
= form.button "Valider modifications", type: :submit, class: "btn btn-primary m-2"
= link_to ic(:clipboard) + " Copier le text", "#", class: "btn btn-primary", "data-document" => price_document_consult.id, onclick: 'copyPriceLines(event)'
- existing_order = PriceDocument.where(doc_ref_id: price_document_consult.id)
- if existing_order.present?
@ -398,7 +399,6 @@
:javascript
const copyPriceLines = (event) => {
event.preventDefault()
@ -436,3 +436,4 @@
// Remove temporary element
document.body.removeChild(el);
}