downloadmultiple as zip
This commit is contained in:
parent
6058b2f239
commit
1933f21835
7 changed files with 47 additions and 5 deletions
|
@ -3,11 +3,15 @@ module Concerns::SendGroupOrderInvoicePdf
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def send_group_order_invoice_pdf(group_order_invoice)
|
def create_invoice_pdf(group_order_invoice)
|
||||||
invoice_data = group_order_invoice.load_data_for_invoice
|
invoice_data = group_order_invoice.load_data_for_invoice
|
||||||
invoice_data[:title] = t('documents.group_order_invoice_pdf.title', supplier: invoice_data[:supplier])
|
invoice_data[:title] = t('documents.group_order_invoice_pdf.title', supplier: invoice_data[:supplier])
|
||||||
invoice_data[:no_footer] = true
|
invoice_data[:no_footer] = true
|
||||||
pdf = GroupOrderInvoicePdf.new invoice_data
|
GroupOrderInvoicePdf.new invoice_data
|
||||||
|
end
|
||||||
|
|
||||||
|
def send_group_order_invoice_pdf(group_order_invoice)
|
||||||
|
pdf = create_invoice_pdf(group_order_invoice)
|
||||||
send_data pdf.to_pdf, filename: pdf.filename, type: 'application/pdf'
|
send_data pdf.to_pdf, filename: pdf.filename, type: 'application/pdf'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -56,4 +56,32 @@ class GroupOrderInvoicesController < ApplicationController
|
||||||
rescue => error
|
rescue => error
|
||||||
redirect_back fallback_location: root_path, notice: 'Something went wrong', :alert => I18n.t('errors.general_msg', :msg => error)
|
redirect_back fallback_location: root_path, notice: 'Something went wrong', :alert => I18n.t('errors.general_msg', :msg => error)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def download_all
|
||||||
|
order = Order.find(params[:order_id])
|
||||||
|
|
||||||
|
invoices = order.group_orders.map(&:group_order_invoice)
|
||||||
|
pdf = {}
|
||||||
|
|
||||||
|
temp_file = Tempfile.new("all_invoices_for_order_#{order.id}.zip")
|
||||||
|
|
||||||
|
Zip::File.open(temp_file.path, Zip::File::CREATE) do |zipfile|
|
||||||
|
invoices.each do |invoice|
|
||||||
|
pdf = create_invoice_pdf(invoice)
|
||||||
|
invoice_file = Tempfile.new("#{pdf.filename}")
|
||||||
|
File.open(invoice_file.path, 'w:ASCII-8BIT') do |file|
|
||||||
|
file.write(pdf.to_pdf)
|
||||||
|
end
|
||||||
|
zipfile.add("#{pdf.filename}", invoice_file.path) unless zipfile.find_entry("#{pdf.filename}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
zip_data = File.read(temp_file.path)
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html {
|
||||||
|
send_data(zip_data, type: 'application/zip', filename: "#{l order.ends, format: :file}-#{order.supplier.name}-#{order.id}.zip", disposition: 'attachment')
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
- title t('.title')
|
- title t('.title')
|
||||||
- puts params
|
|
||||||
- content_for :actionbar do
|
- content_for :actionbar do
|
||||||
- if FoodsoftConfig[:charge_members_manually]
|
- if FoodsoftConfig[:charge_members_manually]
|
||||||
= link_to t('.close_all_direct_with_invoice'), close_all_direct_with_invoice_finance_order_index_path, method: :post, class: 'btn'
|
= link_to t('.close_all_direct_with_invoice'), close_all_direct_with_invoice_finance_order_index_path, method: :post, class: 'btn'
|
||||||
|
|
|
@ -22,4 +22,8 @@
|
||||||
= link_to I18n.t('activerecord.attributes.group_order_invoice.links.delete'), go.group_order_invoice, method: :delete, class: 'btn btn-danger btn-small', remote: true
|
= link_to I18n.t('activerecord.attributes.group_order_invoice.links.delete'), go.group_order_invoice, method: :delete, class: 'btn btn-danger btn-small', remote: true
|
||||||
- else
|
- else
|
||||||
= button_to I18n.t('activerecord.attributes.group_order_invoice.links.generate'), group_order_invoices_path(:method => :post, group_order: go) ,class: 'btn btn-small', params: {id: order.id}, remote: true
|
= button_to I18n.t('activerecord.attributes.group_order_invoice.links.generate'), group_order_invoices_path(:method => :post, group_order: go) ,class: 'btn btn-small', params: {id: order.id}, remote: true
|
||||||
|
- if order.group_orders.map(&:group_order_invoice).compact.present?
|
||||||
|
%br/
|
||||||
|
.row
|
||||||
|
.column.small-3
|
||||||
|
= link_to I18n.t('activerecord.attributes.group_order_invoice.links.download_all_zip'), download_all_group_order_invoices_path(order), class: 'btn btn-small'
|
||||||
|
|
|
@ -98,7 +98,7 @@ de:
|
||||||
generate: Rechnung erzeugen
|
generate: Rechnung erzeugen
|
||||||
invoice_date: Datum der Bestellgruppenrechnung
|
invoice_date: Datum der Bestellgruppenrechnung
|
||||||
generate_with_date: setzen & erzeugen
|
generate_with_date: setzen & erzeugen
|
||||||
|
download_all_zip: Alle Rechnungen herunterladen (zip)
|
||||||
payment_method: Guthaben
|
payment_method: Guthaben
|
||||||
tax_number_not_set: Steuernummer in den Einstellungen nicht gesetzt
|
tax_number_not_set: Steuernummer in den Einstellungen nicht gesetzt
|
||||||
invoice:
|
invoice:
|
||||||
|
@ -1964,3 +1964,4 @@ de:
|
||||||
time:
|
time:
|
||||||
formats:
|
formats:
|
||||||
foodsoft_datetime: "%d.%m.%Y %H:%M"
|
foodsoft_datetime: "%d.%m.%Y %H:%M"
|
||||||
|
file: "%Y-%d-%B"
|
|
@ -98,6 +98,8 @@ en:
|
||||||
invoice_date: date of group order invoice
|
invoice_date: date of group order invoice
|
||||||
generate: generate invoice
|
generate: generate invoice
|
||||||
generate_with_date: set & generate
|
generate_with_date: set & generate
|
||||||
|
download_all_zip: download all invoices as zip
|
||||||
|
|
||||||
payment_method: Credit
|
payment_method: Credit
|
||||||
tax_number_not_set: Tax number not set in configs
|
tax_number_not_set: Tax number not set in configs
|
||||||
invoice:
|
invoice:
|
||||||
|
@ -1986,3 +1988,4 @@ en:
|
||||||
time:
|
time:
|
||||||
formats:
|
formats:
|
||||||
foodsoft_datetime: "%Y-%m-%d %H:%M"
|
foodsoft_datetime: "%Y-%m-%d %H:%M"
|
||||||
|
file: "%Y-%d-%B"
|
||||||
|
|
|
@ -145,6 +145,9 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
|
|
||||||
post 'finance/group_order_invoice', to: 'group_order_invoices#create_multiple'
|
post 'finance/group_order_invoice', to: 'group_order_invoices#create_multiple'
|
||||||
|
|
||||||
|
get 'orders/:order_id/group_order_invoices/download_all', to: 'group_order_invoices#download_all', as: 'download_all_group_order_invoices'
|
||||||
|
|
||||||
resources :group_order_invoices
|
resources :group_order_invoices
|
||||||
|
|
||||||
resources :article_categories
|
resources :article_categories
|
||||||
|
|
Loading…
Reference in a new issue