Show invoice statuses

Invoices get a status badge on the customer page's invoice list and the invoice page: Paid, Partially
paid, Overdue, Open or Voided (zero total), worked out from the total, balance and due date like
QuickBooks' invoice list (RedmineQboBilling::InvoiceStatus; QuickBooks keeps no status on invoices).
The list uses the cached balance and due date; the invoice page uses QuickBooks' current figures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
Claude committed 2026-10-31 14:10:11 -04:00
1 parent 0d35cffb83
commit 03af3457ab
7 files changed
+81 -5

No files matched your search

+1
View File
@@ -126,6 +126,7 @@ Estimates and invoices keep their number, date, customer, total and **man-hours*
* Time lines are linked to their time activities, so QuickBooks marks the time as billed. Estimates the invoice was made from, or imported into it, are linked and closed when it's saved. * Time lines are linked to their time activities, so QuickBooks marks the time as billed. Estimates the invoice was made from, or imported into it, are linked and closed when it's saved.
* **Custom fields from the work orders**: the issues behind an invoice are the ones its time lines and lineitems estimates name. Plugins can fill custom fields from them when they're imported, and block a save (e.g. redmine_qbo_vehicles fills the VIN and mileage and allows one vehicle per invoice). On its own, redmine_qbo leaves the boxes as typed. * **Custom fields from the work orders**: the issues behind an invoice are the ones its time lines and lineitems estimates name. Plugins can fill custom fields from them when they're imported, and block a save (e.g. redmine_qbo_vehicles fills the VIN and mileage and allows one vehicle per invoice). On its own, redmine_qbo leaves the boxes as typed.
* **Sales person**: an invoice credits the sales person on the estimate it was made from (the first linked estimate that names one); if none does, the user who writes the invoice. * **Sales person**: an invoice credits the sales person on the estimate it was made from (the first linked estimate that names one); if none does, the user who writes the invoice.
* Invoices show their status, worked out from the balance and due date like QuickBooks' invoice list: **Paid**, **Partially paid**, **Overdue**, **Open** or **Voided** (a zero total), on the customer page's invoice list and the invoice page.
* Invoices with a payment applied open read-only. The due date is left to QuickBooks (from the customer's terms) unless one is picked. The "default message shown on invoices" fills in the message. * Invoices with a payment applied open read-only. The due date is left to QuickBooks (from the customer's terms) unless one is picked. The "default message shown on invoices" fills in the message.
### Payments ### Payments
+7
View File
@@ -22,4 +22,11 @@ class Invoice < QboBaseModel
doc_number doc_number
end end
# Paid, partially paid, overdue, open or voided, from the cached total, balance and due date
# (RedmineQboBilling::InvoiceStatus); nil when the balance isn't cached
def status(today: User.current.today)
RedmineQboBilling::InvoiceStatus.status(total: self[:total_amount], balance: self[:balance],
due_date: self[:due_date], today: today)
end
end end
+7
View File
@@ -1,4 +1,5 @@
<% unless invoices.empty? %> <% unless invoices.empty? %>
<%= render partial: 'qbo_estimates/status_styles' %>
<%= form_with(url: invoice_path, method: :get) do |form| %> <%= form_with(url: invoice_path, method: :get) do |form| %>
@@ -10,13 +11,19 @@
<hr> <hr>
<% end %> <% end %>
<div class="qbo-invoice-list">
<% invoices.sort.reverse.each do |invoice| %> <% invoices.sort.reverse.each do |invoice| %>
<div class="row"> <div class="row">
<%= check_box_tag "invoice_ids[]", invoice.id, false, onchange: "updateLink()", data: { url: invoice_path(invoice), text: "Invoice ##{invoice.to_s}" }, class: "invoice-checkbox appointment" if invoices.count > 1 %> <%= check_box_tag "invoice_ids[]", invoice.id, false, onchange: "updateLink()", data: { url: invoice_path(invoice), text: "Invoice ##{invoice.to_s}" }, class: "invoice-checkbox appointment" if invoices.count > 1 %>
<b><%= link_to "##{invoice.doc_number}", invoice_path(invoice), target: :_blank %></b> <%= invoice.txn_date %> <b><%= link_to "##{invoice.doc_number}", invoice_path(invoice), target: :_blank %></b> <%= invoice.txn_date %>
<%# Paid / partially paid / overdue / open / voided, from the cached balance and due date %>
<% if (status = invoice.status) %>
<span class="qbo-estimate-status qbo-invoice-status-<%= status %>"><%= RedmineQboBilling::InvoiceStatus.label(status) %></span>
<% end %>
<%= render partial: 'qbo_invoices/invoice_actions', locals: { invoice: invoice } if RedmineQboBilling.invoice_writer? %> <%= render partial: 'qbo_invoices/invoice_actions', locals: { invoice: invoice } if RedmineQboBilling.invoice_writer? %>
</div> </div>
<% end %> <% end %>
</div>
<% if invoices.count > 1 %> <% if invoices.count > 1 %>
<%= form.submit t(:button_bulk_pdf) %> <%= form.submit t(:button_bulk_pdf) %>
+7 -3
View File
@@ -15,9 +15,13 @@
<% if form.sent? %> <% if form.sent? %>
<span class="qbo-estimate-status qbo-estimate-status-sent"><%= l(:label_estimate_sent) %></span> <span class="qbo-estimate-status qbo-estimate-status-sent"><%= l(:label_estimate_sent) %></span>
<% end %> <% end %>
<% if invoice && form.locked == :paid %> <% if invoice %>
<% fully_paid = form.balance.to_d.zero? %> <% status = RedmineQboBilling::InvoiceStatus.status(total: form.total, balance: form.balance,
<span class="qbo-estimate-status qbo-estimate-status-<%= fully_paid ? 'closed' : 'accepted' %>"><%= l(fully_paid ? :label_invoice_paid : :label_invoice_partially_paid) %></span> due_date: RedmineQboBilling::EstimateForm.date(form.due_date),
today: User.current.today) %>
<% if status %>
<span class="qbo-estimate-status qbo-invoice-status-<%= status %>"><%= RedmineQboBilling::InvoiceStatus.label(status) %></span>
<% end %>
<% elsif !invoice && form.txn_status.present? %> <% elsif !invoice && form.txn_status.present? %>
<span class="qbo-estimate-status qbo-estimate-status-<%= form.txn_status.downcase %>"><%= form.txn_status %></span> <span class="qbo-estimate-status qbo-estimate-status-<%= form.txn_status.downcase %>"><%= form.txn_status %></span>
<% end %> <% end %>
@@ -7,4 +7,11 @@
.qbo-estimate-status-closed, .qbo-estimate-status-converted { background: #e8eefa; color: #0d47a1; } .qbo-estimate-status-closed, .qbo-estimate-status-converted { background: #e8eefa; color: #0d47a1; }
.qbo-estimate-status-rejected { background: #fdecea; color: #b71c1c; } .qbo-estimate-status-rejected { background: #fdecea; color: #b71c1c; }
.qbo-estimate-list .qbo-estimate-status { font-size: .8em; padding: 1px 7px; margin-left: 4px; } .qbo-estimate-list .qbo-estimate-status { font-size: .8em; padding: 1px 7px; margin-left: 4px; }
/* Invoices (RedmineQboBilling::InvoiceStatus) */
.qbo-invoice-status-paid { background: #e6f4e4; color: #108000; }
.qbo-invoice-status-partial { background: #fff4d6; color: #8a6100; }
.qbo-invoice-status-overdue { background: #fdecea; color: #b71c1c; }
.qbo-invoice-status-open { background: #e8eefa; color: #0d47a1; }
.qbo-invoice-status-voided { background: #eceef1; color: #6b6c72; text-decoration: line-through; }
.qbo-invoice-list .qbo-estimate-status { font-size: .8em; padding: 1px 7px; margin-left: 4px; }
</style> </style>
+5 -2
View File
@@ -240,8 +240,11 @@ en:
label_invoice_balance: "Balance due %{balance}" label_invoice_balance: "Balance due %{balance}"
label_invoice_date: "Invoice date" label_invoice_date: "Invoice date"
label_invoice_no: "Invoice no." label_invoice_no: "Invoice no."
label_invoice_paid: "Paid" label_invoice_status_paid: "Paid"
label_invoice_partially_paid: "Partially paid" label_invoice_status_partial: "Partially paid"
label_invoice_status_overdue: "Overdue"
label_invoice_status_open: "Open"
label_invoice_status_voided: "Voided"
label_message_on_invoice: "Message displayed on invoice" label_message_on_invoice: "Message displayed on invoice"
label_new_invoice: "New invoice" label_new_invoice: "New invoice"
label_open_estimates: "Open estimates" label_open_estimates: "Open estimates"
+47
View File
@@ -0,0 +1,47 @@
#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
def label(status)
status ? I18n.t("label_invoice_status_#{status}") : ''
end
def to_d(value)
BigDecimal(value.to_s.presence || '0')
rescue ArgumentError
BigDecimal('0')
end
end
end