From 95b78299270f8cd0713dbf24931cf41e040910e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 23 Aug 2021 16:42:42 +0200 Subject: [PATCH 001/131] Remove status input --- app/models/p_customer_sheet.rb | 2 +- app/views/admin/p_customer_sheets/_form.html.haml | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/app/models/p_customer_sheet.rb b/app/models/p_customer_sheet.rb index 70d1426..c38ed4c 100644 --- a/app/models/p_customer_sheet.rb +++ b/app/models/p_customer_sheet.rb @@ -256,7 +256,7 @@ class PCustomerSheet < ApplicationRecord after_create do - #self.state = "brouillon" if self.state != "Panier web" + self.state = "brouillon" if self.state != "Panier web" self.save end diff --git a/app/views/admin/p_customer_sheets/_form.html.haml b/app/views/admin/p_customer_sheets/_form.html.haml index c8c82b9..16361e8 100755 --- a/app/views/admin/p_customer_sheets/_form.html.haml +++ b/app/views/admin/p_customer_sheets/_form.html.haml @@ -1,14 +1,7 @@ =semantic_form_for [:admin, @p_customer_sheet], :html => {:class => "qi_price_form"}, :remote => false do |form| .content - .qi_row - .qi_pannel.qi_plain.padding - -if @p_customer_sheet and @p_customer_sheet.state != "commande" - =#form.input :demande_type, :collection => ["Brouillon", "Demande de bon de commande","Demande de devis"], :as => :select, :include_blank => false, :label => "Type de demande :" - - =form.input :state, :collection => ["AV BPA", "PAS BPA","BPA", "Traitée"], :as => :select, :include_blank => false, :label => "Statut :" - - =form.input :past_id, :label => "N° système actuel" + .price_line_block_form =form.semantic_fields_for :price_line_block do |f| From 399cc1deaa57330d2a03d7fc0f767b483d1929e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Tue, 24 Aug 2021 10:24:56 +0200 Subject: [PATCH 002/131] replace state --- app/controllers/admin/buy_lists_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/buy_lists_controller.rb b/app/controllers/admin/buy_lists_controller.rb index cd1b7b6..d68d6b3 100644 --- a/app/controllers/admin/buy_lists_controller.rb +++ b/app/controllers/admin/buy_lists_controller.rb @@ -8,7 +8,7 @@ class Admin::BuyListsController < ApplicationController @p_customer_sheets = PCustomerSheet.all - @p_customer_sheets = @p_customer_sheets.where(:state => ["AV BPA", "PAS BPA", "BPA"]) + @p_customer_sheets = @p_customer_sheets.where(:state => ["brouillon", "offre", "commande"]) @price_line_blocks = PriceLineBlock.where(:price_lineable_type => "PCustomerSheet", :price_lineable_id => @p_customer_sheets.ids) From a334469ac0469b45db4d649df0d1d69a322e0ef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 3 Sep 2021 17:30:40 +0200 Subject: [PATCH 003/131] Upgrade UX for new customersheet --- app/helpers/document_line_helper.rb | 2 +- .../admin/p_customer_sheets/_form.html.haml | 31 ++-- .../admin/price_line_blocks/_form.html.haml | 151 +++++++++--------- app/views/admin/price_lines/_form.html.haml | 11 +- 4 files changed, 96 insertions(+), 99 deletions(-) diff --git a/app/helpers/document_line_helper.rb b/app/helpers/document_line_helper.rb index 6dbbc93..8066e11 100644 --- a/app/helpers/document_line_helper.rb +++ b/app/helpers/document_line_helper.rb @@ -34,7 +34,7 @@ module DocumentLineHelper end end - link_to name,"#", :onclick => "add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\");return false;", :class => (options[:class]) + link_to name,"#", :onclick => "add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\");return false;", :class => (options[:class]), tabindex: options[:tabindex], style: options[:style] end end diff --git a/app/views/admin/p_customer_sheets/_form.html.haml b/app/views/admin/p_customer_sheets/_form.html.haml index c8c82b9..56f16a6 100755 --- a/app/views/admin/p_customer_sheets/_form.html.haml +++ b/app/views/admin/p_customer_sheets/_form.html.haml @@ -1,22 +1,25 @@ =semantic_form_for [:admin, @p_customer_sheet], :html => {:class => "qi_price_form"}, :remote => false do |form| - + =form.semantic_fields_for :price_line_block do |f| + =render :partial => "admin/price_line_blocks/form", :locals => {:f => f} + .content .qi_row - .qi_pannel.qi_plain.padding - -if @p_customer_sheet and @p_customer_sheet.state != "commande" - =#form.input :demande_type, :collection => ["Brouillon", "Demande de bon de commande","Demande de devis"], :as => :select, :include_blank => false, :label => "Type de demande :" - - =form.input :state, :collection => ["AV BPA", "PAS BPA","BPA", "Traitée"], :as => :select, :include_blank => false, :label => "Statut :" - - =form.input :past_id, :label => "N° système actuel" - - .price_line_block_form - =form.semantic_fields_for :price_line_block do |f| - =render :partial => "admin/price_line_blocks/form", :locals => {:f => f} + .qi_pannel.qi_plain.padding.row + .col-2 + -if @p_customer_sheet and @p_customer_sheet.state != "commande" + =#form.input :demande_type, :collection => ["Brouillon", "Demande de bon de commande","Demande de devis"], :as => :select, :include_blank => false, :label => "Type de demande :" + + =form.input :state, :collection => ["AV BPA", "PAS BPA","BPA", "Traitée"], :as => :select, :include_blank => false, :label => "Statut :" + + =form.input :past_id, :label => "N° système actuel" + =yield :discount + .col-2 + =yield :shipping_date + .col-8 + =yield :particular - - + =yield :price_lines .right.actions =link_to "Annuler", admin_p_customer_sheets_path(), :class => "btn" =form.submit "sauvegarder", :class => "btn btn-primary btn-ap-add" diff --git a/app/views/admin/price_line_blocks/_form.html.haml b/app/views/admin/price_line_blocks/_form.html.haml index e945168..20b07b9 100644 --- a/app/views/admin/price_line_blocks/_form.html.haml +++ b/app/views/admin/price_line_blocks/_form.html.haml @@ -1,104 +1,97 @@ -.qi_row - =f.inputs do +=f.inputs do + + + -if !@p_customer_sheet or (@p_customer_sheet and @p_customer_sheet.state != "commande") + + = f.hidden_field :p_customer_id, :class => "p_customer_id" + =content_for :particular do + .row + .p_customer_sheet_customer.col-12.mb-4 - -if !@p_customer_sheet or (@p_customer_sheet and @p_customer_sheet.state != "commande") - .qi_pannel.qi_plain.padding{:style => "margin:20px 0;"} - - = f.hidden_field :p_customer_id, :class => "p_customer_id" - - .p_customer_sheet_customer - - -if f.object.p_customer and f.object.p_customer.particular =render :partial => "admin/p_customers/apercu", :locals => {:particular => f.object.p_customer.particular} - .padding{:style => "padding:0 10px;"} + .col-6 .addresses.row .columns.span_6 - %h3 Adresse de facturation - + %h4 Adresse de facturation + -if f.object.p_customer =f.inputs do = f.input :particular_bill_id, :collection => f.object.p_customer.particulars.all, :as => :select, :member_label => :address_line, :include_blank => false, :label => "Adresse de facturation" -else =f.inputs do = f.input :particular_bill_id, :collection => [], :as => :select, :include_blank => false, :label => "Adresse de facturation" - + .col-6 + .addresses.row .columns.span_6 - %h3 Adresse de livraison - + %h4 Adresse de livraison + -if f.object.p_customer =f.inputs do = f.input :particular_send_id, :collection => f.object.p_customer.particulars.all, :as => :select, :member_label => :address_line, :include_blank => false, :label => "Adresse de livraison" -else =f.inputs do = f.input :particular_send_id, :collection => [], :as => :select, :include_blank => false, :label => "Adresse de facturation" - + .clear - - - %table{:style => "width:100%;"} - %tr - %td{:style => "width:33%;"} - = f.input :wish_date, :label => "Date de livraison souhaitée :", :as => :date - - %td{:style => "width:33%;"} - = f.input :ct_creation_date, :label => "Date de commande (si différente de la date de création) :", :as => :date - - %td{:style => "width:33%;"} - = f.input :validation_date, :label => "Date de validation :", :as => :date - - - = f.input :customer_ref, :label => "Référence commande client :" - -if current_admin.has_permission?("customer-sheets-bl") - =# f.input :bl_comment, :label => "Commentaire à mettre sur le BL :", :input_html => {:style => "min-height:50px;height:50px;"} - - -if @p_customer_sheet and @p_customer_sheet.p_customer and @p_customer_sheet.p_customer.p_customer_sheet_note? - %div - %strong Notes pour les demandes de commandes pour ce client : - =simple_format @p_customer_sheet.p_customer.p_customer_sheet_note - %br - - - - - .price_lines_form - =f.semantic_fields_for :price_lines do |f| - =render :partial => "admin/price_lines/form", :locals => {:form => f} - - %p= link_to_add_fields "Ajouter une ligne", f, :price_lines, {:class => "btn btn-primary"} - - - -if current_admin.has_permission?("payments") - .qi_pannel.qi_plain.padding.price_line_block_footer{:style => "margin:20px 0;"} - - -if !@p_customer_sheet or (@p_customer_sheet and @p_customer_sheet.state != "commande") - -if !@avoir - = f.input :ct_tot_discount_percent, :label => "Réduction pied de page (%) :", :input_html => {:class => "input_price_line_block_ct_tot_discount_percent"} - = f.input :ct_tot_fdp_ht, :label => "Frais de port personnalisés :" - - - -if current_admin.has_permission?("payments") + =content_for :shipping_date do + = f.input :wish_date, :label => "Date de livraison souhaitée :", :as => :date + = f.input :ct_creation_date, :label => "Date de commande (si différente de la date de création) :", :as => :date + = f.input :validation_date, :label => "Date de validation :", :as => :date + + + + = f.input :customer_ref, :label => "Référence commande client :" + -if current_admin.has_permission?("customer-sheets-bl") + =# f.input :bl_comment, :label => "Commentaire à mettre sur le BL :", :input_html => {:style => "min-height:50px;height:50px;"} + + -if @p_customer_sheet and @p_customer_sheet.p_customer and @p_customer_sheet.p_customer.p_customer_sheet_note? + %div + %strong Notes pour les demandes de commandes pour ce client : + =simple_format @p_customer_sheet.p_customer.p_customer_sheet_note + %br + + + + =content_for :price_lines do + .row + .price_lines_form.col-11.row + =f.semantic_fields_for :price_lines do |f| + =render :partial => "admin/price_lines/form", :locals => {:form => f} + + %p.col-1= link_to_add_fields ic("plus-circle") + " ligne", f, :price_lines, {:class => "btn btn-primary p-2", tabindex: 10, style: "position: sticky; top: 100px"} + + + -if current_admin.has_permission?("payments") + =content_for :discount do -if !@p_customer_sheet or (@p_customer_sheet and @p_customer_sheet.state != "commande") - - if f.object.id - .qi_pannel.qi_plain.padding{:style => "margin:20px 0;"} - %h4 Paiements - - = f.input :p_payment_type_id, :label => "Type de paiement :", :include_blank => false, :collection => PPaymentType.order(:name).all, :as => :select, :input_html => {:id => "payment_type_id_select"} - + -if !@avoir + = f.input :ct_tot_discount_percent, :label => "Réduction pied de page (%) :", :input_html => {:class => "input_price_line_block_ct_tot_discount_percent"} + = f.input :ct_tot_fdp_ht, :label => "Frais de port personnalisés :" + + + -if current_admin.has_permission?("payments") + -if !@p_customer_sheet or (@p_customer_sheet and @p_customer_sheet.state != "commande") + - if f.object.id + .qi_pannel.qi_plain.padding{:style => "margin:20px 0;"} + %h4 Paiements + + = f.input :p_payment_type_id, :label => "Type de paiement :", :include_blank => false, :collection => PPaymentType.order(:name).all, :as => :select, :input_html => {:id => "payment_type_id_select"} + + + = f.input :ct_payment_comptant, :label => "Paiement comptant nécessaire ?" + + -if false + = f.input :ct_acompte, :label => "Acompte nécessaire ?" + = f.input :ct_acompte_percent, :label => "Pourcentage d'acompte :" + + = f.input :ct_payment_delais, :label => "Délais jour de paiement :" + + -if false + = f.input :ct_payment_month_end, :label => "Fin de mois ?" + - = f.input :ct_payment_comptant, :label => "Paiement comptant nécessaire ?" - -if false - = f.input :ct_acompte, :label => "Acompte nécessaire ?" - = f.input :ct_acompte_percent, :label => "Pourcentage d'acompte :" - = f.input :ct_payment_delais, :label => "Délais jour de paiement :" - - -if false - = f.input :ct_payment_month_end, :label => "Fin de mois ?" - - - - \ No newline at end of file diff --git a/app/views/admin/price_lines/_form.html.haml b/app/views/admin/price_lines/_form.html.haml index ed95396..7ad0661 100644 --- a/app/views/admin/price_lines/_form.html.haml +++ b/app/views/admin/price_lines/_form.html.haml @@ -1,5 +1,5 @@ -.qi_pannel.qi_plain.padding.price_line_form.field{:style =>"border-left:4px solid gray;margin-bottom:10px;padding-left:5px;"} +.qi_pannel.qi_plain.padding.price_line_form.col-3.field{:style =>"border-left:4px solid gray;margin-bottom:10px;padding-left:5px;"} %table{:style => "width:100%;"} %tr %td{:style => "width:30px;"} @@ -10,12 +10,13 @@ = form.input :ct_title, :label => "Designation personnalisée : " if @avoir %div{:class => ("error has-error" if form.object.errors[:p_product_ref_id].size > 0 )} %label Produit : - %input.p_product_ref_autocomplete_input.form-control{:type => "text", :value => ("#{form.object.p_product_ref.ref} #{form.object.p_product_ref.cc_name}" if form.object.p_product_ref)} + %input.p_product_ref_autocomplete_input.form-control{:type => "text", tabindex: 1, autofocus: true, :value => ("#{form.object.p_product_ref.ref} #{form.object.p_product_ref.cc_name}" if form.object.p_product_ref)} = form.hidden_field :p_product_ref_id, :class => "p_product_ref_id" :javascript + $('.p_product_ref_autocomplete_input').focus() $( function() { $('.p_product_ref_autocomplete_input').autocomplete({ @@ -102,7 +103,7 @@ .forced_price_wrapper{:style => ("display:none;" if !form.object.forced_price)}= form.input :ct_u_price_ht, :label => false, :input_html => {:class => "input_price_line_ct_u_price_ht"} %td - = form.input :qte, :label => "qte :", :input_html => {:class => "input_price_line_qte"} + = form.input :qte, :label => "qte :", :input_html => {:class => "input_price_line_qte", tabindex: 1} @@ -118,13 +119,13 @@ -else %label Taux de TVA : %br - =select_tag :tva_account_id, options_from_collection_for_select(TvaRate.where(:accounting_zone_id => (@p_customer ? @p_customer.accounting_zone_id : nil)).all, "id", "member_label", form.object.tva_account_id), :class => "input_price_line_tva_account_id" #, :disabled => true + =select_tag :tva_account_id, options_from_collection_for_select(TvaRate.where(:accounting_zone_id => (@p_customer ? @p_customer.accounting_zone_id : nil)).all, "id", "member_label", form.object.tva_account_id), :class => "input_price_line_tva_account_id custom-select" #, :disabled => true =qi_js_field(form, :price_line, :tva_account_value, :hidden => true) - = form.input :comment, :label => "Commentaire" + / = form.input :comment, :label => "Commentaire" From 4b29b62e474a1135917de551322e1979543086d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Tue, 7 Sep 2021 19:09:39 +0200 Subject: [PATCH 004/131] add price_line_resp_select --- .../price_line_resp_selects_controller.rb | 76 +++++++++++++++++++ app/models/price_line_resp_select.rb | 4 + .../price_line_resp_selects/_form.html.haml | 13 ++++ .../_price_line_resp_select.html.haml | 16 ++++ .../price_line_resp_selects/create.js.erb | 2 + .../price_line_resp_selects/destroy.js.erb | 1 + .../admin/price_line_resp_selects/edit.js.erb | 1 + .../price_line_resp_selects/index.html.haml | 16 ++++ .../admin/price_line_resp_selects/new.js.erb | 1 + .../price_line_resp_selects/show.html.haml | 10 +++ .../price_line_resp_selects/update.js.erb | 2 + config/routes.rb | 11 +++ ...07161735_create_price_line_resp_selects.rb | 10 +++ db/schema.rb | 9 ++- 14 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 app/controllers/admin/price_line_resp_selects_controller.rb create mode 100644 app/models/price_line_resp_select.rb create mode 100644 app/views/admin/price_line_resp_selects/_form.html.haml create mode 100644 app/views/admin/price_line_resp_selects/_price_line_resp_select.html.haml create mode 100644 app/views/admin/price_line_resp_selects/create.js.erb create mode 100644 app/views/admin/price_line_resp_selects/destroy.js.erb create mode 100644 app/views/admin/price_line_resp_selects/edit.js.erb create mode 100644 app/views/admin/price_line_resp_selects/index.html.haml create mode 100644 app/views/admin/price_line_resp_selects/new.js.erb create mode 100644 app/views/admin/price_line_resp_selects/show.html.haml create mode 100644 app/views/admin/price_line_resp_selects/update.js.erb create mode 100644 db/migrate/20210907161735_create_price_line_resp_selects.rb diff --git a/app/controllers/admin/price_line_resp_selects_controller.rb b/app/controllers/admin/price_line_resp_selects_controller.rb new file mode 100644 index 0000000..24020fd --- /dev/null +++ b/app/controllers/admin/price_line_resp_selects_controller.rb @@ -0,0 +1,76 @@ +# -*- encoding : utf-8 -*- + +class Admin::PriceLineRespSelectsController < ApplicationController + layout "admin" + before_action :auth_admin + + before_action :admin_space + + def admin_space + @admin_space = "default" + end + + def index + @price_line_resp_selects = PriceLineRespSelect.all + + @price_line_resp_selects = sort_by_sorting(@price_line_resp_selects, "id DESC") + respond_to do |format| + format.html{ + + params[:search][:per_page] = params[:search][:per_page] || 100 + per_page = params[:search][:per_page] + page = (params[:page] and params[:page] != "") ? params[:page] : 1 + @price_line_resp_selects = @price_line_resp_selects.page(page).per(per_page) + + } + end + end + + def show + @price_line_resp_select = PriceLineRespSelect.find(params[:id]) + + end + + def new + @price_line_resp_select = PriceLineRespSelect.new + + end + + def edit + @price_line_resp_select = PriceLineRespSelect.find(params[:id]) + + end + + def create + @price_line_resp_select = PriceLineRespSelect.new(params.require(:price_line_resp_select).permit!) + + if @price_line_resp_select.save + + else + render action: "new" + + end + + end + + + def update + @price_line_resp_select = PriceLineRespSelect.find(params[:id]) + + + if @price_line_resp_select.update_attributes(params.require(:price_line_resp_select).permit!) + + else + render action: "edit" + + end + + end + + + def destroy + @price_line_resp_select = PriceLineRespSelect.find(params[:id]) + @price_line_resp_select.destroy + + end +end diff --git a/app/models/price_line_resp_select.rb b/app/models/price_line_resp_select.rb new file mode 100644 index 0000000..f656ff3 --- /dev/null +++ b/app/models/price_line_resp_select.rb @@ -0,0 +1,4 @@ +class PriceLineRespSelect < ApplicationRecord + belongs_to :price_line_demand, class_name: "PriceLine" + belongs_to :price_line_resp, class_name: "PriceLine" +end diff --git a/app/views/admin/price_line_resp_selects/_form.html.haml b/app/views/admin/price_line_resp_selects/_form.html.haml new file mode 100644 index 0000000..73156af --- /dev/null +++ b/app/views/admin/price_line_resp_selects/_form.html.haml @@ -0,0 +1,13 @@ +=semantic_form_for [:admin, @price_line_resp_select], :remote => true do |f| + + .content + =f.inputs do + = f.input :price_line_demand_id, :label => f.object.label_for(:price_line_demand_id) + = f.input :price_line_resp_id, :label => f.object.label_for(:price_line_resp_id) + + + + + + .actions=f.submit "sauvegarder", :class => "btn btn-primary" + \ No newline at end of file diff --git a/app/views/admin/price_line_resp_selects/_price_line_resp_select.html.haml b/app/views/admin/price_line_resp_selects/_price_line_resp_select.html.haml new file mode 100644 index 0000000..d174a07 --- /dev/null +++ b/app/views/admin/price_line_resp_selects/_price_line_resp_select.html.haml @@ -0,0 +1,16 @@ +%tr#price_line_resp_select_row{:id => price_line_resp_select.id} + -tr = {} + + -tr[:actions] = capture do + %td.actions + = link_to i(:"trash-o"), [:admin, price_line_resp_select], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true + = link_to i(:pencil), edit_admin_price_line_resp_select_path(price_line_resp_select), :remote => true + = link_to i(:eye), admin_price_line_resp_select_path(price_line_resp_select), :remote => true + + + + =render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => price_line_resp_select} + + + + \ No newline at end of file diff --git a/app/views/admin/price_line_resp_selects/create.js.erb b/app/views/admin/price_line_resp_selects/create.js.erb new file mode 100644 index 0000000..aadcb42 --- /dev/null +++ b/app/views/admin/price_line_resp_selects/create.js.erb @@ -0,0 +1,2 @@ +$('#price_line_resp_selects_rows').prepend("<%= escape_javascript(render(@price_line_resp_select))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/app/views/admin/price_line_resp_selects/destroy.js.erb b/app/views/admin/price_line_resp_selects/destroy.js.erb new file mode 100644 index 0000000..9a7da6c --- /dev/null +++ b/app/views/admin/price_line_resp_selects/destroy.js.erb @@ -0,0 +1 @@ +$('#price_line_resp_select_row_<%= @price_line_resp_select.id %>').remove(); \ No newline at end of file diff --git a/app/views/admin/price_line_resp_selects/edit.js.erb b/app/views/admin/price_line_resp_selects/edit.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/price_line_resp_selects/edit.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/price_line_resp_selects/index.html.haml b/app/views/admin/price_line_resp_selects/index.html.haml new file mode 100644 index 0000000..b5afa77 --- /dev/null +++ b/app/views/admin/price_line_resp_selects/index.html.haml @@ -0,0 +1,16 @@ +.qi_header + .right= link_to ic(:plus)+' Ajouter', new_admin_price_line_resp_select_path(), :class => "btn btn-primary btn-ap-add", :remote => true + %h1 + =PriceLineRespSelect.human rescue "" + + + +.qi_search_row + =form_tag "", :method => "get", :onsubmit => "" do + =render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @price_line_resp_selects} + + +=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @price_line_resp_selects} + + + diff --git a/app/views/admin/price_line_resp_selects/new.js.erb b/app/views/admin/price_line_resp_selects/new.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/price_line_resp_selects/new.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/price_line_resp_selects/show.html.haml b/app/views/admin/price_line_resp_selects/show.html.haml new file mode 100644 index 0000000..377ef51 --- /dev/null +++ b/app/views/admin/price_line_resp_selects/show.html.haml @@ -0,0 +1,10 @@ +.qi_header + %h1 + + %span + + + +.qi_row + .qi_pannel.qi_plain.padding + =debug @price_line_resp_select \ No newline at end of file diff --git a/app/views/admin/price_line_resp_selects/update.js.erb b/app/views/admin/price_line_resp_selects/update.js.erb new file mode 100644 index 0000000..d834a55 --- /dev/null +++ b/app/views/admin/price_line_resp_selects/update.js.erb @@ -0,0 +1,2 @@ +$('#price_line_resp_select_row_<%= @price_line_resp_select.id %>').replaceWith("<%= escape_javascript(render(@price_line_resp_select))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index a0c1e29..207c0f8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,16 @@ Rails.application.routes.draw do + namespace :admin do + resources :price_line_resp_selects do + member do + + end + collection do + + end + end + end + namespace :admin do resources :p_grades do member do diff --git a/db/migrate/20210907161735_create_price_line_resp_selects.rb b/db/migrate/20210907161735_create_price_line_resp_selects.rb new file mode 100644 index 0000000..bc401da --- /dev/null +++ b/db/migrate/20210907161735_create_price_line_resp_selects.rb @@ -0,0 +1,10 @@ +class CreatePriceLineRespSelects < ActiveRecord::Migration[6.0] + def change + create_table :price_line_resp_selects do |t| + t.integer :price_line_demand_id + t.integer :price_line_resp_id + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 3107c6a..934a8fe 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_09_07_083709) do +ActiveRecord::Schema.define(version: 2021_09_07_161735) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -2403,6 +2403,13 @@ ActiveRecord::Schema.define(version: 2021_09_07_083709) do t.index ["p_customer_id"], name: "index_price_line_blocks_on_p_customer_id" end + create_table "price_line_resp_selects", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| + t.integer "price_line_demand_id" + t.integer "price_line_resp_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + create_table "price_lines", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.boolean "archived" t.integer "price_line_block_id" From 8f120baa3fc7458cfa0f45a9ccef23c73c9c0b62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Tue, 7 Sep 2021 19:10:21 +0200 Subject: [PATCH 005/131] price_line_resp_select relations --- app/models/price_line.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/models/price_line.rb b/app/models/price_line.rb index 1dabff0..0eba34d 100644 --- a/app/models/price_line.rb +++ b/app/models/price_line.rb @@ -3,6 +3,12 @@ class PriceLine < ApplicationRecord belongs_to :p_product belongs_to :p_product_ref belongs_to :p_product_power + has_many :price_line_resp_selects, :foreign_key => :price_line_demand + has_many :price_line_resps, through: :price_line_resp_selects, :source => :price_line_resp + + + #has_many :price_line_demands, through: :price_line_resp_selects + default_scope { order('position ASC') } validates :p_product_ref_id, :presence => true, :if => :p_product_ref_needed? From 4d8e99aef96524d7a61704f91ee856c85ba3f3dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Tue, 7 Sep 2021 19:26:36 +0200 Subject: [PATCH 006/131] wip analyse --- .../admin/price_documents_controller.rb | 2 +- .../analyse_reponses.html.haml | 40 ++++++++++++++++--- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/app/controllers/admin/price_documents_controller.rb b/app/controllers/admin/price_documents_controller.rb index b480168..8d69bb2 100644 --- a/app/controllers/admin/price_documents_controller.rb +++ b/app/controllers/admin/price_documents_controller.rb @@ -279,7 +279,7 @@ class Admin::PriceDocumentsController < ApplicationController @ref_price_lines = @demande.price_line_block.price_lines @ref_price_lines.group(:p_product_ref_id).each do |plr| - @price_document.price_line_block.price_lines << PriceLine.new(:p_product_ref_id => plr.p_product_ref_id, :qte => @ref_price_lines.where(:p_product_ref_id => plr.p_product_ref_id).sum(:qte)) + @price_document.price_line_block.price_lines << PriceLine.new(:price_line_ref_id => plr.id, :p_product_ref_id => plr.p_product_ref_id, :qte => @ref_price_lines.where(:p_product_ref_id => plr.p_product_ref_id).sum(:qte)) end diff --git a/app/views/admin/price_documents/analyse_reponses.html.haml b/app/views/admin/price_documents/analyse_reponses.html.haml index 96050ca..7528f80 100644 --- a/app/views/admin/price_documents/analyse_reponses.html.haml +++ b/app/views/admin/price_documents/analyse_reponses.html.haml @@ -7,7 +7,7 @@ \- = @price_document.list_designaton - +-unmatched_fournisseur = 0 =semantic_form_for [:admin, @price_document], :html => {:class => "qi_price_form"}, :remote => false do |form| =form.semantic_fields_for :price_line_block do |f| - price_line_block = f.object @@ -77,6 +77,13 @@ %th -if resp.p_fournisseur =resp.p_fournisseur.name + -else + -unmatched_fournisseur += 1 + nom renseigné par le fournisseur : + %br + ="(#{resp.public_fournisseur_name})" + %br + =link_to ic('pencil') + " rapprocher le fournisseur", match_p_fournisseur_admin_price_document_path(resp), remote: true %tbody @@ -127,9 +134,10 @@ / Date du px de référence %td.limit / spec - - =form.input :selected_price_line_id, collection: PriceLine.where(:price_line_ref_id => form.object.id).all, as: :radio, :member_label => :id - =debug form.object.id + =#form.object.price_line_resp_ids + =#form.text_field :price_line_demand_id + =#form.input :price_line_resp_id, collection: PriceLine.where(:price_line_demand_id => form.object.id).all, as: :check_boxes, :member_label => :id + =form.input :price_line_resp_ids, collection: PriceLine.where(:price_line_ref_id => form.object.id).all, as: :check_boxes , :member_label => :id - @price_document_responses.each do |resp| -line = resp.price_line_block.price_lines.where(p_product_ref: price_line.p_product_ref).first -cell = [] @@ -162,7 +170,29 @@ =#form.input :selected_price_offer, as: :radio = radio_button_tag "ref_price_selected_#{price_line.p_product_ref.id}", line.id, false, class: "category-selector" = label_tag "ref_price_selected_#{price_line.p_product_ref.id}_#{line.id}", sanitize(cell.join('
')), class: "p-2 m-auto" - =submit_tag 'valider la selection', class: "btn btn-primary" + + - if unmatched_fournisseur == 0 + =submit_tag 'valider la selection', class: "btn btn-primary ml-4" + - else + %button.btn.btn-primary.ml-4{"type" => "button", "data-toggle" => "modal", "data-target" => "#unmatched-fournisseur"} + Valider la selection + .modal.fade#unmatched-fournisseur{"tab-index" => "-1", "role" => "dialog", "aria-labelledby" => "Raprochement Fournisseur", "aria-hidden" => "true"} + .modal-dialog{role: "dialog"} + .modal-content + .modal-header + %h5.modal-title + Rapprochement du fournisseur + %button.close{"data-dismiss" => "modal", "aria-label" => "Close"} + %span{"aria-hidden" => "true"} + × + .modal-body + Il reste des fournisseurs à prapprocher avant de pouvoir valider. + .modal-footer + %button.btn.btn-light{"data-dismiss" => "modal"} + Close + + + From 8be2ad4ce914c552381a026da278d20bd1a75501 Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Tue, 7 Sep 2021 23:00:31 +0200 Subject: [PATCH 007/131] Ajout des checkboxes dans les bonnes colonnes. Voir les commentaires #Nico pour l'explication --- .../analyse_reponses.html.haml | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/app/views/admin/price_documents/analyse_reponses.html.haml b/app/views/admin/price_documents/analyse_reponses.html.haml index 7528f80..32b719d 100644 --- a/app/views/admin/price_documents/analyse_reponses.html.haml +++ b/app/views/admin/price_documents/analyse_reponses.html.haml @@ -88,7 +88,7 @@ %tbody -# price_lines = f.object.price_lines - + -price_lines_child_index = {} -consult_price_lines = @price_document.price_line_block.price_lines =f.semantic_fields_for :price_lines do |form| - price_line = form.object @@ -134,10 +134,19 @@ / Date du px de référence %td.limit / spec - =#form.object.price_line_resp_ids - =#form.text_field :price_line_demand_id - =#form.input :price_line_resp_id, collection: PriceLine.where(:price_line_demand_id => form.object.id).all, as: :check_boxes, :member_label => :id - =form.input :price_line_resp_ids, collection: PriceLine.where(:price_line_ref_id => form.object.id).all, as: :check_boxes , :member_label => :id + + =#form.input :price_line_resp_ids, collection: PriceLine.where(:price_line_ref_id => form.object.id).all, as: :check_boxes , :member_label => :id + + -#NICO : j'ai commenté l'input qu'on a fait ensemble, par contre, pour toute la suite, j'ai en fait fait un copié collé du rendu de cet inpu ou j'ai remis les champs dynamics en correspondance. + + + -#NICO : j'ai créé un hash plus haut, vide, qui va me permettre de faire correspondre à chaque ID de price_line leur index dans le nested form (qui est différent, une itération, de l'ID de l'élement... Là c'est la magie de rails.) + - price_lines_child_index[form.object.id.to_s] = form.options[:child_index] + + + -#Nico : je commence, pour chaque price line, par faire une checkbox vide. J'aurais pu faire un checkbox tag mais par facilité j'ai copé l'HTML dans HTML2HAML et je suis partid du résultat. Les checkboxes sont ensuite dans ta boucle + %input{:autocomplete => "off", :id => "price_document[price_line_block_attributes][price_lines_attributes][#{form.options[:child_index] }]_price_line_resp_ids_none", :name => "price_document[price_line_block_attributes][price_lines_attributes][#{form.options[:child_index] }][price_line_resp_ids][]", :type => "hidden", :value => ""}/ + - @price_document_responses.each do |resp| -line = resp.price_line_block.price_lines.where(p_product_ref: price_line.p_product_ref).first -cell = [] @@ -167,7 +176,16 @@ %td.p-0 = "reponse price_line ID : #{line.id}" - =#form.input :selected_price_offer, as: :radio + = "price line origine : #{line.price_line_ref_id}" #NICO : simple contrôle, je récupère facilement par là l'ID de la price Line concernée. + + -#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 != "" + %br + %label{: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{: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}>/ + =line.id + + = radio_button_tag "ref_price_selected_#{price_line.p_product_ref.id}", line.id, false, class: "category-selector" = label_tag "ref_price_selected_#{price_line.p_product_ref.id}_#{line.id}", sanitize(cell.join('
')), class: "p-2 m-auto" From 0c128507181b39f2ced719b34ebd7053d3dc31bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Wed, 8 Sep 2021 09:48:16 +0200 Subject: [PATCH 008/131] Skip default redirect after matching p_fournisseur --- app/controllers/admin/price_documents_controller.rb | 10 ++++++++++ .../price_documents/_form_p_fournisseur.html.haml | 2 +- .../price_documents/match_p_fournisseur_save.js.erb | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 app/views/admin/price_documents/match_p_fournisseur_save.js.erb diff --git a/app/controllers/admin/price_documents_controller.rb b/app/controllers/admin/price_documents_controller.rb index 8d69bb2..f8cfc68 100644 --- a/app/controllers/admin/price_documents_controller.rb +++ b/app/controllers/admin/price_documents_controller.rb @@ -599,6 +599,16 @@ class Admin::PriceDocumentsController < ApplicationController @price_document = PriceDocument.find(params[:id]) end + def match_p_fournisseur_save + @price_document = PriceDocument.find(params[:id]) + + if @price_document.update_attributes(params.require(:price_document).permit!) + # redirect_back(fallback_location: price_documents_ptath) + else + render action: "edit" + end + end + def analyse_reponses @price_document = PriceDocument.find(params[:id]) @price_document_responses = PriceDocument.where(:doc_ref_id => @price_document.id ) diff --git a/app/views/admin/price_documents/_form_p_fournisseur.html.haml b/app/views/admin/price_documents/_form_p_fournisseur.html.haml index 3514749..a860e68 100644 --- a/app/views/admin/price_documents/_form_p_fournisseur.html.haml +++ b/app/views/admin/price_documents/_form_p_fournisseur.html.haml @@ -1,4 +1,4 @@ -=semantic_form_for [:admin, @price_document], :html => {:class => "qi_price_form"}, :remote => false do |f| +=semantic_form_for [:admin, @price_document], url: match_p_fournisseur_save_admin_price_document_path, :html => {:class => "qi_price_form"}, :remote => true do |f| =diag do =f.object.errors.messages diff --git a/app/views/admin/price_documents/match_p_fournisseur_save.js.erb b/app/views/admin/price_documents/match_p_fournisseur_save.js.erb new file mode 100644 index 0000000..0d5cc58 --- /dev/null +++ b/app/views/admin/price_documents/match_p_fournisseur_save.js.erb @@ -0,0 +1,2 @@ +location.reload(); +close_pane_hover(); From eed90a2d33e917ac6d1d39c56d05d0c000d3fbd3 Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Wed, 8 Sep 2021 10:18:48 +0200 Subject: [PATCH 009/131] =?UTF-8?q?D=C3=A9but=20popup=20produits?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/javascripts/manager.js | 21 ++++++++++++++++++- app/assets/stylesheets/manager.scss | 3 ++- .../admin/p_product_refs_controller.rb | 5 +++++ .../admin/p_customer_sheets/_form.html.haml | 10 ++++----- .../p_product_refs/_p_product_ref.html.haml | 10 +++++++-- app/views/admin/price_lines/_form.html.haml | 11 ++++++---- 6 files changed, 47 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/manager.js b/app/assets/javascripts/manager.js index 10623e4..b6b2393 100644 --- a/app/assets/javascripts/manager.js +++ b/app/assets/javascripts/manager.js @@ -42,7 +42,7 @@ function manager_show(url){ function manager_hide(){ $("#manager_box_place").removeClass("manager_box_place_active"); - + $('#manager_box').html(""); $("body").css("overflow", "auto"); slider_enabled = null; @@ -239,3 +239,22 @@ function select_video_from_manager(input_id){ } +function select_product_from_manager(input_id){ + + + manager_prompt("/admin/p_product_refs.html?manager=true",function(m_return){ + + $('.p_product_ref_id_'+input_id).val(m_return.id); + $('.p_product_ref_name_'+input_id).val(m_return.name); + + }); + +} + +function send_manager_product(product_id, product_name){ + + manager_send_response({id : product_id, name : product_name}); +} + + + diff --git a/app/assets/stylesheets/manager.scss b/app/assets/stylesheets/manager.scss index eb296d2..f03e584 100644 --- a/app/assets/stylesheets/manager.scss +++ b/app/assets/stylesheets/manager.scss @@ -2,7 +2,8 @@ #manager_box_place{ position:fixed; height:0; - width:100%; + left:100px; + right:30px; z-index:1500; top:0px; margin:0px; diff --git a/app/controllers/admin/p_product_refs_controller.rb b/app/controllers/admin/p_product_refs_controller.rb index 5648846..fbf5675 100644 --- a/app/controllers/admin/p_product_refs_controller.rb +++ b/app/controllers/admin/p_product_refs_controller.rb @@ -57,6 +57,11 @@ class Admin::PProductRefsController < ApplicationController } end + + if params[:manager].to_s == "true" + @manager = true + render :layout => false + end end diff --git a/app/views/admin/p_customer_sheets/_form.html.haml b/app/views/admin/p_customer_sheets/_form.html.haml index c8c82b9..14bc8a5 100755 --- a/app/views/admin/p_customer_sheets/_form.html.haml +++ b/app/views/admin/p_customer_sheets/_form.html.haml @@ -17,8 +17,8 @@ - .right.actions - =link_to "Annuler", admin_p_customer_sheets_path(), :class => "btn" - =form.submit "sauvegarder", :class => "btn btn-primary btn-ap-add" - .clear - + .large_actions + .actions + =link_to "Annuler", admin_p_customer_sheets_path(), :class => "btn" + =form.submit "sauvegarder", :class => "btn btn-primary btn-ap-add" + diff --git a/app/views/admin/p_product_refs/_p_product_ref.html.haml b/app/views/admin/p_product_refs/_p_product_ref.html.haml index 33e3f52..ca09295 100644 --- a/app/views/admin/p_product_refs/_p_product_ref.html.haml +++ b/app/views/admin/p_product_refs/_p_product_ref.html.haml @@ -31,8 +31,14 @@ %td.actions =# link_to i(:"trash-o"), [:admin, p_product_ref], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer ce produit ? ' } , :remote => true if !PriceLine.where(:p_product_ref_id => p_product_ref).first =#debug PriceLine.where(:p_product_ref_id => p_product_ref.id).first - = link_to i(:pencil), edit_admin_p_product_path(p_product_ref.p_product), :remote => false - = link_to i(:eye), admin_p_product_ref_path(p_product_ref), :remote => false + + -if @manager + = link_to i(:eye), admin_p_product_ref_path(p_product_ref), :remote => false, :target => "_blank" + = link_to i(:"check"), "#",:onclick => "send_manager_product('"+p_product_ref.id.to_s+"', '"+escape_javascript(p_product_ref.member_label.to_s)+"');return false;" + + -else + = link_to i(:pencil), edit_admin_p_product_path(p_product_ref.p_product), :remote => false + = link_to i(:eye), admin_p_product_ref_path(p_product_ref), :remote => false =render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => p_product_ref} diff --git a/app/views/admin/price_lines/_form.html.haml b/app/views/admin/price_lines/_form.html.haml index ed95396..f16140b 100644 --- a/app/views/admin/price_lines/_form.html.haml +++ b/app/views/admin/price_lines/_form.html.haml @@ -9,12 +9,15 @@ = form.input :ct_title, :label => "Designation personnalisée : " if @avoir %div{:class => ("error has-error" if form.object.errors[:p_product_ref_id].size > 0 )} + + -key = SecureRandom.hex(6) + %label Produit : - %input.p_product_ref_autocomplete_input.form-control{:type => "text", :value => ("#{form.object.p_product_ref.ref} #{form.object.p_product_ref.cc_name}" if form.object.p_product_ref)} + %input.p_product_ref_autocomplete_input.form-control{:type => "text", :value => ("#{form.object.p_product_ref.ref} #{form.object.p_product_ref.cc_name}" if form.object.p_product_ref), :class => "p_product_ref_name_#{key}"} - - = form.hidden_field :p_product_ref_id, :class => "p_product_ref_id" - + + = form.hidden_field :p_product_ref_id, :class => "p_product_ref_id p_product_ref_id_#{key}" + =link_to "selectionner un produit", "#", :onclick => "select_product_from_manager('#{key}');return false;" :javascript $( function() { From fa8ebf207f8cd046275e38215a3a352079ce3253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Wed, 8 Sep 2021 15:11:29 +0200 Subject: [PATCH 010/131] update price_documents_types --- app/controllers/application_controller.rb | 2 +- app/models/price_document.rb | 2 +- app/views/admin/price_documents/_price_document.html.haml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c9fffcc..0d72570 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -168,7 +168,7 @@ class ApplicationController < ActionController::Base end - set_sub_menu :documents, :"p_document_type_reponse_fournisseur", "Réponses fournisseurs", admin_price_documents_path(:price_document_type_id => 2) + set_sub_menu :documents, :"p_document_type_reponse_fournisseur", "Réponses fournisseurs", admin_price_documents_path(:price_document_type_id => 9) diff --git a/app/models/price_document.rb b/app/models/price_document.rb index 07c348c..9b8b83d 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 prix", "Commande achat", "Facture d'achat"] + PURCHASES = ["Demande de prix", "Commande achat", "Facture d'achat"] 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/views/admin/price_documents/_price_document.html.haml b/app/views/admin/price_documents/_price_document.html.haml index 1422646..21b2a88 100644 --- a/app/views/admin/price_documents/_price_document.html.haml +++ b/app/views/admin/price_documents/_price_document.html.haml @@ -22,7 +22,7 @@ -tr[:p_fournisseur] = capture do %td - - if price_document.price_document_type_id == 2 + - if price_document.price_document_type.label == "Réponse fournisseur" -if price_document.p_fournisseur.present? = price_document.p_fournisseur.name - else @@ -135,7 +135,7 @@ -tr[:actions] = capture do %td.actions - -if price_document.price_document_type_id == 1 + -if price_document.price_document_type.label == "Demande de prix" =link_to i("bar-chart"), analyse_reponses_admin_price_document_path(price_document) -if !price_document.imported -if current_admin.has_permission?("payments") From 55c3c371b2a9726687158e4948d51826c9293425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Wed, 8 Sep 2021 15:12:10 +0200 Subject: [PATCH 011/131] WIP final consult --- .../admin/price_documents_controller.rb | 17 +++++++++++++++++ .../price_documents/final_consult.html.haml | 4 ++++ config/routes.rb | 2 ++ 3 files changed, 23 insertions(+) create mode 100644 app/views/admin/price_documents/final_consult.html.haml diff --git a/app/controllers/admin/price_documents_controller.rb b/app/controllers/admin/price_documents_controller.rb index f8cfc68..7cb043d 100644 --- a/app/controllers/admin/price_documents_controller.rb +++ b/app/controllers/admin/price_documents_controller.rb @@ -614,4 +614,21 @@ class Admin::PriceDocumentsController < ApplicationController @price_document_responses = PriceDocument.where(:doc_ref_id => @price_document.id ) end + + def final_consult + @params = params + @demande_prix = PriceDocument.find(params[:id]) + @final_consult = PriceDocument.new(price_document_type_id: 10) + # @final_consult.price_line_block.new(params.require[:price_document][:price_line_block_attributes].permit!) + # @price_document = PriceDocument.new(:p_customer_id => params[:p_customer_id], :p_fournisseur_id => params[:p_fournisseur_id]) + # @price_document.price_document_type = PriceDocumentType.where(:label => "Réponse fournisseur").first + # @price_document.price_line_block = PriceLineBlock.new(:p_customer_id => params[:p_customer_id], :p_fournisseur_id => params[:p_fournisseur_id]) + # @price_document.doc_ref_id = @demande.id + + # @ref_price_lines = @demande.price_line_block.price_lines + + # @ref_price_lines.group(:p_product_ref_id).each do |plr| + # @price_document.price_line_block.price_lines << PriceLine.new(:price_line_ref_id => plr.id, :p_product_ref_id => plr.p_product_ref_id, :qte => @ref_price_lines.where(:p_product_ref_id => plr.p_product_ref_id).sum(:qte)) + # end + end end diff --git a/app/views/admin/price_documents/final_consult.html.haml b/app/views/admin/price_documents/final_consult.html.haml new file mode 100644 index 0000000..cb99cd5 --- /dev/null +++ b/app/views/admin/price_documents/final_consult.html.haml @@ -0,0 +1,4 @@ +%h1 Hello +=debug @final_consult +%h1 Params +=debug @params diff --git a/config/routes.rb b/config/routes.rb index 207c0f8..ff939f3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -627,7 +627,9 @@ Rails.application.routes.draw do get :consult_edit put :consult_update get :match_p_fournisseur + patch :match_p_fournisseur_save get :analyse_reponses + post :final_consult end collection do get :search_to_affect From 7f2208576d95e11d9c0d051c3a8222a9fafcf7d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Wed, 8 Sep 2021 15:12:32 +0200 Subject: [PATCH 012/131] Update analyse --- .../analyse_reponses.html.haml | 59 +++++++++++++------ 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/app/views/admin/price_documents/analyse_reponses.html.haml b/app/views/admin/price_documents/analyse_reponses.html.haml index 32b719d..35139c9 100644 --- a/app/views/admin/price_documents/analyse_reponses.html.haml +++ b/app/views/admin/price_documents/analyse_reponses.html.haml @@ -8,7 +8,7 @@ = @price_document.list_designaton -unmatched_fournisseur = 0 -=semantic_form_for [:admin, @price_document], :html => {:class => "qi_price_form"}, :remote => false do |form| +=semantic_form_for [:admin, @price_document],url: final_consult_admin_price_document_path, method: :post, :html => {:class => "qi_price_form"}, :remote => false do |form| =form.semantic_fields_for :price_line_block do |f| - price_line_block = f.object .qi_pannel.padding.new_table_container @@ -26,9 +26,23 @@ Consultation %th{colspan: nb_resp} Fournisseurs - .btn.btn-light.ml-4#reset-radio + .btn.btn-light.mx-4#reset-radio reset - + .legend.d-flex + légende : + .inlie-block.d-flex.flex-wrap.justify-content-end + .mx-2.red + = ic("diamond") + " Spot detecté !" + .mx-2.green + = ic("money") + " Meilleur prix" + .mx-2.red + = ic(:times) + " Alerte marge basse" + .mx-2.green + = ic(:check) + " Marge ok" + .mx-2.orange + = ic(:warning) + " Alerte Qté" + .mx-2.info + = ic('info-circle') + " Commentaire fournisseur" %tr %th Qté à @@ -75,6 +89,7 @@ -@price_document_responses.each do |resp| %th + =resp.id -if resp.p_fournisseur =resp.p_fournisseur.name -else @@ -94,7 +109,6 @@ - price_line = form.object -#price_lines = @price_document.price_line_block.price_lines -#price_lines.each do |price_line| - %tr %td =# ATTENTION ! On a plus accès direct aux commandes qui on engendré cette demande de prix. donc plus accès aux délais différent entre les différentes commades pour une ref donée @@ -142,19 +156,22 @@ -#NICO : j'ai créé un hash plus haut, vide, qui va me permettre de faire correspondre à chaque ID de price_line leur index dans le nested form (qui est différent, une itération, de l'ID de l'élement... Là c'est la magie de rails.) - price_lines_child_index[form.object.id.to_s] = form.options[:child_index] - - + -best_price = PriceLine.where(price_line_ref_id: price_line.id).where("ct_u_price_ht > 0").order(:ct_u_price_ht).ids -#Nico : je commence, pour chaque price line, par faire une checkbox vide. J'aurais pu faire un checkbox tag mais par facilité j'ai copé l'HTML dans HTML2HAML et je suis partid du résultat. Les checkboxes sont ensuite dans ta boucle %input{:autocomplete => "off", :id => "price_document[price_line_block_attributes][price_lines_attributes][#{form.options[:child_index] }]_price_line_resp_ids_none", :name => "price_document[price_line_block_attributes][price_lines_attributes][#{form.options[:child_index] }][price_line_resp_ids][]", :type => "hidden", :value => ""}/ + =#{}"price doc id : #{@price_document_responses.ids}" + - @price_document_responses.each do |resp| -line = resp.price_line_block.price_lines.where(p_product_ref: price_line.p_product_ref).first -cell = [] - if line.qte_available.to_i > 0 - -if line.qte_available >= price_line.qte.to_i + - if line.id == best_price[0] + -cell << "#{ic(:money)} Meilleur prix" + - if line.qte_available >= price_line.qte.to_i - cell << "Qté dispo : #{line.qte_available.to_i}" - -else + - else - cell << "#{ic(:warning, class: "orange")} Qté dispo : #{line.qte_available.to_i} (#{line.qte_available.to_i - price_line.qte.to_i})" - cell << "PA: #{line.ct_u_price_ht} €" - # mp = calcul de la marge prévisionelle TODO @@ -174,20 +191,19 @@ - display_comment = line.comment - cell << "#{ic('info-circle')} #{display_comment}#{line.comment}" - %td.p-0 - = "reponse price_line ID : #{line.id}" - = "price line origine : #{line.price_line_ref_id}" #NICO : simple contrôle, je récupère facilement par là l'ID de la price Line concernée. + %td.p-0{class: ("best-price" if line.id == best_price[0])} + =# "reponse price_line ID : #{line.id}" + =# "price line origine : #{line.price_line_ref_id}" #NICO : simple contrôle, je récupère facilement par là l'ID de la price Line concernée. -#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 != "" - %br - %label{: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{: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}>/ - =line.id + %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}"} + =sanitize(cell.join('
')) - = radio_button_tag "ref_price_selected_#{price_line.p_product_ref.id}", line.id, false, class: "category-selector" - = label_tag "ref_price_selected_#{price_line.p_product_ref.id}_#{line.id}", sanitize(cell.join('
')), class: "p-2 m-auto" + =# radio_button_tag "ref_price_selected_#{price_line.p_product_ref.id}", line.id, false, class: "category-selector" + =# label_tag "ref_price_selected_#{price_line.p_product_ref.id}_#{line.id}", sanitize(cell.join('
')), class: "p-2 m-auto" - if unmatched_fournisseur == 0 =submit_tag 'valider la selection', class: "btn btn-primary ml-4" @@ -235,6 +251,12 @@ .category-selector:checked + label { background-color: #b4f99e !important; + border-radius: 1em; + border: green solid 0.2em; + } + + .best-price{ + background-color: #f8fdab !important; } .limit { @@ -250,6 +272,7 @@ .orange { color: orange; } + .info { color: #009bbf; position: relative; @@ -305,5 +328,5 @@ :javascript $( "#reset-radio" ).click(function(event){ - $( ":radio" ).prop('checked',false); + $('input:checkbox').prop('checked',false); }) From 3bf1514bcc62ddb481eb094a2567e5a910333d4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Wed, 8 Sep 2021 16:20:58 +0200 Subject: [PATCH 013/131] Replace price_line form --- app/views/admin/price_lines/_form.html.haml | 225 ++++++++---------- .../admin/price_lines/_form_old.html.haml | 133 +++++++++++ 2 files changed, 236 insertions(+), 122 deletions(-) create mode 100644 app/views/admin/price_lines/_form_old.html.haml diff --git a/app/views/admin/price_lines/_form.html.haml b/app/views/admin/price_lines/_form.html.haml index 7ad0661..42c6235 100644 --- a/app/views/admin/price_lines/_form.html.haml +++ b/app/views/admin/price_lines/_form.html.haml @@ -1,134 +1,115 @@ -.qi_pannel.qi_plain.padding.price_line_form.col-3.field{:style =>"border-left:4px solid gray;margin-bottom:10px;padding-left:5px;"} - %table{:style => "width:100%;"} +.qi_pannel.qi_plain.padding.price_line_form.col-12.field{:style =>"border-left:4px solid gray;margin-bottom:10px;padding-left:5px;"} + = form.input :ct_title, :label => "Designation personnalisée : " if @avoir + %table %tr - %td{:style => "width:30px;"} - .take + %td{:class => ("error has-error" if form.object.errors[:p_product_ref_id].size > 0 )} + .take.mx-1 =ic :arrows %td - - = form.input :ct_title, :label => "Designation personnalisée : " if @avoir - %div{:class => ("error has-error" if form.object.errors[:p_product_ref_id].size > 0 )} - %label Produit : - %input.p_product_ref_autocomplete_input.form-control{:type => "text", tabindex: 1, autofocus: true, :value => ("#{form.object.p_product_ref.ref} #{form.object.p_product_ref.cc_name}" if form.object.p_product_ref)} - - - = form.hidden_field :p_product_ref_id, :class => "p_product_ref_id" - - :javascript - $('.p_product_ref_autocomplete_input').focus() - $( function() { - - $('.p_product_ref_autocomplete_input').autocomplete({ - source: function( request, response ) { - $.ajax( { - url: "/admin/p_product_refs/autocomplete.json", - dataType: "json", - data: { - search: request.term, - p_customer_id: $(".p_customer_id").val() - }, - success: function(data){ - - arr = jQuery.map( data, function( item ) { - return { - label: item.member_label, - value: item.member_label, - id: item.id - } - }); - - response(arr) - - } - - } ); - }, - minLength: 2, - select: function( event, ui ) { - - $(this).next(".p_product_ref_id").val(ui.item.id) - - form = $(this).closest(".price_line_form") - - - - $.ajax( { - url: "/admin/p_product_refs/"+ui.item.id+"/get_infos.json", - dataType: "json", - data: { - type: "price", - qte: form.find(".input_price_line_qte").val(), - p_customer_id: $(".p_customer_id").val() - }, - success: function (data) { - form.find(".input_price_line_price_u_ht").val(data.price); - form.find(".input_price_line_tva_account_id").val(data.tva_account_id); - form.find(".input_price_line_tva_account_value").val(data.tva_account_value); - form.find(".input_price_line_weight_u").val(data.weight); - - - - } - - - } ); - - - - - //return false - } - }); - - - - } ); - - - %table.top_td{:style => "width:100%;margin-top:5px;"} - %tr - %td{:style => "width:30px"} - %span.destroy=link_to_remove_fields ic(:"trash-o"), form + %label.mx-3 Produit : %td + %input.p_product_ref_autocomplete_input.form-control{:type => "text", tabindex: 1, autofocus: true, :value => ("#{form.object.p_product_ref.ref} #{form.object.p_product_ref.cc_name}" if form.object.p_product_ref)} -form.object.forced_price = true if form.object.ct_u_price_ht - + -if form.object.forced_price and form.object.p_product_ref - =qi_js_field(form, :price_line, :price_u_ht, :label => "Prix U HT :", :value => form.object.th_price_u_ht) + %td + .mx-4 + =qi_js_field(form, :price_line, :price_u_ht, :label => "Prix U HT :", :value => form.object.th_price_u_ht) -else - =qi_js_field(form, :price_line, :price_u_ht, :label => "Prix U HT :") - - %div{:style => ("display:none;" if !current_admin or !current_admin.has_permission?("customer-sheets-personalised-price"))} + %td + .mx-4 + =qi_js_field(form, :price_line, :price_u_ht, :label => "Prix U HT :") + %td + .form-inline.mx-4{:style => ("display:none;" if !current_admin or !current_admin.has_permission?("customer-sheets-personalised-price"))} = form.input :forced_price, :label => "Prix personnalisé ?", :as => :boolean, :input_html => {:class => "input_price_line_forced_price"} - .forced_price_wrapper{:style => ("display:none;" if !form.object.forced_price)}= form.input :ct_u_price_ht, :label => false, :input_html => {:class => "input_price_line_ct_u_price_ht"} - - %td - = form.input :qte, :label => "qte :", :input_html => {:class => "input_price_line_qte", tabindex: 1} + .forced_price_wrapper.mx-4{:style => ("display:none;" if !form.object.forced_price)}= form.input :ct_u_price_ht, :label => false, :input_html => {:class => "input_price_line_ct_u_price_ht"} + %td + .mx-4.form-inline + = form.input :qte, :label => "qte :", :input_html => {:class => "input_price_line_qte form-control mx-2", tabindex: 1} - - + = form.hidden_field :p_product_ref_id, :class => "p_product_ref_id" %td - =#qi_js_field(form, :price_line, :tva_account_id, :label => "Compte TVA :") - - -if @avoir - - -if !form.object.ct_tva_account_id - -form.object.ct_tva_account_id = form.object.tva_account_id - = form.input :ct_tva_account_id, :collection => TvaRate.where(:accounting_zone_id => (@p_customer ? @p_customer.accounting_zone_id : nil)).all, :as => :select, :member_label => :member_label, :include_blank => false, :label => "TVA personnalisée", :input_html => { :class => "input_price_line_tva_account_id"} - - -else - %label Taux de TVA : - %br - =select_tag :tva_account_id, options_from_collection_for_select(TvaRate.where(:accounting_zone_id => (@p_customer ? @p_customer.accounting_zone_id : nil)).all, "id", "member_label", form.object.tva_account_id), :class => "input_price_line_tva_account_id custom-select" #, :disabled => true - - - - =qi_js_field(form, :price_line, :tva_account_value, :hidden => true) - - / = form.input :comment, :label => "Commentaire" - - - + .form-inline + %label.mx-4 Taux de TVA : + =select_tag :tva_account_id, options_from_collection_for_select(TvaRate.where(:accounting_zone_id => (@p_customer ? @p_customer.accounting_zone_id : nil)).all, "id", "member_label", form.object.tva_account_id), :class => "input_price_line_tva_account_id form-control custom-select" #, :disabled => true + %td + .mx-4 + %span.destroy=link_to_remove_fields ic(:"trash-o"), form - = form.hidden_field :position, :class => "price_line_position_input" - + + + =qi_js_field(form, :price_line, :tva_account_value, :hidden => true) + + = form.hidden_field :position, :class => "price_line_position_input" + + + :javascript + $('.p_product_ref_autocomplete_input').focus() + $( function() { + + $('.p_product_ref_autocomplete_input').autocomplete({ + source: function( request, response ) { + $.ajax( { + url: "/admin/p_product_refs/autocomplete.json", + dataType: "json", + data: { + search: request.term, + p_customer_id: $(".p_customer_id").val() + }, + success: function(data){ + + arr = jQuery.map( data, function( item ) { + return { + label: item.member_label, + value: item.member_label, + id: item.id + } + }); + + response(arr) + + } + + } ); + }, + minLength: 2, + select: function( event, ui ) { + + $(this).next(".p_product_ref_id").val(ui.item.id) + + form = $(this).closest(".price_line_form") + + + + $.ajax( { + url: "/admin/p_product_refs/"+ui.item.id+"/get_infos.json", + dataType: "json", + data: { + type: "price", + qte: form.find(".input_price_line_qte").val(), + p_customer_id: $(".p_customer_id").val() + }, + success: function (data) { + form.find(".input_price_line_price_u_ht").val(data.price); + form.find(".input_price_line_tva_account_id").val(data.tva_account_id); + form.find(".input_price_line_tva_account_value").val(data.tva_account_value); + form.find(".input_price_line_weight_u").val(data.weight); + + + + } + + + } ); + + + + + //return false + } + }); + + + + } ); diff --git a/app/views/admin/price_lines/_form_old.html.haml b/app/views/admin/price_lines/_form_old.html.haml new file mode 100644 index 0000000..60e70c1 --- /dev/null +++ b/app/views/admin/price_lines/_form_old.html.haml @@ -0,0 +1,133 @@ + +.qi_pannel.qi_plain.padding.price_line_form.col-12.field{:style =>"border-left:4px solid gray;margin-bottom:10px;padding-left:5px;"} + %table{:style => "width:100%;"} + %tr + %td{:style => "width:30px;"} + .take + =ic :arrows + %td + + = form.input :ct_title, :label => "Designation personnalisée : " if @avoir + %div{:class => ("error has-error" if form.object.errors[:p_product_ref_id].size > 0 )} + %label Produit : + %td + %input.p_product_ref_autocomplete_input.form-control{:type => "text", tabindex: 1, autofocus: true, :value => ("#{form.object.p_product_ref.ref} #{form.object.p_product_ref.cc_name}" if form.object.p_product_ref)} + + + = form.hidden_field :p_product_ref_id, :class => "p_product_ref_id" + + :javascript + $('.p_product_ref_autocomplete_input').focus() + $( function() { + + $('.p_product_ref_autocomplete_input').autocomplete({ + source: function( request, response ) { + $.ajax( { + url: "/admin/p_product_refs/autocomplete.json", + dataType: "json", + data: { + search: request.term, + p_customer_id: $(".p_customer_id").val() + }, + success: function(data){ + + arr = jQuery.map( data, function( item ) { + return { + label: item.member_label, + value: item.member_label, + id: item.id + } + }); + + response(arr) + + } + + } ); + }, + minLength: 2, + select: function( event, ui ) { + + $(this).next(".p_product_ref_id").val(ui.item.id) + + form = $(this).closest(".price_line_form") + + + + $.ajax( { + url: "/admin/p_product_refs/"+ui.item.id+"/get_infos.json", + dataType: "json", + data: { + type: "price", + qte: form.find(".input_price_line_qte").val(), + p_customer_id: $(".p_customer_id").val() + }, + success: function (data) { + form.find(".input_price_line_price_u_ht").val(data.price); + form.find(".input_price_line_tva_account_id").val(data.tva_account_id); + form.find(".input_price_line_tva_account_value").val(data.tva_account_value); + form.find(".input_price_line_weight_u").val(data.weight); + + + + } + + + } ); + + + + + //return false + } + }); + + + + } ); + + + %td{:style => "width:30px"} + %span.destroy=link_to_remove_fields ic(:"trash-o"), form + %td + -form.object.forced_price = true if form.object.ct_u_price_ht + + -if form.object.forced_price and form.object.p_product_ref + =qi_js_field(form, :price_line, :price_u_ht, :label => "Prix U HT :", :value => form.object.th_price_u_ht) + -else + =qi_js_field(form, :price_line, :price_u_ht, :label => "Prix U HT :") + + %div{:style => ("display:none;" if !current_admin or !current_admin.has_permission?("customer-sheets-personalised-price"))} + = form.input :forced_price, :label => "Prix personnalisé ?", :as => :boolean, :input_html => {:class => "input_price_line_forced_price"} + .forced_price_wrapper{:style => ("display:none;" if !form.object.forced_price)}= form.input :ct_u_price_ht, :label => false, :input_html => {:class => "input_price_line_ct_u_price_ht"} + + %td + = form.input :qte, :label => "qte :", :input_html => {:class => "input_price_line_qte", tabindex: 1} + + + + %td + =#qi_js_field(form, :price_line, :tva_account_id, :label => "Compte TVA :") + + -if @avoir + + -if !form.object.ct_tva_account_id + -form.object.ct_tva_account_id = form.object.tva_account_id + = form.input :ct_tva_account_id, :collection => TvaRate.where(:accounting_zone_id => (@p_customer ? @p_customer.accounting_zone_id : nil)).all, :as => :select, :member_label => :member_label, :include_blank => false, :label => "TVA personnalisée", :input_html => { :class => "input_price_line_tva_account_id"} + + -else + %label Taux de TVA : + %br + =select_tag :tva_account_id, options_from_collection_for_select(TvaRate.where(:accounting_zone_id => (@p_customer ? @p_customer.accounting_zone_id : nil)).all, "id", "member_label", form.object.tva_account_id), :class => "input_price_line_tva_account_id custom-select" #, :disabled => true + + + + =qi_js_field(form, :price_line, :tva_account_value, :hidden => true) + + / = form.input :comment, :label => "Commentaire" + + + + + = form.hidden_field :position, :class => "price_line_position_input" + From 455dc38ad8885e8a2b261c56d1b90fe28333c917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Wed, 8 Sep 2021 19:40:11 +0200 Subject: [PATCH 014/131] WIP Final consult --- .../admin/price_documents_controller.rb | 33 ++++++++++++++++--- .../analyse_reponses.html.haml | 2 +- .../price_documents/consult_index.html.haml | 2 ++ .../price_documents/final_consult.html.haml | 4 --- config/routes.rb | 1 + 5 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 app/views/admin/price_documents/consult_index.html.haml delete mode 100644 app/views/admin/price_documents/final_consult.html.haml diff --git a/app/controllers/admin/price_documents_controller.rb b/app/controllers/admin/price_documents_controller.rb index 7cb043d..b2458c6 100644 --- a/app/controllers/admin/price_documents_controller.rb +++ b/app/controllers/admin/price_documents_controller.rb @@ -615,11 +615,26 @@ class Admin::PriceDocumentsController < ApplicationController end - def final_consult - @params = params - @demande_prix = PriceDocument.find(params[:id]) - @final_consult = PriceDocument.new(price_document_type_id: 10) - # @final_consult.price_line_block.new(params.require[:price_document][:price_line_block_attributes].permit!) + 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_document_demand = PriceDocument.find(params[:id]) + @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]) + + PriceDocument.new() + @result << pl_demand + render :consult_index + + # @price_document = PriceDocument.new(:p_customer_id => params[:p_customer_id], :p_fournisseur_id => params[:p_fournisseur_id]) # @price_document.price_document_type = PriceDocumentType.where(:label => "Réponse fournisseur").first # @price_document.price_line_block = PriceLineBlock.new(:p_customer_id => params[:p_customer_id], :p_fournisseur_id => params[:p_fournisseur_id]) @@ -631,4 +646,12 @@ class Admin::PriceDocumentsController < ApplicationController # @price_document.price_line_block.price_lines << PriceLine.new(:price_line_ref_id => plr.id, :p_product_ref_id => plr.p_product_ref_id, :qte => @ref_price_lines.where(:p_product_ref_id => plr.p_product_ref_id).sum(:qte)) # end end + + def final_consult + @price_document = PriceDocument.find(params[:id]) + if @price_document.update_attributes(params.require(:price_document).permit!) + else + render :edit + end + end end diff --git a/app/views/admin/price_documents/analyse_reponses.html.haml b/app/views/admin/price_documents/analyse_reponses.html.haml index 35139c9..2e027e3 100644 --- a/app/views/admin/price_documents/analyse_reponses.html.haml +++ b/app/views/admin/price_documents/analyse_reponses.html.haml @@ -224,7 +224,7 @@ .modal-footer %button.btn.btn-light{"data-dismiss" => "modal"} Close - +=link_to "Generer les consultations", generate_final_consult_admin_price_document_path, class: "btn btn-primary ml-4 mt-4" diff --git a/app/views/admin/price_documents/consult_index.html.haml b/app/views/admin/price_documents/consult_index.html.haml new file mode 100644 index 0000000..4ffa515 --- /dev/null +++ b/app/views/admin/price_documents/consult_index.html.haml @@ -0,0 +1,2 @@ +%h1 Hello +=debug @result diff --git a/app/views/admin/price_documents/final_consult.html.haml b/app/views/admin/price_documents/final_consult.html.haml deleted file mode 100644 index cb99cd5..0000000 --- a/app/views/admin/price_documents/final_consult.html.haml +++ /dev/null @@ -1,4 +0,0 @@ -%h1 Hello -=debug @final_consult -%h1 Params -=debug @params diff --git a/config/routes.rb b/config/routes.rb index ff939f3..dbbb448 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -630,6 +630,7 @@ Rails.application.routes.draw do patch :match_p_fournisseur_save get :analyse_reponses post :final_consult + get :generate_final_consult end collection do get :search_to_affect From 26e36e8c3814e0f8d952df26f92dc291310243c8 Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Wed, 8 Sep 2021 22:23:06 +0200 Subject: [PATCH 015/131] Suite consultation fournisseurs --- .../admin/price_documents_controller.rb | 55 ++++++-- app/models/price_document.rb | 2 +- app/models/price_line.rb | 2 + app/models/price_line_block.rb | 2 +- .../price_documents/_price_document.html.haml | 17 ++- .../analyse_reponses.html.haml | 4 +- .../admin/price_documents/show.html.haml | 131 ++++++++++-------- 7 files changed, 138 insertions(+), 75 deletions(-) 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) From 9abd0b87cf101eb02e3ddb1cc5f36afd734432ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 9 Sep 2021 12:51:15 +0200 Subject: [PATCH 016/131] remove final consult --- .../admin/price_documents_controller.rb | 64 +++++-------------- .../analyse_reponses.html.haml | 2 +- .../price_documents/consult_index.html.haml | 2 - config/routes.rb | 2 +- 4 files changed, 17 insertions(+), 53 deletions(-) delete mode 100644 app/views/admin/price_documents/consult_index.html.haml diff --git a/app/controllers/admin/price_documents_controller.rb b/app/controllers/admin/price_documents_controller.rb index 542942d..6fa1ad2 100644 --- a/app/controllers/admin/price_documents_controller.rb +++ b/app/controllers/admin/price_documents_controller.rb @@ -612,35 +612,32 @@ 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_type_id => PriceDocumentType.find_by_label("Réponse fournisseur").id ) - end + def analyse_reponses_save + @price_document = PriceDocument.find(params[:id]) + if @price_document.update_attributes(params.require(:price_document).permit!) + redirect_to :analyse_reponses_admin_price_document + else + render :edit + end + 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 = {} @price_document_demand = PriceDocument.find(params[:id]) - #@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_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]) @@ -648,43 +645,12 @@ class Admin::PriceDocumentsController < ApplicationController 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 - - #end - - - render :consult_index - - - # @price_document = PriceDocument.new(:p_customer_id => params[:p_customer_id], :p_fournisseur_id => params[:p_fournisseur_id]) - # @price_document.price_document_type = PriceDocumentType.where(:label => "Réponse fournisseur").first - # @price_document.price_line_block = PriceLineBlock.new(:p_customer_id => params[:p_customer_id], :p_fournisseur_id => params[:p_fournisseur_id]) - # @price_document.doc_ref_id = @demande.id - - # @ref_price_lines = @demande.price_line_block.price_lines - - # @ref_price_lines.group(:p_product_ref_id).each do |plr| - # @price_document.price_line_block.price_lines << PriceLine.new(:price_line_ref_id => plr.id, :p_product_ref_id => plr.p_product_ref_id, :qte => @ref_price_lines.where(:p_product_ref_id => plr.p_product_ref_id).sum(:qte)) - # end - end - - def final_consult - @price_document = PriceDocument.find(params[:id]) - if @price_document.update_attributes(params.require(:price_document).permit!) - else - render :edit - end + @final_consult = PriceDocument.where(price_document_type: PriceDocumentType.find_by_label("Consultation fournisseur")).last + redirect_to :analyse_reponses_admin_price_document end end diff --git a/app/views/admin/price_documents/analyse_reponses.html.haml b/app/views/admin/price_documents/analyse_reponses.html.haml index 67ae51e..f0adeb4 100644 --- a/app/views/admin/price_documents/analyse_reponses.html.haml +++ b/app/views/admin/price_documents/analyse_reponses.html.haml @@ -8,7 +8,7 @@ = @price_document.list_designaton -unmatched_fournisseur = 0 -=semantic_form_for [:admin, @price_document],url: final_consult_admin_price_document_path, method: :post, :html => {:class => "qi_price_form"}, :remote => false do |form| +=semantic_form_for [:admin, @price_document],url: analyse_reponses_save_admin_price_document_path, method: :post, :html => {:class => "qi_price_form"}, :remote => false do |form| =form.semantic_fields_for :price_line_block do |f| - price_line_block = f.object .qi_pannel.padding.new_table_container diff --git a/app/views/admin/price_documents/consult_index.html.haml b/app/views/admin/price_documents/consult_index.html.haml deleted file mode 100644 index 4ffa515..0000000 --- a/app/views/admin/price_documents/consult_index.html.haml +++ /dev/null @@ -1,2 +0,0 @@ -%h1 Hello -=debug @result diff --git a/config/routes.rb b/config/routes.rb index dbbb448..83c02a0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -629,7 +629,7 @@ Rails.application.routes.draw do get :match_p_fournisseur patch :match_p_fournisseur_save get :analyse_reponses - post :final_consult + post :analyse_reponses_save get :generate_final_consult end collection do From aca25bb1cb8547f621906c04ba60e1c4d71fecfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 9 Sep 2021 12:52:14 +0200 Subject: [PATCH 017/131] bugfix doc type name --- app/controllers/application_controller.rb | 2 +- app/views/admin/price_documents/_price_document.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0d72570..0e10c2f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -168,7 +168,7 @@ class ApplicationController < ActionController::Base end - set_sub_menu :documents, :"p_document_type_reponse_fournisseur", "Réponses fournisseurs", admin_price_documents_path(:price_document_type_id => 9) + # set_sub_menu :documents, :"p_document_type_reponse_fournisseur", "Réponses fournisseurs", admin_price_documents_path(:price_document_type_id => PriceDocumentType.find_by(label: "Réponse fournisseur").id) diff --git a/app/views/admin/price_documents/_price_document.html.haml b/app/views/admin/price_documents/_price_document.html.haml index 29b43ac..68fe2c3 100644 --- a/app/views/admin/price_documents/_price_document.html.haml +++ b/app/views/admin/price_documents/_price_document.html.haml @@ -144,7 +144,7 @@ -tr[:actions] = capture do %td.actions - -if price_document.price_document_type.label == "Demande de prix" + -if price_document.price_document_type.label == "Demande prix" =link_to i("bar-chart"), analyse_reponses_admin_price_document_path(price_document) -if !price_document.imported -if current_admin.has_permission?("payments") From 6771c8050fb6f8d5f64a0943f181504484ab1f49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 9 Sep 2021 12:54:08 +0200 Subject: [PATCH 018/131] Remove jaune pisse --- .../analyse_reponses.html.haml | 50 +++++++++++++++---- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/app/views/admin/price_documents/analyse_reponses.html.haml b/app/views/admin/price_documents/analyse_reponses.html.haml index f0adeb4..1a9df9d 100644 --- a/app/views/admin/price_documents/analyse_reponses.html.haml +++ b/app/views/admin/price_documents/analyse_reponses.html.haml @@ -197,12 +197,12 @@ -#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-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}"} + %input.seletable_price{: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}"} =sanitize(cell.join('
')) - =# radio_button_tag "ref_price_selected_#{price_line.p_product_ref.id}", line.id, false, class: "category-selector" + =# radio_button_tag "ref_price_selected_#{price_line.p_product_ref.id}", line.id, false, class: "seletable_price" =# label_tag "ref_price_selected_#{price_line.p_product_ref.id}_#{line.id}", sanitize(cell.join('
')), class: "p-2 m-auto" - if unmatched_fournisseur == 0 @@ -234,29 +234,61 @@ + :scss - .category-selector { + .seletable_price { position: absolute; transform: scale(0); } - .category-selector + label { + .seletable_price + label { display: block; min-height: 105px; cursor: pointer; box-sizing: border-box; width: 100%; text-align: left; + + &:hover{ + background:linear-gradient(to top, #efefef 5%, #fdfdfd 100%); + background-color:#5cb811; + } + &:active{ + position:relative; + top:1px; + } } - .category-selector:checked + label { - background-color: #b4f99e !important; + .seletable_priceOLD:checked + label { + background-color: green !important; border-radius: 1em; - border: green solid 0.2em; + border: darkgreen solid 0.2em; + mix-blend-mode: difference; + } + .seletable_price:checked + label{ + box-shadow:inset 0px 1px 0px 0px #caefab; + background:linear-gradient(to bottom, #77d42a 5%, #5cb811 100%); + background-color:#77d42a; + border-radius:6px; + border:1px solid #268a16; + display:inline-block; + cursor:pointer; + color:#306108; + font-family:Arial; + font-size:15px; + font-weight:bold; + padding:6px 24px; + text-decoration:none; + text-shadow:0px 1px 0px #aade7c; + + &:hover{ + background:linear-gradient(to bottom, #5cb811 5%, #77d42a 100%); + background-color:#5cb811; + } } .best-price{ - background-color: #f8fdab !important; + background-color: #b4f99e !important; } .limit { From de98227be7668e33a8a169b82cfc8eb148b7340c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 9 Sep 2021 12:54:31 +0200 Subject: [PATCH 019/131] add button to consult --- .../price_documents/analyse_reponses.html.haml | 1 + app/views/admin/price_documents/show.html.haml | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/views/admin/price_documents/analyse_reponses.html.haml b/app/views/admin/price_documents/analyse_reponses.html.haml index 1a9df9d..f4c2572 100644 --- a/app/views/admin/price_documents/analyse_reponses.html.haml +++ b/app/views/admin/price_documents/analyse_reponses.html.haml @@ -226,6 +226,7 @@ Close =link_to "Generer les consultations", generate_final_consult_admin_price_document_path, class: "btn btn-primary ml-4 mt-4" +=link_to "Acceder aux consultations", admin_price_document_path(@price_document, anchor: "consult"), class: "btn btn-primary ml-4 mt-4" diff --git a/app/views/admin/price_documents/show.html.haml b/app/views/admin/price_documents/show.html.haml index 2ce92e1..98256c1 100644 --- a/app/views/admin/price_documents/show.html.haml +++ b/app/views/admin/price_documents/show.html.haml @@ -342,7 +342,7 @@ %h3 Consultations fournisseur - #bills + #consult -params[:search][:per_page] = params[:search][:per_page] || 5000 -per_page = params[:search][:per_page] -page = (params[:page] and params[:page] != "") ? params[:page] : 1 @@ -360,4 +360,16 @@ .clear =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @price_documents, :key => "reponses-prix-show"} - + -if @price_documents.empty? + .qi_pannel.qi_plain.padding + Pas de consultation générée. + %br + Vous devez d'abord Selectionner les prix sur le page d'analyse : + =link_to ic("bar-chart")+" analyse des réponses", analyse_reponses_admin_price_document_path(@price_document), class: "btn btn-primary" + puis Generer les consultations + -@price_documents.each do |price_document_consult| + %h4= price_document_consult.p_fournisseur.name + =semantic_form_for [:admin, price_document_consult], :html => {:class => "qi_price_form"}, :remote => false do |form| + =form.semantic_fields_for :price_line_block do |f| + =f.semantic_fields_for :price_lines do |form| + =render partial: "admin/price_lines/form", locals: {form: form} From de726629982a669af89f48518468be047172afa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 9 Sep 2021 13:05:31 +0200 Subject: [PATCH 020/131] inlie Qte --- app/views/admin/price_lines/_form.html.haml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/views/admin/price_lines/_form.html.haml b/app/views/admin/price_lines/_form.html.haml index 42c6235..9eb6281 100644 --- a/app/views/admin/price_lines/_form.html.haml +++ b/app/views/admin/price_lines/_form.html.haml @@ -15,11 +15,13 @@ -if form.object.forced_price and form.object.p_product_ref %td .mx-4 - =qi_js_field(form, :price_line, :price_u_ht, :label => "Prix U HT :", :value => form.object.th_price_u_ht) + .form-inline + =qi_js_field(form, :price_line, :price_u_ht, :label => "Prix U HT :", :value => form.object.th_price_u_ht) -else %td - .mx-4 - =qi_js_field(form, :price_line, :price_u_ht, :label => "Prix U HT :") + .mx-3 + .form-inline + =qi_js_field(form, :price_line, :price_u_ht, :label => "Prix U HT :") %td .form-inline.mx-4{:style => ("display:none;" if !current_admin or !current_admin.has_permission?("customer-sheets-personalised-price"))} = form.input :forced_price, :label => "Prix personnalisé ?", :as => :boolean, :input_html => {:class => "input_price_line_forced_price"} @@ -34,7 +36,7 @@ %label.mx-4 Taux de TVA : =select_tag :tva_account_id, options_from_collection_for_select(TvaRate.where(:accounting_zone_id => (@p_customer ? @p_customer.accounting_zone_id : nil)).all, "id", "member_label", form.object.tva_account_id), :class => "input_price_line_tva_account_id form-control custom-select" #, :disabled => true %td - .mx-4 + .ml-4 %span.destroy=link_to_remove_fields ic(:"trash-o"), form From 00e390f50b5ed37b5ac3e50741cdfb6aa3100107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 9 Sep 2021 14:04:22 +0200 Subject: [PATCH 021/131] finx indent --- app/views/admin/p_customer_sheets/_form.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/admin/p_customer_sheets/_form.html.haml b/app/views/admin/p_customer_sheets/_form.html.haml index 6b0e3c0..2c1194a 100755 --- a/app/views/admin/p_customer_sheets/_form.html.haml +++ b/app/views/admin/p_customer_sheets/_form.html.haml @@ -22,7 +22,7 @@ =yield :price_lines .large_actions .actions - =link_to "Annuler", admin_p_customer_sheets_path(), :class => "btn" - =form.submit "sauvegarder", :class => "btn btn-primary btn-ap-add" + =link_to "Annuler", admin_p_customer_sheets_path(), :class => "btn" + =form.submit "sauvegarder", :class => "btn btn-primary btn-ap-add" .clear From 1e5316a3bfba79c292634af981bb7a95c55b2d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 9 Sep 2021 18:53:57 +0200 Subject: [PATCH 022/131] Wip show consult --- app/helpers/application_helper.rb | 15 +- .../admin/price_documents/show.html.haml | 27 +- app/views/admin/price_lines/_form.html.haml | 238 ++++++------------ .../admin/price_lines/_form_consult.html.haml | 27 ++ 4 files changed, 134 insertions(+), 173 deletions(-) create mode 100644 app/views/admin/price_lines/_form_consult.html.haml diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9e30dd0..31e8de0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -13,7 +13,20 @@ module ApplicationHelper end return raw(r) end - + + def qi_js_field_price_line_form(form, model, method, options = {}) + r = "" + if options[:hidden] + r += hidden_field_tag(method, eval("form.object.#{method}"), :class => "input_#{model}_#{method} form-control",:disabled => true) + else + if options[:label] + r += label_tag(:input, options[:label], class: options[:label_class]) + end + r += text_field_tag(method, (options[:value] ? options[:value] : eval("form.object.#{method}")), :class => "input_#{model}_#{method} form-control",:disabled => true) + end + return raw(r) + end + def edit_watcher(element_type, element_id, key='' ) raw ('
') diff --git a/app/views/admin/price_documents/show.html.haml b/app/views/admin/price_documents/show.html.haml index 98256c1..2059688 100644 --- a/app/views/admin/price_documents/show.html.haml +++ b/app/views/admin/price_documents/show.html.haml @@ -367,9 +367,28 @@ Vous devez d'abord Selectionner les prix sur le page d'analyse : =link_to ic("bar-chart")+" analyse des réponses", analyse_reponses_admin_price_document_path(@price_document), class: "btn btn-primary" puis Generer les consultations + -@price_documents.each do |price_document_consult| + + =link_to ic(:clipboard) + " test clipboard TODO", "#", class: "right btn btn-primary", "data-document" => price_document_consult.id, onclick: 'copyPriceLines(event)' %h4= price_document_consult.p_fournisseur.name - =semantic_form_for [:admin, price_document_consult], :html => {:class => "qi_price_form"}, :remote => false do |form| - =form.semantic_fields_for :price_line_block do |f| - =f.semantic_fields_for :price_lines do |form| - =render partial: "admin/price_lines/form", locals: {form: form} + = semantic_form_for [:admin, price_document_consult], :html => {:class => "qi_price_form"}, :remote => false do |form| + = form.button ic(:clipboard) + "Valider modifications (TODO +copier la consultation)", type: :submit, class: "btn btn-primary m-2" + .price-lines{"data-document" => price_document_consult.id} + =form.semantic_fields_for :price_line_block do |f| + =f.semantic_fields_for :price_lines do |form| + =render partial: "admin/price_lines/form_consult", locals: {form: form} + +:javascript + const copyPriceLines = (event) => { + event.preventDefault() + console.log(event.target.dataset.document) + let result = $('div[data-document=38]') + copy(result) + } + const copy = (element) => { + element.select() + document.execCommand("copy") + } + + diff --git a/app/views/admin/price_lines/_form.html.haml b/app/views/admin/price_lines/_form.html.haml index 3cc5a9b..77c4f79 100644 --- a/app/views/admin/price_lines/_form.html.haml +++ b/app/views/admin/price_lines/_form.html.haml @@ -4,121 +4,45 @@ %table %tr %td{:class => ("error has-error" if form.object.errors[:p_product_ref_id].size > 0 )} - .take.mx-1 + .take.mr-1 =ic :arrows %td = form.input :ct_title, :label => "Designation personnalisée : " if @avoir - %div{:class => ("error has-error" if form.object.errors[:p_product_ref_id].size > 0 )} - - -key = SecureRandom.hex(6) - - %label Produit : - %input.p_product_ref_autocomplete_input.form-control{:type => "text", :value => ("#{form.object.p_product_ref.ref} #{form.object.p_product_ref.cc_name}" if form.object.p_product_ref), :class => "p_product_ref_name_#{key}"} + -key = SecureRandom.hex(6) + %label.ml-3.mr-2 Produit : + %td + %input.p_product_ref_autocomplete_input.form-control{:type => "text", tabindex: 1, autofocus: true, :value => ("#{form.object.p_product_ref.ref} #{form.object.p_product_ref.cc_name}" if form.object.p_product_ref), :class => "p_product_ref_name_#{key}"} - = form.hidden_field :p_product_ref_id, :class => "p_product_ref_id p_product_ref_id_#{key}" - =link_to "selectionner un produit", "#", :onclick => "select_product_from_manager('#{key}');return false;" - :javascript - $( function() { - - $('.p_product_ref_autocomplete_input').autocomplete({ - source: function( request, response ) { - $.ajax( { - url: "/admin/p_product_refs/autocomplete.json", - dataType: "json", - data: { - search: request.term, - p_customer_id: $(".p_customer_id").val() - }, - success: function(data){ - - arr = jQuery.map( data, function( item ) { - return { - label: item.member_label, - value: item.member_label, - id: item.id - } - }); - - response(arr) - - } - - } ); - }, - minLength: 2, - select: function( event, ui ) { - - $(this).next(".p_product_ref_id").val(ui.item.id) - - form = $(this).closest(".price_line_form") - - - - $.ajax( { - url: "/admin/p_product_refs/"+ui.item.id+"/get_infos.json", - dataType: "json", - data: { - type: "price", - qte: form.find(".input_price_line_qte").val(), - p_customer_id: $(".p_customer_id").val() - }, - success: function (data) { - form.find(".input_price_line_price_u_ht").val(data.price); - form.find(".input_price_line_tva_account_id").val(data.tva_account_id); - form.find(".input_price_line_tva_account_value").val(data.tva_account_value); - form.find(".input_price_line_weight_u").val(data.weight); - - - - } - - - } ); - - - - - //return false - } - }); - - - - } ); - - - %table.top_td{:style => "width:100%;margin-top:5px;"} - %tr - %td{:style => "width:30px"} - %span.destroy=link_to_remove_fields ic(:"trash-o"), form + = form.hidden_field :p_product_ref_id, :class => "p_product_ref_id p_product_ref_id_#{key}" %td - %input.p_product_ref_autocomplete_input.form-control{:type => "text", tabindex: 1, autofocus: true, :value => ("#{form.object.p_product_ref.ref} #{form.object.p_product_ref.cc_name}" if form.object.p_product_ref)} - -form.object.forced_price = true if form.object.ct_u_price_ht + =link_to ic(:search), "#", class: "ml-2",:onclick => "select_product_from_manager('#{key}');return false;" - -if form.object.forced_price and form.object.p_product_ref - %td - .mx-4 - .form-inline - =qi_js_field(form, :price_line, :price_u_ht, :label => "Prix U HT :", :value => form.object.th_price_u_ht) - -else - %td - .mx-3 - .form-inline - =qi_js_field(form, :price_line, :price_u_ht, :label => "Prix U HT :") + -form.object.forced_price = true if form.object.ct_u_price_ht + + -if form.object.forced_price and form.object.p_product_ref %td - .form-inline.mx-4{:style => ("display:none;" if !current_admin or !current_admin.has_permission?("customer-sheets-personalised-price"))} - = form.input :forced_price, :label => "Prix personnalisé ?", :as => :boolean, :input_html => {:class => "input_price_line_forced_price"} - .forced_price_wrapper.mx-4{:style => ("display:none;" if !form.object.forced_price)}= form.input :ct_u_price_ht, :label => false, :input_html => {:class => "input_price_line_ct_u_price_ht"} + .mx-2 + .form-inline + =qi_js_field_price_line_form(form, :price_line, :price_u_ht, :label => "Prix U HT :", label_class: "mr-1", :value => form.object.th_price_u_ht) + -else %td - .mx-4.form-inline - = form.input :qte, :label => "qte :", :input_html => {:class => "input_price_line_qte form-control mx-2", tabindex: 1} + .mx-2 + .form-inline + =qi_js_field_price_line_form(form, :price_line, :price_u_ht, :label => "Prix U HT :", label_class: "mr-1") + %td + .form-inline.mr-2{:style => ("display:none;" if !current_admin or !current_admin.has_permission?("customer-sheets-personalised-price"))} + = form.input :forced_price, :label => "Prix personnalisé ?", :as => :boolean, :input_html => {:class => "form-inline input_price_line_forced_price"} + .forced_price_wrapper.mx-2{:style => ("display:none;" if !form.object.forced_price)}= form.input :ct_u_price_ht, :label => false, :input_html => {:class => "input_price_line_ct_u_price_ht"} + %td + .mx-2.form-inline + = form.input :qte, :label => "qte :", :input_html => {:class => "input_price_line_qte form-control mx-2", tabindex: 1} = form.hidden_field :p_product_ref_id, :class => "p_product_ref_id" %td .form-inline - %label.mx-4 Taux de TVA : + %label.mx-2 Taux de TVA : =select_tag :tva_account_id, options_from_collection_for_select(TvaRate.where(:accounting_zone_id => (@p_customer ? @p_customer.accounting_zone_id : nil)).all, "id", "member_label", form.object.tva_account_id), :class => "input_price_line_tva_account_id form-control custom-select" #, :disabled => true %td .ml-4 @@ -131,72 +55,50 @@ = form.hidden_field :position, :class => "price_line_position_input" - :javascript - $('.p_product_ref_autocomplete_input').focus() - $( function() { - - $('.p_product_ref_autocomplete_input').autocomplete({ - source: function( request, response ) { - $.ajax( { - url: "/admin/p_product_refs/autocomplete.json", - dataType: "json", - data: { - search: request.term, - p_customer_id: $(".p_customer_id").val() - }, - success: function(data){ - - arr = jQuery.map( data, function( item ) { - return { - label: item.member_label, - value: item.member_label, - id: item.id - } - }); - - response(arr) - - } - - } ); - }, - minLength: 2, - select: function( event, ui ) { - - $(this).next(".p_product_ref_id").val(ui.item.id) - - form = $(this).closest(".price_line_form") - - - - $.ajax( { - url: "/admin/p_product_refs/"+ui.item.id+"/get_infos.json", - dataType: "json", - data: { - type: "price", - qte: form.find(".input_price_line_qte").val(), - p_customer_id: $(".p_customer_id").val() - }, - success: function (data) { - form.find(".input_price_line_price_u_ht").val(data.price); - form.find(".input_price_line_tva_account_id").val(data.tva_account_id); - form.find(".input_price_line_tva_account_value").val(data.tva_account_value); - form.find(".input_price_line_weight_u").val(data.weight); - - - + :javascript + $('.p_product_ref_autocomplete_input').focus() + $( function() { + $('.p_product_ref_autocomplete_input').autocomplete({ + source: function( request, response ) { + $.ajax( { + url: "/admin/p_product_refs/autocomplete.json", + dataType: "json", + data: { + search: request.term, + p_customer_id: $(".p_customer_id").val() + }, + success: function(data){ + arr = jQuery.map( data, function( item ) { + return { + label: item.member_label, + value: item.member_label, + id: item.id } - - - } ); - - - - - //return false - } + }); + response(arr) + } }); - - - - } ); + }, + minLength: 2, + select: function( event, ui ) { + $(this).next(".p_product_ref_id").val(ui.item.id) + form = $(this).closest(".price_line_form") + $.ajax( { + url: "/admin/p_product_refs/"+ui.item.id+"/get_infos.json", + dataType: "json", + data: { + type: "price", + qte: form.find(".input_price_line_qte").val(), + p_customer_id: $(".p_customer_id").val() + }, + success: function (data) { + form.find(".input_price_line_price_u_ht").val(data.price); + form.find(".input_price_line_tva_account_id").val(data.tva_account_id); + form.find(".input_price_line_tva_account_value").val(data.tva_account_value); + form.find(".input_price_line_weight_u").val(data.weight); + } + }); + //return false + } + }); + }); diff --git a/app/views/admin/price_lines/_form_consult.html.haml b/app/views/admin/price_lines/_form_consult.html.haml new file mode 100644 index 0000000..61f9872 --- /dev/null +++ b/app/views/admin/price_lines/_form_consult.html.haml @@ -0,0 +1,27 @@ +- price_line = form.object +.qi_pannel.qi_plain.padding.price_line_form.col-12.field{:style =>"border-left:4px solid gray;margin-bottom:10px;padding-left:5px;"} + .row + .col-1 + .take.mr-1 + =ic :arrows + .col-6 + Produit : + =price_line.p_product_ref.cc_name + + .col-2 + Base de prix U HT : + = price_line.price_u_ht + € + .col-3 + .form-inline + = form.input :qte, :label => "qte :", :input_html => {:class => "input_price_line_qte form-control mx-2", tabindex: 1} + %span.destroy=link_to_remove_fields ic(:"trash-o"), form + + = form.hidden_field :p_product_ref_id, :class => "p_product_ref_id" + + + + =qi_js_field(form, :price_line, :tva_account_value, :hidden => true) + + = form.hidden_field :position, :class => "price_line_position_input" + From 6f00816efc1d438df0ea39c5bc343d1b21608154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 10 Sep 2021 10:48:24 +0200 Subject: [PATCH 023/131] Copy to clipboard --- .../admin/price_documents/show.html.haml | 60 ++++++++++++++----- .../admin/price_lines/_form_consult.html.haml | 21 ++++--- 2 files changed, 57 insertions(+), 24 deletions(-) diff --git a/app/views/admin/price_documents/show.html.haml b/app/views/admin/price_documents/show.html.haml index 2059688..07b10c7 100644 --- a/app/views/admin/price_documents/show.html.haml +++ b/app/views/admin/price_documents/show.html.haml @@ -320,7 +320,7 @@ -if @price_document.label == "Demande prix" - %h3 Réponses fournisseur + %h3.ml-2 Réponses fournisseur #bills -params[:search][:per_page] = params[:search][:per_page] || 5000 -per_page = params[:search][:per_page] @@ -341,7 +341,7 @@ =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @price_documents, :key => "reponses-prix-show"} - %h3 Consultations fournisseur + %h3.ml-2 Consultations fournisseur #consult -params[:search][:per_page] = params[:search][:per_page] || 5000 -per_page = params[:search][:per_page] @@ -370,25 +370,55 @@ -@price_documents.each do |price_document_consult| - =link_to ic(:clipboard) + " test clipboard TODO", "#", class: "right btn btn-primary", "data-document" => price_document_consult.id, onclick: 'copyPriceLines(event)' - %h4= price_document_consult.p_fournisseur.name + %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 ic(:clipboard) + "Valider modifications (TODO +copier la consultation)", 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)' .price-lines{"data-document" => price_document_consult.id} =form.semantic_fields_for :price_line_block do |f| - =f.semantic_fields_for :price_lines do |form| - =render partial: "admin/price_lines/form_consult", locals: {form: form} + .mx-2 + =f.semantic_fields_for :price_lines do |form| + =render partial: "admin/price_lines/form_consult", locals: {form: form} + + + + + :javascript const copyPriceLines = (event) => { event.preventDefault() - console.log(event.target.dataset.document) - let result = $('div[data-document=38]') - copy(result) - } - const copy = (element) => { - element.select() - document.execCommand("copy") + let priceDocumentId = event.target.dataset.document + let names = $(`.p_product_ref_cc_name_${priceDocumentId}`) + let qtes = $(`.input_price_line_qte_${priceDocumentId}`) + let prices = $(`.price_line_price_u_ht_${priceDocumentId}`) + + let table = [] + names.each(function( i ) { + let row = [] + row.push(qtes[i].valueAsNumber) + row.push(" X ") + row.push(names[i].innerText) + row.push(" @ ") + row.push(prices[i].innerText) + table.push(row.join(' ')) + }) + copyStringToClipboard(table.join('\r\n')) } - + function copyStringToClipboard (str) { + // Create new element + var el = document.createElement('textarea'); + // Set value (string to be copied) + el.value = str; + // Set non-editable to avoid focus and move outside of view + el.setAttribute('readonly', ''); + el.style = {position: 'absolute', left: '-9999px'}; + document.body.appendChild(el); + // Select text inside element + el.select(); + // Copy text to clipboard + document.execCommand('copy'); + // Remove temporary element + document.body.removeChild(el); + } diff --git a/app/views/admin/price_lines/_form_consult.html.haml b/app/views/admin/price_lines/_form_consult.html.haml index 61f9872..64841df 100644 --- a/app/views/admin/price_lines/_form_consult.html.haml +++ b/app/views/admin/price_lines/_form_consult.html.haml @@ -1,20 +1,23 @@ - price_line = form.object .qi_pannel.qi_plain.padding.price_line_form.col-12.field{:style =>"border-left:4px solid gray;margin-bottom:10px;padding-left:5px;"} .row - .col-1 - .take.mr-1 + .col-6.d-flex + .take.mr-4 =ic :arrows - .col-6 - Produit : - =price_line.p_product_ref.cc_name + .mr-1 + ref : + %div{class: "p_product_ref_cc_name_#{price_line.price_line_block.price_lineable_id}"} + =price_line.p_product_ref.cc_name - .col-2 + + .col-3.d-flex Base de prix U HT : - = price_line.price_u_ht - € + %div{class: "mx-1 price_line_price_u_ht_#{price_line.price_line_block.price_lineable_id}"} + = price_line.price_u_ht + € .col-3 .form-inline - = form.input :qte, :label => "qte :", :input_html => {:class => "input_price_line_qte form-control mx-2", tabindex: 1} + = form.input :qte, :label => "qte :", :input_html => {:class => "input_price_line_qte_#{price_line.price_line_block.price_lineable_id} form-control mx-2", tabindex: 1} %span.destroy=link_to_remove_fields ic(:"trash-o"), form = form.hidden_field :p_product_ref_id, :class => "p_product_ref_id" From 2fe82678a5710d7365dd1e4e89ad3e0149525261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 10 Sep 2021 12:54:45 +0200 Subject: [PATCH 024/131] move tooltip to admin.scss --- app/assets/stylesheets/admin.scss | 86 ++++++++++++++++++- .../analyse_reponses.html.haml | 46 +--------- 2 files changed, 86 insertions(+), 46 deletions(-) diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index a53341c..cb1ee54 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -1782,4 +1782,88 @@ td{ } -// Fin \ No newline at end of file + +// Html5 Tooltip +.info { + color: #009bbf; + position: relative; + display: inline-block; + text-overflow: ellipsis; + + .info-text-top { + visibility: hidden; + background-color: #555; + color: #fff; + text-align: center; + padding: 5px; + border-radius: 6px; + max-width: 500px; + min-width: fit-content; + white-space: normal; + + /* Position the tooltip text */ + position: absolute; + z-index: 1; + bottom: 125%; + left: 50%; + margin-left: -60px; + + /* Fade in tooltip */ + opacity: 0; + transition: opacity 0.3s; + } + .info-text-top::after { + content: ""; + position: absolute; + top: 100%; + left: 50%; + margin-left: -5px; + border-width: 5px; + border-style: solid; + border-color: #555 transparent transparent transparent; + } + .info-text-bottom { + visibility: hidden; + background-color: #555; + color: #fff; + text-align: center; + padding: 5px; + border-radius: 6px; + max-width: 500px; + min-width: fit-content; + white-space: normal; + + /* Position the tooltip text */ + position: absolute; + z-index: 1; + top: 125%; + left: 200%; + margin-left: -60px; + + /* Fade in tooltip */ + opacity: 0; + transition: opacity 0.3s; + } + .info-text-bottom::after { + content: ""; + position: absolute; + bottom: 100%; + left: 50%; + margin-left: -5px; + border-width: 5px; + border-style: solid; + border-color: transparent transparent #555 transparent; + } +} +.info:hover { + .info-text-top { + visibility: visible; + opacity: 1; + } + .info-text-bottom { + visibility: visible; + opacity: 1; + } +} + +// Fin diff --git a/app/views/admin/price_documents/analyse_reponses.html.haml b/app/views/admin/price_documents/analyse_reponses.html.haml index f4c2572..b88eab3 100644 --- a/app/views/admin/price_documents/analyse_reponses.html.haml +++ b/app/views/admin/price_documents/analyse_reponses.html.haml @@ -189,7 +189,7 @@ - display_comment = "#{line.comment[0..10]} (..)" - else - display_comment = line.comment - - cell << "#{ic('info-circle')} #{display_comment}#{line.comment}" + - cell << "#{ic('info-circle')} #{display_comment}#{line.comment}" %td.p-0{class: ("best-price" if line.id == best_price[0])} =# "reponse price_line ID : #{line.id}" @@ -306,51 +306,7 @@ color: orange; } - .info { - color: #009bbf; - position: relative; - display: inline-block; - text-overflow: ellipsis; - .info-text { - visibility: hidden; - background-color: #555; - color: #fff; - text-align: center; - padding: 5px; - border-radius: 6px; - max-width: 500px; - min-width: fit-content; - white-space: normal; - - /* Position the tooltip text */ - position: absolute; - z-index: 1; - bottom: 125%; - left: 50%; - margin-left: -60px; - - /* Fade in tooltip */ - opacity: 0; - transition: opacity 0.3s; - } - .info-text::after { - content: ""; - position: absolute; - top: 100%; - left: 50%; - margin-left: -5px; - border-width: 5px; - border-style: solid; - border-color: #555 transparent transparent transparent; - } - } - .info:hover { - .info-text { - visibility: visible; - opacity: 1; - } - } .darkblue { color: darkblue; } From f20dda1f15218c05d4c0ec89d1683f752e470efc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 10 Sep 2021 12:55:32 +0200 Subject: [PATCH 025/131] =?UTF-8?q?remove=200=20qt=C3=A9=20price=5Fline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admin/price_documents_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/price_documents_controller.rb b/app/controllers/admin/price_documents_controller.rb index 6fa1ad2..7a40418 100644 --- a/app/controllers/admin/price_documents_controller.rb +++ b/app/controllers/admin/price_documents_controller.rb @@ -239,7 +239,9 @@ class Admin::PriceDocumentsController < ApplicationController p_product_ref_qte = params[:qte].values p_product_ref_id.each_with_index do |key, i| - @price_document.price_line_block.price_lines << PriceLine.new(:p_product_ref_id => key, :qte => p_product_ref_qte[i]) + if p_product_ref_qte[i].to_i > 0 + @price_document.price_line_block.price_lines << PriceLine.new(:p_product_ref_id => key, :qte => p_product_ref_qte[i]) + end end # @ref_price_lines = PriceLine.where(:id => params[:price_line_ids]) From 9a752ac1a7c49a5efdc0229ba4ec3ff6b56ffccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 10 Sep 2021 12:56:12 +0200 Subject: [PATCH 026/131] =?UTF-8?q?pre-fill=20Qt=C3=A9=20+=20tooltip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/admin/buy_lists/index.html.haml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/views/admin/buy_lists/index.html.haml b/app/views/admin/buy_lists/index.html.haml index 37beefd..cb6bed8 100644 --- a/app/views/admin/buy_lists/index.html.haml +++ b/app/views/admin/buy_lists/index.html.haml @@ -104,6 +104,9 @@ Qté en stock %th.mask Qté souhaité + %span.info + =ic("info-circle") + %span.info-text-bottom BPA - Qté en stock %th.mask BPA %th.mask AV BPA %th.mask PAS BPA @@ -131,6 +134,9 @@ -ppr_lines = @price_lines.where(:p_product_ref_id => plr.p_product_ref.id) %tr.ref_tr + - bpa_qte = ppr_lines.where(:cc_state => "BPA").sum(:qte).to_i + - qte_available = LineStock.where(p_product_ref_id: plr.p_product_ref.id).sum(:qte_available).to_i + -if checkbox %td @@ -165,13 +171,12 @@ =ic(:hourglass) =ppr_lines.asap_triage(20).last %td.mask - = LineStock.where(p_product_ref_id: plr.p_product_ref.id).sum(:qte_available).to_i + = qte_available + %td.mask + =number_field_tag "qte[#{plr.p_product_ref.id}]", '', class: "small-input", value: (bpa_qte - qte_available) %td.mask - =text_field_tag "qte[#{plr.p_product_ref.id}]", '', class: "small-input" - - %td.mask - =ppr_lines.where(:cc_state => "BPA").sum(:qte).to_i + = bpa_qte %td.mask =ppr_lines.where(:cc_state => "AV BPA").sum(:qte).to_i %td.mask From e8d66c91d7e83accc9a6b42e71bfa677c46bd375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 10 Sep 2021 17:21:28 +0200 Subject: [PATCH 027/131] Skip p_fournisseur validation for demande de prix --- app/models/price_line_block.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/price_line_block.rb b/app/models/price_line_block.rb index 7e9ea94..3a048e0 100644 --- a/app/models/price_line_block.rb +++ b/app/models/price_line_block.rb @@ -23,9 +23,9 @@ class PriceLineBlock < ApplicationRecord belongs_to :p_payment_type - PURCHASE_BLOCKS = ["Demande prix", "Réponse fournisseur", "Commande achat", "Facture d'achat", "Consultation fournisseur"] + PURCHASE_BLOCKS = [ "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 accepts_nested_attributes_for :p_fournisseur From ce6a7a6c91f410fb65fbea3dfbc4f423f615a6bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 10 Sep 2021 17:21:41 +0200 Subject: [PATCH 028/131] Generate commande achat --- .../admin/price_documents_controller.rb | 15 ++++ .../admin/price_documents/show.html.haml | 74 ++++++++++--------- config/routes.rb | 1 + 3 files changed, 54 insertions(+), 36 deletions(-) diff --git a/app/controllers/admin/price_documents_controller.rb b/app/controllers/admin/price_documents_controller.rb index 7a40418..ccb68b1 100644 --- a/app/controllers/admin/price_documents_controller.rb +++ b/app/controllers/admin/price_documents_controller.rb @@ -655,4 +655,19 @@ class Admin::PriceDocumentsController < ApplicationController @final_consult = PriceDocument.where(price_document_type: PriceDocumentType.find_by_label("Consultation fournisseur")).last redirect_to :analyse_reponses_admin_price_document end + + def buy_order_create + + @final_consult = PriceDocument.find(params[:id]) + price_line_block = PriceLineBlock.new(p_fournisseur: @final_consult.price_line_block.p_fournisseur) + price_lines = PriceLine.where(price_line_block: @final_consult.price_line_block) + + @price_document = PriceDocument.new(date: Date.today, price_line_block: price_line_block, doc_ref_id: @final_consult.id, :price_document_type => PriceDocumentType.find_by_label("Commande achat")) + price_lines.each do |pl| + @price_document.price_line_block.price_lines << PriceLine.new(p_product_ref: pl.p_product_ref, qte: pl.qte, ct_u_price_ht: pl.price_u_ht) + end + if @price_document.save! + redirect_to admin_price_document_path(@price_document) + end + end end diff --git a/app/views/admin/price_documents/show.html.haml b/app/views/admin/price_documents/show.html.haml index 07b10c7..838b25f 100644 --- a/app/views/admin/price_documents/show.html.haml +++ b/app/views/admin/price_documents/show.html.haml @@ -371,9 +371,11 @@ -@price_documents.each do |price_document_consult| %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" - =link_to ic(:clipboard) + " Copier le text", "#", class: "btn btn-primary", "data-document" => price_document_consult.id, onclick: 'copyPriceLines(event)' + = link_to ic(:clipboard) + " Copier le text", "#", class: "btn btn-primary", "data-document" => price_document_consult.id, onclick: 'copyPriceLines(event)' + = link_to "Generer la commande", buy_order_create_admin_price_document_path(price_document_consult) .price-lines{"data-document" => price_document_consult.id} =form.semantic_fields_for :price_line_block do |f| .mx-2 @@ -385,40 +387,40 @@ -:javascript - const copyPriceLines = (event) => { - event.preventDefault() - let priceDocumentId = event.target.dataset.document - let names = $(`.p_product_ref_cc_name_${priceDocumentId}`) - let qtes = $(`.input_price_line_qte_${priceDocumentId}`) - let prices = $(`.price_line_price_u_ht_${priceDocumentId}`) + :javascript + const copyPriceLines = (event) => { + event.preventDefault() + let priceDocumentId = event.target.dataset.document + let names = $(`.p_product_ref_cc_name_${priceDocumentId}`) + let qtes = $(`.input_price_line_qte_${priceDocumentId}`) + let prices = $(`.price_line_price_u_ht_${priceDocumentId}`) - let table = [] - names.each(function( i ) { - let row = [] - row.push(qtes[i].valueAsNumber) - row.push(" X ") - row.push(names[i].innerText) - row.push(" @ ") - row.push(prices[i].innerText) - table.push(row.join(' ')) - }) - copyStringToClipboard(table.join('\r\n')) - } + let table = [] + names.each(function( i ) { + let row = [] + row.push(qtes[i].valueAsNumber) + row.push(" X ") + row.push(names[i].innerText) + row.push(" @ ") + row.push(prices[i].innerText) + table.push(row.join(' ')) + }) + copyStringToClipboard(table.join('\r\n')) + } - function copyStringToClipboard (str) { - // Create new element - var el = document.createElement('textarea'); - // Set value (string to be copied) - el.value = str; - // Set non-editable to avoid focus and move outside of view - el.setAttribute('readonly', ''); - el.style = {position: 'absolute', left: '-9999px'}; - document.body.appendChild(el); - // Select text inside element - el.select(); - // Copy text to clipboard - document.execCommand('copy'); - // Remove temporary element - document.body.removeChild(el); - } + function copyStringToClipboard (str) { + // Create new element + var el = document.createElement('textarea'); + // Set value (string to be copied) + el.value = str; + // Set non-editable to avoid focus and move outside of view + el.setAttribute('readonly', ''); + el.style = {position: 'absolute', left: '-9999px'}; + document.body.appendChild(el); + // Select text inside element + el.select(); + // Copy text to clipboard + document.execCommand('copy'); + // Remove temporary element + document.body.removeChild(el); + } diff --git a/config/routes.rb b/config/routes.rb index 83c02a0..d266eda 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -631,6 +631,7 @@ Rails.application.routes.draw do get :analyse_reponses post :analyse_reponses_save get :generate_final_consult + get :buy_order_create end collection do get :search_to_affect From 2f7a3a48a14798ac20fc9101ad5d41a88d0fe163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 13 Sep 2021 11:16:55 +0200 Subject: [PATCH 029/131] Add form slug option to add_fields --- app/helpers/document_line_helper.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/helpers/document_line_helper.rb b/app/helpers/document_line_helper.rb index 8066e11..0e54205 100644 --- a/app/helpers/document_line_helper.rb +++ b/app/helpers/document_line_helper.rb @@ -28,6 +28,10 @@ module DocumentLineHelper fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder| render("admin/"+association.to_s + "/essentials_form", :form => builder) end + elsif options[:slug] + fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder| + render("admin/"+association.to_s + "/form_#{options[:slug]}", :form => builder) + end else fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder| render("admin/"+association.to_s + "/form", :form => builder) From 2a540f292a947f7ee598e08b95e129917d873f17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 13 Sep 2021 11:21:55 +0200 Subject: [PATCH 030/131] update price-line form demande de prix --- .../_form_demande_prix.html.haml | 4 +- .../price_lines/_form_demande_prix.html.haml | 118 ++++-------------- .../_form_demande_prix_OLD.html.haml | 98 +++++++++++++++ 3 files changed, 122 insertions(+), 98 deletions(-) create mode 100644 app/views/admin/price_lines/_form_demande_prix_OLD.html.haml diff --git a/app/views/admin/price_line_blocks/_form_demande_prix.html.haml b/app/views/admin/price_line_blocks/_form_demande_prix.html.haml index 28deefc..14a5e63 100644 --- a/app/views/admin/price_line_blocks/_form_demande_prix.html.haml +++ b/app/views/admin/price_line_blocks/_form_demande_prix.html.haml @@ -21,7 +21,7 @@ =f.semantic_fields_for :price_lines do |f| =render :partial => "admin/price_lines/form_#{f.object.block_type_slug}", :locals => {:form => f} - %p= link_to_add_fields "Ajouter une ligne", f, :price_lines, {:class => "btn btn-primary"} + %p= link_to_add_fields "Ajouter une ligne", f, :price_lines, {slug: f.object.block_type_slug , :class => "btn btn-primary", tabindex: 2} - \ No newline at end of file + diff --git a/app/views/admin/price_lines/_form_demande_prix.html.haml b/app/views/admin/price_lines/_form_demande_prix.html.haml index 0661845..ed5a37a 100644 --- a/app/views/admin/price_lines/_form_demande_prix.html.haml +++ b/app/views/admin/price_lines/_form_demande_prix.html.haml @@ -1,98 +1,24 @@ - -.qi_pannel.qi_plain.padding.price_line_form.field{:style =>"border-left:4px solid gray;margin-bottom:10px;padding-left:5px;"} - %table{:style => "width:100%;"} - %tr - %td{:style => "width:30px;"} - .take +.qi_pannel.qi_plain.padding.price_line_form.col-12.field{:style =>"border-left:4px solid gray;margin-bottom:10px;padding-left:5px;"} + - price_line = form.object + .row + .col-6.row + .col-2.d-flex + .take.mx-3 =ic :arrows - %td - - = form.input :ct_title, :label => "Designation personnalisée : " if @avoir - %div{:class => ("error has-error" if form.object.errors[:p_product_ref_id].size > 0 )} - %label Produit : - %input.p_product_ref_autocomplete_input.form-control{:disabled => true, :type => "text", :value => ("#{form.object.p_product_ref.member_label}" if form.object.p_product_ref)} - - - = form.hidden_field :p_product_ref_id, :class => "p_product_ref_id" - - :javascript - $( function() { - - $('.p_product_ref_autocomplete_input').autocomplete({ - source: function( request, response ) { - $.ajax( { - url: "/admin/p_product_refs/autocomplete.json", - dataType: "json", - data: { - search: request.term, - }, - success: function(data){ - - arr = jQuery.map( data, function( item ) { - return { - label: item.member_label, - value: item.member_label, - id: item.id - } - }); - - response(arr) - - } - - } ); - }, - minLength: 2, - select: function( event, ui ) { - - $(this).next(".p_product_ref_id").val(ui.item.id) - - form = $(this).closest(".price_line_form") - - - - $.ajax( { - url: "/admin/p_product_refs/"+ui.item.id+"/get_infos.json", - dataType: "json", - data: { - type: "price", - qte: form.find(".input_price_line_qte").val(), - p_customer_id: $(".p_customer_id").val() - }, - success: function (data) { - form.find(".input_price_line_price_u_ht").val(data.price); - form.find(".input_price_line_tva_account_id").val(data.tva_account_id); - form.find(".input_price_line_tva_account_value").val(data.tva_account_value); - form.find(".input_price_line_weight_u").val(data.weight); - - - - } - - - } ); - - - - - //return false - } - }); - - - - } ); - - - %table.top_td{:style => "width:100%;margin-top:5px;"} - %tr - %td{:style => "width:30px"} - %span.destroy=link_to_remove_fields ic(:"trash-o"), form - - %td - = form.input :qte, :label => "qte :", :input_html => {:class => "input_price_line_qte"} - - + %label + ref : + %input.p_product_ref_autocomplete_input.form-control.col{:type => "text", tabindex: 1, autofocus: true, :value => ("#{form.object.p_product_ref.ref} #{form.object.p_product_ref.cc_name}" if form.object.p_product_ref)} + + .col-3.ml-4 + .form-inline + = form.input :qte, :label => "qte :", :input_html => { class: "mx-2", tabindex: 1} + .col-1 + %span.destroy=link_to_remove_fields ic(:"trash-o"), form + = form.hidden_field :p_product_ref_id, :class => "p_product_ref_id" + + + + =qi_js_field(form, :price_line, :tva_account_value, :hidden => true) + + = form.hidden_field :position, :class => "price_line_position_input" - = form.hidden_field :position, :class => "price_line_position_input" - diff --git a/app/views/admin/price_lines/_form_demande_prix_OLD.html.haml b/app/views/admin/price_lines/_form_demande_prix_OLD.html.haml new file mode 100644 index 0000000..0661845 --- /dev/null +++ b/app/views/admin/price_lines/_form_demande_prix_OLD.html.haml @@ -0,0 +1,98 @@ + +.qi_pannel.qi_plain.padding.price_line_form.field{:style =>"border-left:4px solid gray;margin-bottom:10px;padding-left:5px;"} + %table{:style => "width:100%;"} + %tr + %td{:style => "width:30px;"} + .take + =ic :arrows + %td + + = form.input :ct_title, :label => "Designation personnalisée : " if @avoir + %div{:class => ("error has-error" if form.object.errors[:p_product_ref_id].size > 0 )} + %label Produit : + %input.p_product_ref_autocomplete_input.form-control{:disabled => true, :type => "text", :value => ("#{form.object.p_product_ref.member_label}" if form.object.p_product_ref)} + + + = form.hidden_field :p_product_ref_id, :class => "p_product_ref_id" + + :javascript + $( function() { + + $('.p_product_ref_autocomplete_input').autocomplete({ + source: function( request, response ) { + $.ajax( { + url: "/admin/p_product_refs/autocomplete.json", + dataType: "json", + data: { + search: request.term, + }, + success: function(data){ + + arr = jQuery.map( data, function( item ) { + return { + label: item.member_label, + value: item.member_label, + id: item.id + } + }); + + response(arr) + + } + + } ); + }, + minLength: 2, + select: function( event, ui ) { + + $(this).next(".p_product_ref_id").val(ui.item.id) + + form = $(this).closest(".price_line_form") + + + + $.ajax( { + url: "/admin/p_product_refs/"+ui.item.id+"/get_infos.json", + dataType: "json", + data: { + type: "price", + qte: form.find(".input_price_line_qte").val(), + p_customer_id: $(".p_customer_id").val() + }, + success: function (data) { + form.find(".input_price_line_price_u_ht").val(data.price); + form.find(".input_price_line_tva_account_id").val(data.tva_account_id); + form.find(".input_price_line_tva_account_value").val(data.tva_account_value); + form.find(".input_price_line_weight_u").val(data.weight); + + + + } + + + } ); + + + + + //return false + } + }); + + + + } ); + + + %table.top_td{:style => "width:100%;margin-top:5px;"} + %tr + %td{:style => "width:30px"} + %span.destroy=link_to_remove_fields ic(:"trash-o"), form + + %td + = form.input :qte, :label => "qte :", :input_html => {:class => "input_price_line_qte"} + + + + = form.hidden_field :position, :class => "price_line_position_input" + From 6751e34f29f33f6c1739922ad00019bf796f64d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 13 Sep 2021 18:36:21 +0200 Subject: [PATCH 031/131] Wip bon de livraison --- .../admin/price_documents_controller.rb | 80 ++++ .../admin/price_documents/show.html.haml | 397 +++++++++--------- config/routes.rb | 2 + 3 files changed, 283 insertions(+), 196 deletions(-) diff --git a/app/controllers/admin/price_documents_controller.rb b/app/controllers/admin/price_documents_controller.rb index ccb68b1..62756c9 100644 --- a/app/controllers/admin/price_documents_controller.rb +++ b/app/controllers/admin/price_documents_controller.rb @@ -670,4 +670,84 @@ class Admin::PriceDocumentsController < ApplicationController redirect_to admin_price_document_path(@price_document) 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 diff --git a/app/views/admin/price_documents/show.html.haml b/app/views/admin/price_documents/show.html.haml index 838b25f..9400fbe 100644 --- a/app/views/admin/price_documents/show.html.haml +++ b/app/views/admin/price_documents/show.html.haml @@ -5,25 +5,25 @@ -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 - - + + = diag do = 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(:download), print_admin_price_document_path(@price_document.token), :remote => false, :target => "_blank" if !PriceLineBlock::PURCHASE_BLOCKS.include?(@price_document.block_type) - + %h1 Documents - + %span =@price_document.price_document_type.label - + %span ="##{@price_document.id}" %span =@price_document.d_number - + .qi_row @@ -35,16 +35,21 @@ 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.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" %tr @@ -57,23 +62,23 @@ 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é à + Envoyé à %td =simple_format @price_document.acheteur_text - + %tr %td Lien pour consultation @@ -86,20 +91,20 @@ .qi_pannel.qi_plain.padding -if false =debug @price_document - - - + + + -if true - + -price_line_block = @price_document.price_line_block - - + + =#render price_line_block - + -else -params[:search][:per_page] = params[:search][:per_page] || 5000 -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 @@ -112,85 +117,86 @@ - .clear + .clear =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 current_admin and current_admin.id == 1 - %table.table - %tr - %th Archivé ? - %td - = diag do - -if @price_document.archived - Oui - =link_to "Désarchiver", unarchive_now_admin_price_document_path(@price_document.id) - -else - =link_to "Archiver", archive_now_admin_price_document_path(@price_document.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) - + -enable_stat = false + -if enable_stat + %table.table + %tr + %th Archivé ? + %td + = diag do + -if @price_document.archived + Oui + =link_to "Désarchiver", unarchive_now_admin_price_document_path(@price_document.id) + -else + =link_to "Archiver", archive_now_admin_price_document_path(@price_document.id) + %tr + %th Id bloc + %td=price_line_block.id - .clear - =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @stat_lines} - - - - - - - - + %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 + =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @stat_lines} + + + + + + + + %h3 Lignes de produits %table.table %thead %tr %th %th Référence - %th Produit + %th Marque %th Désignation %th Qté %th P.U. HT @@ -204,131 +210,130 @@ ="##{price_line.id}" %td =price_line.ref - - + + %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 - =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 =price_line.qte - + %td.numeraire =number_to_currency price_line.price_u_ht - - + + %td.numeraire =price_line.tva_account_value.to_s+"%" - - - - + + + + %td.numeraire =number_to_currency price_line.tot_amount_ht - - %td - = price_line.line_stocks.sum(:price_ht) - - -if current_admin.has_permission?("show-costs") - %br - %br - %p - -if @price_document.price_document_type_id == 6 - =link_to "Générer les stocks", generate_stocks_admin_price_document_path(@price_document), :class => "btn btn-primary" if !@price_document.stock_ok - -elsif @price_document.price_document_type_id == 4 or @price_document.price_document_type_id == 5 - %p - Coût : - =number_to_currency @price_document.cost_ht - %p - 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 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 - %thead - %tr - %th Produit - %th Quantité dans cette pièce comptable - %th Quantité restante - %th - -@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| - %tr - %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 + + / %td=# price_line.line_stocks.sum(:price_ht) + +.qi_row + -if current_admin.has_permission?("show-costs") + %p + -if @price_document.price_document_type_id == 6 + =link_to "Générer les stocks", generate_stocks_admin_price_document_path(@price_document), :class => "btn btn-primary" if !@price_document.stock_ok + -elsif @price_document.price_document_type_id == 4 or @price_document.price_document_type_id == 5 + %p + Coût : + =number_to_currency @price_document.cost_ht + %p + 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.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" + + -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 + %thead + %tr + %th Produit + %th Quantité dans cette pièce comptable + %th Quantité restante + %th + -@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| %tr %td - =pl.p_product_ref.cc_name + =ppa.p_product_ref.cc_name %td - =@a = pl.qte.to_f - + =@a = (pl.qte.to_f * ppa.qte.to_f).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 - + =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 pl.p_product_ref.stocked and @a > @b + -if @a > @b .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") - -@line_stocks = @line_stocks.page(page).per(per_page) - %br - + -else + %tr + %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" %h3.ml-2 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 + -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 = 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"} - - + + %h3.ml-2 Consultations fournisseur #consult -params[:search][:per_page] = params[:search][:per_page] || 5000 -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 = 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"} -if @price_documents.empty? .qi_pannel.qi_plain.padding diff --git a/config/routes.rb b/config/routes.rb index d266eda..faa9cc1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -632,6 +632,8 @@ Rails.application.routes.draw do post :analyse_reponses_save get :generate_final_consult get :buy_order_create + get :bon_de_reception + end collection do get :search_to_affect From bb8c841404f00b1aa98a10de5fc12434823ae05d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 13 Sep 2021 18:36:38 +0200 Subject: [PATCH 032/131] show amount --- app/models/price_line.rb | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/app/models/price_line.rb b/app/models/price_line.rb index f156d9b..d33c571 100644 --- a/app/models/price_line.rb +++ b/app/models/price_line.rb @@ -546,38 +546,36 @@ class PriceLine < ApplicationRecord - - def ca_tot_amount_ht - if ct_tot_amount_ht + if self.ct_tot_amount_ht self.ct_tot_amount_ht else - (self.ca_price_u_kg_net_ht * self.weight_qte.to_f).round(2) + (self.ca_price_u_ht * self.qte.to_f).round(3) end end def ca_tot_amount_tva - (self.tot_amount_ht * (self.tva_account_value/100)).round(2) + (self.tot_amount_ht * (self.tva_account_value/100)).round(3) end def ca_tot_amount_ttc - (self.tot_amount_ht + self.tot_amount_tva).round(2) + (self.tot_amount_ht + self.tot_amount_tva).round(3) end - - - + + + def ca_tot_discount_ht - (self.ca_price_u_ht * self.qte.to_f).round(2) - self.ca_tot_amount_ht + (self.ca_price_u_ht * self.qte.to_f).round(3) - self.ca_tot_amount_ht end - - - + + + def ca_tot_discount_tva - (self.tot_discount_ht * (self.tva_account_value/100)).round(2) + (self.tot_discount_ht * (self.tva_account_value/100)).round(3) end def ca_tot_discount_ttc - (self.tot_discount_ht+self.tot_discount_tva).round(2) + (self.tot_discount_ht+self.tot_discount_tva).round(3) end From 5f7b79139c8ee2423410bd38a0ca674110470a51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Tue, 14 Sep 2021 16:26:28 +0200 Subject: [PATCH 033/131] add price_doc history --- .../20210914071847_add_doc_hist_to_price_documents.rb | 9 +++++++++ db/schema.rb | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20210914071847_add_doc_hist_to_price_documents.rb diff --git a/db/migrate/20210914071847_add_doc_hist_to_price_documents.rb b/db/migrate/20210914071847_add_doc_hist_to_price_documents.rb new file mode 100644 index 0000000..eebac6b --- /dev/null +++ b/db/migrate/20210914071847_add_doc_hist_to_price_documents.rb @@ -0,0 +1,9 @@ +class AddDocHistToPriceDocuments < ActiveRecord::Migration[6.0] + def change + add_column :price_documents, :bon_de_commande_achat_id, :integer + add_column :price_documents, :bon_de_reception_achat_id, :integer + add_column :price_documents, :demande_de_prix_id, :integer + add_column :price_documents, :avoir_achat_id, :integer + add_column :price_documents, :facture_achat_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 934a8fe..077818c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_09_07_161735) do +ActiveRecord::Schema.define(version: 2021_09_14_071847) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -2251,6 +2251,11 @@ ActiveRecord::Schema.define(version: 2021_09_07_161735) do t.string "f_token" t.text "acheteur_text" t.string "public_fournisseur_name" + t.integer "bon_de_commande_achat_id" + t.integer "bon_de_reception_achat_id" + t.integer "demande_de_prix_id" + t.integer "avoir_achat_id" + t.integer "facture_achat_id" t.index ["p_customer_id"], name: "index_price_documents_on_p_customer_id" end From 04d2bbd60acc954dcaa0803e3301957fdfeff44f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Tue, 14 Sep 2021 16:27:55 +0200 Subject: [PATCH 034/131] Wip bon de reception achat --- .../admin/price_documents_controller.rb | 20 ++---- app/models/price_line_block.rb | 21 +++++-- .../admin/price_documents/_relicats.html.haml | 62 +++++++++++++++++++ .../admin/price_documents/show.html.haml | 11 +++- .../_form_bon_de_reception_achat.html.haml | 27 ++++++++ .../_form_bon_de_reception_achat.html.haml | 27 ++++++++ 6 files changed, 145 insertions(+), 23 deletions(-) create mode 100644 app/views/admin/price_documents/_relicats.html.haml create mode 100644 app/views/admin/price_line_blocks/_form_bon_de_reception_achat.html.haml create mode 100644 app/views/admin/price_lines/_form_bon_de_reception_achat.html.haml diff --git a/app/controllers/admin/price_documents_controller.rb b/app/controllers/admin/price_documents_controller.rb index 62756c9..5b9d7d8 100644 --- a/app/controllers/admin/price_documents_controller.rb +++ b/app/controllers/admin/price_documents_controller.rb @@ -662,7 +662,7 @@ class Admin::PriceDocumentsController < ApplicationController price_line_block = PriceLineBlock.new(p_fournisseur: @final_consult.price_line_block.p_fournisseur) price_lines = PriceLine.where(price_line_block: @final_consult.price_line_block) - @price_document = PriceDocument.new(date: Date.today, price_line_block: price_line_block, doc_ref_id: @final_consult.id, :price_document_type => PriceDocumentType.find_by_label("Commande achat")) + @price_document = PriceDocument.new(date: Date.today, price_line_block: price_line_block, doc_ref_id: @final_consult.id, demande_de_prix_id: @final_consult.id ,:price_document_type => PriceDocumentType.find_by_label("Commande achat")) price_lines.each do |pl| @price_document.price_line_block.price_lines << PriceLine.new(p_product_ref: pl.p_product_ref, qte: pl.qte, ct_u_price_ht: pl.price_u_ht) end @@ -671,6 +671,7 @@ class Admin::PriceDocumentsController < ApplicationController end end + def bon_de_reception @past_price_document = PriceDocument.find(params[:id]) @@ -678,31 +679,22 @@ class Admin::PriceDocumentsController < ApplicationController 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 - - - + price_document.reliquat = true if PriceDocument.where(:bon_de_commande_achat_id => @past_price_document.id, :price_document_type => PriceDocumentType.find_by_label("Bon de réception achat")).count > 0 end if @past_price_document.cc_label == "Facture achat" price_document.facture_achat_id = @past_price_document.id - - end @@ -719,9 +711,9 @@ class Admin::PriceDocumentsController < ApplicationController new_pl = pl.dup new_pl.price_line_ref_id = pl.id new_pl.ac_block_type = nil - + raise 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]) + bls = PriceDocument.where(:bon_de_commande_achat_id => @past_price_document.id, :price_document_type => PriceDocumentType.find_by_label("Bon de réception achat")) 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) @@ -744,8 +736,6 @@ class Admin::PriceDocumentsController < ApplicationController else redirect_to [:admin, price_document] end - - else render :inline => price_document.errors.messages.to_s end diff --git a/app/models/price_line_block.rb b/app/models/price_line_block.rb index 3a048e0..f4d44af 100644 --- a/app/models/price_line_block.rb +++ b/app/models/price_line_block.rb @@ -23,7 +23,8 @@ class PriceLineBlock < ApplicationRecord belongs_to :p_payment_type - PURCHASE_BLOCKS = [ "Réponse fournisseur", "Commande achat", "Facture d'achat", "Consultation fournisseur"] + PURCHASE_BLOCKS = ["Réponse fournisseur", "Consultation fournisseur", "Facture d'achat", "Commande achat", "Demande de prix", "Bon de commande achat", "Bon de réception achat", "Facture achat", "Avoir achat"] + SALE_BLOCKS = ["Demande de commande", "Bon de commande", "Devis", "Bon de livraison", "Facture", "Avoir"] belongs_to :p_fournisseur @@ -261,7 +262,9 @@ class PriceLineBlock < ApplicationRecord end def wish_date_needed? - if PriceLineBlock::PURCHASE_BLOCKS.include?(self.block_type) or self.block_type == "Réponse fournisseur" + if PriceLineBlock::PURCHASE_BLOCKS.include?(self.block_type) + false + elsif self.block_type == "Devis" false else true @@ -270,7 +273,9 @@ class PriceLineBlock < ApplicationRecord def particular_bill_needed? if !self.imported - if PriceLineBlock::PURCHASE_BLOCKS.include?(self.block_type) or self.block_type == "Demande prix" or self.block_type == "Réponse fournisseur" + if PriceLineBlock::PURCHASE_BLOCKS.include?(self.block_type) + false + elsif self.block_type == "Devis" false else true @@ -280,7 +285,9 @@ class PriceLineBlock < ApplicationRecord def particular_send_needed? if !self.imported - if PriceLineBlock::PURCHASE_BLOCKS.include?(self.block_type) or self.block_type == "Demande prix" or self.block_type == "Réponse fournisseur" + if PriceLineBlock::PURCHASE_BLOCKS.include?(self.block_type) + false + elsif self.block_type == "Devis" false else true @@ -297,9 +304,11 @@ class PriceLineBlock < ApplicationRecord end def p_customer_needed? - if PriceLineBlock::PURCHASE_BLOCKS.include?(self.block_type) or self.block_type == "Demande prix" or self.block_type == "Réponse fournisseur" + if PriceLineBlock::PURCHASE_BLOCKS.include?(self.block_type) false - elsif !self.imported + elsif self.block_type == "Devis" + false + else true end end diff --git a/app/views/admin/price_documents/_relicats.html.haml b/app/views/admin/price_documents/_relicats.html.haml new file mode 100644 index 0000000..035846f --- /dev/null +++ b/app/views/admin/price_documents/_relicats.html.haml @@ -0,0 +1,62 @@ + +#bills + + .qi_tab_header + %h3 Bons de réception associés + .right + + + -params[:search][:per_page] = params[:search][:per_page] || 50 + -per_page = params[:search][:per_page] + -page = (params[:page] and params[:page] != "") ? params[:page] : 1 + + -@price_documents = PriceDocument.where(:bon_de_commande_achat_id => bca.id, :price_document_type_id => [5]).order("date DESC, created_at DESC") + + -@price_documents = sort_by_sorting(@price_documents, "created_at DESC") + -@all_price_documents = @price_documents + -@price_documents = @price_documents.page(page).per(per_page) + + =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @price_documents, :key => "projet-factures"} + + +%h3 Etat des réceptions par articles + +- bca_price_line_blocks = PriceLineBlock.where(:price_lineable_type => "PriceDocument", :price_lineable_id => bca.id) + +- bra_price_line_blocks = PriceLineBlock.where(:price_lineable_type => "PriceDocument", :price_lineable_id => @all_price_documents.ids) + +%table.table.table-striped.table-hover.table-bordered.data_table + %thead + %tr + %th + Code produit + %th + Produit + %th Quantité commandée + + %th Quantité réceptionnée + + %th Différence + %tbody + - PriceLine.where(:price_line_block_id => (bca_price_line_blocks.ids + bra_price_line_blocks.ids)).map {|pl| pl.p_product_ref_id}.uniq.each do |p_product_ref_id| + -if p_product_ref = PProductRef.where(:id => p_product_ref_id).first + %tr + %td + =link_to [:admin, p_product_ref] do + =p_product_ref.ref + %td + =link_to [:admin, p_product_ref] do + =p_product_ref.cc_name + + %td + =a = PriceLine.where(:p_product_ref_id => p_product_ref_id, :price_line_block_id => bca_price_line_blocks).sum(:qte) + + + %td + =b = PriceLine.where(:p_product_ref_id => p_product_ref_id, :price_line_block_id => bra_price_line_blocks).sum(:qte) + + %td + = a -b + + + diff --git a/app/views/admin/price_documents/show.html.haml b/app/views/admin/price_documents/show.html.haml index 9400fbe..ef8c572 100644 --- a/app/views/admin/price_documents/show.html.haml +++ b/app/views/admin/price_documents/show.html.haml @@ -255,7 +255,8 @@ -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" - + -if @price_document.cc_label == "Commande achat" + =render :partial => "admin/price_documents/relicats", :locals => {:bca => @price_document} -if false -if @price_document.price_document_type_id == 4 or @price_document.price_document_type_id == 5 and !@price_document.cost_ok @@ -380,7 +381,13 @@ = 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" = link_to ic(:clipboard) + " Copier le text", "#", class: "btn btn-primary", "data-document" => price_document_consult.id, onclick: 'copyPriceLines(event)' - = link_to "Generer la commande", buy_order_create_admin_price_document_path(price_document_consult) + - existing_order = PriceDocument.where(doc_ref_id: price_document_consult.id) + - if existing_order.present? + = link_to ic(:eye) + " Afficher la commande", admin_price_document_path(existing_order.first), class: "btn btn-tertiary" + - else + = link_to "Generer la commande", buy_order_create_admin_price_document_path(price_document_consult), class: "btn btn-primary" + + .price-lines{"data-document" => price_document_consult.id} =form.semantic_fields_for :price_line_block do |f| .mx-2 diff --git a/app/views/admin/price_line_blocks/_form_bon_de_reception_achat.html.haml b/app/views/admin/price_line_blocks/_form_bon_de_reception_achat.html.haml new file mode 100644 index 0000000..c4c181a --- /dev/null +++ b/app/views/admin/price_line_blocks/_form_bon_de_reception_achat.html.haml @@ -0,0 +1,27 @@ + +=f.inputs do + + + -if !@p_customer_sheet or (@p_customer_sheet and @p_customer_sheet.state != "commande") + .qi_pannel.qi_plain.padding{:style => "margin:20px 0;"} + + %table{:style => "width:100%;"} + %tr + %td{:style => "width:50%;"} + = f.input :wish_date, :label => "Date de livraison souhaitée :", :as => :date + + + -if @price_document.label != "Demande prix" + = f.input :customer_ref, :label => "Référence commande client :" + -if current_admin.has_permission?("customer-sheets-bl") + = f.input :bl_comment, :label => "Commentaire à mettre sur le BL :", :input_html => {:style => "min-height:50px;height:50px;"} + + + .price_lines_form + =f.semantic_fields_for :price_lines do |f| + =render :partial => "admin/price_lines/form_#{f.object.block_type_slug}", :locals => {:form => f} + + %p= link_to_add_fields "Ajouter une ligne", f, :price_lines, {slug: f.object.block_type_slug , :class => "btn btn-primary", tabindex: 2} + + + diff --git a/app/views/admin/price_lines/_form_bon_de_reception_achat.html.haml b/app/views/admin/price_lines/_form_bon_de_reception_achat.html.haml new file mode 100644 index 0000000..56ccde8 --- /dev/null +++ b/app/views/admin/price_lines/_form_bon_de_reception_achat.html.haml @@ -0,0 +1,27 @@ +.qi_pannel.qi_plain.padding.price_line_form.col-12.field{:style =>"border-left:4px solid gray;margin-bottom:10px;padding-left:5px;"} + - price_line = form.object + .row + .col-6.row + .col-2.d-flex + .take.mx-3 + =ic :arrows + %label + ref : + %input.p_product_ref_autocomplete_input.form-control.col{:type => "text", tabindex: 1, autofocus: true, :value => ("#{form.object.p_product_ref.ref} #{form.object.p_product_ref.cc_name}" if form.object.p_product_ref)} + + .col-3.ml-2 + .form-inline + = form.input :qte, :label => "qte :", :input_html => { class: "mx-2", tabindex: 1} + .col-2 + .form-inline + = form.input :ct_u_price_ht, :label => "PU :", :input_html => { class: "mx-2"} + .col-1.ml-2 + %span.destroy=link_to_remove_fields ic(:"trash-o"), form + = form.hidden_field :p_product_ref_id, :class => "p_product_ref_id" + + + + =qi_js_field(form, :price_line, :tva_account_value, :hidden => true) + + = form.hidden_field :position, :class => "price_line_position_input" + From f0638e82ace1a6a26a14199c54adbadd79ed9b96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Tue, 14 Sep 2021 16:30:39 +0200 Subject: [PATCH 035/131] remove raise --- app/controllers/admin/price_documents_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/price_documents_controller.rb b/app/controllers/admin/price_documents_controller.rb index 5b9d7d8..7542407 100644 --- a/app/controllers/admin/price_documents_controller.rb +++ b/app/controllers/admin/price_documents_controller.rb @@ -711,7 +711,7 @@ class Admin::PriceDocumentsController < ApplicationController new_pl = pl.dup new_pl.price_line_ref_id = pl.id new_pl.ac_block_type = nil - raise + if price_document.reliquat and @p_customer_sheet bls = PriceDocument.where(:bon_de_commande_achat_id => @past_price_document.id, :price_document_type => PriceDocumentType.find_by_label("Bon de réception achat")) From 28490c3e962f834c5f16026f03beb3722130b5db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Tue, 14 Sep 2021 16:30:53 +0200 Subject: [PATCH 036/131] remove form commande --- .../_form_commande_achat.html.haml | 41 ------------------- 1 file changed, 41 deletions(-) delete mode 100644 app/views/admin/price_line_blocks/_form_commande_achat.html.haml diff --git a/app/views/admin/price_line_blocks/_form_commande_achat.html.haml b/app/views/admin/price_line_blocks/_form_commande_achat.html.haml deleted file mode 100644 index 77f22ec..0000000 --- a/app/views/admin/price_line_blocks/_form_commande_achat.html.haml +++ /dev/null @@ -1,41 +0,0 @@ - -=f.inputs do - - - -if !@p_customer_sheet or (@p_customer_sheet and @p_customer_sheet.state != "commande") - .qi_pannel.qi_plain.padding{:style => "margin:20px 0;"} - - - - - - = f.input :p_fournisseur, :label => "Fournisseur :", :collection => PFournisseur.order(:name).all, :as => :select - - - - = f.input :customer_ref, :label => "Numéro de facture fournisseur :" - -if current_admin.has_permission?("customer-sheets-bl") - =# f.input :bl_comment, :label => "Commentaire à mettre sur le BL :", :input_html => {:style => "min-height:50px;height:50px;"} - - -if @p_customer_sheet and @p_customer_sheet.p_customer and @p_customer_sheet.p_customer.p_customer_sheet_note? - %div - %strong Notes pour les demandes de commandes pour ce client : - =simple_format @p_customer_sheet.p_customer.p_customer_sheet_note - %br - - - - = f.input :p_devise_id, :label => "Devise :", :collection => PDevise.order(:id).all, :as => :select, :include_blank => false - = f.input :local_amount_ttc, :label => "Montant TTC en € réglé pour cette facture :" - - - - .price_lines_form - =f.semantic_fields_for :price_lines do |f| - =render :partial => "admin/price_lines/form_facture_dachat", :locals => {:form => f} - - %p= link_to_add_fields "Ajouter une ligne", f, :price_lines, {:class => "btn btn-primary", :partial => "admin/price_lines/form_facture_dachat"} - - - - \ No newline at end of file From d6e1986935959f21066c13662f6bc468a96615d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Wed, 15 Sep 2021 10:09:16 +0200 Subject: [PATCH 037/131] Reliquat bug-fix --- app/controllers/admin/price_documents_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/price_documents_controller.rb b/app/controllers/admin/price_documents_controller.rb index 7542407..93139eb 100644 --- a/app/controllers/admin/price_documents_controller.rb +++ b/app/controllers/admin/price_documents_controller.rb @@ -712,7 +712,7 @@ class Admin::PriceDocumentsController < ApplicationController new_pl.price_line_ref_id = pl.id new_pl.ac_block_type = nil - if price_document.reliquat and @p_customer_sheet + if price_document.reliquat #and @p_customer_sheet bls = PriceDocument.where(:bon_de_commande_achat_id => @past_price_document.id, :price_document_type => PriceDocumentType.find_by_label("Bon de réception achat")) 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) From d28ad68e99e0e9be491f7249c801774aafc4c3b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Wed, 15 Sep 2021 11:35:51 +0200 Subject: [PATCH 038/131] add facture_achat route --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index faa9cc1..76ae891 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -633,7 +633,7 @@ Rails.application.routes.draw do get :generate_final_consult get :buy_order_create get :bon_de_reception - + get :facture_achat end collection do get :search_to_affect 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 039/131] 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); } + From 74992c6607492e88b0c4fe1ed35b1b1b545bcb47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Wed, 15 Sep 2021 18:39:16 +0200 Subject: [PATCH 040/131] small front upgrades --- app/models/price_document.rb | 2 +- .../analyse_reponses.html.haml | 3 ++- .../admin/price_documents/index.html.haml | 2 +- .../_form_bon_de_reception_achat.html.haml | 24 ++++--------------- .../_form_bon_de_reception_achat.html.haml | 4 ++-- 5 files changed, 10 insertions(+), 25 deletions(-) diff --git a/app/models/price_document.rb b/app/models/price_document.rb index 8ed50a1..24fcc09 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 prix", "Réponse fournisseur", "Commande achat", "Facture d'achat", "Consultation fournisseur"] + PURCHASES = ["Demande prix", "Réponse fournisseur", "Commande achat", "Facture 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/views/admin/price_documents/analyse_reponses.html.haml b/app/views/admin/price_documents/analyse_reponses.html.haml index b88eab3..7b68000 100644 --- a/app/views/admin/price_documents/analyse_reponses.html.haml +++ b/app/views/admin/price_documents/analyse_reponses.html.haml @@ -224,7 +224,8 @@ .modal-footer %button.btn.btn-light{"data-dismiss" => "modal"} Close -=link_to "Generer les consultations", generate_final_consult_admin_price_document_path, class: "btn btn-primary ml-4 mt-4" +- if PriceDocument.where(doc_ref_id: @price_document, price_document_type: PriceDocumentType.find_by_label("Consultation fournisseur")).empty? + =link_to "Generer les consultations", generate_final_consult_admin_price_document_path, class: "btn btn-primary ml-4 mt-4" =link_to "Acceder aux consultations", admin_price_document_path(@price_document, anchor: "consult"), class: "btn btn-primary ml-4 mt-4" diff --git a/app/views/admin/price_documents/index.html.haml b/app/views/admin/price_documents/index.html.haml index 8513399..014b9eb 100644 --- a/app/views/admin/price_documents/index.html.haml +++ b/app/views/admin/price_documents/index.html.haml @@ -65,7 +65,7 @@ Type de document : %td - -if [1,2,6,7].include?(params[:price_document_type_id].to_i)or (params[:price_document_type_ids] and (params[:price_document_type_ids].include?("6") or params[:price_document_type_ids].include?("7"))) + -if [3,4,5,6,7,9,10].include?(params[:price_document_type_id].to_i)or (params[:price_document_type_ids] and (params[:price_document_type_ids].include?("6") or params[:price_document_type_ids].include?("7"))) -PriceDocumentType.where(:label => PriceDocument::PURCHASES, :enabled => true).order("id DESC").each do |pdt| %p.d-inline-flex.ml-3 = check_box_tag :"price_document_type_ids[]", pdt.id, (true if params[:price_document_type_ids].include?(pdt.id.to_s)), {:id => "price_document_type_ids_#{pdt.id}", class: "my-auto"} diff --git a/app/views/admin/price_line_blocks/_form_bon_de_reception_achat.html.haml b/app/views/admin/price_line_blocks/_form_bon_de_reception_achat.html.haml index c4c181a..783139d 100644 --- a/app/views/admin/price_line_blocks/_form_bon_de_reception_achat.html.haml +++ b/app/views/admin/price_line_blocks/_form_bon_de_reception_achat.html.haml @@ -1,27 +1,11 @@ =f.inputs do + .price_lines_form + =f.semantic_fields_for :price_lines do |f| + =render :partial => "admin/price_lines/form_#{f.object.block_type_slug}", :locals => {:form => f} - -if !@p_customer_sheet or (@p_customer_sheet and @p_customer_sheet.state != "commande") - .qi_pannel.qi_plain.padding{:style => "margin:20px 0;"} - - %table{:style => "width:100%;"} - %tr - %td{:style => "width:50%;"} - = f.input :wish_date, :label => "Date de livraison souhaitée :", :as => :date - - - -if @price_document.label != "Demande prix" - = f.input :customer_ref, :label => "Référence commande client :" - -if current_admin.has_permission?("customer-sheets-bl") - = f.input :bl_comment, :label => "Commentaire à mettre sur le BL :", :input_html => {:style => "min-height:50px;height:50px;"} - - - .price_lines_form - =f.semantic_fields_for :price_lines do |f| - =render :partial => "admin/price_lines/form_#{f.object.block_type_slug}", :locals => {:form => f} - - %p= link_to_add_fields "Ajouter une ligne", f, :price_lines, {slug: f.object.block_type_slug , :class => "btn btn-primary", tabindex: 2} + %p= link_to_add_fields "Ajouter une ligne", f, :price_lines, {slug: f.object.block_type_slug , :class => "btn btn-primary", tabindex: 2} diff --git a/app/views/admin/price_lines/_form_bon_de_reception_achat.html.haml b/app/views/admin/price_lines/_form_bon_de_reception_achat.html.haml index 56ccde8..a8d7aa0 100644 --- a/app/views/admin/price_lines/_form_bon_de_reception_achat.html.haml +++ b/app/views/admin/price_lines/_form_bon_de_reception_achat.html.haml @@ -7,11 +7,11 @@ =ic :arrows %label ref : - %input.p_product_ref_autocomplete_input.form-control.col{:type => "text", tabindex: 1, autofocus: true, :value => ("#{form.object.p_product_ref.ref} #{form.object.p_product_ref.cc_name}" if form.object.p_product_ref)} + %input.p_product_ref_autocomplete_input.form-control.col{:type => "text", :value => ("#{form.object.p_product_ref.ref} #{form.object.p_product_ref.cc_name}" if form.object.p_product_ref)} .col-3.ml-2 .form-inline - = form.input :qte, :label => "qte :", :input_html => { class: "mx-2", tabindex: 1} + = form.input :qte, :label => "qte :", :input_html => { class: "mx-2", autofocus: true, tabindex: 1} .col-2 .form-inline = form.input :ct_u_price_ht, :label => "PU :", :input_html => { class: "mx-2"} From 4faade463ca73263db0f7b7c9e63ea87ae902291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 16 Sep 2021 13:14:15 +0200 Subject: [PATCH 041/131] update consultation show --- .../admin/price_documents/show.html.haml | 95 +++++++++++-------- 1 file changed, 55 insertions(+), 40 deletions(-) diff --git a/app/views/admin/price_documents/show.html.haml b/app/views/admin/price_documents/show.html.haml index 2ef5d7b..0e7a91f 100644 --- a/app/views/admin/price_documents/show.html.haml +++ b/app/views/admin/price_documents/show.html.haml @@ -191,6 +191,16 @@ %h3 Lignes de produits + .mb-3 + - if @price_document.cc_label == "Consultation fournisseur" + = link_to ic(:clipboard) + " Copier le text", "#", class: "btn btn-primary", "data-document" => @price_document.id, onclick: 'copyPriceLines(event)' + - existing_order = PriceDocument.where(doc_ref_id: @price_document.id, cc_label: "Commande achat") + + - if existing_order.present? + = link_to ic(:eye) + " Afficher la commande", admin_price_document_path(existing_order.first), class: "btn btn-tertiary" + - else + = link_to "Generer la commande", buy_order_create_admin_price_document_path(@price_document), class: "btn btn-primary" + %table.table %thead %tr @@ -213,16 +223,17 @@ + %td =price_line.p_product_ref.p_product.s_brand.name - %td + %td{class: "p_product_ref_cc_name_#{@price_document.id}"} =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{class: "price_line_qte_#{@price_document.id}"} =price_line.qte - %td.numeraire + %td.numeraire{class: "price_line_price_u_ht_#{@price_document.id}"} =number_to_currency price_line.price_u_ht @@ -382,7 +393,7 @@ = 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" = 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) + - existing_order = PriceDocument.where(doc_ref_id: price_document_consult.id, cc_label: "Commande achat") - if existing_order.present? = link_to ic(:eye) + " Afficher la commande", admin_price_document_path(existing_order.first), class: "btn btn-tertiary" - else @@ -399,41 +410,45 @@ - :javascript - const copyPriceLines = (event) => { - event.preventDefault() - let priceDocumentId = event.target.dataset.document - let names = $(`.p_product_ref_cc_name_${priceDocumentId}`) - let qtes = $(`.input_price_line_qte_${priceDocumentId}`) - let prices = $(`.price_line_price_u_ht_${priceDocumentId}`) +:javascript + const copyPriceLines = (event) => { + event.preventDefault() + let priceDocumentId = event.target.dataset.document + let names = $(`.p_product_ref_cc_name_${priceDocumentId}`) + let qtes_input = $(`.input_price_line_qte_${priceDocumentId}`) + let qtes = $(`.price_line_qte_${priceDocumentId}`) + let prices = $(`.price_line_price_u_ht_${priceDocumentId}`) + let table = [] + names.each(function( i ) { + let row = [] + if(qtes_input.length > 0) { + row.push(qtes_input[i].valueAsNumber) + }else{ + row.push(qtes[i].innerText.slice(0, -2)) + } + row.push(" X ") + row.push(names[i].innerText) + row.push(" @ ") + row.push(prices[i].innerText) + table.push(row.join(' ')) + }) + copyStringToClipboard(table.join('\r\n')) + } - let table = [] - names.each(function( i ) { - let row = [] - row.push(qtes[i].valueAsNumber) - row.push(" X ") - row.push(names[i].innerText) - row.push(" @ ") - row.push(prices[i].innerText) - table.push(row.join(' ')) - }) - copyStringToClipboard(table.join('\r\n')) - } - - function copyStringToClipboard (str) { - // Create new element - var el = document.createElement('textarea'); - // Set value (string to be copied) - el.value = str; - // Set non-editable to avoid focus and move outside of view - el.setAttribute('readonly', ''); - el.style = {position: 'absolute', left: '-9999px'}; - document.body.appendChild(el); - // Select text inside element - el.select(); - // Copy text to clipboard - document.execCommand('copy'); - // Remove temporary element - document.body.removeChild(el); - } + function copyStringToClipboard (str) { + // Create new element + var el = document.createElement('textarea'); + // Set value (string to be copied) + el.value = str; + // Set non-editable to avoid focus and move outside of view + el.setAttribute('readonly', ''); + el.style = {position: 'absolute', left: '-9999px'}; + document.body.appendChild(el); + // Select text inside element + el.select(); + // Copy text to clipboard + document.execCommand('copy'); + // Remove temporary element + document.body.removeChild(el); + } From bfafa906ce243c4479c5d4875be363c861e7c4c7 Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Thu, 16 Sep 2021 17:29:12 +0200 Subject: [PATCH 042/131] =?UTF-8?q?Cases=20=C3=A0=20cocher=20buy=20list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/price_documents_controller.rb | 10 ++++----- app/controllers/application_controller.rb | 21 ++++++++++--------- app/views/admin/buy_lists/index.html.haml | 5 ++++- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/app/controllers/admin/price_documents_controller.rb b/app/controllers/admin/price_documents_controller.rb index 7ca73b2..ce7b3f5 100644 --- a/app/controllers/admin/price_documents_controller.rb +++ b/app/controllers/admin/price_documents_controller.rb @@ -235,12 +235,12 @@ class Admin::PriceDocumentsController < ApplicationController @price_document.price_line_block = PriceLineBlock.new(:p_customer_id => params[:p_customer_id], :p_fournisseur_id => params[:p_fournisseur_id]) if @price_document.price_document_type.label == "Demande prix" - p_product_ref_id = params[:qte].keys - p_product_ref_qte = params[:qte].values + p_product_ref_id = params[:p_product_ref_ids] - [""] + p_product_ref_qte = params[:qte].permit!.to_hash - p_product_ref_id.each_with_index do |key, i| - if p_product_ref_qte[i].to_i > 0 - @price_document.price_line_block.price_lines << PriceLine.new(:p_product_ref_id => key, :qte => p_product_ref_qte[i]) + p_product_ref_id.each do |i| + if p_product_ref_qte[i.to_s].to_i > 0 + @price_document.price_line_block.price_lines << PriceLine.new(:p_product_ref_id => i, :qte => p_product_ref_qte[i.to_s]) end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0e10c2f..ce02913 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,7 +2,7 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception - before_action :set_current_p_customer_sheet + #before_action :set_current_p_customer_sheet @@ -33,9 +33,6 @@ class ApplicationController < ActionController::Base elsif v[:elements] v[:elements].each do |a,b| - puts "TEST" - puts b[0] - puts "B" if b[:sub_elements] and b[:sub_elements][sym.to_sym] @qi_menu_active = k @qi_menu_sub_menu_active = sym.to_sym @@ -474,13 +471,17 @@ class ApplicationController < ActionController::Base def current_admin - if cookies[:admin_remember_token] - if @current_admin = Admin.find_by_remember_token(cookies[:admin_remember_token]) - @current_admin = Admin.find_by_remember_token(cookies[:admin_remember_token]) - else - cookies[:admin_remember_token] =nil - end + if @current_admin + return @current_admin + else + if cookies[:admin_remember_token] + if @current_admin = Admin.find_by_remember_token(cookies[:admin_remember_token]) + @current_admin = Admin.find_by_remember_token(cookies[:admin_remember_token]) + else + cookies[:admin_remember_token] =nil + end + end end diff --git a/app/views/admin/buy_lists/index.html.haml b/app/views/admin/buy_lists/index.html.haml index cb6bed8..59a005d 100644 --- a/app/views/admin/buy_lists/index.html.haml +++ b/app/views/admin/buy_lists/index.html.haml @@ -72,7 +72,8 @@ =form_tag new_admin_price_document_path(), :method => "get" do =hidden_field_tag :"document_type", "Demande prix" - =hidden_field_tag :"price_line_ids[]", "" + =hidden_field_tag :"p_product_ref_ids[]", "" + .freezeTable %table.table.table-striped.table-hover.table-bordered.data_table %thead.header @@ -173,6 +174,8 @@ %td.mask = qte_available %td.mask + =check_box_tag :"p_product_ref_ids[]", plr.p_product_ref.id + =number_field_tag "qte[#{plr.p_product_ref.id}]", '', class: "small-input", value: (bpa_qte - qte_available) %td.mask From 1609c92ab70ebca77ead1025879785d54a7b3453 Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Thu, 16 Sep 2021 20:01:42 +0200 Subject: [PATCH 043/131] Popup produits --- app/assets/javascripts/manager.js | 5 ++-- .../admin/p_product_refs_controller.rb | 8 ++++++ .../admin/p_product_refs/index.html.haml | 25 +++++++++++-------- app/views/admin/p_product_refs/index.js.erb | 9 +++++++ app/views/admin/price_lines/_form.html.haml | 4 ++- app/views/qi/_qi_ordered_table.html.haml | 4 ++- 6 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 app/views/admin/p_product_refs/index.js.erb diff --git a/app/assets/javascripts/manager.js b/app/assets/javascripts/manager.js index b6b2393..861df04 100644 --- a/app/assets/javascripts/manager.js +++ b/app/assets/javascripts/manager.js @@ -240,9 +240,10 @@ function select_video_from_manager(input_id){ function select_product_from_manager(input_id){ - - manager_prompt("/admin/p_product_refs.html?manager=true",function(m_return){ + + + manager_prompt(p_product_refs_url,function(m_return){ $('.p_product_ref_id_'+input_id).val(m_return.id); $('.p_product_ref_name_'+input_id).val(m_return.name); diff --git a/app/controllers/admin/p_product_refs_controller.rb b/app/controllers/admin/p_product_refs_controller.rb index fbf5675..1f2017e 100644 --- a/app/controllers/admin/p_product_refs_controller.rb +++ b/app/controllers/admin/p_product_refs_controller.rb @@ -47,6 +47,14 @@ class Admin::PProductRefsController < ApplicationController @p_product_refs = sort_by_sorting(@p_product_refs, "id DESC") respond_to do |format| + format.js{ + + params[:search][:per_page] = params[:search][:per_page] || 100 + per_page = params[:search][:per_page] + page = (params[:page] and params[:page] != "") ? params[:page] : 1 + @p_product_refs = @p_product_refs.page(page).per(per_page) + + } format.html{ params[:search][:per_page] = params[:search][:per_page] || 100 diff --git a/app/views/admin/p_product_refs/index.html.haml b/app/views/admin/p_product_refs/index.html.haml index 9e77e44..3a3aeaf 100644 --- a/app/views/admin/p_product_refs/index.html.haml +++ b/app/views/admin/p_product_refs/index.html.haml @@ -1,17 +1,19 @@ -.qi_header - .right= link_to ic(:plus)+' Ajouter un produit', new_admin_p_product_path(), :class => "btn btn-primary btn-ap-add", :remote => false - %h1 - Achats - %span - Produits +-if !@manager + .qi_header + .right= link_to ic(:plus)+' Ajouter un produit', new_admin_p_product_path(), :class => "btn btn-primary btn-ap-add", :remote => false + %h1 + Achats + %span + Références + .qi_search_row - =form_tag "", :method => "get", :onsubmit => "" do + =form_tag admin_p_product_refs_path, :method => "get", :onsubmit => "", :remote => true do =hidden_field_tag :column, params[:column] =hidden_field_tag :direction, params[:direction] - + =hidden_field_tag :manager, params[:manager] %table %tr %td @@ -42,7 +44,7 @@ -=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @p_product_refs} +#p_product_refs_index_wrapper=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @p_product_refs, :remote => true} @@ -52,4 +54,7 @@ }); - \ No newline at end of file + +:coffeescript + $(".qi_search_row form").on "submit", -> + $("#p_product_refs_index_wrapper").html('recherche en cours ...') \ No newline at end of file diff --git a/app/views/admin/p_product_refs/index.js.erb b/app/views/admin/p_product_refs/index.js.erb new file mode 100644 index 0000000..ab3b84a --- /dev/null +++ b/app/views/admin/p_product_refs/index.js.erb @@ -0,0 +1,9 @@ + +var p_product_refs_url = "<%= escape_javascript(request.url) %>"; + + +$('#p_product_refs_index_wrapper').html("<%= escape_javascript(render(:partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @p_product_refs, :remote => true}))%>"); + + + +$(".btn-qi-search").html(' Rechercher'); \ No newline at end of file diff --git a/app/views/admin/price_lines/_form.html.haml b/app/views/admin/price_lines/_form.html.haml index 77c4f79..728e663 100644 --- a/app/views/admin/price_lines/_form.html.haml +++ b/app/views/admin/price_lines/_form.html.haml @@ -18,6 +18,9 @@ = form.hidden_field :p_product_ref_id, :class => "p_product_ref_id p_product_ref_id_#{key}" %td =link_to ic(:search), "#", class: "ml-2",:onclick => "select_product_from_manager('#{key}');return false;" + + :javascript + var p_product_refs_url = "#{admin_p_product_refs_path(:manager => true)}" -form.object.forced_price = true if form.object.ct_u_price_ht @@ -39,7 +42,6 @@ .mx-2.form-inline = form.input :qte, :label => "qte :", :input_html => {:class => "input_price_line_qte form-control mx-2", tabindex: 1} - = form.hidden_field :p_product_ref_id, :class => "p_product_ref_id" %td .form-inline %label.mx-2 Taux de TVA : diff --git a/app/views/qi/_qi_ordered_table.html.haml b/app/views/qi/_qi_ordered_table.html.haml index 79c9a48..b968bab 100644 --- a/app/views/qi/_qi_ordered_table.html.haml +++ b/app/views/qi/_qi_ordered_table.html.haml @@ -1,5 +1,7 @@ - "QI ActsAsCaching V0.6" +- remote = remote || false + -if true -masqued_columns = masqued_columns || nil @@ -183,7 +185,7 @@ .qi_pagination - = paginate qi_ordered_table_collection #, :remote => true + = paginate qi_ordered_table_collection, :remote => remote :scss From 57bac61ac9fd1bfc0f9f0fca199e52de9b59f6cc Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Fri, 17 Sep 2021 00:18:04 +0200 Subject: [PATCH 044/131] =?UTF-8?q?Bug=20recherche=20marques=20sur=20r?= =?UTF-8?q?=C3=A9f=C3=A9rences?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admin/p_product_refs_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/p_product_refs_controller.rb b/app/controllers/admin/p_product_refs_controller.rb index 1f2017e..ecec7c3 100644 --- a/app/controllers/admin/p_product_refs_controller.rb +++ b/app/controllers/admin/p_product_refs_controller.rb @@ -42,7 +42,7 @@ class Admin::PProductRefsController < ApplicationController if params[:search][:s_brand_id].to_s != "" - @p_product_refs = @p_product_refs.where(:s_brand_id => params[:search][:s_brand_id]) + @p_product_refs = @p_product_refs.where(:p_products => {:s_brand_id => params[:search][:s_brand_id]}) end @p_product_refs = sort_by_sorting(@p_product_refs, "id DESC") From 390fe5d98df68e63df268b388c68f761e35cfea6 Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Fri, 17 Sep 2021 00:18:29 +0200 Subject: [PATCH 045/131] Ergo + popup --- app/assets/javascripts/admin.coffee | 5 +- app/assets/javascripts/admin/random_hexa.js | 2 + app/assets/javascripts/manager.js | 4 +- app/assets/javascripts/nested_fields.coffee | 6 +- .../admin/price_line_blocks/_form.html.haml | 21 +- app/views/admin/price_lines/_form.html.haml | 201 ++++++++++-------- 6 files changed, 135 insertions(+), 104 deletions(-) create mode 100644 app/assets/javascripts/admin/random_hexa.js diff --git a/app/assets/javascripts/admin.coffee b/app/assets/javascripts/admin.coffee index 7a571ec..ea98f59 100644 --- a/app/assets/javascripts/admin.coffee +++ b/app/assets/javascripts/admin.coffee @@ -56,6 +56,7 @@ #= require freeze-table +#= require admin/random_hexa @@ -856,6 +857,4 @@ $(document).on 'click', '.datepicker', (e) -> $(this).next('.' + autocomplete_object + '_id').val ui.item.id return return - - - + \ No newline at end of file diff --git a/app/assets/javascripts/admin/random_hexa.js b/app/assets/javascripts/admin/random_hexa.js new file mode 100644 index 0000000..910cebf --- /dev/null +++ b/app/assets/javascripts/admin/random_hexa.js @@ -0,0 +1,2 @@ +const genRanHex = size => [...Array(size)].map(() => Math.floor(Math.random() * 16).toString(16)).join(''); + \ No newline at end of file diff --git a/app/assets/javascripts/manager.js b/app/assets/javascripts/manager.js index 861df04..561153d 100644 --- a/app/assets/javascripts/manager.js +++ b/app/assets/javascripts/manager.js @@ -245,8 +245,8 @@ function select_product_from_manager(input_id){ manager_prompt(p_product_refs_url,function(m_return){ - $('.p_product_ref_id_'+input_id).val(m_return.id); - $('.p_product_ref_name_'+input_id).val(m_return.name); + $('#p_product_ref_id_'+input_id).val(m_return.id); + $('#p_product_ref_name_'+input_id).val(m_return.name); }); diff --git a/app/assets/javascripts/nested_fields.coffee b/app/assets/javascripts/nested_fields.coffee index c589739..c0a6ca7 100644 --- a/app/assets/javascripts/nested_fields.coffee +++ b/app/assets/javascripts/nested_fields.coffee @@ -10,9 +10,11 @@ if $(link).closest("p").next("." + association + "_form").length > 0 form_element = $(link).closest("p").next("." + association + "_form") - else + else if $(link).closest("p").prev("." + association + "_form").length > 0 form_element = $(link).closest("p").prev("." + association + "_form") - + else + form_element = $(link).closest(".qi_field_wrapper").find("." + association + "_form") + form_element.append content_final $(".new_field").removeClass "new_field" diff --git a/app/views/admin/price_line_blocks/_form.html.haml b/app/views/admin/price_line_blocks/_form.html.haml index 20b07b9..8494cba 100644 --- a/app/views/admin/price_line_blocks/_form.html.haml +++ b/app/views/admin/price_line_blocks/_form.html.haml @@ -56,12 +56,23 @@ =content_for :price_lines do - .row - .price_lines_form.col-11.row - =f.semantic_fields_for :price_lines do |f| - =render :partial => "admin/price_lines/form", :locals => {:form => f} + %div{:style=>"padding:0 30px;"} + .row.qi_field_wrapper + %table{:style => "width:100%;border-collapse:separate;"} + %thead + %tr + %th + %th Produit + %th{:style => "width:200px;"} Prix + %th + %th{:style => "width:100px;"} Qté + %th TVA + %th + %tbody.price_lines_form + =f.semantic_fields_for :price_lines do |f| + =render :partial => "admin/price_lines/form", :locals => {:form => f} - %p.col-1= link_to_add_fields ic("plus-circle") + " ligne", f, :price_lines, {:class => "btn btn-primary p-2", tabindex: 10, style: "position: sticky; top: 100px"} + %p{:style=>"padding-top:10px;"}= link_to_add_fields ic("plus-circle") + " ligne", f, :price_lines, {:class => "btn btn-primary p-2", tabindex: 10, style: "position: sticky; top: 100px"} -if current_admin.has_permission?("payments") diff --git a/app/views/admin/price_lines/_form.html.haml b/app/views/admin/price_lines/_form.html.haml index 728e663..48b670c 100644 --- a/app/views/admin/price_lines/_form.html.haml +++ b/app/views/admin/price_lines/_form.html.haml @@ -1,54 +1,63 @@ +%tr.qi_pannel.qi_plain.padding.price_line_form.col-12.field{:style =>"border-left:4px solid gray;margin-bottom:10px;padding-left:5px;"} -.qi_pannel.qi_plain.padding.price_line_form.col-12.field{:style =>"border-left:4px solid gray;margin-bottom:10px;padding-left:5px;"} - = form.input :ct_title, :label => "Designation personnalisée : " if @avoir - %table - %tr - %td{:class => ("error has-error" if form.object.errors[:p_product_ref_id].size > 0 )} - .take.mr-1 - =ic :arrows - %td - - = form.input :ct_title, :label => "Designation personnalisée : " if @avoir - -key = SecureRandom.hex(6) - %label.ml-3.mr-2 Produit : - %td - %input.p_product_ref_autocomplete_input.form-control{:type => "text", tabindex: 1, autofocus: true, :value => ("#{form.object.p_product_ref.ref} #{form.object.p_product_ref.cc_name}" if form.object.p_product_ref), :class => "p_product_ref_name_#{key}"} - - - = form.hidden_field :p_product_ref_id, :class => "p_product_ref_id p_product_ref_id_#{key}" - %td - =link_to ic(:search), "#", class: "ml-2",:onclick => "select_product_from_manager('#{key}');return false;" + + %td{:style => "padding-left:10px;", :class => ("error has-error" if form.object.errors[:p_product_ref_id].size > 0 )} + .take.mr-1 + =ic :arrows + %td{:style => "white-space: nowrap;"} + + + + .input-group + %input.p_product_ref_autocomplete_input.form-control{:type => "text", :style => "", tabindex: 1, autofocus: true, :value => ("#{form.object.p_product_ref.member_label}" if form.object.p_product_ref), :class => "p_product_ref_name"} + + + + + .input-group-append + =link_to "#", class: "btn btn-dark",:onclick => "key=genRanHex(12);select_product_from_manager(key);$(this).closest('tr').find('.p_product_ref_id').attr('id', 'p_product_ref_id_'+key);$(this).closest('tr').find('.p_product_ref_name').attr('id', 'p_product_ref_name_'+key);return false;" do + =ic(:search) - :javascript - var p_product_refs_url = "#{admin_p_product_refs_path(:manager => true)}" + + + + + = form.hidden_field :p_product_ref_id, :class => "p_product_ref_id" + + + + + :javascript + var p_product_refs_url = "#{admin_p_product_refs_path(:manager => true)}" - -form.object.forced_price = true if form.object.ct_u_price_ht + -form.object.forced_price = true if form.object.ct_u_price_ht - -if form.object.forced_price and form.object.p_product_ref - %td - .mx-2 - .form-inline - =qi_js_field_price_line_form(form, :price_line, :price_u_ht, :label => "Prix U HT :", label_class: "mr-1", :value => form.object.th_price_u_ht) - -else - %td - .mx-2 - .form-inline - =qi_js_field_price_line_form(form, :price_line, :price_u_ht, :label => "Prix U HT :", label_class: "mr-1") - %td - .form-inline.mr-2{:style => ("display:none;" if !current_admin or !current_admin.has_permission?("customer-sheets-personalised-price"))} - = form.input :forced_price, :label => "Prix personnalisé ?", :as => :boolean, :input_html => {:class => "form-inline input_price_line_forced_price"} - .forced_price_wrapper.mx-2{:style => ("display:none;" if !form.object.forced_price)}= form.input :ct_u_price_ht, :label => false, :input_html => {:class => "input_price_line_ct_u_price_ht"} - %td - .mx-2.form-inline - = form.input :qte, :label => "qte :", :input_html => {:class => "input_price_line_qte form-control mx-2", tabindex: 1} - - %td + -if form.object.forced_price and form.object.p_product_ref + %td + .mx-2 .form-inline - %label.mx-2 Taux de TVA : - =select_tag :tva_account_id, options_from_collection_for_select(TvaRate.where(:accounting_zone_id => (@p_customer ? @p_customer.accounting_zone_id : nil)).all, "id", "member_label", form.object.tva_account_id), :class => "input_price_line_tva_account_id form-control custom-select" #, :disabled => true - %td - .ml-4 - %span.destroy=link_to_remove_fields ic(:"trash-o"), form + =qi_js_field_price_line_form(form, :price_line, :price_u_ht, :label => false, label_class: "mr-1", :value => form.object.th_price_u_ht) + -else + %td + .mx-2 + .form-inline + =qi_js_field_price_line_form(form, :price_line, :price_u_ht, :label =>false, label_class: "mr-1") + %td + .form-inline.mr-2{:style => ("display:none;" if !current_admin or !current_admin.has_permission?("customer-sheets-personalised-price"))} + = form.input :forced_price, :label => "Prix personnalisé ?", :as => :boolean, :input_html => {:class => "form-inline input_price_line_forced_price"} + .forced_price_wrapper.mx-2{:style => ("display:none;" if !form.object.forced_price)}= form.input :ct_u_price_ht, :label => false, :input_html => {:class => "input_price_line_ct_u_price_ht"} + %td{:style => "width:100px;"} + + = form.input :qte, :label => false, :input_html => {:class => "input_price_line_qte form-control", tabindex: 1} + + %td + + + =form.input :ct_tva_account_id, :collection => options_from_collection_for_select(TvaRate.where(:accounting_zone_id => (@p_customer ? @p_customer.accounting_zone_id : nil)).all, "id", "member_label", form.object.tva_account_id), :as => :select ,:label => false, :include_blank => false , :input_html => {:class => "input_price_line_tva_account_id form-control custom-select"} + + %td + + %span.destroy=link_to_remove_fields ic(:"trash-o"), form @@ -57,50 +66,58 @@ = form.hidden_field :position, :class => "price_line_position_input" - :javascript - $('.p_product_ref_autocomplete_input').focus() - $( function() { - $('.p_product_ref_autocomplete_input').autocomplete({ - source: function( request, response ) { - $.ajax( { - url: "/admin/p_product_refs/autocomplete.json", - dataType: "json", - data: { - search: request.term, - p_customer_id: $(".p_customer_id").val() - }, - success: function(data){ - arr = jQuery.map( data, function( item ) { - return { - label: item.member_label, - value: item.member_label, - id: item.id - } - }); - response(arr) - } - }); - }, - minLength: 2, - select: function( event, ui ) { - $(this).next(".p_product_ref_id").val(ui.item.id) - form = $(this).closest(".price_line_form") - $.ajax( { - url: "/admin/p_product_refs/"+ui.item.id+"/get_infos.json", - dataType: "json", - data: { - type: "price", - qte: form.find(".input_price_line_qte").val(), - p_customer_id: $(".p_customer_id").val() - }, - success: function (data) { - form.find(".input_price_line_price_u_ht").val(data.price); - form.find(".input_price_line_tva_account_id").val(data.tva_account_id); - form.find(".input_price_line_tva_account_value").val(data.tva_account_value); - form.find(".input_price_line_weight_u").val(data.weight); - } - }); - //return false - } - }); +:javascript + $('.p_product_ref_autocomplete_input').focus() + $( function() { + $('.p_product_ref_autocomplete_input').autocomplete({ + source: function( request, response ) { + $.ajax( { + url: "/admin/p_product_refs/autocomplete.json", + dataType: "json", + data: { + search: request.term, + p_customer_id: $(".p_customer_id").val() + }, + success: function(data){ + arr = jQuery.map( data, function( item ) { + return { + label: item.member_label, + value: item.member_label, + id: item.id + } + }); + response(arr) + } + }); + }, + minLength: 2, + select: function( event, ui ) { + $(this).next(".p_product_ref_id").val(ui.item.id) + form = $(this).closest(".price_line_form") + $.ajax( { + url: "/admin/p_product_refs/"+ui.item.id+"/get_infos.json", + dataType: "json", + data: { + type: "price", + qte: form.find(".input_price_line_qte").val(), + p_customer_id: $(".p_customer_id").val() + }, + success: function (data) { + form.find(".input_price_line_price_u_ht").val(data.price); + form.find(".input_price_line_tva_account_id").val(data.tva_account_id); + form.find(".input_price_line_tva_account_value").val(data.tva_account_value); + form.find(".input_price_line_weight_u").val(data.weight); + } + }); + //return false + } }); + }); + + +:scss + .price_line_form{ + .form-group{ + margin-bottom:0;} + + } \ No newline at end of file From a9453ab5225a9c846f79d053c86972f860c0fdad Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Fri, 17 Sep 2021 00:22:01 +0200 Subject: [PATCH 046/131] Suite (le retour) --- app/views/admin/price_line_blocks/_form.html.haml | 3 ++- app/views/admin/price_lines/_form.html.haml | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/views/admin/price_line_blocks/_form.html.haml b/app/views/admin/price_line_blocks/_form.html.haml index 8494cba..f01c327 100644 --- a/app/views/admin/price_line_blocks/_form.html.haml +++ b/app/views/admin/price_line_blocks/_form.html.haml @@ -1,5 +1,6 @@ =f.inputs do - + :javascript + var p_product_refs_url = "#{admin_p_product_refs_path(:manager => true)}" -if !@p_customer_sheet or (@p_customer_sheet and @p_customer_sheet.state != "commande") diff --git a/app/views/admin/price_lines/_form.html.haml b/app/views/admin/price_lines/_form.html.haml index 48b670c..fab597d 100644 --- a/app/views/admin/price_lines/_form.html.haml +++ b/app/views/admin/price_lines/_form.html.haml @@ -27,8 +27,6 @@ - :javascript - var p_product_refs_url = "#{admin_p_product_refs_path(:manager => true)}" -form.object.forced_price = true if form.object.ct_u_price_ht From 2f2cfb344e85747fc57972c6aee16146f4b26966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 17 Sep 2021 10:07:15 +0200 Subject: [PATCH 047/131] Focus after manager select --- app/assets/javascripts/manager.js | 2 +- app/views/admin/price_lines/_form.html.haml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/manager.js b/app/assets/javascripts/manager.js index 561153d..49a11fb 100644 --- a/app/assets/javascripts/manager.js +++ b/app/assets/javascripts/manager.js @@ -247,7 +247,7 @@ function select_product_from_manager(input_id){ $('#p_product_ref_id_'+input_id).val(m_return.id); $('#p_product_ref_name_'+input_id).val(m_return.name); - + $('#p_product_ref_qte_'+input_id).focus() }); } diff --git a/app/views/admin/price_lines/_form.html.haml b/app/views/admin/price_lines/_form.html.haml index fab597d..123ca49 100644 --- a/app/views/admin/price_lines/_form.html.haml +++ b/app/views/admin/price_lines/_form.html.haml @@ -15,7 +15,7 @@ .input-group-append - =link_to "#", class: "btn btn-dark",:onclick => "key=genRanHex(12);select_product_from_manager(key);$(this).closest('tr').find('.p_product_ref_id').attr('id', 'p_product_ref_id_'+key);$(this).closest('tr').find('.p_product_ref_name').attr('id', 'p_product_ref_name_'+key);return false;" do + =link_to "#", class: "btn btn-dark",:onclick => "key=genRanHex(12);select_product_from_manager(key);$(this).closest('tr').find('.p_product_ref_id').attr('id', 'p_product_ref_id_'+key);$(this).closest('tr').find('.p_product_ref_name').attr('id', 'p_product_ref_name_'+key);$(this).closest('tr').find('.p_product_ref_qte').attr('id', 'p_product_ref_qte_'+key);return false;" do =ic(:search) @@ -46,7 +46,7 @@ .forced_price_wrapper.mx-2{:style => ("display:none;" if !form.object.forced_price)}= form.input :ct_u_price_ht, :label => false, :input_html => {:class => "input_price_line_ct_u_price_ht"} %td{:style => "width:100px;"} - = form.input :qte, :label => false, :input_html => {:class => "input_price_line_qte form-control", tabindex: 1} + = form.input :qte, :label => false, :input_html => {:class => "input_price_line_qte form-control p_product_ref_qte", tabindex: 1} %td @@ -118,4 +118,4 @@ .form-group{ margin-bottom:0;} - } \ No newline at end of file + } From 0020ee07ec9249434c944f8a63a9ca4172634344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 17 Sep 2021 10:09:22 +0200 Subject: [PATCH 048/131] ETA date search on buylist --- app/controllers/admin/buy_lists_controller.rb | 50 ++++++++++++++----- app/views/admin/buy_lists/index.html.haml | 42 +++++++++++++--- 2 files changed, 73 insertions(+), 19 deletions(-) diff --git a/app/controllers/admin/buy_lists_controller.rb b/app/controllers/admin/buy_lists_controller.rb index 662c25d..0fb842d 100644 --- a/app/controllers/admin/buy_lists_controller.rb +++ b/app/controllers/admin/buy_lists_controller.rb @@ -33,35 +33,61 @@ class Admin::BuyListsController < ApplicationController date_regex = /^(0[1-9]|[12][0-9]|3[01])[\/](0[1-9]|1[012])[\/](19|20)\d\d$/i - params[:start] = Date.today.beginning_of_month.strftime('%d/%m/%Y') if !params[:start] + params[:cc_creation_date_start] = Date.today.beginning_of_month.strftime('%d/%m/%Y') if !params[:cc_creation_date_start] - if params[:start] and params[:start] =~ date_regex + if params[:cc_creation_date_start] and params[:cc_creation_date_start] =~ date_regex #fsfds = sdfsfd - @start = Date.parse(params[:start]).beginning_of_day - params[:start]= @start.strftime('%d/%m/%Y') + @cc_creation_date_start = Date.parse(params[:cc_creation_date_start]).beginning_of_day + params[:cc_creation_date_start]= @cc_creation_date_start.strftime('%d/%m/%Y') else - @start = nil + @cc_creation_date_start = nil end if true - params[:stop] = Date.today.end_of_month.strftime('%d/%m/%Y') if !params[:stop] + params[:cc_creation_date_stop] = Date.today.end_of_month.strftime('%d/%m/%Y') if !params[:cc_creation_date_stop] - if params[:stop].to_s != "" # and params[:stop] =~ date_regex - @stop = Date.parse(params[:stop]).end_of_day + if params[:cc_creation_date_stop].to_s != "" # and params[:stop] =~ date_regex + @cc_creation_date_stop = Date.parse(params[:cc_creation_date_stop]).end_of_day - params[:stop]= @stop.strftime('%d/%m/%Y') + params[:cc_creation_date_stop]= @cc_creation_date_stop.strftime('%d/%m/%Y') else - @stop = nil + @cc_creation_date_stop = nil end end - @price_lines = @price_lines.where("price_lines.cc_creation_date >= ?", @start) if @start - @price_lines = @price_lines.where("price_lines.cc_creation_date <= ?", @stop.end_of_day) if @stop + @price_lines = @price_lines.where("price_lines.cc_creation_date >= ?", @cc_creation_date_start) if @cc_creation_date_start + @price_lines = @price_lines.where("price_lines.cc_creation_date <= ?", @cc_creation_date_stop.end_of_day) if @cc_creation_date_stop + + params[:wish_date_start] = Date.today.beginning_of_month.strftime('%d/%m/%Y') if !params[:wish_date_start] + + if params[:wish_date_start] and params[:wish_date_start] =~ date_regex + #fsfds = sdfsfd + @wish_date_start = Date.parse(params[:wish_date_start]).beginning_of_day + params[:wish_date_start]= @wish_date_start.strftime('%d/%m/%Y') + else + @wish_date_start = nil + end + + if true + params[:wish_date_stop] = Date.today.end_of_month.strftime('%d/%m/%Y') if !params[:wish_date_stop] + if params[:wish_date_stop].to_s != "" # and params[:stop] =~ date_regex + @wish_date_stop = Date.parse(params[:wish_date_stop]).end_of_day + + params[:wish_date_stop]= @wish_date_stop.strftime('%d/%m/%Y') + + + else + @wish_date_stop = nil + end + + end + @price_lines = @price_lines.joins(:price_line_block).where("price_line_blocks.wish_date >= ?", @wish_date_start) if @wish_date_start + @price_lines = @price_lines.joins(:price_line_block).where("price_line_blocks.wish_date <= ?", @wish_date_stop.end_of_day) if @wish_date_stop respond_to do |format| format.html{ diff --git a/app/views/admin/buy_lists/index.html.haml b/app/views/admin/buy_lists/index.html.haml index 59a005d..ce0934c 100644 --- a/app/views/admin/buy_lists/index.html.haml +++ b/app/views/admin/buy_lists/index.html.haml @@ -11,20 +11,20 @@ =form_tag "", :method => "get", :onsubmit => "" do -params[:search] =params[:search] || {} - %p Date de consultation : %table %tr.form-inline %td + Date saisie commande : Début %td.input-group - =text_field_tag :start, params[:start],:class => "form-control datepicker", :placeholder => "Début" + =text_field_tag :cc_creation_date_start, params[:cc_creation_date_start],:class => "form-control datepicker", :placeholder => "Début" .input-group-append %span.input-group-text{:onclick => "$(this).prev('input').val('');"} =ic(:times) %td.pl-4 Fin %td.input-group - =text_field_tag :stop, params[:stop],:class => "form-control datepicker", :placeholder => "Fin" + =text_field_tag :cc_creation_date_stop, params[:cc_creation_date_stop],:class => "form-control datepicker", :placeholder => "Fin" .input-group-append %span.input-group-text{:onclick => "$(this).prev('input').val('');"} =ic(:times) @@ -39,17 +39,45 @@ Code client : =text_field_tag "search[p_customer_code]", params[:search][:p_customer_code],:class => "form-control" + %tr.form-inline + %td{width: "110px"} + + %td.right.mx-4 + -if @cc_creation_date_start and @cc_creation_date_stop + + =link_to "< Mois précédent",request.query_parameters.merge({cc_creation_date_start: ((@cc_creation_date_start - 1.month).beginning_of_month.strftime('%d/%m/%Y')), cc_creation_date_stop: ((@cc_creation_date_stop - 1.month).end_of_month.strftime('%d/%m/%Y'))}), :class => "btn btn-tertiary" + %td{width: "20px"} + %td.mr-auto + -if @cc_creation_date_start and @cc_creation_date_stop + =link_to "Mois suivant >",request.query_parameters.merge({cc_creation_date_start: ((@cc_creation_date_start + 1.month).beginning_of_month.strftime('%d/%m/%Y')), cc_creation_date_stop: ((@cc_creation_date_stop + 1.month).end_of_month.strftime('%d/%m/%Y'))}), :class => "btn btn-tertiary" + + %tr.form-inline + %td + Date ETA : + Début + %td.input-group + =text_field_tag :wish_date_start, params[:wish_date_start],:class => "form-control datepicker", :placeholder => "Début" + .input-group-append + %span.input-group-text{:onclick => "$(this).prev('input').val('');"} + =ic(:times) + %td.pl-4 + Fin + %td.input-group + =text_field_tag :wish_date_stop, params[:wish_date_stop],:class => "form-control datepicker", :placeholder => "Fin" + .input-group-append + %span.input-group-text{:onclick => "$(this).prev('input').val('');"} + =ic(:times) %tr.form-inline %td{width: "110px"} %td.right.mx-4 - -if @start and @stop + -if @wish_date_start and @wish_date_stop - =link_to "< Mois précédent",request.query_parameters.merge({start: ((@start - 1.month).beginning_of_month.strftime('%d/%m/%Y')), stop: ((@stop - 1.month).end_of_month.strftime('%d/%m/%Y'))}), :class => "btn btn-tertiary" + =link_to "< Mois précédent",request.query_parameters.merge({wish_date_start: ((@wish_date_start - 1.month).beginning_of_month.strftime('%d/%m/%Y')), wish_date_stop: ((@wish_date_stop - 1.month).end_of_month.strftime('%d/%m/%Y'))}), :class => "btn btn-tertiary" %td{width: "20px"} %td.mr-auto - -if @start and @stop - =link_to "Mois suivant >",request.query_parameters.merge({start: ((@start + 1.month).beginning_of_month.strftime('%d/%m/%Y')), stop: ((@stop + 1.month).end_of_month.strftime('%d/%m/%Y'))}), :class => "btn btn-tertiary" + -if @wish_date_start and @wish_date_stop + =link_to "Mois suivant >",request.query_parameters.merge({wish_date_start: ((@wish_date_start + 1.month).beginning_of_month.strftime('%d/%m/%Y')), wish_date_stop: ((@wish_date_stop + 1.month).end_of_month.strftime('%d/%m/%Y'))}), :class => "btn btn-tertiary" =link_to ic(:search)+" Rechercher", "#", :class => "btn btn-default btn-qi-search", :onclick => "$(this).closest('form').submit();$(this).html('...');return false;" From 198cdbe89813cb2efb6787540b35380d69b34014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 17 Sep 2021 10:09:46 +0200 Subject: [PATCH 049/131] typo --- app/views/admin/price_documents/show.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/admin/price_documents/show.html.haml b/app/views/admin/price_documents/show.html.haml index 0e7a91f..47c1885 100644 --- a/app/views/admin/price_documents/show.html.haml +++ b/app/views/admin/price_documents/show.html.haml @@ -193,7 +193,7 @@ %h3 Lignes de produits .mb-3 - if @price_document.cc_label == "Consultation fournisseur" - = link_to ic(:clipboard) + " Copier le text", "#", class: "btn btn-primary", "data-document" => @price_document.id, onclick: 'copyPriceLines(event)' + = link_to ic(:clipboard) + " Copier le texte", "#", class: "btn btn-primary", "data-document" => @price_document.id, onclick: 'copyPriceLines(event)' - existing_order = PriceDocument.where(doc_ref_id: @price_document.id, cc_label: "Commande achat") - if existing_order.present? @@ -392,7 +392,7 @@ = 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" - = link_to ic(:clipboard) + " Copier le text", "#", class: "btn btn-primary", "data-document" => price_document_consult.id, onclick: 'copyPriceLines(event)' + = link_to ic(:clipboard) + " Copier le texte", "#", class: "btn btn-primary", "data-document" => price_document_consult.id, onclick: 'copyPriceLines(event)' - existing_order = PriceDocument.where(doc_ref_id: price_document_consult.id, cc_label: "Commande achat") - if existing_order.present? = link_to ic(:eye) + " Afficher la commande", admin_price_document_path(existing_order.first), class: "btn btn-tertiary" From f3246d020938aa27ae09f1894b923e1e7686e6e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 17 Sep 2021 10:11:16 +0200 Subject: [PATCH 050/131] Small fixes --- app/models/price_line_block.rb | 6 ++++-- app/views/admin/buy_lists/index.html.haml | 2 +- app/views/admin/price_documents/analyse_reponses.html.haml | 1 - 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/models/price_line_block.rb b/app/models/price_line_block.rb index edfe0cb..6efcba4 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 = ["Réponse fournisseur", "Consultation fournisseur", "Facture d'achat", "Commande achat", "Demande de prix", "Bon de commande achat", "Bon de réception achat", "Facture achat", "Avoir achat"] + PURCHASE_BLOCKS = ["Réponse fournisseur", "Consultation fournisseur", "Facture d'achat", "Commande achat", "Demande prix", "Bon de commande achat", "Bon de réception achat", "Facture achat", "Avoir achat"] SALE_BLOCKS = ["Demande de commande", "Bon de commande", "Devis", "Bon de livraison", "Facture", "Avoir"] @@ -296,7 +296,9 @@ class PriceLineBlock < ApplicationRecord end def p_fournisseur_needed? - if PriceLineBlock::PURCHASE_BLOCKS.include?(self.block_type) + if ["Demande prix", "Consultation fournisseur", "Réponse fournisseur"].include?(self.block_type) + false + elsif PriceLineBlock::PURCHASE_BLOCKS.include?(self.block_type) true else false diff --git a/app/views/admin/buy_lists/index.html.haml b/app/views/admin/buy_lists/index.html.haml index ce0934c..1808240 100644 --- a/app/views/admin/buy_lists/index.html.haml +++ b/app/views/admin/buy_lists/index.html.haml @@ -204,7 +204,7 @@ %td.mask =check_box_tag :"p_product_ref_ids[]", plr.p_product_ref.id - =number_field_tag "qte[#{plr.p_product_ref.id}]", '', class: "small-input", value: (bpa_qte - qte_available) + =number_field_tag "qte[#{plr.p_product_ref.id}]", '', class: "small-input", value: ([bpa_qte - qte_available, 0].max) %td.mask = bpa_qte diff --git a/app/views/admin/price_documents/analyse_reponses.html.haml b/app/views/admin/price_documents/analyse_reponses.html.haml index 7b68000..5801960 100644 --- a/app/views/admin/price_documents/analyse_reponses.html.haml +++ b/app/views/admin/price_documents/analyse_reponses.html.haml @@ -89,7 +89,6 @@ -@price_document_responses.each do |resp| %th - =resp.id -if resp.p_fournisseur =resp.p_fournisseur.name -else From d6640ded5a3458a4b8e371d11c32cde2c8b2a1d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 17 Sep 2021 14:08:08 +0200 Subject: [PATCH 051/131] Add sorecop to p_product_ref --- app/models/p_product_ref.rb | 9 +++++++++ .../20210917115613_add_sorecop_to_p_product_refs.rb | 7 +++++++ db/schema.rb | 5 ++++- 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20210917115613_add_sorecop_to_p_product_refs.rb diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb index 07926e6..106fce6 100644 --- a/app/models/p_product_ref.rb +++ b/app/models/p_product_ref.rb @@ -48,6 +48,7 @@ class PProductRef < ApplicationRecord :actions => {:name => "Actions", :reorder => false} } + acts_as_caching :fields => [:sorecop] def not_imported? if !self.p_product or !self.p_product.imported @@ -150,4 +151,12 @@ class PProductRef < ApplicationRecord "#{self.ref} | #{self.p_product.name} - #{self.ct_sub_name} - #{self.p_product_color.name if self.p_product_color} | #{self.cat_name}" end + def ca_sorecop + if self.cc_sorecop + return self.cc_sorecop + else + "TODO Calcul sorecop" + end + end + end diff --git a/db/migrate/20210917115613_add_sorecop_to_p_product_refs.rb b/db/migrate/20210917115613_add_sorecop_to_p_product_refs.rb new file mode 100644 index 0000000..83162ee --- /dev/null +++ b/db/migrate/20210917115613_add_sorecop_to_p_product_refs.rb @@ -0,0 +1,7 @@ +class AddSorecopToPProductRefs < ActiveRecord::Migration[6.0] + def change + add_column :p_product_refs, :ca_sorecop, :decimal + add_column :p_product_refs, :cc_sorecop, :decimal + add_column :p_product_refs, :ct_sorecop, :decimal + end +end diff --git a/db/schema.rb b/db/schema.rb index 077818c..b4d95e9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_09_14_071847) do +ActiveRecord::Schema.define(version: 2021_09_17_115613) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -1793,6 +1793,9 @@ ActiveRecord::Schema.define(version: 2021_09_14_071847) do t.boolean "stocked", default: true t.text "description" t.integer "p_product_color_id" + t.decimal "ca_sorecop", precision: 10 + t.decimal "cc_sorecop", precision: 10 + t.decimal "ct_sorecop", precision: 10 end create_table "p_product_specs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| From 210ac207185ee2f8e5c20ce60b327906e7cf2742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 17 Sep 2021 14:12:23 +0200 Subject: [PATCH 052/131] add DEE to p_product_ref --- app/models/p_product_ref.rb | 10 +++++++++- db/migrate/20210917121011_add_dee_to_p_product_refs.rb | 7 +++++++ db/schema.rb | 5 ++++- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20210917121011_add_dee_to_p_product_refs.rb diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb index 106fce6..d689bac 100644 --- a/app/models/p_product_ref.rb +++ b/app/models/p_product_ref.rb @@ -48,7 +48,7 @@ class PProductRef < ApplicationRecord :actions => {:name => "Actions", :reorder => false} } - acts_as_caching :fields => [:sorecop] + acts_as_caching :fields => [:sorecop, :dee] def not_imported? if !self.p_product or !self.p_product.imported @@ -159,4 +159,12 @@ class PProductRef < ApplicationRecord end end + def ca_dee + if self.cc_dee + return self.cc_dee + else + "TODO Calcul DEE" + end + end + end diff --git a/db/migrate/20210917121011_add_dee_to_p_product_refs.rb b/db/migrate/20210917121011_add_dee_to_p_product_refs.rb new file mode 100644 index 0000000..0984648 --- /dev/null +++ b/db/migrate/20210917121011_add_dee_to_p_product_refs.rb @@ -0,0 +1,7 @@ +class AddDeeToPProductRefs < ActiveRecord::Migration[6.0] + def change + add_column :p_product_refs, :ca_dee, :decimal + add_column :p_product_refs, :cc_dee, :decimal + add_column :p_product_refs, :ct_dee, :decimal + end +end diff --git a/db/schema.rb b/db/schema.rb index b4d95e9..c81bb6b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_09_17_115613) do +ActiveRecord::Schema.define(version: 2021_09_17_121011) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -1796,6 +1796,9 @@ ActiveRecord::Schema.define(version: 2021_09_17_115613) do t.decimal "ca_sorecop", precision: 10 t.decimal "cc_sorecop", precision: 10 t.decimal "ct_sorecop", precision: 10 + t.decimal "ca_dee", precision: 10 + t.decimal "cc_dee", precision: 10 + t.decimal "ct_dee", precision: 10 end create_table "p_product_specs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| From 7dbed2374c67e59a0a69c95b61dc77f420f42da7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 17 Sep 2021 14:46:19 +0200 Subject: [PATCH 053/131] add sorecop_comment & ean --- db/migrate/20210917122153_add_ean_to_p_product_refs.rb | 5 +++++ .../20210917124338_add_sorecop_comment_to_p_product_refs.rb | 5 +++++ db/schema.rb | 4 +++- 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20210917122153_add_ean_to_p_product_refs.rb create mode 100644 db/migrate/20210917124338_add_sorecop_comment_to_p_product_refs.rb diff --git a/db/migrate/20210917122153_add_ean_to_p_product_refs.rb b/db/migrate/20210917122153_add_ean_to_p_product_refs.rb new file mode 100644 index 0000000..43bf5de --- /dev/null +++ b/db/migrate/20210917122153_add_ean_to_p_product_refs.rb @@ -0,0 +1,5 @@ +class AddEanToPProductRefs < ActiveRecord::Migration[6.0] + def change + add_column :p_product_refs, :ean, :integer + end +end diff --git a/db/migrate/20210917124338_add_sorecop_comment_to_p_product_refs.rb b/db/migrate/20210917124338_add_sorecop_comment_to_p_product_refs.rb new file mode 100644 index 0000000..3c239fb --- /dev/null +++ b/db/migrate/20210917124338_add_sorecop_comment_to_p_product_refs.rb @@ -0,0 +1,5 @@ +class AddSorecopCommentToPProductRefs < ActiveRecord::Migration[6.0] + def change + add_column :p_product_refs, :sorecop_comment, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index c81bb6b..490c94d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_09_17_121011) do +ActiveRecord::Schema.define(version: 2021_09_17_124338) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -1799,6 +1799,8 @@ ActiveRecord::Schema.define(version: 2021_09_17_121011) do t.decimal "ca_dee", precision: 10 t.decimal "cc_dee", precision: 10 t.decimal "ct_dee", precision: 10 + t.integer "ean" + t.string "sorecop_comment" end create_table "p_product_specs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| From 3720120124b08f760b6d25d4464b9f1693dbe73e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 17 Sep 2021 16:16:24 +0200 Subject: [PATCH 054/131] EAN to string + integer validation --- app/models/p_product_ref.rb | 8 +++++++- db/migrate/20210917122153_add_ean_to_p_product_refs.rb | 2 +- db/schema.rb | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb index d689bac..9ff80d1 100644 --- a/app/models/p_product_ref.rb +++ b/app/models/p_product_ref.rb @@ -18,7 +18,7 @@ class PProductRef < ApplicationRecord accepts_nested_attributes_for :p_product_ref_specs, allow_destroy: true #validates :ct_price_ht, :presence => true - + validate :ean, :is_integer has_many :p_customer_product_prices, :dependent => :destroy accepts_nested_attributes_for :p_customer_product_prices, allow_destroy: true @@ -167,4 +167,10 @@ class PProductRef < ApplicationRecord end end + def is_integer + if ean.present? && ean.match(/\A[+-]?\d+\z/).nil? + errors.add(:ean, "ne doit être composé que de chiffres") + end + end + end diff --git a/db/migrate/20210917122153_add_ean_to_p_product_refs.rb b/db/migrate/20210917122153_add_ean_to_p_product_refs.rb index 43bf5de..128e438 100644 --- a/db/migrate/20210917122153_add_ean_to_p_product_refs.rb +++ b/db/migrate/20210917122153_add_ean_to_p_product_refs.rb @@ -1,5 +1,5 @@ class AddEanToPProductRefs < ActiveRecord::Migration[6.0] def change - add_column :p_product_refs, :ean, :integer + add_column :p_product_refs, :ean, :string end end diff --git a/db/schema.rb b/db/schema.rb index 490c94d..bebdd70 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1799,7 +1799,7 @@ ActiveRecord::Schema.define(version: 2021_09_17_124338) do t.decimal "ca_dee", precision: 10 t.decimal "cc_dee", precision: 10 t.decimal "ct_dee", precision: 10 - t.integer "ean" + t.string "ean" t.string "sorecop_comment" end From 56dc686008a1e465e38ef33882471b394bb11567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 17 Sep 2021 16:31:23 +0200 Subject: [PATCH 055/131] Decimal precision --- .../20210917115613_add_sorecop_to_p_product_refs.rb | 6 +++--- .../20210917121011_add_dee_to_p_product_refs.rb | 6 +++--- db/schema.rb | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/db/migrate/20210917115613_add_sorecop_to_p_product_refs.rb b/db/migrate/20210917115613_add_sorecop_to_p_product_refs.rb index 83162ee..80e2940 100644 --- a/db/migrate/20210917115613_add_sorecop_to_p_product_refs.rb +++ b/db/migrate/20210917115613_add_sorecop_to_p_product_refs.rb @@ -1,7 +1,7 @@ class AddSorecopToPProductRefs < ActiveRecord::Migration[6.0] def change - add_column :p_product_refs, :ca_sorecop, :decimal - add_column :p_product_refs, :cc_sorecop, :decimal - add_column :p_product_refs, :ct_sorecop, :decimal + add_column :p_product_refs, :ca_sorecop, :decimal, :precision => 10, :scale => 2 + add_column :p_product_refs, :cc_sorecop, :decimal, :precision => 10, :scale => 2 + add_column :p_product_refs, :ct_sorecop, :decimal, :precision => 10, :scale => 2 end end diff --git a/db/migrate/20210917121011_add_dee_to_p_product_refs.rb b/db/migrate/20210917121011_add_dee_to_p_product_refs.rb index 0984648..ddf1f70 100644 --- a/db/migrate/20210917121011_add_dee_to_p_product_refs.rb +++ b/db/migrate/20210917121011_add_dee_to_p_product_refs.rb @@ -1,7 +1,7 @@ class AddDeeToPProductRefs < ActiveRecord::Migration[6.0] def change - add_column :p_product_refs, :ca_dee, :decimal - add_column :p_product_refs, :cc_dee, :decimal - add_column :p_product_refs, :ct_dee, :decimal + add_column :p_product_refs, :ca_dee, :decimal, :precision => 10, :scale => 2 + add_column :p_product_refs, :cc_dee, :decimal, :precision => 10, :scale => 2 + add_column :p_product_refs, :ct_dee, :decimal, :precision => 10, :scale => 2 end end diff --git a/db/schema.rb b/db/schema.rb index bebdd70..81e123a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1793,12 +1793,12 @@ ActiveRecord::Schema.define(version: 2021_09_17_124338) do t.boolean "stocked", default: true t.text "description" t.integer "p_product_color_id" - t.decimal "ca_sorecop", precision: 10 - t.decimal "cc_sorecop", precision: 10 - t.decimal "ct_sorecop", precision: 10 - t.decimal "ca_dee", precision: 10 - t.decimal "cc_dee", precision: 10 - t.decimal "ct_dee", precision: 10 + t.decimal "ca_sorecop", precision: 10, scale: 2 + t.decimal "cc_sorecop", precision: 10, scale: 2 + t.decimal "ct_sorecop", precision: 10, scale: 2 + t.decimal "ca_dee", precision: 10, scale: 2 + t.decimal "cc_dee", precision: 10, scale: 2 + t.decimal "ct_dee", precision: 10, scale: 2 t.string "ean" t.string "sorecop_comment" end From 39fe54bdad4101043420c878e589e2344ae1d3c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 17 Sep 2021 16:48:14 +0200 Subject: [PATCH 056/131] missing e in DEEE --- app/models/p_product_ref.rb | 16 +++++++++------- app/views/admin/p_product_refs/_form.html.haml | 10 ++++++++++ .../20210917121011_add_dee_to_p_product_refs.rb | 7 ------- .../20210917121011_add_deee_to_p_product_refs.rb | 7 +++++++ db/schema.rb | 6 +++--- 5 files changed, 29 insertions(+), 17 deletions(-) delete mode 100644 db/migrate/20210917121011_add_dee_to_p_product_refs.rb create mode 100644 db/migrate/20210917121011_add_deee_to_p_product_refs.rb diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb index 9ff80d1..9a7fccf 100644 --- a/app/models/p_product_ref.rb +++ b/app/models/p_product_ref.rb @@ -43,12 +43,14 @@ class PProductRef < ApplicationRecord :description => {:name => "Description"}, :ct_sub_name => {:name => "Nom référence"}, :ct_price_ht => {:name => "Prix de vente", :as => :currency}, - - + :ean => {:name => "EAN"}, + :ca_deee => {:name => "DEEE", :as => :currency}, + :ca_sorecop => {:name => "Sorecop", :as => :currency}, + :sorecop_comment => {:name => "Type de Sorecop"}, :actions => {:name => "Actions", :reorder => false} } - acts_as_caching :fields => [:sorecop, :dee] + acts_as_caching :fields => [:sorecop, :deee] def not_imported? if !self.p_product or !self.p_product.imported @@ -159,11 +161,11 @@ class PProductRef < ApplicationRecord end end - def ca_dee - if self.cc_dee - return self.cc_dee + def ca_deee + if self.cc_deee + return self.cc_deee else - "TODO Calcul DEE" + "TODO Calcul DEEE" end end diff --git a/app/views/admin/p_product_refs/_form.html.haml b/app/views/admin/p_product_refs/_form.html.haml index b7ff800..4b0b755 100644 --- a/app/views/admin/p_product_refs/_form.html.haml +++ b/app/views/admin/p_product_refs/_form.html.haml @@ -1,3 +1,4 @@ +=#debug form.object.errors.messages =# form.input :ref, :label => "Ref :" .qi_row.field .qi_pannel.qi_plain.padding @@ -19,6 +20,15 @@ %td =form.input :p_product_color_id, :label => "Couleur :", :collection => PProductColor.all, :as => :select, :include_blank => true + %td + =form.input :ct_sorecop, :label => "Sorecop personalisée :" + %td + =form.input :sorecop_comment, :label => "Type de Sorecop :" + %td + =form.input :ct_deee, :label => "DEEE personalisée :" + %td + =form.input :ean + diff --git a/db/migrate/20210917121011_add_dee_to_p_product_refs.rb b/db/migrate/20210917121011_add_dee_to_p_product_refs.rb deleted file mode 100644 index ddf1f70..0000000 --- a/db/migrate/20210917121011_add_dee_to_p_product_refs.rb +++ /dev/null @@ -1,7 +0,0 @@ -class AddDeeToPProductRefs < ActiveRecord::Migration[6.0] - def change - add_column :p_product_refs, :ca_dee, :decimal, :precision => 10, :scale => 2 - add_column :p_product_refs, :cc_dee, :decimal, :precision => 10, :scale => 2 - add_column :p_product_refs, :ct_dee, :decimal, :precision => 10, :scale => 2 - end -end diff --git a/db/migrate/20210917121011_add_deee_to_p_product_refs.rb b/db/migrate/20210917121011_add_deee_to_p_product_refs.rb new file mode 100644 index 0000000..9542490 --- /dev/null +++ b/db/migrate/20210917121011_add_deee_to_p_product_refs.rb @@ -0,0 +1,7 @@ +class AddDeeeToPProductRefs < ActiveRecord::Migration[6.0] + def change + add_column :p_product_refs, :ca_deee, :decimal, :precision => 10, :scale => 2 + add_column :p_product_refs, :cc_deee, :decimal, :precision => 10, :scale => 2 + add_column :p_product_refs, :ct_deee, :decimal, :precision => 10, :scale => 2 + end +end diff --git a/db/schema.rb b/db/schema.rb index 81e123a..5baae52 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1796,9 +1796,9 @@ ActiveRecord::Schema.define(version: 2021_09_17_124338) do t.decimal "ca_sorecop", precision: 10, scale: 2 t.decimal "cc_sorecop", precision: 10, scale: 2 t.decimal "ct_sorecop", precision: 10, scale: 2 - t.decimal "ca_dee", precision: 10, scale: 2 - t.decimal "cc_dee", precision: 10, scale: 2 - t.decimal "ct_dee", precision: 10, scale: 2 + t.decimal "ca_deee", precision: 10, scale: 2 + t.decimal "cc_deee", precision: 10, scale: 2 + t.decimal "ct_deee", precision: 10, scale: 2 t.string "ean" t.string "sorecop_comment" end From a96ab1e4b6fe073d72ac9e6ba21e2046af89e13c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 17 Sep 2021 17:05:50 +0200 Subject: [PATCH 057/131] WIP export excel p_customer_sheets --- .../admin/p_customer_sheets_controller.rb | 81 ++++++++++++++++++- .../admin/p_customer_sheets/index.html.haml | 2 +- config/routes.rb | 1 + 3 files changed, 82 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/p_customer_sheets_controller.rb b/app/controllers/admin/p_customer_sheets_controller.rb index 5729f1c..76d9edd 100644 --- a/app/controllers/admin/p_customer_sheets_controller.rb +++ b/app/controllers/admin/p_customer_sheets_controller.rb @@ -280,6 +280,85 @@ class Admin::PCustomerSheetsController < ApplicationController end - + def export_xls + @p_customer_sheets = PCustomerSheet.all + respond_to do |format| + format.csv { + @headers = ["BUID", "DATE", "NUMERO", "CLIENT", "REFERENCE", "EAN", "DESIGNATION", "QTE", "PRIX 1", "PRIX 2", "DEEE", "SORECOP", "FOURNISSEUR", "CODE ARTICLE MAG", "NomMarque", "Code Douanier", "Type SORECOP"] + @columns = [] + # PCustomerSheet.qi_table_order.each do |key, value| + # if value.instance_of? Hash + # name = value[:name] + # else + # name = value + # end + + # if name != "Actions" + # @headers << name.to_s + # @columns << key + # end + + # end + + xlsx_package = Axlsx::Package.new + wb = xlsx_package.workbook + wb.add_worksheet(name: "BASIC extract to Chronopost") do |sheet| + sheet.add_row @headers + + @p_customer_sheets.each do |p_customer_sheet| + p_customer_sheet.price_line_block.price_lines.each do |price_line| + line = [] + line << price_line.id + line << p_customer_sheet.created_at.strftime("%d/%d/%Y") + line << p_customer_sheet.id + line << p_customer_sheet.p_customer.code + " - " + p_customer_sheet.p_customer.particulars.first.organisation + line << price_line.p_product_ref.cc_name + # line << price_line.p_product_ref.cc_ean + line << price_line.p_product_ref.ean + line << price_line.p_product_ref.cc_name + + line << price_line.qte + line << price_line.cc_price_u_ht + line << price_line.ct_u_price_ht + line << price_line.p_product_ref.deee + line << price_line.p_product_ref.sorecop + # line << price_line.p_product_ref.referal_fournisseur + line << "Fournisseur" + line << "" + + line << price_line.p_product_ref.p_product.s_brand.name + line << "Code douanier" + line << price_line.p_product_ref.sorecop_comment + sheet.add_row line, types: line.map{|t| cell_type_from_value(t)} + # puts line + end + + + # @columns.each do |column| + + # if (p_customer_sheet.respond_to?("csv_"+column.to_s)) + # line << p_customer_sheet.send("csv_"+column.to_s) + # elsif (p_customer_sheet.respond_to?(column)) + # if p_customer_sheet.send(column.to_s).class.to_s == "BigDecimal" + # line << p_customer_sheet.send(column.to_s).to_s.gsub('.', ',') + # else + # line << p_customer_sheet.send(column.to_s) + # end + # else + # line << column.to_s + # end + # end + # sheet.add_row line, types: line.map{|t| cell_type_from_value(t)} + end + end + + @final_file = "#{Rails.root}/private_medias/export-inscrits-#{Time.now.to_s.to_slug}.xlsx" + + xlsx_package.serialize(@final_file) + send_file @final_file + } + end + end + end diff --git a/app/views/admin/p_customer_sheets/index.html.haml b/app/views/admin/p_customer_sheets/index.html.haml index 8657d2a..0819b93 100644 --- a/app/views/admin/p_customer_sheets/index.html.haml +++ b/app/views/admin/p_customer_sheets/index.html.haml @@ -1,7 +1,7 @@ .qi_header .right =link_to ic(:plus)+" Demande de commande", admin_p_customers_path(:offre => true), :class => "btn btn-primary btn-ap-add" - + =link_to "Export xls", export_xls_admin_p_customer_sheets_path(format: :csv) %h1 Ventes %span diff --git a/config/routes.rb b/config/routes.rb index 76ae891..a5835ca 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1053,6 +1053,7 @@ Rails.application.routes.draw do collection do get :affects get :update_stocks + get :export_xls end end From c42a3909ee7141f2dfdfed75078938b3bf471ae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 17 Sep 2021 17:50:40 +0200 Subject: [PATCH 058/131] Check if qte change + min qte = 0 --- app/views/admin/buy_lists/index.html.haml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/views/admin/buy_lists/index.html.haml b/app/views/admin/buy_lists/index.html.haml index 1808240..862b4f4 100644 --- a/app/views/admin/buy_lists/index.html.haml +++ b/app/views/admin/buy_lists/index.html.haml @@ -204,7 +204,7 @@ %td.mask =check_box_tag :"p_product_ref_ids[]", plr.p_product_ref.id - =number_field_tag "qte[#{plr.p_product_ref.id}]", '', class: "small-input", value: ([bpa_qte - qte_available, 0].max) + =number_field_tag "qte[#{plr.p_product_ref.id}]", '', class: "small-input", value: ([bpa_qte - qte_available, 0].max), min: 0 %td.mask = bpa_qte @@ -307,9 +307,11 @@ } :javascript + // TOOGLE ORDERS DETAILS - set to hidden $('.detail').hide() $('.col-detail').hide() let state = 0 + // TOGGLE ORDER LINE DETAILS $('.plus').click(function(event){ if( event.currentTarget.className == "plus") { $(event.currentTarget).removeClass('plus').addClass('minus') @@ -328,6 +330,7 @@ $('.col-detail').show() } }); + // TOOGLE ALL ORDERS DETAILS $('.plus-all').click(function(event){ if( event.currentTarget.className == "mask plus-all") { state += $('.plus').length @@ -351,6 +354,15 @@ $('.col-detail').show() } }); + // CHECK QTE IF QTE CHANGE + $('.small-input').change(function(){ + let checkbox = $(this).closest('td').find("input[type=checkbox]") + if (this.value > 0) { + checkbox.prop("checked", true) + } else { + checkbox.prop("checked", false) + } + }) From 2bf2efc6a630b3605622414b05fa683f2ab1423c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 17 Sep 2021 19:11:37 +0200 Subject: [PATCH 059/131] Redirect on price_documents --- .../admin/p_product_refs_controller.rb | 4 +- .../admin/price_documents_controller.rb | 16 ++- app/models/price_line.rb | 2 +- app/models/price_line_block.rb | 2 +- .../_form_commande_achat.html.haml | 106 ++++++++++++++++++ .../_form_facture_achat.html.haml | 106 ++++++++++++++++++ 6 files changed, 229 insertions(+), 7 deletions(-) create mode 100644 app/views/admin/price_line_blocks/_form_commande_achat.html.haml create mode 100644 app/views/admin/price_line_blocks/_form_facture_achat.html.haml diff --git a/app/controllers/admin/p_product_refs_controller.rb b/app/controllers/admin/p_product_refs_controller.rb index ecec7c3..736d823 100644 --- a/app/controllers/admin/p_product_refs_controller.rb +++ b/app/controllers/admin/p_product_refs_controller.rb @@ -106,9 +106,11 @@ class Admin::PProductRefsController < ApplicationController if @p_product_ref.update_attributes(params.require(:p_product_ref).permit!) + else - render action: "edit" + + render action: "edit" end diff --git a/app/controllers/admin/price_documents_controller.rb b/app/controllers/admin/price_documents_controller.rb index ce7b3f5..6966596 100644 --- a/app/controllers/admin/price_documents_controller.rb +++ b/app/controllers/admin/price_documents_controller.rb @@ -224,7 +224,7 @@ class Admin::PriceDocumentsController < ApplicationController def show @price_document = PriceDocument.find(params[:id]) - + @facture_achat_childrens = PriceDocument.where(doc_ref_id: @price_document.id, price_document_type: PriceDocumentType.find_by_label("Facture achat")) end def new @@ -322,7 +322,11 @@ class Admin::PriceDocumentsController < ApplicationController @price_document.date = Date.today @avoir = true if @price_document.label == "Avoir" if @price_document.save - redirect_to admin_price_documents_path(:price_document_type_id => @price_document.price_document_type_id) + if @price_document.cc_label == "Demande prix" + render action: :show + else + redirect_to admin_price_documents_path(:price_document_type_id => @price_document.price_document_type_id) + end else render action: "new" @@ -343,7 +347,11 @@ class Admin::PriceDocumentsController < ApplicationController #@price_document.unarchive_now #@price_document.archive_now - if @price_document.ref_element + if @price_document.cc_label = "Facture achat" + redirect_to [:admin, @price_document] + elsif @price_document.doc_ref_id + redirect_to [:admin, PriceDocument.find(@price_document.doc_ref_id)] + elsif @price_document.ref_element redirect_to [:admin, @price_document.ref_element] else redirect_to [:admin, @price_document] @@ -653,7 +661,7 @@ class Admin::PriceDocumentsController < ApplicationController end @final_consult = PriceDocument.where(price_document_type: PriceDocumentType.find_by_label("Consultation fournisseur")).last - redirect_to :analyse_reponses_admin_price_document + redirect_to admin_price_document_path(@price_document_demand, anchor: "consult") end def buy_order_create diff --git a/app/models/price_line.rb b/app/models/price_line.rb index 9be5aea..32e2d5b 100644 --- a/app/models/price_line.rb +++ b/app/models/price_line.rb @@ -52,7 +52,7 @@ 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) + FACTURE_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) 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) diff --git a/app/models/price_line_block.rb b/app/models/price_line_block.rb index 6efcba4..942a0ea 100644 --- a/app/models/price_line_block.rb +++ b/app/models/price_line_block.rb @@ -326,7 +326,7 @@ 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) + FACTURE_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) 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) diff --git a/app/views/admin/price_line_blocks/_form_commande_achat.html.haml b/app/views/admin/price_line_blocks/_form_commande_achat.html.haml new file mode 100644 index 0000000..dca9aea --- /dev/null +++ b/app/views/admin/price_line_blocks/_form_commande_achat.html.haml @@ -0,0 +1,106 @@ + +=f.inputs do + + + -if !@p_customer_sheet or (@p_customer_sheet and @p_customer_sheet.state != "commande") + .qi_pannel.qi_plain.padding{:style => "margin:20px 0;"} + = f.input :p_commercial_id, :label => "Commercial :", :collection => PCommercial.order(:name).all, :as => :select, :member_label => :long_name if f.object.id + + + = f.hidden_field :p_customer_id, :class => "p_customer_id" + + .p_customer_sheet_customer + + + -if f.object.p_customer and f.object.p_customer.particular + =render :partial => "admin/p_customers/apercu", :locals => {:particular => f.object.p_customer.particular} + + .addresses.row + .columns.span_6 + %h3 Adresse de facturation + + -if f.object.p_customer + =f.inputs do + = f.input :particular_bill_id, :collection => f.object.p_customer.particulars.all, :as => :select, :member_label => :address_line, :include_blank => false, :label => "Adresse de facturation" + -else + =f.inputs do + = f.input :particular_bill_id, :collection => [], :as => :select, :include_blank => false, :label => "Adresse de facturation" + + .columns.span_6 + %h3 Adresse de livraison + + -if f.object.p_customer + =f.inputs do + = f.input :particular_send_id, :collection => f.object.p_customer.particulars.all, :as => :select, :member_label => :address_line, :include_blank => false, :label => "Adresse de livraison" + -else + =f.inputs do + = f.input :particular_send_id, :collection => [], :as => :select, :include_blank => false, :label => "Adresse de facturation" + + .clear + + + %table{:style => "width:100%;"} + %tr + %td{:style => "width:50%;"} + = f.input :wish_date, :label => "Date de livraison souhaitée :", :as => :date + + %td{:style => "width:50%;"} + = f.input :ct_creation_date, :label => "Date de commande (si différente de la date de création) :", :as => :date + + + + = f.input :customer_ref, :label => "Référence commande client :" + -if current_admin.has_permission?("customer-sheets-bl") + = f.input :bl_comment, :label => "Commentaire à mettre sur le BL :", :input_html => {:style => "min-height:50px;height:50px;"} + + -if @p_customer_sheet and @p_customer_sheet.p_customer and @p_customer_sheet.p_customer.p_customer_sheet_note? + %div + %strong Notes pour les demandes de commandes pour ce client : + =simple_format @p_customer_sheet.p_customer.p_customer_sheet_note + %br + + + + + .price_lines_form + =f.semantic_fields_for :price_lines do |f| + =render :partial => "admin/price_lines/form_bon_de_reception_achat", :locals => {:form => f} + + %p= link_to_add_fields "Ajouter une ligne", f, :price_lines, {:class => "btn btn-primary"} + + + -if current_admin.has_permission?("payments") + .qi_pannel.qi_plain.padding.price_line_block_footer{:style => "margin:20px 0;"} + + -if !@p_customer_sheet or (@p_customer_sheet and @p_customer_sheet.state != "commande") + -if !@avoir + = f.input :ct_tot_discount_percent, :label => "Réduction pied de page (%) :", :input_html => {:class => "input_price_line_block_ct_tot_discount_percent"} + = f.input :ct_tot_fdp_ht, :label => "Frais de port personnalisés :" + + -if !@avoir + -if current_admin.has_permission?("customer-sheets-bl") + = f.input :ct_nbr_ship, :label => "Nombre de colis :" + + -if current_admin.has_permission?("payments") + -if !@p_customer_sheet or (@p_customer_sheet and @p_customer_sheet.state != "commande") + - if f.object.id + .qi_pannel.qi_plain.padding{:style => "margin:20px 0;"} + %h4 Paiements + + = f.input :p_payment_type_id, :label => "Type de paiement :", :include_blank => false, :collection => PPaymentType.order(:name).all, :as => :select, :input_html => {:id => "payment_type_id_select"} + + + = f.input :ct_payment_comptant, :label => "Paiement comptant nécessaire ?" + + -if false + = f.input :ct_acompte, :label => "Acompte nécessaire ?" + = f.input :ct_acompte_percent, :label => "Pourcentage d'acompte :" + + = f.input :ct_payment_delais, :label => "Délais jour de paiement :" + + -if false + = f.input :ct_payment_month_end, :label => "Fin de mois ?" + + + + diff --git a/app/views/admin/price_line_blocks/_form_facture_achat.html.haml b/app/views/admin/price_line_blocks/_form_facture_achat.html.haml new file mode 100644 index 0000000..dca9aea --- /dev/null +++ b/app/views/admin/price_line_blocks/_form_facture_achat.html.haml @@ -0,0 +1,106 @@ + +=f.inputs do + + + -if !@p_customer_sheet or (@p_customer_sheet and @p_customer_sheet.state != "commande") + .qi_pannel.qi_plain.padding{:style => "margin:20px 0;"} + = f.input :p_commercial_id, :label => "Commercial :", :collection => PCommercial.order(:name).all, :as => :select, :member_label => :long_name if f.object.id + + + = f.hidden_field :p_customer_id, :class => "p_customer_id" + + .p_customer_sheet_customer + + + -if f.object.p_customer and f.object.p_customer.particular + =render :partial => "admin/p_customers/apercu", :locals => {:particular => f.object.p_customer.particular} + + .addresses.row + .columns.span_6 + %h3 Adresse de facturation + + -if f.object.p_customer + =f.inputs do + = f.input :particular_bill_id, :collection => f.object.p_customer.particulars.all, :as => :select, :member_label => :address_line, :include_blank => false, :label => "Adresse de facturation" + -else + =f.inputs do + = f.input :particular_bill_id, :collection => [], :as => :select, :include_blank => false, :label => "Adresse de facturation" + + .columns.span_6 + %h3 Adresse de livraison + + -if f.object.p_customer + =f.inputs do + = f.input :particular_send_id, :collection => f.object.p_customer.particulars.all, :as => :select, :member_label => :address_line, :include_blank => false, :label => "Adresse de livraison" + -else + =f.inputs do + = f.input :particular_send_id, :collection => [], :as => :select, :include_blank => false, :label => "Adresse de facturation" + + .clear + + + %table{:style => "width:100%;"} + %tr + %td{:style => "width:50%;"} + = f.input :wish_date, :label => "Date de livraison souhaitée :", :as => :date + + %td{:style => "width:50%;"} + = f.input :ct_creation_date, :label => "Date de commande (si différente de la date de création) :", :as => :date + + + + = f.input :customer_ref, :label => "Référence commande client :" + -if current_admin.has_permission?("customer-sheets-bl") + = f.input :bl_comment, :label => "Commentaire à mettre sur le BL :", :input_html => {:style => "min-height:50px;height:50px;"} + + -if @p_customer_sheet and @p_customer_sheet.p_customer and @p_customer_sheet.p_customer.p_customer_sheet_note? + %div + %strong Notes pour les demandes de commandes pour ce client : + =simple_format @p_customer_sheet.p_customer.p_customer_sheet_note + %br + + + + + .price_lines_form + =f.semantic_fields_for :price_lines do |f| + =render :partial => "admin/price_lines/form_bon_de_reception_achat", :locals => {:form => f} + + %p= link_to_add_fields "Ajouter une ligne", f, :price_lines, {:class => "btn btn-primary"} + + + -if current_admin.has_permission?("payments") + .qi_pannel.qi_plain.padding.price_line_block_footer{:style => "margin:20px 0;"} + + -if !@p_customer_sheet or (@p_customer_sheet and @p_customer_sheet.state != "commande") + -if !@avoir + = f.input :ct_tot_discount_percent, :label => "Réduction pied de page (%) :", :input_html => {:class => "input_price_line_block_ct_tot_discount_percent"} + = f.input :ct_tot_fdp_ht, :label => "Frais de port personnalisés :" + + -if !@avoir + -if current_admin.has_permission?("customer-sheets-bl") + = f.input :ct_nbr_ship, :label => "Nombre de colis :" + + -if current_admin.has_permission?("payments") + -if !@p_customer_sheet or (@p_customer_sheet and @p_customer_sheet.state != "commande") + - if f.object.id + .qi_pannel.qi_plain.padding{:style => "margin:20px 0;"} + %h4 Paiements + + = f.input :p_payment_type_id, :label => "Type de paiement :", :include_blank => false, :collection => PPaymentType.order(:name).all, :as => :select, :input_html => {:id => "payment_type_id_select"} + + + = f.input :ct_payment_comptant, :label => "Paiement comptant nécessaire ?" + + -if false + = f.input :ct_acompte, :label => "Acompte nécessaire ?" + = f.input :ct_acompte_percent, :label => "Pourcentage d'acompte :" + + = f.input :ct_payment_delais, :label => "Délais jour de paiement :" + + -if false + = f.input :ct_payment_month_end, :label => "Fin de mois ?" + + + + From f17034592d9ca56ffd6acba6231fa580d479ad84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 17 Sep 2021 19:11:49 +0200 Subject: [PATCH 060/131] Update show --- .../admin/price_documents/show.html.haml | 53 +++++++++++++------ 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/app/views/admin/price_documents/show.html.haml b/app/views/admin/price_documents/show.html.haml index 47c1885..132a98c 100644 --- a/app/views/admin/price_documents/show.html.haml +++ b/app/views/admin/price_documents/show.html.haml @@ -266,6 +266,24 @@ -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" + %p=link_to "Générer la facture", facture_achat_admin_price_document_path(@price_document), :class => "btn btn-primary" + + -if @facture_achat_childrens.present? + %h3 Facture Achat + -params[:search][:per_page] = params[:search][:per_page] || 5000 + -per_page = params[:search][:per_page] + -page = (params[:page] and params[:page] != "") ? params[:page] : 1 + + -@facture_achat_childrens = @facture_achat_childrens.order("date DESC, created_at DESC") + + + -#@line_stocks = sort_by_sorting(@line_stocks, "created_at DESC") + -@facture_achat_childrens = @facture_achat_childrens.page(page).per(per_page) + %br + .clear + + =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @facture_achat_childrens} + -if @price_document.cc_label == "Commande achat" =render :partial => "admin/price_documents/relicats", :locals => {:bca => @price_document} -if false @@ -359,25 +377,9 @@ =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 - -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) - - - - - -@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"} -if @price_documents.empty? .qi_pannel.qi_plain.padding Pas de consultation générée. @@ -406,6 +408,23 @@ =f.semantic_fields_for :price_lines do |form| =render partial: "admin/price_lines/form_consult", locals: {form: form} + -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) + + + + + -@price_documents = sort_by_sorting(@price_documents, "created_at DESC") + -@price_documents = @price_documents.page(page).per(per_page) + %br + + + %h4.ml-2 Liste des consultations fournisseurs + .clear + =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @price_documents, :key => "reponses-prix-show"} From cc90aa2457f9b7480c80b1a3bedd428867c6ab6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 20 Sep 2021 15:12:14 +0200 Subject: [PATCH 061/131] checkbox checked if qte > 0 --- app/views/admin/buy_lists/index.html.haml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/admin/buy_lists/index.html.haml b/app/views/admin/buy_lists/index.html.haml index 862b4f4..de9fbbb 100644 --- a/app/views/admin/buy_lists/index.html.haml +++ b/app/views/admin/buy_lists/index.html.haml @@ -202,9 +202,10 @@ %td.mask = qte_available %td.mask - =check_box_tag :"p_product_ref_ids[]", plr.p_product_ref.id + - default_qte = [bpa_qte - qte_available, 0].max + =check_box_tag :"p_product_ref_ids[]", plr.p_product_ref.id, (true if default_qte > 0 ) - =number_field_tag "qte[#{plr.p_product_ref.id}]", '', class: "small-input", value: ([bpa_qte - qte_available, 0].max), min: 0 + =number_field_tag "qte[#{plr.p_product_ref.id}]", '', class: "small-input", value: default_qte, min: 0 %td.mask = bpa_qte From 30ad9d661d379b29e6d6d52f9aa27d20ee23c184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 20 Sep 2021 17:50:04 +0200 Subject: [PATCH 062/131] bugfix --- app/controllers/admin/price_documents_controller.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/price_documents_controller.rb b/app/controllers/admin/price_documents_controller.rb index 6966596..2eb5ca2 100644 --- a/app/controllers/admin/price_documents_controller.rb +++ b/app/controllers/admin/price_documents_controller.rb @@ -340,14 +340,13 @@ class Admin::PriceDocumentsController < ApplicationController @avoir = true if @price_document.label == "Avoir" if @price_document.update_attributes(params.require(:price_document).permit!) - if params[:public_edit].to_s == "true" @price_document.reset_for_update #@price_document.unarchive_now #@price_document.archive_now - if @price_document.cc_label = "Facture achat" + if @price_document.cc_label == "Facture achat" redirect_to [:admin, @price_document] elsif @price_document.doc_ref_id redirect_to [:admin, PriceDocument.find(@price_document.doc_ref_id)] @@ -356,6 +355,11 @@ class Admin::PriceDocumentsController < ApplicationController else redirect_to [:admin, @price_document] end + + elsif @price_document.doc_ref_id + redirect_to [:admin, PriceDocument.find(@price_document.doc_ref_id)] + elsif @price_document.ref_element + redirect_to [:admin, @price_document.ref_element] else redirect_to [:admin, @price_document] end From c74863ad27544c5ca44b9580f0b79a39c32a683c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 20 Sep 2021 19:13:46 +0200 Subject: [PATCH 063/131] p_customer_sheet Export xls --- .../admin/p_customer_sheets_controller.rb | 4 ++ app/models/p_customer_sheet.rb | 1 + .../_p_customer_sheet.html.haml | 8 ++- .../admin/p_customer_sheets/index.html.haml | 58 ++++++++++++++++++- 4 files changed, 67 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/p_customer_sheets_controller.rb b/app/controllers/admin/p_customer_sheets_controller.rb index 76d9edd..fbc5058 100644 --- a/app/controllers/admin/p_customer_sheets_controller.rb +++ b/app/controllers/admin/p_customer_sheets_controller.rb @@ -282,6 +282,10 @@ class Admin::PCustomerSheetsController < ApplicationController def export_xls @p_customer_sheets = PCustomerSheet.all + if params[:p_customer_sheet_ids].present? + @p_customer_sheets = PCustomerSheet.where(id: params[:p_customer_sheet_ids]) + end + respond_to do |format| format.csv { @headers = ["BUID", "DATE", "NUMERO", "CLIENT", "REFERENCE", "EAN", "DESIGNATION", "QTE", "PRIX 1", "PRIX 2", "DEEE", "SORECOP", "FOURNISSEUR", "CODE ARTICLE MAG", "NomMarque", "Code Douanier", "Type SORECOP"] diff --git a/app/models/p_customer_sheet.rb b/app/models/p_customer_sheet.rb index 70d1426..b09c5f4 100644 --- a/app/models/p_customer_sheet.rb +++ b/app/models/p_customer_sheet.rb @@ -40,6 +40,7 @@ class PCustomerSheet < ApplicationRecord :tot_amount_ht => {:name => "Total HT", :reorder => true, :sort_name => "cc_tot_amount_ht", :sort_name => "p_customer_sheets.cc_tot_amount_ht"}, :tot_amount_ttc => {:name => "Total TTC", :reorder => true, :sort_name => "cc_tot_amount_ttc", :sort_name => "p_customer_sheets.cc_tot_amount_ttc"}, :state => {:name => "Statut", :reorder => false, :as => :state}, + :check_box => {:name => "Export excel", :reorder => false}, :actions => {:name => "Actions", :reorder => false}, } diff --git a/app/views/admin/p_customer_sheets/_p_customer_sheet.html.haml b/app/views/admin/p_customer_sheets/_p_customer_sheet.html.haml index 5a8f2b5..7d589a3 100644 --- a/app/views/admin/p_customer_sheets/_p_customer_sheet.html.haml +++ b/app/views/admin/p_customer_sheets/_p_customer_sheet.html.haml @@ -43,9 +43,11 @@ -tr[:tot_amount_ttc] = capture do %td.numeraire =number_to_currency p_customer_sheet.cc_tot_amount_ttc - - - + + -tr[:check_box] = capture do + %td + =check_box_tag "p_customer_sheet_ids[]", p_customer_sheet.id, false, data: { client: p_customer_sheet.p_customer.id }, id: "p_customer_sheet_id_checkbox_#{p_customer_sheet.id}" + -tr[:actions] = capture do %td.actions -if p_customer_sheet.state == "brouillon" and p_customer_sheet.demande_type.to_s == "Brouillon" diff --git a/app/views/admin/p_customer_sheets/index.html.haml b/app/views/admin/p_customer_sheets/index.html.haml index 0819b93..1a14c94 100644 --- a/app/views/admin/p_customer_sheets/index.html.haml +++ b/app/views/admin/p_customer_sheets/index.html.haml @@ -179,5 +179,61 @@ ="-" =link_to ic(:times)+" Supprimer ce filtre", params.permit!.merge({ :active_kpi => nil, :p_customer_sheet_ids => nil}) +%div + =form_tag export_xls_admin_p_customer_sheets_path(format: :csv), id: 'export-form', :method => "get" do + .table + =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @p_customer_sheets} + + %button.btn.btn-primary.ml-4{onclick: "checkMultipleClient()"} + =ic("file-excel-o") + Export Xls +.modal.fade#multi-client-export{"tab-index" => "-1", "role" => "dialog", "aria-labelledby" => "Raprochement Fournisseur", "aria-hidden" => "true"} + .modal-dialog{role: "dialog"} + .modal-content + .modal-header + %h5.modal-title + Export Excel + %button.close{"data-dismiss" => "modal", "aria-label" => "Close"} + %span{"aria-hidden" => "true"} + × + .modal-body + Attention ! + %br + %br + Selection de plusieurs clients détécté + %br + Vous avez selectionné des commandes liées à différents clients. + %br + Etes-vous sûr ? + + .modal-footer + %button.btn.btn-light{"data-dismiss" => "modal"} + Annuler l'export + %button.btn.btn-primary{"data-dismiss" => "modal", onclick: "submitExport()"} + =ic("file-excel-o") + Confirmer + +:javascript + function submitExport() { + $('#export-form').submit() + } + + function checkDiff(arr) { + return arr.every(e => e == arr[0]); + } + + const checkMultipleClient = () => { + let arr = [] + $('.table input[type=checkbox]').each(function( i ) { + if ( this.checked === true) + arr.push($(this).data('client')) + }) + if (checkDiff(arr) === false) { + $('#multi-client-export').modal('show') + } else { + submitExport() + } + } + + -=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @p_customer_sheets} From c49f7e3533658206199c2a6c1e410b4205cfa4b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 20 Sep 2021 19:13:59 +0200 Subject: [PATCH 064/131] bugfix --- app/views/admin/price_documents/show.html.haml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/views/admin/price_documents/show.html.haml b/app/views/admin/price_documents/show.html.haml index 132a98c..e7b30d4 100644 --- a/app/views/admin/price_documents/show.html.haml +++ b/app/views/admin/price_documents/show.html.haml @@ -390,7 +390,11 @@ -@price_documents.each do |price_document_consult| - %h4.ml-2= price_document_consult.p_fournisseur.name + - if price_document_consult.p_fournisseur + %h4.ml-2= price_document_consult.p_fournisseur.name + - else + %h4.ml-2=link_to ic('pencil') + " rapprocher le fournisseur", match_p_fournisseur_admin_price_document_path(price_document_consult), remote: true + = 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" From d84111fe672c4e71ff48a66b20d1ffdec9f8b94d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 20 Sep 2021 19:15:56 +0200 Subject: [PATCH 065/131] remove old link --- app/views/admin/p_customer_sheets/index.html.haml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/admin/p_customer_sheets/index.html.haml b/app/views/admin/p_customer_sheets/index.html.haml index 1a14c94..ad62a4b 100644 --- a/app/views/admin/p_customer_sheets/index.html.haml +++ b/app/views/admin/p_customer_sheets/index.html.haml @@ -1,7 +1,6 @@ .qi_header .right =link_to ic(:plus)+" Demande de commande", admin_p_customers_path(:offre => true), :class => "btn btn-primary btn-ap-add" - =link_to "Export xls", export_xls_admin_p_customer_sheets_path(format: :csv) %h1 Ventes %span @@ -186,7 +185,7 @@ %button.btn.btn-primary.ml-4{onclick: "checkMultipleClient()"} =ic("file-excel-o") - Export Xls + Export xls .modal.fade#multi-client-export{"tab-index" => "-1", "role" => "dialog", "aria-labelledby" => "Raprochement Fournisseur", "aria-hidden" => "true"} .modal-dialog{role: "dialog"} .modal-content From 70826a52ca2a21b6235e3a4087b2411319b6cbcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Tue, 21 Sep 2021 09:47:45 +0200 Subject: [PATCH 066/131] udate redirects --- app/controllers/admin/price_documents_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/price_documents_controller.rb b/app/controllers/admin/price_documents_controller.rb index 2eb5ca2..b224d70 100644 --- a/app/controllers/admin/price_documents_controller.rb +++ b/app/controllers/admin/price_documents_controller.rb @@ -346,7 +346,7 @@ class Admin::PriceDocumentsController < ApplicationController #@price_document.unarchive_now #@price_document.archive_now - if @price_document.cc_label == "Facture achat" + if ["Facture achat", "Commande achat"].include?(@price_document.cc_label) redirect_to [:admin, @price_document] elsif @price_document.doc_ref_id redirect_to [:admin, PriceDocument.find(@price_document.doc_ref_id)] From bb6e89d7f1f596a93e8c20ebf6b8d5b4fa45d83b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Tue, 21 Sep 2021 10:55:22 +0200 Subject: [PATCH 067/131] add container --- .../admin/price_documents/consult.html.haml | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/app/views/admin/price_documents/consult.html.haml b/app/views/admin/price_documents/consult.html.haml index 5554f0f..840b8fd 100644 --- a/app/views/admin/price_documents/consult.html.haml +++ b/app/views/admin/price_documents/consult.html.haml @@ -30,27 +30,32 @@ =f.hidden_field :doc_ref_id =f.hidden_field :price_document_type_id - - %center= f.input :public_fournisseur_name, :label => "Nom de votre société :" + + %center + .small-container + = f.input :public_fournisseur_name, :label => "Nom de votre société :" - %p{:style => "text-align:center;font-size:1.2em;"} - Vous pouvez également indiquer votre référence interne : + %p{:style => "text-align:center;font-size:1.2em;"} + Vous pouvez également indiquer votre référence interne : - =hidden_field_tag :public_edit, params[:public_edit] + =hidden_field_tag :public_edit, params[:public_edit] - .price_line_block_form - =f.semantic_fields_for :price_line_block do |f| - %center=render :partial => "admin/price_line_blocks/form_#{f.object.block_type_slug}", :locals => {:f => f} + .price_line_block_form + =f.semantic_fields_for :price_line_block do |f| + %center=render :partial => "admin/price_line_blocks/form_#{f.object.block_type_slug}", :locals => {:f => f} %center =f.submit "sauvegarder", :class => "btn btn-primary" - +:scss + .small-container{ + max-width: 500px; + } - \ No newline at end of file + From 5a979f96dccedd5731000037a9297a0dc6f83386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 23 Sep 2021 12:36:05 +0200 Subject: [PATCH 068/131] Select all p_customer_sheets export --- app/models/p_customer_sheet.rb | 2 +- .../admin/p_customer_sheets/index.html.haml | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/models/p_customer_sheet.rb b/app/models/p_customer_sheet.rb index b09c5f4..158e723 100644 --- a/app/models/p_customer_sheet.rb +++ b/app/models/p_customer_sheet.rb @@ -40,7 +40,7 @@ class PCustomerSheet < ApplicationRecord :tot_amount_ht => {:name => "Total HT", :reorder => true, :sort_name => "cc_tot_amount_ht", :sort_name => "p_customer_sheets.cc_tot_amount_ht"}, :tot_amount_ttc => {:name => "Total TTC", :reorder => true, :sort_name => "cc_tot_amount_ttc", :sort_name => "p_customer_sheets.cc_tot_amount_ttc"}, :state => {:name => "Statut", :reorder => false, :as => :state}, - :check_box => {:name => "Export excel", :reorder => false}, + :check_box => {:name => "Export excel #{''}", :reorder => false}, :actions => {:name => "Actions", :reorder => false}, } diff --git a/app/views/admin/p_customer_sheets/index.html.haml b/app/views/admin/p_customer_sheets/index.html.haml index ad62a4b..f61d281 100644 --- a/app/views/admin/p_customer_sheets/index.html.haml +++ b/app/views/admin/p_customer_sheets/index.html.haml @@ -199,7 +199,7 @@ Attention ! %br %br - Selection de plusieurs clients détécté + Selection de plusieurs clients détéctée %br Vous avez selectionné des commandes liées à différents clients. %br @@ -213,6 +213,17 @@ Confirmer :javascript + $("#check-all").parent().on("click", function(event) { + console.log(event.currentTarget) + event.currentTarget.classList.toggle("checked") + if(event.currentTarget.classList.contains("checked")){ + $('.table input[type=checkbox]').prop("checked", true) + }else{ + $('.table input[type=checkbox]').prop("checked", false) + } + }) + + "#dataTable tbody tr" function submitExport() { $('#export-form').submit() } @@ -235,4 +246,9 @@ } +:scss + th > i { + cursor: pointer; + } + From d9b76dfae9fe2c7cdaaacdd38fd864c1a04379e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 23 Sep 2021 17:48:13 +0200 Subject: [PATCH 069/131] remove fake marge --- app/views/admin/price_documents/analyse_reponses.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/admin/price_documents/analyse_reponses.html.haml b/app/views/admin/price_documents/analyse_reponses.html.haml index 5801960..8627aca 100644 --- a/app/views/admin/price_documents/analyse_reponses.html.haml +++ b/app/views/admin/price_documents/analyse_reponses.html.haml @@ -2,7 +2,7 @@ %h1 Achats %span - Analyse des réponces à la consiltation n° + Analyse des réponces à la demande de prix n° = link_to @price_document.d_number, admin_price_document_path(@price_document) \- = @price_document.list_designaton @@ -175,7 +175,7 @@ - cell << "PA: #{line.ct_u_price_ht} €" - # mp = calcul de la marge prévisionelle TODO - line.id.odd? ? mp = 0.17 : mp = 0.11 - - if mp.present? + - if false -if mp > 0.15 - cell << "#{ic(:check)} MP: #{mp * 100} %" -else From 8e7442dcc044b9c14005d2413357a358b4a3d166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 23 Sep 2021 17:51:41 +0200 Subject: [PATCH 070/131] filter consult --- app/views/admin/price_documents/show.html.haml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/admin/price_documents/show.html.haml b/app/views/admin/price_documents/show.html.haml index e7b30d4..1f7bc6a 100644 --- a/app/views/admin/price_documents/show.html.haml +++ b/app/views/admin/price_documents/show.html.haml @@ -376,6 +376,7 @@ .clear =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @price_documents, :key => "reponses-prix-show"} + -@price_documents = PriceDocument.where(:doc_ref_id => @price_document.id, :price_document_type_id => PriceDocumentType.find_by_label("Consultation fournisseur").id) %h3.ml-2 Consultations fournisseur : #consult From a9a5e222513c46236d77b2aed0bb3301c6cee330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 23 Sep 2021 18:19:47 +0200 Subject: [PATCH 071/131] g qis sorecop_cats --- .../admin/sorecop_cats_controller.rb | 76 +++++++++++++++++++ app/models/sorecop_cat.rb | 2 + app/views/admin/sorecop_cats/_form.html.haml | 12 +++ .../admin/sorecop_cats/_sorecop_cat.html.haml | 16 ++++ app/views/admin/sorecop_cats/create.js.erb | 2 + app/views/admin/sorecop_cats/destroy.js.erb | 1 + app/views/admin/sorecop_cats/edit.js.erb | 1 + app/views/admin/sorecop_cats/index.html.haml | 16 ++++ app/views/admin/sorecop_cats/new.js.erb | 1 + app/views/admin/sorecop_cats/show.html.haml | 10 +++ app/views/admin/sorecop_cats/update.js.erb | 2 + config/routes.rb | 11 +++ .../20210923161914_create_sorecop_cats.rb | 9 +++ test/fixtures/sorecop_cats.yml | 7 ++ test/models/sorecop_cat_test.rb | 7 ++ 15 files changed, 173 insertions(+) create mode 100644 app/controllers/admin/sorecop_cats_controller.rb create mode 100644 app/models/sorecop_cat.rb create mode 100644 app/views/admin/sorecop_cats/_form.html.haml create mode 100644 app/views/admin/sorecop_cats/_sorecop_cat.html.haml create mode 100644 app/views/admin/sorecop_cats/create.js.erb create mode 100644 app/views/admin/sorecop_cats/destroy.js.erb create mode 100644 app/views/admin/sorecop_cats/edit.js.erb create mode 100644 app/views/admin/sorecop_cats/index.html.haml create mode 100644 app/views/admin/sorecop_cats/new.js.erb create mode 100644 app/views/admin/sorecop_cats/show.html.haml create mode 100644 app/views/admin/sorecop_cats/update.js.erb create mode 100644 db/migrate/20210923161914_create_sorecop_cats.rb create mode 100644 test/fixtures/sorecop_cats.yml create mode 100644 test/models/sorecop_cat_test.rb diff --git a/app/controllers/admin/sorecop_cats_controller.rb b/app/controllers/admin/sorecop_cats_controller.rb new file mode 100644 index 0000000..9a0803e --- /dev/null +++ b/app/controllers/admin/sorecop_cats_controller.rb @@ -0,0 +1,76 @@ +# -*- encoding : utf-8 -*- + +class Admin::SorecopCatsController < ApplicationController + layout "admin" + before_action :auth_admin + + before_action :admin_space + + def admin_space + @admin_space = "default" + end + + def index + @sorecop_cats = SorecopCat.all + + @sorecop_cats = sort_by_sorting(@sorecop_cats, "id DESC") + respond_to do |format| + format.html{ + + params[:search][:per_page] = params[:search][:per_page] || 100 + per_page = params[:search][:per_page] + page = (params[:page] and params[:page] != "") ? params[:page] : 1 + @sorecop_cats = @sorecop_cats.page(page).per(per_page) + + } + end + end + + def show + @sorecop_cat = SorecopCat.find(params[:id]) + + end + + def new + @sorecop_cat = SorecopCat.new + + end + + def edit + @sorecop_cat = SorecopCat.find(params[:id]) + + end + + def create + @sorecop_cat = SorecopCat.new(params.require(:sorecop_cat).permit!) + + if @sorecop_cat.save + + else + render action: "new" + + end + + end + + + def update + @sorecop_cat = SorecopCat.find(params[:id]) + + + if @sorecop_cat.update_attributes(params.require(:sorecop_cat).permit!) + + else + render action: "edit" + + end + + end + + + def destroy + @sorecop_cat = SorecopCat.find(params[:id]) + @sorecop_cat.destroy + + end +end diff --git a/app/models/sorecop_cat.rb b/app/models/sorecop_cat.rb new file mode 100644 index 0000000..be69dba --- /dev/null +++ b/app/models/sorecop_cat.rb @@ -0,0 +1,2 @@ +class SorecopCat < ApplicationRecord +end diff --git a/app/views/admin/sorecop_cats/_form.html.haml b/app/views/admin/sorecop_cats/_form.html.haml new file mode 100644 index 0000000..92adc9a --- /dev/null +++ b/app/views/admin/sorecop_cats/_form.html.haml @@ -0,0 +1,12 @@ +=semantic_form_for [:admin, @sorecop_cat], :remote => true do |f| + + .content + =f.inputs do + = f.input :name, :label => f.object.label_for(:name) + + + + + + .actions=f.submit "sauvegarder", :class => "btn btn-primary" + \ No newline at end of file diff --git a/app/views/admin/sorecop_cats/_sorecop_cat.html.haml b/app/views/admin/sorecop_cats/_sorecop_cat.html.haml new file mode 100644 index 0000000..f7c3aa2 --- /dev/null +++ b/app/views/admin/sorecop_cats/_sorecop_cat.html.haml @@ -0,0 +1,16 @@ +%tr#sorecop_cat_row{:id => sorecop_cat.id} + -tr = {} + + -tr[:actions] = capture do + %td.actions + = link_to i(:"trash-o"), [:admin, sorecop_cat], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true + = link_to i(:pencil), edit_admin_sorecop_cat_path(sorecop_cat), :remote => true + = link_to i(:eye), admin_sorecop_cat_path(sorecop_cat), :remote => true + + + + =render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => sorecop_cat} + + + + \ No newline at end of file diff --git a/app/views/admin/sorecop_cats/create.js.erb b/app/views/admin/sorecop_cats/create.js.erb new file mode 100644 index 0000000..5b32752 --- /dev/null +++ b/app/views/admin/sorecop_cats/create.js.erb @@ -0,0 +1,2 @@ +$('#sorecop_cats_rows').prepend("<%= escape_javascript(render(@sorecop_cat))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/app/views/admin/sorecop_cats/destroy.js.erb b/app/views/admin/sorecop_cats/destroy.js.erb new file mode 100644 index 0000000..53582e6 --- /dev/null +++ b/app/views/admin/sorecop_cats/destroy.js.erb @@ -0,0 +1 @@ +$('#sorecop_cat_row_<%= @sorecop_cat.id %>').remove(); \ No newline at end of file diff --git a/app/views/admin/sorecop_cats/edit.js.erb b/app/views/admin/sorecop_cats/edit.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/sorecop_cats/edit.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/sorecop_cats/index.html.haml b/app/views/admin/sorecop_cats/index.html.haml new file mode 100644 index 0000000..635f57b --- /dev/null +++ b/app/views/admin/sorecop_cats/index.html.haml @@ -0,0 +1,16 @@ +.qi_header + .right= link_to ic(:plus)+' Ajouter', new_admin_sorecop_cat_path(), :class => "btn btn-primary btn-ap-add", :remote => true + %h1 + =SorecopCat.human rescue "" + + + +.qi_search_row + =form_tag "", :method => "get", :onsubmit => "" do + =render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @sorecop_cats} + + +=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @sorecop_cats} + + + diff --git a/app/views/admin/sorecop_cats/new.js.erb b/app/views/admin/sorecop_cats/new.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/sorecop_cats/new.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/sorecop_cats/show.html.haml b/app/views/admin/sorecop_cats/show.html.haml new file mode 100644 index 0000000..764b0b5 --- /dev/null +++ b/app/views/admin/sorecop_cats/show.html.haml @@ -0,0 +1,10 @@ +.qi_header + %h1 + + %span + + + +.qi_row + .qi_pannel.qi_plain.padding + =debug @sorecop_cat \ No newline at end of file diff --git a/app/views/admin/sorecop_cats/update.js.erb b/app/views/admin/sorecop_cats/update.js.erb new file mode 100644 index 0000000..3fe7cb0 --- /dev/null +++ b/app/views/admin/sorecop_cats/update.js.erb @@ -0,0 +1,2 @@ +$('#sorecop_cat_row_<%= @sorecop_cat.id %>').replaceWith("<%= escape_javascript(render(@sorecop_cat))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index a5835ca..bb3e0c3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,16 @@ Rails.application.routes.draw do + namespace :admin do + resources :sorecop_cats do + member do + + end + collection do + + end + end + end + namespace :admin do resources :price_line_resp_selects do member do diff --git a/db/migrate/20210923161914_create_sorecop_cats.rb b/db/migrate/20210923161914_create_sorecop_cats.rb new file mode 100644 index 0000000..4679ff6 --- /dev/null +++ b/db/migrate/20210923161914_create_sorecop_cats.rb @@ -0,0 +1,9 @@ +class CreateSorecopCats < ActiveRecord::Migration[6.0] + def change + create_table :sorecop_cats do |t| + t.string :name + + t.timestamps + end + end +end diff --git a/test/fixtures/sorecop_cats.yml b/test/fixtures/sorecop_cats.yml new file mode 100644 index 0000000..7d41224 --- /dev/null +++ b/test/fixtures/sorecop_cats.yml @@ -0,0 +1,7 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + +two: + name: MyString diff --git a/test/models/sorecop_cat_test.rb b/test/models/sorecop_cat_test.rb new file mode 100644 index 0000000..2daceaa --- /dev/null +++ b/test/models/sorecop_cat_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SorecopCatTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From 91dc7a86317643fd6314cab9290506855052149d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 23 Sep 2021 18:52:52 +0200 Subject: [PATCH 072/131] g qis sorecop_taxes --- .../admin/sorecop_taxes_controller.rb | 76 +++++++++++++++++++ app/models/sorecop_tax.rb | 3 + app/views/admin/sorecop_taxes/_form.html.haml | 16 ++++ .../sorecop_taxes/_sorecop_tax.html.haml | 16 ++++ app/views/admin/sorecop_taxes/create.js.erb | 2 + app/views/admin/sorecop_taxes/destroy.js.erb | 1 + app/views/admin/sorecop_taxes/edit.js.erb | 1 + app/views/admin/sorecop_taxes/index.html.haml | 16 ++++ app/views/admin/sorecop_taxes/new.js.erb | 1 + app/views/admin/sorecop_taxes/show.html.haml | 10 +++ app/views/admin/sorecop_taxes/update.js.erb | 2 + config/routes.rb | 11 +++ .../20210923165046_create_sorecop_taxes.rb | 13 ++++ test/fixtures/sorecop_taxes.yml | 15 ++++ test/models/sorecop_tax_test.rb | 7 ++ 15 files changed, 190 insertions(+) create mode 100644 app/controllers/admin/sorecop_taxes_controller.rb create mode 100644 app/models/sorecop_tax.rb create mode 100644 app/views/admin/sorecop_taxes/_form.html.haml create mode 100644 app/views/admin/sorecop_taxes/_sorecop_tax.html.haml create mode 100644 app/views/admin/sorecop_taxes/create.js.erb create mode 100644 app/views/admin/sorecop_taxes/destroy.js.erb create mode 100644 app/views/admin/sorecop_taxes/edit.js.erb create mode 100644 app/views/admin/sorecop_taxes/index.html.haml create mode 100644 app/views/admin/sorecop_taxes/new.js.erb create mode 100644 app/views/admin/sorecop_taxes/show.html.haml create mode 100644 app/views/admin/sorecop_taxes/update.js.erb create mode 100644 db/migrate/20210923165046_create_sorecop_taxes.rb create mode 100644 test/fixtures/sorecop_taxes.yml create mode 100644 test/models/sorecop_tax_test.rb diff --git a/app/controllers/admin/sorecop_taxes_controller.rb b/app/controllers/admin/sorecop_taxes_controller.rb new file mode 100644 index 0000000..a67105b --- /dev/null +++ b/app/controllers/admin/sorecop_taxes_controller.rb @@ -0,0 +1,76 @@ +# -*- encoding : utf-8 -*- + +class Admin::SorecopTaxesController < ApplicationController + layout "admin" + before_action :auth_admin + + before_action :admin_space + + def admin_space + @admin_space = "default" + end + + def index + @sorecop_taxes = SorecopTax.all + + @sorecop_taxes = sort_by_sorting(@sorecop_taxes, "id DESC") + respond_to do |format| + format.html{ + + params[:search][:per_page] = params[:search][:per_page] || 100 + per_page = params[:search][:per_page] + page = (params[:page] and params[:page] != "") ? params[:page] : 1 + @sorecop_taxes = @sorecop_taxes.page(page).per(per_page) + + } + end + end + + def show + @sorecop_tax = SorecopTax.find(params[:id]) + + end + + def new + @sorecop_tax = SorecopTax.new + + end + + def edit + @sorecop_tax = SorecopTax.find(params[:id]) + + end + + def create + @sorecop_tax = SorecopTax.new(params.require(:sorecop_tax).permit!) + + if @sorecop_tax.save + + else + render action: "new" + + end + + end + + + def update + @sorecop_tax = SorecopTax.find(params[:id]) + + + if @sorecop_tax.update_attributes(params.require(:sorecop_tax).permit!) + + else + render action: "edit" + + end + + end + + + def destroy + @sorecop_tax = SorecopTax.find(params[:id]) + @sorecop_tax.destroy + + end +end diff --git a/app/models/sorecop_tax.rb b/app/models/sorecop_tax.rb new file mode 100644 index 0000000..9fb2cd7 --- /dev/null +++ b/app/models/sorecop_tax.rb @@ -0,0 +1,3 @@ +class SorecopTax < ApplicationRecord + belongs_to :sorecop_cat_id +end diff --git a/app/views/admin/sorecop_taxes/_form.html.haml b/app/views/admin/sorecop_taxes/_form.html.haml new file mode 100644 index 0000000..389bbe6 --- /dev/null +++ b/app/views/admin/sorecop_taxes/_form.html.haml @@ -0,0 +1,16 @@ +=semantic_form_for [:admin, @sorecop_tax], :remote => true do |f| + + .content + =f.inputs do + = f.input :critere_min, :label => f.object.label_for(:critere_min) + = f.input :critere_max, :label => f.object.label_for(:critere_max) + = f.input :title, :label => f.object.label_for(:title) + = f.input :fixed_price, :label => f.object.label_for(:fixed_price) + = f.input :sorecop_cat_id, :label => f.object.label_for(:sorecop_cat_id) + + + + + + .actions=f.submit "sauvegarder", :class => "btn btn-primary" + \ No newline at end of file diff --git a/app/views/admin/sorecop_taxes/_sorecop_tax.html.haml b/app/views/admin/sorecop_taxes/_sorecop_tax.html.haml new file mode 100644 index 0000000..4a318ec --- /dev/null +++ b/app/views/admin/sorecop_taxes/_sorecop_tax.html.haml @@ -0,0 +1,16 @@ +%tr#sorecop_tax_row{:id => sorecop_tax.id} + -tr = {} + + -tr[:actions] = capture do + %td.actions + = link_to i(:"trash-o"), [:admin, sorecop_tax], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true + = link_to i(:pencil), edit_admin_sorecop_tax_path(sorecop_tax), :remote => true + = link_to i(:eye), admin_sorecop_tax_path(sorecop_tax), :remote => true + + + + =render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => sorecop_tax} + + + + \ No newline at end of file diff --git a/app/views/admin/sorecop_taxes/create.js.erb b/app/views/admin/sorecop_taxes/create.js.erb new file mode 100644 index 0000000..a917ef3 --- /dev/null +++ b/app/views/admin/sorecop_taxes/create.js.erb @@ -0,0 +1,2 @@ +$('#sorecop_taxes_rows').prepend("<%= escape_javascript(render(@sorecop_tax))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/app/views/admin/sorecop_taxes/destroy.js.erb b/app/views/admin/sorecop_taxes/destroy.js.erb new file mode 100644 index 0000000..527b1f6 --- /dev/null +++ b/app/views/admin/sorecop_taxes/destroy.js.erb @@ -0,0 +1 @@ +$('#sorecop_tax_row_<%= @sorecop_tax.id %>').remove(); \ No newline at end of file diff --git a/app/views/admin/sorecop_taxes/edit.js.erb b/app/views/admin/sorecop_taxes/edit.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/sorecop_taxes/edit.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/sorecop_taxes/index.html.haml b/app/views/admin/sorecop_taxes/index.html.haml new file mode 100644 index 0000000..90d80c4 --- /dev/null +++ b/app/views/admin/sorecop_taxes/index.html.haml @@ -0,0 +1,16 @@ +.qi_header + .right= link_to ic(:plus)+' Ajouter', new_admin_sorecop_tax_path(), :class => "btn btn-primary btn-ap-add", :remote => true + %h1 + =SorecopTax.human rescue "" + + + +.qi_search_row + =form_tag "", :method => "get", :onsubmit => "" do + =render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @sorecop_taxes} + + +=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @sorecop_taxes} + + + diff --git a/app/views/admin/sorecop_taxes/new.js.erb b/app/views/admin/sorecop_taxes/new.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/sorecop_taxes/new.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/sorecop_taxes/show.html.haml b/app/views/admin/sorecop_taxes/show.html.haml new file mode 100644 index 0000000..cb114cd --- /dev/null +++ b/app/views/admin/sorecop_taxes/show.html.haml @@ -0,0 +1,10 @@ +.qi_header + %h1 + + %span + + + +.qi_row + .qi_pannel.qi_plain.padding + =debug @sorecop_tax \ No newline at end of file diff --git a/app/views/admin/sorecop_taxes/update.js.erb b/app/views/admin/sorecop_taxes/update.js.erb new file mode 100644 index 0000000..0d6db14 --- /dev/null +++ b/app/views/admin/sorecop_taxes/update.js.erb @@ -0,0 +1,2 @@ +$('#sorecop_tax_row_<%= @sorecop_tax.id %>').replaceWith("<%= escape_javascript(render(@sorecop_tax))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index bb3e0c3..3543334 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,16 @@ Rails.application.routes.draw do + namespace :admin do + resources :sorecop_taxes do + member do + + end + collection do + + end + end + end + namespace :admin do resources :sorecop_cats do member do diff --git a/db/migrate/20210923165046_create_sorecop_taxes.rb b/db/migrate/20210923165046_create_sorecop_taxes.rb new file mode 100644 index 0000000..c272193 --- /dev/null +++ b/db/migrate/20210923165046_create_sorecop_taxes.rb @@ -0,0 +1,13 @@ +class CreateSorecopTaxes < ActiveRecord::Migration[6.0] + def change + create_table :sorecop_taxes do |t| + t.decimal :critere_min + t.decimal :critere_max + t.string :title + t.boolean :fixed_price + t.references :sorecop_cat_id, foreign_key: true + + t.timestamps + end + end +end diff --git a/test/fixtures/sorecop_taxes.yml b/test/fixtures/sorecop_taxes.yml new file mode 100644 index 0000000..f3c9843 --- /dev/null +++ b/test/fixtures/sorecop_taxes.yml @@ -0,0 +1,15 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + critere_min: 9.99 + critere_max: 9.99 + title: MyString + fixed_price: false + sorecop_cat_id: one + +two: + critere_min: 9.99 + critere_max: 9.99 + title: MyString + fixed_price: false + sorecop_cat_id: two diff --git a/test/models/sorecop_tax_test.rb b/test/models/sorecop_tax_test.rb new file mode 100644 index 0000000..afb017b --- /dev/null +++ b/test/models/sorecop_tax_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SorecopTaxTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From 07014ae159ac78012296e3bedcbd2a081c2aace2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 23 Sep 2021 18:58:09 +0200 Subject: [PATCH 073/131] typo fix --- .../20210923165046_create_sorecop_taxes.rb | 8 ++++---- db/schema.rb | 20 ++++++++++++++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/db/migrate/20210923165046_create_sorecop_taxes.rb b/db/migrate/20210923165046_create_sorecop_taxes.rb index c272193..bbeeaff 100644 --- a/db/migrate/20210923165046_create_sorecop_taxes.rb +++ b/db/migrate/20210923165046_create_sorecop_taxes.rb @@ -1,11 +1,11 @@ class CreateSorecopTaxes < ActiveRecord::Migration[6.0] def change create_table :sorecop_taxes do |t| - t.decimal :critere_min - t.decimal :critere_max + t.decimal :critere_min, :precision => 10, :scale => 2 + t.decimal :critere_max, :precision => 10, :scale => 2 t.string :title - t.boolean :fixed_price - t.references :sorecop_cat_id, foreign_key: true + t.boolean :fixed_price, default: true + t.references :sorecop_cats, foreign_key: true t.timestamps end diff --git a/db/schema.rb b/db/schema.rb index 5baae52..abb4522 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_09_17_124338) do +ActiveRecord::Schema.define(version: 2021_09_23_165046) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -2754,6 +2754,23 @@ ActiveRecord::Schema.define(version: 2021_09_17_124338) do t.decimal "ac_remise", precision: 14, scale: 2 end + create_table "sorecop_cats", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| + t.string "name" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + + create_table "sorecop_taxes", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| + t.decimal "critere_min", precision: 10, scale: 2 + t.decimal "critere_max", precision: 10, scale: 2 + t.string "title" + t.boolean "fixed_price", default: true + t.bigint "sorecop_cats_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["sorecop_cats_id"], name: "index_sorecop_taxes_on_sorecop_cats_id" + end + create_table "specific_preferences", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "key" t.string "value" @@ -3176,6 +3193,7 @@ ActiveRecord::Schema.define(version: 2021_09_17_124338) do add_foreign_key "partition_lines", "partitions" add_foreign_key "partitions", "admins" add_foreign_key "s_modules", "s_modules_states" + add_foreign_key "sorecop_taxes", "sorecop_cats", column: "sorecop_cats_id" add_foreign_key "stat_lines", "p_commercials" add_foreign_key "stat_lines", "p_customers" add_foreign_key "stat_lines", "p_product_refs" From 7a5e27685caa173b57769396a59e517b2b51dcc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 23 Sep 2021 19:55:56 +0200 Subject: [PATCH 074/131] update migration --- db/migrate/20210923165046_create_sorecop_taxes.rb | 7 ++++--- ...10923170130_add_sorecop_cat_id_to_p_product_refs.rb | 5 +++++ db/schema.rb | 10 ++++++---- 3 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 db/migrate/20210923170130_add_sorecop_cat_id_to_p_product_refs.rb diff --git a/db/migrate/20210923165046_create_sorecop_taxes.rb b/db/migrate/20210923165046_create_sorecop_taxes.rb index bbeeaff..1bf6e8b 100644 --- a/db/migrate/20210923165046_create_sorecop_taxes.rb +++ b/db/migrate/20210923165046_create_sorecop_taxes.rb @@ -1,11 +1,12 @@ class CreateSorecopTaxes < ActiveRecord::Migration[6.0] def change create_table :sorecop_taxes do |t| - t.decimal :critere_min, :precision => 10, :scale => 2 - t.decimal :critere_max, :precision => 10, :scale => 2 + t.decimal :critere_min, precision: 10, scale: 2 + t.decimal :critere_max, precision: 10, scale: 2 t.string :title t.boolean :fixed_price, default: true - t.references :sorecop_cats, foreign_key: true + t.decimal :price, precision: 10, scale: 2 + t.references :sorecop_cat, foreign_key: true t.timestamps end diff --git a/db/migrate/20210923170130_add_sorecop_cat_id_to_p_product_refs.rb b/db/migrate/20210923170130_add_sorecop_cat_id_to_p_product_refs.rb new file mode 100644 index 0000000..b4d65a9 --- /dev/null +++ b/db/migrate/20210923170130_add_sorecop_cat_id_to_p_product_refs.rb @@ -0,0 +1,5 @@ +class AddSorecopCatIdToPProductRefs < ActiveRecord::Migration[6.0] + def change + add_column :p_product_refs, :sorecop_cat_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index abb4522..5e36bad 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_09_23_165046) do +ActiveRecord::Schema.define(version: 2021_09_23_170130) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -1801,6 +1801,7 @@ ActiveRecord::Schema.define(version: 2021_09_23_165046) do t.decimal "ct_deee", precision: 10, scale: 2 t.string "ean" t.string "sorecop_comment" + t.integer "sorecop_cat_id" end create_table "p_product_specs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| @@ -2765,10 +2766,11 @@ ActiveRecord::Schema.define(version: 2021_09_23_165046) do t.decimal "critere_max", precision: 10, scale: 2 t.string "title" t.boolean "fixed_price", default: true - t.bigint "sorecop_cats_id" + t.decimal "price", precision: 10, scale: 2 + t.bigint "sorecop_cat_id" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false - t.index ["sorecop_cats_id"], name: "index_sorecop_taxes_on_sorecop_cats_id" + t.index ["sorecop_cat_id"], name: "index_sorecop_taxes_on_sorecop_cat_id" end create_table "specific_preferences", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| @@ -3193,7 +3195,7 @@ ActiveRecord::Schema.define(version: 2021_09_23_165046) do add_foreign_key "partition_lines", "partitions" add_foreign_key "partitions", "admins" add_foreign_key "s_modules", "s_modules_states" - add_foreign_key "sorecop_taxes", "sorecop_cats", column: "sorecop_cats_id" + add_foreign_key "sorecop_taxes", "sorecop_cats" add_foreign_key "stat_lines", "p_commercials" add_foreign_key "stat_lines", "p_customers" add_foreign_key "stat_lines", "p_product_refs" From 0246cf966e66fc154c0f5098d01ecc5c476a97f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 23 Sep 2021 19:56:51 +0200 Subject: [PATCH 075/131] menu & forms --- app/controllers/application_controller.rb | 4 +++- app/models/p_product_ref.rb | 3 ++- app/models/sorecop_cat.rb | 8 ++++++++ app/models/sorecop_tax.rb | 14 +++++++++++++- app/views/admin/sorecop_taxes/_form.html.haml | 16 +++++++++------- .../admin/sorecop_taxes/_sorecop_tax.html.haml | 7 ++++++- 6 files changed, 41 insertions(+), 11 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ce02913..6441a74 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -126,7 +126,9 @@ class ApplicationController < ActionController::Base set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_grades, "Grades" if PGrade::ACTIVATED set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_product_powers, "Types de chargeurs" set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_product_zones, "Zones produits" - + set_sub_sub_menu :stocks, :p_preferences_products_menu, :sorecop_cats, "Catégories SORECOP" + set_sub_sub_menu :stocks, :p_preferences_products_menu, :sorecop_taxes, "taxe SORECOP" + end diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb index 9a7fccf..49d5d80 100644 --- a/app/models/p_product_ref.rb +++ b/app/models/p_product_ref.rb @@ -1,6 +1,7 @@ class PProductRef < ApplicationRecord belongs_to :p_product - + belongs_to :sorecop_cat + has_many :sorecop_taxes, through: :sorecop_cat has_many :p_customer_cats, :through => :p_product has_many :p_product_features diff --git a/app/models/sorecop_cat.rb b/app/models/sorecop_cat.rb index be69dba..a0af0d4 100644 --- a/app/models/sorecop_cat.rb +++ b/app/models/sorecop_cat.rb @@ -1,2 +1,10 @@ class SorecopCat < ApplicationRecord + has_many :p_product_refs + has_many :sorecop_taxes, dependent: :destroy + + acts_as_sorting :fields => { + :id => {:name => "ID"}, + :name => {:name => "Catégorie", :reorder => true}, + :actions => {:name => "Actions", :reorder => true} + } end diff --git a/app/models/sorecop_tax.rb b/app/models/sorecop_tax.rb index 9fb2cd7..518bb01 100644 --- a/app/models/sorecop_tax.rb +++ b/app/models/sorecop_tax.rb @@ -1,3 +1,15 @@ class SorecopTax < ApplicationRecord - belongs_to :sorecop_cat_id + belongs_to :sorecop_cat + + + acts_as_sorting :fields => { + :id => {:name => "ID"}, + :title => {:name => "Désignation", :reorder => true}, + :critere_min => {:name => "Critère mini (Go)", :reorder => true}, + :critere_max => {:name => "Critère maxi (Go)", :reorder => true}, + :fixed_price => {:name => "Prix forfaitaire", :reorder => true, :format => :boolean}, + :sorecop_cat => {:name => "Catégorie SORECOP", :reorder => false}, + :price => {:name => "Prix", :reorder => false}, + :actions => {:name => "Actions", :reorder => true} + } end diff --git a/app/views/admin/sorecop_taxes/_form.html.haml b/app/views/admin/sorecop_taxes/_form.html.haml index 389bbe6..38654b8 100644 --- a/app/views/admin/sorecop_taxes/_form.html.haml +++ b/app/views/admin/sorecop_taxes/_form.html.haml @@ -2,15 +2,17 @@ .content =f.inputs do - = f.input :critere_min, :label => f.object.label_for(:critere_min) - = f.input :critere_max, :label => f.object.label_for(:critere_max) - = f.input :title, :label => f.object.label_for(:title) - = f.input :fixed_price, :label => f.object.label_for(:fixed_price) - = f.input :sorecop_cat_id, :label => f.object.label_for(:sorecop_cat_id) - + = f.input :sorecop_cat_id, as: :select, collection: SorecopCat.pluck(:name, :id) ,:label => f.object.label_for(:sorecop_cat) + = f.input :title, :label => f.object.label_for(:title) + = f.input :critere_min, :label => f.object.label_for(:critere_min) + = f.input :critere_max, :label => f.object.label_for(:critere_max) + = f.input :price, :label => f.object.label_for(:price) + = f.input :fixed_price, :label => f.object.label_for(:fixed_price) + + .actions=f.submit "sauvegarder", :class => "btn btn-primary" - \ No newline at end of file + diff --git a/app/views/admin/sorecop_taxes/_sorecop_tax.html.haml b/app/views/admin/sorecop_taxes/_sorecop_tax.html.haml index 4a318ec..c35450f 100644 --- a/app/views/admin/sorecop_taxes/_sorecop_tax.html.haml +++ b/app/views/admin/sorecop_taxes/_sorecop_tax.html.haml @@ -1,5 +1,10 @@ %tr#sorecop_tax_row{:id => sorecop_tax.id} -tr = {} + + -tr[:sorecop_cat] = capture do + %td + = sorecop_tax.sorecop_cat.name + -tr[:actions] = capture do %td.actions @@ -13,4 +18,4 @@ - \ No newline at end of file + From 2e83114c3f1f3ff463f8715fe531e829c76bedd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 24 Sep 2021 12:30:19 +0200 Subject: [PATCH 076/131] Update sorecop text table --- app/models/sorecop_tax.rb | 4 ++-- .../sorecop_taxes/_sorecop_tax.html.haml | 20 ++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/models/sorecop_tax.rb b/app/models/sorecop_tax.rb index 518bb01..061dd00 100644 --- a/app/models/sorecop_tax.rb +++ b/app/models/sorecop_tax.rb @@ -8,8 +8,8 @@ class SorecopTax < ApplicationRecord :critere_min => {:name => "Critère mini (Go)", :reorder => true}, :critere_max => {:name => "Critère maxi (Go)", :reorder => true}, :fixed_price => {:name => "Prix forfaitaire", :reorder => true, :format => :boolean}, - :sorecop_cat => {:name => "Catégorie SORECOP", :reorder => false}, - :price => {:name => "Prix", :reorder => false}, + :sorecop_cat => {:name => "Catégorie SORECOP",member_label: :name, :reorder => false}, + :price => {:name => "Prix", :reorder => false, as: :currency}, :actions => {:name => "Actions", :reorder => true} } end diff --git a/app/views/admin/sorecop_taxes/_sorecop_tax.html.haml b/app/views/admin/sorecop_taxes/_sorecop_tax.html.haml index c35450f..684f550 100644 --- a/app/views/admin/sorecop_taxes/_sorecop_tax.html.haml +++ b/app/views/admin/sorecop_taxes/_sorecop_tax.html.haml @@ -1,11 +1,25 @@ %tr#sorecop_tax_row{:id => sorecop_tax.id} -tr = {} - -tr[:sorecop_cat] = capture do + -tr[:critere_min] = capture do %td - = sorecop_tax.sorecop_cat.name + = sorecop_tax.critere_min + Go + + -tr[:critere_max] = capture do + %td + = sorecop_tax.critere_max + Go + + -tr[:fixed_price] = capture do + %td.text-center + -if sorecop_tax.fixed_price + =ic("check-square-o") + -else + =ic("square-o") + + - -tr[:actions] = capture do %td.actions = link_to i(:"trash-o"), [:admin, sorecop_tax], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true From 91754a6192447358fee3c11a584d5315a3e4ea51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 24 Sep 2021 15:11:43 +0200 Subject: [PATCH 077/131] Spec value default order --- app/controllers/admin/p_spec_values_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/p_spec_values_controller.rb b/app/controllers/admin/p_spec_values_controller.rb index 2dfd736..4ddb464 100644 --- a/app/controllers/admin/p_spec_values_controller.rb +++ b/app/controllers/admin/p_spec_values_controller.rb @@ -13,7 +13,7 @@ class Admin::PSpecValuesController < ApplicationController def index @p_spec_values = PSpecValue.all - @p_spec_values = sort_by_sorting(@p_spec_values, "id DESC") + @p_spec_values = sort_by_sorting(@p_spec_values, "value + 0 ASC") respond_to do |format| format.html{ From e8ebce23edc9588ccbd555cd09266bc3d5127165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 24 Sep 2021 15:12:17 +0200 Subject: [PATCH 078/131] ca_sorecop for p_product_ref --- app/models/p_product_ref.rb | 22 +++++++++++++++---- .../admin/p_product_refs/_form.html.haml | 4 +++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb index 49d5d80..f8cf488 100644 --- a/app/models/p_product_ref.rb +++ b/app/models/p_product_ref.rb @@ -10,6 +10,7 @@ class PProductRef < ApplicationRecord has_many :p_product_ref_price_histories belongs_to :p_product_color + belongs_to :sorecop_cat has_many :p_articles has_many :p_article_serial_nums, through: :p_articles @@ -46,7 +47,7 @@ class PProductRef < ApplicationRecord :ct_price_ht => {:name => "Prix de vente", :as => :currency}, :ean => {:name => "EAN"}, :ca_deee => {:name => "DEEE", :as => :currency}, - :ca_sorecop => {:name => "Sorecop", :as => :currency}, + :sorecop => {:name => "Sorecop", :as => :currency}, :sorecop_comment => {:name => "Type de Sorecop"}, :actions => {:name => "Actions", :reorder => false} } @@ -155,13 +156,26 @@ class PProductRef < ApplicationRecord end def ca_sorecop - if self.cc_sorecop - return self.cc_sorecop + if self.sorecop_cat + if self.cc_sorecop + return self.cc_sorecop + else + if self.p_product_ref_specs.where(p_spec_type: PSpecType.find_by_name("Stockage")) + find_sorecop_tax.price + else + "Pas de spec de Stockage" + end + end else - "TODO Calcul sorecop" + "Pas de catégorie Sorecop" end end + def find_sorecop_tax + storage_capacity = self.p_product_ref_specs.where(p_spec_type: PSpecType.find_by_name("Stockage")).first.p_spec_value.value + self.sorecop_cat.sorecop_taxes.where('critere_min < ? AND critere_max >= ?', storage_capacity, storage_capacity).first + end + def ca_deee if self.cc_deee return self.cc_deee diff --git a/app/views/admin/p_product_refs/_form.html.haml b/app/views/admin/p_product_refs/_form.html.haml index 4b0b755..f55ec17 100644 --- a/app/views/admin/p_product_refs/_form.html.haml +++ b/app/views/admin/p_product_refs/_form.html.haml @@ -20,10 +20,12 @@ %td =form.input :p_product_color_id, :label => "Couleur :", :collection => PProductColor.all, :as => :select, :include_blank => true + %td + =form.input :sorecop_cat_id, label: "Catgorie Sorecop :", :collection => SorecopCat.all, :as => :select, :include_blank => true %td =form.input :ct_sorecop, :label => "Sorecop personalisée :" %td - =form.input :sorecop_comment, :label => "Type de Sorecop :" + =form.input :sorecop_comment, :label => "Commentaire de Sorecop :" %td =form.input :ct_deee, :label => "DEEE personalisée :" %td From 72cee7f797bc7925d02ea7cf30f00da8d39389a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 24 Sep 2021 15:59:38 +0200 Subject: [PATCH 079/131] update sorecop calcul --- app/models/p_product_ref.rb | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb index f8cf488..2588ad3 100644 --- a/app/models/p_product_ref.rb +++ b/app/models/p_product_ref.rb @@ -48,7 +48,7 @@ class PProductRef < ApplicationRecord :ean => {:name => "EAN"}, :ca_deee => {:name => "DEEE", :as => :currency}, :sorecop => {:name => "Sorecop", :as => :currency}, - :sorecop_comment => {:name => "Type de Sorecop"}, + :sorecop_comment => {:name => "Commentaire Sorecop"}, :actions => {:name => "Actions", :reorder => false} } @@ -156,14 +156,17 @@ class PProductRef < ApplicationRecord end def ca_sorecop + if ct_sorecop + return ct_sorecop + end if self.sorecop_cat if self.cc_sorecop return self.cc_sorecop else - if self.p_product_ref_specs.where(p_spec_type: PSpecType.find_by_name("Stockage")) - find_sorecop_tax.price + if self.p_product_ref_specs.where(p_spec_type: PSpecType.find_by_name("Stockage")).empty? + "Pas de stockage" else - "Pas de spec de Stockage" + find_sorecop_tax end end else @@ -172,8 +175,13 @@ class PProductRef < ApplicationRecord end def find_sorecop_tax - storage_capacity = self.p_product_ref_specs.where(p_spec_type: PSpecType.find_by_name("Stockage")).first.p_spec_value.value - self.sorecop_cat.sorecop_taxes.where('critere_min < ? AND critere_max >= ?', storage_capacity, storage_capacity).first + storage_capacity = self.p_product_ref_specs.where(p_spec_type: PSpecType.find_by_name("Stockage")).first.p_spec_value.value.to_f + tax = self.sorecop_cat.sorecop_taxes.where('critere_min < ? AND critere_max >= ?', storage_capacity, storage_capacity).first + if tax.fixed_price + tax.price + else + tax.price * storage_capacity + end end def ca_deee From 82fdb06254c4134f18a699dbb18eac05d748b384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 24 Sep 2021 15:59:56 +0200 Subject: [PATCH 080/131] fomr in 2 lines --- app/views/admin/p_product_refs/_form.html.haml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/admin/p_product_refs/_form.html.haml b/app/views/admin/p_product_refs/_form.html.haml index f55ec17..7ce89d3 100644 --- a/app/views/admin/p_product_refs/_form.html.haml +++ b/app/views/admin/p_product_refs/_form.html.haml @@ -20,6 +20,9 @@ %td =form.input :p_product_color_id, :label => "Couleur :", :collection => PProductColor.all, :as => :select, :include_blank => true + %td + =form.input :ean + %tr %td =form.input :sorecop_cat_id, label: "Catgorie Sorecop :", :collection => SorecopCat.all, :as => :select, :include_blank => true %td @@ -28,8 +31,6 @@ =form.input :sorecop_comment, :label => "Commentaire de Sorecop :" %td =form.input :ct_deee, :label => "DEEE personalisée :" - %td - =form.input :ean From 60ee0d819761bd33be3c7d48a082f257aa141d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 24 Sep 2021 17:19:44 +0200 Subject: [PATCH 081/131] move sorecop_cat to p_product --- app/models/p_product.rb | 2 +- app/models/p_product_ref.rb | 40 ++++++++++--------- app/models/sorecop_cat.rb | 2 +- .../admin/p_product_refs/_form.html.haml | 2 - app/views/admin/p_products/_form.html.haml | 5 ++- ...30_add_sorecop_cat_id_to_p_product_refs.rb | 5 --- ...145644_add_sorecop_cat_id_to_p_products.rb | 5 +++ db/schema.rb | 4 +- 8 files changed, 33 insertions(+), 32 deletions(-) delete mode 100644 db/migrate/20210923170130_add_sorecop_cat_id_to_p_product_refs.rb create mode 100644 db/migrate/20210924145644_add_sorecop_cat_id_to_p_products.rb diff --git a/app/models/p_product.rb b/app/models/p_product.rb index 893a83c..43bab07 100644 --- a/app/models/p_product.rb +++ b/app/models/p_product.rb @@ -28,7 +28,7 @@ class PProduct < ApplicationRecord has_many :p_product_images belongs_to :p_customer - + belongs_to :sorecop_cat belongs_to :p_product_cat belongs_to :s_brand diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb index 2588ad3..5e2992c 100644 --- a/app/models/p_product_ref.rb +++ b/app/models/p_product_ref.rb @@ -10,7 +10,6 @@ class PProductRef < ApplicationRecord has_many :p_product_ref_price_histories belongs_to :p_product_color - belongs_to :sorecop_cat has_many :p_articles has_many :p_article_serial_nums, through: :p_articles @@ -46,7 +45,7 @@ class PProductRef < ApplicationRecord :ct_sub_name => {:name => "Nom référence"}, :ct_price_ht => {:name => "Prix de vente", :as => :currency}, :ean => {:name => "EAN"}, - :ca_deee => {:name => "DEEE", :as => :currency}, + :deee => {:name => "DEEE", :as => :currency}, :sorecop => {:name => "Sorecop", :as => :currency}, :sorecop_comment => {:name => "Commentaire Sorecop"}, :actions => {:name => "Actions", :reorder => false} @@ -156,27 +155,27 @@ class PProductRef < ApplicationRecord end def ca_sorecop - if ct_sorecop - return ct_sorecop - end - if self.sorecop_cat - if self.cc_sorecop - return self.cc_sorecop - else - if self.p_product_ref_specs.where(p_spec_type: PSpecType.find_by_name("Stockage")).empty? - "Pas de stockage" - else - find_sorecop_tax - end - end + return ct_sorecop if ct_sorecop + return "Pas de catégorie Sorecop" if self.p_product.sorecop_cat.blank? + + if self.cc_sorecop + return self.cc_sorecop else - "Pas de catégorie Sorecop" + find_sorecop_tax end end def find_sorecop_tax - storage_capacity = self.p_product_ref_specs.where(p_spec_type: PSpecType.find_by_name("Stockage")).first.p_spec_value.value.to_f - tax = self.sorecop_cat.sorecop_taxes.where('critere_min < ? AND critere_max >= ?', storage_capacity, storage_capacity).first + p_product_ref_spec = self.p_product_ref_specs.where(p_spec_type: PSpecType.find_by_name("Stockage")).first + return "Pas de stockage" if p_product_ref_spec.blank? + + storage_capacity = p_product_ref_spec.p_spec_value.value.to_f + if p_product_ref_spec.p_spec_value.unit.casecmp?("Go") + tax = self.p_product.sorecop_cat.sorecop_taxes.where('critere_min < ? AND critere_max >= ?', storage_capacity, storage_capacity).first + elsif p_product_ref_spec.p_spec_value.unit.casecmp?("To") + tax = self.p_product.sorecop_cat.sorecop_taxes.where('critere_min < ? AND critere_max >= ?', storage_capacity * 1000, storage_capacity * 1000).first + end + if tax.fixed_price tax.price else @@ -185,10 +184,13 @@ class PProductRef < ApplicationRecord end def ca_deee + if ct_deee + return ct_deee + end if self.cc_deee return self.cc_deee else - "TODO Calcul DEEE" + "DEEE à renseigner" end end diff --git a/app/models/sorecop_cat.rb b/app/models/sorecop_cat.rb index a0af0d4..ebb0575 100644 --- a/app/models/sorecop_cat.rb +++ b/app/models/sorecop_cat.rb @@ -1,5 +1,5 @@ class SorecopCat < ApplicationRecord - has_many :p_product_refs + has_many :p_products has_many :sorecop_taxes, dependent: :destroy acts_as_sorting :fields => { diff --git a/app/views/admin/p_product_refs/_form.html.haml b/app/views/admin/p_product_refs/_form.html.haml index 7ce89d3..89561b6 100644 --- a/app/views/admin/p_product_refs/_form.html.haml +++ b/app/views/admin/p_product_refs/_form.html.haml @@ -23,8 +23,6 @@ %td =form.input :ean %tr - %td - =form.input :sorecop_cat_id, label: "Catgorie Sorecop :", :collection => SorecopCat.all, :as => :select, :include_blank => true %td =form.input :ct_sorecop, :label => "Sorecop personalisée :" %td diff --git a/app/views/admin/p_products/_form.html.haml b/app/views/admin/p_products/_form.html.haml index dcc5078..d298195 100755 --- a/app/views/admin/p_products/_form.html.haml +++ b/app/views/admin/p_products/_form.html.haml @@ -19,7 +19,8 @@ =# f.input :stocked, :label => "Suivi de stock ?" - + .col-sm-2 + =f.input :sorecop_cat, label: "Catgorie Sorecop :", :collection => SorecopCat.all, :as => :select, :include_blank => true @@ -112,4 +113,4 @@ - \ No newline at end of file + diff --git a/db/migrate/20210923170130_add_sorecop_cat_id_to_p_product_refs.rb b/db/migrate/20210923170130_add_sorecop_cat_id_to_p_product_refs.rb deleted file mode 100644 index b4d65a9..0000000 --- a/db/migrate/20210923170130_add_sorecop_cat_id_to_p_product_refs.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddSorecopCatIdToPProductRefs < ActiveRecord::Migration[6.0] - def change - add_column :p_product_refs, :sorecop_cat_id, :integer - end -end diff --git a/db/migrate/20210924145644_add_sorecop_cat_id_to_p_products.rb b/db/migrate/20210924145644_add_sorecop_cat_id_to_p_products.rb new file mode 100644 index 0000000..6091257 --- /dev/null +++ b/db/migrate/20210924145644_add_sorecop_cat_id_to_p_products.rb @@ -0,0 +1,5 @@ +class AddSorecopCatIdToPProducts < ActiveRecord::Migration[6.0] + def change + add_column :p_products, :sorecop_cat_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 5e36bad..0c04f68 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_09_23_170130) do +ActiveRecord::Schema.define(version: 2021_09_24_145644) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -1801,7 +1801,6 @@ ActiveRecord::Schema.define(version: 2021_09_23_170130) do t.decimal "ct_deee", precision: 10, scale: 2 t.string "ean" t.string "sorecop_comment" - t.integer "sorecop_cat_id" end create_table "p_product_specs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| @@ -1891,6 +1890,7 @@ ActiveRecord::Schema.define(version: 2021_09_23_170130) do t.decimal "finesse_max", precision: 6, scale: 2 t.boolean "conserve_proportion", default: false t.boolean "frontpage", default: true + t.integer "sorecop_cat_id" t.index ["p_product_cat_id"], name: "index_p_products_on_p_product_cat_id" t.index ["s_brand_id"], name: "index_p_products_on_s_brand_id" end From 4ad0ac7db520f5d6fd0be8be56e202184a0cd55d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 24 Sep 2021 17:52:23 +0200 Subject: [PATCH 082/131] remove qi_cache --- app/models/p_product_ref.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb index 5e2992c..9141d45 100644 --- a/app/models/p_product_ref.rb +++ b/app/models/p_product_ref.rb @@ -88,11 +88,11 @@ class PProductRef < ApplicationRecord self.p_product.p_product_cat_id end - QI_DYNAMICS = %w(name code p_product_cat_id sub_cat_names cat_name) + # QI_DYNAMICS = %w(name code p_product_cat_id sub_cat_names cat_name) - eval(QI_DYNAMICS_CORE) + # eval(QI_DYNAMICS_CORE) - before_validation :qi_dynamics_cache + # before_validation :qi_dynamics_cache def get_price(options) p_customer = PCustomer.find(options[:p_customer_id]) if options[:p_customer_id] From d43fd65822b2ce86271d8b0b7d45bbf5fa140f24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 24 Sep 2021 17:52:37 +0200 Subject: [PATCH 083/131] rename ac_ column --- .../20210924153716_rename_ca_to_ac_for_product_refs.rb | 6 ++++++ db/schema.rb | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20210924153716_rename_ca_to_ac_for_product_refs.rb diff --git a/db/migrate/20210924153716_rename_ca_to_ac_for_product_refs.rb b/db/migrate/20210924153716_rename_ca_to_ac_for_product_refs.rb new file mode 100644 index 0000000..304762e --- /dev/null +++ b/db/migrate/20210924153716_rename_ca_to_ac_for_product_refs.rb @@ -0,0 +1,6 @@ +class RenameCaToAcForProductRefs < ActiveRecord::Migration[6.0] + def change + rename_column :p_product_refs, :ca_deee, :ac_deee + rename_column :p_product_refs, :ca_sorecop, :ac_sorecop + end +end diff --git a/db/schema.rb b/db/schema.rb index 0c04f68..016eb45 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_09_24_145644) do +ActiveRecord::Schema.define(version: 2021_09_24_153716) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -1793,10 +1793,10 @@ ActiveRecord::Schema.define(version: 2021_09_24_145644) do t.boolean "stocked", default: true t.text "description" t.integer "p_product_color_id" - t.decimal "ca_sorecop", precision: 10, scale: 2 + t.decimal "ac_sorecop", precision: 10, scale: 2 t.decimal "cc_sorecop", precision: 10, scale: 2 t.decimal "ct_sorecop", precision: 10, scale: 2 - t.decimal "ca_deee", precision: 10, scale: 2 + t.decimal "ac_deee", precision: 10, scale: 2 t.decimal "cc_deee", precision: 10, scale: 2 t.decimal "ct_deee", precision: 10, scale: 2 t.string "ean" From de98190ea3d074e4d69debd58562758bd2ee79de Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Mon, 27 Sep 2021 16:52:59 +0200 Subject: [PATCH 084/131] Nginx --- config/nginx.conf | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/config/nginx.conf b/config/nginx.conf index 2623153..224c07c 100644 --- a/config/nginx.conf +++ b/config/nginx.conf @@ -10,7 +10,7 @@ upstream presta_app_unicorn { server { listen [::]:443 ssl; - server_name presta.basiclabs.fr; + server_name arcom.basiclabs.fr; root /srv/www/web/presta_app/current/public; try_files $uri/index.html $uri @unicorn; @@ -36,23 +36,10 @@ server { keepalive_timeout 10; ssl on; - ssl_certificate /etc/letsencrypt/live/fid.olwen.xyz/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/fid.olwen.xyz/privkey.pem; + ssl_certificate /etc/letsencrypt/live/arcom.basiclabs.fr/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/arcom.basiclabs.fr/privkey.pem; include snippets/letsencrypt.conf; } - - - -server { - listen [::]:80; - server_name presta.basiclabs.fr; - - return 301 https://presta.basiclabs.fr$request_uri; - - include snippets/letsencrypt.conf; -} - - From 4c49e4d3faa566bbad744947a43d84de0f37aa61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 30 Sep 2021 12:46:27 +0200 Subject: [PATCH 085/131] WIP import client --- .../admin/p_fournisseurs_controller.rb | 14 +++++++++++++- app/views/admin/p_fournisseurs/import.html.haml | 17 +++++++++-------- .../import_fournisseurs.html.haml | 16 ++++++++++++++++ app/views/admin/p_fournisseurs/index.html.haml | 4 ++-- config/routes.rb | 2 ++ 5 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 app/views/admin/p_fournisseurs/import_fournisseurs.html.haml diff --git a/app/controllers/admin/p_fournisseurs_controller.rb b/app/controllers/admin/p_fournisseurs_controller.rb index 3b8b041..e406eed 100644 --- a/app/controllers/admin/p_fournisseurs_controller.rb +++ b/app/controllers/admin/p_fournisseurs_controller.rb @@ -23,7 +23,19 @@ class Admin::PFournisseursController < ApplicationController end - + def import_fournisseurs + # @file = params[:csv_file] + # require 'csv' + + # csv_text = File.read("#{Rails.root}/import_csv/fournisseurs.csv") #.force_encoding('ISO-8859-1') + # @csv = CSV.parse(csv_text, :headers => true, :col_sep => ";") + + end + + def import_fournisseurs_xls + raise + end + def index @p_fournisseurs = PFournisseur.order(:name).all diff --git a/app/views/admin/p_fournisseurs/import.html.haml b/app/views/admin/p_fournisseurs/import.html.haml index 276b6d1..41199bd 100644 --- a/app/views/admin/p_fournisseurs/import.html.haml +++ b/app/views/admin/p_fournisseurs/import.html.haml @@ -1,13 +1,14 @@ --@import= true +-if false + -@import= true --i = 0 --@csv.each do |csv| - -i += 1 + -i = 0 + -@csv.each do |csv| + -i += 1 - =csv["code"] - -if csv["code"].to_s != "" - sfsd - -PFournisseur.create(:code => csv["code"],:name => csv["nom"],:address1 => csv["adresse 1"],:address2 => csv["adresse 2"],:cp => csv["code postal"],:city => csv["city"],:country => csv["country"],:email => csv["email"],:tel => csv["tel"]) + =csv["code"] + -if csv["code"].to_s != "" + sfsd + -PFournisseur.create(:code => csv["code"],:name => csv["nom"],:address1 => csv["adresse 1"],:address2 => csv["adresse 2"],:cp => csv["code postal"],:city => csv["city"],:country => csv["country"],:email => csv["email"],:tel => csv["tel"]) diff --git a/app/views/admin/p_fournisseurs/import_fournisseurs.html.haml b/app/views/admin/p_fournisseurs/import_fournisseurs.html.haml new file mode 100644 index 0000000..1010d73 --- /dev/null +++ b/app/views/admin/p_fournisseurs/import_fournisseurs.html.haml @@ -0,0 +1,16 @@ +.qi_header + .right + %h1 + Import + %span + Fournisseurs + + +.qi_row + .qi_pannel.qi_plain.padding + %table.table + %tr + %td + =form_with url: import_fournisseurs_xls_admin_p_fournisseurs_path() do |form| + =form.file_field_tag 'Base client', accept: '.xls, .xlsx' + =form.submit_tag 'importer' diff --git a/app/views/admin/p_fournisseurs/index.html.haml b/app/views/admin/p_fournisseurs/index.html.haml index f77d543..22fa1ce 100644 --- a/app/views/admin/p_fournisseurs/index.html.haml +++ b/app/views/admin/p_fournisseurs/index.html.haml @@ -1,7 +1,7 @@ .qi_header .right = link_to 'Ajouter un fournisseur', new_admin_p_fournisseur_path(), :class => "btn btn-primary", :remote => true - + =link_to 'import base fournisseurs', import_fournisseurs_admin_p_fournisseurs_path(), :class => "btn btn-primary" %h1 Achats %span @@ -28,4 +28,4 @@ %tbody#p_fournisseurs_rows =render @p_fournisseurs - \ No newline at end of file + diff --git a/config/routes.rb b/config/routes.rb index a5835ca..355ebde 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -967,6 +967,8 @@ Rails.application.routes.draw do resources :p_fournisseurs do collection do get :import + get :import_fournisseurs + post :import_fournisseurs_xls end From aa3dbed95b35983076cf45af5775399a1ef059d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Tue, 5 Oct 2021 15:28:44 +0200 Subject: [PATCH 086/131] import csv work with xlsx files --- app/models/import_csv.rb | 89 +++++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 32 deletions(-) diff --git a/app/models/import_csv.rb b/app/models/import_csv.rb index 7414d1b..d0d1dd1 100644 --- a/app/models/import_csv.rb +++ b/app/models/import_csv.rb @@ -10,7 +10,7 @@ class ImportCsv < ApplicationRecord validates :file, :presence => true validates :table_name, :presence => true - + has_many :import_csv_champs, :dependent => :destroy accepts_nested_attributes_for :import_csv_champs, :allow_destroy => true @@ -21,72 +21,97 @@ class ImportCsv < ApplicationRecord :name => {:name => "Nom", :reorder => true}, :file => {:name => "Fichier", :reorder => true}, :table_name => {:name => "Table", :reorder => true}, - + :nbr_headers => {:name => "Nbr champs", :reorder => true}, :nbr_elements => {:name => "Nbr elements", :reorder => true}, - - - + + + :actions => {:name => "Actions", :reorder => false} } after_create do - - csv_text = File.read(self.file.path, :encoding => 'UTF-8') - @csv = CSV.parse(csv_text, :headers => true, :col_sep => ";") - - @csv.headers.each do |header| + if file_is_csv? + csv_text = File.read(self.file.path, :encoding => 'UTF-8') + csv = CSV.parse(csv_text, :headers => true, :col_sep => ";") + headers = csv.headers + else + xlsx = Roo::Spreadsheet.open(self.file.path, extension: :xlsx) # open spreadsheet + headers = xlsx.row(1) + end + headers.each do |header| self.import_csv_headers << ImportCsvHeader.new(:name => header) end self.table_name.classify.constantize.import_csv_fields.each do |h| if self.parent and c = self.parent.import_csv_champs.where(:champ => h.to_s).first - self.import_csv_champs.new(:champ => h.to_s, :header => c.header) + self.import_csv_champs.new(:champ => h.to_s, :header => c.header) else - self.import_csv_champs.new(:champ => h.to_s) + self.import_csv_champs.new(:champ => h.to_s) end end - self.save - - end + + def file_is_csv? + File.read(self.file.path, :encoding => 'utf-8').valid_encoding? + end + + def charge - + self.import_csv_elements.each do |e| e.element.destroy if e.element e.destroy end - csv_text = File.read(self.file.path, :encoding => 'UTF-8') - @csv = CSV.parse(csv_text, :headers => true, :col_sep => ";") r = [] - @csv.each do |row| - line = {} - self.import_csv_champs.each do |import_csv_champ| - if import_csv_champ.header? - eval "line['#{import_csv_champ.champ}'] = row[\"#{import_csv_champ.header}\"]" - elsif import_csv_champ.value? - eval "line['#{import_csv_champ.champ}'] = \"#{import_csv_champ.value}\"" + + if file_is_csv? + csv_text = File.read(self.file.path, :encoding => 'UTF-8') + csv = CSV.parse(csv_text, :headers => true, :col_sep => ";") + csv.each do |row| + line = {} + self.import_csv_champs.each do |import_csv_champ| + if import_csv_champ.header? + eval "line['#{import_csv_champ.champ}'] = row[\"#{import_csv_champ.header}\"]" + elsif import_csv_champ.value? + eval "line['#{import_csv_champ.champ}'] = \"#{import_csv_champ.value}\"" + end end - + r << line end - - r << line - + return r + else + xlsx = Roo::Spreadsheet.open(self.file.path, extension: :xlsx) # open spreadsheet + headers = xlsx.row(1) # get header row + xlsx.each_with_index do |row, idx| + line = {} + next if idx == 0 # skip header + # create hash from headers and cells + data = Hash[[headers, row].transpose] + self.import_csv_champs.each do |import_csv_champ| + # raise + if import_csv_champ.header? + eval "line['#{import_csv_champ.champ}'] = data[\"#{import_csv_champ.header}\"]" + elsif import_csv_champ.value? + eval "line['#{import_csv_champ.champ}'] = \"#{import_csv_champ.value}\"" + end + end + r << line + end + return r end - - return r end def load self.table_name.classify.constantize.import_csv(self.charge, self) - + end From e6ddcfe1835928b23e07640d04a88847937359eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Tue, 5 Oct 2021 15:29:05 +0200 Subject: [PATCH 087/131] add import xls to menu --- app/controllers/application_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ce02913..06d193f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -126,8 +126,7 @@ class ApplicationController < ActionController::Base set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_grades, "Grades" if PGrade::ACTIVATED set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_product_powers, "Types de chargeurs" set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_product_zones, "Zones produits" - - + set_sub_sub_menu :stocks, :p_preferences_products_menu, :import_csvs, "Import Excel" end From 0e33efd61ab5a72bcc26d101d67ea1128fde748c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Tue, 5 Oct 2021 15:37:31 +0200 Subject: [PATCH 088/131] p_fournisseur CSV+EXCEL import ok --- app/models/p_contact.rb | 2 +- app/models/p_fournisseur.rb | 79 +++++++++++++++++++ app/models/p_payment_type.rb | 3 +- app/views/admin/import_csvs/_form.html.haml | 4 +- app/views/admin/import_csvs/index.html.haml | 4 +- .../20211004161651_add_skype_to_p_contacts.rb | 5 ++ ...004161753_add_details_to_p_fournisseurs.rb | 9 +++ db/schema.rb | 8 +- lib/acts_as_csv_import/hook.rb | 2 +- 9 files changed, 108 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20211004161651_add_skype_to_p_contacts.rb create mode 100644 db/migrate/20211004161753_add_details_to_p_fournisseurs.rb diff --git a/app/models/p_contact.rb b/app/models/p_contact.rb index 28706f5..6da354d 100644 --- a/app/models/p_contact.rb +++ b/app/models/p_contact.rb @@ -5,5 +5,5 @@ class PContact < ApplicationRecord has_many :p_contact_contact_types, :dependent => :destroy has_many :p_contact_types, :through => :p_contact_contact_types - + belongs_to :p_payment_type end diff --git a/app/models/p_fournisseur.rb b/app/models/p_fournisseur.rb index b24d696..e585732 100644 --- a/app/models/p_fournisseur.rb +++ b/app/models/p_fournisseur.rb @@ -1,2 +1,81 @@ class PFournisseur < ApplicationRecord + # has_many :particulars, :as => :owner, :dependent => :destroy + has_many :p_contacts, :as => :contactable, :dependent => :destroy + + acts_as_csv_import :fields => [ + :name, + :address1, + :cp, + :city, + :country, + :email, + :tel, + :p_contact_name, + :p_contact_comment, + :p_contact_tel, + :p_contact_skype, + :p_contact_email_1, + :p_contact_email_2, + :p_contact_email_3, + :bic, + :iban, + :payment_delais, + :tva_num, + :p_payment_type + ] + + def self.custom_csv_import(list, import_csv) + # ap "*********************************************************************************************************" + # ap "*********************************************************************************************************" + # ap "*********************************************************************************************************" + # ap list + # ap list.class + # ap "*********************************************************************************************************" + # ap "*********************************************************************************************************" + # ap "*********************************************************************************************************" + # ap import_csv + # ap "*********************************************************************************************************" + # ap "*********************************************************************************************************" + # ap "*********************************************************************************************************" + + list.each do |row| + + n = self.new + # particular = Particular.new(pro: true) + contact_1 = PContact.new + contact_2 = nil + contact_3 = nil + row.each do |key, value| + + if self.type_for_attribute(key) and self.type_for_attribute(key).type == :decimal + eval "n.#{key} = value.to_s.gsub(' ', '').gsub(',', '.')" + elsif key == "p_contact_name" + contact_1.name = value + elsif key == "p_contact_comment" + contact_1.p_contact_types << PContactType.find_or_create_by(name: value) + elsif key == "p_contact_tel" + contact_1.tel = value + elsif key == "p_contact_skype" + contact_1.skype = value + elsif key == "p_contact_email_1" + contact_1.email = value + elsif key == "p_contact_email_2" + contact_2 = PContact.new(email: value) + elsif key == "p_contact_email_3" + contact_3 = PContact.new(email: value) + elsif key == "p_payment_type" + n.p_payment_type_id = PPaymentType.find_or_create_by(name: value).id + else + eval "n.#{key} = value" + end + + end + # particular.organisation = self.name + n.save + n.p_contacts << contact_1 if (contact_1.name || contact_1.tel || contact_1.skype || contact_1.email) + n.p_contacts << contact_2 if contact_2 + n.p_contacts << contact_3 if contact_3 + # import_csv.import_csv_elements << ImportCsvElement.new(:element => n) + end + end end diff --git a/app/models/p_payment_type.rb b/app/models/p_payment_type.rb index a6cfaa8..fbd2f02 100644 --- a/app/models/p_payment_type.rb +++ b/app/models/p_payment_type.rb @@ -1,7 +1,8 @@ class PPaymentType < ApplicationRecord belongs_to :p_bank_account has_many :p_payments - + has_many :p_fournisseurs + after_save do if self.p_bank_account self.p_payments.where(:remise => false).update_all(:p_bank_account_id => self.p_bank_account_id) diff --git a/app/views/admin/import_csvs/_form.html.haml b/app/views/admin/import_csvs/_form.html.haml index f115a9c..ede671b 100644 --- a/app/views/admin/import_csvs/_form.html.haml +++ b/app/views/admin/import_csvs/_form.html.haml @@ -6,7 +6,7 @@ = f.input :name, :label => "Nom de l'import :" = f.input :file, :label => "file :" - = f.input :table_name, :label => "Table :" , :as => :select, :collection => ["order_hist_lines"] + = f.input :table_name, :label => "Type d'import :" , :as => :select, :collection => [["Base fournisseurs", "p_fournisseur"], ["Mise à jour catalogue prix","price_document"]] -if f.object.id %table.import_csv_champs_form @@ -23,4 +23,4 @@ .actions=f.submit "sauvegarder", :class => "btn btn-primary" - \ No newline at end of file + diff --git a/app/views/admin/import_csvs/index.html.haml b/app/views/admin/import_csvs/index.html.haml index 78aa6d9..54de32a 100644 --- a/app/views/admin/import_csvs/index.html.haml +++ b/app/views/admin/import_csvs/index.html.haml @@ -1,6 +1,6 @@ .qi_header .right= link_to ic(:plus)+' Ajouter', new_admin_import_csv_path(), :class => "btn btn-primary btn-ap-add", :remote => true - %h1 + %h1 Import xls @@ -12,4 +12,4 @@ =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @import_csvs} -=debug OrderHistLine.new.class.type_for_attribute("ff") \ No newline at end of file +=debug OrderHistLine.new.class.type_for_attribute("ff") diff --git a/db/migrate/20211004161651_add_skype_to_p_contacts.rb b/db/migrate/20211004161651_add_skype_to_p_contacts.rb new file mode 100644 index 0000000..2560a30 --- /dev/null +++ b/db/migrate/20211004161651_add_skype_to_p_contacts.rb @@ -0,0 +1,5 @@ +class AddSkypeToPContacts < ActiveRecord::Migration[6.0] + def change + add_column :p_contacts, :skype, :string + end +end diff --git a/db/migrate/20211004161753_add_details_to_p_fournisseurs.rb b/db/migrate/20211004161753_add_details_to_p_fournisseurs.rb new file mode 100644 index 0000000..345ce24 --- /dev/null +++ b/db/migrate/20211004161753_add_details_to_p_fournisseurs.rb @@ -0,0 +1,9 @@ +class AddDetailsToPFournisseurs < ActiveRecord::Migration[6.0] + def change + add_column :p_fournisseurs, :payment_delais, :integer + add_column :p_fournisseurs, :tva_num, :string + add_column :p_fournisseurs, :p_payment_type_id, :integer + add_column :p_fournisseurs, :iban, :string + add_column :p_fournisseurs, :bic, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 5baae52..dc64e8d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_09_17_124338) do +ActiveRecord::Schema.define(version: 2021_10_04_161753) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -1164,6 +1164,7 @@ ActiveRecord::Schema.define(version: 2021_09_17_124338) do t.string "contactable_type" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.string "skype" t.index ["contactable_id"], name: "index_p_contacts_on_contactable_id" end @@ -1463,6 +1464,11 @@ ActiveRecord::Schema.define(version: 2021_09_17_124338) do t.string "compta_account" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.integer "payment_delais" + t.string "tva_num" + t.integer "p_payment_type_id" + t.string "iban" + t.string "bic" end create_table "p_grades", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| diff --git a/lib/acts_as_csv_import/hook.rb b/lib/acts_as_csv_import/hook.rb index ab6502b..e140daf 100644 --- a/lib/acts_as_csv_import/hook.rb +++ b/lib/acts_as_csv_import/hook.rb @@ -9,7 +9,7 @@ module ActsAsCsvImport::Hook end def self.import_csv(list, import_csv) - puts self.instance_methods + # puts self.instance_methods if self.methods.include?(:custom_csv_import) custom_csv_import(list, import_csv) From 268456d09f109c52efb9a2779126bca3213318f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Tue, 5 Oct 2021 15:38:31 +0200 Subject: [PATCH 089/131] add roo + awesome print --- Gemfile | 3 ++- Gemfile.lock | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index f4aa40b..42799b6 100644 --- a/Gemfile +++ b/Gemfile @@ -103,7 +103,7 @@ group :development do gem 'capistrano-bundler', '~> 1.1', require: false gem "capistrano-rvm", group: :development gem 'capistrano3-nginx', '~> 2.0', group: :development - + gem "awesome_print" end gem 'zip-zip' @@ -114,3 +114,4 @@ gem 'axlsx', '3.0.0.pre' gem 'axlsx_rails' gem 'mimemagic', "0.3.10" +gem "roo" diff --git a/Gemfile.lock b/Gemfile.lock index a758dba..fa63faf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -63,6 +63,7 @@ GEM public_suffix (>= 2.0.2, < 5.0) airbrussh (1.3.3) sshkit (>= 1.6.1, != 1.7.0) + awesome_print (1.9.2) axlsx (3.0.0.pre) htmlentities (~> 4.3, >= 4.3.4) mimemagic (~> 0.3) @@ -270,6 +271,9 @@ GEM ffi (~> 1.0) regexp_parser (1.6.0) rmagick (4.2.2) + roo (2.8.2) + nokogiri (~> 1) + rubyzip (>= 1.2.1, < 2.0.0) ruby-vips (2.0.14) ffi (~> 1.9) ruby_dep (1.5.0) @@ -357,6 +361,7 @@ PLATFORMS DEPENDENCIES acts_as_commentable acts_as_tree + awesome_print axlsx (= 3.0.0.pre) axlsx_rails bcrypt (~> 3.1.7) @@ -390,6 +395,7 @@ DEPENDENCIES rails (= 6.0.3.4) rails_autolink rmagick + roo sass-rails (~> 5) searchkick selenium-webdriver From 0209a981d49f8c7623724e33f8dc81123b9b9f19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Tue, 5 Oct 2021 15:44:14 +0200 Subject: [PATCH 090/131] WIP import CSV fournisseur catalogue --- app/models/price_document.rb | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/app/models/price_document.rb b/app/models/price_document.rb index 24fcc09..3fe9fe5 100644 --- a/app/models/price_document.rb +++ b/app/models/price_document.rb @@ -31,6 +31,7 @@ class PriceDocument < ApplicationRecord AVANCEMENT = ["0%", "25%", "50%", "75%", "100"] validates :public_fournisseur_name, :presence => true, :if => :public_fournisseur_name_needed? + acts_as_csv_import :fields => [:p_fournisseur_id, :p_product_ref] def public_fournisseur_name_needed? if self.label == "Réponse fournisseur" @@ -707,6 +708,59 @@ class PriceDocument < ApplicationRecord end + def self.custom_csv_import(list, import_csv) + ap "*********************************************************************************************************" + ap "*********************************************************************************************************" + ap "*********************************************************************************************************" + ap list + ap list.class + ap "*********************************************************************************************************" + ap "*********************************************************************************************************" + ap "*********************************************************************************************************" + ap import_csv + ap "*********************************************************************************************************" + ap "*********************************************************************************************************" + ap "*********************************************************************************************************" + list.each do |row| + + n = self.new(price_document_type: PriceDocumentType.find_by_label("Catalogue fournisseur")) + # price_document = PriceDocument.new(price_document_type: PriceDocumentType.find_by_label("Catalogue fournisseur")) + contact_2 = nil + contact_3 = nil + row.each do |key, value| + + if self.type_for_attribute(key) and self.type_for_attribute(key).type == :decimal + eval "n.#{key} = value.to_s.gsub(' ', '').gsub(',', '.')" + # elsif key == "p_fournisseur_id" + # price_document.p_fournisseur = PFournisseur.find(key) + # elsif key == "p_contact_comment" + # contact_1.p_contact_types << PContactType.find_or_create_by(name: value) + # elsif key == "p_contact_tel" + # contact_1.tel = value + # elsif key == "p_contact_skype" + # contact_1.skype = value + # elsif key == "p_contact_email_1" + # contact_1.email = value + # elsif key == "p_contact_email_2" + # contact_2 = PContact.new(email: value) + # elsif key == "p_contact_email_3" + # contact_3 = PContact.new(email: value) + # elsif key == "p_payment_type" + # n.p_payment_type_id = PPaymentType.find_or_create_by(name: value).id + else + eval "n.#{key} = value" + end + + end + # particular.organisation = self.name + # n.save + ap n + # n.p_contacts << contact_1 if (contact_1.name || contact_1.tel || contact_1.skype || contact_1.email) + # n.p_contacts << contact_2 if contact_2 + # n.p_contacts << contact_3 if contact_3 + # import_csv.import_csv_elements << ImportCsvElement.new(:element => n) + end + end end From 9de88372a138ce2d116640e1101e0c54561d4d7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Tue, 5 Oct 2021 15:51:33 +0200 Subject: [PATCH 091/131] add p_fournisseur_ref --- .../admin/p_fournisseur_refs_controller.rb | 76 +++++++++++++++++++ app/models/p_fournisseur_ref.rb | 4 + .../admin/p_fournisseur_refs/_form.html.haml | 14 ++++ .../_p_fournisseur_ref.html.haml | 16 ++++ .../admin/p_fournisseur_refs/create.js.erb | 2 + .../admin/p_fournisseur_refs/destroy.js.erb | 1 + .../admin/p_fournisseur_refs/edit.js.erb | 1 + .../admin/p_fournisseur_refs/index.html.haml | 16 ++++ app/views/admin/p_fournisseur_refs/new.js.erb | 1 + .../admin/p_fournisseur_refs/show.html.haml | 10 +++ .../admin/p_fournisseur_refs/update.js.erb | 2 + config/routes.rb | 11 +++ ...0211005134955_create_p_fournisseur_refs.rb | 11 +++ db/schema.rb | 14 +++- test/fixtures/p_fournisseur_refs.yml | 11 +++ test/models/p_fournisseur_ref_test.rb | 7 ++ 16 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 app/controllers/admin/p_fournisseur_refs_controller.rb create mode 100644 app/models/p_fournisseur_ref.rb create mode 100644 app/views/admin/p_fournisseur_refs/_form.html.haml create mode 100644 app/views/admin/p_fournisseur_refs/_p_fournisseur_ref.html.haml create mode 100644 app/views/admin/p_fournisseur_refs/create.js.erb create mode 100644 app/views/admin/p_fournisseur_refs/destroy.js.erb create mode 100644 app/views/admin/p_fournisseur_refs/edit.js.erb create mode 100644 app/views/admin/p_fournisseur_refs/index.html.haml create mode 100644 app/views/admin/p_fournisseur_refs/new.js.erb create mode 100644 app/views/admin/p_fournisseur_refs/show.html.haml create mode 100644 app/views/admin/p_fournisseur_refs/update.js.erb create mode 100644 db/migrate/20211005134955_create_p_fournisseur_refs.rb create mode 100644 test/fixtures/p_fournisseur_refs.yml create mode 100644 test/models/p_fournisseur_ref_test.rb diff --git a/app/controllers/admin/p_fournisseur_refs_controller.rb b/app/controllers/admin/p_fournisseur_refs_controller.rb new file mode 100644 index 0000000..31e86bc --- /dev/null +++ b/app/controllers/admin/p_fournisseur_refs_controller.rb @@ -0,0 +1,76 @@ +# -*- encoding : utf-8 -*- + +class Admin::PFournisseurRefsController < ApplicationController + layout "admin" + before_action :auth_admin + + before_action :admin_space + + def admin_space + @admin_space = "default" + end + + def index + @p_fournisseur_refs = PFournisseurRef.all + + @p_fournisseur_refs = sort_by_sorting(@p_fournisseur_refs, "id DESC") + respond_to do |format| + format.html{ + + params[:search][:per_page] = params[:search][:per_page] || 100 + per_page = params[:search][:per_page] + page = (params[:page] and params[:page] != "") ? params[:page] : 1 + @p_fournisseur_refs = @p_fournisseur_refs.page(page).per(per_page) + + } + end + end + + def show + @p_fournisseur_ref = PFournisseurRef.find(params[:id]) + + end + + def new + @p_fournisseur_ref = PFournisseurRef.new + + end + + def edit + @p_fournisseur_ref = PFournisseurRef.find(params[:id]) + + end + + def create + @p_fournisseur_ref = PFournisseurRef.new(params.require(:p_fournisseur_ref).permit!) + + if @p_fournisseur_ref.save + + else + render action: "new" + + end + + end + + + def update + @p_fournisseur_ref = PFournisseurRef.find(params[:id]) + + + if @p_fournisseur_ref.update_attributes(params.require(:p_fournisseur_ref).permit!) + + else + render action: "edit" + + end + + end + + + def destroy + @p_fournisseur_ref = PFournisseurRef.find(params[:id]) + @p_fournisseur_ref.destroy + + end +end diff --git a/app/models/p_fournisseur_ref.rb b/app/models/p_fournisseur_ref.rb new file mode 100644 index 0000000..5c8fa6c --- /dev/null +++ b/app/models/p_fournisseur_ref.rb @@ -0,0 +1,4 @@ +class PFournisseurRef < ApplicationRecord + belongs_to :p_product_ref + belongs_to :p_fournisseur +end diff --git a/app/views/admin/p_fournisseur_refs/_form.html.haml b/app/views/admin/p_fournisseur_refs/_form.html.haml new file mode 100644 index 0000000..0fdf241 --- /dev/null +++ b/app/views/admin/p_fournisseur_refs/_form.html.haml @@ -0,0 +1,14 @@ +=semantic_form_for [:admin, @p_fournisseur_ref], :remote => true do |f| + + .content + =f.inputs do + = f.input :ref, :label => f.object.label_for(:ref) + = f.input :p_product_ref, :label => f.object.label_for(:p_product_ref) + = f.input :p_fournisseur, :label => f.object.label_for(:p_fournisseur) + + + + + + .actions=f.submit "sauvegarder", :class => "btn btn-primary" + \ No newline at end of file diff --git a/app/views/admin/p_fournisseur_refs/_p_fournisseur_ref.html.haml b/app/views/admin/p_fournisseur_refs/_p_fournisseur_ref.html.haml new file mode 100644 index 0000000..b9969b4 --- /dev/null +++ b/app/views/admin/p_fournisseur_refs/_p_fournisseur_ref.html.haml @@ -0,0 +1,16 @@ +%tr#p_fournisseur_ref_row{:id => p_fournisseur_ref.id} + -tr = {} + + -tr[:actions] = capture do + %td.actions + = link_to i(:"trash-o"), [:admin, p_fournisseur_ref], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true + = link_to i(:pencil), edit_admin_p_fournisseur_ref_path(p_fournisseur_ref), :remote => true + = link_to i(:eye), admin_p_fournisseur_ref_path(p_fournisseur_ref), :remote => true + + + + =render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => p_fournisseur_ref} + + + + \ No newline at end of file diff --git a/app/views/admin/p_fournisseur_refs/create.js.erb b/app/views/admin/p_fournisseur_refs/create.js.erb new file mode 100644 index 0000000..a57e725 --- /dev/null +++ b/app/views/admin/p_fournisseur_refs/create.js.erb @@ -0,0 +1,2 @@ +$('#p_fournisseur_refs_rows').prepend("<%= escape_javascript(render(@p_fournisseur_ref))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/app/views/admin/p_fournisseur_refs/destroy.js.erb b/app/views/admin/p_fournisseur_refs/destroy.js.erb new file mode 100644 index 0000000..72148c9 --- /dev/null +++ b/app/views/admin/p_fournisseur_refs/destroy.js.erb @@ -0,0 +1 @@ +$('#p_fournisseur_ref_row_<%= @p_fournisseur_ref.id %>').remove(); \ No newline at end of file diff --git a/app/views/admin/p_fournisseur_refs/edit.js.erb b/app/views/admin/p_fournisseur_refs/edit.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/p_fournisseur_refs/edit.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/p_fournisseur_refs/index.html.haml b/app/views/admin/p_fournisseur_refs/index.html.haml new file mode 100644 index 0000000..bcead3b --- /dev/null +++ b/app/views/admin/p_fournisseur_refs/index.html.haml @@ -0,0 +1,16 @@ +.qi_header + .right= link_to ic(:plus)+' Ajouter', new_admin_p_fournisseur_ref_path(), :class => "btn btn-primary btn-ap-add", :remote => true + %h1 + =PFournisseurRef.human rescue "" + + + +.qi_search_row + =form_tag "", :method => "get", :onsubmit => "" do + =render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @p_fournisseur_refs} + + +=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @p_fournisseur_refs} + + + diff --git a/app/views/admin/p_fournisseur_refs/new.js.erb b/app/views/admin/p_fournisseur_refs/new.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/p_fournisseur_refs/new.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/p_fournisseur_refs/show.html.haml b/app/views/admin/p_fournisseur_refs/show.html.haml new file mode 100644 index 0000000..213e4c6 --- /dev/null +++ b/app/views/admin/p_fournisseur_refs/show.html.haml @@ -0,0 +1,10 @@ +.qi_header + %h1 + + %span + + + +.qi_row + .qi_pannel.qi_plain.padding + =debug @p_fournisseur_ref \ No newline at end of file diff --git a/app/views/admin/p_fournisseur_refs/update.js.erb b/app/views/admin/p_fournisseur_refs/update.js.erb new file mode 100644 index 0000000..b135464 --- /dev/null +++ b/app/views/admin/p_fournisseur_refs/update.js.erb @@ -0,0 +1,2 @@ +$('#p_fournisseur_ref_row_<%= @p_fournisseur_ref.id %>').replaceWith("<%= escape_javascript(render(@p_fournisseur_ref))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 355ebde..d3a9d8a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,16 @@ Rails.application.routes.draw do + namespace :admin do + resources :p_fournisseur_refs do + member do + + end + collection do + + end + end + end + namespace :admin do resources :price_line_resp_selects do member do diff --git a/db/migrate/20211005134955_create_p_fournisseur_refs.rb b/db/migrate/20211005134955_create_p_fournisseur_refs.rb new file mode 100644 index 0000000..dc65fc0 --- /dev/null +++ b/db/migrate/20211005134955_create_p_fournisseur_refs.rb @@ -0,0 +1,11 @@ +class CreatePFournisseurRefs < ActiveRecord::Migration[6.0] + def change + create_table :p_fournisseur_refs do |t| + t.string :ref + t.references :p_product_ref, foreign_key: true + t.references :p_fournisseur, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index dc64e8d..15f694f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_10_04_161753) do +ActiveRecord::Schema.define(version: 2021_10_05_134955) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -1451,6 +1451,16 @@ ActiveRecord::Schema.define(version: 2021_10_04_161753) do t.index ["p_fournisseur_id"], name: "index_p_fournisseur_orders_on_p_fournisseur_id" end + create_table "p_fournisseur_refs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| + t.string "ref" + t.bigint "p_product_ref_id" + t.bigint "p_fournisseur_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["p_fournisseur_id"], name: "index_p_fournisseur_refs_on_p_fournisseur_id" + t.index ["p_product_ref_id"], name: "index_p_fournisseur_refs_on_p_product_ref_id" + end + create_table "p_fournisseurs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" t.string "code" @@ -3158,6 +3168,8 @@ ActiveRecord::Schema.define(version: 2021_10_04_161753) do add_foreign_key "p_customer_product_prices", "p_customers" add_foreign_key "p_customer_product_prices", "p_product_refs" add_foreign_key "p_customer_ribs", "p_customers" + add_foreign_key "p_fournisseur_refs", "p_fournisseurs" + add_foreign_key "p_fournisseur_refs", "p_product_refs" add_foreign_key "p_product_aromes", "p_aromes" add_foreign_key "p_product_aromes", "p_products" add_foreign_key "p_product_images", "image_files" diff --git a/test/fixtures/p_fournisseur_refs.yml b/test/fixtures/p_fournisseur_refs.yml new file mode 100644 index 0000000..0e0af5e --- /dev/null +++ b/test/fixtures/p_fournisseur_refs.yml @@ -0,0 +1,11 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + ref: MyString + p_product_ref: one + p_fournisseur: one + +two: + ref: MyString + p_product_ref: two + p_fournisseur: two diff --git a/test/models/p_fournisseur_ref_test.rb b/test/models/p_fournisseur_ref_test.rb new file mode 100644 index 0000000..c6087ea --- /dev/null +++ b/test/models/p_fournisseur_ref_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class PFournisseurRefTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From e6945481e7cf20ca14d956d05d063c66a6bc5c31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 7 Oct 2021 16:30:39 +0200 Subject: [PATCH 092/131] add label to p_fournisseur_ref --- db/migrate/20211005134955_create_p_fournisseur_refs.rb | 1 + db/schema.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/db/migrate/20211005134955_create_p_fournisseur_refs.rb b/db/migrate/20211005134955_create_p_fournisseur_refs.rb index dc65fc0..a7d3866 100644 --- a/db/migrate/20211005134955_create_p_fournisseur_refs.rb +++ b/db/migrate/20211005134955_create_p_fournisseur_refs.rb @@ -2,6 +2,7 @@ class CreatePFournisseurRefs < ActiveRecord::Migration[6.0] def change create_table :p_fournisseur_refs do |t| t.string :ref + t.string :label t.references :p_product_ref, foreign_key: true t.references :p_fournisseur, foreign_key: true diff --git a/db/schema.rb b/db/schema.rb index 15f694f..83454f6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1453,6 +1453,7 @@ ActiveRecord::Schema.define(version: 2021_10_05_134955) do create_table "p_fournisseur_refs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "ref" + t.string "label" t.bigint "p_product_ref_id" t.bigint "p_fournisseur_id" t.datetime "created_at", precision: 6, null: false From 7e34e20757e504e4fdde7fe4f3ebd19e21f20655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 7 Oct 2021 17:19:22 +0200 Subject: [PATCH 093/131] p_fournisseur has_many p_fournisseur_ref --- app/models/p_fournisseur.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/p_fournisseur.rb b/app/models/p_fournisseur.rb index e585732..c804f32 100644 --- a/app/models/p_fournisseur.rb +++ b/app/models/p_fournisseur.rb @@ -1,6 +1,7 @@ class PFournisseur < ApplicationRecord # has_many :particulars, :as => :owner, :dependent => :destroy has_many :p_contacts, :as => :contactable, :dependent => :destroy + has_many :p_fournisseur_refs acts_as_csv_import :fields => [ :name, From 97f0ae99c50947b2d70a5cd39986acd8ab49aece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 7 Oct 2021 17:19:56 +0200 Subject: [PATCH 094/131] price_document import --- app/models/price_document.rb | 87 +++++++++++++++++------------------- 1 file changed, 41 insertions(+), 46 deletions(-) diff --git a/app/models/price_document.rb b/app/models/price_document.rb index 3fe9fe5..5161238 100644 --- a/app/models/price_document.rb +++ b/app/models/price_document.rb @@ -31,7 +31,7 @@ class PriceDocument < ApplicationRecord AVANCEMENT = ["0%", "25%", "50%", "75%", "100"] validates :public_fournisseur_name, :presence => true, :if => :public_fournisseur_name_needed? - acts_as_csv_import :fields => [:p_fournisseur_id, :p_product_ref] + acts_as_csv_import :fields => [:p_fournisseur_id, :p_fournisseur_name, :p_fournisseur_ref_ref, :p_fournisseur_ref_label, :p_product_ref_name, :price_line_qte, :date, :price_line_ct_u_price_ht, :p_devise ] def public_fournisseur_name_needed? if self.label == "Réponse fournisseur" @@ -709,57 +709,52 @@ class PriceDocument < ApplicationRecord def self.custom_csv_import(list, import_csv) - ap "*********************************************************************************************************" - ap "*********************************************************************************************************" - ap "*********************************************************************************************************" - ap list - ap list.class - ap "*********************************************************************************************************" - ap "*********************************************************************************************************" - ap "*********************************************************************************************************" - ap import_csv - ap "*********************************************************************************************************" - ap "*********************************************************************************************************" - ap "*********************************************************************************************************" list.each do |row| + p_product_ref = nil - n = self.new(price_document_type: PriceDocumentType.find_by_label("Catalogue fournisseur")) - # price_document = PriceDocument.new(price_document_type: PriceDocumentType.find_by_label("Catalogue fournisseur")) - contact_2 = nil - contact_3 = nil - row.each do |key, value| + p_devise = PDevise.find_by(symbol: row["p_devise"]) - if self.type_for_attribute(key) and self.type_for_attribute(key).type == :decimal - eval "n.#{key} = value.to_s.gsub(' ', '').gsub(',', '.')" - # elsif key == "p_fournisseur_id" - # price_document.p_fournisseur = PFournisseur.find(key) - # elsif key == "p_contact_comment" - # contact_1.p_contact_types << PContactType.find_or_create_by(name: value) - # elsif key == "p_contact_tel" - # contact_1.tel = value - # elsif key == "p_contact_skype" - # contact_1.skype = value - # elsif key == "p_contact_email_1" - # contact_1.email = value - # elsif key == "p_contact_email_2" - # contact_2 = PContact.new(email: value) - # elsif key == "p_contact_email_3" - # contact_3 = PContact.new(email: value) - # elsif key == "p_payment_type" - # n.p_payment_type_id = PPaymentType.find_or_create_by(name: value).id - else - eval "n.#{key} = value" - end + p_fournisseur = PFournisseur.find_by(id: row["p_fournisseur_id"]) + if row["p_fournisseur_id"].nil? + p_fournisseur = PFournisseur.find_by(name: row["p_fournisseur_name"]) end - # particular.organisation = self.name - # n.save - ap n - # n.p_contacts << contact_1 if (contact_1.name || contact_1.tel || contact_1.skype || contact_1.email) - # n.p_contacts << contact_2 if contact_2 - # n.p_contacts << contact_3 if contact_3 - # import_csv.import_csv_elements << ImportCsvElement.new(:element => n) + + raise "Fournisseur introuvable. Ajouter le fournisseur manquant avant l'import" if p_fournisseur.nil? + + n = self.find_or_initialize_by(price_document_type: PriceDocumentType.find_by_label("Catalogue fournisseur"), p_fournisseur: p_fournisseur, date: row["date"], p_devise: p_devise ) + if n.price_line_block.nil? + n.price_line_block = PriceLineBlock.new(p_devise: p_devise, p_fournisseur: p_fournisseur, imported: true) + end + + + if row["p_fournisseur_ref_ref"].present? + p_fournisseur_ref = PFournisseurRef.find_by(p_fournisseur: p_fournisseur, ref: row["p_fournisseur_ref_ref"]) + p_product_ref = p_fournisseur_ref.p_product_ref if p_fournisseur_ref + else + p_fournisseur_ref = PFournisseurRef.find_by(p_fournisseur: p_fournisseur, label: row["p_fournisseur_ref_label"]) + p_product_ref = p_fournisseur_ref.p_product_ref if p_fournisseur_ref + end + + + if row["price_line_qte"].kind_of? Float + qte = row["price_line_qte"] + elsif row["price_line_qte"].kind_of? Integer + qte = row["price_line_qte"].to_f + elsif row["price_line_qte"].kind_of? String + qte = row["price_line_qte"].split.map {|x| x[/\d+/]}[0].to_f + else + qte = 0 + end + + price_line = PriceLine.new(p_product_ref: p_product_ref, ct_ref: row["p_fournisseur_ref_ref"], ct_title: row["p_fournisseur_ref_label"], price_line_block: n.price_line_block, qte: qte || 0.0, ct_u_price_ht: row["price_line_ct_u_price_ht"], imported: true ) + price_line.p_product = p_product_ref.p_product if p_product_ref && p_product_ref.p_product + n.price_line_block.price_lines << price_line + + + n.save + import_csv.import_csv_elements << ImportCsvElement.new(:element => n) end end From 5a3cd4163b35af2f4b2add1a42eab3911e7d2f93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 7 Oct 2021 17:21:37 +0200 Subject: [PATCH 095/131] p_product_ref_match --- .../admin/import_csvs_controller.rb | 9 +- .../admin/p_products_controller.rb | 2 +- .../admin/price_documents_controller.rb | 2 + app/controllers/application_controller.rb | 1 + app/models/p_product_ref.rb | 1 + app/models/price_line.rb | 24 ++++- app/models/price_line_block.rb | 2 +- .../admin/import_csvs/match_refs.html.haml | 26 ++++++ .../price_lines/_form_match_refs.html.haml | 93 +++++++++++++++++++ config/routes.rb | 3 + 10 files changed, 155 insertions(+), 8 deletions(-) create mode 100644 app/views/admin/import_csvs/match_refs.html.haml create mode 100644 app/views/admin/price_lines/_form_match_refs.html.haml diff --git a/app/controllers/admin/import_csvs_controller.rb b/app/controllers/admin/import_csvs_controller.rb index 4f8ae2c..9f70258 100644 --- a/app/controllers/admin/import_csvs_controller.rb +++ b/app/controllers/admin/import_csvs_controller.rb @@ -31,13 +31,20 @@ class Admin::ImportCsvsController < ApplicationController end + def match_refs + @price_documents = PriceDocument.joins(price_line_block: :price_lines).where({price_line_block: {price_lines: {p_product_ref: nil}}}).distinct + redirect_to :action => :index if @price_documents.empty? + end + def charge @import_csv = ImportCsv.find(params[:id]) @import_csv.load - redirect_to :action => :index + # redirect_to :action => :index + redirect_to match_refs_admin_import_csvs_path end + def new @import_csv = ImportCsv.new(:parent_id => params[:parent_id]) if @import_csv.parent diff --git a/app/controllers/admin/p_products_controller.rb b/app/controllers/admin/p_products_controller.rb index 9cb4915..2ded2ca 100644 --- a/app/controllers/admin/p_products_controller.rb +++ b/app/controllers/admin/p_products_controller.rb @@ -72,7 +72,7 @@ class Admin::PProductsController < ApplicationController @p_product = PProduct.new #(:p_customer_cat_ids => [3]) - + @p_product.name = params[:p_fournisseur_ref_label] if params[:p_fournisseur_ref_label] # @p_product.p_product_refs << PProductRef.new @p_product_refs = @p_product.p_product_refs.build @p_product_ref_specs = @p_product_refs.p_product_ref_specs.build diff --git a/app/controllers/admin/price_documents_controller.rb b/app/controllers/admin/price_documents_controller.rb index b224d70..f0b89fc 100644 --- a/app/controllers/admin/price_documents_controller.rb +++ b/app/controllers/admin/price_documents_controller.rb @@ -360,6 +360,8 @@ class Admin::PriceDocumentsController < ApplicationController redirect_to [:admin, PriceDocument.find(@price_document.doc_ref_id)] elsif @price_document.ref_element redirect_to [:admin, @price_document.ref_element] + elsif @price_document.label == "Catalogue fournisseur" + redirect_to match_refs_admin_import_csvs_path else redirect_to [:admin, @price_document] end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 06d193f..a0b3022 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -127,6 +127,7 @@ class ApplicationController < ActionController::Base set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_product_powers, "Types de chargeurs" set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_product_zones, "Zones produits" set_sub_sub_menu :stocks, :p_preferences_products_menu, :import_csvs, "Import Excel" + set_sub_sub_menu :stocks, :p_preferences_products_menu, :import_csv_match_refs, "Rapprochement références", match_refs_admin_import_csvs_path end diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb index 9a7fccf..4b9d5a3 100644 --- a/app/models/p_product_ref.rb +++ b/app/models/p_product_ref.rb @@ -22,6 +22,7 @@ class PProductRef < ApplicationRecord has_many :p_customer_product_prices, :dependent => :destroy accepts_nested_attributes_for :p_customer_product_prices, allow_destroy: true + has_many :p_fournisseur_refs scope :enableds, -> {where(:enabled => true)} diff --git a/app/models/price_line.rb b/app/models/price_line.rb index 32e2d5b..897399c 100644 --- a/app/models/price_line.rb +++ b/app/models/price_line.rb @@ -14,6 +14,7 @@ class PriceLine < ApplicationRecord default_scope { order('position ASC') } validates :p_product_ref_id, :presence => true, :if => :p_product_ref_needed? + validates :p_product_id, :presence => true, :if => :p_product_needed? validates :qte, :presence => true @@ -21,7 +22,8 @@ class PriceLine < ApplicationRecord has_many :line_stocks - + after_update :memorize_p_fournisseur_ref, if: :p_fournisseur_ref_is_memorizable? + acts_as_sorting :fields => { :ref => {:name => "Ref", :reorder => true}, :title => {:name => "Désignation", :reorder => true}, @@ -58,7 +60,7 @@ class PriceLine < ApplicationRecord 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) - + def to_no_archive if !self.imported %w(cost_ht marge_ht) @@ -170,7 +172,13 @@ class PriceLine < ApplicationRecord true end end - + + def p_product_needed? + if !self.ct_title? and !self.imported + true + end + end + def personalised_archive end @@ -617,6 +625,12 @@ class PriceLine < ApplicationRecord return [asap, non_asap] end - - + def p_fournisseur_ref_is_memorizable? + self.p_product_ref.present? && self.imported? && PFournisseurRef.where(p_fournisseur: self.p_fournisseur, ref: self.ct_ref, label: self.ct_title).empty? + end + + def memorize_p_fournisseur_ref + PFournisseurRef.create(p_fournisseur: self.p_fournisseur, p_product_ref: self.p_product_ref, ref: self.ct_ref, label: self.ct_title) + end + end diff --git a/app/models/price_line_block.rb b/app/models/price_line_block.rb index 942a0ea..223aab1 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 = ["Réponse fournisseur", "Consultation fournisseur", "Facture d'achat", "Commande achat", "Demande prix", "Bon de commande achat", "Bon de réception achat", "Facture achat", "Avoir achat"] + PURCHASE_BLOCKS = ["Réponse fournisseur", "Consultation fournisseur", "Facture d'achat", "Commande achat", "Demande prix", "Bon de commande achat", "Bon de réception achat", "Facture achat", "Avoir achat", "Catalogue fournisseur"] SALE_BLOCKS = ["Demande de commande", "Bon de commande", "Devis", "Bon de livraison", "Facture", "Avoir"] diff --git a/app/views/admin/import_csvs/match_refs.html.haml b/app/views/admin/import_csvs/match_refs.html.haml new file mode 100644 index 0000000..c44a8c0 --- /dev/null +++ b/app/views/admin/import_csvs/match_refs.html.haml @@ -0,0 +1,26 @@ +:javascript + var p_product_refs_url = "#{admin_p_product_refs_path(:manager => true)}" +.qi_row + %h1 Rapprochement de références produits + + -@price_documents.each do |price_document| + %br + .qi_pannel.qi_plain.padding.mt-4 + =semantic_form_for [:admin, price_document] do |f| + =f.semantic_fields_for :price_line_block do |f| + %h2= "Import catalogue : " + f.object.p_fournisseur.name + %div{:style=>"padding:0 30px;"} + .row.qi_field_wrapper + %table{:style => "width:100%;border-collapse:separate;"} + %thead + %tr + %th + %th Référence Produit Arcom + %th Créer une référence + %th Référence fournisseur + %th + %tbody.price_lines_form + =f.semantic_fields_for :price_lines do |form| + -if form.object.p_product_ref.nil? + =render :partial => "admin/price_lines/form_match_refs", :locals => {:form => form} + =f.submit "Valider", class: "btn btn-primary mt-3" diff --git a/app/views/admin/price_lines/_form_match_refs.html.haml b/app/views/admin/price_lines/_form_match_refs.html.haml new file mode 100644 index 0000000..a8c2482 --- /dev/null +++ b/app/views/admin/price_lines/_form_match_refs.html.haml @@ -0,0 +1,93 @@ +%tr.qi_pannel.qi_plain.padding.price_line_form.col-12.field{:style =>"border-left:4px solid gray;margin-bottom:10px;padding-left:5px;"} + + + %td{:style => "width: 30px;", :class => ("error has-error" if form.object.errors[:p_product_ref_id].size > 0 )} + .take.text-center.px-2 + =ic :arrows + %td{:style => "white-space: nowrap; width: 400px;"} + + + + .input-group + %input.p_product_ref_autocomplete_input.form-control{:type => "text", :style => "", tabindex: 1, autofocus: true, :value => ("#{form.object.p_product_ref.member_label}" if form.object.p_product_ref), :class => "p_product_ref_name"} + =form.hidden_field :p_product_ref_id, :class => "p_product_ref_id" + + + + + .input-group-append + =link_to "#", class: "btn btn-dark",:onclick => "key=genRanHex(12);select_product_from_manager(key);$(this).closest('tr').find('.p_product_ref_id').attr('id', 'p_product_ref_id_'+key);$(this).closest('tr').find('.p_product_ref_name').attr('id', 'p_product_ref_name_'+key);$(this).closest('tr').find('.p_product_ref_qte').attr('id', 'p_product_ref_qte_'+key);return false;" do + =ic(:search) + + + %td.text-center{style: "width: 80px;"} + %span=link_to ic(:"plus"), new_admin_p_product_path(p_fournisseur_ref_label: form.object.title) + + + + %td.pl-2 + =form.object.title + %td.text-center{style: "width: 30px;"} + %span.destroy=link_to_remove_fields ic(:"trash-o"), form + + + =qi_js_field(form, :price_line, :tva_account_value, :hidden => true) + + = form.hidden_field :position, :class => "price_line_position_input" + + +:javascript + $('.p_product_ref_autocomplete_input').focus() + $( function() { + $('.p_product_ref_autocomplete_input').autocomplete({ + source: function( request, response ) { + $.ajax( { + url: "/admin/p_product_refs/autocomplete.json", + dataType: "json", + data: { + search: request.term, + p_customer_id: $(".p_customer_id").val() + }, + success: function(data){ + arr = jQuery.map( data, function( item ) { + return { + label: item.member_label, + value: item.member_label, + id: item.id + } + }); + response(arr) + } + }); + }, + minLength: 2, + select: function( event, ui ) { + $(this).next(".p_product_ref_id").val(ui.item.id) + form = $(this).closest(".price_line_form") + $.ajax( { + url: "/admin/p_product_refs/"+ui.item.id+"/get_infos.json", + dataType: "json", + data: { + type: "price", + qte: form.find(".input_price_line_qte").val(), + p_customer_id: $(".p_customer_id").val() + }, + success: function (data) { + form.find(".input_price_line_price_u_ht").val(data.price); + form.find(".input_price_line_tva_account_id").val(data.tva_account_id); + form.find(".input_price_line_tva_account_value").val(data.tva_account_value); + form.find(".input_price_line_weight_u").val(data.weight); + } + }); + //return false + } + }); + }); + + +:scss + .price_line_form{ + .form-group{ + margin-bottom:0;} + + } diff --git a/config/routes.rb b/config/routes.rb index d3a9d8a..6b62c9c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -456,6 +456,9 @@ Rails.application.routes.draw do namespace :admin do resources :import_csvs do + collection do + get :match_refs + end member do get :charge end From 1fc9e696bc6d8d1ba13455b2b7ac195361433f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 7 Oct 2021 17:21:48 +0200 Subject: [PATCH 096/131] bugfix autocomplete --- app/views/admin/price_lines/_form.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/price_lines/_form.html.haml b/app/views/admin/price_lines/_form.html.haml index 123ca49..6861e44 100644 --- a/app/views/admin/price_lines/_form.html.haml +++ b/app/views/admin/price_lines/_form.html.haml @@ -10,6 +10,7 @@ .input-group %input.p_product_ref_autocomplete_input.form-control{:type => "text", :style => "", tabindex: 1, autofocus: true, :value => ("#{form.object.p_product_ref.member_label}" if form.object.p_product_ref), :class => "p_product_ref_name"} + = form.hidden_field :p_product_ref_id, :class => "p_product_ref_id" @@ -22,7 +23,6 @@ - = form.hidden_field :p_product_ref_id, :class => "p_product_ref_id" From 296e4aef5fa29aadf2c3b9b86fac1a92eb074c82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 8 Oct 2021 19:24:16 +0200 Subject: [PATCH 097/131] add new p_product_ref after import --- .../admin/import_csvs_controller.rb | 17 ++++ .../admin/p_product_refs_controller.rb | 12 ++- .../admin/p_products_controller.rb | 4 +- app/models/p_product.rb | 5 +- app/models/p_product_ref.rb | 5 +- app/models/p_product_ref_spec.rb | 2 + .../_form_temp_p_product.html.haml | 89 +++++++++++++++++++ .../admin/import_csvs/temp_p_product.js.erb | 1 + .../admin/p_product_ref_specs/_form.html.haml | 8 +- app/views/admin/p_product_refs/update.js.erb | 8 +- .../price_lines/_form_match_refs.html.haml | 4 +- config/routes.rb | 1 + 12 files changed, 138 insertions(+), 18 deletions(-) create mode 100644 app/views/admin/import_csvs/_form_temp_p_product.html.haml create mode 100644 app/views/admin/import_csvs/temp_p_product.js.erb diff --git a/app/controllers/admin/import_csvs_controller.rb b/app/controllers/admin/import_csvs_controller.rb index 9f70258..9d3ebb1 100644 --- a/app/controllers/admin/import_csvs_controller.rb +++ b/app/controllers/admin/import_csvs_controller.rb @@ -92,4 +92,21 @@ class Admin::ImportCsvsController < ApplicationController @import_csv.destroy end + + def temp_p_product + dev_mode = false + if dev_mode + @p_product_ref = PProductRef.last #DEV mode only + @price_line = PriceLine.find(params[:price_line_id]) + + @p_product_ref.ct_price_ht = @price_line.ct_u_price_ht #DEV ode onmy + @p_product_ref.p_product_ref_specs.build + else + if params[:price_line_id] + @price_line = PriceLine.find(params[:price_line_id]) + @p_product_ref = PProductRef.find_or_create_by(p_product: PProduct.find_by(name: "--> Selectioner un produit <--"), ct_sub_name: @price_line.title, ct_price_ht: @price_line.ct_u_price_ht) + @p_product_ref.p_product_ref_specs.build + end + end + end end diff --git a/app/controllers/admin/p_product_refs_controller.rb b/app/controllers/admin/p_product_refs_controller.rb index 736d823..2ff7f98 100644 --- a/app/controllers/admin/p_product_refs_controller.rb +++ b/app/controllers/admin/p_product_refs_controller.rb @@ -1,6 +1,8 @@ # -*- encoding : utf-8 -*- class Admin::PProductRefsController < ApplicationController + include ActionView::RecordIdentifier # adds `dom_id` + layout "admin" before_action :auth_admin @@ -102,12 +104,14 @@ class Admin::PProductRefsController < ApplicationController def update + @p_product_ref = PProductRef.find(params[:id]) - - if @p_product_ref.update_attributes(params.require(:p_product_ref).permit!) - - + if params[:update_price_line_id] + @price_line = PriceLine.find(params[:update_price_line_id]) + @price_line.update(p_product_ref: @p_product_ref) + end + # redirect_to admin_p_products_path(@p_product_ref.p_product, anchor: dom_id(@p_product_ref)) else render action: "edit" diff --git a/app/controllers/admin/p_products_controller.rb b/app/controllers/admin/p_products_controller.rb index 2ded2ca..aef9a1a 100644 --- a/app/controllers/admin/p_products_controller.rb +++ b/app/controllers/admin/p_products_controller.rb @@ -72,9 +72,9 @@ class Admin::PProductsController < ApplicationController @p_product = PProduct.new #(:p_customer_cat_ids => [3]) - @p_product.name = params[:p_fournisseur_ref_label] if params[:p_fournisseur_ref_label] # @p_product.p_product_refs << PProductRef.new - @p_product_refs = @p_product.p_product_refs.build + fournisseur_label = params[:fournisseur_label] if params[:fournisseur_label] + @p_product_refs = @p_product.p_product_refs.build(ct_sub_name: fournisseur_label) @p_product_ref_specs = @p_product_refs.p_product_ref_specs.build @p_spec_type = @p_product_ref_specs.build_p_spec_type @p_spec_value = @p_product_ref_specs.build_p_spec_value diff --git a/app/models/p_product.rb b/app/models/p_product.rb index 893a83c..ef6cdc6 100644 --- a/app/models/p_product.rb +++ b/app/models/p_product.rb @@ -33,9 +33,8 @@ class PProduct < ApplicationRecord belongs_to :p_product_cat belongs_to :s_brand - validates :name, :presence => true - validates :code, :presence => true, :uniqueness => true - + validates :name, :presence => true, exclusion: { in: ["--> Selectioner un produit <--"], message: "Selectioner un produit avant de valider" } + validates :code, :presence => true, :uniqueness => true, exclusion: { in: ["--> Indiquer un code produit <--"], message: "Indiquer un code produit avant de valider" } has_many :tvable_tva_rates, :as => :tvable has_many :tva_rates, :through => :tvable_tva_rates diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb index 4b9d5a3..d11adc1 100644 --- a/app/models/p_product_ref.rb +++ b/app/models/p_product_ref.rb @@ -15,7 +15,7 @@ class PProductRef < ApplicationRecord accepts_nested_attributes_for :p_article_serial_nums, allow_destroy: true has_many :p_product_ref_specs - accepts_nested_attributes_for :p_product_ref_specs, allow_destroy: true + accepts_nested_attributes_for :p_product_ref_specs, allow_destroy: true, reject_if: :all_blank #validates :ct_price_ht, :presence => true validate :ean, :is_integer @@ -88,7 +88,8 @@ class PProductRef < ApplicationRecord self.p_product.p_product_cat_id end - QI_DYNAMICS = %w(name code p_product_cat_id sub_cat_names cat_name) + # QI_DYNAMICS = %w(name code p_product_cat_id sub_cat_names cat_name) + QI_DYNAMICS = %w(name code p_product_cat_id cat_name) #sub_cat_names removed eval(QI_DYNAMICS_CORE) diff --git a/app/models/p_product_ref_spec.rb b/app/models/p_product_ref_spec.rb index a036951..e15b3f1 100644 --- a/app/models/p_product_ref_spec.rb +++ b/app/models/p_product_ref_spec.rb @@ -5,6 +5,8 @@ class PProductRefSpec < ApplicationRecord accepts_nested_attributes_for :p_spec_type, :p_spec_value + validates :p_spec_type_id, :p_spec_value_id, presence: true + acts_as_sorting :fields => { :id => {:name => "ID"}, :p_product_ref => {:name => "Référence produit", :reorder => true}, diff --git a/app/views/admin/import_csvs/_form_temp_p_product.html.haml b/app/views/admin/import_csvs/_form_temp_p_product.html.haml new file mode 100644 index 0000000..afa6595 --- /dev/null +++ b/app/views/admin/import_csvs/_form_temp_p_product.html.haml @@ -0,0 +1,89 @@ +=semantic_form_for [:admin, @p_product_ref], remote: true do |form| + =hidden_field_tag :update_price_line_id, @price_line.id + .content + .qi_row.field + .padding + + %h1 Ajouter une références + %table.form-table + %tr + %td{colspan: 3} + %label Selectionner le produit parent + .input-group + %input.p_product_autocomplete_input.form-control{:type => "text", :style => "", tabindex: 1, autofocus: true, :class => "p_product_name"} + =form.hidden_field :p_product_id, :class => "p_product_id" + + =link_to ic(:plus)+ " Ajouter produit", new_admin_p_product_path(fournisseur_label: @p_product_ref.ct_sub_name) + + %tr + %td{:colspan => 3} + %input.form-control{type: "text", placeholder: @p_product_ref.ct_sub_name, "aria-label" => "Disabled input example", disabled: true} + =#form.input :ct_sub_name, label: "Label fournisseur", input_html: {disabled: true} + + %tr + %td{:colspan => 3} + = form.input :ct_sub_name, :label => "Désignation ARCOM :" + %tr + %td + = form.input :ref, :label => "Réf int. :" + + %td + = form.input :ct_price_ht, :label => "Prix vente HT :" + + %td + =form.input :p_product_color_id, :label => "Couleur :", :collection => PProductColor.all, :as => :select, :include_blank => true, input_html: {class: "custom-select"} + %tr + %td + =form.input :ct_sorecop, :label => "Sorecop personalisée :" + %td + =form.input :sorecop_comment, :label => "Type de Sorecop :" + %td + =form.input :ct_deee, :label => "DEEE personalisée :" + %tr + %td + =form.input :ean + + %td{:colspan => 2} + = form.input :description, :label => "Désignation longue :" , :input_html => {rows: 1} + + %tr + %td{:colspan => 3} + .qi_pannel.qi_plain.padding + .p_product_ref_specs_form + = form.semantic_fields_for :p_product_ref_specs do |f| + =render :partial => "admin/p_product_ref_specs/form", :locals => {:form => f} + %p= link_to_add_fields "Ajouter une spec", form, :p_product_ref_specs + + .actions=form.submit "sauvegarder", :class => "btn btn-primary" + + + +:javascript + $('.p_product_autocomplete_input').focus() + $( function() { + $('.p_product_autocomplete_input').autocomplete({ + source: function( request, response ) { + $.ajax( { + url: "/admin/p_products/autocomplete.json", + dataType: "json", + data: { + search: request.term, + }, + success: function(data){ + arr = jQuery.map( data, function( item ) { + return { + label: item.name, + value: item.name, + id: item.id + } + }); + response(arr) + } + }); + }, + minLength: 2, + select: function( event, ui ) { + $(this).next(".p_product_id").val(ui.item.id) + } + }); + }); diff --git a/app/views/admin/import_csvs/temp_p_product.js.erb b/app/views/admin/import_csvs/temp_p_product.js.erb new file mode 100644 index 0000000..0562b62 --- /dev/null +++ b/app/views/admin/import_csvs/temp_p_product.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form_temp_p_product"))%>",700,900); diff --git a/app/views/admin/p_product_ref_specs/_form.html.haml b/app/views/admin/p_product_ref_specs/_form.html.haml index ffde9d3..d369fed 100644 --- a/app/views/admin/p_product_ref_specs/_form.html.haml +++ b/app/views/admin/p_product_ref_specs/_form.html.haml @@ -15,15 +15,15 @@ %table %tr %td - %h4 spec : - + %h4 Specs : + %tr %td -#form.object.p_spec_type = PSpecType.new if !form.object.p_spec_type -#form.object.p_spec_value = PSpecValue.new if !form.object.p_spec_value - = form.input :p_spec_type_id, :label => "Type", as: :select, collection: PSpecType.all, :include_blank => false + = form.input :p_spec_type_id, :label => "Type", as: :select, collection: PSpecType.all, :include_blank => true,input_html: {class: "custom-select"} %td - = form.input :p_spec_value_id, :label => "Valeur", as: :select, collection: PSpecValue.all, :include_blank => false, :member_label => :member_label + = form.input :p_spec_value_id, :label => "Valeur", as: :select, collection: PSpecValue.all, :include_blank => true, :member_label => :member_label, input_html: {class: "custom-select"} =#form.inputs do diff --git a/app/views/admin/p_product_refs/update.js.erb b/app/views/admin/p_product_refs/update.js.erb index 49eb092..8b84b1e 100644 --- a/app/views/admin/p_product_refs/update.js.erb +++ b/app/views/admin/p_product_refs/update.js.erb @@ -1,2 +1,8 @@ $('#p_product_ref_row_<%= @p_product_ref.id %>').replaceWith("<%= escape_javascript(render(@p_product_ref))%>"); -close_pane_hover(); \ No newline at end of file + +if ($('#<%= dom_id(@price_line) %>').parents('.qi_pannel.qi_plain').find('tbody').find('tr').length === 1) { + $('#<%= dom_id(@price_line) %>').parents('.qi_pannel.qi_plain').remove() +} +$('#<%= dom_id(@price_line) %>').remove(); + +close_pane_hover(); diff --git a/app/views/admin/price_lines/_form_match_refs.html.haml b/app/views/admin/price_lines/_form_match_refs.html.haml index a8c2482..fb4fc62 100644 --- a/app/views/admin/price_lines/_form_match_refs.html.haml +++ b/app/views/admin/price_lines/_form_match_refs.html.haml @@ -1,4 +1,4 @@ -%tr.qi_pannel.qi_plain.padding.price_line_form.col-12.field{:style =>"border-left:4px solid gray;margin-bottom:10px;padding-left:5px;"} +%tr.qi_pannel.qi_plain.padding.price_line_form.col-12.field{:style =>"border-left:4px solid gray;margin-bottom:10px;padding-left:5px;", id: dom_id(form.object)} %td{:style => "width: 30px;", :class => ("error has-error" if form.object.errors[:p_product_ref_id].size > 0 )} @@ -21,7 +21,7 @@ %td.text-center{style: "width: 80px;"} - %span=link_to ic(:"plus"), new_admin_p_product_path(p_fournisseur_ref_label: form.object.title) + %span=link_to ic(:"plus"), temp_p_product_admin_import_csvs_path(price_line_id: form.object.id), remote: true diff --git a/config/routes.rb b/config/routes.rb index 6b62c9c..59be0a4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -458,6 +458,7 @@ Rails.application.routes.draw do resources :import_csvs do collection do get :match_refs + get :temp_p_product end member do get :charge From 63d1069be5e426efee38b7b6d5ec1105eb457d1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 8 Oct 2021 19:24:31 +0200 Subject: [PATCH 098/131] small improvement --- app/views/admin/p_product_refs/_form.html.haml | 6 +++--- app/views/admin/p_product_refs/_p_product_ref.html.haml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/admin/p_product_refs/_form.html.haml b/app/views/admin/p_product_refs/_form.html.haml index 4b0b755..8b4149f 100644 --- a/app/views/admin/p_product_refs/_form.html.haml +++ b/app/views/admin/p_product_refs/_form.html.haml @@ -1,6 +1,6 @@ =#debug form.object.errors.messages =# form.input :ref, :label => "Ref :" -.qi_row.field +.qi_row.field{id: dom_id(form.object)} .qi_pannel.qi_plain.padding %table.form-table @@ -19,7 +19,7 @@ = form.input :ct_price_ht, :label => "Prix vente HT :" %td - =form.input :p_product_color_id, :label => "Couleur :", :collection => PProductColor.all, :as => :select, :include_blank => true + =form.input :p_product_color_id, :label => "Couleur :", :collection => PProductColor.all, :as => :select, :include_blank => true, input_html: {class: "custom-select"} %td =form.input :ct_sorecop, :label => "Sorecop personalisée :" %td @@ -44,7 +44,7 @@ %tr %td{:colspan => 2} %td{:colspan => 4} - = form.input :description, :label => "Désignation longue :" , :input_html => {:style => "height:100px;"} + = form.input :description, :label => "Désignation longue :" , :input_html => {rows: 1} -if false %tr diff --git a/app/views/admin/p_product_refs/_p_product_ref.html.haml b/app/views/admin/p_product_refs/_p_product_ref.html.haml index ca09295..3fb1b23 100644 --- a/app/views/admin/p_product_refs/_p_product_ref.html.haml +++ b/app/views/admin/p_product_refs/_p_product_ref.html.haml @@ -37,10 +37,10 @@ = link_to i(:"check"), "#",:onclick => "send_manager_product('"+p_product_ref.id.to_s+"', '"+escape_javascript(p_product_ref.member_label.to_s)+"');return false;" -else - = link_to i(:pencil), edit_admin_p_product_path(p_product_ref.p_product), :remote => false + = link_to i(:pencil), edit_admin_p_product_path(p_product_ref.p_product, anchor: dom_id(p_product_ref)), :remote => false = link_to i(:eye), admin_p_product_ref_path(p_product_ref), :remote => false =render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => p_product_ref} - \ No newline at end of file + From dbc8d3bfd67d50b248fcadf5f2ab34ae4e545514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 11 Oct 2021 19:07:32 +0200 Subject: [PATCH 099/131] refacto --- app/controllers/admin/import_csvs_controller.rb | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/app/controllers/admin/import_csvs_controller.rb b/app/controllers/admin/import_csvs_controller.rb index 9d3ebb1..bac0c29 100644 --- a/app/controllers/admin/import_csvs_controller.rb +++ b/app/controllers/admin/import_csvs_controller.rb @@ -94,19 +94,11 @@ class Admin::ImportCsvsController < ApplicationController end def temp_p_product - dev_mode = false - if dev_mode - @p_product_ref = PProductRef.last #DEV mode only + if params[:price_line_id] @price_line = PriceLine.find(params[:price_line_id]) - - @p_product_ref.ct_price_ht = @price_line.ct_u_price_ht #DEV ode onmy + p_product = PProduct.find_or_create_by(name: "--> Selectioner un produit <--", code: "--> Indiquer un code produit <--") + @p_product_ref = PProductRef.find_or_create_by(p_product: p_product, ct_sub_name: @price_line.title, ct_price_ht: @price_line.ct_u_price_ht) @p_product_ref.p_product_ref_specs.build - else - if params[:price_line_id] - @price_line = PriceLine.find(params[:price_line_id]) - @p_product_ref = PProductRef.find_or_create_by(p_product: PProduct.find_by(name: "--> Selectioner un produit <--"), ct_sub_name: @price_line.title, ct_price_ht: @price_line.ct_u_price_ht) - @p_product_ref.p_product_ref_specs.build - end end end end From e56c6bb37dae798bdc6d0a5e3df6d6de0bd66ae5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 11 Oct 2021 19:13:34 +0200 Subject: [PATCH 100/131] update price_line after create p_product + destroy callbacks --- app/controllers/admin/p_products_controller.rb | 3 +++ app/models/p_product.rb | 8 +++++++- app/models/p_product_ref.rb | 13 +++++++++++++ .../import_csvs/_form_temp_p_product.html.haml | 2 +- app/views/admin/p_product_refs/_form.html.haml | 4 +++- 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/p_products_controller.rb b/app/controllers/admin/p_products_controller.rb index aef9a1a..871bd95 100644 --- a/app/controllers/admin/p_products_controller.rb +++ b/app/controllers/admin/p_products_controller.rb @@ -74,6 +74,9 @@ class Admin::PProductsController < ApplicationController @p_product = PProduct.new #(:p_customer_cat_ids => [3]) # @p_product.p_product_refs << PProductRef.new fournisseur_label = params[:fournisseur_label] if params[:fournisseur_label] + if params[:price_line_id] + @price_line = PriceLine.find(params[:price_line_id]) + end @p_product_refs = @p_product.p_product_refs.build(ct_sub_name: fournisseur_label) @p_product_ref_specs = @p_product_refs.p_product_ref_specs.build @p_spec_type = @p_product_ref_specs.build_p_spec_type diff --git a/app/models/p_product.rb b/app/models/p_product.rb index ef6cdc6..4e501c0 100644 --- a/app/models/p_product.rb +++ b/app/models/p_product.rb @@ -103,15 +103,21 @@ class PProduct < ApplicationRecord after_create do - end after_save do self.p_product_refs.each do |ppr| ppr.save end + self.class.destroy_temp_p_product end + def self.destroy_temp_p_product + temp_p_product = PProduct.find_by(name: "--> Selectioner un produit <--", code: "--> Indiquer un code produit <--") + if temp_p_product.present? + temp_p_product.destroy + end + end def tva_rate(accounting_zone_id) if r = self.tva_rates.where(:accounting_zone_id => accounting_zone_id).first diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb index d11adc1..3203fc1 100644 --- a/app/models/p_product_ref.rb +++ b/app/models/p_product_ref.rb @@ -53,6 +53,19 @@ class PProductRef < ApplicationRecord acts_as_caching :fields => [:sorecop, :deee] + attr_accessor :price_line_id + + after_create do + if self.price_line_id + pl = PriceLine.find(self.price_line_id) + pl.update(p_product_ref: self) + end + end + + after_save do + PProduct.destroy_temp_p_product + end + def not_imported? if !self.p_product or !self.p_product.imported true diff --git a/app/views/admin/import_csvs/_form_temp_p_product.html.haml b/app/views/admin/import_csvs/_form_temp_p_product.html.haml index afa6595..9173a3d 100644 --- a/app/views/admin/import_csvs/_form_temp_p_product.html.haml +++ b/app/views/admin/import_csvs/_form_temp_p_product.html.haml @@ -13,7 +13,7 @@ %input.p_product_autocomplete_input.form-control{:type => "text", :style => "", tabindex: 1, autofocus: true, :class => "p_product_name"} =form.hidden_field :p_product_id, :class => "p_product_id" - =link_to ic(:plus)+ " Ajouter produit", new_admin_p_product_path(fournisseur_label: @p_product_ref.ct_sub_name) + =link_to ic(:plus)+ " Ajouter produit", new_admin_p_product_path(fournisseur_label: @p_product_ref.ct_sub_name, price_line_id: @price_line.id) %tr %td{:colspan => 3} diff --git a/app/views/admin/p_product_refs/_form.html.haml b/app/views/admin/p_product_refs/_form.html.haml index 8b4149f..f89bf35 100644 --- a/app/views/admin/p_product_refs/_form.html.haml +++ b/app/views/admin/p_product_refs/_form.html.haml @@ -11,7 +11,9 @@ %td = form.input :ref, :label => "Réf int. :" =#form.hidden_field :ref_id - + -if @price_line + =form.hidden_field :price_line_id, value: @price_line.id + %td = form.input :ct_sub_name, :label => "Désignation :" From 906e101881e5f268fb2bc06ed0fe80802455720c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 11 Oct 2021 19:13:58 +0200 Subject: [PATCH 101/131] uncomment element add --- app/models/p_fournisseur.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/p_fournisseur.rb b/app/models/p_fournisseur.rb index c804f32..0b6de85 100644 --- a/app/models/p_fournisseur.rb +++ b/app/models/p_fournisseur.rb @@ -76,7 +76,7 @@ class PFournisseur < ApplicationRecord n.p_contacts << contact_1 if (contact_1.name || contact_1.tel || contact_1.skype || contact_1.email) n.p_contacts << contact_2 if contact_2 n.p_contacts << contact_3 if contact_3 - # import_csv.import_csv_elements << ImportCsvElement.new(:element => n) + import_csv.import_csv_elements << ImportCsvElement.new(:element => n) end end end From 8f92692d79fb618193fd799fdcca42138e5d6cc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Wed, 13 Oct 2021 18:13:47 +0200 Subject: [PATCH 102/131] refacto import --- app/models/p_fournisseur.rb | 125 +++++++++++++++++++++++++----------- 1 file changed, 89 insertions(+), 36 deletions(-) diff --git a/app/models/p_fournisseur.rb b/app/models/p_fournisseur.rb index 0b6de85..44a7f77 100644 --- a/app/models/p_fournisseur.rb +++ b/app/models/p_fournisseur.rb @@ -4,27 +4,27 @@ class PFournisseur < ApplicationRecord has_many :p_fournisseur_refs acts_as_csv_import :fields => [ - :name, - :address1, + :nom_fournisseur, + :address, :cp, - :city, - :country, - :email, + :ville, + :pays, + :tva_intracom, + :delai_paiement, + :interlocuteur, + :fonction, :tel, - :p_contact_name, - :p_contact_comment, - :p_contact_tel, - :p_contact_skype, - :p_contact_email_1, - :p_contact_email_2, - :p_contact_email_3, - :bic, + :skype, + :email_1, + :email_2, + :email_3, :iban, - :payment_delais, - :tva_num, - :p_payment_type + :bic, + :reglement_par ] + + def self.custom_csv_import(list, import_csv) # ap "*********************************************************************************************************" # ap "*********************************************************************************************************" @@ -50,33 +50,86 @@ class PFournisseur < ApplicationRecord if self.type_for_attribute(key) and self.type_for_attribute(key).type == :decimal eval "n.#{key} = value.to_s.gsub(' ', '').gsub(',', '.')" - elsif key == "p_contact_name" - contact_1.name = value - elsif key == "p_contact_comment" - contact_1.p_contact_types << PContactType.find_or_create_by(name: value) - elsif key == "p_contact_tel" - contact_1.tel = value - elsif key == "p_contact_skype" - contact_1.skype = value - elsif key == "p_contact_email_1" - contact_1.email = value - elsif key == "p_contact_email_2" - contact_2 = PContact.new(email: value) - elsif key == "p_contact_email_3" - contact_3 = PContact.new(email: value) - elsif key == "p_payment_type" - n.p_payment_type_id = PPaymentType.find_or_create_by(name: value).id else - eval "n.#{key} = value" + case key + when "nom_fournisseur" + n.name = value + when "address" + n.address1 = value + when "ville" + n.city = value + when "pays" + n.country = value + when "tva_intracom" + n.tva_num = value + when "delai_paiement" + next if value.nil? + case value + when "A la commande" + n.payment_delais = 0 + when "A réception" + n.payment_delais = 0 + when "7 jours net" + n.payment_delais = 7 + when "21 jours net" + n.payment_delais = 21 + when "30 jours" + n.payment_delais = 30 + when "30 jours net" + n.payment_delais = 30 + when "30 jours fin de mois" + n.payment_delais = 30 + when "35 jours net" + n.payment_delais = 35 + when "40 jours net" + n.payment_delais = 40 + when "60 jours net" + n.payment_delais = 60 + when "60 jours fin de mois" + n.payment_delais = 60 + else + n.payment_delais = value + end + when "interlocuteur" + contact_1.name = value + when "fonction" + contact_1.p_contact_types << PContactType.find_or_create_by(name: value) + when "tel" + contact_1.tel = value + when "skype" + contact_1.skype = value + when "email_1" + contact_1.email = value + when "email_2" + contact_2 = PContact.new(email: value) + when "email_3" + contact_3 = PContact.new(email: value) + when "reglement_par" + n.p_payment_type_id = PPaymentType.find_or_create_by(name: value).id + else + eval "n.#{key} = value" + end end end # particular.organisation = self.name n.save - n.p_contacts << contact_1 if (contact_1.name || contact_1.tel || contact_1.skype || contact_1.email) - n.p_contacts << contact_2 if contact_2 - n.p_contacts << contact_3 if contact_3 + if (contact_1.name || contact_1.tel || contact_1.skype || contact_1.email) + n.p_contacts << contact_1 + import_csv.import_csv_elements << ImportCsvElement.new(:element => contact_1) + end + if contact_2 + n.p_contacts << contact_2 + import_csv.import_csv_elements << ImportCsvElement.new(:element => contact_2) + end + + if contact_3 + n.p_contacts << contact_3 + import_csv.import_csv_elements << ImportCsvElement.new(:element => contact_3) + end + import_csv.import_csv_elements << ImportCsvElement.new(:element => n) + end end end From 719f0007b72375acbc5bbac9b8bbbdacc26473ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Wed, 13 Oct 2021 18:14:15 +0200 Subject: [PATCH 103/131] can be deleted by csv_element destroy --- app/models/p_customer_rib.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/p_customer_rib.rb b/app/models/p_customer_rib.rb index 856d1d3..2b4a176 100644 --- a/app/models/p_customer_rib.rb +++ b/app/models/p_customer_rib.rb @@ -1,7 +1,7 @@ class PCustomerRib < ActiveRecord::Base belongs_to :p_customer - has_many :p_documents, :dependent => :nullify + # has_many :p_documents, :dependent => :nullify def generate_rum if self.sign_date From cbb5d65098e639dd356155844c53d2169829e54a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Wed, 13 Oct 2021 18:14:41 +0200 Subject: [PATCH 104/131] add import p_customer --- app/views/admin/import_csvs/_form.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/import_csvs/_form.html.haml b/app/views/admin/import_csvs/_form.html.haml index ede671b..499e7be 100644 --- a/app/views/admin/import_csvs/_form.html.haml +++ b/app/views/admin/import_csvs/_form.html.haml @@ -6,7 +6,7 @@ = f.input :name, :label => "Nom de l'import :" = f.input :file, :label => "file :" - = f.input :table_name, :label => "Type d'import :" , :as => :select, :collection => [["Base fournisseurs", "p_fournisseur"], ["Mise à jour catalogue prix","price_document"]] + = f.input :table_name, :label => "Type d'import :" , :as => :select, :collection => [["Base fournisseurs", "p_fournisseur"], ["Mise à jour catalogue prix","price_document"], ["Base client", "p_customer"]] -if f.object.id %table.import_csv_champs_form From 8cefeec6b3cf11167ff6c4d23493cd920743ea18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Wed, 13 Oct 2021 18:14:54 +0200 Subject: [PATCH 105/131] import p_customer --- app/models/p_bank.rb | 1 + app/models/p_customer.rb | 423 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 424 insertions(+) diff --git a/app/models/p_bank.rb b/app/models/p_bank.rb index cbd7d79..097616d 100644 --- a/app/models/p_bank.rb +++ b/app/models/p_bank.rb @@ -1,2 +1,3 @@ class PBank < ApplicationRecord + has_many :particulars, :as => :owner, :dependent => :destroy end diff --git a/app/models/p_customer.rb b/app/models/p_customer.rb index e1ee85d..282b46f 100644 --- a/app/models/p_customer.rb +++ b/app/models/p_customer.rb @@ -256,6 +256,7 @@ class PCustomer < ApplicationRecord end def solde_avoir_and_bills(date = Date.today) + raise # p_document_id à remplacer self.p_documents.where(:p_document_type_id => [4,7]).where("created_at < ?", date.to_time.end_of_day).sum(:cache_total_ttc) end @@ -480,5 +481,427 @@ class PCustomer < ApplicationRecord end while PCustomer.exists?(column => self[column]) end + acts_as_csv_import :fields => [ + :code, + :societe_raison_sociale, + :nom_enseigne, + :adresse_facturation_1, + :adresse_livraison_2, + :adresse_3, + :cp, + :cp2, + :ville_1, + :ville_2, + :pays, + :societe_livraison, + :forme_juridique, + :famille_client, + :facturer_ttc, + :mode_reglement, + :libelle_mode_reglement, + :telephone_1, + :telephone_2, + :fax, + :risque, + :bloque, + :credit_accorde, + :mode_tva, + :nii, + :nom_banque, + :adresse_banque_1, + :adresse_banque_2, + :adresse_banque_3, + :code_banque, + :ville_banque, + :pays_banque, + :code_banque, + :code_guichet, + :numero_compte, + :cle_rib, + :compte_comptable, + :analytique, + :taux_remise, + :observation, + :export_compta, + :releve_compte, + :email, + :url, + :siret, + :representant, + :nom_representant, + :encour_initial, + :credit_disponible, + :code_tarif, + :telephone_livraison, + :portable_livraison, + :fax_livraison, + :encours_courant, + :encours, + :client_divers, + :contacts_client, + :date_creation, + :code_iban, + :code_bic, + :nom_contact, + :societe_contact, + :titre_contact, + :fonction_contact, + :telephone_contact, + :portable_contact, + :email_contact + ] + def self.custom_csv_import(list, import_csv) + #OK Code AUTO :code OK :code + #OK Société - Raison Sociale :particular.organisation OK :societe_raison_sociale + #OK Nom enseigne :particular.com_name OK :nom_enseigne + #OK Adresse facturation 1 :particular.address_1 OK :adresse_facturation_1 + #OK Adresse Livraison 2 :particular.address_2 OK :adresse_livraison_2 + #OK Adresse 3 :particular.address_3 OK :adresse_3 + #OK Code Postal 1 :particular.cp OK :cp + #OK Code Postal 2 VIDE OK :cp2 + #OK Ville 1 :particular_city OK :ville_1 + #OK Ville 2 VIDE OK :ville_2 + #OK Pays :particular.country OK :pays + #OK Société Livraison :particular.address_4 OK :societe_livraison + #OK Forme juridique livraison :particular.address_5 OK :forme_juridique + #OK Famille Client VIDE OK :famille_client + #OK Facturer en TTC VIDE OK :facturer_ttc + #OK Mode Règlement :p_payment_type OK :mode_reglement + #OK Libellé Mode Règlement :payment_delais OK :libelle_mode_reglement + #OK Téléphone 1 :particular.tel OK :telephone_1 + #OK Téléphone 2 :particular.tel2 OK :telephone_2 + #OK Fax :particular.fax OK :fax + #OK Risque VIDE OK :risque + #OK Bloqué VIDE OK :bloque + #OK Crédit accordé VIDE OK :credit_accorde + #OK Mode TVA VIDE OK :mode_tva + #OK N.I.I. VIDE OK :nii + #OK Nom Banque :p_bank.name OK :nom_banque + #OK Adresse 1 Banque :p_bank.particular.address_1 OK :adresse_banque_1 + #OK Adresse 2 Banque :p_bank.particular.address_2 OK :adresse_banque_2 + #OK Adresse 3 Banque VIDE OK :adresse_banque_3 + #OK Code Postal Banque :p_bank.particular.cp OK :code_banque + #OK Ville Banque :p_bank.particular.ville OK :ville_banque + #OK Pays Banque :p_bank.particular.pays OK :pays_banque + #OK Code Banque INUTILE OK :code_banque + #OK Code Guichet INUTILE OK :code_guichet + #OK Numéro Compte INUTILE OK :numero_compte + #OK Clé RIB INUTILE OK :cle_rib + # Compte Comptable ??? ?? :compte_comptable + #OK Analytique VIDE OK :analytique + #OK Taux Remise VIDE OK :taux_remise + #OK Observations AUTO :p_customer_sheet_note OK :observation + #OK Export Compta VIDE OK :export_compta + # Relevé Compte Bboolean à ajouter dans la base ?? :releve_compte + #OK E-mail AUTO :email OK :email + #OK URL VIDE OK :url + #OK SIRET AUTO :siret OK :siret + #OK Représentant :p_commercial_code OK :representant + #OK Nom Représentant :p_commercial_firstname OK :nom_representant + # Encours initial ??? ?? :encour_initial + # Crédit Disponible ??? ?? :credit_disponible + #OK Code Tarif VIDE OK :code_tarif + #OK Téléphone Livraison :particular.send_tel OK :telephone_livraison + #OK Portable Livraison :particular.send_tel2 OK :portable_livraison + #OK Fax Livraison :particular.send_fax OK :fax_livraison + # Encours courant ??? ?? :encours_courant + # encours_courant ??? ?? :encours + # Client divers ??? ?? :client_divers + #OK Contacts client INUTILE OK :contacts_client + #OK Date de création INUTILE OK :date_creation + #OK Code IBAN :p_customer_ribs.iban OK :code_iban + #OK Code BIC :p_customer_ribs.bic OK :code_bic + #OK Nom du contact :p_contact_name OK :nom_contact + #OK Société du contact VIDE OK :societe_contact + #OK Titre du contact :p_contact.civilite OK :titre_contact + #OK Fonction du contact :p_contact.comment OK :fonction_contact + #OK Téléphone du contact :p_contact.tel OK :telephone_contact + #OK Portable du contact :p_contact.tel2 OK :portable_contact + #OK E-mail du contact :p_contact.email OK :email_contact + + + + # ap "*********************************************************************************************************" + # ap "*********************************************************************************************************" + # ap "*********************************************************************************************************" + # ap list + # ap list.class + # ap "*********************************************************************************************************" + # ap "*********************************************************************************************************" + # ap "*********************************************************************************************************" + # ap import_csv + # ap "*********************************************************************************************************" + # ap "*********************************************************************************************************" + # ap "*********************************************************************************************************" + + list.each do |row| + + n = self.new(imported: true, p_customer_cat: PCustomerCat.find_by_name("Professionnel")) + # particular = Particular.new(pro: true) + particular_bill = Particular.new + bank = bic = iban = p_commercial = particular_send = send_tel = send_tel2 = send_fax = send_address_2 = p_commercial_code = p_commercial_firstname = contact_2 = nil + + + bank_particular = Particular.new + contact = PContact.new + + row.each do |key, value| + + if self.type_for_attribute(key) and self.type_for_attribute(key).type == :decimal + eval "n.#{key} = value.to_s.gsub(' ', '').gsub(',', '.')" + else + case key + when "societe_raison_sociale" + particular_bill.organisation = value + + when "nom_enseigne" + particular_bill.com_name = value + + when "adresse_facturation_1" + particular_bill.address_1 = value + + when "adresse_livraison_2" + send_address_2 = value + + when "adresse_3" + particular_bill.address_3 = value + + when "cp" + particular_bill.cp = value + + when "ville_1" + particular_bill.city = value + + when "pays" + particular_bill.country = value + + when "societe_livraison" + particular_bill.address_4 = value + + when "forme_juridique" + particular_bill.address_5 = value + + when "telephone_1" + particular_bill.tel = value + + when "telephone_2" + particular_bill.tel2 = value + + when "fax" + particular_bill.fax = value + + when "mode_reglement" + next if value.nil? + if value == "VIR" || "VIR COM" || "VIR 60 J NET" || "VIR 30 J NET" + n.p_payment_type_id = PPaymentType.find_or_create_by(name: "Virement").id + elsif value == "TRAITE" + n.p_payment_type_id = PPaymentType.find_or_create_by(name: "Traite").id + else + n.p_payment_type_id = PPaymentType.find_or_create_by(name: value).id + end + + when "libelle_mode_reglement" + case value + when "Virement à la commande" + n.payment_delais = 0 + when "Chèque à la commande" + n.payment_delais = 0 + when "Chèque à réception" + n.payment_delais = 0 + when "30 JOURS FIN DE MOIS" + n.payment_delais = 30 + when "VIR 60J NET DATE RELEVE" + n.payment_delais = 60 + when "TRAITE A 60 JOURS FIN DE MOIS" + n.payment_delais = 60 + when "Mensuel - 30j fin de mois du dépôt" + n.payment_delais = 30 + else + n.payment_delais = value + end + + when "nom_banque" + next if value.nil? + bank = PBank.find_or_create_by(name: value) + + when "adresse_banque_1" + bank_particular.address_1 = value + + when "adresse_banque_2" + bank_particular.address_2 = value + + when "code_banque" + bank_particular.cp = value + + when "ville_banque" + bank_particular.city = value + + when "pays_banque" + bank_particular.country = value + + when "telephone_livraison" + send_tel = value + + when "portable_livraison" + send_tel2 = value + + when "fax_livraison" + send_fax = value + + when "representant" + p_commercial_code = value + when "nom_representant" + p_commercial_firstname = value + + when "code_iban" + iban = value + when "code_bic" + bic = value + + when "nom_contact" + contact.name = value + + when "titre_contact" + particular_bill.civilite = value + + when "fonction_contact" + next if value.nil? + contact.p_contact_types << PContactType.find_or_create_by(name: value) + + when "telephone_contact" + contact.tel = value + + when "portable_contact" + next if value.nil? + if contact.tel.nil? + contact.tel = value + else + contact_2 = PContact.new(tel: value) + end + + when "email_contact" + contact.email = value + + when "observation" + n.p_customer_sheet_note = value + + + + + + + # champs vides ou inutiles : + when "cp2" + when "ville_2" + when "famille_client" + when "facturer_ttc" + when "risque" + when "bloque" + when "credit_accorde" + when "mode_tva" + when "nii" + when "adresse_banque_3" + when "code_banque" + when "code_guichet" + when "numero_compte" + when "cle_rib" + when "analytique" + when "taux_remise" + when "export_compta" + when "url" + when "code_tarif" + when "contacts_client" + when "date_creation" + when "societe_contact" + + # Champs ??? + when "compte_comptable" + when "encour_initial" + when "credit_disponible" + when "releve_compte" + when "encours_courant" + when "releve_compte" + when "encours" + when "client_divers" + + else + eval "n.#{key} = value" + end + + + + + end + end + + n.particulars << particular_bill + + n.save + + if bank + bank.bic = bic + bank.particulars << bank_particular if bank_particular.address_1 + bank.save + import_csv.import_csv_elements << ImportCsvElement.new(:element => bank) + + end + + if bic || iban + rib = PCustomerRib.create(bic: bic, iban: iban) + rib.bank = bank.name if bank + account = PBankAccount.create(bic: bic, iban: iban, p_bank: bank, p_customer: n) + n.p_customer_ribs << rib + import_csv.import_csv_elements << ImportCsvElement.new(:element => rib) + import_csv.import_csv_elements << ImportCsvElement.new(:element => account) + end + + if p_commercial_code || p_commercial_firstname + p_commercial = PCommercial.find_or_create_by(code: p_commercial_code, firstname: p_commercial_firstname) + n.p_commercial = p_commercial + end + + if send_tel || send_tel2 || send_fax || send_address_2 + particular_send = Particular.new + particular_send.tel = send_tel if send_tel + particular_send.tel2 = send_tel2 if send_tel2 + particular_send.fax = send_fax if send_fax + + n.particulars << particular_send + n.particular_send_id = particular_send.id + end + + n.p_contacts << contact if (contact.name || contact.tel || contact.email) + n.p_contacts << contact_2 if contact_2 + + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap n + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ contact §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap contact + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n.contacts §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap n.p_contacts + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n.particulars §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap n.particulars + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n.p_customer_ribs §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap n.p_customer_ribs + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n.p_commercial §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap n.p_commercial + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + + import_csv.import_csv_elements << ImportCsvElement.new(:element => n) + end + end end From b57ed75754b77b259eff749ecbac7195e8af59b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Wed, 13 Oct 2021 18:23:10 +0200 Subject: [PATCH 106/131] add price_line to csv_element --- app/models/price_document.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/price_document.rb b/app/models/price_document.rb index 5161238..1e5a9b1 100644 --- a/app/models/price_document.rb +++ b/app/models/price_document.rb @@ -755,6 +755,7 @@ class PriceDocument < ApplicationRecord n.save import_csv.import_csv_elements << ImportCsvElement.new(:element => n) + import_csv.import_csv_elements << ImportCsvElement.new(:element => price_line) end end From 2abba273a97dc700a7c26342f9e5c0365e9a510c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 14 Oct 2021 09:08:25 +0200 Subject: [PATCH 107/131] remove next in custom_import --- app/models/p_customer.rb | 37 ++++++++++++++------------ app/models/p_fournisseur.rb | 53 +++++++++++++++++++------------------ 2 files changed, 47 insertions(+), 43 deletions(-) diff --git a/app/models/p_customer.rb b/app/models/p_customer.rb index 282b46f..b2ee2c1 100644 --- a/app/models/p_customer.rb +++ b/app/models/p_customer.rb @@ -692,13 +692,14 @@ class PCustomer < ApplicationRecord particular_bill.fax = value when "mode_reglement" - next if value.nil? - if value == "VIR" || "VIR COM" || "VIR 60 J NET" || "VIR 30 J NET" - n.p_payment_type_id = PPaymentType.find_or_create_by(name: "Virement").id - elsif value == "TRAITE" - n.p_payment_type_id = PPaymentType.find_or_create_by(name: "Traite").id - else - n.p_payment_type_id = PPaymentType.find_or_create_by(name: value).id + if value.present? + if value == "VIR" || "VIR COM" || "VIR 60 J NET" || "VIR 30 J NET" + n.p_payment_type_id = PPaymentType.find_or_create_by(name: "Virement").id + elsif value == "TRAITE" + n.p_payment_type_id = PPaymentType.find_or_create_by(name: "Traite").id + else + n.p_payment_type_id = PPaymentType.find_or_create_by(name: value).id + end end when "libelle_mode_reglement" @@ -722,8 +723,9 @@ class PCustomer < ApplicationRecord end when "nom_banque" - next if value.nil? - bank = PBank.find_or_create_by(name: value) + if value.present? + bank = PBank.find_or_create_by(name: value) + end when "adresse_banque_1" bank_particular.address_1 = value @@ -766,18 +768,19 @@ class PCustomer < ApplicationRecord particular_bill.civilite = value when "fonction_contact" - next if value.nil? - contact.p_contact_types << PContactType.find_or_create_by(name: value) - + if value.present? + contact.p_contact_types << PContactType.find_or_create_by(name: value) + end when "telephone_contact" contact.tel = value when "portable_contact" - next if value.nil? - if contact.tel.nil? - contact.tel = value - else - contact_2 = PContact.new(tel: value) + if value.present? + if contact.tel.nil? + contact.tel = value + else + contact_2 = PContact.new(tel: value) + end end when "email_contact" diff --git a/app/models/p_fournisseur.rb b/app/models/p_fournisseur.rb index 44a7f77..f65ac86 100644 --- a/app/models/p_fournisseur.rb +++ b/app/models/p_fournisseur.rb @@ -63,32 +63,33 @@ class PFournisseur < ApplicationRecord when "tva_intracom" n.tva_num = value when "delai_paiement" - next if value.nil? - case value - when "A la commande" - n.payment_delais = 0 - when "A réception" - n.payment_delais = 0 - when "7 jours net" - n.payment_delais = 7 - when "21 jours net" - n.payment_delais = 21 - when "30 jours" - n.payment_delais = 30 - when "30 jours net" - n.payment_delais = 30 - when "30 jours fin de mois" - n.payment_delais = 30 - when "35 jours net" - n.payment_delais = 35 - when "40 jours net" - n.payment_delais = 40 - when "60 jours net" - n.payment_delais = 60 - when "60 jours fin de mois" - n.payment_delais = 60 - else - n.payment_delais = value + if value.present? + case value + when "A la commande" + n.payment_delais = 0 + when "A réception" + n.payment_delais = 0 + when "7 jours net" + n.payment_delais = 7 + when "21 jours net" + n.payment_delais = 21 + when "30 jours" + n.payment_delais = 30 + when "30 jours net" + n.payment_delais = 30 + when "30 jours fin de mois" + n.payment_delais = 30 + when "35 jours net" + n.payment_delais = 35 + when "40 jours net" + n.payment_delais = 40 + when "60 jours net" + n.payment_delais = 60 + when "60 jours fin de mois" + n.payment_delais = 60 + else + n.payment_delais = value + end end when "interlocuteur" contact_1.name = value From c3cc3b63cab30547502a6866ef5e79dd0b130223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 14 Oct 2021 09:48:11 +0200 Subject: [PATCH 108/131] add p_customer import menu --- app/views/admin/import_csvs/_form.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/import_csvs/_form.html.haml b/app/views/admin/import_csvs/_form.html.haml index 499e7be..71bbec7 100644 --- a/app/views/admin/import_csvs/_form.html.haml +++ b/app/views/admin/import_csvs/_form.html.haml @@ -6,7 +6,7 @@ = f.input :name, :label => "Nom de l'import :" = f.input :file, :label => "file :" - = f.input :table_name, :label => "Type d'import :" , :as => :select, :collection => [["Base fournisseurs", "p_fournisseur"], ["Mise à jour catalogue prix","price_document"], ["Base client", "p_customer"]] + = f.input :table_name, :label => "Type d'import :" , :as => :select, :collection => [["Mise à jour catalogue prix","price_document"], ["Base fournisseurs", "p_fournisseur"], ["Base client", "p_customer"], ["Base produit", "p_product"]] -if f.object.id %table.import_csv_champs_form From e313408aefbe55e9546fa6731905f902be736127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 14 Oct 2021 09:48:42 +0200 Subject: [PATCH 109/131] WIP import csv p_product --- app/models/p_product.rb | 181 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) diff --git a/app/models/p_product.rb b/app/models/p_product.rb index 4e501c0..793b3c0 100644 --- a/app/models/p_product.rb +++ b/app/models/p_product.rb @@ -166,4 +166,185 @@ class PProduct < ApplicationRecord self.p_product_images.order(:position).first end + acts_as_csv_import :fields => [ + :gencode, + :id, + :marque, + :famille, + :reference, + :modele, + :couleur, + :color, + :connectivite, + :sim, + :taille, + :capacite, + :infos_supp, + :reference_fabricant, + :etat, + :code_hs, + :indice_reparabilite, + :duree_dispo_pces_detachees, + :das_tête, + :das_corps, + :das_membre, + :poids, + :nb_pcs_colis, + :code_om, + :dtl, + :gbh_code_971, + :gbh_code_972, + :gbh_code_973, + :code_art, + :sorecop, + :pmp_hors_sorecop, + :target_hors_sorecop, + :frs, + :date, + :spec, + :dtl_targ, + :commentaires, + :com + ] + + def self.custom_csv_import(list, import_csv) + # ap "*********************************************************************************************************" + # ap "*********************************************************************************************************" + ap "*********************************************************************************************************" + ap list.size + # ap list.class + # ap "*********************************************************************************************************" + # ap "*********************************************************************************************************" + # ap "*********************************************************************************************************" + # ap import_csv + # ap "*********************************************************************************************************" + # ap "*********************************************************************************************************" + # ap "*********************************************************************************************************" + + list.each do |row| + next if row["marque"].blank? + + n = self.new(imported: true) + + row.each do |key, value| + if self.type_for_attribute(key) and self.type_for_attribute(key).type == :decimal + eval "n.#{key} = value.to_s.gsub(' ', '').gsub(',', '.')" + else + case key + when "gencode" + + when "id" + + when "marque" + + when "famille" + n.p_product_cat = PProductCat.find_or_create_by(name: value) + + when "reference" + + when "modele" + + when "couleur" + + when "color" + + when "connectivite" + + when "sim" + + when "taille" + + when "capacite" + + when "infos_supp" + + when "reference_fabricant" + + when "etat" + + when "code_hs" + + when "indice_reparabilite" + + when "duree_dispo_pces_detachees" + + when "das_tête" + + when "das_corps" + + when "das_membre" + + when "poids" + + when "nb_pcs_colis" + + when "code_om" + + when "dtl" + + when "gbh_code_971" + + when "gbh_code_972" + + when "gbh_code_973" + + when "code_art" + + when "sorecop" + + when "pmp_hors_sorecop" + + when "target_hors_sorecop" + + when "frs" + + when "date" + + when "spec" + + when "dtl_targ" + + when "commentaires" + + when "com" + + else + # eval "n.#{key} = value" + end + end + end + + # n.save + + + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap n + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ contact §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap contact + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n.contacts §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap n.p_contacts + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n.particulars §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap n.particulars + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n.p_customer_ribs §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap n.p_customer_ribs + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n.p_commercial §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap n.p_commercial + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + + # import_csv.import_csv_elements << ImportCsvElement.new(:element => n) + end + end end From c6912295556d85eb0ae29186b9dbd65d9fe8d77c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 14 Oct 2021 11:47:03 +0200 Subject: [PATCH 110/131] pluck existing unit in form --- app/models/p_spec_value.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/p_spec_value.rb b/app/models/p_spec_value.rb index 8471de5..c9aade6 100644 --- a/app/models/p_spec_value.rb +++ b/app/models/p_spec_value.rb @@ -1,7 +1,7 @@ class PSpecValue < ApplicationRecord has_many :p_product_ref_specs - UNITS = ["Go", "Mo"] + UNITS = self.distinct.pluck(:unit) def member_label "#{value} #{unit}" From cdb200f4a443a0d0c509c23bb39940a3abcabec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 14 Oct 2021 18:32:16 +0200 Subject: [PATCH 111/131] add details to import --- ...211014081433_add_genecode_to_p_products.rb | 5 +++++ ...4444_add_import_field_to_p_product_refs.rb | 22 +++++++++++++++++++ db/schema.rb | 21 +++++++++++++++++- 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20211014081433_add_genecode_to_p_products.rb create mode 100644 db/migrate/20211014134444_add_import_field_to_p_product_refs.rb diff --git a/db/migrate/20211014081433_add_genecode_to_p_products.rb b/db/migrate/20211014081433_add_genecode_to_p_products.rb new file mode 100644 index 0000000..d4acf40 --- /dev/null +++ b/db/migrate/20211014081433_add_genecode_to_p_products.rb @@ -0,0 +1,5 @@ +class AddGenecodeToPProducts < ActiveRecord::Migration[6.0] + def change + add_column :p_products, :genecode, :string + end +end diff --git a/db/migrate/20211014134444_add_import_field_to_p_product_refs.rb b/db/migrate/20211014134444_add_import_field_to_p_product_refs.rb new file mode 100644 index 0000000..d747875 --- /dev/null +++ b/db/migrate/20211014134444_add_import_field_to_p_product_refs.rb @@ -0,0 +1,22 @@ +class AddImportFieldToPProductRefs < ActiveRecord::Migration[6.0] + def change + add_column :p_product_refs, :manufacturer_ref, :string + add_column :p_product_refs, :used_state, :string + add_column :p_product_refs, :i_code_hs, :string + add_column :p_product_refs, :prepair_score, :decimal, precision: 10, scale: 2 + add_column :p_product_refs, :part_delay, :string + add_column :p_product_refs, :das_head, :string + add_column :p_product_refs, :das_body, :string + add_column :p_product_refs, :das_membre, :string + add_column :p_product_refs, :nb_pcs_colis, :integer + add_column :p_product_refs, :code_om, :string + add_column :p_product_refs, :gbh_code_971, :string + add_column :p_product_refs, :gbh_code_972, :string + add_column :p_product_refs, :gbh_code_973, :string + add_column :p_product_refs, :code_art, :string + add_column :p_product_refs, :i_comment, :string + add_column :p_product_refs, :i_pmp_hors_sorecop, :string + add_column :p_product_refs, :i_target_hors_sorecop, :string + add_column :p_product_refs, :p_fournisseur_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 5c1a20a..c4ad708 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_10_05_134955) do +ActiveRecord::Schema.define(version: 2021_10_14_134444) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -1818,6 +1818,24 @@ ActiveRecord::Schema.define(version: 2021_10_05_134955) do t.decimal "ct_deee", precision: 10, scale: 2 t.string "ean" t.string "sorecop_comment" + t.string "manufacturer_ref" + t.string "used_state" + t.string "i_code_hs" + t.decimal "prepair_score", precision: 10, scale: 2 + t.string "part_delay" + t.string "das_head" + t.string "das_body" + t.string "das_membre" + t.integer "nb_pcs_colis" + t.string "code_om" + t.string "gbh_code_971" + t.string "gbh_code_972" + t.string "gbh_code_973" + t.string "code_art" + t.string "i_comment" + t.string "i_pmp_hors_sorecop" + t.string "i_target_hors_sorecop" + t.integer "p_fournisseur_id" end create_table "p_product_specs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| @@ -1908,6 +1926,7 @@ ActiveRecord::Schema.define(version: 2021_10_05_134955) do t.boolean "conserve_proportion", default: false t.boolean "frontpage", default: true t.integer "sorecop_cat_id" + t.string "genecode" t.index ["p_product_cat_id"], name: "index_p_products_on_p_product_cat_id" t.index ["s_brand_id"], name: "index_p_products_on_s_brand_id" end From e911fa598c6284db952b77fed2ae401657161b28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 14 Oct 2021 18:32:53 +0200 Subject: [PATCH 112/131] Update Type constant --- app/models/p_spec_type.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/p_spec_type.rb b/app/models/p_spec_type.rb index 42875d3..ec3b632 100644 --- a/app/models/p_spec_type.rb +++ b/app/models/p_spec_type.rb @@ -1,6 +1,7 @@ class PSpecType < ApplicationRecord has_many :p_product_ref_specs - TYPES = ["Ram", "Stockage"] + + TYPES = self.distinct.pluck(:name) acts_as_sorting :fields => { :id => {:name => "ID"}, From 6ce208d553216b1c429164df2fca8ef420f3ebe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 14 Oct 2021 18:33:10 +0200 Subject: [PATCH 113/131] bugfix --- app/models/p_product_ref.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb index fce57e9..5f8a453 100644 --- a/app/models/p_product_ref.rb +++ b/app/models/p_product_ref.rb @@ -165,7 +165,7 @@ class PProductRef < ApplicationRecord end def member_label - "#{self.ref} | #{self.p_product.name} - #{self.ct_sub_name} - #{self.p_product_color.name if self.p_product_color} | #{self.cat_name}" + "#{self.ref} | #{self.p_product.name} - #{self.ct_sub_name} - #{self.p_product_color.name if self.p_product_color} | #{self.ca_name}" end def ca_sorecop From 2de306d5e6bc014b5accf4b7a6504bd96cf2e228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 14 Oct 2021 18:33:20 +0200 Subject: [PATCH 114/131] WIP Import --- app/models/p_product.rb | 144 ++++++++++++++++++++++++++++------------ 1 file changed, 100 insertions(+), 44 deletions(-) diff --git a/app/models/p_product.rb b/app/models/p_product.rb index 19088a9..4f8c65e 100644 --- a/app/models/p_product.rb +++ b/app/models/p_product.rb @@ -167,6 +167,7 @@ class PProduct < ApplicationRecord end acts_as_csv_import :fields => [ + :identifiant, :gencode, :id, :marque, @@ -185,7 +186,7 @@ class PProduct < ApplicationRecord :code_hs, :indice_reparabilite, :duree_dispo_pces_detachees, - :das_tête, + :das_tete, :das_corps, :das_membre, :poids, @@ -211,7 +212,7 @@ class PProduct < ApplicationRecord # ap "*********************************************************************************************************" # ap "*********************************************************************************************************" ap "*********************************************************************************************************" - ap list.size + # ap list.size # ap list.class # ap "*********************************************************************************************************" # ap "*********************************************************************************************************" @@ -220,96 +221,151 @@ class PProduct < ApplicationRecord # ap "*********************************************************************************************************" # ap "*********************************************************************************************************" # ap "*********************************************************************************************************" + soreco_cat_hash = { + "Smartphone" => "Smartphones & Téléphones mobiles", + "Tablette" => "Tablettes média et tablette PC", + "MP4" => "Baladeur MP4" + } list.each do |row| next if row["marque"].blank? n = self.new(imported: true) + ref = PProductRef.find_or_initialize_by(p_product: n, description: row["identifiant"]) row.each do |key, value| if self.type_for_attribute(key) and self.type_for_attribute(key).type == :decimal eval "n.#{key} = value.to_s.gsub(' ', '').gsub(',', '.')" else case key + when "identifiant" + ref.description = value when "gencode" - + n.genecode = value when "id" when "marque" + n.s_brand = SBrand.find_or_create_by(name: value) when "famille" n.p_product_cat = PProductCat.find_or_create_by(name: value) when "reference" + n.name = value when "modele" + ref.ct_sub_name = value if value.present? when "couleur" + ref.p_product_color = PProductColor.find_or_create_by(name: value) when "color" - + if ref.p_product_color.nil? + ref.p_product_color = PProductColor.find_or_create_by(color: value) + end when "connectivite" + arr = [] + cellular = [ "5G", "3G", "3G+", "4G", "4G+", "2G", "wifi", "BT"] + video = ["4K","HD" ] + power = ["5W", "12W", "18W", "20W", "96W", "40W", "10W", "40W"] + mix = ["<87W/4K", "5G/4K", "wifi/BT" ] + geoloc = [ "GPS" ] + + if mix.include?(value) + arr = value.split('/') + else + arr << value + end + + arr.each do |value| + spec = nil + if cellular.include?(value) + spec = PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Connectivité"), p_spec_value: PSpecValue.find_or_create_by(value: value)) + elsif video.include?(value) + spec = PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Résolution"), p_spec_value: PSpecValue.find_or_create_by(value: value)) + elsif power.include?(value) + PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Puissance éléctrique"), p_spec_value: PSpecValue.find_or_create_by(value: value.gsub('W', ''), unit: "W")) + elsif geoloc.include?(value) + spec = PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Géolocalisation"), p_spec_value: PSpecValue.find_or_create_by(value: value)) + else + spec = PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Autre"), p_spec_value: PSpecValue.find_or_create_by(value: value)) + end + import_csv.import_csv_elements << ImportCsvElement.new(:element => spec) + end when "sim" + if ["DS", "SS"].include?(value) + PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Sim"), p_spec_value: PSpecValue.find_or_create_by(value: value)) + elsif value == "4G" + PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Connectivité"), p_spec_value: PSpecValue.find_or_create_by(value: value)) + end when "taille" + PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Taille"), p_spec_value: PSpecValue.find_or_create_by(value: value.to_s)) when "capacite" - + unit = value.match(/\D+/) + num = value.match(/\d+/) + spec = PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Stockage"), p_spec_value: PSpecValue.find_or_create_by(value: num.to_s, unit: unit.to_s)) + import_csv.import_csv_elements << ImportCsvElement.new(:element => spec) when "infos_supp" - + spec = PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Autre"), p_spec_value: PSpecValue.find_or_create_by(value: value)) + import_csv.import_csv_elements << ImportCsvElement.new(:element => spec) when "reference_fabricant" - + ref.manufacturer_ref = value when "etat" - + ref.used_state = value when "code_hs" - + ref.i_code_hs = value when "indice_reparabilite" - + ref.prepair_score = value when "duree_dispo_pces_detachees" - - when "das_tête" - + ref.part_delay = value + when "das_tete" + ref.das_head = value when "das_corps" - + ref.das_body = value when "das_membre" - + ref.das_membre = value when "poids" - + ref.weight = value when "nb_pcs_colis" - + ref.nb_pcs_colis = value when "code_om" - - when "dtl" - + ref.code_om = value when "gbh_code_971" - + ref.gbh_code_971 = value when "gbh_code_972" - + ref.gbh_code_972 = value when "gbh_code_973" - + ref.gbh_code_973 = value when "code_art" - + ref.code_art = value when "sorecop" - + ref.p_product.sorecop_cat = SorecopCat.find_by(name: soreco_cat_hash[row["famille"]]) + if ref.sorecop.kind_of?(String) + ref.ct_sorecop = value + end when "pmp_hors_sorecop" - + ref.i_pmp_hors_sorecop = value when "target_hors_sorecop" - + ref.i_target_hors_sorecop = value when "frs" - - when "date" - + ref.fournisseur_id = PFournisseur.find_or_create_by(name: value) when "spec" - - when "dtl_targ" - + spec = PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Version ROM"), p_spec_value: PSpecValue.find_or_create_by(value: value)) + import_csv.import_csv_elements << ImportCsvElement.new(:element => spec) when "commentaires" - + ref.i_comment = value + # champs ignorés + when "date" + # colonne vide + when "dtl_targ" + when "dtl" when "com" else - # eval "n.#{key} = value" + eval "n.#{key} = value" end end end @@ -317,14 +373,14 @@ class PProduct < ApplicationRecord # n.save - # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" - # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" - # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" - # ap n - # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" - # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" - # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ contact §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" - # ap contact + ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + ap n + ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n.ref §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + ap n.ref # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n.contacts §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" @@ -344,7 +400,7 @@ class PProduct < ApplicationRecord # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" - # import_csv.import_csv_elements << ImportCsvElement.new(:element => n) + import_csv.import_csv_elements << ImportCsvElement.new(:element => n) end end end From 8965db5a59ffe672f16aaf624a702f4d82e46da1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 15 Oct 2021 18:21:20 +0200 Subject: [PATCH 115/131] genecode to p_product_ref --- db/migrate/20211014081433_add_genecode_to_p_products.rb | 5 ----- .../20211014134444_add_import_field_to_p_product_refs.rb | 1 + db/schema.rb | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) delete mode 100644 db/migrate/20211014081433_add_genecode_to_p_products.rb diff --git a/db/migrate/20211014081433_add_genecode_to_p_products.rb b/db/migrate/20211014081433_add_genecode_to_p_products.rb deleted file mode 100644 index d4acf40..0000000 --- a/db/migrate/20211014081433_add_genecode_to_p_products.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddGenecodeToPProducts < ActiveRecord::Migration[6.0] - def change - add_column :p_products, :genecode, :string - end -end diff --git a/db/migrate/20211014134444_add_import_field_to_p_product_refs.rb b/db/migrate/20211014134444_add_import_field_to_p_product_refs.rb index d747875..439853f 100644 --- a/db/migrate/20211014134444_add_import_field_to_p_product_refs.rb +++ b/db/migrate/20211014134444_add_import_field_to_p_product_refs.rb @@ -1,5 +1,6 @@ class AddImportFieldToPProductRefs < ActiveRecord::Migration[6.0] def change + add_column :p_product_refs, :genecode, :string add_column :p_product_refs, :manufacturer_ref, :string add_column :p_product_refs, :used_state, :string add_column :p_product_refs, :i_code_hs, :string diff --git a/db/schema.rb b/db/schema.rb index c4ad708..e724b16 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1818,6 +1818,7 @@ ActiveRecord::Schema.define(version: 2021_10_14_134444) do t.decimal "ct_deee", precision: 10, scale: 2 t.string "ean" t.string "sorecop_comment" + t.string "genecode" t.string "manufacturer_ref" t.string "used_state" t.string "i_code_hs" @@ -1926,7 +1927,6 @@ ActiveRecord::Schema.define(version: 2021_10_14_134444) do t.boolean "conserve_proportion", default: false t.boolean "frontpage", default: true t.integer "sorecop_cat_id" - t.string "genecode" t.index ["p_product_cat_id"], name: "index_p_products_on_p_product_cat_id" t.index ["s_brand_id"], name: "index_p_products_on_s_brand_id" end From ad135f6ff81de7f68ebc8f597e6f68ba950e2a0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 15 Oct 2021 18:22:02 +0200 Subject: [PATCH 116/131] Import p_product ok --- app/models/p_product.rb | 115 ++++++++++++++++++++++++------------ app/models/p_product_ref.rb | 52 ++++++++++++---- app/models/s_brand.rb | 21 +++++++ 3 files changed, 139 insertions(+), 49 deletions(-) diff --git a/app/models/p_product.rb b/app/models/p_product.rb index 4f8c65e..2b2a73a 100644 --- a/app/models/p_product.rb +++ b/app/models/p_product.rb @@ -70,6 +70,11 @@ class PProduct < ApplicationRecord } + before_validation do + if self.code.blank? + generate_code + end + end def self.for_search(search) @@ -166,6 +171,35 @@ class PProduct < ApplicationRecord self.p_product_images.order(:position).first end + + def generate_code + if !self.code + arr = [] + brand = self.s_brand.code.to_s if self.s_brand + + cat = self.p_product_cat.name.slice(0, 5).to_slug.upcase.to_s if self.p_product_cat + last_number = 1 + + arr << brand if brand.present? + arr << cat if cat.present? + arr << "%02d" % [last_number] + arr.prepend("PRODUCT") if arr.length < 2 + code = arr.join('-') + + while self.class.find_by(code: code) + arr = [] + last_number += 1 + arr << brand if brand.present? + arr << cat if cat.present? + arr << "%02d" % [last_number] + arr.prepend("PRODUCT") if arr.length < 2 + code = arr.join('-') + end + self.code = code + end + end + + acts_as_csv_import :fields => [ :identifiant, :gencode, @@ -223,32 +257,36 @@ class PProduct < ApplicationRecord # ap "*********************************************************************************************************" soreco_cat_hash = { "Smartphone" => "Smartphones & Téléphones mobiles", + "Mobile" => "Smartphones & Téléphones mobiles", "Tablette" => "Tablettes média et tablette PC", - "MP4" => "Baladeur MP4" + "MP4" => "Baladeur MP4", + "Clé USB" => "Clés USB", + "Carte Mémoire" => "Cartes mémoires", + "Boitier Multimédia" => "Décodeurs, téléviseurs, enregistreurs" } list.each do |row| next if row["marque"].blank? - - n = self.new(imported: true) - ref = PProductRef.find_or_initialize_by(p_product: n, description: row["identifiant"]) + n = self.find_or_initialize_by(s_brand: SBrand.find_by(name: row["marque"]), name: row["reference"]) + n.imported = true + n.sorecop_cat = SorecopCat.find_by(name: soreco_cat_hash[row["famille"]]) + ref = n.p_product_refs.build row.each do |key, value| - if self.type_for_attribute(key) and self.type_for_attribute(key).type == :decimal - eval "n.#{key} = value.to_s.gsub(' ', '').gsub(',', '.')" - else + if value.present? + puts key case key when "identifiant" ref.description = value when "gencode" - n.genecode = value + ref.genecode = value when "id" when "marque" - n.s_brand = SBrand.find_or_create_by(name: value) + n.s_brand = SBrand.find_or_create_by!(name: value) when "famille" - n.p_product_cat = PProductCat.find_or_create_by(name: value) + n.p_product_cat = PProductCat.find_or_create_by!(name: value) when "reference" n.name = value @@ -257,11 +295,11 @@ class PProduct < ApplicationRecord ref.ct_sub_name = value if value.present? when "couleur" - ref.p_product_color = PProductColor.find_or_create_by(name: value) + ref.p_product_color = PProductColor.find_or_create_by!(name: value) when "color" if ref.p_product_color.nil? - ref.p_product_color = PProductColor.find_or_create_by(color: value) + ref.p_product_color = PProductColor.find_or_create_by!(color: value) end when "connectivite" arr = [] @@ -280,36 +318,36 @@ class PProduct < ApplicationRecord arr.each do |value| spec = nil if cellular.include?(value) - spec = PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Connectivité"), p_spec_value: PSpecValue.find_or_create_by(value: value)) + spec = PProductRefSpec.create!(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Connectivité"), p_spec_value: PSpecValue.find_or_create_by!(value: value)) elsif video.include?(value) - spec = PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Résolution"), p_spec_value: PSpecValue.find_or_create_by(value: value)) + spec = PProductRefSpec.create!(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Résolution"), p_spec_value: PSpecValue.find_or_create_by!(value: value)) elsif power.include?(value) - PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Puissance éléctrique"), p_spec_value: PSpecValue.find_or_create_by(value: value.gsub('W', ''), unit: "W")) + PProductRefSpec.create!(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Puissance éléctrique"), p_spec_value: PSpecValue.find_or_create_by!(value: value.gsub('W', ''), unit: "W")) elsif geoloc.include?(value) - spec = PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Géolocalisation"), p_spec_value: PSpecValue.find_or_create_by(value: value)) + spec = PProductRefSpec.create!(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Géolocalisation"), p_spec_value: PSpecValue.find_or_create_by!(value: value)) else - spec = PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Autre"), p_spec_value: PSpecValue.find_or_create_by(value: value)) + spec = PProductRefSpec.create!(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Autre"), p_spec_value: PSpecValue.find_or_create_by!(value: value)) end import_csv.import_csv_elements << ImportCsvElement.new(:element => spec) end when "sim" if ["DS", "SS"].include?(value) - PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Sim"), p_spec_value: PSpecValue.find_or_create_by(value: value)) + PProductRefSpec.create!(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Sim"), p_spec_value: PSpecValue.find_or_create_by!(value: value)) elsif value == "4G" - PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Connectivité"), p_spec_value: PSpecValue.find_or_create_by(value: value)) + PProductRefSpec.create!(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Connectivité"), p_spec_value: PSpecValue.find_or_create_by!(value: value)) end when "taille" - PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Taille"), p_spec_value: PSpecValue.find_or_create_by(value: value.to_s)) + PProductRefSpec.create!(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Taille"), p_spec_value: PSpecValue.find_or_create_by!(value: value.to_s)) when "capacite" unit = value.match(/\D+/) num = value.match(/\d+/) - spec = PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Stockage"), p_spec_value: PSpecValue.find_or_create_by(value: num.to_s, unit: unit.to_s)) + spec = PProductRefSpec.create!(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Stockage"), p_spec_value: PSpecValue.find_or_create_by!(value: num.to_s, unit: unit.to_s)) import_csv.import_csv_elements << ImportCsvElement.new(:element => spec) when "infos_supp" - spec = PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Autre"), p_spec_value: PSpecValue.find_or_create_by(value: value)) + spec = PProductRefSpec.create!(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Autre"), p_spec_value: PSpecValue.find_or_create_by!(value: value)) import_csv.import_csv_elements << ImportCsvElement.new(:element => spec) when "reference_fabricant" ref.manufacturer_ref = value @@ -344,43 +382,47 @@ class PProduct < ApplicationRecord when "sorecop" ref.p_product.sorecop_cat = SorecopCat.find_by(name: soreco_cat_hash[row["famille"]]) if ref.sorecop.kind_of?(String) - ref.ct_sorecop = value + ref.ct_sorecop = value if !value.blank? end when "pmp_hors_sorecop" ref.i_pmp_hors_sorecop = value when "target_hors_sorecop" ref.i_target_hors_sorecop = value when "frs" - ref.fournisseur_id = PFournisseur.find_or_create_by(name: value) + ref.p_fournisseur_id = PFournisseur.find_or_create_by!(name: value).id when "spec" - spec = PProductRefSpec.create(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Version ROM"), p_spec_value: PSpecValue.find_or_create_by(value: value)) + spec = PProductRefSpec.create!(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Version ROM"), p_spec_value: PSpecValue.find_or_create_by!(value: value)) import_csv.import_csv_elements << ImportCsvElement.new(:element => spec) when "commentaires" ref.i_comment = value + # champs ignorés when "date" # colonne vide when "dtl_targ" when "dtl" when "com" - else eval "n.#{key} = value" end + # if self.type_for_attribute(key) and self.type_for_attribute(key).type == :decimal + # eval "n.#{key} = value.to_s.gsub(' ', '').gsub(',', '.')" + # end end end - # n.save + n.save! + import_csv.import_csv_elements << ImportCsvElement.new(:element => ref) + import_csv.import_csv_elements << ImportCsvElement.new(:element => n) - - ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" - ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" - ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" - ap n - ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" - ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" - ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n.ref §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" - ap n.ref + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap n + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n.ref §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" + # ap ref # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n.contacts §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" @@ -400,7 +442,6 @@ class PProduct < ApplicationRecord # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" # ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§" - import_csv.import_csv_elements << ImportCsvElement.new(:element => n) end end end diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb index 5f8a453..5790117 100644 --- a/app/models/p_product_ref.rb +++ b/app/models/p_product_ref.rb @@ -15,7 +15,7 @@ class PProductRef < ApplicationRecord has_many :p_article_serial_nums, through: :p_articles accepts_nested_attributes_for :p_article_serial_nums, allow_destroy: true - has_many :p_product_ref_specs + has_many :p_product_ref_specs, dependent: :destroy accepts_nested_attributes_for :p_product_ref_specs, allow_destroy: true, reject_if: :all_blank #validates :ct_price_ht, :presence => true @@ -52,7 +52,7 @@ class PProductRef < ApplicationRecord :actions => {:name => "Actions", :reorder => false} } - acts_as_caching :fields => [:sorecop, :deee] + acts_as_caching :fields => [:sorecop, :deee, :name, :code] attr_accessor :price_line_id @@ -89,9 +89,35 @@ class PProductRef < ApplicationRecord def ca_name - if self.p_product - self.p_product.name + " - " + self.ct_sub_name - end + storage = self.p_product_ref_specs.where(p_spec_type: PSpecType.find_by(name: "Stockage")).first + cellular = self.p_product_ref_specs.where(p_spec_type: PSpecType.find_by(name: "Connectivité")).first + screen = self.p_product_ref_specs.where(p_spec_type: PSpecType.find_by(name: "Résolution")).first + power = self.p_product_ref_specs.where(p_spec_type: PSpecType.find_by(name: "Puissance éléctrique")).first + geoloc = self.p_product_ref_specs.where(p_spec_type: PSpecType.find_by(name: "Géolocalisation")).first + sim = self.p_product_ref_specs.where(p_spec_type: PSpecType.find_by(name: "Sim")).first + size = self.p_product_ref_specs.where(p_spec_type: PSpecType.find_by(name: "Taille")).first + version = self.p_product_ref_specs.where(p_spec_type: PSpecType.find_by(name: "Version ROM")).first + + + + + arr = [] + arr << self.p_product.name if self.p_product + arr << self.ct_sub_name + arr << storage.p_spec_value.member_label if storage + arr << cellular.p_spec_value.member_label if cellular + arr << screen.p_spec_value.member_label if screen + arr << power.p_spec_value.member_label if power + arr << geoloc.p_spec_value.member_label if geoloc + arr << sim.p_spec_value.member_label if sim + arr << size.p_spec_value.member_label if size + arr << version.p_spec_value.member_label if version + arr << self.p_product_color.name if p_product_color + + arr.compact.each{|el| el.strip!}.join(' ') + # if self.p_product + # self.p_product.name + " - " + self.ct_sub_name + # end end def ca_code @@ -169,14 +195,14 @@ class PProductRef < ApplicationRecord end def ca_sorecop - return ct_sorecop if ct_sorecop + # return ct_sorecop if ct_sorecop return "Pas de catégorie Sorecop" if self.p_product.sorecop_cat.blank? - if self.cc_sorecop - return self.cc_sorecop - else + # if self.cc_sorecop and self.cc_sorecop > 0.0 + # return self.cc_sorecop + # else find_sorecop_tax - end + # end end def find_sorecop_tax @@ -184,10 +210,12 @@ class PProductRef < ApplicationRecord return "Pas de stockage" if p_product_ref_spec.blank? storage_capacity = p_product_ref_spec.p_spec_value.value.to_f - if p_product_ref_spec.p_spec_value.unit.casecmp?("Go") + if p_product_ref_spec.p_spec_value.unit.casecmp?("Gb") tax = self.p_product.sorecop_cat.sorecop_taxes.where('critere_min < ? AND critere_max >= ?', storage_capacity, storage_capacity).first - elsif p_product_ref_spec.p_spec_value.unit.casecmp?("To") + elsif p_product_ref_spec.p_spec_value.unit.casecmp?("Tb") tax = self.p_product.sorecop_cat.sorecop_taxes.where('critere_min < ? AND critere_max >= ?', storage_capacity * 1000, storage_capacity * 1000).first + elsif p_product_ref_spec.p_spec_value.unit.casecmp?("Mb") + tax = self.p_product.sorecop_cat.sorecop_taxes.where('critere_min < ? AND critere_max >= ?', storage_capacity / 1000, storage_capacity / 1000).first end if tax.fixed_price diff --git a/app/models/s_brand.rb b/app/models/s_brand.rb index c5db009..4f87015 100644 --- a/app/models/s_brand.rb +++ b/app/models/s_brand.rb @@ -1,4 +1,25 @@ class SBrand < ApplicationRecord validates :name, :presence => true, :uniqueness => true + + before_save do + if self.code.blank? + generate_code + end + end + + + def generate_code + if self.code.blank? + prefix = self.name.slice(0, 4).to_slug.upcase + last_number = 1 + code = prefix + "%02d" % [last_number] + + while self.class.find_by(code: code) + last_number += 1 + code = prefix + "%02d" % [last_number] + end + self.code = code + end + end end From cd0d3d2b53b3a88074022c017ca6b4274f283f41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 15 Oct 2021 18:24:23 +0200 Subject: [PATCH 117/131] protect from zero --- app/models/p_product.rb | 44 ++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/app/models/p_product.rb b/app/models/p_product.rb index 2b2a73a..1147c4a 100644 --- a/app/models/p_product.rb +++ b/app/models/p_product.rb @@ -277,9 +277,9 @@ class PProduct < ApplicationRecord puts key case key when "identifiant" - ref.description = value + ref.description = value if !value.blank? when "gencode" - ref.genecode = value + ref.genecode = value if !value.blank? when "id" when "marque" @@ -289,10 +289,10 @@ class PProduct < ApplicationRecord n.p_product_cat = PProductCat.find_or_create_by!(name: value) when "reference" - n.name = value + n.name = value if !value.blank? when "modele" - ref.ct_sub_name = value if value.present? + ref.ct_sub_name = value if !value.blank? when "couleur" ref.p_product_color = PProductColor.find_or_create_by!(name: value) @@ -350,51 +350,51 @@ class PProduct < ApplicationRecord spec = PProductRefSpec.create!(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Autre"), p_spec_value: PSpecValue.find_or_create_by!(value: value)) import_csv.import_csv_elements << ImportCsvElement.new(:element => spec) when "reference_fabricant" - ref.manufacturer_ref = value + ref.manufacturer_ref = value if !value.blank? when "etat" - ref.used_state = value + ref.used_state = value if !value.blank? when "code_hs" - ref.i_code_hs = value + ref.i_code_hs = value if !value.blank? when "indice_reparabilite" - ref.prepair_score = value + ref.prepair_score = value if !value.blank? when "duree_dispo_pces_detachees" - ref.part_delay = value + ref.part_delay = value if !value.blank? when "das_tete" - ref.das_head = value + ref.das_head = value if !value.blank? when "das_corps" - ref.das_body = value + ref.das_body = value if !value.blank? when "das_membre" - ref.das_membre = value + ref.das_membre = value if !value.blank? when "poids" - ref.weight = value + ref.weight = value if !value.blank? when "nb_pcs_colis" - ref.nb_pcs_colis = value + ref.nb_pcs_colis = value if !value.blank? when "code_om" - ref.code_om = value + ref.code_om = value if !value.blank? when "gbh_code_971" - ref.gbh_code_971 = value + ref.gbh_code_971 = value if !value.blank? when "gbh_code_972" - ref.gbh_code_972 = value + ref.gbh_code_972 = value if !value.blank? when "gbh_code_973" - ref.gbh_code_973 = value + ref.gbh_code_973 = value if !value.blank? when "code_art" - ref.code_art = value + ref.code_art = value if !value.blank? when "sorecop" ref.p_product.sorecop_cat = SorecopCat.find_by(name: soreco_cat_hash[row["famille"]]) if ref.sorecop.kind_of?(String) ref.ct_sorecop = value if !value.blank? end when "pmp_hors_sorecop" - ref.i_pmp_hors_sorecop = value + ref.i_pmp_hors_sorecop = value if !value.blank? when "target_hors_sorecop" - ref.i_target_hors_sorecop = value + ref.i_target_hors_sorecop = value if !value.blank? when "frs" ref.p_fournisseur_id = PFournisseur.find_or_create_by!(name: value).id when "spec" spec = PProductRefSpec.create!(p_product_ref: ref, p_spec_type: PSpecType.find_by(name: "Version ROM"), p_spec_value: PSpecValue.find_or_create_by!(value: value)) import_csv.import_csv_elements << ImportCsvElement.new(:element => spec) when "commentaires" - ref.i_comment = value + ref.i_comment = value if !value.blank? # champs ignorés when "date" From 3a7b510e64430ea371afc5ddc68250e3566b5e03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 18 Oct 2021 09:42:01 +0200 Subject: [PATCH 118/131] raise if creation abort --- app/models/p_customer.rb | 12 ++++++------ app/models/p_fournisseur.rb | 6 +++--- app/models/price_document.rb | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/models/p_customer.rb b/app/models/p_customer.rb index b2ee2c1..a0e3a00 100644 --- a/app/models/p_customer.rb +++ b/app/models/p_customer.rb @@ -694,11 +694,11 @@ class PCustomer < ApplicationRecord when "mode_reglement" if value.present? if value == "VIR" || "VIR COM" || "VIR 60 J NET" || "VIR 30 J NET" - n.p_payment_type_id = PPaymentType.find_or_create_by(name: "Virement").id + n.p_payment_type_id = PPaymentType.find_or_create_by!(name: "Virement").id elsif value == "TRAITE" - n.p_payment_type_id = PPaymentType.find_or_create_by(name: "Traite").id + n.p_payment_type_id = PPaymentType.find_or_create_by!(name: "Traite").id else - n.p_payment_type_id = PPaymentType.find_or_create_by(name: value).id + n.p_payment_type_id = PPaymentType.find_or_create_by!(name: value).id end end @@ -724,7 +724,7 @@ class PCustomer < ApplicationRecord when "nom_banque" if value.present? - bank = PBank.find_or_create_by(name: value) + bank = PBank.find_or_create_by!(name: value) end when "adresse_banque_1" @@ -769,7 +769,7 @@ class PCustomer < ApplicationRecord when "fonction_contact" if value.present? - contact.p_contact_types << PContactType.find_or_create_by(name: value) + contact.p_contact_types << PContactType.find_or_create_by!(name: value) end when "telephone_contact" contact.tel = value @@ -860,7 +860,7 @@ class PCustomer < ApplicationRecord end if p_commercial_code || p_commercial_firstname - p_commercial = PCommercial.find_or_create_by(code: p_commercial_code, firstname: p_commercial_firstname) + p_commercial = PCommercial.find_or_create_by!(code: p_commercial_code, firstname: p_commercial_firstname) n.p_commercial = p_commercial end diff --git a/app/models/p_fournisseur.rb b/app/models/p_fournisseur.rb index f65ac86..344c669 100644 --- a/app/models/p_fournisseur.rb +++ b/app/models/p_fournisseur.rb @@ -94,7 +94,7 @@ class PFournisseur < ApplicationRecord when "interlocuteur" contact_1.name = value when "fonction" - contact_1.p_contact_types << PContactType.find_or_create_by(name: value) + contact_1.p_contact_types << PContactType.find_or_create_by!(name: value) when "tel" contact_1.tel = value when "skype" @@ -106,7 +106,7 @@ class PFournisseur < ApplicationRecord when "email_3" contact_3 = PContact.new(email: value) when "reglement_par" - n.p_payment_type_id = PPaymentType.find_or_create_by(name: value).id + n.p_payment_type_id = PPaymentType.find_or_create_by!(name: value).id else eval "n.#{key} = value" end @@ -114,7 +114,7 @@ class PFournisseur < ApplicationRecord end # particular.organisation = self.name - n.save + n.save! if (contact_1.name || contact_1.tel || contact_1.skype || contact_1.email) n.p_contacts << contact_1 import_csv.import_csv_elements << ImportCsvElement.new(:element => contact_1) diff --git a/app/models/price_document.rb b/app/models/price_document.rb index 1e5a9b1..a6b847b 100644 --- a/app/models/price_document.rb +++ b/app/models/price_document.rb @@ -753,7 +753,7 @@ class PriceDocument < ApplicationRecord n.price_line_block.price_lines << price_line - n.save + n.save! import_csv.import_csv_elements << ImportCsvElement.new(:element => n) import_csv.import_csv_elements << ImportCsvElement.new(:element => price_line) end From 5da52468000065cbd1a616c5f5ea566b57eeef3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 18 Oct 2021 09:42:12 +0200 Subject: [PATCH 119/131] protect from blank --- app/models/p_customer.rb | 66 ++++++++++++++++++------------------- app/models/p_fournisseur.rb | 22 ++++++------- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/app/models/p_customer.rb b/app/models/p_customer.rb index a0e3a00..42bf4cd 100644 --- a/app/models/p_customer.rb +++ b/app/models/p_customer.rb @@ -653,43 +653,43 @@ class PCustomer < ApplicationRecord else case key when "societe_raison_sociale" - particular_bill.organisation = value + particular_bill.organisation = value if !value.blank? when "nom_enseigne" - particular_bill.com_name = value + particular_bill.com_name = value if !value.blank? when "adresse_facturation_1" - particular_bill.address_1 = value + particular_bill.address_1 = value if !value.blank? when "adresse_livraison_2" - send_address_2 = value + send_address_2 = value if !value.blank? when "adresse_3" - particular_bill.address_3 = value + particular_bill.address_3 = value if !value.blank? when "cp" - particular_bill.cp = value + particular_bill.cp = value if !value.blank? when "ville_1" - particular_bill.city = value + particular_bill.city = value if !value.blank? when "pays" - particular_bill.country = value + particular_bill.country = value if !value.blank? when "societe_livraison" - particular_bill.address_4 = value + particular_bill.address_4 = value if !value.blank? when "forme_juridique" - particular_bill.address_5 = value + particular_bill.address_5 = value if !value.blank? when "telephone_1" - particular_bill.tel = value + particular_bill.tel = value if !value.blank? when "telephone_2" - particular_bill.tel2 = value + particular_bill.tel2 = value if !value.blank? when "fax" - particular_bill.fax = value + particular_bill.fax = value if !value.blank? when "mode_reglement" if value.present? @@ -719,7 +719,7 @@ class PCustomer < ApplicationRecord when "Mensuel - 30j fin de mois du dépôt" n.payment_delais = 30 else - n.payment_delais = value + n.payment_delais = value if !value.blank? end when "nom_banque" @@ -728,66 +728,66 @@ class PCustomer < ApplicationRecord end when "adresse_banque_1" - bank_particular.address_1 = value + bank_particular.address_1 = value if !value.blank? when "adresse_banque_2" - bank_particular.address_2 = value + bank_particular.address_2 = value if !value.blank? when "code_banque" - bank_particular.cp = value + bank_particular.cp = value if !value.blank? when "ville_banque" - bank_particular.city = value + bank_particular.city = value if !value.blank? when "pays_banque" - bank_particular.country = value + bank_particular.country = value if !value.blank? when "telephone_livraison" - send_tel = value + send_tel = value if !value.blank? when "portable_livraison" - send_tel2 = value + send_tel2 = value if !value.blank? when "fax_livraison" - send_fax = value + send_fax = value if !value.blank? when "representant" - p_commercial_code = value + p_commercial_code = value if !value.blank? when "nom_representant" - p_commercial_firstname = value + p_commercial_firstname = value if !value.blank? when "code_iban" - iban = value + iban = value if !value.blank? when "code_bic" - bic = value + bic = value if !value.blank? when "nom_contact" - contact.name = value + contact.name = value if !value.blank? when "titre_contact" - particular_bill.civilite = value + particular_bill.civilite = value if !value.blank? when "fonction_contact" if value.present? contact.p_contact_types << PContactType.find_or_create_by!(name: value) end when "telephone_contact" - contact.tel = value + contact.tel = value if !value.blank? when "portable_contact" if value.present? if contact.tel.nil? - contact.tel = value + contact.tel = value if !value.blank? else contact_2 = PContact.new(tel: value) end end when "email_contact" - contact.email = value + contact.email = value if !value.blank? when "observation" - n.p_customer_sheet_note = value + n.p_customer_sheet_note = value if !value.blank? @@ -829,7 +829,7 @@ class PCustomer < ApplicationRecord when "client_divers" else - eval "n.#{key} = value" + eval "n.#{key} = value if !value.blank?" end diff --git a/app/models/p_fournisseur.rb b/app/models/p_fournisseur.rb index 344c669..6f0cacb 100644 --- a/app/models/p_fournisseur.rb +++ b/app/models/p_fournisseur.rb @@ -53,15 +53,15 @@ class PFournisseur < ApplicationRecord else case key when "nom_fournisseur" - n.name = value + n.name = value if !value.blank? when "address" - n.address1 = value + n.address1 = value if !value.blank? when "ville" - n.city = value + n.city = value if !value.blank? when "pays" - n.country = value + n.country = value if !value.blank? when "tva_intracom" - n.tva_num = value + n.tva_num = value if !value.blank? when "delai_paiement" if value.present? case value @@ -88,19 +88,19 @@ class PFournisseur < ApplicationRecord when "60 jours fin de mois" n.payment_delais = 60 else - n.payment_delais = value + n.payment_delais = value if !value.blank? end end when "interlocuteur" - contact_1.name = value + contact_1.name = value if !value.blank? when "fonction" contact_1.p_contact_types << PContactType.find_or_create_by!(name: value) when "tel" - contact_1.tel = value + contact_1.tel = value if !value.blank? when "skype" - contact_1.skype = value + contact_1.skype = value if !value.blank? when "email_1" - contact_1.email = value + contact_1.email = value if !value.blank? when "email_2" contact_2 = PContact.new(email: value) when "email_3" @@ -108,7 +108,7 @@ class PFournisseur < ApplicationRecord when "reglement_par" n.p_payment_type_id = PPaymentType.find_or_create_by!(name: value).id else - eval "n.#{key} = value" + eval "n.#{key} = value if !value.blank?" end end From 0fad587a3e35b360d74aae94b41556aa6345f356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 18 Oct 2021 14:32:05 +0200 Subject: [PATCH 120/131] Display price_line data on matching index --- .../_form_temp_p_product.html.haml | 22 ++++++++++++------- .../admin/import_csvs/match_refs.html.haml | 5 +++-- .../price_lines/_form_match_refs.html.haml | 7 ++++-- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/app/views/admin/import_csvs/_form_temp_p_product.html.haml b/app/views/admin/import_csvs/_form_temp_p_product.html.haml index 9173a3d..f5a2ac1 100644 --- a/app/views/admin/import_csvs/_form_temp_p_product.html.haml +++ b/app/views/admin/import_csvs/_form_temp_p_product.html.haml @@ -4,21 +4,27 @@ .qi_row.field .padding - %h1 Ajouter une références + %h1 Ajouter une référence + .card.border.border-primary.mb-3 + %h5.card-header.border-bottom Rappel des infos fournisseurs + .card-body + %h5.card-title libellé : + %p.card-text + =@p_product_ref.ct_sub_name + + %table.form-table %tr %td{colspan: 3} - %label Selectionner le produit parent + %label Selectionner le produit parent : .input-group %input.p_product_autocomplete_input.form-control{:type => "text", :style => "", tabindex: 1, autofocus: true, :class => "p_product_name"} =form.hidden_field :p_product_id, :class => "p_product_id" =link_to ic(:plus)+ " Ajouter produit", new_admin_p_product_path(fournisseur_label: @p_product_ref.ct_sub_name, price_line_id: @price_line.id) + %br - %tr - %td{:colspan => 3} - %input.form-control{type: "text", placeholder: @p_product_ref.ct_sub_name, "aria-label" => "Disabled input example", disabled: true} - =#form.input :ct_sub_name, label: "Label fournisseur", input_html: {disabled: true} + %tr{height: "20px"} %tr %td{:colspan => 3} @@ -34,9 +40,9 @@ =form.input :p_product_color_id, :label => "Couleur :", :collection => PProductColor.all, :as => :select, :include_blank => true, input_html: {class: "custom-select"} %tr %td - =form.input :ct_sorecop, :label => "Sorecop personalisée :" + =form.input :ct_sorecop, :label => "Sorecop personalisée (€) :" %td - =form.input :sorecop_comment, :label => "Type de Sorecop :" + =form.input :sorecop_comment, :label => "Commentaire Sorecop :" %td =form.input :ct_deee, :label => "DEEE personalisée :" %tr diff --git a/app/views/admin/import_csvs/match_refs.html.haml b/app/views/admin/import_csvs/match_refs.html.haml index c44a8c0..c55dd77 100644 --- a/app/views/admin/import_csvs/match_refs.html.haml +++ b/app/views/admin/import_csvs/match_refs.html.haml @@ -17,8 +17,9 @@ %th %th Référence Produit Arcom %th Créer une référence - %th Référence fournisseur - %th + %th Libélé fournisseur + %th Prix unitaire + %th Quantité %tbody.price_lines_form =f.semantic_fields_for :price_lines do |form| -if form.object.p_product_ref.nil? diff --git a/app/views/admin/price_lines/_form_match_refs.html.haml b/app/views/admin/price_lines/_form_match_refs.html.haml index fb4fc62..0fd0b42 100644 --- a/app/views/admin/price_lines/_form_match_refs.html.haml +++ b/app/views/admin/price_lines/_form_match_refs.html.haml @@ -24,9 +24,13 @@ %span=link_to ic(:"plus"), temp_p_product_admin_import_csvs_path(price_line_id: form.object.id), remote: true - + %td.pl-2 =form.object.title + %td + =number_to_currency form.object.price_u_ht + %td + =form.object.qte %td.text-center{style: "width: 30px;"} %span.destroy=link_to_remove_fields ic(:"trash-o"), form @@ -35,7 +39,6 @@ = form.hidden_field :position, :class => "price_line_position_input" - :javascript $('.p_product_ref_autocomplete_input').focus() $( function() { From 999ae95c827d8db5093ea605e1048c9eeeb25a4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 18 Oct 2021 14:32:21 +0200 Subject: [PATCH 121/131] Generate code for client --- app/models/p_customer.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/models/p_customer.rb b/app/models/p_customer.rb index 42bf4cd..54900d5 100644 --- a/app/models/p_customer.rb +++ b/app/models/p_customer.rb @@ -65,6 +65,26 @@ class PCustomer < ApplicationRecord has_many :order_hists # before_validation :set_auth_token, on: [:create, :update] + before_validation do + if self.code.blank? + generate_code + end + end + + def generate_code + if !self.code + last_used_code = self.class.all.order(code: :desc).limit(1)[0].code + last_number = last_used_code.match(/\d+/).to_s.to_i + 1 + + code = "CLI%04d" % [last_number] + + while self.class.find_by(code: code) + last_number += 1 + code = "CLI%04d" % [last_number] + end + self.code = code + end + end def self.qi_table_order From 14faad87376ceb8d3937c8d81a92c3b81f71f750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 18 Oct 2021 14:36:33 +0200 Subject: [PATCH 122/131] p_customer code auto --- app/views/admin/p_customers/_form.html.haml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/admin/p_customers/_form.html.haml b/app/views/admin/p_customers/_form.html.haml index 36b96f5..ee76638 100755 --- a/app/views/admin/p_customers/_form.html.haml +++ b/app/views/admin/p_customers/_form.html.haml @@ -61,7 +61,8 @@ = form.input :particular_send_id, :collection => form.object.particulars.all, :as => :select, :member_label => :address_line, :include_blank => true, :label => "Adresse de livraison :" - =form.input :code, :label => "Code client" + -if false + =form.input :code, :label => "Code client" -if !@p_customer.id From 56820f3f0438d8c54f9cea5c188ce1012b90eca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 18 Oct 2021 16:16:55 +0200 Subject: [PATCH 123/131] remove useless import p_fournisseur --- .../admin/p_fournisseurs_controller.rb | 13 ------------- .../p_fournisseurs/import_fournisseurs.html.haml | 16 ---------------- app/views/admin/p_fournisseurs/index.html.haml | 1 - config/routes.rb | 2 -- 4 files changed, 32 deletions(-) delete mode 100644 app/views/admin/p_fournisseurs/import_fournisseurs.html.haml diff --git a/app/controllers/admin/p_fournisseurs_controller.rb b/app/controllers/admin/p_fournisseurs_controller.rb index e406eed..992106e 100644 --- a/app/controllers/admin/p_fournisseurs_controller.rb +++ b/app/controllers/admin/p_fournisseurs_controller.rb @@ -22,19 +22,6 @@ class Admin::PFournisseursController < ApplicationController end end - - def import_fournisseurs - # @file = params[:csv_file] - # require 'csv' - - # csv_text = File.read("#{Rails.root}/import_csv/fournisseurs.csv") #.force_encoding('ISO-8859-1') - # @csv = CSV.parse(csv_text, :headers => true, :col_sep => ";") - - end - - def import_fournisseurs_xls - raise - end def index @p_fournisseurs = PFournisseur.order(:name).all diff --git a/app/views/admin/p_fournisseurs/import_fournisseurs.html.haml b/app/views/admin/p_fournisseurs/import_fournisseurs.html.haml deleted file mode 100644 index 1010d73..0000000 --- a/app/views/admin/p_fournisseurs/import_fournisseurs.html.haml +++ /dev/null @@ -1,16 +0,0 @@ -.qi_header - .right - %h1 - Import - %span - Fournisseurs - - -.qi_row - .qi_pannel.qi_plain.padding - %table.table - %tr - %td - =form_with url: import_fournisseurs_xls_admin_p_fournisseurs_path() do |form| - =form.file_field_tag 'Base client', accept: '.xls, .xlsx' - =form.submit_tag 'importer' diff --git a/app/views/admin/p_fournisseurs/index.html.haml b/app/views/admin/p_fournisseurs/index.html.haml index 22fa1ce..3423253 100644 --- a/app/views/admin/p_fournisseurs/index.html.haml +++ b/app/views/admin/p_fournisseurs/index.html.haml @@ -1,7 +1,6 @@ .qi_header .right = link_to 'Ajouter un fournisseur', new_admin_p_fournisseur_path(), :class => "btn btn-primary", :remote => true - =link_to 'import base fournisseurs', import_fournisseurs_admin_p_fournisseurs_path(), :class => "btn btn-primary" %h1 Achats %span diff --git a/config/routes.rb b/config/routes.rb index ab30648..a385f22 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1004,8 +1004,6 @@ Rails.application.routes.draw do resources :p_fournisseurs do collection do get :import - get :import_fournisseurs - post :import_fournisseurs_xls end From 6ed30defc6ce5dd1dc17718c06ff678faf5a5a0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 18 Oct 2021 16:18:06 +0200 Subject: [PATCH 124/131] bugfix import --- app/models/p_customer.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/models/p_customer.rb b/app/models/p_customer.rb index 54900d5..23c9012 100644 --- a/app/models/p_customer.rb +++ b/app/models/p_customer.rb @@ -732,12 +732,16 @@ class PCustomer < ApplicationRecord n.payment_delais = 0 when "30 JOURS FIN DE MOIS" n.payment_delais = 30 + n.comptant = false when "VIR 60J NET DATE RELEVE" n.payment_delais = 60 + n.comptant = false when "TRAITE A 60 JOURS FIN DE MOIS" n.payment_delais = 60 + n.comptant = false when "Mensuel - 30j fin de mois du dépôt" n.payment_delais = 30 + n.comptant = false else n.payment_delais = value if !value.blank? end @@ -860,20 +864,22 @@ class PCustomer < ApplicationRecord n.particulars << particular_bill - n.save + n.save! if bank bank.bic = bic bank.particulars << bank_particular if bank_particular.address_1 - bank.save + bank.save! import_csv.import_csv_elements << ImportCsvElement.new(:element => bank) end if bic || iban - rib = PCustomerRib.create(bic: bic, iban: iban) + rib = PCustomerRib.find_or_create_by!(bic: bic, iban: iban) rib.bank = bank.name if bank - account = PBankAccount.create(bic: bic, iban: iban, p_bank: bank, p_customer: n) + account = PBankAccount.find_or_create_by!(bic: bic, iban: iban, p_customer: n) + account.update(p_bank: bank) if bank + n.p_customer_ribs << rib import_csv.import_csv_elements << ImportCsvElement.new(:element => rib) import_csv.import_csv_elements << ImportCsvElement.new(:element => account) @@ -882,6 +888,7 @@ class PCustomer < ApplicationRecord if p_commercial_code || p_commercial_firstname p_commercial = PCommercial.find_or_create_by!(code: p_commercial_code, firstname: p_commercial_firstname) n.p_commercial = p_commercial + import_csv.import_csv_elements << ImportCsvElement.new(:element => p_commercial) end if send_tel || send_tel2 || send_fax || send_address_2 From c9c65474cfe738fdf9399306e6b0e72d846cb0cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 18 Oct 2021 16:18:26 +0200 Subject: [PATCH 125/131] show automatic cc_name --- app/models/p_product_ref.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb index 5790117..0248b8d 100644 --- a/app/models/p_product_ref.rb +++ b/app/models/p_product_ref.rb @@ -42,8 +42,8 @@ class PProductRef < ApplicationRecord :p_product_cat => {:name => "Catégorie", :reorder => true}, :ref => {:name => "Référence"}, :cc_name => {:name => "Produit"}, - :description => {:name => "Description"}, - :ct_sub_name => {:name => "Nom référence"}, + # :description => {:name => "Description"}, + :cc_name => {:name => "Nom référence"}, :ct_price_ht => {:name => "Prix de vente", :as => :currency}, :ean => {:name => "EAN"}, :deee => {:name => "DEEE", :as => :currency}, @@ -195,7 +195,7 @@ class PProductRef < ApplicationRecord end def ca_sorecop - # return ct_sorecop if ct_sorecop + return ct_sorecop if ct_sorecop return "Pas de catégorie Sorecop" if self.p_product.sorecop_cat.blank? # if self.cc_sorecop and self.cc_sorecop > 0.0 From bd277931c066f009adc49f68a55cf80d1267c334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 18 Oct 2021 16:18:34 +0200 Subject: [PATCH 126/131] remove deug --- app/views/admin/import_csvs/index.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/import_csvs/index.html.haml b/app/views/admin/import_csvs/index.html.haml index 54de32a..70eead3 100644 --- a/app/views/admin/import_csvs/index.html.haml +++ b/app/views/admin/import_csvs/index.html.haml @@ -12,4 +12,4 @@ =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @import_csvs} -=debug OrderHistLine.new.class.type_for_attribute("ff") +=#debug OrderHistLine.new.class.type_for_attribute("ff") From 9660ba7147a7136088f9e2aec164f7cf62337954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 18 Oct 2021 17:14:51 +0200 Subject: [PATCH 127/131] upgrade scale for sorecop_tax --- db/migrate/20211018142636_add3scale_for_sorecop_taxex.rb | 6 ++++++ db/schema.rb | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20211018142636_add3scale_for_sorecop_taxex.rb diff --git a/db/migrate/20211018142636_add3scale_for_sorecop_taxex.rb b/db/migrate/20211018142636_add3scale_for_sorecop_taxex.rb new file mode 100644 index 0000000..c14b795 --- /dev/null +++ b/db/migrate/20211018142636_add3scale_for_sorecop_taxex.rb @@ -0,0 +1,6 @@ +class Add3scaleForSorecopTaxex < ActiveRecord::Migration[6.0] + def change + change_column :sorecop_taxes, :critere_min, :decimal, :precision => 14, :scale => 3 + change_column :sorecop_taxes, :critere_max, :decimal, :precision => 14, :scale => 3 + end +end diff --git a/db/schema.rb b/db/schema.rb index e724b16..1bbd164 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_10_14_134444) do +ActiveRecord::Schema.define(version: 2021_10_18_142636) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -2798,8 +2798,8 @@ ActiveRecord::Schema.define(version: 2021_10_14_134444) do end create_table "sorecop_taxes", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| - t.decimal "critere_min", precision: 10, scale: 2 - t.decimal "critere_max", precision: 10, scale: 2 + t.decimal "critere_min", precision: 14, scale: 3 + t.decimal "critere_max", precision: 14, scale: 3 t.string "title" t.boolean "fixed_price", default: true t.decimal "price", precision: 10, scale: 2 From 58b262a14f6482f50570ab68892dce37ecfc5402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 18 Oct 2021 17:15:02 +0200 Subject: [PATCH 128/131] default sorting --- app/controllers/admin/sorecop_taxes_controller.rb | 2 +- app/models/sorecop_tax.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/sorecop_taxes_controller.rb b/app/controllers/admin/sorecop_taxes_controller.rb index a67105b..4f62458 100644 --- a/app/controllers/admin/sorecop_taxes_controller.rb +++ b/app/controllers/admin/sorecop_taxes_controller.rb @@ -13,7 +13,7 @@ class Admin::SorecopTaxesController < ApplicationController def index @sorecop_taxes = SorecopTax.all - @sorecop_taxes = sort_by_sorting(@sorecop_taxes, "id DESC") + @sorecop_taxes = sort_by_sorting(@sorecop_taxes, "sorecop_cat_id ASC") respond_to do |format| format.html{ diff --git a/app/models/sorecop_tax.rb b/app/models/sorecop_tax.rb index 061dd00..66bec55 100644 --- a/app/models/sorecop_tax.rb +++ b/app/models/sorecop_tax.rb @@ -8,7 +8,7 @@ class SorecopTax < ApplicationRecord :critere_min => {:name => "Critère mini (Go)", :reorder => true}, :critere_max => {:name => "Critère maxi (Go)", :reorder => true}, :fixed_price => {:name => "Prix forfaitaire", :reorder => true, :format => :boolean}, - :sorecop_cat => {:name => "Catégorie SORECOP",member_label: :name, :reorder => false}, + :sorecop_cat => {:name => "Catégorie SORECOP",member_label: :name, :reorder => true, :sort_name => "sorecop_taxes.sorecop_cat_id"}, :price => {:name => "Prix", :reorder => false, as: :currency}, :actions => {:name => "Actions", :reorder => true} } From 60dadd0cb9441b7617c94e600ac19fa581ea5384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Tue, 19 Oct 2021 10:44:19 +0200 Subject: [PATCH 129/131] small improvement for ref match form --- .../admin/import_csvs_controller.rb | 2 +- .../_form_temp_p_product.html.haml | 36 +++++++++++++------ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/app/controllers/admin/import_csvs_controller.rb b/app/controllers/admin/import_csvs_controller.rb index bac0c29..7a3ed47 100644 --- a/app/controllers/admin/import_csvs_controller.rb +++ b/app/controllers/admin/import_csvs_controller.rb @@ -97,7 +97,7 @@ class Admin::ImportCsvsController < ApplicationController if params[:price_line_id] @price_line = PriceLine.find(params[:price_line_id]) p_product = PProduct.find_or_create_by(name: "--> Selectioner un produit <--", code: "--> Indiquer un code produit <--") - @p_product_ref = PProductRef.find_or_create_by(p_product: p_product, ct_sub_name: @price_line.title, ct_price_ht: @price_line.ct_u_price_ht) + @p_product_ref = PProductRef.find_or_create_by(p_product: p_product, description: @price_line.title, ct_price_ht: @price_line.ct_u_price_ht) @p_product_ref.p_product_ref_specs.build end end diff --git a/app/views/admin/import_csvs/_form_temp_p_product.html.haml b/app/views/admin/import_csvs/_form_temp_p_product.html.haml index f5a2ac1..f2c41fa 100644 --- a/app/views/admin/import_csvs/_form_temp_p_product.html.haml +++ b/app/views/admin/import_csvs/_form_temp_p_product.html.haml @@ -7,10 +7,24 @@ %h1 Ajouter une référence .card.border.border-primary.mb-3 %h5.card-header.border-bottom Rappel des infos fournisseurs - .card-body - %h5.card-title libellé : - %p.card-text - =@p_product_ref.ct_sub_name + %ul.list-group.list-group-flush + %li.list-group-item + .d-inline-flex + %h5.card-title{style: "min-width: 80px;"} libellé : + %p.card-text=@p_product_ref.description + %li.list-group-item + .d-inline-flex + %h5.card-title{style: "min-width: 80px;"} Qté : + %p.card-text + =@price_line.qte + %li.list-group-item + .d-inline-flex + %h5.card-title{style: "min-width: 80px;"} Prix : + %p.card-text + =number_to_currency @p_product_ref.ct_price_ht + + + %table.form-table @@ -21,20 +35,20 @@ %input.p_product_autocomplete_input.form-control{:type => "text", :style => "", tabindex: 1, autofocus: true, :class => "p_product_name"} =form.hidden_field :p_product_id, :class => "p_product_id" - =link_to ic(:plus)+ " Ajouter produit", new_admin_p_product_path(fournisseur_label: @p_product_ref.ct_sub_name, price_line_id: @price_line.id) + =link_to ic(:plus)+ " Ajouter produit", new_admin_p_product_path(fournisseur_label: @p_product_ref.description, price_line_id: @price_line.id) %br %tr{height: "20px"} - - %tr - %td{:colspan => 3} - = form.input :ct_sub_name, :label => "Désignation ARCOM :" + -if false + %tr + %td{:colspan => 3} + = form.input :ct_sub_name, :label => "Désignation ARCOM :" %tr %td = form.input :ref, :label => "Réf int. :" %td - = form.input :ct_price_ht, :label => "Prix vente HT :" + = form.input :ct_price_ht, :label => "Prix vente € HT:" %td =form.input :p_product_color_id, :label => "Couleur :", :collection => PProductColor.all, :as => :select, :include_blank => true, input_html: {class: "custom-select"} @@ -44,7 +58,7 @@ %td =form.input :sorecop_comment, :label => "Commentaire Sorecop :" %td - =form.input :ct_deee, :label => "DEEE personalisée :" + =form.input :ct_deee, :label => "DEEE personalisée (€):" %tr %td =form.input :ean From 2941d5f2848d8a503306d86856ef78bb4f46e7b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Tue, 19 Oct 2021 10:44:55 +0200 Subject: [PATCH 130/131] don't raise on error --- app/models/price_document.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/price_document.rb b/app/models/price_document.rb index a6b847b..125545e 100644 --- a/app/models/price_document.rb +++ b/app/models/price_document.rb @@ -721,7 +721,10 @@ class PriceDocument < ApplicationRecord p_fournisseur = PFournisseur.find_by(name: row["p_fournisseur_name"]) end - raise "Fournisseur introuvable. Ajouter le fournisseur manquant avant l'import" if p_fournisseur.nil? + if p_fournisseur.nil? + # TODO : envoyer une alerte sans bloquer l'import. + # idée ? creer une priceline vide => pour la retrouver dans les ref à matcher. + end n = self.find_or_initialize_by(price_document_type: PriceDocumentType.find_by_label("Catalogue fournisseur"), p_fournisseur: p_fournisseur, date: row["date"], p_devise: p_devise ) if n.price_line_block.nil? @@ -753,7 +756,7 @@ class PriceDocument < ApplicationRecord n.price_line_block.price_lines << price_line - n.save! + n.save import_csv.import_csv_elements << ImportCsvElement.new(:element => n) import_csv.import_csv_elements << ImportCsvElement.new(:element => price_line) end From 761a36693e4eedc27086055c2c060fa9a6871a0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Tue, 19 Oct 2021 10:51:31 +0200 Subject: [PATCH 131/131] remove bottom space --- app/views/admin/import_csvs/_form_temp_p_product.html.haml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/admin/import_csvs/_form_temp_p_product.html.haml b/app/views/admin/import_csvs/_form_temp_p_product.html.haml index f2c41fa..c27d130 100644 --- a/app/views/admin/import_csvs/_form_temp_p_product.html.haml +++ b/app/views/admin/import_csvs/_form_temp_p_product.html.haml @@ -10,16 +10,16 @@ %ul.list-group.list-group-flush %li.list-group-item .d-inline-flex - %h5.card-title{style: "min-width: 80px;"} libellé : + %h5{style: "min-width: 80px;"} libellé : %p.card-text=@p_product_ref.description %li.list-group-item .d-inline-flex - %h5.card-title{style: "min-width: 80px;"} Qté : + %h5{style: "min-width: 80px;"} Qté : %p.card-text =@price_line.qte %li.list-group-item .d-inline-flex - %h5.card-title{style: "min-width: 80px;"} Prix : + %h5{style: "min-width: 80px;"} Prix : %p.card-text =number_to_currency @p_product_ref.ct_price_ht