From 084e71905fadf6bbcca7698de921c40110eef0d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Wed, 15 Sep 2021 18:37:59 +0200 Subject: [PATCH] facture achat --- .../admin/price_documents_controller.rb | 60 ++++++++++++++++++- app/models/price_line.rb | 2 + app/models/price_line_block.rb | 6 +- .../admin/price_documents/_form.html.haml | 4 +- .../price_documents/_price_document.html.haml | 4 +- .../admin/price_documents/show.html.haml | 33 +++++----- 6 files changed, 86 insertions(+), 23 deletions(-) diff --git a/app/controllers/admin/price_documents_controller.rb b/app/controllers/admin/price_documents_controller.rb index 93139eb..7ca73b2 100644 --- a/app/controllers/admin/price_documents_controller.rb +++ b/app/controllers/admin/price_documents_controller.rb @@ -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 diff --git a/app/models/price_line.rb b/app/models/price_line.rb index d33c571..9be5aea 100644 --- a/app/models/price_line.rb +++ b/app/models/price_line.rb @@ -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) diff --git a/app/models/price_line_block.rb b/app/models/price_line_block.rb index f4d44af..edfe0cb 100644 --- a/app/models/price_line_block.rb +++ b/app/models/price_line_block.rb @@ -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 diff --git a/app/views/admin/price_documents/_form.html.haml b/app/views/admin/price_documents/_form.html.haml index 1a74d5a..60a7314 100644 --- a/app/views/admin/price_documents/_form.html.haml +++ b/app/views/admin/price_documents/_form.html.haml @@ -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 diff --git a/app/views/admin/price_documents/_price_document.html.haml b/app/views/admin/price_documents/_price_document.html.haml index 68fe2c3..a18ec45 100644 --- a/app/views/admin/price_documents/_price_document.html.haml +++ b/app/views/admin/price_documents/_price_document.html.haml @@ -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} diff --git a/app/views/admin/price_documents/show.html.haml b/app/views/admin/price_documents/show.html.haml index ef8c572..2ef5d7b 100644 --- a/app/views/admin/price_documents/show.html.haml +++ b/app/views/admin/price_documents/show.html.haml @@ -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); } +