From 92f9eb1bc7fdec48d6b9c8eb8db58ca116a65175 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Tue, 17 Nov 2026 19:39:08 -0500 Subject: [PATCH] Customer page lists: short paid badge, aligned icons, appointment link * 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 --- README.md | 4 +- .../customers/_new_issue_link_script.html.erb | 83 +++++++++++-------- app/views/customers/show.html.erb | 2 +- app/views/estimates/_list.html.erb | 17 ++-- app/views/invoices/_list.html.erb | 19 +++-- .../qbo_estimates/_status_styles.html.erb | 7 ++ assets/javascripts/application.js | 20 ----- config/locales/en.yml | 2 + lib/redmine_qbo/hooks/view_hook_listener.rb | 1 - lib/redmine_qbo_billing/invoice_status.rb | 20 +++++ test/unit/business_report_test.rb | 14 ++++ 11 files changed, 117 insertions(+), 72 deletions(-) delete mode 100644 assets/javascripts/application.js diff --git a/README.md b/README.md index 87fd565..ee6ee85 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ Estimates and invoices keep their number, date, customer, total, sales tax and * * 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. * **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. A paid invoice shows the day it was paid in full (e.g. **Paid 11/03/2026**): the later of its date and the last payment or credit memo applied to it. +* 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. A paid invoice shows when it was paid in full (the later of its date and the last payment or credit memo applied to it): on the customer page's list, **Paid** when it was paid the day it was written, or **Paid +3d** when it was paid in full 3 days after its date, with the date when hovering over it; on the invoice page, the date (e.g. **Paid 11/03/2026**). * 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 @@ -250,7 +250,7 @@ Hook|:qbo_billing_issues_created, { estimate:, issues:, params: } | Called after Hook|:qbo_billing_field_defaults, { customer:, issues: } | Return `{ field_id => value }` for a document's work orders: used when an invoice is made from an estimate, for the fields it leaves blank. New estimates and invoices start blank (redmine_qbo_vehicles: the work orders' VIN and highest mileage) Hook|:qbo_billing_field_options, { customer: } | Return `{ field_id => [{ value:, label: }, ...] }` to suggest in the editor's custom field boxes for a customer (redmine_qbo_vehicles: the customer's vehicles for the VIN box) View|:view_qbo_estimate_form_bottom, { form:, document: } | Add your plugin's script to the estimate/invoice editor. It can use `window.qboEditor` (`field(id)`, `fieldNamed(/name/)`, `setFieldOptions(id, options)`) and listen for `qbo:customer-changed` and `qbo:imported` on the form (redmine_qbo_vehicles fills the VIN and mileage) -View|checkboxes with `data-new-issue-param="issue[field]"` on the customer page | Ticking one adds `issue[field]=value` to the New issue link, one per field (redmine_qbo's estimates, redmine_qbo_vehicles' vehicles) +View|checkboxes with `data-new-issue-param="issue[field]"` and `data-appointment-param="field"` on the customer page | Ticking one adds `issue[field]=value` to the New issue link and `field=value` to redmine_qbo_calendar's Add appointment link (`#appointment_link`), one per field (redmine_qbo's estimates: `estimate_id`, redmine_qbo_vehicles' vehicles: `vehicle_id`) View Hook|:view_qbo_estimate_contextual, { estimate_id:, customer_id:, custom_fields:, doc_number: } | Adds links to an estimate page's action area (e.g. redmine_qbo_calendar's Add appointment); `custom_fields` is `{ field_id => value }` View Hook|:view_qbo_invoice_contextual, { invoice_id:, customer_id:, doc_number: } | Adds links to an invoice page's action area (e.g. redmine_qbo_labels' Print label) diff --git a/app/views/customers/_new_issue_link_script.html.erb b/app/views/customers/_new_issue_link_script.html.erb index 6bb9864..5ab1858 100644 --- a/app/views/customers/_new_issue_link_script.html.erb +++ b/app/views/customers/_new_issue_link_script.html.erb @@ -1,45 +1,58 @@ <%# - Adds what's ticked on the customer page to the "New issue" link (#dynamic-new-issue-link in the contextual - area). Any checkbox with data-new-issue-param="issue[field]" takes part, one ticked per field: this plugin's - estimates (issue[estimate_id]), and other plugins' lists (e.g. redmine_qbo_vehicles' issue[vehicle_id]). + Adds what's ticked on the customer page to its links: "New issue" (#dynamic-new-issue-link in the contextual area) + and redmine_qbo_calendar's "Add appointment" (#appointment_link). A checkbox takes part with + data-new-issue-param="issue[field]" (New issue) and data-appointment-param="field" (Add appointment); one is + ticked per field: this plugin's estimates (estimate_id), and other plugins' lists (e.g. redmine_qbo_vehicles' + vehicle_id). %> diff --git a/app/views/customers/show.html.erb b/app/views/customers/show.html.erb index 6d0bf7c..72b8f06 100644 --- a/app/views/customers/show.html.erb +++ b/app/views/customers/show.html.erb @@ -52,7 +52,7 @@

<%=t(:estimates)%>:

- <%= render partial: 'estimates/list', locals: {estimates: @customer.estimates} %> + <%= render partial: 'estimates/list', locals: {estimates: @customer.estimates, new_issue_checkboxes: true} %>
diff --git a/app/views/estimates/_list.html.erb b/app/views/estimates/_list.html.erb index aea470b..7686ea3 100644 --- a/app/views/estimates/_list.html.erb +++ b/app/views/estimates/_list.html.erb @@ -3,14 +3,19 @@ <%= render partial: 'qbo_estimates/status_styles' %>
<% estimates.sort.reverse.each do |estimate| %> + <%# One cell each (qbo_estimates/_status_styles lines them up in columns, so the icons line up) %>
- <%= check_box_tag "estimate_ids[]", estimate.id, false, onchange: "updateLink()", data: { text: "Estimate ##{estimate.doc_number}", new_issue_param: 'issue[estimate_id]' }, class: "estimate-checkbox appointment" %> - <%= link_to "##{estimate.doc_number}", estimate_path(estimate), target: :_blank %> <%= estimate.txn_date %> + <%# Ticking an estimate adds it to the customer page's New issue and Add appointment links (customers/_new_issue_link_script) %> + <%= check_box_tag "estimate_ids[]", estimate.id, false, data: { new_issue_param: 'issue[estimate_id]', appointment_param: 'estimate_id' }, class: "estimate-checkbox" if local_assigns[:new_issue_checkboxes] %> + <%= link_to "##{estimate.doc_number}", estimate_path(estimate), target: :_blank %> + <%= estimate.txn_date %> <%# QuickBooks status, cached by the estimate sync (kept current by the webhook) %> - <% if estimate.txn_status.present? %> - <%= estimate.txn_status %> - <% end %> - <%= render partial: 'qbo_estimates/estimate_actions', locals: { estimate: estimate } if RedmineQboBilling.writer? %> + + <% if estimate.txn_status.present? %> + <%= estimate.txn_status %> + <% end %> + + <%= render partial: 'qbo_estimates/estimate_actions', locals: { estimate: estimate } if RedmineQboBilling.writer? %>
<% end %>
diff --git a/app/views/invoices/_list.html.erb b/app/views/invoices/_list.html.erb index 6606a1d..5072c37 100644 --- a/app/views/invoices/_list.html.erb +++ b/app/views/invoices/_list.html.erb @@ -13,14 +13,19 @@
<% invoices.sort.reverse.each do |invoice| %> + <%# One cell each (qbo_estimates/_status_styles lines them up in columns, so the icons line up) %>
- <%= 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 %> - <%= link_to "##{invoice.doc_number}", invoice_path(invoice), target: :_blank %> <%= invoice.txn_date %> - <%# Paid / partially paid / overdue / open / voided, from the cached balance and due date %> - <% if (status = invoice.status) %> - <%= RedmineQboBilling::InvoiceStatus.label(status, paid_on: invoice.paid_on) %> - <% end %> - <%= render partial: 'qbo_invoices/invoice_actions', locals: { invoice: invoice } if RedmineQboBilling.invoice_writer? %> + <%= check_box_tag "invoice_ids[]", invoice.id, false, class: "invoice-checkbox" if invoices.count > 1 %> + <%= link_to "##{invoice.doc_number}", invoice_path(invoice), target: :_blank %> + <%= invoice.txn_date %> + <%# Paid / partially paid / overdue / open / voided, from the cached balance and due date; short so the list + stays narrow: "Paid", or "Paid +3d" when paid in full days after its date (the date on hover) %> + + <% if (status = invoice.status) %> + <%= RedmineQboBilling::InvoiceStatus.short_label(status, paid_on: invoice.paid_on, invoice_date: invoice.txn_date) %> + <% end %> + + <%= render partial: 'qbo_invoices/invoice_actions', locals: { invoice: invoice } if RedmineQboBilling.invoice_writer? %>
<% end %>
diff --git a/app/views/qbo_estimates/_status_styles.html.erb b/app/views/qbo_estimates/_status_styles.html.erb index 98b76ee..84e122a 100644 --- a/app/views/qbo_estimates/_status_styles.html.erb +++ b/app/views/qbo_estimates/_status_styles.html.erb @@ -14,4 +14,11 @@ .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; } + /* The estimate and invoice lists: checkbox, number, date, status and actions in columns, so the edit/view icons + line up; a list wider than its column scrolls instead of wrapping */ + .qbo-estimate-list, .qbo-invoice-list { display: grid; grid-template-columns: repeat(5, max-content); column-gap: .35em; + row-gap: 2px; align-items: center; overflow-x: auto; } + .qbo-estimate-list .row, .qbo-invoice-list .row { display: contents; } + .qbo-estimate-list .row > *, .qbo-invoice-list .row > * { white-space: nowrap; } + .qbo-list-status .qbo-estimate-status { margin-left: 0; } diff --git a/assets/javascripts/application.js b/assets/javascripts/application.js deleted file mode 100644 index f7863fd..0000000 --- a/assets/javascripts/application.js +++ /dev/null @@ -1,20 +0,0 @@ -function updateLink() { - console.log("updateLink called"); - const linkElement = document.getElementById("appointment_link"); - const regex = /((?:|%3Cbr\/?%3E))([\s\S]*?)(&dates)/gi; - linkElement.href = linkElement.href.replace(regex, `$1${getSelectedDocs()}$3`); -} - -function getSelectedDocs() { - const appointent_extras = document.querySelectorAll('.appointment'); - - let output = ''; - for (const item of appointent_extras) { - if (item.checked) { - console.log(`Checked item: ${item.dataset.text} with URL: ${item.dataset.url}`); - output += `%0A`+ encodeURIComponent(`${item.dataset.text}`) +`%0A`; - } - } - - return output; -} diff --git a/config/locales/en.yml b/config/locales/en.yml index 8b6e9c4..36dddf4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -290,6 +290,8 @@ en: label_invoice_no: "Invoice no." label_invoice_status_paid: "Paid" label_invoice_status_paid_on: "Paid %{date}" + label_invoice_status_paid_days: "Paid +%{days}d" + text_invoice_paid_in_full: "Paid in full %{date}" label_invoice_status_partial: "Partially paid" label_invoice_status_overdue: "Overdue" label_invoice_status_open: "Open" diff --git a/lib/redmine_qbo/hooks/view_hook_listener.rb b/lib/redmine_qbo/hooks/view_hook_listener.rb index da6862a..ed4119c 100644 --- a/lib/redmine_qbo/hooks/view_hook_listener.rb +++ b/lib/redmine_qbo/hooks/view_hook_listener.rb @@ -16,7 +16,6 @@ module RedmineQbo # Load the javascript to support the autocomplete forms def view_layouts_base_html_head(context = {}) safe_join([ - javascript_include_tag( 'application.js', plugin: :redmine_qbo), javascript_include_tag( 'autocomplete.js', plugin: :redmine_qbo), javascript_include_tag( 'checkbox_controller.js', plugin: :redmine_qbo), stylesheet_link_tag( 'autocomplete', plugin: :redmine_qbo) diff --git a/lib/redmine_qbo_billing/invoice_status.rb b/lib/redmine_qbo_billing/invoice_status.rb index 8790cc0..c74a964 100644 --- a/lib/redmine_qbo_billing/invoice_status.rb +++ b/lib/redmine_qbo_billing/invoice_status.rb @@ -42,6 +42,26 @@ module RedmineQboBilling 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 diff --git a/test/unit/business_report_test.rb b/test/unit/business_report_test.rb index 8838c22..b1c28aa 100644 --- a/test/unit/business_report_test.rb +++ b/test/unit/business_report_test.rb @@ -65,4 +65,18 @@ class BusinessReportTest < ActiveSupport::TestCase assert_equal 105.0, r.chart[:current][:tax_invoiced].compact.sum assert_equal 70.0, r.chart[:current][:tax_collected].compact.sum end + + def test_short_paid_badge + status = RedmineQboBilling::InvoiceStatus + nov18 = Date.new(2026, 11, 18) + assert_equal 'Paid', status.short_label(:paid, paid_on: nov18, invoice_date: nov18) + assert_equal 'Paid +1d', status.short_label(:paid, paid_on: nov18 + 1, invoice_date: nov18) + assert_equal 'Paid +34d', status.short_label(:paid, paid_on: nov18 + 34, invoice_date: nov18) + assert_equal 'Paid', status.short_label(:paid, paid_on: nil, invoice_date: nov18) + # A deposit taken before the invoice: paid in full on its date + assert_equal 'Paid', status.short_label(:paid, paid_on: nov18, invoice_date: nov18 + 2) + assert_equal 'Open', status.short_label(:open, paid_on: nov18 + 3, invoice_date: nov18) + assert_match(/\APaid in full \S+/, status.title(:paid, paid_on: nov18)) + assert_nil status.title(:open, paid_on: nov18) + end end