From 0d35cffb835b38dc0055a62e4f5bbffb82872ce2 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 31 Oct 2026 13:51:19 -0400 Subject: [PATCH] Cost performance index on the business report CPI = invoiced hours / spent hours, for the period and for each month, colour-coded: green at 1.00 or more, yellow below 1, red below 0.80. It replaces the invoiced-vs-spent percentage (the same figure). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM --- README.md | 2 +- app/views/qbo_reports/index.html.erb | 22 +++++++++++++++++++++- config/locales/en.yml | 4 +++- lib/redmine_qbo_billing/business_report.rb | 20 ++++++++++++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d6f0dd0..99ad42a 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ Estimates and invoices keep their number, date, customer, total and **man-hours* **Business report** in the top menu compares, for a period (this or last month, quarter or year, or custom dates): * **Sales**: estimates written, invoices written and payments received (totals and counts), invoiced vs. estimated, collected vs. invoiced, and what's still owed on those invoices. -* **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 spent vs. estimated, and the **cost performance index** (CPI = invoiced hours ÷ spent hours): green at 1.00 or more, yellow below 1, red below 0.80. Each month shows its CPI too. * **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. While estimates, invoices or payments are syncing, the report says so (with how many have been read) and refreshes every 30 seconds; the settings page's Synchronization table shows the same per type. 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. diff --git a/app/views/qbo_reports/index.html.erb b/app/views/qbo_reports/index.html.erb index 6a7b7b4..dabf276 100644 --- a/app/views/qbo_reports/index.html.erb +++ b/app/views/qbo_reports/index.html.erb @@ -91,8 +91,16 @@ <% end %> + <% cpi_badge = lambda do |cpi| + level = RedmineQboBilling::BusinessReport.cpi_level(cpi) + content_tag(:span, cpi.nil? ? '–' : format('%.2f', cpi), class: "qbo-cpi qbo-cpi-#{level || 'none'}") + end %> +

+ <%= l(:label_report_cpi) %> + <%= cpi_badge.call(@report.cpi) %> + <%= l(:text_report_cpi) %> +

- <%= l(:label_report_invoiced_of_spent) %>: <%= pct.call(ratios[:invoiced_of_spent]) %>
<%= l(:label_report_spent_of_estimated) %>: <%= pct.call(ratios[:spent_of_estimated]) %>

@@ -111,6 +119,7 @@ <%= l(:label_report_issue_hours) %> <%= l(:label_report_invoice_hours) %> <%= l(:label_report_spent_hours) %> + <%= l(:label_report_cpi_short) %> @@ -124,6 +133,7 @@ <%= fmt_hours.call(row[:issue_hours]) %> <%= fmt_hours.call(row[:invoice_hours]) %> <%= fmt_hours.call(row[:spent_hours]) %> + <%= cpi_badge.call(RedmineQboBilling::BusinessReport.cpi(row[:invoice_hours], row[:spent_hours])) %> <% end %> @@ -137,6 +147,7 @@ <%= fmt_hours.call(hours[:issue_hours]) %> <%= fmt_hours.call(hours[:invoice_hours]) %> <%= fmt_hours.call(hours[:spent_hours]) %> + <%= cpi_badge.call(@report.cpi) %> @@ -154,6 +165,15 @@ .qbo-bar-payments, .qbo-bar-spent_hours { background: #5aa05a; } .qbo-bar-issue_hours { background: #9b7fc0; } .qbo-report-ratios { margin: 8px 4px; line-height: 1.7; } + .qbo-report-cpi { margin: 10px 4px 4px; } + .qbo-report-cpi .qbo-cpi-label { font-weight: 600; margin-right: 6px; } + .qbo-report-cpi .qbo-cpi { font-size: 1.3em; padding: 3px 12px; } + .qbo-report-cpi em.info { display: block; margin-top: 4px; } + .qbo-cpi { display: inline-block; font-weight: 700; padding: 1px 8px; border-radius: 10px; background: #eceef1; color: #393a3d; } + .qbo-cpi-poor { background: #fdecea; color: #b71c1c; } + .qbo-cpi-under { background: #fff4d6; color: #8a6100; } + .qbo-cpi-good { background: #e6f4e4; color: #108000; } + table.qbo-report-months td.cpi, table.qbo-report-months th.cpi { text-align: center; } .qbo-report-range { color: #666; margin: 4px 0 10px; } .qbo-report-syncing ul { display: inline-block; text-align: left; margin: 6px 0 0; } table.qbo-report-months td, table.qbo-report-months th { text-align: right; white-space: nowrap; } diff --git a/config/locales/en.yml b/config/locales/en.yml index 2c75c99..3b21291 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -326,7 +326,9 @@ en: label_report_invoiced_of_estimated: "Invoiced vs. estimated" label_report_collected_of_invoiced: "Collected vs. invoiced" label_report_open_balance: "Still owed on these invoices" - label_report_invoiced_of_spent: "Invoiced vs. spent hours" + label_report_cpi: "Cost performance index (CPI)" + label_report_cpi_short: "CPI" + text_report_cpi: "Invoiced hours ÷ spent hours. 1.00 or more (green): every hour worked was billed; below 1 (yellow): some time wasn't billed; below 0.80 (red): a fifth or more wasn't." label_report_spent_of_estimated: "Spent vs. issues' estimated hours" text_report_syncing: "QuickBooks is still syncing, so these figures are incomplete until it finishes. This page refreshes every 30 seconds." text_qbo_sync_running: "syncing, %{count} read so far (started %{time})" diff --git a/lib/redmine_qbo_billing/business_report.rb b/lib/redmine_qbo_billing/business_report.rb index 567aab9..4b019c6 100644 --- a/lib/redmine_qbo_billing/business_report.rb +++ b/lib/redmine_qbo_billing/business_report.rb @@ -79,6 +79,26 @@ module RedmineQboBilling } end + # Cost performance index: invoiced hours / spent hours (e.g. 0.85), or nil without spent time. Below + # CPI_WARNING (0.8) is poor, below 1 is under, 1 or more is on or over (more billed than worked). + CPI_WARNING = 0.8 + + def self.cpi(invoice_hours, spent_hours) + spent = spent_hours.to_f + spent.positive? ? (invoice_hours.to_f / spent).round(2) : nil + end + + # :poor (below 0.8), :under (below 1) or :good (1 or more); nil without a CPI + def self.cpi_level(cpi) + return nil if cpi.nil? + return :poor if cpi < CPI_WARNING + cpi < 1 ? :under : :good + end + + def cpi + self.class.cpi(hours[:invoice_hours], hours[:spent_hours]) + end + # Percentages comparing the figures (nil when there's nothing to compare against) def ratios {