diff --git a/app/controllers/admin/price_documents_controller.rb b/app/controllers/admin/price_documents_controller.rb index b2458c6..542942d 100644 --- a/app/controllers/admin/price_documents_controller.rb +++ b/app/controllers/admin/price_documents_controller.rb @@ -611,27 +611,60 @@ class Admin::PriceDocumentsController < ApplicationController def analyse_reponses @price_document = PriceDocument.find(params[:id]) - @price_document_responses = PriceDocument.where(:doc_ref_id => @price_document.id ) + @price_document_responses = PriceDocument.where(:doc_ref_id => @price_document.id, :price_document_type_id => PriceDocumentType.find_by_label("Réponse fournisseur").id ) end def generate_final_consult # price_line_to_add ={id_fournisseur {price_line_resp_id: id, ||||| id priceline resp => id price line selectionné, prix} } - - price_lines_to_add = {p_fournisseur_id: 0} + + price_lines_to_add = {} @price_document_demand = PriceDocument.find(params[:id]) - @price_document_responses = PriceDocument.where(doc_ref_id: price_document_demand) - @result = [] + #@price_document_responses = PriceDocument.where(doc_ref_id: price_document_demand) + #@result = [] @price_document_demand.price_line_block.price_lines.each do |pl_demand| - pl_response = pl_demand.price_line_resps.first - @p_fournisseur = PFournisseur.find(pl_response) - @final_consult.price_line_block.new(params.require[:price_document][:price_line_block_attributes].permit!) - @price_document = PriceDocument.new(:p_fournisseur_id => params[:p_fournisseur_id]) + + pl_demand.price_line_resps.all.each do |price_line_resp| + + price_lines_to_add[price_line_resp.p_fournisseur.id] = price_lines_to_add[price_line_resp.p_fournisseur.id] || {:p_fournisseur => price_line_resp.p_fournisseur, :price_lines => [] } + + + price_lines_to_add[price_line_resp.p_fournisseur.id][:price_lines] << price_line_resp + + + end + + end + + + + + price_lines_to_add.each do |k,v| + new_final_consult = PriceDocument.new(:doc_ref_id => @price_document_demand.id,:date => Date.today, :price_document_type => PriceDocumentType.find_by_label("Consultation fournisseur")) + new_final_consult.price_line_block = PriceLineBlock.new(:p_fournisseur => v[:p_fournisseur]) + + v[:price_lines].each do |price_line_resp| + new_final_consult.price_line_block.price_lines << PriceLine.new(:p_product_ref => price_line_resp.p_product_ref, :qte => price_line_resp.qte_available, :ct_u_price_ht => price_line_resp.price_u_ht ) + end + + new_final_consult.save + + end + + + #pl_response = pl_demand.price_line_resps.first + #@p_fournisseur = PFournisseur.find(pl_response) + #@final_consult.price_line_block.new(params.require[:price_document][:price_line_block_attributes].permit!) + #@price_document = PriceDocument.new(:p_fournisseur_id => params[:p_fournisseur_id]) - PriceDocument.new() - @result << pl_demand + #PriceDocument.new() + #@result << pl_demand + + #end + + render :consult_index diff --git a/app/models/price_document.rb b/app/models/price_document.rb index 9b8b83d..8ed50a1 100644 --- a/app/models/price_document.rb +++ b/app/models/price_document.rb @@ -25,7 +25,7 @@ class PriceDocument < ApplicationRecord has_many :avoir_p_payment_documents, :dependent => :destroy, :foreign_key => :avoir_id, :class_name => "PPaymentDocument" accepts_nested_attributes_for :avoir_p_payment_documents, allow_destroy: true - PURCHASES = ["Demande de prix", "Commande achat", "Facture d'achat"] + PURCHASES = ["Demande prix", "Réponse fournisseur", "Commande achat", "Facture d'achat", "Consultation fournisseur"] SALES = ["Bon de commande", "Devis", "Bon de livraison", "Facture", "Avoir"] # AVANCEMENT = ["0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%"] AVANCEMENT = ["0%", "25%", "50%", "75%", "100"] diff --git a/app/models/price_line.rb b/app/models/price_line.rb index 0eba34d..f156d9b 100644 --- a/app/models/price_line.rb +++ b/app/models/price_line.rb @@ -7,6 +7,8 @@ class PriceLine < ApplicationRecord has_many :price_line_resps, through: :price_line_resp_selects, :source => :price_line_resp + has_one :p_fournisseur, :through => :price_line_block + #has_many :price_line_demands, through: :price_line_resp_selects default_scope { order('position ASC') } diff --git a/app/models/price_line_block.rb b/app/models/price_line_block.rb index 14b7469..7e9ea94 100644 --- a/app/models/price_line_block.rb +++ b/app/models/price_line_block.rb @@ -23,7 +23,7 @@ class PriceLineBlock < ApplicationRecord belongs_to :p_payment_type - PURCHASE_BLOCKS = ["Facture d'achat", "Commande achat"] + PURCHASE_BLOCKS = ["Demande prix", "Réponse fournisseur", "Commande achat", "Facture d'achat", "Consultation fournisseur"] SALE_BLOCKS = ["Demande de commande", "Bon de commande", "Devis", "Bon de livraison", "Facture", "Avoir"] belongs_to :p_fournisseur diff --git a/app/views/admin/price_documents/_price_document.html.haml b/app/views/admin/price_documents/_price_document.html.haml index 21b2a88..29b43ac 100644 --- a/app/views/admin/price_documents/_price_document.html.haml +++ b/app/views/admin/price_documents/_price_document.html.haml @@ -69,12 +69,15 @@ %td - if price_document.avancement = price_document.avancement.to_s + " %" - - elsif parent_doc.avancement + - elsif parent_doc and parent_doc.avancement = parent_doc.avancement.to_s + " %" -tr[:list_designaton] = capture do %td - = price_document.list_designaton || parent_doc.list_designaton + -if price_document.list_designaton + = price_document.list_designaton + -elsif parent_doc + =parent_doc.list_designaton -tr[:end_date] = capture do %td @@ -87,11 +90,17 @@ -tr[:dp_comment] = capture do %td - = price_document.dp_comment || parent_doc.dp_comment + -if price_document.dp_comment + = price_document.dp_comment + -elsif parent_doc + =parent_doc.dp_comment -tr[:acheteur_text] = capture do %td - = price_document.acheteur_text || parent_doc.acheteur_text + -if price_document.acheteur_text + = price_document.acheteur_text + -elsif parent_doc + =parent_doc.acheteur_text -tr[:customer_ref] = capture do %td diff --git a/app/views/admin/price_documents/analyse_reponses.html.haml b/app/views/admin/price_documents/analyse_reponses.html.haml index 2e027e3..67ae51e 100644 --- a/app/views/admin/price_documents/analyse_reponses.html.haml +++ b/app/views/admin/price_documents/analyse_reponses.html.haml @@ -197,8 +197,8 @@ -#NICO : si on a un price_line_ref_id, j'ajoute la case à cocher. Je récupère l'index de nested form dans mon hash, et je passe en value le line.id -if line.price_line_ref_id.to_s != "" - %input.category-selector{:id => "price_document_price_line_block_attributes_price_lines_attributes_#{price_lines_child_index[line.price_line_ref_id.to_s]}_price_line_resp_ids_#{line.id}" , :autocomplete => "off", :checked => ("checked" if PriceLine.find(line.price_line_ref_id).price_line_resp_ids.include?(line.id) ), :name => "price_document[price_line_block_attributes][price_lines_attributes][#{price_lines_child_index[line.price_line_ref_id.to_s]}][price_line_resp_ids][]", :type => "checkbox", :value => line.id}>/ - %label.p-2.m-auto{:for => "price_document_price_line_block_attributes_price_lines_attributes_#{price_lines_child_index[line.price_line_ref_id.to_s]}_price_line_resp_ids_#{line.id}"} + %input.category-selectornico{:id => "price_document_price_line_block_attributes_price_lines_attributes_#{price_lines_child_index[line.price_line_ref_id.to_s]}_price_line_resp_ids_#{line.id}" , :autocomplete => "off", :checked => ("checked" if PriceLine.find(line.price_line_ref_id).price_line_resp_ids.include?(line.id) ), :name => "price_document[price_line_block_attributes][price_lines_attributes][#{price_lines_child_index[line.price_line_ref_id.to_s]}][price_line_resp_ids][]", :type => "checkbox", :value => line.id}>/ + %label.p-2.m-autonico{:for => "price_document_price_line_block_attributes_price_lines_attributes_#{price_lines_child_index[line.price_line_ref_id.to_s]}_price_line_resp_ids_#{line.id}"} =sanitize(cell.join('
')) diff --git a/app/views/admin/price_documents/show.html.haml b/app/views/admin/price_documents/show.html.haml index c1be467..2ce92e1 100644 --- a/app/views/admin/price_documents/show.html.haml +++ b/app/views/admin/price_documents/show.html.haml @@ -25,62 +25,61 @@ =@price_document.d_number --if @price_document.label == "Réponse fournisseur" - .qi_row - .qi_pannel.padding - - %table.table.table-striped - %tr - %td - Nom fournisseur saisi - %td - =@price_document.public_fournisseur_name - %tr - %td - Fournisseur - %td - =link_to @price_document.p_fournisseur.name, [:admin, @price_document.p_fournisseur] if @price_document.p_fournisseur - +.qi_row + %table.table.table-striped + -if @price_document.label == "Réponse fournisseur" + + %tr + %td + Nom fournisseur saisi + %td + =@price_document.public_fournisseur_name + + -if @price_document.p_fournisseur + %tr + %td + Fournisseur + %td + =link_to @price_document.p_fournisseur.name, [:admin, @price_document.p_fournisseur] if @price_document.p_fournisseur + --if @price_document.label == "Demande prix" - .qi_row - .qi_pannel.padding - %table.table.table-striped - %tr - %td - Avancement (%) - %td - =@price_document.avancement.to_s + " %" - %tr - %td - Désignation - %td - =@price_document.list_designaton - - %tr - %td Date de fin de consultation : - %td - =l @price_document.end_date if @price_document.end_date - - %tr - %td Commentaire - %td - =simple_format @price_document.dp_comment - - %tr - %td - Envoyé à - %td - =simple_format @price_document.acheteur_text - - %tr - %td - Lien pour consultation - %td - =link_to consult_admin_price_document_url(:id => @price_document.f_token, :lang => nil), consult_admin_price_document_url(:id => @price_document.f_token, :lang => nil) + + -if @price_document.label == "Demande prix" + %tr + %td + Avancement (%) + %td + =@price_document.avancement.to_s + " %" + %tr + %td + Désignation + %td + =@price_document.list_designaton + + %tr + %td Date de fin de consultation : + %td + =l @price_document.end_date if @price_document.end_date + %tr + %td Commentaire + %td + =simple_format @price_document.dp_comment + + %tr + %td + Envoyé à + %td + =simple_format @price_document.acheteur_text + + %tr + %td + Lien pour consultation + %td + =link_to consult_admin_price_document_url(:id => @price_document.f_token, :lang => nil), consult_admin_price_document_url(:id => @price_document.f_token, :lang => nil) + .qi_row @@ -90,12 +89,12 @@ - -if false + -if true -price_line_block = @price_document.price_line_block - =render price_line_block + =#render price_line_block -else -params[:search][:per_page] = params[:search][:per_page] || 5000 @@ -321,14 +320,34 @@ -if @price_document.label == "Demande prix" - %h3 Réponses fournisseur #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 - -@price_documents = PriceDocument.where(:doc_ref_id => @price_document.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 = @price_documents.page(page).per(per_page) + %br + + + + .clear + =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @price_documents, :key => "reponses-prix-show"} + + + %h3 Consultations fournisseur + #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 + + -@price_documents = PriceDocument.where(:doc_ref_id => @price_document.id, :price_document_type_id => PriceDocumentType.find_by_label("Consultation fournisseur").id)