Files
itflow/admin/modals/tax/tax_form.php
johnnyq cd565b73c7 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
2026-10-17 13:27:53 -04:00

110 lines
6.2 KiB
PHP

<?php
/*
* A tax's fields - for tax_add.php and tax_edit.php, which set $tax (a
* taxRow(), or null when new). One rate, or parts each charged on the line
* or on top of the parts above it (js/tax_form.js). Posts to admin/post.php
* (admin/post/tax.php).
*/
isset($mysqli) || die("Direct file access is not allowed");
$t = $tax ?? null;
$t_parts = $t && $t['grouped'] ? $t['components'] : [];
// One part's row - $key keeps a part's name, percent and "on top" together when rows are added and removed
$tax_part_row = function ($key, array $part = []) {
ob_start(); ?>
<div class="row g-2 align-items-center mb-2" data-tax-part>
<div class="col-sm-4">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-tag"></i></span>
<input type="text" class="form-control" name="part_name[<?= $key ?>]" maxlength="200" placeholder="State, county, GST..." value="<?= escapeHtml($part['name'] ?? '') ?>" data-tax-part-name>
</div>
</div>
<div class="col-sm-3">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-id-card"></i></span>
<input type="text" class="form-control" name="part_registration[<?= $key ?>]" maxlength="100" placeholder="Its own reg. no." title="This part's registration number, when it isn't the tax's" value="<?= escapeHtml($part['registration'] ?? '') ?>">
</div>
</div>
<div class="col-7 col-sm-2">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-percent"></i></span>
<input type="text" class="form-control" inputmode="decimal" pattern="[0-9]*\.?[0-9]{0,4}" name="part_percent[<?= $key ?>]" placeholder="0" value="<?= isset($part['percent']) ? taxPercentText($part['percent']) : '' ?>" data-tax-part-percent>
</div>
</div>
<div class="col-3 col-sm-2">
<div class="form-check mb-0" title="Charged on the line plus the parts above it, not just the line">
<input type="checkbox" class="form-check-input" name="part_compound[<?= $key ?>]" value="1" id="taxPartCompound<?= $key ?>"<?= !empty($part['compound']) ? ' checked' : '' ?> data-tax-part-compound>
<label class="form-check-label small" for="taxPartCompound<?= $key ?>">On top</label>
</div>
</div>
<div class="col-2 col-sm-1 text-end">
<button type="button" class="btn btn-sm btn-outline-secondary" title="Remove this part" data-tax-remove-part><i class="fas fa-times"></i></button>
</div>
</div>
<?php return ob_get_clean();
};
?>
<div data-tax-form>
<div class="mb-3">
<label class="form-label">Name <strong class="text-danger">*</strong></label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-balance-scale"></i></span>
<input type="text" class="form-control" name="name" maxlength="200" placeholder="PA Sales Tax, GST, VAT" value="<?= escapeHtml($t['tax_name'] ?? '') ?>" required autofocus>
</div>
</div>
<div class="row">
<div class="col-md-7 mb-3">
<label class="form-label">Description</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-align-left"></i></span>
<input type="text" class="form-control" name="description" maxlength="255" placeholder="Where and what it is charged on" value="<?= escapeHtml($t['tax_description'] ?? '') ?>">
</div>
</div>
<div class="col-md-5 mb-3">
<label class="form-label">Registration number</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-id-card"></i></span>
<input type="text" class="form-control" name="registration" maxlength="100" placeholder="Permit, GST/HST or VAT number" value="<?= escapeHtml($t['tax_registration_number'] ?? '') ?>">
</div>
<small class="text-secondary">Printed with this tax on invoices</small>
</div>
</div>
<div class="mb-1<?= $t_parts ? ' d-none' : '' ?>" data-tax-single>
<label class="form-label">Rate <strong class="text-danger">*</strong></label>
<div class="row g-2 align-items-center">
<div class="col-sm-4">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-percent"></i></span>
<input type="text" class="form-control" inputmode="decimal" pattern="[0-9]*\.?[0-9]{0,4}" name="percent" placeholder="0" value="<?= $t && !$t_parts ? taxPercentText($t['tax_percent']) : '' ?>"<?= $t_parts ? ' disabled' : ' required' ?> data-tax-percent>
</div>
</div>
<div class="col-sm-8">
<button type="button" class="btn btn-link btn-sm px-0 text-decoration-none" data-tax-split><i class="fas fa-layer-group me-1"></i>Split into parts - a state's and a county's, GST and PST</button>
</div>
</div>
</div>
<div class="mb-1<?= $t_parts ? '' : ' d-none' ?>" data-tax-parts>
<label class="form-label">Parts <strong class="text-danger">*</strong></label>
<div data-tax-part-rows>
<?php foreach ($t_parts as $i => $part) {
echo $tax_part_row($i, $part);
} ?>
</div>
<template data-tax-part-template><?= $tax_part_row('__KEY__') ?></template>
<div class="d-flex flex-wrap align-items-center gap-2">
<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. Name a part the same as another tax's (PA Sales Tax at 6%) and Tax Collected adds them up together.</small>
</div>
</div>
<script src="/js/tax_form.js"></script>