mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-18 02:20:37 -05:00
Business report without sales tax; invoices paid in full; paid dates
Estimates and invoices written are reported without sales tax (new
estimates.tax_amount, filled in by the estimate sync), and a new
Invoices paid in full figure counts invoices on the day they were paid
in full. Payments stay as received, so collected vs. invoiced compares
them with the invoices' totals with tax.
Paid invoices show the day they were paid in full on the customer's
invoice list and the invoice page ("Paid 11/03/2026").
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5b6c1ed2c2
commit
a72b0fa73b
10 files changed
+152
-32
No files matched your search
@@ -97,7 +97,7 @@ Customer records are automatically updated in the local database when changes oc
|
||||
|
||||
### Estimates, Invoices and Payments
|
||||
|
||||
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.
|
||||
Estimates and invoices keep their number, date, customer, total, sales tax 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.
|
||||
|
||||
---
|
||||
|
||||
@@ -128,7 +128,7 @@ Estimates and invoices keep their number, date, customer, total and **man-hours*
|
||||
* 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.
|
||||
* **Custom fields from the work orders**: the issues behind an invoice are the ones its time lines and lineitems estimates name. Plugins can fill custom fields from them when they're imported, and block a save (e.g. redmine_qbo_vehicles fills the VIN and mileage and allows one vehicle per invoice). On its own, redmine_qbo leaves the boxes as typed.
|
||||
* **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 show their status, worked out from the balance and due date like QuickBooks' invoice list: **Paid**, **Partially paid**, **Overdue**, **Open** or **Voided** (a zero total), on the customer page's invoice list and the invoice page.
|
||||
* Invoices show their status, worked out from the balance and due date like QuickBooks' invoice list: **Paid**, **Partially paid**, **Overdue**, **Open** or **Voided** (a zero total), on the customer page's invoice list and the invoice page. A paid invoice shows the day it was paid in full (e.g. **Paid 11/03/2026**): the later of its date and the last payment or credit memo applied to it.
|
||||
* 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.
|
||||
|
||||
### Payments
|
||||
@@ -158,7 +158,7 @@ Refunds for canceled orders and returned parts, following SOP-OPS-014, so they d
|
||||
|
||||
**Business report** in the top menu compares, for a period (this or last week, month, quarter or year, or custom dates; weeks start on the day set in Redmine's *Start calendars on* setting, Monday when it follows the language):
|
||||
|
||||
* **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.
|
||||
* **Sales**: estimates written, invoices written, invoices paid in full (on the day each was paid in full) and payments received (totals and counts), invoiced vs. estimated, collected vs. invoiced, and what's still owed on those invoices. Estimates and invoices are without sales tax (QuickBooks' tax on each is cached with it); payments are as received, so collected vs. invoiced compares them with the invoices' totals with tax.
|
||||
* **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.
|
||||
* **Charts**: above each set of bars, a line chart of the same figures in the same colors (Chart.js 4.5.1, MIT licensed, bundled with the plugin in assets/javascripts so it doesn't clash with other plugins' copies such as redmine_indicator's Chart.js 2), with a point per day for a week, per week for up to about three months, and per month beyond. Hovering a point shows its figures. **Compare with last year** adds last year's lines, dashed and faded, without reloading: days and weeks go back 52 weeks so weekdays line up, months go back to the same month. Clicking a figure in the legend hides it (and its last-year line); clicking *last year* stops comparing. Today's line stops at today.
|
||||
* **By month**: every figure month by month, with totals.
|
||||
|
||||
@@ -30,6 +30,8 @@ class EstimateSyncService < SyncServiceBase
|
||||
map_attribute :txn_status
|
||||
# Man-hours: quantities of the labor products/services (plugin settings)
|
||||
map_attribute(:hours) { |remote| RedmineQboBilling::ManHours.hours(remote) }
|
||||
# Sales tax, so the business report can compare estimates and invoices without it
|
||||
map_attribute(:tax_amount) { |remote| RedmineQboBilling::InvoicePaidOn.tax(remote) }
|
||||
map_belongs_to :customer
|
||||
|
||||
end
|
||||
@@ -18,7 +18,7 @@
|
||||
<b><%= link_to "##{invoice.doc_number}", invoice_path(invoice), target: :_blank %></b> <%= invoice.txn_date %>
|
||||
<%# Paid / partially paid / overdue / open / voided, from the cached balance and due date %>
|
||||
<% if (status = invoice.status) %>
|
||||
<span class="qbo-estimate-status qbo-invoice-status-<%= status %>"><%= RedmineQboBilling::InvoiceStatus.label(status) %></span>
|
||||
<span class="qbo-estimate-status qbo-invoice-status-<%= status %>"><%= RedmineQboBilling::InvoiceStatus.label(status, paid_on: invoice.paid_on) %></span>
|
||||
<% end %>
|
||||
<%= render partial: 'qbo_invoices/invoice_actions', locals: { invoice: invoice } if RedmineQboBilling.invoice_writer? %>
|
||||
</div>
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
due_date: RedmineQboBilling::EstimateForm.date(form.due_date),
|
||||
today: User.current.today) %>
|
||||
<% if status %>
|
||||
<span class="qbo-estimate-status qbo-invoice-status-<%= status %>"><%= RedmineQboBilling::InvoiceStatus.label(status) %></span>
|
||||
<% paid_on = Invoice.where(id: form.id).pick(:paid_on) if status == :paid && form.id.present? %>
|
||||
<span class="qbo-estimate-status qbo-invoice-status-<%= status %>"><%= RedmineQboBilling::InvoiceStatus.label(status, paid_on: paid_on) %></span>
|
||||
<% end %>
|
||||
<% elsif !invoice && form.txn_status.present? %>
|
||||
<span class="qbo-estimate-status qbo-estimate-status-<%= form.txn_status.downcase %>"><%= form.txn_status %></span>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<% money = @report.money %>
|
||||
<% hours = @report.hours %>
|
||||
<% ratios = @report.ratios %>
|
||||
<% max_money = [money[:estimates][:total], money[:invoices][:total], money[:payments][:total]].max.to_f %>
|
||||
<% max_money = [money[:estimates][:total], money[:invoices][:total], money[:paid][:total], money[:payments][:total]].max.to_f %>
|
||||
<% max_hours = hours.values.max.to_f %>
|
||||
<% bar = ->(value, max) { max > 0 ? (value.to_f / max * 100).round(1) : 0 } %>
|
||||
<% fmt_hours = ->(h) { format('%.1f', h.to_f) } %>
|
||||
@@ -40,6 +40,7 @@
|
||||
end %>
|
||||
<% sales_series = chart_series.call([[:estimates, l(:label_report_estimates_written), '#628db6'],
|
||||
[:invoices, l(:label_report_invoices_written), '#e8a33d'],
|
||||
[:paid, l(:label_report_invoices_paid), '#c0504d'],
|
||||
[:payments, l(:label_report_payments_received), '#5aa05a']]) %>
|
||||
<% hours_series = chart_series.call([[:estimate_hours, l(:label_report_estimate_hours), '#628db6'],
|
||||
[:issue_hours, l(:label_report_issue_hours), '#9b7fc0'],
|
||||
@@ -132,7 +133,7 @@
|
||||
<table class="list qbo-report">
|
||||
<tbody>
|
||||
<% [[:estimates, l(:label_report_estimates_written)], [:invoices, l(:label_report_invoices_written)],
|
||||
[:payments, l(:label_report_payments_received)]].each do |key, label| %>
|
||||
[:paid, l(:label_report_invoices_paid)], [:payments, l(:label_report_payments_received)]].each do |key, label| %>
|
||||
<tr>
|
||||
<td class="name"><%= label %> <span class="count">(<%= money[key][:count] %>)</span></td>
|
||||
<td class="bar"><div class="qbo-bar qbo-bar-<%= key %>" style="width: <%= bar.call(money[key][:total], max_money) %>%"></div></td>
|
||||
@@ -146,6 +147,7 @@
|
||||
<%= l(:label_report_collected_of_invoiced) %>: <strong><%= pct.call(ratios[:collected_of_invoiced]) %></strong><br />
|
||||
<%= l(:label_report_open_balance) %>: <strong><%= number_to_currency(money[:invoices][:balance]) %></strong>
|
||||
</p>
|
||||
<p><em class="info"><%= l(:text_report_without_tax) %></em></p>
|
||||
</div>
|
||||
|
||||
<div class="splitcontentright">
|
||||
@@ -188,6 +190,7 @@
|
||||
<th class="month"><%= l(:label_month) %></th>
|
||||
<th><%= l(:label_report_estimates_written) %></th>
|
||||
<th><%= l(:label_report_invoices_written) %></th>
|
||||
<th><%= l(:label_report_invoices_paid) %></th>
|
||||
<th><%= l(:label_report_payments_received) %></th>
|
||||
<th class="hours-start"><%= l(:label_report_estimate_hours) %></th>
|
||||
<th><%= l(:label_report_issue_hours) %></th>
|
||||
@@ -202,6 +205,7 @@
|
||||
<td class="month"><%= ::I18n.t('date.abbr_month_names')[row[:month].month] %> <%= row[:month].year %></td>
|
||||
<td><%= number_to_currency(row[:estimates]) %></td>
|
||||
<td><%= number_to_currency(row[:invoices]) %></td>
|
||||
<td><%= number_to_currency(row[:paid]) %></td>
|
||||
<td><%= number_to_currency(row[:payments]) %></td>
|
||||
<td class="hours-start"><%= fmt_hours.call(row[:estimate_hours]) %></td>
|
||||
<td><%= fmt_hours.call(row[:issue_hours]) %></td>
|
||||
@@ -216,6 +220,7 @@
|
||||
<td class="month"><strong><%= l(:label_total) %></strong></td>
|
||||
<td><strong><%= number_to_currency(money[:estimates][:total]) %></strong></td>
|
||||
<td><strong><%= number_to_currency(money[:invoices][:total]) %></strong></td>
|
||||
<td><strong><%= number_to_currency(money[:paid][:total]) %></strong></td>
|
||||
<td><strong><%= number_to_currency(money[:payments][:total]) %></strong></td>
|
||||
<td class="hours-start"><strong><%= fmt_hours.call(hours[:estimate_hours]) %></strong></td>
|
||||
<td><strong><%= fmt_hours.call(hours[:issue_hours]) %></strong></td>
|
||||
@@ -237,6 +242,7 @@
|
||||
.qbo-bar { height: 14px; border-radius: 2px; min-width: 1px; background: #628db6; }
|
||||
.qbo-bar-invoices, .qbo-bar-invoice_hours { background: #e8a33d; }
|
||||
.qbo-bar-payments, .qbo-bar-spent_hours { background: #5aa05a; }
|
||||
.qbo-bar-paid { background: #c0504d; }
|
||||
.qbo-bar-issue_hours { background: #9b7fc0; }
|
||||
.qbo-report-ratios { margin: 8px 4px; line-height: 1.7; }
|
||||
.qbo-report-cpi { margin: 10px 4px 4px; }
|
||||
|
||||
@@ -289,6 +289,7 @@ en:
|
||||
label_invoice_date: "Invoice date"
|
||||
label_invoice_no: "Invoice no."
|
||||
label_invoice_status_paid: "Paid"
|
||||
label_invoice_status_paid_on: "Paid %{date}"
|
||||
label_invoice_status_partial: "Partially paid"
|
||||
label_invoice_status_overdue: "Overdue"
|
||||
label_invoice_status_open: "Open"
|
||||
@@ -383,6 +384,8 @@ en:
|
||||
label_report_last_year: "last year"
|
||||
label_report_estimates_written: "Estimates written"
|
||||
label_report_invoices_written: "Invoices written"
|
||||
label_report_invoices_paid: "Invoices paid in full"
|
||||
text_report_without_tax: "Estimates and invoices are without sales tax; invoices paid in full count on the day they were paid in full. Payments are as received, so collected vs. invoiced compares them with the invoices' totals with tax."
|
||||
label_report_payments_received: "Payments received"
|
||||
label_report_estimate_hours: "Estimated (estimates)"
|
||||
label_report_issue_hours: "Estimated (issues)"
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#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.
|
||||
|
||||
# An estimate's sales tax, cached like its total, so the business report can compare estimates and invoices
|
||||
# without tax. A full estimate sync fills it in for estimates synced before.
|
||||
class AddEstimateTax < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :estimates, :tax_amount, :decimal, precision: 15, scale: 2 unless column_exists?(:estimates, :tax_amount)
|
||||
end
|
||||
end
|
||||
@@ -12,7 +12,8 @@
|
||||
module RedmineQboBilling
|
||||
# Business figures for a date range, from the estimates, invoices and payments cached from QuickBooks and from
|
||||
# Redmine's issues and spent time:
|
||||
# money: estimates written, invoices written, payments received (totals and counts)
|
||||
# money: estimates written, invoices written, invoices paid in full, payments received (totals and counts);
|
||||
# estimates and invoices without sales tax (it isn't the shop's revenue), payments as received
|
||||
# hours: man-hours on estimates, issues' estimated time, man-hours invoiced, time spent
|
||||
# with a month-by-month breakdown. Estimates, invoices and payments count by their QuickBooks date, issues by
|
||||
# the day they were created (only issues without subtasks, so parents' totals aren't counted twice), and
|
||||
@@ -24,7 +25,7 @@ module RedmineQboBilling
|
||||
# Chart points: a day each for up to two weeks, a week each up to about three months, else a month each
|
||||
DAILY_UP_TO = 14
|
||||
WEEKLY_UP_TO = 93
|
||||
MONEY = %i[estimates invoices payments].freeze
|
||||
MONEY = %i[estimates invoices paid payments].freeze
|
||||
HOURS = %i[estimate_hours issue_hours invoice_hours spent_hours].freeze
|
||||
|
||||
attr_reader :from, :to, :period, :project_ids
|
||||
@@ -54,8 +55,9 @@ module RedmineQboBilling
|
||||
nil
|
||||
end
|
||||
|
||||
# data (for tests): { estimates: [[date, total, hours]], invoices: [[date, total, hours, balance]],
|
||||
# payments: [[date, total]], issues: [[date, estimated_hours]], time_entries: [[date, hours]] }
|
||||
# data (for tests): { estimates: [[date, total, hours, tax]], invoices: [[date, total, hours, balance, tax]],
|
||||
# paid: [[paid_on, total, tax]], payments: [[date, total]], issues: [[date, estimated_hours]],
|
||||
# time_entries: [[date, hours]] }. Tax may be left off (none).
|
||||
# week_start: the first day of a week (:monday, :saturday or :sunday); see week_start_from_setting.
|
||||
# previous_data (for tests): last year's data, like data.
|
||||
# project_ids: the projects whose issues and spent time count; blank for every project.
|
||||
@@ -150,13 +152,31 @@ module RedmineQboBilling
|
||||
@data ||= load_data
|
||||
end
|
||||
|
||||
# { estimates: { total:, count: }, invoices: { total:, count:, balance: }, payments: { total:, count: } }
|
||||
# Where each money figure's rows are and how much each row counts: estimates, invoices and invoices paid in
|
||||
# full without their sales tax, payments as received
|
||||
MONEY_ROWS = {
|
||||
estimates: [:estimates, ->(r) { to_money(r[1]) - to_money(r[3]) }],
|
||||
invoices: [:invoices, ->(r) { to_money(r[1]) - to_money(r[4]) }],
|
||||
paid: [:paid, ->(r) { to_money(r[1]) - to_money(r[2]) }],
|
||||
payments: [:payments, ->(r) { to_money(r[1]) }]
|
||||
}.freeze
|
||||
|
||||
def self.to_money(value)
|
||||
BigDecimal(value.to_s.presence || '0')
|
||||
rescue ArgumentError
|
||||
BigDecimal('0')
|
||||
end
|
||||
|
||||
# { estimates: { total:, count: }, invoices: { total:, count:, balance:, with_tax: }, paid: { total:, count: },
|
||||
# payments: { total:, count: } }. Invoices' balance (still owed) and with_tax are what the customers pay.
|
||||
def money
|
||||
@money ||= {
|
||||
estimates: { total: money_sum(data[:estimates], 1), count: data[:estimates].size },
|
||||
invoices: { total: money_sum(data[:invoices], 1), count: data[:invoices].size, balance: money_sum(data[:invoices], 3) },
|
||||
payments: { total: money_sum(data[:payments], 1), count: data[:payments].size }
|
||||
}
|
||||
@money ||= MONEY_ROWS.to_h do |key, (source, value)|
|
||||
rows = Array(data[source])
|
||||
[key, { total: rows.sum(BigDecimal('0')) { |r| value.call(r) }, count: rows.size }]
|
||||
end.tap do |figures|
|
||||
figures[:invoices][:balance] = money_sum(data[:invoices], 3)
|
||||
figures[:invoices][:with_tax] = money_sum(data[:invoices], 1)
|
||||
end
|
||||
end
|
||||
|
||||
# { estimate_hours:, issue_hours:, invoice_hours:, spent_hours: }
|
||||
@@ -193,7 +213,8 @@ module RedmineQboBilling
|
||||
def ratios
|
||||
{
|
||||
invoiced_of_estimated: percent(money[:invoices][:total], money[:estimates][:total]),
|
||||
collected_of_invoiced: percent(money[:payments][:total], money[:invoices][:total]),
|
||||
# Payments include sales tax, so they're compared with the invoices' totals with tax
|
||||
collected_of_invoiced: percent(money[:payments][:total], money[:invoices][:with_tax]),
|
||||
invoiced_of_spent: percent(hours[:invoice_hours], hours[:spent_hours]),
|
||||
spent_of_estimated: percent(hours[:spent_hours], hours[:issue_hours])
|
||||
}
|
||||
@@ -218,9 +239,12 @@ module RedmineQboBilling
|
||||
r[key] += kind == :money ? to_d(row[col]) : row[col].to_f
|
||||
end
|
||||
end
|
||||
add.call(data[:estimates], :estimates, 1, :money)
|
||||
add.call(data[:invoices], :invoices, 1, :money)
|
||||
add.call(data[:payments], :payments, 1, :money)
|
||||
MONEY_ROWS.each do |key, (source, value)|
|
||||
Array(data[source]).each do |row|
|
||||
r = index[[row[0].year, row[0].month]] or next
|
||||
r[key] += value.call(row)
|
||||
end
|
||||
end
|
||||
add.call(data[:estimates], :estimate_hours, 2, :hours)
|
||||
add.call(data[:issues], :issue_hours, 1, :hours)
|
||||
add.call(data[:invoices], :invoice_hours, 2, :hours)
|
||||
@@ -229,9 +253,11 @@ module RedmineQboBilling
|
||||
end
|
||||
end
|
||||
|
||||
# Estimates and invoices in the range that synced before totals and hours were cached (a full sync fills them)
|
||||
# Estimates and invoices in the range that synced before totals, hours and sales tax were cached (a full sync
|
||||
# fills them)
|
||||
def unsynced_count
|
||||
data[:estimates].count { |r| r[1].nil? || r[2].nil? } + data[:invoices].count { |r| r[1].nil? || r[2].nil? }
|
||||
data[:estimates].count { |r| r[1].nil? || r[2].nil? || (r.size > 3 && r[3].nil?) } +
|
||||
data[:invoices].count { |r| r[1].nil? || r[2].nil? || (r.size > 4 && r[4].nil?) }
|
||||
end
|
||||
|
||||
private
|
||||
@@ -242,14 +268,18 @@ module RedmineQboBilling
|
||||
find = lambda do |date|
|
||||
bucket_list.index { |a, b| date >= a && date <= b }
|
||||
end
|
||||
columns = {
|
||||
estimates: [:estimates, 1], invoices: [:invoices, 1], payments: [:payments, 1],
|
||||
estimate_hours: [:estimates, 2], issue_hours: [:issues, 1], invoice_hours: [:invoices, 2], spent_hours: [:time_entries, 1]
|
||||
}
|
||||
MONEY_ROWS.each do |key, (source, value)|
|
||||
Array(rows[source]).each do |row|
|
||||
i = find.call(row[0]) or next
|
||||
sums[key][i] += value.call(row).to_f
|
||||
end
|
||||
end
|
||||
columns = { estimate_hours: [:estimates, 2], issue_hours: [:issues, 1], invoice_hours: [:invoices, 2],
|
||||
spent_hours: [:time_entries, 1] }
|
||||
columns.each do |key, (source, col)|
|
||||
Array(rows[source]).each do |row|
|
||||
i = find.call(row[0]) or next
|
||||
sums[key][i] += MONEY.include?(key) ? to_d(row[col]).to_f : row[col].to_f
|
||||
sums[key][i] += row[col].to_f
|
||||
end
|
||||
end
|
||||
sums.transform_values { |values| values.map { |v| v.round(2) } }
|
||||
@@ -266,8 +296,9 @@ module RedmineQboBilling
|
||||
time_entries = time_entries.where(project_id: project_ids)
|
||||
end
|
||||
{
|
||||
estimates: Estimate.where(txn_date: dates).pluck(:txn_date, :total_amount, :hours),
|
||||
invoices: Invoice.where(txn_date: dates).pluck(:txn_date, :total_amount, :hours, :balance),
|
||||
estimates: Estimate.where(txn_date: dates).pluck(:txn_date, :total_amount, :hours, :tax_amount),
|
||||
invoices: Invoice.where(txn_date: dates).pluck(:txn_date, :total_amount, :hours, :balance, :tax_amount),
|
||||
paid: Invoice.where(paid_on: dates).where('total_amount > 0').pluck(:paid_on, :total_amount, :tax_amount),
|
||||
payments: Payment.where(txn_date: dates).pluck(:txn_date, :total_amount),
|
||||
issues: issues.pluck(:created_on, :estimated_hours).map { |t, h| [t.in_time_zone.to_date, h] },
|
||||
time_entries: time_entries.pluck(:spent_on, :hours)
|
||||
|
||||
@@ -34,8 +34,12 @@ module RedmineQboBilling
|
||||
balance < total ? :partial : :open
|
||||
end
|
||||
|
||||
def label(status)
|
||||
status ? I18n.t("label_invoice_status_#{status}") : ''
|
||||
# "Paid", or with the day it was paid in full, "Paid 11/03/2026"
|
||||
def label(status, paid_on: nil)
|
||||
return '' unless status
|
||||
return I18n.t(:label_invoice_status_paid_on, date: I18n.l(paid_on)) if status == :paid && paid_on
|
||||
|
||||
I18n.t("label_invoice_status_#{status}")
|
||||
end
|
||||
|
||||
def to_d(value)
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
#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.
|
||||
|
||||
require File.expand_path('../test_helper', __dir__)
|
||||
|
||||
class BusinessReportTest < ActiveSupport::TestCase
|
||||
Report = RedmineQboBilling::BusinessReport
|
||||
NOV = Date.new(2026, 11, 1)
|
||||
|
||||
def report(data)
|
||||
full = { estimates: [], invoices: [], paid: [], payments: [], issues: [], time_entries: [] }.merge(data)
|
||||
Report.new(period: 'custom', from: NOV, to: NOV.end_of_month, today: Date.new(2026, 11, 20), data: full,
|
||||
previous_data: full.transform_values { [] })
|
||||
end
|
||||
|
||||
def test_estimates_and_invoices_without_tax
|
||||
r = report(estimates: [[NOV + 1, '1080', 10, '80'], [NOV + 2, '500', 2]],
|
||||
invoices: [[NOV + 3, '1070', 5, '0', '70'], [NOV + 4, '200', 1, '200', '0']],
|
||||
payments: [[NOV + 5, '1070']])
|
||||
assert_equal BigDecimal('1500'), r.money[:estimates][:total]
|
||||
assert_equal BigDecimal('1200'), r.money[:invoices][:total]
|
||||
assert_equal BigDecimal('1270'), r.money[:invoices][:with_tax]
|
||||
assert_equal BigDecimal('200'), r.money[:invoices][:balance]
|
||||
assert_equal BigDecimal('1070'), r.money[:payments][:total]
|
||||
# $1,070 collected of $1,270 invoiced with tax
|
||||
assert_equal 84, r.ratios[:collected_of_invoiced]
|
||||
assert_equal 80, r.ratios[:invoiced_of_estimated]
|
||||
end
|
||||
|
||||
def test_invoices_paid_in_full
|
||||
r = report(paid: [[NOV + 3, '1070', '70'], [NOV + 9, '500', nil]])
|
||||
assert_equal BigDecimal('1500'), r.money[:paid][:total]
|
||||
assert_equal 2, r.money[:paid][:count]
|
||||
november = r.months.find { |m| m[:month] == NOV }
|
||||
assert_equal BigDecimal('1500'), november[:paid]
|
||||
assert_equal 1500.0, r.chart[:current][:paid].compact.sum
|
||||
end
|
||||
|
||||
def test_rows_missing_tax_are_unsynced
|
||||
r = report(estimates: [[NOV + 1, '100', 1, nil]], invoices: [[NOV + 1, '100', 1, '0', '0']])
|
||||
assert_equal 1, r.unsynced_count
|
||||
end
|
||||
|
||||
def test_paid_badge_shows_the_day
|
||||
assert_equal 'Paid', RedmineQboBilling::InvoiceStatus.label(:paid)
|
||||
assert_match(/\APaid \S+/, RedmineQboBilling::InvoiceStatus.label(:paid, paid_on: Date.new(2026, 11, 3)))
|
||||
assert_equal 'Open', RedmineQboBilling::InvoiceStatus.label(:open, paid_on: Date.new(2026, 11, 3))
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user