Class: Dolibarr::Payments
Overview
Payments recorded against customer invoices.
Dolibarr's per-invoice payment endpoint settles the full remaining amount (there
is no partial-amount field) and can close the invoice in the same call via
closepaidinvoices. #register exposes exactly that: pay and close in one shot.
Instance Method Summary collapse
-
#for_invoice(invoice_id:) ⇒ Array<Payment>
The payments already recorded on an invoice.
-
#register(invoice_id:, account_id:, payment_mode_id:, date: Date.today, close: true, number: nil, comment: nil) ⇒ Integer
Record a payment on an invoice, settling its remaining balance, and (by default) close it.
Methods inherited from Resource
Constructor Details
This class inherits a constructor from Dolibarr::Resource
Instance Method Details
#for_invoice(invoice_id:) ⇒ Array<Payment>
The payments already recorded on an invoice.
16 17 18 |
# File 'lib/dolibarr/payments.rb', line 16 def for_invoice(invoice_id:) get_list("/invoices/#{encode(invoice_id)}/payments").map { |raw| Payment.from(raw) } end |
#register(invoice_id:, account_id:, payment_mode_id:, date: Date.today, close: true, number: nil, comment: nil) ⇒ Integer
Record a payment on an invoice, settling its remaining balance, and (by default) close it.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/dolibarr/payments.rb', line 31 def register(invoice_id:, account_id:, payment_mode_id:, date: Date.today, close: true, number: nil, comment: nil) body = { 'accountid' => account_id, 'paymentid' => payment_mode_id, 'datepaye' => iso_date(date), 'closepaidinvoices' => close ? 'yes' : 'no', 'num_payment' => number, 'comment' => comment, }.compact call do connection.call( :POST, "/invoices/#{encode(invoice_id)}/payments", type: nil, auth: ['api_key'], body: body ).data end end |