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
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue