mirror of
https://github.com/itflow-org/itflow
synced 2026-11-20 11:27:23 +00:00
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:
@@ -643,47 +643,6 @@ function checkForUpdates() {
|
||||
|
||||
}
|
||||
|
||||
function getMonthlyTax($tax_name, $month, $year, $mysqli) {
|
||||
// Cash basis - tax is booked to the month the money arrived, in proportion to
|
||||
// how much of the invoice that payment covered. Driving off payments (rather
|
||||
// than invoice_items) counts each payment exactly once, and pre-aggregating
|
||||
// the line items stops a multi-payment invoice multiplying its own tax.
|
||||
$sql = "SELECT SUM(invoice_tax.tax_total * (payments.payment_amount / invoices.invoice_amount)) AS monthly_tax
|
||||
FROM payments
|
||||
INNER JOIN invoices ON invoices.invoice_id = payments.payment_invoice_id
|
||||
INNER JOIN (SELECT item_invoice_id, SUM(item_tax) AS tax_total
|
||||
FROM invoice_items
|
||||
WHERE item_tax_id = (SELECT tax_id FROM taxes WHERE tax_name = '$tax_name')
|
||||
GROUP BY item_invoice_id) AS invoice_tax
|
||||
ON invoice_tax.item_invoice_id = invoices.invoice_id
|
||||
WHERE YEAR(payments.payment_date) = $year AND MONTH(payments.payment_date) = $month
|
||||
AND invoices.invoice_amount > 0";
|
||||
$result = mysqli_query($mysqli, $sql);
|
||||
$row = mysqli_fetch_assoc($result);
|
||||
return $row['monthly_tax'] ?? 0;
|
||||
}
|
||||
|
||||
function getQuarterlyTax($tax_name, $quarter, $year, $mysqli) {
|
||||
// Calculate start and end months for the quarter
|
||||
$start_month = ($quarter - 1) * 3 + 1;
|
||||
$end_month = $start_month + 2;
|
||||
|
||||
// SQL to calculate quarterly tax - see getMonthlyTax for why it is shaped this way
|
||||
$sql = "SELECT SUM(invoice_tax.tax_total * (payments.payment_amount / invoices.invoice_amount)) AS quarterly_tax
|
||||
FROM payments
|
||||
INNER JOIN invoices ON invoices.invoice_id = payments.payment_invoice_id
|
||||
INNER JOIN (SELECT item_invoice_id, SUM(item_tax) AS tax_total
|
||||
FROM invoice_items
|
||||
WHERE item_tax_id = (SELECT tax_id FROM taxes WHERE tax_name = '$tax_name')
|
||||
GROUP BY item_invoice_id) AS invoice_tax
|
||||
ON invoice_tax.item_invoice_id = invoices.invoice_id
|
||||
WHERE YEAR(payments.payment_date) = $year AND MONTH(payments.payment_date) BETWEEN $start_month AND $end_month
|
||||
AND invoices.invoice_amount > 0";
|
||||
$result = mysqli_query($mysqli, $sql);
|
||||
$row = mysqli_fetch_assoc($result);
|
||||
return $row['quarterly_tax'] ?? 0;
|
||||
}
|
||||
|
||||
function addToMailQueue($data) {
|
||||
|
||||
global $mysqli;
|
||||
|
||||
Reference in New Issue
Block a user