export commandes

This commit is contained in:
Nicolas Bally 2017-11-24 10:03:16 +01:00
parent af58cee288
commit 95c4f98feb
3 changed files with 107 additions and 1 deletions

View File

@ -10,6 +10,100 @@ class Admin::ProductOrdersController < ApplicationController
def export
@product_orders = ProductOrder.where(:completed_finish => true).order("created_at DESC")
respond_to do |format|
format.html
format.csv {
@file = ""
elements = {
"token" => "token",
"bl_number" => "bl_number",
"bl_index" => "bl_index",
"bl_year" => "bl_year",
"created_at" => "created_at",
"fact_organisation" => "particular_bill.firstname",
"fact_prenom" => "particular_bill.firstname",
"fact_nom" => "particular_bill.name",
"fact_adresse" => "particular_bill.address_2",
"fact_adresse suite" => "particular_bill.address_3",
"fact_cp" => "particular_bill.cp",
"fact_ville" => "particular_bill.city",
"fact_pays" => "particular_bill.country",
"fact_tel" => "particular_bill.tel",
"livr_organisation" => "particular_send.firstname",
"livr_prenom" => "particular_send.firstname",
"livr_nom" => "particular_send.name",
"livr_adresse" => "particular_send.address_2",
"livr_adresse suite" => "particular_send.address_3",
"livr_cp" => "particular_send.cp",
"livr_ville" => "particular_send.city",
"livr_pays" => "particular_send.country",
"livr_tel" => "particular_send.tel",
"total HT" => "exp_archived_total_ht",
"total TVA" => "exp_archived_total_tva",
"total TTC" => "exp_archived_total_ttc",
}
headers = []
attributes = []
elements.each do |key, value|
headers << key
attributes << value
end
@csv = CSV.generate(:headers => true, :col_sep => ";") do |csv|
csv << headers
@product_orders.all.each do |product_order|
csv << attributes.map{ |attr| eval("product_order."+attr.to_s) }
end
end
send_data @csv.encode('iso-8859-1', :undef => :replace, :replace => ''), :filename => "export-#{Date.today.to_s.to_slug}.csv", :type => 'text/csv; charset=iso-8859-1; header=present' }
end
end
def ship def ship
@product_order = ProductOrder.find(params[:id]) @product_order = ProductOrder.find(params[:id])
@product_order.after_ship @product_order.after_ship

View File

@ -111,7 +111,16 @@ class ProductOrder < ActiveRecord::Base
end end
def exp_archived_total_ttc
archived_total_ttc.round(2)
end
def exp_archived_total_tva
archived_total_tva.round(2)
end
def exp_archived_total_ht
archived_total_ht.round(2)
end
def archived_total_ttc def archived_total_ttc
archived_total_ht + archived_total_tva archived_total_ht + archived_total_tva

View File

@ -311,6 +311,9 @@ Rails.application.routes.draw do
resources :product_order_payments resources :product_order_payments
resources :product_orders do resources :product_orders do
collection do
get :export
end
member do member do
get :ship get :ship