WIP export excel p_customer_sheets
This commit is contained in:
parent
39fe54bdad
commit
a96ab1e4b6
@ -280,6 +280,85 @@ class Admin::PCustomerSheetsController < ApplicationController
|
|||||||
|
|
||||||
end
|
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
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
.qi_header
|
.qi_header
|
||||||
.right
|
.right
|
||||||
=link_to ic(:plus)+" Demande de commande", admin_p_customers_path(:offre => true), :class => "btn btn-primary btn-ap-add"
|
=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
|
%h1
|
||||||
Ventes
|
Ventes
|
||||||
%span
|
%span
|
||||||
|
@ -1053,6 +1053,7 @@ Rails.application.routes.draw do
|
|||||||
collection do
|
collection do
|
||||||
get :affects
|
get :affects
|
||||||
get :update_stocks
|
get :update_stocks
|
||||||
|
get :export_xls
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user