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 : [] +%> +