Taxes stage 2: Tax Collected report rebuilt for filing with an Invoiced basis (each sent invoice in the month of its date) or Paid basis (each payment carrying its share of its invoice), tax by part of each rate with registration numbers so a state's and a county's parts count apart and parts named alike add up in one row, sales before tax and net of discounts split into taxable, exempt and non-taxable, tax paid on purchases by part and net tax collected less paid, exempt sales by client with certificate and expiry, quarterly or monthly with a chart and CSV export of the tax table or the exempt sales, archived payments left out; expenses and recurring expenses record the tax included in them with a rate worked out from the amount as typed or typed over from the receipt, a tax amount with no rate allowed, refunds giving their tax back, recurring expenses copying it to each expense recorded, vendor defaults filling it in, and the list and quick looks showing it; exports gain invoice subtotal, discount, tax and tax by part, quote and recurring invoice tax, expense before tax, tax and tax rate, and client tax rate and exemption columns; API adds a taxes read endpoint with each rate's parts, subtotal, tax, tax by part and registration numbers on invoice and quote reads, and each line's rate on invoice item reads; Admin > Taxes explains naming parts alike and links the report; demo data names Allegheny County's state part PA Sales Tax and taxes the company's own-use purchases; removes the unused getMonthlyTax and getQuarterlyTax; database 3.1.2 adds expense and recurring expense tax rate and amount; changelog updated

This commit is contained in:
johnnyq
2026-10-17 13:27:53 -04:00
parent afaaa5fc32
commit cd565b73c7
29 changed files with 797 additions and 224 deletions

View File

@@ -0,0 +1,20 @@
<?php
/*
* ITFlow - Database update to version 3.1.2 (from 3.1.1)
* Included by admin/database_updates.php - do not access directly
*/
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
// The tax included in what an expense cost - its rate (0: none, or a tax
// with no rate of ours) and the amount, part of expense_amount, for the
// tax paid on purchases in the Tax Collected report
mysqli_query($mysqli, "ALTER TABLE `expenses`
ADD COLUMN `expense_tax_id` int(11) NOT NULL DEFAULT 0 AFTER `expense_amount`,
ADD COLUMN `expense_tax_amount` decimal(15,2) NOT NULL DEFAULT 0.00 AFTER `expense_tax_id`");
// The same on a recurring expense, copied to each expense it records
mysqli_query($mysqli, "ALTER TABLE `recurring_expenses`
ADD COLUMN `recurring_expense_tax_id` int(11) NOT NULL DEFAULT 0 AFTER `recurring_expense_amount`,
ADD COLUMN `recurring_expense_tax_amount` decimal(15,2) NOT NULL DEFAULT 0.00 AFTER `recurring_expense_tax_id`");

View File

@@ -102,7 +102,7 @@ $tax_part_row = function ($key, array $part = []) {
<button type="button" class="btn btn-outline-secondary btn-sm" data-tax-add-part><i class="fas fa-plus me-1"></i>Add a part</button>
<span class="ms-auto">Comes to <strong data-tax-total><?= $t ? taxPercentText($t['tax_percent']) : '0' ?>%</strong></span>
</div>
<small class="text-secondary d-block mt-1">Each part is shown on its own on invoices, with its registration number - or the tax's. <em>On top</em> charges a part on the line plus the parts above it.</small>
<small class="text-secondary d-block mt-1">Each part is shown on its own on invoices, with its registration number - or the tax's. <em>On top</em> charges a part on the line plus the parts above it. Name a part the same as another tax's (PA Sales Tax at 6%) and Tax Collected adds them up together.</small>
</div>
</div>

View File

@@ -93,7 +93,8 @@ function demoDataSlas() {
function demoDataTaxes() {
return [
['PA Sales Tax', 6.0, 'Pennsylvania state sales tax', '75520193', []],
['Allegheny County Sales Tax', 7.0, 'Pennsylvania 6% plus the Allegheny County local 1%', '75520193', [['Pennsylvania', 6.0], ['Allegheny County', 1.0]]],
// The state's part is named as the state's own rate, so Tax Collected adds the two up in one row
['Allegheny County Sales Tax', 7.0, 'Pennsylvania 6% plus the Allegheny County local 1%', '75520193', [['PA Sales Tax', 6.0], ['Allegheny County', 1.0]]],
];
}
@@ -3396,6 +3397,10 @@ function demoBuildCompanyFinancials($mysqli, $context, &$counts) {
$card_categories = ['Software', 'Cloud and Hosting', 'Office Supplies', 'Meals', 'Shipping and Postage', 'Dues and Subscriptions', 'Telecom and Internet'];
$card_spent = [];
// What we buy for our own use pays sales tax; stock to resell doesn't
$taxed_categories = ['Office Supplies', 'Tools and Test Equipment', 'Equipment', 'Vehicle and Fuel'];
$purchase_tax_id = intval($context['taxes']['PA Sales Tax']['id'] ?? 0);
// Which purchases put hardware on the shelf, and what they bring in
$stock_lines = [
'UniFi shelf stock for the workshop' => ['Ubiquiti U6-Pro Access Point', 4],
@@ -3416,9 +3421,12 @@ function demoBuildCompanyFinancials($mysqli, $context, &$counts) {
$card_spent[$month] = ($card_spent[$month] ?? 0) + round($cost[1] * $drift, 2);
}
$taxed = $purchase_tax_id && in_array($cost[2], $taxed_categories, true);
$expense_id = starterInsert($mysqli, 'expenses', [
'expense_description' => $cost[0],
'expense_amount' => number_format($cost[1] * $drift, 2, '.', ''),
'expense_tax_id' => $taxed ? $purchase_tax_id : 0,
'expense_tax_amount' => number_format($taxed ? taxIncluded(round($cost[1] * $drift, 2), $purchase_tax_id) : 0, 2, '.', ''),
'expense_currency_code' => $currency,
'expense_date' => demoMonthDate($month, $cost[4]),
'expense_reference' => 'BILL-' . demoSerial('company' . $cost[0] . $month, 8),

View File

@@ -210,7 +210,8 @@ $used_text = function (array $u) {
<div class="card">
<div class="card-body small text-secondary">
<p class="mb-2"><i class="fas fa-fw fa-history me-1"></i><strong>Changing a rate.</strong> Once a rate is on an invoice or quote, saving a new percent or parts makes a new rate with the same name. What was already billed keeps the old rate; products, clients, the default and recurring invoices move to the new one.</p>
<p class="mb-0"><i class="fas fa-fw fa-user-shield me-1"></i><strong>Exempt clients.</strong> Mark a client tax exempt, with its certificate, on the client's Billing tab. Its new lines get no tax, and its invoices say why.</p>
<p class="mb-2"><i class="fas fa-fw fa-user-shield me-1"></i><strong>Exempt clients.</strong> Mark a client tax exempt, with its certificate, on the client's Billing tab. Its new lines get no tax, and its invoices say why.</p>
<p class="mb-0"><i class="fas fa-fw fa-percent me-1"></i><strong>Filing.</strong> The <a href="/agent/reports/tax_summary.php">Tax Collected</a> report adds up each part by month or quarter, invoiced or paid, with exempt sales and the tax paid on expenses.</p>
</div>
</div>
</div>