diff --git a/README.md b/README.md index b313108..193be22 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ Estimates and invoices keep their number, date, customer, total and **man-hours* * **Undo import** puts the lines back until the invoice is saved. * **An estimate is billed once**: an estimate that's on an invoice (linked to one, or closed) or was rejected can't be made into an invoice or imported, and its page shows the invoice it's billed on. This is checked against QuickBooks again when the invoice is saved, so an estimate invoiced meanwhile (in another tab, by someone else, or in QuickBooks) stops the save. * 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. -* **VIN and mileage from the work orders**: the issues behind an invoice are the ones its time lines and lineitems estimates name. When they're imported, the VIN box takes their vehicle's VIN (with redmine_qbo_vehicles) and a **Mileage** box (shown when QuickBooks has a text custom field named like "Mileage") takes the highest value of the issues' Mileage custom field. With redmine_qbo_vehicles, an invoice whose work orders are for more than one vehicle isn't saved. +* **VIN and mileage from the work orders**: the issues behind an invoice are the ones its time lines and lineitems estimates name. When they're imported, the VIN box takes their vehicle's VIN and a **Mileage** box (shown when QuickBooks has a text custom field named like "Mileage") takes the highest value of the issues' Mileage custom field, both supplied by redmine_qbo_vehicles. With redmine_qbo_vehicles, an invoice whose work orders are for more than one vehicle isn't saved. * **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 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. @@ -218,10 +218,13 @@ View Hook|:pdf_right, { issue: issue } | Used to add text to right side of PDF View Hook|:show_customer_view_right, { customer: customer } | Used to show partials on right side of customer view Hook| :qbo_additional_entities | Used to add additional entites to be processed by the WebhookProcessJob Hook| :qbo_full_sync | Used to add a Class to be called by the QboSyncDispatcher -Hook|:qbo_billing_issue_values, { issues: } | Return `{ field => { issue_id => value } }` for the work orders behind an invoice, e.g. `{ vin: { 116 => "1C4..." } }` (redmine_qbo_vehicles). Importing time or estimates fills the VIN box when the work orders share one VIN, and the mileage box with the highest mileage (read from the issue custom field named "Mileage") +Hook|:qbo_billing_issue_values, { issues: } | Return `{ field => { issue_id => value } }` for the work orders behind an invoice, e.g. `{ vin: { 116 => "1C4..." } }` (redmine_qbo_vehicles). Importing time or estimates fills the VIN box when the work orders share one VIN, and the mileage box with the highest `mileage` value (redmine_qbo_vehicles reads it from the issue custom field named "Mileage") Hook|:qbo_billing_validate, { document:, form:, issues: } | Return an error message (or several) to stop an estimate or invoice from saving, e.g. redmine_qbo_vehicles: one vehicle per invoice -Hook|:qbo_billing_issue_defaults, { estimate:, params: } | Return `start_date`, `due_date`, `assignee`, `vehicle_id`, `project`, `description`, `return_path`, `return_label` for issues created from an estimate (redmine_qbo_calendar, when opened from an appointment) +Hook|:qbo_billing_issue_defaults, { estimate:, params: } | Return `start_date`, `due_date`, `assignee`, `project`, `description`, `return_path`, `return_label`, plus any values your own fields need (e.g. redmine_qbo_calendar's `vehicle_id`), for issues created from an estimate (redmine_qbo_calendar, when opened from an appointment) +Hook|:qbo_billing_build_issue, { issue:, estimate:, defaults: } | Set your plugin's own fields on each issue created from an estimate, before it's saved (redmine_qbo_vehicles sets the vehicle: the one in `defaults`, or the customer's vehicle whose VIN is on the estimate) Hook|:qbo_billing_issues_created, { estimate:, issues:, params: } | Called after issues are created from an estimate +Hook|:qbo_billing_vin_options, { customer: } | Return `[{ vin:, name: }, ...]` to suggest in the estimate/invoice VIN box; one suggestion fills an empty box (redmine_qbo_vehicles: the customer's vehicles) +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 Hook|:view_qbo_estimate_contextual, { estimate_id:, customer_id:, vin:, doc_number: } | Adds links to an estimate page's action area (e.g. redmine_qbo_calendar's Add appointment) Other plugins create estimates with `RedmineQboBilling::EstimateWriter.create_estimate(customer:, lines:, private_note:, vin:, mileage:, user:)`; each line is a hash of `description`, `item_id`, `quantity`, `rate` and `taxable`. diff --git a/app/controllers/qbo_estimates_controller.rb b/app/controllers/qbo_estimates_controller.rb index 4993656..92d5c88 100644 --- a/app/controllers/qbo_estimates_controller.rb +++ b/app/controllers/qbo_estimates_controller.rb @@ -106,18 +106,18 @@ class QboEstimatesController < ApplicationController end end - # Customer details for the editor when a customer is picked: email, billing address and vehicles (VINs) + # Customer details for the editor when a customer is picked: email, billing address and the VINs plugins + # suggest for the VIN box (RedmineQboBilling.vin_options) def customer_info customer = Customer.find_by(id: params[:customer_id]) return render(json: {}, status: :not_found) unless customer - vehicles = customer.respond_to?(:vehicles) ? customer.vehicles.to_a : [] render json: { id: customer.id, name: customer.name, email: RedmineQboBilling::EstimateWriter.customer_email(customer), billing_address: RedmineQboBilling::EstimateWriter.customer_address(customer), - vehicles: vehicles.select { |v| v.vin.present? }.map { |v| { vin: v.vin, name: v.to_s } } + vin_options: RedmineQboBilling.vin_options(customer) } end diff --git a/app/views/customers/_new_issue_link_script.html.erb b/app/views/customers/_new_issue_link_script.html.erb index 00358e0..6bb9864 100644 --- a/app/views/customers/_new_issue_link_script.html.erb +++ b/app/views/customers/_new_issue_link_script.html.erb @@ -1,59 +1,45 @@ <%# - Adds the estimate and vehicle ticked on the customer page to the "New issue" link - (#dynamic-new-issue-link in the contextual area). One of each can be ticked. + 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]). %> diff --git a/app/views/customers/show.html.erb b/app/views/customers/show.html.erb index 54db347..1b1296c 100644 --- a/app/views/customers/show.html.erb +++ b/app/views/customers/show.html.erb @@ -1,5 +1,5 @@
- <%# New issue for this customer; picks up the estimate / vehicle ticked on this page %> + <%# New issue for this customer; picks up what's ticked on this page (an estimate, other plugins' items) %> <%= link_to sprite_icon('add', l(:label_new_issue)), new_issue_path(issue: { customer_id: @customer.id }), id: 'dynamic-new-issue-link', class: 'icon icon-add', target: :_blank %> <%# Plugins add their customer actions here (e.g. redmine_qbo_calendar's Add appointment) %> diff --git a/app/views/estimates/_list.html.erb b/app/views/estimates/_list.html.erb index b422fc2..5bb8059 100644 --- a/app/views/estimates/_list.html.erb +++ b/app/views/estimates/_list.html.erb @@ -2,7 +2,7 @@ <% estimates.sort.reverse.each do |estimate| %>
- <%= check_box_tag "estimate_ids[]", estimate.id, false, onchange: "updateLink()", data: { text: "Estimate ##{estimate.doc_number}" }, class: "estimate-checkbox appointment" %> + <%= 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 %> <%= render partial: 'qbo_estimates/estimate_actions', locals: { estimate: estimate } if RedmineQboBilling.writer? %>
diff --git a/app/views/qbo_estimates/_form.html.erb b/app/views/qbo_estimates/_form.html.erb index 3d96343..d3b398c 100644 --- a/app/views/qbo_estimates/_form.html.erb +++ b/app/views/qbo_estimates/_form.html.erb @@ -4,7 +4,8 @@ vin_field = company.vin_field mileage_field = company.mileage_field customer = Customer.find_by(id: form.customer_id) if form.customer_id.present? - vehicles = customer.respond_to?(:vehicles) ? customer.vehicles.select { |v| v.vin.present? } : [] + # VINs other plugins suggest for the VIN box (e.g. redmine_qbo_vehicles: the customer's vehicles) + vin_options = RedmineQboBilling.vin_options(customer) # When QuickBooks' settings couldn't be read at all, the page header says so instead of each field settings_read = company.settings.present? # The same editor writes estimates and invoices @@ -121,8 +122,8 @@ <%= text_field_tag 'estimate[vin]', form.vin, id: 'qbo_estimate_vin', list: 'qbo-estimate-vins', maxlength: 31, autocomplete: 'off', spellcheck: false, disabled: vin_field.nil? %> - <% vehicles.each do |vehicle| %> - + <% vin_options.each do |option| %> + <% end %> <% if settings_read && !vin_field %> diff --git a/app/views/qbo_estimates/_script.html.erb b/app/views/qbo_estimates/_script.html.erb index 3dbc50f..1fcbdf5 100644 --- a/app/views/qbo_estimates/_script.html.erb +++ b/app/views/qbo_estimates/_script.html.erb @@ -283,12 +283,14 @@ $(function () { loadedEmail = info.email || ''; $('#qbo-estimate-address').text(info.billing_address || ''); + // VINs plugins suggest for this customer (e.g. their vehicles); one fills an empty VIN box + var options = info.vin_options || []; var $list = $('#qbo-estimate-vins').empty(); - (info.vehicles || []).forEach(function (vehicle) { - $('