mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-18 02:20:37 -05:00
Combine the labor settings into Labor products/services
The estimate item codes and "Replaced by imported time" become one list of products/services (RedmineQboBilling::LaborItems), used to create issues from an estimate's labor lines (and an appointment's minimum hours), to offer an invoice's labor lines to be replaced by imported time, and to total the hours on estimates and invoices for the business report. While none are chosen, products/services named Labor are used. The old settings and redmine_qbo_calendar's fallbacks are no longer read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
12 files changed
+120
-83
No files matched your search
@@ -95,7 +95,7 @@ Customer records are automatically updated in the local database when changes oc
|
|||||||
|
|
||||||
### Estimates, Invoices and Payments
|
### Estimates, Invoices and Payments
|
||||||
|
|
||||||
Estimates and invoices keep their number, date, customer, total and **man-hours** (the quantities of the products/services set as "Replaced by imported time", including lines inside bundles; the estimate item codes are used while that setting is blank). Payments keep their customer, date, amount and unapplied amount. These cached figures feed the business report.
|
Estimates and invoices keep their number, date, customer, total and **man-hours** (the quantities of the labor products/services, including lines inside bundles). Payments keep their customer, date, amount and unapplied amount. These cached figures feed the business report.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ Estimates and invoices keep their number, date, customer, total and **man-hours*
|
|||||||
* **Edit** any estimate from the Edit link next to it on the customer page or the issue page.
|
* **Edit** any estimate from the Edit link next to it on the customer page or the issue page.
|
||||||
* **Duplicate** an estimate to start a similar one: same customer, lines, subtotals, VIN and messages, dated today, with the current user as sales person.
|
* **Duplicate** an estimate to start a similar one: same customer, lines, subtotals, VIN and messages, dated today, with the current user as sales person.
|
||||||
* **Read-only once linked to an issue**: an estimate that an issue is linked to can be viewed, emailed and duplicated, but not changed, so the work doesn't drift from what was quoted. The list shows a View link for these instead of Edit.
|
* **Read-only once linked to an issue**: an estimate that an issue is linked to can be viewed, emailed and duplicated, but not changed, so the work doesn't drift from what was quoted. The list shows a View link for these instead of Edit.
|
||||||
* **Create issues** from an estimate's labor lines (moved here from redmine_qbo_calendar): each line whose item matches an **estimate item code** (e.g. Labor) becomes an issue with the line's description as subject and its quantity as estimated hours. Pick the project, trackers, templates and shared custom fields first. Lines already turned into issues can't be created twice, and issues from the same estimate are related to each other. Opened from an appointment, the issues get the appointment's dates, technician and vehicle.
|
* **Create issues** from an estimate's labor lines (moved here from redmine_qbo_calendar): each line with one of the **labor products/services** (e.g. Labor) becomes an issue with the line's description as subject and its quantity as estimated hours. Pick the project, trackers, templates and shared custom fields first. Lines already turned into issues can't be created twice, and issues from the same estimate are related to each other. Opened from an appointment, the issues get the appointment's dates, technician and vehicle.
|
||||||
* **Email** the estimate with QuickBooks' own estimate email, with **Save and send** or the Email link.
|
* **Email** the estimate with QuickBooks' own estimate email, with **Save and send** or the Email link.
|
||||||
* The page follows QuickBooks' estimate screen: customer, customer email, billing address, estimate date, expiration date, estimate number, then the product/service lines (#, product/service, description, qty, rate, amount, tax), the message displayed on the estimate, the memo, and the totals.
|
* The page follows QuickBooks' estimate screen: customer, customer email, billing address, estimate date, expiration date, estimate number, then the product/service lines (#, product/service, description, qty, rate, amount, tax), the message displayed on the estimate, the memo, and the totals.
|
||||||
* Lines work like QuickBooks: the product list opens when the box is clicked, picking a product fills in its description, rate and tax, typing an amount works out the rate, a spare empty line is always at the bottom, and lines are reordered by dragging them by the handle.
|
* Lines work like QuickBooks: the product list opens when the box is clicked, picking a product fills in its description, rate and tax, typing an amount works out the rate, a spare empty line is always at the bottom, and lines are reordered by dragging them by the handle.
|
||||||
@@ -117,7 +117,7 @@ Estimates and invoices keep their number, date, customer, total and **man-hours*
|
|||||||
|
|
||||||
* **Create invoice** on an estimate's page makes an invoice from it (customer, lines, subtotals, VIN), like QuickBooks' "Create invoice". **Create invoice** on the customer page starts a blank one, and the Edit link next to each invoice on the customer page opens it.
|
* **Create invoice** on an estimate's page makes an invoice from it (customer, lines, subtotals, VIN), like QuickBooks' "Create invoice". **Create invoice** on the customer page starts a blank one, and the Edit link next to each invoice on the customer page opens it.
|
||||||
* **Import time & estimates** lists the customer's billable QuickBooks time (the time activities redmine_qbo makes from an issue's time entries) and their open estimates (e.g. the ones redmine_qbo_lineitems makes for parts that weren't quoted).
|
* **Import time & estimates** lists the customer's billable QuickBooks time (the time activities redmine_qbo makes from an issue's time entries) and their open estimates (e.g. the ones redmine_qbo_lineitems makes for parts that weren't quoted).
|
||||||
* Tick the time to bill and, under **Replace these lines**, the lines it replaces (e.g. the estimate's labor lines). When products/services are set as **Replaced by imported time** in the plugin settings, only lines with one of them are offered there; with none set, every line is. The time goes where the first ticked line was and the ticked lines are removed, so the invoice reads in the same order.
|
* Tick the time to bill and, under **Replace these lines**, the lines it replaces (e.g. the estimate's labor lines). Only lines with one of the **labor products/services** from the plugin settings are offered there. The time goes where the first ticked line was and the ticked lines are removed, so the invoice reads in the same order.
|
||||||
* Ticked estimates go right after the time for the same issue: a redmine_qbo_lineitems estimate starting "Added from: Install #116: …" lands after the time for #116, without that note line, since the time line already names the issue. Estimates with no matching time keep the note and go at the end.
|
* Ticked estimates go right after the time for the same issue: a redmine_qbo_lineitems estimate starting "Added from: Install #116: …" lands after the time for #116, without that note line, since the time line already names the issue. Estimates with no matching time keep the note and go at the end.
|
||||||
* **Undo import** puts the lines back until the invoice is saved.
|
* **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.
|
* **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.
|
||||||
@@ -143,7 +143,7 @@ Estimates and invoices keep their number, date, customer, total and **man-hours*
|
|||||||
* **Hours**: estimated hours on estimates, issues' estimated time, invoiced hours on invoices and time spent, with invoiced vs. spent and spent vs. estimated.
|
* **Hours**: estimated hours on estimates, issues' estimated time, invoiced hours on invoices and time spent, with invoiced vs. spent and spent vs. estimated.
|
||||||
* **By month**: every figure month by month, with totals.
|
* **By month**: every figure month by month, with totals.
|
||||||
|
|
||||||
Estimates, invoices and payments count by their QuickBooks date. Issues' estimated time counts issues created in the period, leaving out parents so subtasks aren't counted twice. Spent time counts time logged in the period. Estimates and invoices synced before these figures were added have no total or hours until a full sync (the report says how many); run one again after changing "Replaced by imported time".
|
Estimates, invoices and payments count by their QuickBooks date. Issues' estimated time counts issues created in the period, leaving out parents so subtasks aren't counted twice. Spent time counts time logged in the period. Estimates and invoices synced before these figures were added have no total or hours until a full sync (the report says how many); run one again after changing the labor products/services.
|
||||||
|
|
||||||
### QuickBooks custom fields
|
### QuickBooks custom fields
|
||||||
|
|
||||||
@@ -188,9 +188,9 @@ Administration → Items lists the QuickBooks product/service list (synced from
|
|||||||
|
|
||||||
2. Settings (Administration -> Plugins -> Configure)
|
2. Settings (Administration -> Plugins -> Configure)
|
||||||
* **Estimates expire after (days)**: new estimates get an expiration date this many days after the estimate date (e.g. 30). Leave blank for none.
|
* **Estimates expire after (days)**: new estimates get an expiration date this many days after the estimate date (e.g. 30). Leave blank for none.
|
||||||
* **Issues from estimates**: the estimate item codes (also an estimate's labor hours, which an appointment's hours can't be less than), the default project and the default tracker. Until saved here, redmine_qbo_calendar's old values are used.
|
* **Labor products/services** (e.g. Labor): one list used three ways. An estimate's lines with them can become issues (their quantities are also the estimate's labor hours, which an appointment's hours can't be less than); an invoice's lines with them are offered under Replace these lines when time is imported; and their quantities are the hours on estimates and invoices in the business report. While none are chosen, products/services named Labor are used.
|
||||||
* **Replaced by imported time**: the products/services (e.g. Labor) whose invoice lines time can replace. Only those lines are offered under Replace these lines; leave empty to offer every line.
|
* **Issues from estimates**: the default project and the default tracker.
|
||||||
* Item and account counts, the default income account, and Sync Items / Sync Accounts.
|
* Item and account counts, the default income account and their syncs are under Synchronization.
|
||||||
|
|
||||||
3. Writing an estimate
|
3. Writing an estimate
|
||||||
|
|
||||||
@@ -312,7 +312,7 @@ The settings page has three sections:
|
|||||||
|
|
||||||
* **QuickBooks connection**: client ID and secret, webhook token, sandbox, when the access token expires, and Connect to QuickBooks.
|
* **QuickBooks connection**: client ID and secret, webhook token, sandbox, when the access token expires, and Connect to QuickBooks.
|
||||||
* **Synchronization**: customers, employees, estimates, invoices, payments, products/services (items) and accounts, with how many of each are stored, when each last synced and a **Sync** link for each (it re-reads every record of that type). **Sync changes** reads only what changed since the last sync; **Full sync** re-reads everything. The default income account for new products/services is shown here too.
|
* **Synchronization**: customers, employees, estimates, invoices, payments, products/services (items) and accounts, with how many of each are stored, when each last synced and a **Sync** link for each (it re-reads every record of that type). **Sync changes** reads only what changed since the last sync; **Full sync** re-reads everything. The default income account for new products/services is shown here too.
|
||||||
* **Billing**: estimate expiration, "Replaced by imported time" and the issues-from-estimates settings.
|
* **Billing**: estimate expiration, the labor products/services and the issues-from-estimates defaults.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class EstimateSyncService < SyncServiceBase
|
|||||||
|
|
||||||
map_attributes :doc_number, :txn_date
|
map_attributes :doc_number, :txn_date
|
||||||
map_attribute :total_amount, :total
|
map_attribute :total_amount, :total
|
||||||
# Man-hours: quantities of the products/services set as "Replaced by imported time"
|
# Man-hours: quantities of the labor products/services (plugin settings)
|
||||||
map_attribute(:hours) { |remote| RedmineQboBilling::ManHours.hours(remote) }
|
map_attribute(:hours) { |remote| RedmineQboBilling::ManHours.hours(remote) }
|
||||||
map_belongs_to :customer
|
map_belongs_to :customer
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class InvoiceSyncService < SyncServiceBase
|
|||||||
|
|
||||||
map_attributes :balance, :doc_number, :due_date, :txn_date
|
map_attributes :balance, :doc_number, :due_date, :txn_date
|
||||||
map_attribute :total_amount, :total
|
map_attribute :total_amount, :total
|
||||||
# Man-hours: quantities of the products/services set as "Replaced by imported time"
|
# Man-hours: quantities of the labor products/services (plugin settings)
|
||||||
map_attribute(:hours) { |remote| RedmineQboBilling::ManHours.hours(remote) }
|
map_attribute(:hours) { |remote| RedmineQboBilling::ManHours.hours(remote) }
|
||||||
map_attribute :qbo_updated_at, "meta_data.last_updated_time"
|
map_attribute :qbo_updated_at, "meta_data.last_updated_time"
|
||||||
map_belongs_to :customer
|
map_belongs_to :customer
|
||||||
|
|||||||
@@ -5,26 +5,22 @@
|
|||||||
min: 0, step: 1, size: 6 %>
|
min: 0, step: 1, size: 6 %>
|
||||||
<em class="info"><%= l(:text_estimate_expiration_days) %></em>
|
<em class="info"><%= l(:text_estimate_expiration_days) %></em>
|
||||||
</p>
|
</p>
|
||||||
|
<%# Labor: issues from estimates, lines imported time replaces on invoices, and hours for the business report.
|
||||||
|
While none are chosen, items named "Labor" are used and shown selected. %>
|
||||||
<p>
|
<p>
|
||||||
<label for="settings_replaceable_item_ids"><%= l(:label_replaceable_items) %></label>
|
<label for="settings_labor_item_ids"><%= l(:label_labor_items) %></label>
|
||||||
<%= hidden_field_tag 'settings[replaceable_item_ids][]', '', id: nil %>
|
<%= hidden_field_tag 'settings[labor_item_ids][]', '', id: nil %>
|
||||||
<%= select_tag 'settings[replaceable_item_ids][]',
|
<%= select_tag 'settings[labor_item_ids][]',
|
||||||
options_from_collection_for_select(Item.where(active: true).order(:name), :id, :name,
|
options_from_collection_for_select(Item.where(active: true).order(:name), :id, :name,
|
||||||
Array(@settings['replaceable_item_ids']).map(&:to_s)),
|
RedmineQboBilling::LaborItems.item_ids),
|
||||||
multiple: true, size: 8, id: 'settings_replaceable_item_ids' %>
|
multiple: true, size: 8, id: 'settings_labor_item_ids' %>
|
||||||
<em class="info"><%= l(:text_replaceable_items) %></em>
|
<em class="info"><%= l(:text_labor_items) %></em>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%# Issues from estimates (moved from redmine_qbo_calendar; its old values are shown until these are saved) %>
|
|
||||||
<% issue_builder = RedmineQboBilling::EstimateIssueBuilder %>
|
<% issue_builder = RedmineQboBilling::EstimateIssueBuilder %>
|
||||||
<fieldset class="box tabular">
|
<fieldset class="box tabular">
|
||||||
<legend><%= l(:label_estimate_issue_settings) %></legend>
|
<legend><%= l(:label_estimate_issue_settings) %></legend>
|
||||||
<p>
|
|
||||||
<label for="settings_issue_item_codes"><%= l(:label_estimate_item_codes) %></label>
|
|
||||||
<%= text_area_tag 'settings[issue_item_codes]', issue_builder.item_codes.join("\n"), rows: 5, cols: 30, id: 'settings_issue_item_codes' %>
|
|
||||||
<em class="info"><%= l(:text_estimate_item_codes_info) %></em>
|
|
||||||
</p>
|
|
||||||
<p>
|
<p>
|
||||||
<label for="settings_issue_default_project_id"><%= l(:label_default_project) %></label>
|
<label for="settings_issue_default_project_id"><%= l(:label_default_project) %></label>
|
||||||
<%= select_tag 'settings[issue_default_project_id]',
|
<%= select_tag 'settings[issue_default_project_id]',
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
data: {
|
data: {
|
||||||
document: form.document,
|
document: form.document,
|
||||||
import_url: (import_options_qbo_invoices_path if invoice),
|
import_url: (import_options_qbo_invoices_path if invoice),
|
||||||
replaceable_item_ids: (RedmineQboBilling::InvoiceWriter.replaceable_item_ids if invoice),
|
labor_item_ids: (RedmineQboBilling::LaborItems.item_ids if invoice),
|
||||||
items_url: items_qbo_estimates_path,
|
items_url: items_qbo_estimates_path,
|
||||||
customer_info_url: customer_info_qbo_estimates_path,
|
customer_info_url: customer_info_qbo_estimates_path,
|
||||||
saved_subtotal: (form.persisted? ? form.subtotal.to_s('F') : ''),
|
saved_subtotal: (form.persisted? ? form.subtotal.to_s('F') : ''),
|
||||||
|
|||||||
@@ -414,9 +414,9 @@ $(function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// The invoice's lines, for ticking the ones the time replaces (e.g. the estimate's labor lines).
|
// The invoice's lines, for ticking the ones the time replaces (e.g. the estimate's labor lines).
|
||||||
// When products/services are set as replaceable by time in the plugin settings, only lines with one of
|
// Only lines with one of the labor products/services (plugin settings) are offered; if none are known,
|
||||||
// them are offered; with none set, every line is.
|
// every line is.
|
||||||
var replaceable = ($form.data('replaceableItemIds') || []).map(String);
|
var replaceable = ($form.data('laborItemIds') || []).map(String);
|
||||||
var fillReplaceList = function () {
|
var fillReplaceList = function () {
|
||||||
var $list = $('#qbo-import-replace').empty();
|
var $list = $('#qbo-import-replace').empty();
|
||||||
rows().each(function () {
|
rows().each(function () {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
<% if proposals.empty? %>
|
<% if proposals.empty? %>
|
||||||
<p class="nodata">
|
<p class="nodata">
|
||||||
<%= l(:error_no_labor_lines_found) %>
|
<%= l(:error_no_labor_lines_found) %>
|
||||||
(<%= l(:label_estimate_item_codes) %>: <%= RedmineQboBilling::EstimateIssueBuilder.item_codes.join(', ') %>)
|
(<%= l(:label_labor_items) %>: <%= RedmineQboBilling::LaborItems.names.join(', ') %>)
|
||||||
<% if User.current.admin? %>
|
<% if User.current.admin? %>
|
||||||
· <%= link_to l(:label_settings), plugin_settings_path(id: 'redmine_qbo') %>
|
· <%= link_to l(:label_settings), plugin_settings_path(id: 'redmine_qbo') %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -205,12 +205,14 @@ en:
|
|||||||
label_item_new: "New Item"
|
label_item_new: "New Item"
|
||||||
label_items: "Items"
|
label_items: "Items"
|
||||||
label_management_and_sync: "Synchronization"
|
label_management_and_sync: "Synchronization"
|
||||||
|
label_labor_items: "Labor products/services"
|
||||||
|
text_labor_items: "Products/services billed as labor hours, e.g. Labor. Used to create issues from an estimate's labor lines (and an appointment's minimum hours), to offer an invoice's labor lines to be replaced by imported time, and to total hours on estimates and invoices for the business report (sync estimates and invoices after changing). While none are chosen, products/services named Labor are used. Ctrl/Cmd-click to pick several."
|
||||||
label_qbo_connection: "QuickBooks connection"
|
label_qbo_connection: "QuickBooks connection"
|
||||||
label_qbo_records: "Records"
|
label_qbo_records: "Records"
|
||||||
label_employee_plural: "Employees"
|
label_employee_plural: "Employees"
|
||||||
label_sync_changes: "Sync changes"
|
label_sync_changes: "Sync changes"
|
||||||
label_full_sync: "Full sync"
|
label_full_sync: "Full sync"
|
||||||
text_qbo_sync_info: "Sync changes reads what changed in QuickBooks since the last sync; Full sync and each type's Sync re-read every record (e.g. after changing \"Replaced by imported time\", sync estimates and invoices). Webhooks keep things current in between."
|
text_qbo_sync_info: "Sync changes reads what changed in QuickBooks since the last sync; Full sync and each type's Sync re-read every record (e.g. after changing the labor products/services, sync estimates and invoices). Webhooks keep things current in between."
|
||||||
text_default_account_info: "New products/services go in this income account; set it on the Accounts page."
|
text_default_account_info: "New products/services go in this income account; set it on the Accounts page."
|
||||||
label_never_synced: "Never synced"
|
label_never_synced: "Never synced"
|
||||||
label_no: "No"
|
label_no: "No"
|
||||||
@@ -247,7 +249,6 @@ en:
|
|||||||
label_new_invoice: "New invoice"
|
label_new_invoice: "New invoice"
|
||||||
label_open_estimates: "Open estimates"
|
label_open_estimates: "Open estimates"
|
||||||
label_replace_lines: "Replace these lines"
|
label_replace_lines: "Replace these lines"
|
||||||
label_replaceable_items: "Replaced by imported time"
|
|
||||||
label_time_badge: "Time"
|
label_time_badge: "Time"
|
||||||
notice_invoice_saved_and_sent: "Invoice #%{number} saved in QuickBooks and emailed to %{email}"
|
notice_invoice_saved_and_sent: "Invoice #%{number} saved in QuickBooks and emailed to %{email}"
|
||||||
notice_invoice_saved_in_quickbooks: "Invoice #%{number} saved in QuickBooks"
|
notice_invoice_saved_in_quickbooks: "Invoice #%{number} saved in QuickBooks"
|
||||||
@@ -256,7 +257,6 @@ en:
|
|||||||
text_invoice_from_estimate: "Made from estimate #%{number}. The estimate is closed when the invoice is saved."
|
text_invoice_from_estimate: "Made from estimate #%{number}. The estimate is closed when the invoice is saved."
|
||||||
text_invoice_many_vehicles: "These work orders are for more than one vehicle:"
|
text_invoice_many_vehicles: "These work orders are for more than one vehicle:"
|
||||||
text_line_bills_time: "Bills a QuickBooks time activity; saving marks the time as billed"
|
text_line_bills_time: "Bills a QuickBooks time activity; saving marks the time as billed"
|
||||||
text_replaceable_items: "Products/services that billable time can replace on invoices, e.g. Labor. Only invoice lines with these are offered under Replace these lines when time is imported. Leave empty to offer every line. They are also the man-hours counted on estimates and invoices for the business report (run a full sync after changing them). Ctrl/Cmd-click to pick several."
|
|
||||||
text_replace_lines: "Tick the lines the time replaces (e.g. the estimate's labor lines). The time goes where the first ticked line is."
|
text_replace_lines: "Tick the lines the time replaces (e.g. the estimate's labor lines). The time goes where the first ticked line is."
|
||||||
|
|
||||||
# Issues from estimates (moved from redmine_qbo_calendar)
|
# Issues from estimates (moved from redmine_qbo_calendar)
|
||||||
@@ -270,7 +270,6 @@ en:
|
|||||||
label_estimate_issue_fields: "Issue fields"
|
label_estimate_issue_fields: "Issue fields"
|
||||||
label_estimate_issue_settings: "Issues from estimates"
|
label_estimate_issue_settings: "Issues from estimates"
|
||||||
label_estimate_item: "Item"
|
label_estimate_item: "Item"
|
||||||
label_estimate_item_codes: "Estimate item codes"
|
|
||||||
label_estimate_line_already_created: "Already created"
|
label_estimate_line_already_created: "Already created"
|
||||||
label_issue_template: "Template"
|
label_issue_template: "Template"
|
||||||
label_no_issue_template: "(no template)"
|
label_no_issue_template: "(no template)"
|
||||||
@@ -282,7 +281,6 @@ en:
|
|||||||
text_estimate_issue_fields_info: "Entered once and applied to every created issue whose tracker uses the field. Fields marked * are required by the selected trackers."
|
text_estimate_issue_fields_info: "Entered once and applied to every created issue whose tracker uses the field. Fields marked * are required by the selected trackers."
|
||||||
text_estimate_issues_hint: "The subject comes from the estimate line's description and estimated hours from its quantity. Edit anything before creating. New issues are related to each other and to issues already created from this estimate."
|
text_estimate_issues_hint: "The subject comes from the estimate line's description and estimated hours from its quantity. Edit anything before creating. New issues are related to each other and to issues already created from this estimate."
|
||||||
text_estimate_issues_template_hint: "The subject comes from the estimate line's description and estimated hours from its quantity. A template supplies the issue's description. New issues are related to each other and to issues already created from this estimate."
|
text_estimate_issues_template_hint: "The subject comes from the estimate line's description and estimated hours from its quantity. A template supplies the issue's description. New issues are related to each other and to issues already created from this estimate."
|
||||||
text_estimate_item_codes_info: "QBO item names that can become issues, one per line (e.g. Labor, Alignments). Matches the full item name or any part of a Category:Item name, ignoring case. Their quantities are also an estimate's labor hours (an appointment's hours can't be less)."
|
|
||||||
|
|
||||||
# Payments
|
# Payments
|
||||||
button_print_payment: "Print"
|
button_print_payment: "Print"
|
||||||
@@ -332,7 +330,7 @@ en:
|
|||||||
label_report_invoiced_of_spent: "Invoiced vs. spent hours"
|
label_report_invoiced_of_spent: "Invoiced vs. spent hours"
|
||||||
label_report_spent_of_estimated: "Spent vs. issues' estimated hours"
|
label_report_spent_of_estimated: "Spent vs. issues' estimated hours"
|
||||||
text_report_needs_sync: "%{count} estimates or invoices in this period don't have their total or hours yet. Run a full sync from QuickBooks to fill them in."
|
text_report_needs_sync: "%{count} estimates or invoices in this period don't have their total or hours yet. Run a full sync from QuickBooks to fill them in."
|
||||||
text_report_notes: "Estimates, invoices and payments count by their QuickBooks date; their hours are the quantities of the products/services set as \"Replaced by imported time\" (or the estimate item codes while that's blank). Issues' estimated time counts issues created in the period, without subtasks. Spent time counts time logged in the period."
|
text_report_notes: "Estimates, invoices and payments count by their QuickBooks date; their hours are the quantities of the labor products/services. Issues' estimated time counts issues created in the period, without subtasks. Spent time counts time logged in the period."
|
||||||
notice_payment_not_found: "Payment not found in QuickBooks"
|
notice_payment_not_found: "Payment not found in QuickBooks"
|
||||||
notice_payment_saved: "Payment of %{amount} saved in QuickBooks"
|
notice_payment_saved: "Payment of %{amount} saved in QuickBooks"
|
||||||
text_no_payment_methods: "QuickBooks' payment methods couldn't be read. Check the QuickBooks connection."
|
text_no_payment_methods: "QuickBooks' payment methods couldn't be read. Check the QuickBooks connection."
|
||||||
|
|||||||
@@ -26,57 +26,34 @@ module RedmineQboBilling
|
|||||||
class EstimateIssueBuilder
|
class EstimateIssueBuilder
|
||||||
include Redmine::I18n
|
include Redmine::I18n
|
||||||
|
|
||||||
DEFAULT_ITEM_CODES = ['Labor'].freeze
|
|
||||||
|
|
||||||
Proposal = Struct.new(:line_id, :item_name, :description, :hours, :existing_issue, keyword_init: true) do
|
Proposal = Struct.new(:line_id, :item_name, :description, :hours, :existing_issue, keyword_init: true) do
|
||||||
def created?
|
def created?
|
||||||
existing_issue.present?
|
existing_issue.present?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Item codes from the plugin settings, one per line (commas also accepted). Until they're set here, the
|
|
||||||
# ones redmine_qbo_calendar used are kept.
|
|
||||||
def self.item_codes
|
|
||||||
raw = setting('issue_item_codes', 'item_codes').to_s
|
|
||||||
codes = raw.split(/[\n,]/).map(&:strip).reject(&:blank?)
|
|
||||||
codes.presence || DEFAULT_ITEM_CODES
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.default_tracker_id
|
def self.default_tracker_id
|
||||||
setting('issue_default_tracker_id', 'default_tracker_id').to_i
|
setting('issue_default_tracker_id').to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.default_project_id
|
def self.default_project_id
|
||||||
setting('issue_default_project_id', 'default_project_id').to_i
|
setting('issue_default_project_id').to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
# This plugin's setting, or redmine_qbo_calendar's old one while this one is blank
|
def self.setting(key)
|
||||||
def self.setting(key, calendar_key)
|
(Setting.plugin_redmine_qbo || {})[key]
|
||||||
ours = (Setting.plugin_redmine_qbo || {})[key]
|
|
||||||
return ours if ours.present?
|
|
||||||
|
|
||||||
calendar = Setting.respond_to?(:plugin_redmine_qbo_calendar) ? (Setting.plugin_redmine_qbo_calendar || {}) : {}
|
|
||||||
calendar[calendar_key]
|
|
||||||
rescue StandardError
|
rescue StandardError
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# A line matches a code if its QBO item name equals the code, or any part of a
|
# The estimate's labor hours: the quantities of its labor lines (LaborItems)
|
||||||
# "Category:Item" name does. Case-insensitive.
|
|
||||||
def self.item_matches?(item_name, codes = item_codes)
|
|
||||||
name = item_name.to_s.strip.downcase
|
|
||||||
parts = name.split(':').map(&:strip)
|
|
||||||
codes.map { |c| c.strip.downcase }.any? { |code| name == code || parts.include?(code) }
|
|
||||||
end
|
|
||||||
|
|
||||||
# The estimate's labor hours: the quantities of its lines whose item matches an item code
|
|
||||||
# (e.g. for an appointment's hours, which shouldn't be less)
|
# (e.g. for an appointment's hours, which shouldn't be less)
|
||||||
def self.labor_hours(estimate)
|
def self.labor_hours(estimate)
|
||||||
return 0.0 if estimate.nil?
|
return 0.0 if estimate.nil?
|
||||||
|
|
||||||
Array(estimate.line_items).sum do |line|
|
Array(estimate.line_items).sum do |line|
|
||||||
detail = line.respond_to?(:sales_line_item_detail) ? line.sales_line_item_detail : nil
|
detail = line.respond_to?(:sales_line_item_detail) ? line.sales_line_item_detail : nil
|
||||||
next 0.0 if detail.nil? || detail.item_ref.nil? || !item_matches?(detail.item_ref.name)
|
next 0.0 if detail.nil? || !LaborItems.match?(detail.item_ref)
|
||||||
detail.quantity.to_f
|
detail.quantity.to_f
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -172,7 +149,8 @@ module RedmineQboBilling
|
|||||||
def build_proposals
|
def build_proposals
|
||||||
return [] if estimate.blank?
|
return [] if estimate.blank?
|
||||||
|
|
||||||
codes = self.class.item_codes
|
ids = LaborItems.ids
|
||||||
|
codes = LaborItems.codes
|
||||||
links = QboEstimateLineIssue.where(estimate_id: estimate.id).includes(:issue).index_by(&:line_id)
|
links = QboEstimateLineIssue.where(estimate_id: estimate.id).includes(:issue).index_by(&:line_id)
|
||||||
|
|
||||||
Array(estimate.line_items).each_with_index.filter_map do |line, index|
|
Array(estimate.line_items).each_with_index.filter_map do |line, index|
|
||||||
@@ -180,7 +158,7 @@ module RedmineQboBilling
|
|||||||
next if detail.nil? || detail.item_ref.nil?
|
next if detail.nil? || detail.item_ref.nil?
|
||||||
|
|
||||||
item_name = detail.item_ref.name.to_s.strip
|
item_name = detail.item_ref.name.to_s.strip
|
||||||
next unless self.class.item_matches?(item_name, codes)
|
next unless LaborItems.match?(detail.item_ref, ids: ids, codes: codes)
|
||||||
|
|
||||||
# The subject comes from the line's description, so lines without one are skipped
|
# The subject comes from the line's description, so lines without one are skipped
|
||||||
description = line.description.to_s.strip
|
description = line.description.to_s.strip
|
||||||
|
|||||||
@@ -39,14 +39,6 @@ module RedmineQboBilling
|
|||||||
EstimateWriter
|
EstimateWriter
|
||||||
end
|
end
|
||||||
|
|
||||||
# The plugin setting "Replaced by imported time": only lines with these products/services are offered
|
|
||||||
# under Replace these lines when time is imported (e.g. an estimate's Labor lines); empty offers every line
|
|
||||||
def replaceable_item_ids
|
|
||||||
Array(Setting.plugin_redmine_qbo['replaceable_item_ids']).map(&:to_s).reject(&:blank?).uniq
|
|
||||||
rescue StandardError
|
|
||||||
[]
|
|
||||||
end
|
|
||||||
|
|
||||||
# A blank invoice for the customer, dated today
|
# A blank invoice for the customer, dated today
|
||||||
def new_form(customer: nil, user: User.current)
|
def new_form(customer: nil, user: User.current)
|
||||||
EstimateForm.new(
|
EstimateForm.new(
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
#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
|
||||||
|
# The labor products/services (plugin setting "Labor products/services", e.g. Labor). They are used to:
|
||||||
|
# * create issues from an estimate's labor lines (and work out its labor hours for appointments)
|
||||||
|
# * offer an invoice's labor lines to be replaced by imported time
|
||||||
|
# * total the man-hours on estimates and invoices for the business report
|
||||||
|
#
|
||||||
|
# While none are chosen, products/services named "Labor" are used (the full name or any part of a
|
||||||
|
# "Category:Item" name, ignoring case).
|
||||||
|
module LaborItems
|
||||||
|
DEFAULT_CODES = ['Labor'].freeze
|
||||||
|
|
||||||
|
module_function
|
||||||
|
|
||||||
|
# The chosen products/services' QuickBooks ids
|
||||||
|
def ids(settings = plugin_settings)
|
||||||
|
Array(settings['labor_item_ids']).map(&:to_s).reject(&:blank?).uniq
|
||||||
|
end
|
||||||
|
|
||||||
|
# Item names matched while no products/services are chosen
|
||||||
|
def codes
|
||||||
|
DEFAULT_CODES
|
||||||
|
end
|
||||||
|
|
||||||
|
# True when a line's product/service (its ItemRef) is labor
|
||||||
|
def match?(item_ref, ids: self.ids, codes: nil)
|
||||||
|
return false if item_ref.nil?
|
||||||
|
return ids.include?(item_ref.value.to_s) if ids.any?
|
||||||
|
|
||||||
|
name_matches?(item_ref.name, codes || self.codes)
|
||||||
|
end
|
||||||
|
|
||||||
|
def name_matches?(item_name, codes)
|
||||||
|
name = item_name.to_s.strip.downcase
|
||||||
|
return false if name.empty?
|
||||||
|
|
||||||
|
parts = name.split(':').map(&:strip)
|
||||||
|
codes.map { |c| c.strip.downcase }.any? { |code| name == code || parts.include?(code) }
|
||||||
|
end
|
||||||
|
|
||||||
|
# The labor products/services as ids: the chosen ones, else the local items whose names match the codes
|
||||||
|
# (for the settings page and the invoice's Replace these lines list)
|
||||||
|
def item_ids
|
||||||
|
chosen = ids
|
||||||
|
return chosen if chosen.any?
|
||||||
|
|
||||||
|
list = codes
|
||||||
|
Item.where(active: true).pluck(:id, :name).select { |_, name| name_matches?(name, list) }.map { |id, _| id.to_s }
|
||||||
|
rescue StandardError
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
|
||||||
|
# Names to show, e.g. when an estimate has no labor lines
|
||||||
|
def names
|
||||||
|
chosen = ids
|
||||||
|
return codes if chosen.empty?
|
||||||
|
|
||||||
|
Item.where(id: chosen).pluck(:name).presence || chosen
|
||||||
|
rescue StandardError
|
||||||
|
chosen
|
||||||
|
end
|
||||||
|
|
||||||
|
def plugin_settings
|
||||||
|
Setting.plugin_redmine_qbo || {}
|
||||||
|
rescue StandardError
|
||||||
|
{}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -10,17 +10,16 @@
|
|||||||
|
|
||||||
|
|
||||||
module RedmineQboBilling
|
module RedmineQboBilling
|
||||||
# The man-hours on a QuickBooks estimate or invoice: the quantities of its lines whose product/service is set
|
# The man-hours on a QuickBooks estimate or invoice: the quantities of its labor lines (the plugin setting
|
||||||
# as "Replaced by imported time" (e.g. Labor), including lines inside bundles. While that setting is blank,
|
# "Labor products/services", see LaborItems), including lines inside bundles.
|
||||||
# lines matching the estimate item codes are counted instead (counting every line would include parts).
|
|
||||||
module ManHours
|
module ManHours
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
def hours(document, item_ids: InvoiceWriter.replaceable_item_ids, codes: nil)
|
def hours(document, item_ids: LaborItems.ids, codes: nil)
|
||||||
return 0.0 if document.nil?
|
return 0.0 if document.nil?
|
||||||
|
|
||||||
ids = Array(item_ids).map(&:to_s).reject(&:blank?)
|
ids = Array(item_ids).map(&:to_s).reject(&:blank?)
|
||||||
codes ||= EstimateIssueBuilder.item_codes if ids.empty?
|
codes ||= LaborItems.codes if ids.empty?
|
||||||
sum_lines(document.line_items, ids, codes).round(2)
|
sum_lines(document.line_items, ids, codes).round(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -30,7 +29,7 @@ module RedmineQboBilling
|
|||||||
next sum_lines(group.line_items, ids, codes) if group
|
next sum_lines(group.line_items, ids, codes) if group
|
||||||
|
|
||||||
detail = sales_detail(line)
|
detail = sales_detail(line)
|
||||||
next 0.0 unless detail&.item_ref && man_hour_item?(detail.item_ref, ids, codes)
|
next 0.0 unless detail && LaborItems.match?(detail.item_ref, ids: ids, codes: codes)
|
||||||
detail.quantity.to_f
|
detail.quantity.to_f
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -40,10 +39,5 @@ module RedmineQboBilling
|
|||||||
elsif line.respond_to?(:sales_item_line_detail) then line.sales_item_line_detail
|
elsif line.respond_to?(:sales_item_line_detail) then line.sales_item_line_detail
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def man_hour_item?(ref, ids, codes)
|
|
||||||
return ids.include?(ref.value.to_s) if ids.any?
|
|
||||||
EstimateIssueBuilder.item_matches?(ref.name, codes)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Reference in new issue
Block a user