mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-18 02:20:37 -05:00
* The invoice list's paid badge is short so each invoice stays on one line: "Paid", or "Paid +3d" when it was paid in full 3 days after its date, with the day on hover. The invoice page keeps the date. * The estimate and invoice lists are laid out in columns (checkbox, number, date, status, actions), so the edit/view icons line up. * Ticked estimates (and redmine_qbo_vehicles' vehicles) fill in redmine_qbo_calendar's Add appointment link (estimate_id, vehicle_id) as well as New issue. Estimate checkboxes are only on the customer page, where they're used. * application.js is gone: it only carried the old Google Calendar link code, which threw an error when a box was ticked on a vehicle page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
72 lines
3.2 KiB
Ruby
72 lines
3.2 KiB
Ruby
#The MIT License (MIT)
|
|
#
|
|
#Copyright (c) 2026 rick barrette
|
|
#
|
|
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
#
|
|
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
#
|
|
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
module RedmineQboBilling
|
|
# An invoice's status, worked out from its total, balance and due date the way QuickBooks' invoice list
|
|
# shows it (QuickBooks keeps no status field on invoices):
|
|
# :voided - nothing to pay at all (a voided invoice has a zero total)
|
|
# :paid - nothing left owing
|
|
# :partial - some of it paid
|
|
# :overdue - money owing and past the due date
|
|
# :open - money owing, not yet due
|
|
# nil when the balance isn't known (e.g. an invoice synced before balances were kept).
|
|
module InvoiceStatus
|
|
STATUSES = %i[voided paid partial overdue open].freeze
|
|
|
|
module_function
|
|
|
|
def status(total:, balance:, due_date: nil, today: Date.current)
|
|
return nil if balance.nil? || balance.to_s.strip.empty?
|
|
|
|
total = to_d(total)
|
|
balance = to_d(balance)
|
|
return :voided if total.zero? && balance.zero?
|
|
return :paid if balance <= 0
|
|
return :overdue if due_date && due_date < today
|
|
balance < total ? :partial : :open
|
|
end
|
|
|
|
# "Paid", or with the day it was paid in full, "Paid 11/03/2026"
|
|
def label(status, paid_on: nil)
|
|
return '' unless status
|
|
return I18n.t(:label_invoice_status_paid_on, date: I18n.l(paid_on)) if status == :paid && paid_on
|
|
|
|
I18n.t("label_invoice_status_#{status}")
|
|
end
|
|
|
|
# The invoice list's short badge: "Paid", or "Paid +3d" when it was paid in full 3 days after its date
|
|
def short_label(status, paid_on: nil, invoice_date: nil)
|
|
days = days_to_pay(invoice_date, paid_on) if status == :paid
|
|
return I18n.t(:label_invoice_status_paid_days, days: days) if days&.positive?
|
|
|
|
label(status)
|
|
end
|
|
|
|
# The badge's tooltip: "Paid in full 11/19/2025" (nil unless it's paid with a known day)
|
|
def title(status, paid_on: nil)
|
|
I18n.t(:text_invoice_paid_in_full, date: I18n.l(paid_on)) if status == :paid && paid_on
|
|
end
|
|
|
|
# Days from the invoice's date to the day it was paid in full
|
|
def days_to_pay(invoice_date, paid_on)
|
|
return nil unless invoice_date && paid_on
|
|
|
|
(paid_on.to_date - invoice_date.to_date).to_i
|
|
end
|
|
|
|
def to_d(value)
|
|
BigDecimal(value.to_s.presence || '0')
|
|
rescue ArgumentError
|
|
BigDecimal('0')
|
|
end
|
|
end
|
|
end
|