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