export commandes
This commit is contained in:
parent
af58cee288
commit
95c4f98feb
@ -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
|
||||
@product_order = ProductOrder.find(params[:id])
|
||||
@product_order.after_ship
|
||||
|
@ -111,7 +111,16 @@ class ProductOrder < ActiveRecord::Base
|
||||
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
|
||||
archived_total_ht + archived_total_tva
|
||||
|
@ -311,6 +311,9 @@ Rails.application.routes.draw do
|
||||
|
||||
resources :product_order_payments
|
||||
resources :product_orders do
|
||||
collection do
|
||||
get :export
|
||||
end
|
||||
member do
|
||||
get :ship
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user