mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-18 02:20:37 -05:00
Add a customer payments page
Payments on the customer page lists the customer's QuickBooks payments, newest first, with the invoices each was applied to, memo, amount, unapplied credit and totals; each links to the payment page and its PDF. A new View payments permission allows the list, payment page and PDF; Receive payments includes it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
10 files changed
+133
-7
No files matched your search
@@ -105,6 +105,20 @@ module RedmineQboBilling
|
||||
saved
|
||||
end
|
||||
|
||||
# Every payment the customer has made, newest first (by date, then QuickBooks id), read from QuickBooks
|
||||
def customer_payments(customer)
|
||||
payments = with_service('Payment') do |service|
|
||||
service.all("SELECT * FROM Payment WHERE CustomerRef = '#{customer.id.to_i}' ORDERBY TxnDate DESC")
|
||||
end
|
||||
Array(payments).sort_by { |p| [p.txn_date || Date.new(1900), p.id.to_i] }.reverse
|
||||
end
|
||||
|
||||
# Totals for the customer's payment list: amount received and what's still unapplied (credit)
|
||||
def payment_totals(payments)
|
||||
sum = ->(values) { values.sum(BigDecimal('0')) { |v| BigDecimal(v.to_s.presence || '0') } }
|
||||
{ received: sum.call(payments.map(&:total)), unapplied: sum.call(payments.map(&:unapplied_amount)) }
|
||||
end
|
||||
|
||||
def load(id)
|
||||
payment = with_service('Payment') { |service| service.fetch_by_id(id) }
|
||||
raise Error, I18n.t(:notice_payment_not_found) unless payment
|
||||
|
||||
Reference in new issue
Block a user