diff --git a/app/controllers/concerns/send_group_order_invoice_pdf.rb b/app/controllers/concerns/send_group_order_invoice_pdf.rb index 0e7ad08a..76e71c99 100644 --- a/app/controllers/concerns/send_group_order_invoice_pdf.rb +++ b/app/controllers/concerns/send_group_order_invoice_pdf.rb @@ -3,11 +3,15 @@ module Concerns::SendGroupOrderInvoicePdf 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[:title] = t('documents.group_order_invoice_pdf.title', supplier: invoice_data[:supplier]) 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' end end diff --git a/app/controllers/group_order_invoices_controller.rb b/app/controllers/group_order_invoices_controller.rb index 5fcca2d7..2e5a8408 100644 --- a/app/controllers/group_order_invoices_controller.rb +++ b/app/controllers/group_order_invoices_controller.rb @@ -56,4 +56,32 @@ class GroupOrderInvoicesController < ApplicationController rescue => error redirect_back fallback_location: root_path, notice: 'Something went wrong', :alert => I18n.t('errors.general_msg', :msg => error) 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 diff --git a/app/views/finance/balancing/index.html.haml b/app/views/finance/balancing/index.html.haml index 0cfeccbd..4a7fd119 100644 --- a/app/views/finance/balancing/index.html.haml +++ b/app/views/finance/balancing/index.html.haml @@ -1,5 +1,4 @@ - title t('.title') -- puts params - content_for :actionbar do - 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' diff --git a/app/views/group_order_invoices/_links.html.haml b/app/views/group_order_invoices/_links.html.haml index 34bd6271..9e55cedf 100644 --- a/app/views/group_order_invoices/_links.html.haml +++ b/app/views/group_order_invoices/_links.html.haml @@ -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 - 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 - +- 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' diff --git a/config/locales/de.yml b/config/locales/de.yml index 1ee73275..639bfbd3 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -98,7 +98,7 @@ de: generate: Rechnung erzeugen invoice_date: Datum der Bestellgruppenrechnung generate_with_date: setzen & erzeugen - + download_all_zip: Alle Rechnungen herunterladen (zip) payment_method: Guthaben tax_number_not_set: Steuernummer in den Einstellungen nicht gesetzt invoice: @@ -1964,3 +1964,4 @@ de: time: formats: foodsoft_datetime: "%d.%m.%Y %H:%M" + file: "%Y-%d-%B" \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 08d34061..1ee30987 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -98,6 +98,8 @@ en: invoice_date: date of group order invoice generate: generate invoice generate_with_date: set & generate + download_all_zip: download all invoices as zip + payment_method: Credit tax_number_not_set: Tax number not set in configs invoice: @@ -1986,3 +1988,4 @@ en: time: formats: foodsoft_datetime: "%Y-%m-%d %H:%M" + file: "%Y-%d-%B" diff --git a/config/routes.rb b/config/routes.rb index 527d6b40..de68ce73 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -145,6 +145,9 @@ Rails.application.routes.draw do 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 :article_categories