export sage

This commit is contained in:
Nicolas Bally 2017-12-20 13:31:32 +01:00
parent de61331e22
commit 4a077a836b
7 changed files with 103 additions and 9 deletions

View File

@ -10,6 +10,72 @@ class Admin::ProductOrdersController < ApplicationController
def export2
@product_orders = ProductOrder.where(:completed_finish => true).order("created_at DESC")
respond_to do |format|
format.html
format.csv {
@file = ""
elements = {
"N°Pièce" => "product_order.bl_number",
"Date" => "product_order.created_at",
"Type document" => "product_order.sage_type_doc",
"Tiers" => "product_order.sage_tiers",
"Référence article" => "sage_reference",
"Quantité" => "qty",
"Type prix" => "product_order.sage_type_prix",
"Prix unitaire" => "archived_product.price_ht",
}
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|
product_order.product_order_products.each do |product_order_product|
csv << attributes.map{ |attr| eval("product_order_product."+attr.to_s) }
end
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 export def export
@product_orders = ProductOrder.where(:completed_finish => true).order("created_at DESC") @product_orders = ProductOrder.where(:completed_finish => true).order("created_at DESC")
@ -33,7 +99,7 @@ class Admin::ProductOrdersController < ApplicationController
"created_at" => "created_at", "created_at" => "created_at",
"fact_organisation" => "particular_bill.firstname", "fact_organisation" => "particular_bill.organisation",
"fact_prenom" => "particular_bill.firstname", "fact_prenom" => "particular_bill.firstname",
"fact_nom" => "particular_bill.name", "fact_nom" => "particular_bill.name",
"fact_adresse" => "particular_bill.address_2", "fact_adresse" => "particular_bill.address_2",
@ -43,7 +109,7 @@ class Admin::ProductOrdersController < ApplicationController
"fact_pays" => "particular_bill.country", "fact_pays" => "particular_bill.country",
"fact_tel" => "particular_bill.tel", "fact_tel" => "particular_bill.tel",
"livr_organisation" => "particular_send.firstname", "livr_organisation" => "particular_send.organisation",
"livr_prenom" => "particular_send.firstname", "livr_prenom" => "particular_send.firstname",
"livr_nom" => "particular_send.name", "livr_nom" => "particular_send.name",
"livr_adresse" => "particular_send.address_2", "livr_adresse" => "particular_send.address_2",

View File

@ -31,6 +31,18 @@ class ProductOrder < ActiveRecord::Base
attr_accessor :force_fdp_validation, :force_payment, :force_cgv_validation attr_accessor :force_fdp_validation, :force_payment, :force_cgv_validation
def sage_tiers
"tiers"
end
def sage_type_prix
0
end
def sage_type_doc
1
end
def prodons_country def prodons_country
countr = particular_bill.country countr = particular_bill.country

View File

@ -11,6 +11,12 @@ class ProductOrderProduct < ActiveRecord::Base
belongs_to :archived_product_size, class_name: "ProductSize" belongs_to :archived_product_size, class_name: "ProductSize"
belongs_to :archived_product_option, class_name: "ProductOption" belongs_to :archived_product_option, class_name: "ProductOption"
def sage_reference
if self.product
self.product.sage_reference
end
end
def tva def tva
20.0 20.0
end end

View File

@ -36,6 +36,7 @@
%h3 Tailles possibles : %h3 Tailles possibles :
=form.input :product_sizes, :collection => ProductSize.where("archived is null").order(:position).all, :as => :check_boxes, :label => "Tailles" =form.input :product_sizes, :collection => ProductSize.where("archived is null").order(:position).all, :as => :check_boxes, :label => "Tailles"
=form.input :sage_reference, :label => "Référence sage :"
.actions .actions

View File

@ -313,6 +313,7 @@ Rails.application.routes.draw do
resources :product_orders do resources :product_orders do
collection do collection do
get :export get :export
get :export2
end end
member do member do
get :ship get :ship

View File

@ -0,0 +1,6 @@
class AddSageToProducts < ActiveRecord::Migration
def change
add_column :products, :sage_reference, :string
add_column :products, :sage_tiers, :string
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20171022211011) do ActiveRecord::Schema.define(version: 20171220122439) do
create_table "accepted_offers", force: :cascade do |t| create_table "accepted_offers", force: :cascade do |t|
t.datetime "created_at", null: false t.datetime "created_at", null: false
@ -888,6 +888,8 @@ ActiveRecord::Schema.define(version: 20171022211011) do
t.integer "product_collection_id", limit: 4 t.integer "product_collection_id", limit: 4
t.boolean "archived", limit: 1, default: false t.boolean "archived", limit: 1, default: false
t.integer "reseaux_id", limit: 4 t.integer "reseaux_id", limit: 4
t.string "sage_reference", limit: 255
t.string "sage_tiers", limit: 255
end end
add_index "products", ["product_category_id"], name: "index_products_on_product_category_id", using: :btree add_index "products", ["product_category_id"], name: "index_products_on_product_category_id", using: :btree