Compare commits
No commits in common. "928a02ed3f71f7745e731c939a6a79bb9eb7cd54" and "fb8ccfea4a16c118deadfb8bdc0b22600b1ec859" have entirely different histories.
928a02ed3f
...
fb8ccfea4a
13 changed files with 17 additions and 111 deletions
|
@ -49,7 +49,7 @@ class OrdersController < ApplicationController
|
||||||
send_order_pdf @order, params[:document]
|
send_order_pdf @order, params[:document]
|
||||||
end
|
end
|
||||||
format.csv do
|
format.csv do
|
||||||
send_data OrderCsv.new(@order, options= {custom_csv: params[:custom_csv]}).to_csv, filename: @order.name + '.csv', type: 'text/csv'
|
send_data OrderCsv.new(@order).to_csv, filename: @order.name + '.csv', type: 'text/csv'
|
||||||
end
|
end
|
||||||
format.text do
|
format.text do
|
||||||
send_data OrderTxt.new(@order).to_txt, filename: @order.name + '.txt', type: 'text/plain'
|
send_data OrderTxt.new(@order).to_txt, filename: @order.name + '.txt', type: 'text/plain'
|
||||||
|
@ -57,19 +57,6 @@ class OrdersController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def custom_csv
|
|
||||||
@order = Order.find(params[:id])
|
|
||||||
@view = (params[:view] || 'default').gsub(/[^-_a-zA-Z0-9]/, '')
|
|
||||||
@partial = case @view
|
|
||||||
when 'default' then 'articles'
|
|
||||||
when 'groups' then 'shared/articles_by/groups'
|
|
||||||
when 'articles' then 'shared/articles_by/articles'
|
|
||||||
else 'articles'
|
|
||||||
end
|
|
||||||
|
|
||||||
render :layout => false
|
|
||||||
end
|
|
||||||
|
|
||||||
# Page to create a new order.
|
# Page to create a new order.
|
||||||
def new
|
def new
|
||||||
if params[:order_id]
|
if params[:order_id]
|
||||||
|
|
|
@ -155,16 +155,4 @@ module OrdersHelper
|
||||||
link_to t('orders.index.action_receive'), receive_order_path(order), class: "btn#{' btn-success' unless order.received?} #{options[:class]}"
|
link_to t('orders.index.action_receive'), receive_order_path(order), class: "btn#{' btn-success' unless order.received?} #{options[:class]}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def custom_csv_collection
|
|
||||||
[
|
|
||||||
OrderArticle.human_attribute_name(:units_to_order),
|
|
||||||
Article.human_attribute_name(:order_number),
|
|
||||||
Article.human_attribute_name(:name),
|
|
||||||
Article.human_attribute_name(:unit),
|
|
||||||
Article.human_attribute_name(:unit_quantity_short),
|
|
||||||
ArticlePrice.human_attribute_name(:price),
|
|
||||||
OrderArticle.human_attribute_name(:total_price)
|
|
||||||
]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,60 +2,28 @@ require 'csv'
|
||||||
|
|
||||||
class OrderCsv < RenderCsv
|
class OrderCsv < RenderCsv
|
||||||
def header
|
def header
|
||||||
params = @options[:custom_csv]
|
[
|
||||||
arr = if params.nil?
|
OrderArticle.human_attribute_name(:units_to_order),
|
||||||
[
|
Article.human_attribute_name(:order_number),
|
||||||
OrderArticle.human_attribute_name(:units_to_order),
|
Article.human_attribute_name(:name),
|
||||||
Article.human_attribute_name(:order_number),
|
Article.human_attribute_name(:unit),
|
||||||
Article.human_attribute_name(:name),
|
Article.human_attribute_name(:unit_quantity_short),
|
||||||
Article.human_attribute_name(:unit),
|
ArticlePrice.human_attribute_name(:price),
|
||||||
Article.human_attribute_name(:unit_quantity_short),
|
OrderArticle.human_attribute_name(:total_price)
|
||||||
ArticlePrice.human_attribute_name(:price),
|
]
|
||||||
OrderArticle.human_attribute_name(:total_price)
|
|
||||||
]
|
|
||||||
else
|
|
||||||
[
|
|
||||||
params[:first],
|
|
||||||
params[:second],
|
|
||||||
params[:third],
|
|
||||||
params[:fourth],
|
|
||||||
params[:fifth],
|
|
||||||
params[:sixth],
|
|
||||||
params[:seventh]
|
|
||||||
]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def data
|
def data
|
||||||
@object.order_articles.ordered.includes([:article, :article_price]).all.map do |oa|
|
@object.order_articles.ordered.includes([:article, :article_price]).all.map do |oa|
|
||||||
yield [
|
yield [
|
||||||
match_params(oa, header[0]),
|
oa.units_to_order,
|
||||||
match_params(oa, header[1]),
|
oa.article.order_number,
|
||||||
match_params(oa, header[2]),
|
oa.article.name,
|
||||||
match_params(oa, header[3]),
|
oa.article.unit,
|
||||||
match_params(oa, header[4]),
|
oa.price.unit_quantity > 1 ? oa.price.unit_quantity : nil,
|
||||||
match_params(oa, header[5]),
|
number_to_currency(oa.price.price * oa.price.unit_quantity),
|
||||||
match_params(oa, header[6])
|
number_to_currency(oa.total_price)
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def match_params(object, attribute)
|
|
||||||
case attribute
|
|
||||||
when OrderArticle.human_attribute_name(:units_to_order)
|
|
||||||
object.units_to_order
|
|
||||||
when Article.human_attribute_name(:order_number)
|
|
||||||
object.article.order_number
|
|
||||||
when Article.human_attribute_name(:name)
|
|
||||||
object.article.name
|
|
||||||
when Article.human_attribute_name(:unit)
|
|
||||||
object.article.unit
|
|
||||||
when Article.human_attribute_name(:unit_quantity_short)
|
|
||||||
object.price.unit_quantity > 1 ? object.price.unit_quantity : nil
|
|
||||||
when ArticlePrice.human_attribute_name(:price)
|
|
||||||
number_to_currency(object.price.price * object.price.unit_quantity)
|
|
||||||
when OrderArticle.human_attribute_name(:total_price)
|
|
||||||
number_to_currency(object.total_price)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,7 +20,6 @@ class RenderCsv
|
||||||
end
|
end
|
||||||
data { |d| csv << d }
|
data { |d| csv << d }
|
||||||
end
|
end
|
||||||
ret << I18n.t('.orders.articles.prices_sum') << ";" << "#{number_to_currency(@object.sum(:gross))}/#{number_to_currency(@object.sum(:net))}" if @options[:custom_csv]
|
|
||||||
ret.encode(@options[:encoding], invalid: :replace, undef: :replace)
|
ret.encode(@options[:encoding], invalid: :replace, undef: :replace)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
= simple_form_for :custom_csv,format: :csv, :url => order_path(@order, view: @view, format: :csv), method: :get do |f|
|
|
||||||
.modal-header
|
|
||||||
= close_button :modal
|
|
||||||
.h3=I18n.t('.orders.custom_csv.description')
|
|
||||||
.modal-body
|
|
||||||
= f.input :first, as: :select, collection: custom_csv_collection, label: "1. " + I18n.t('.orders.custom_csv.column')
|
|
||||||
= f.input :second, as: :select, collection: custom_csv_collection, required: false, label: "2. " + I18n.t('.orders.custom_csv.column')
|
|
||||||
= f.input :third, as: :select, collection: custom_csv_collection, required: false, label: "3. " + I18n.t('.orders.custom_csv.column')
|
|
||||||
= f.input :fourth, as: :select, collection: custom_csv_collection, required: false, label: "4. " + I18n.t('.orders.custom_csv.column')
|
|
||||||
= f.input :fifth, as: :select, collection: custom_csv_collection, required: false, label: "5. " + I18n.t('.orders.custom_csv.column')
|
|
||||||
= f.input :sixth, as: :select, collection: custom_csv_collection, required: false, label: "6. " + I18n.t('.orders.custom_csv.column')
|
|
||||||
= f.input :seventh, as: :select, collection: custom_csv_collection, required: false, label: "7. " + I18n.t('.orders.custom_csv.column')
|
|
||||||
.modal-footer
|
|
||||||
= link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'}
|
|
||||||
= f.submit class: 'btn btn-primary'
|
|
|
@ -1,3 +0,0 @@
|
||||||
$('#modalContainer').html('#{j(render("custom_csv_form"))}');
|
|
||||||
$('#modalContainer').modal();
|
|
||||||
$('#modalContainer').submit(function() {$('#modalContainer').modal('hide');});
|
|
|
@ -10,4 +10,3 @@
|
||||||
- unless order.stockit?
|
- unless order.stockit?
|
||||||
%li= link_to t('.fax_txt'), order_path(order, format: :txt), {title: t('.download_file')}
|
%li= link_to t('.fax_txt'), order_path(order, format: :txt), {title: t('.download_file')}
|
||||||
%li= link_to t('.fax_csv'), order_path(order, format: :csv), {title: t('.download_file')}
|
%li= link_to t('.fax_csv'), order_path(order, format: :csv), {title: t('.download_file')}
|
||||||
%li= link_to t('.custom_csv'), custom_csv_order_path(order), remote: true
|
|
||||||
|
|
|
@ -1463,9 +1463,6 @@ de:
|
||||||
units_ordered: Bestellte Einheiten
|
units_ordered: Bestellte Einheiten
|
||||||
create:
|
create:
|
||||||
notice: Die Bestellung wurde erstellt.
|
notice: Die Bestellung wurde erstellt.
|
||||||
custom_csv:
|
|
||||||
description: Wähle die Attribute und deren Reihenfolge für die zu erzeugende CSV Datei
|
|
||||||
column: Spalte
|
|
||||||
edit:
|
edit:
|
||||||
title: 'Bestellung bearbeiten: %{name}'
|
title: 'Bestellung bearbeiten: %{name}'
|
||||||
edit_amount:
|
edit_amount:
|
||||||
|
|
|
@ -1473,9 +1473,6 @@ en:
|
||||||
units_ordered: Units ordered
|
units_ordered: Units ordered
|
||||||
create:
|
create:
|
||||||
notice: The order was created.
|
notice: The order was created.
|
||||||
custom_csv:
|
|
||||||
description: Please choose the order as well as the attributes for the csv file
|
|
||||||
column: column
|
|
||||||
edit:
|
edit:
|
||||||
title: 'Edit order: %{name}'
|
title: 'Edit order: %{name}'
|
||||||
edit_amount:
|
edit_amount:
|
||||||
|
@ -1629,7 +1626,6 @@ en:
|
||||||
who_ordered: Who ordered?
|
who_ordered: Who ordered?
|
||||||
order_download_button:
|
order_download_button:
|
||||||
article_pdf: Article PDF
|
article_pdf: Article PDF
|
||||||
custom_csv: Custom CSV
|
|
||||||
download_file: Download file
|
download_file: Download file
|
||||||
fax_csv: Fax CSV
|
fax_csv: Fax CSV
|
||||||
fax_pdf: Fax PDF
|
fax_pdf: Fax PDF
|
||||||
|
|
|
@ -1259,9 +1259,6 @@ es:
|
||||||
units_ordered: Unidades pedidas
|
units_ordered: Unidades pedidas
|
||||||
create:
|
create:
|
||||||
notice: Se ha creado el pedido
|
notice: Se ha creado el pedido
|
||||||
custom_csv:
|
|
||||||
description: Por favor elija el orden de los atributos así como los atributos para el archivo csv
|
|
||||||
column: columna
|
|
||||||
edit:
|
edit:
|
||||||
title: 'Edita pedido: %{name}'
|
title: 'Edita pedido: %{name}'
|
||||||
edit_amount:
|
edit_amount:
|
||||||
|
|
|
@ -1010,9 +1010,6 @@ fr:
|
||||||
units_ordered: Unités commandées
|
units_ordered: Unités commandées
|
||||||
create:
|
create:
|
||||||
notice: La commande a bien été définie.
|
notice: La commande a bien été définie.
|
||||||
custom_csv:
|
|
||||||
description: Veuillez choisir l'ordre des attributs ainsi que les attributs pour le fichier csv
|
|
||||||
column: colonne
|
|
||||||
edit:
|
edit:
|
||||||
title: 'Modifier la commande: %{name}'
|
title: 'Modifier la commande: %{name}'
|
||||||
edit_amount:
|
edit_amount:
|
||||||
|
|
|
@ -1438,9 +1438,6 @@ nl:
|
||||||
units_ordered: Bestelde eenheden
|
units_ordered: Bestelde eenheden
|
||||||
create:
|
create:
|
||||||
notice: De bestelling is aangemaakt.
|
notice: De bestelling is aangemaakt.
|
||||||
custom_csv:
|
|
||||||
description: Kies de volgorde van de attributen en de attributen voor het csv-bestand
|
|
||||||
column: kolom
|
|
||||||
edit:
|
edit:
|
||||||
title: 'Bestelling aanpassen: %{name}'
|
title: 'Bestelling aanpassen: %{name}'
|
||||||
edit_amount:
|
edit_amount:
|
||||||
|
|
|
@ -47,7 +47,6 @@ Rails.application.routes.draw do
|
||||||
get :receive
|
get :receive
|
||||||
post :receive
|
post :receive
|
||||||
|
|
||||||
get :custom_csv
|
|
||||||
get :receive_on_order_article_create
|
get :receive_on_order_article_create
|
||||||
get :receive_on_order_article_update
|
get :receive_on_order_article_update
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue