diff --git a/app/controllers/admin/p_product_stocks_controller.rb b/app/controllers/admin/p_product_stocks_controller.rb index d711951..80c807a 100644 --- a/app/controllers/admin/p_product_stocks_controller.rb +++ b/app/controllers/admin/p_product_stocks_controller.rb @@ -6,6 +6,76 @@ class Admin::PProductStocksController < ApplicationController before_filter :admin_space + def export + @p_products = PProduct.where(:archived => false, :enabled => true).all + + @file = "" + + @headers = [ + "ID Sys", + "Ref produit", + "Nom", + "Ref variante", + "Taille", + "Couleur", + "Stock Physique", + "Stock théorique (prenant en compte les commandes en cours)" + + ] + + @csv = CSV.generate(:headers => true, :col_sep => ";") do |csv| + csv << @headers + + @p_products.each do |p_product| + p_product.p_product_stocks.each do |pps| + line = [] + + line << p_product.id + line << p_product.code + line << p_product.name + + line << pps.code + line << (pps.p_color ? pps.p_color.name : "") + line << (pps.p_size ? pps.p_size.name : "") + + line << pps.stock_ok + + line << pps.stock_th_ok + + csv << line + + end + + end + + end + + + @data_to_send = @csv.encode('iso-8859-1', :undef => :replace, :replace => '') + + file_path = Rails.root.join("pdf", "export.csv") + + File.open(file_path, "w+") do |f| + f.write(@data_to_send) + end + + respond_to do |format| + format.html{ + require 'csv' + + csv_text = File.read(file_path).encode('utf-8') + @csv = CSV.parse(csv_text, :headers => true, :col_sep => ";") + } + format.csv { + send_file file_path, :filename => "etat-stocks.csv", :type => 'text/csv; charset=iso-8859-1; header=present' + + } + end + + + + + end def import if true diff --git a/app/controllers/admin/p_products_controller.rb b/app/controllers/admin/p_products_controller.rb index f8bcccc..5ab3c87 100644 --- a/app/controllers/admin/p_products_controller.rb +++ b/app/controllers/admin/p_products_controller.rb @@ -10,6 +10,161 @@ class Admin::PProductsController < ApplicationController @admin_space = "ventes" end + def export + @p_products = PProduct.where(:archived => false, :enabled => true).all + + @file = "" + + @headers = [ + "ID Sys", + "Ref produit", + "Catégorie", + "Nom", + "Description", + "Grammage", + "Origine", + "Certifications", + "Qté/cartons", + "Ref variante", + "Taille", + "Couleur" + + ] + + @csv = CSV.generate(:headers => true, :col_sep => ";") do |csv| + csv << @headers + + @p_products.each do |p_product| + p_product.p_product_stocks.each do |pps| + line = [] + + line << p_product.id + line << p_product.code + line << (p_product.p_product_cat ? p_product.p_product_cat.name : "") + line << p_product.name + line << p_product.description + if p_product.p_ep + line << p_product.p_ep.ep + else + line << "" + end + if p_product.p_origine + line << p_product.p_origine.name + else + line << "" + end + line << p_product.p_certifs.all.map{|pc| pc.name}.join(",") + line << p_product.p_qtes.all.map{|pq| pq.qte}.join(",") + line << pps.code + line << (pps.p_color ? pps.p_color.name : "") + line << (pps.p_size ? pps.p_size.name : "") + + csv << line + + end + + end + + end + + + @data_to_send = @csv.encode('iso-8859-1', :undef => :replace, :replace => '') + + file_path = Rails.root.join("pdf", "export.csv") + + File.open(file_path, "w+") do |f| + f.write(@data_to_send) + end + + respond_to do |format| + format.html{ + require 'csv' + + csv_text = File.read(file_path).encode('utf-8') + @csv = CSV.parse(csv_text, :headers => true, :col_sep => ";") + } + format.csv { + send_file file_path, :filename => "export-produits.csv", :type => 'text/csv; charset=iso-8859-1; header=present' + + } + end + + + + + end + + def export_prix + @p_products = PProduct.where(:archived => false, :enabled => true).all + + @file = "" + + @headers = [ + "ID Sys", + "Ref produit", + "Nom", + "Ref variante", + "Qte min.", + "Prix U HT" + + ] + + @csv = CSV.generate(:headers => true, :col_sep => ";") do |csv| + csv << @headers + + @p_products.each do |p_product| + p_product.p_product_stocks.each do |pps| + line = [] + + line << p_product.id + line << p_product.code + + line << pps.code + line << 500 + + p_price_cat = PPriceCat.where(:name => "R0").first + + p_degressifs = p_product.p_degressifs.joins(:p_price_cats).where(:p_price_cats => {:id => p_price_cat.id}).order("nbr ASC") + + p_degressif = p_degressifs.first + + line << ((p_degressif and p_degressif.price.to_f > 0.0) ? p_degressif.price : "") + + csv << line + + end + + end + + end + + + @data_to_send = @csv.encode('iso-8859-1', :undef => :replace, :replace => '') + + file_path = Rails.root.join("pdf", "export.csv") + + File.open(file_path, "w+") do |f| + f.write(@data_to_send) + end + + respond_to do |format| + format.html{ + require 'csv' + + csv_text = File.read(file_path).encode('utf-8') + @csv = CSV.parse(csv_text, :headers => true, :col_sep => ";") + } + format.csv { + send_file file_path, :filename => "export-prix.csv", :type => 'text/csv; charset=iso-8859-1; header=present' + + } + end + + + + + end + def index @p_products = PProduct.joins(:p_product_cat).order("p_product_cats.name ASC, p_products.name ASC").all diff --git a/app/views/admin/admin_spaces/_stocks.html.haml b/app/views/admin/admin_spaces/_stocks.html.haml index bbefbc7..e56fa18 100644 --- a/app/views/admin/admin_spaces/_stocks.html.haml +++ b/app/views/admin/admin_spaces/_stocks.html.haml @@ -1,8 +1,8 @@ %li= link_to "Commandes fournisseurs", admin_p_fournisseur_orders_path - -%li= link_to "Cuves", admin_p_tanks_path -%li= link_to "Fournisseurs", admin_p_fournisseurs_path -%li= link_to "Facture transport", admin_p_ship_bills_path +-if false + %li= link_to "Cuves", admin_p_tanks_path + %li= link_to "Fournisseurs", admin_p_fournisseurs_path + %li= link_to "Facture transport", admin_p_ship_bills_path =#%li= link_to "Fichiers", admin_data_files_path \ No newline at end of file diff --git a/app/views/admin/p_documents/_form.html.haml b/app/views/admin/p_documents/_form.html.haml index b400162..4e821c4 100755 --- a/app/views/admin/p_documents/_form.html.haml +++ b/app/views/admin/p_documents/_form.html.haml @@ -146,6 +146,26 @@ $(".p_sheet_lines_tot_ttc").html(accounting.formatMoney(tot_sheet_fdp*tva)) #alert(tot_sheet) + @udpate_sheet_lines = -> + $(".p_sheet_line_field").each -> + price = parseFloat($(this).find(".price").find("input").val()) + price_tot = 0 + qte_tot = 0 + $(this).find(".color_line").each -> + qte = 0 + $(this).find("input.qte").each -> + qte += parseFloat($(this).val()) if parseFloat($(this).val()) + price_color = qte * price + $(this).find(".price_color_tot").html(accounting.formatMoney(price_color)) + $(this).find(".qte_color_tot").html(qte) + + + qte_tot += qte + + $(this).find(".qte_tot").html(qte_tot) + $(this).find(".price_tot").html(accounting.formatMoney(qte_tot*price)) + $(this).find(".price_tot").attr("data-price",qte_tot*price) + $(this).find(".price_tot").data("price",qte_tot*price) :coffeescript diff --git a/app/views/admin/p_product_stocks/export.html.haml b/app/views/admin/p_product_stocks/export.html.haml new file mode 100644 index 0000000..81b1e02 --- /dev/null +++ b/app/views/admin/p_product_stocks/export.html.haml @@ -0,0 +1,16 @@ + + + +.qi_row + .qi_pannel.qi_plain.padding + =link_to "Técharger en CSV", params.merge(:format => :csv) + + %table.table + %tr + -@csv.headers.each do |h| + %td=h + + -@csv.each do |csv| + %tr + -csv.each do |t| + %td=t[1] \ No newline at end of file diff --git a/app/views/admin/p_product_stocks/index.html.haml b/app/views/admin/p_product_stocks/index.html.haml index 263c75e..fcecb01 100644 --- a/app/views/admin/p_product_stocks/index.html.haml +++ b/app/views/admin/p_product_stocks/index.html.haml @@ -8,6 +8,12 @@ .qi_row .qi_pannel.qi_plain.padding + =link_to "Export stocks", export_admin_p_product_stocks_path, :class => "btn btn-default" + + %br + %br + + %table.table %tr %th Code gén. diff --git a/app/views/admin/p_products/_index.html.haml b/app/views/admin/p_products/_index.html.haml index f99d037..babce40 100644 --- a/app/views/admin/p_products/_index.html.haml +++ b/app/views/admin/p_products/_index.html.haml @@ -1,3 +1,4 @@ + %table.table %tr %th Code diff --git a/app/views/admin/p_products/export.html.haml b/app/views/admin/p_products/export.html.haml new file mode 100644 index 0000000..81b1e02 --- /dev/null +++ b/app/views/admin/p_products/export.html.haml @@ -0,0 +1,16 @@ + + + +.qi_row + .qi_pannel.qi_plain.padding + =link_to "Técharger en CSV", params.merge(:format => :csv) + + %table.table + %tr + -@csv.headers.each do |h| + %td=h + + -@csv.each do |csv| + %tr + -csv.each do |t| + %td=t[1] \ No newline at end of file diff --git a/app/views/admin/p_products/export_prix.html.haml b/app/views/admin/p_products/export_prix.html.haml new file mode 100644 index 0000000..81b1e02 --- /dev/null +++ b/app/views/admin/p_products/export_prix.html.haml @@ -0,0 +1,16 @@ + + + +.qi_row + .qi_pannel.qi_plain.padding + =link_to "Técharger en CSV", params.merge(:format => :csv) + + %table.table + %tr + -@csv.headers.each do |h| + %td=h + + -@csv.each do |csv| + %tr + -csv.each do |t| + %td=t[1] \ No newline at end of file diff --git a/app/views/admin/p_products/index.html.haml b/app/views/admin/p_products/index.html.haml index af5693f..5363822 100644 --- a/app/views/admin/p_products/index.html.haml +++ b/app/views/admin/p_products/index.html.haml @@ -8,5 +8,13 @@ .qi_row .qi_pannel.qi_plain.padding + =link_to "Export liste produits avec vente en ligne", export_admin_p_products_path, :class => "btn btn-default" + =link_to "Export liste prix produits avec vente en ligne", export_prix_admin_p_products_path, :class => "btn btn-default" + + %br + %br + #p_product_index + + =render :partial => "index" \ No newline at end of file diff --git a/app/views/admin/p_sheet_lines/_avoir_form.html.haml b/app/views/admin/p_sheet_lines/_avoir_form.html.haml index e6fce14..b0fda8f 100755 --- a/app/views/admin/p_sheet_lines/_avoir_form.html.haml +++ b/app/views/admin/p_sheet_lines/_avoir_form.html.haml @@ -69,7 +69,7 @@ %td.qte_color_tot.price_td %td.price.price_td{:data => {:price => form.object.price}} - =number_to_currency form.object.price + =#number_to_currency form.object.price %td.price_color_tot.price_td -elsif form.object.p_product @@ -106,8 +106,9 @@ %td.qte_tot.price_td{:style => "font-weight:bold;"} %strong=form.object.qte - %td.price.price_td{:style => "font-weight:bold;", :data => {:price => form.object.price}} - %strong=number_to_currency form.object.price + %td.price.price_td{:style => "font-weight:bold;text-align:right;", :data => {:price => form.object.price}} + =form.input :ok_price, :label => false, :input_html => {:style => "display:inline-block;text-align:right"} + =#%strong=number_to_currency form.object.price %td.price_tot.price_td{:style => "font-weight:bold;"} diff --git a/config/routes.rb b/config/routes.rb index fdb2564..acf057b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -132,6 +132,7 @@ Rails.application.routes.draw do namespace :admin do resources :p_product_stocks do collection do + get :export get :import get :import_prix end @@ -162,7 +163,10 @@ Rails.application.routes.draw do resources :p_products do + collection do + get :export + get :export_prix get :autocomplete post :reorder end