mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-18 02:20:37 -05:00
Business report: sales tax invoiced and collected
A Sales tax section: tax invoiced (on invoices dated in the period, accrual) and tax collected (on invoices paid in full in the period, counted on the day each was paid in full, cash), with counts, a line chart and a month-by-month table. Only invoices are counted; sales tax is filed from QuickBooks' Sales Tax Liability report. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a72b0fa73b
commit
ec4e5f681d
5 files changed
+96
-7
No files matched your search
@@ -159,12 +159,13 @@ 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):
|
**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, 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.
|
* **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.
|
||||||
|
* **Sales tax**: **tax invoiced**, the sales tax on invoices dated in the period, paid or not (accrual), and **tax collected**, the sales tax on invoices paid in full in the period, counted on the day each was paid in full (cash), each with how many invoices carried tax, a line chart and a month-by-month table. A partly paid invoice's tax counts as collected once it's paid in full. Only invoices are counted: sales receipts, refund receipts and credit memos aren't kept in Redmine, so file sales tax from QuickBooks' *Sales Tax Liability* report.
|
||||||
* **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.
|
* **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.
|
* **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.
|
* **By month**: every sales and hours figure month by month, with totals (the sales tax has its own table).
|
||||||
* **Projects**: pick one or more open projects (Ctrl/Cmd-click; closed and archived projects aren't listed) to count only their issues' estimated time and spent time, in the totals, charts and months; none picked counts every project. Estimates, invoices and payments have no project in QuickBooks, so they always cover the whole business (as do the CPI's invoiced hours). **Remember these projects** saves the choice in your Redmine preferences, and the report opens with it until you save another (saving none goes back to every project).
|
* **Projects**: pick one or more open projects (Ctrl/Cmd-click; closed and archived projects aren't listed) to count only their issues' estimated time and spent time, in the totals, charts and months; none picked counts every project. Estimates, invoices and payments have no project in QuickBooks, so they always cover the whole business (as do the CPI's invoiced hours). **Remember these projects** saves the choice in your Redmine preferences, and the report opens with it until you save another (saving none goes back to every project).
|
||||||
|
|
||||||
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.
|
Estimates, invoices and payments count by their QuickBooks date; invoices paid in full and tax collected by the day each invoice was paid in full. 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, hours or sales tax, and paid invoices no paid-in-full day, until a full sync (the report says how many); run one again after changing the labor products/services.
|
||||||
|
|
||||||
### QuickBooks custom fields
|
### QuickBooks custom fields
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,10 @@
|
|||||||
[:invoices, l(:label_report_invoices_written), '#e8a33d'],
|
[:invoices, l(:label_report_invoices_written), '#e8a33d'],
|
||||||
[:paid, l(:label_report_invoices_paid), '#c0504d'],
|
[:paid, l(:label_report_invoices_paid), '#c0504d'],
|
||||||
[:payments, l(:label_report_payments_received), '#5aa05a']]) %>
|
[:payments, l(:label_report_payments_received), '#5aa05a']]) %>
|
||||||
|
<% taxes = @report.taxes %>
|
||||||
|
<% max_tax = taxes.values.map { |t| t[:total] }.max.to_f %>
|
||||||
|
<% tax_series = chart_series.call([[:tax_invoiced, l(:label_report_tax_invoiced), '#e8a33d'],
|
||||||
|
[:tax_collected, l(:label_report_tax_collected), '#c0504d']]) %>
|
||||||
<% hours_series = chart_series.call([[:estimate_hours, l(:label_report_estimate_hours), '#628db6'],
|
<% hours_series = chart_series.call([[:estimate_hours, l(:label_report_estimate_hours), '#628db6'],
|
||||||
[:issue_hours, l(:label_report_issue_hours), '#9b7fc0'],
|
[:issue_hours, l(:label_report_issue_hours), '#9b7fc0'],
|
||||||
[:invoice_hours, l(:label_report_invoice_hours), '#e8a33d'],
|
[:invoice_hours, l(:label_report_invoice_hours), '#e8a33d'],
|
||||||
@@ -182,6 +186,54 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<h3><%= l(:label_report_taxes) %></h3>
|
||||||
|
<div class="splitcontent">
|
||||||
|
<div class="splitcontentleft">
|
||||||
|
<div class="qbo-report-chart">
|
||||||
|
<canvas id="qbo-chart-taxes" data-kind="money" data-series="<%= tax_series.to_json %>"></canvas>
|
||||||
|
</div>
|
||||||
|
<table class="list qbo-report">
|
||||||
|
<tbody>
|
||||||
|
<% [[:tax_invoiced, l(:label_report_tax_invoiced)], [:tax_collected, l(:label_report_tax_collected)]].each do |key, label| %>
|
||||||
|
<tr>
|
||||||
|
<td class="name"><%= label %> <span class="count">(<%= l(:label_report_taxed_invoices, count: taxes[key][:count]) %>)</span></td>
|
||||||
|
<td class="bar"><div class="qbo-bar qbo-bar-<%= key %>" style="width: <%= bar.call(taxes[key][:total], max_tax) %>%"></div></td>
|
||||||
|
<td class="value"><%= number_to_currency(taxes[key][:total]) %></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<p><em class="info"><%= l(:text_report_taxes) %></em></p>
|
||||||
|
</div>
|
||||||
|
<div class="splitcontentright">
|
||||||
|
<table class="list qbo-report-months qbo-report-tax-months">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="month"><%= l(:label_month) %></th>
|
||||||
|
<th><%= l(:label_report_tax_invoiced) %></th>
|
||||||
|
<th><%= l(:label_report_tax_collected) %></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% @report.months.each do |row| %>
|
||||||
|
<tr>
|
||||||
|
<td class="month"><%= ::I18n.t('date.abbr_month_names')[row[:month].month] %> <%= row[:month].year %></td>
|
||||||
|
<td><%= number_to_currency(row[:tax_invoiced]) %></td>
|
||||||
|
<td><%= number_to_currency(row[:tax_collected]) %></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
<tfoot>
|
||||||
|
<tr class="total">
|
||||||
|
<td class="month"><strong><%= l(:label_total) %></strong></td>
|
||||||
|
<td><strong><%= number_to_currency(taxes[:tax_invoiced][:total]) %></strong></td>
|
||||||
|
<td><strong><%= number_to_currency(taxes[:tax_collected][:total]) %></strong></td>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<h3><%= l(:label_report_by_month) %></h3>
|
<h3><%= l(:label_report_by_month) %></h3>
|
||||||
<div class="autoscroll">
|
<div class="autoscroll">
|
||||||
<table class="list qbo-report-months">
|
<table class="list qbo-report-months">
|
||||||
@@ -242,7 +294,8 @@
|
|||||||
.qbo-bar { height: 14px; border-radius: 2px; min-width: 1px; background: #628db6; }
|
.qbo-bar { height: 14px; border-radius: 2px; min-width: 1px; background: #628db6; }
|
||||||
.qbo-bar-invoices, .qbo-bar-invoice_hours { background: #e8a33d; }
|
.qbo-bar-invoices, .qbo-bar-invoice_hours { background: #e8a33d; }
|
||||||
.qbo-bar-payments, .qbo-bar-spent_hours { background: #5aa05a; }
|
.qbo-bar-payments, .qbo-bar-spent_hours { background: #5aa05a; }
|
||||||
.qbo-bar-paid { background: #c0504d; }
|
.qbo-bar-paid, .qbo-bar-tax_collected { background: #c0504d; }
|
||||||
|
.qbo-bar-tax_invoiced { background: #e8a33d; }
|
||||||
.qbo-bar-issue_hours { background: #9b7fc0; }
|
.qbo-bar-issue_hours { background: #9b7fc0; }
|
||||||
.qbo-report-ratios { margin: 8px 4px; line-height: 1.7; }
|
.qbo-report-ratios { margin: 8px 4px; line-height: 1.7; }
|
||||||
.qbo-report-cpi { margin: 10px 4px 4px; }
|
.qbo-report-cpi { margin: 10px 4px 4px; }
|
||||||
|
|||||||
@@ -385,6 +385,13 @@ en:
|
|||||||
label_report_estimates_written: "Estimates written"
|
label_report_estimates_written: "Estimates written"
|
||||||
label_report_invoices_written: "Invoices written"
|
label_report_invoices_written: "Invoices written"
|
||||||
label_report_invoices_paid: "Invoices paid in full"
|
label_report_invoices_paid: "Invoices paid in full"
|
||||||
|
label_report_taxes: "Sales tax"
|
||||||
|
label_report_tax_invoiced: "Tax invoiced"
|
||||||
|
label_report_tax_collected: "Tax collected"
|
||||||
|
label_report_taxed_invoices:
|
||||||
|
one: "1 invoice"
|
||||||
|
other: "%{count} invoices"
|
||||||
|
text_report_taxes: "Tax invoiced is the sales tax on invoices dated in the period (accrual); tax collected is the sales tax on invoices paid in full in the period (cash), counted on the day each was paid in full. Sales receipts and refunds aren't included: file from QuickBooks' Sales Tax Liability report."
|
||||||
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."
|
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_payments_received: "Payments received"
|
||||||
label_report_estimate_hours: "Estimated (estimates)"
|
label_report_estimate_hours: "Estimated (estimates)"
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ module RedmineQboBilling
|
|||||||
# Redmine's issues and spent time:
|
# Redmine's issues and spent time:
|
||||||
# money: estimates written, invoices written, invoices paid in full, 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
|
# estimates and invoices without sales tax (it isn't the shop's revenue), payments as received
|
||||||
|
# taxes: sales tax on invoices written (by their date) and on invoices paid in full (by that day)
|
||||||
# hours: man-hours on estimates, issues' estimated time, man-hours invoiced, time spent
|
# 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
|
# 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
|
# the day they were created (only issues without subtasks, so parents' totals aren't counted twice), and
|
||||||
@@ -27,6 +28,7 @@ module RedmineQboBilling
|
|||||||
WEEKLY_UP_TO = 93
|
WEEKLY_UP_TO = 93
|
||||||
MONEY = %i[estimates invoices paid payments].freeze
|
MONEY = %i[estimates invoices paid payments].freeze
|
||||||
HOURS = %i[estimate_hours issue_hours invoice_hours spent_hours].freeze
|
HOURS = %i[estimate_hours issue_hours invoice_hours spent_hours].freeze
|
||||||
|
TAXES = %i[tax_invoiced tax_collected].freeze
|
||||||
|
|
||||||
attr_reader :from, :to, :period, :project_ids
|
attr_reader :from, :to, :period, :project_ids
|
||||||
|
|
||||||
@@ -161,6 +163,12 @@ module RedmineQboBilling
|
|||||||
payments: [:payments, ->(r) { to_money(r[1]) }]
|
payments: [:payments, ->(r) { to_money(r[1]) }]
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
|
# Sales tax on invoices written (by their date) and on invoices paid in full (by that day)
|
||||||
|
TAX_ROWS = {
|
||||||
|
tax_invoiced: [:invoices, ->(r) { to_money(r[4]) }],
|
||||||
|
tax_collected: [:paid, ->(r) { to_money(r[2]) }]
|
||||||
|
}.freeze
|
||||||
|
|
||||||
def self.to_money(value)
|
def self.to_money(value)
|
||||||
BigDecimal(value.to_s.presence || '0')
|
BigDecimal(value.to_s.presence || '0')
|
||||||
rescue ArgumentError
|
rescue ArgumentError
|
||||||
@@ -179,6 +187,14 @@ module RedmineQboBilling
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# { tax_invoiced: { total:, count: }, tax_collected: { total:, count: } }: count is the invoices that had tax
|
||||||
|
def taxes
|
||||||
|
@taxes ||= TAX_ROWS.to_h do |key, (source, value)|
|
||||||
|
amounts = Array(data[source]).map { |r| value.call(r) }
|
||||||
|
[key, { total: amounts.sum(BigDecimal('0')), count: amounts.count(&:positive?) }]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# { estimate_hours:, issue_hours:, invoice_hours:, spent_hours: }
|
# { estimate_hours:, issue_hours:, invoice_hours:, spent_hours: }
|
||||||
def hours
|
def hours
|
||||||
@hours ||= {
|
@hours ||= {
|
||||||
@@ -229,7 +245,7 @@ module RedmineQboBilling
|
|||||||
last = [to, @today].min
|
last = [to, @today].min
|
||||||
last = from if last < from
|
last = from if last < from
|
||||||
while month <= last
|
while month <= last
|
||||||
rows << { month: month }.merge((MONEY + HOURS).index_with { |_| 0 })
|
rows << { month: month }.merge((MONEY + HOURS + TAXES).index_with { |_| 0 })
|
||||||
month = month.next_month
|
month = month.next_month
|
||||||
end
|
end
|
||||||
index = rows.index_by { |r| [r[:month].year, r[:month].month] }
|
index = rows.index_by { |r| [r[:month].year, r[:month].month] }
|
||||||
@@ -239,7 +255,7 @@ module RedmineQboBilling
|
|||||||
r[key] += kind == :money ? to_d(row[col]) : row[col].to_f
|
r[key] += kind == :money ? to_d(row[col]) : row[col].to_f
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
MONEY_ROWS.each do |key, (source, value)|
|
MONEY_ROWS.merge(TAX_ROWS).each do |key, (source, value)|
|
||||||
Array(data[source]).each do |row|
|
Array(data[source]).each do |row|
|
||||||
r = index[[row[0].year, row[0].month]] or next
|
r = index[[row[0].year, row[0].month]] or next
|
||||||
r[key] += value.call(row)
|
r[key] += value.call(row)
|
||||||
@@ -264,11 +280,11 @@ module RedmineQboBilling
|
|||||||
|
|
||||||
# { money key or hours key => [sum per bucket] } for the data, in buckets ([first day, last day] pairs)
|
# { money key or hours key => [sum per bucket] } for the data, in buckets ([first day, last day] pairs)
|
||||||
def sums_by_bucket(rows, bucket_list)
|
def sums_by_bucket(rows, bucket_list)
|
||||||
sums = (MONEY + HOURS).index_with { |_| Array.new(bucket_list.size, 0.0) }
|
sums = (MONEY + HOURS + TAXES).index_with { |_| Array.new(bucket_list.size, 0.0) }
|
||||||
find = lambda do |date|
|
find = lambda do |date|
|
||||||
bucket_list.index { |a, b| date >= a && date <= b }
|
bucket_list.index { |a, b| date >= a && date <= b }
|
||||||
end
|
end
|
||||||
MONEY_ROWS.each do |key, (source, value)|
|
MONEY_ROWS.merge(TAX_ROWS).each do |key, (source, value)|
|
||||||
Array(rows[source]).each do |row|
|
Array(rows[source]).each do |row|
|
||||||
i = find.call(row[0]) or next
|
i = find.call(row[0]) or next
|
||||||
sums[key][i] += value.call(row).to_f
|
sums[key][i] += value.call(row).to_f
|
||||||
|
|||||||
@@ -53,4 +53,16 @@ class BusinessReportTest < ActiveSupport::TestCase
|
|||||||
assert_match(/\APaid \S+/, RedmineQboBilling::InvoiceStatus.label(:paid, paid_on: Date.new(2026, 11, 3)))
|
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))
|
assert_equal 'Open', RedmineQboBilling::InvoiceStatus.label(:open, paid_on: Date.new(2026, 11, 3))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_taxes
|
||||||
|
r = report(invoices: [[NOV + 3, '1070', 5, '0', '70'], [NOV + 4, '200', 1, '200', '0'], [NOV + 6, '535', 2, '0', '35']],
|
||||||
|
paid: [[NOV + 9, '1070', '70'], [Date.new(2026, 11, 10), '500', nil]])
|
||||||
|
assert_equal({ total: BigDecimal('105'), count: 2 }, r.taxes[:tax_invoiced])
|
||||||
|
assert_equal({ total: BigDecimal('70'), count: 1 }, r.taxes[:tax_collected])
|
||||||
|
november = r.months.find { |m| m[:month] == NOV }
|
||||||
|
assert_equal BigDecimal('105'), november[:tax_invoiced]
|
||||||
|
assert_equal BigDecimal('70'), november[:tax_collected]
|
||||||
|
assert_equal 105.0, r.chart[:current][:tax_invoiced].compact.sum
|
||||||
|
assert_equal 70.0, r.chart[:current][:tax_collected].compact.sum
|
||||||
|
end
|
||||||
end
|
end
|
||||||
Reference in new issue
Block a user