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}