6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'app/jobs/solidus_invoice/daily_summary_job.rb', line 6
def perform(*args)
serials = Spree::InvoiceSerial.includes(:invoices).where(
doc_type: args[:doc_type],
store_id: args[:store_id]
)
lines = []
serials.each do
invoices = serials.invoices.where(communicated: false).order(doc_number: :asc)
line = SunatInvoice::SummaryLine.new(document_type: serial.doc_type,
document_serial: serial.serial,
start_document_number: invoice.first.doc_number,
end_document_number: invoice.last.doc_number,
total_amount: invoices.sum(:total),
taxable: invoice.sum(:taxable))
lines << line
end
client = SunatInvoice::InvoiceClient.new
summary = SunatInvoice::DailySummary.new(reference_date: Time.with_zone.yesterday,
lines: lines)
client.dispatch(summary)
end
|