From 4ba96e2dfd4e28311d396a0e0164adf8fa7b0a92 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Mon, 2 Nov 2026 17:55:14 -0500 Subject: [PATCH] Warn about the customer's open issues on a new invoice A new invoice lists the customer's open issues (any project, those the user can see) in a warning under the title, so work orders aren't left open once the work is billed. It's there when the page opens with a customer (from the customer page or an estimate) and follows the customer when it's changed: customer_info returns open_issues_html for invoices. Co-Authored-By: Claude Opus 5.5 --- app/controllers/qbo_estimates_controller.rb | 8 +++++++- app/views/qbo_estimates/_script.html.erb | 4 +++- app/views/qbo_invoices/_open_issues.html.erb | 17 +++++++++++++++++ app/views/qbo_invoices/new.html.erb | 1 + config/locales/en.yml | 3 +++ 5 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 app/views/qbo_invoices/_open_issues.html.erb diff --git a/app/controllers/qbo_estimates_controller.rb b/app/controllers/qbo_estimates_controller.rb index 2586872..24997ec 100644 --- a/app/controllers/qbo_estimates_controller.rb +++ b/app/controllers/qbo_estimates_controller.rb @@ -116,13 +116,19 @@ class QboEstimatesController < ApplicationController customer = Customer.find_by(id: params[:customer_id]) return render(json: {}, status: :not_found) unless customer - render json: { + info = { id: customer.id, name: customer.name, email: RedmineQboBilling::EstimateWriter.customer_email(customer), billing_address: RedmineQboBilling::EstimateWriter.customer_address(customer), field_options: RedmineQboBilling.field_options(customer) } + # A new invoice warns about the customer's open issues + if params[:document] == 'invoice' + info[:open_issues_html] = render_to_string(partial: 'qbo_invoices/open_issues', formats: [:html], + locals: { customer: customer }) + end + render json: info end # Product/service search for the line table (the QuickBooks item list) diff --git a/app/views/qbo_estimates/_script.html.erb b/app/views/qbo_estimates/_script.html.erb index 4f74547..8cd63cf 100644 --- a/app/views/qbo_estimates/_script.html.erb +++ b/app/views/qbo_estimates/_script.html.erb @@ -446,7 +446,9 @@ $(function () { var id = $(this).val(); if (!id) return; dirty = true; - $.getJSON($form.data('customerInfoUrl'), { customer_id: id }).done(function (info) { + $.getJSON($form.data('customerInfoUrl'), { customer_id: id, document: $form.data('document') }).done(function (info) { + // A new invoice's open issues notice follows the customer + if (info.open_issues_html !== undefined) $('#qbo-open-issues').replaceWith(info.open_issues_html); // Replace the email only if it was the previous customer's (or empty) if (!$email.val().trim() || $email.val() === loadedEmail) $email.val(info.email || ''); loadedEmail = info.email || ''; diff --git a/app/views/qbo_invoices/_open_issues.html.erb b/app/views/qbo_invoices/_open_issues.html.erb new file mode 100644 index 0000000..edf78ef --- /dev/null +++ b/app/views/qbo_invoices/_open_issues.html.erb @@ -0,0 +1,17 @@ +<%# A new invoice's customer still has open issues (work orders), so they're not left behind once billed. + Replaced when the customer is changed (customer_info's open_issues_html). %> +<% + issues = customer ? customer.issues.open.visible.order(id: :desc).to_a : [] +%> +
+ <% if issues.any? %> +
+ <%= l(:text_invoice_customer_open_issues, count: issues.size) %> +
    + <% issues.each do |issue| %> +
  • <%= link_to_issue(issue, truncate: 60) %> (<%= issue.status %>)
  • + <% end %> +
+
+ <% end %> +
diff --git a/app/views/qbo_invoices/new.html.erb b/app/views/qbo_invoices/new.html.erb index c1586fa..73da973 100644 --- a/app/views/qbo_invoices/new.html.erb +++ b/app/views/qbo_invoices/new.html.erb @@ -1,4 +1,5 @@ <% html_title l(:label_new_invoice) %> <%= render partial: 'qbo_estimates/header', locals: { form: @form } %> +<%= render partial: 'qbo_invoices/open_issues', locals: { customer: (Customer.find_by(id: @form.customer_id) if @form.customer_id.present?) } %> <%= render partial: 'qbo_estimates/form', locals: { form: @form } %> diff --git a/config/locales/en.yml b/config/locales/en.yml index a67692f..4af930c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -256,6 +256,9 @@ en: notice_invoice_sent: "Invoice #%{number} emailed to %{email}" text_email_invoice_confirmation: "Email invoice #%{number} to %{email}?" text_invoice_from_estimate: "Made from estimate #%{number}. The estimate is closed when the invoice is saved." + text_invoice_customer_open_issues: + one: "This customer has an open issue. Make sure its work is finished and billed so it isn't left open:" + other: "This customer has %{count} open issues. Make sure their work is finished and billed so none are left open:" text_line_bills_time: "Bills a QuickBooks time activity; saving marks the time as billed" text_replace_lines: "Tick the lines the time replaces (e.g. the estimate's labor lines). Each time entry takes the place of the line with its issue's description (e.g. Install Lift Kit), then any others in order."