8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/egg_csa_invoice.rb', line 8
def egg_csa_invoice(opts = {}, &block)
invoice = FarmingEngineers::Invoices::Eggs::Invoice.new
invoice.instance_eval(&block)
history_table = Table(:date, :description, :quantity, :total, :balance) do |t|
balance = 0
invoice.history.each do |line|
balance += line.total
t << [line.date, line.description, line.quantity, d(line.total), d(balance)]
end
t << ['', '', '', opts[:total_label] || 'TOTAL', d(balance)]
end
history_table.rename_columns(
:date => 'Date',
:description => 'Description',
:quantity => 'Quantity',
:total => 'Total',
:balance => 'Balance'
)
invoice_id = opts[:id] || "#{Date.today.strftime('%Y%m%d')}-#{$invoice_count += 1}"
invoice_file = invoice_id + '.pdf'
puts invoice_file
Ruport::Controller::Invoice.render :pdf, :file => invoice_file do |i|
i.data = history_table
i.options do |o|
o.company_info = "the farming engineers\nPO Box 1031\nWestfield, IN 46074"
o.customer_info = "#{invoice.customer}\n#{invoice.address.join("\n")}"
o. = "#{invoice.notes}"
o.order_info = "Invoice #{invoice_id}"
o.title = "Egg delivery"
o.body_width = 480
o. = 12
o.title_font_size = 10
end
end
end
|