8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'app/workers/invoice_fund_auto_capture_worker.rb', line 8
def perform
@invoices = Invoice.unpaid
.included_in_notifications
.joins(order: :payments)
.where(orders: { state: 'invoiced' })
.where(payments: { category: ['Bread', 'Credit Card', 'PayPal'] })
.where(invoices: { terms: 'Due' })
.joins("LEFT JOIN receipt_details on receipt_details.invoice_id = invoices.id and receipt_details.state != 'void'")
.where.not(payments: { state: 'captured' })
.group('invoices.id')
.having('invoices.total > coalesce(sum(receipt_details.amount + receipt_details.write_off + receipt_details.discount),0)')
@invoices.each do |invoice|
invoice.capture_funds?
logger.info "invoicing capture finished for invoice id: #{invoice.id}"
end
end
|