$exempt_client) { if (!hasClientAccess($exempt_client_id)) { $hidden_exempt += $exempt_client['amount']; unset($sales['exempt_clients'][$exempt_client_id]); } } if ($hidden_exempt != 0) { $sales['exempt_clients'][-1] = ['name' => 'Clients you cannot open', 'number' => '', 'expires' => '', 'expired' => false, 'amount' => $hidden_exempt]; } $purchases = taxReportPurchases("$year-01-01", $to); $prev = taxReportSales(($year - 1) . '-01-01', $current_year ? dashboardShiftMonths(date('Y-m-d'), -12) : ($year - 1) . '-12-31', $basis); $compare = $current_year ? 'the same time last year' : (string) ($year - 1); $sum = function (array $months) { return array_sum($months); }; $tax_months = taxReportMonths(); foreach ($sales['parts'] as $part) { foreach ($part['months'] as $m => $amount) { $tax_months[$m] += $amount; } } $paid_months = taxReportMonths(); foreach ($purchases['parts'] as $part) { foreach ($part['months'] as $m => $amount) { $paid_months[$m] += $amount; } } $net_months = array_map(function ($collected, $paid) { return $collected - $paid; }, $tax_months, $paid_months); $net_months = array_combine(range(1, 12), $net_months); $tax_total = $sum($tax_months); $paid_total = $sum($paid_months); $prev_tax_total = array_sum(array_column($prev['parts'], 'total')); $has_purchases = (bool) $purchases['parts']; // A table row for each figure: [group, name, sub, months, emphasis] $grid = []; foreach ($sales['parts'] as $label => $part) { $grid[] = ['Tax collected', $label, '', $part['months'], false]; } $grid[] = ['Tax collected', 'Total tax collected', '', $tax_months, true]; $grid[] = ['Sales, before tax and net of discounts', 'Total sales', '', $sales['sales'], true]; $grid[] = ['Sales, before tax and net of discounts', 'Taxable', 'Lines with tax on them', $sales['taxable'], false]; $grid[] = ['Sales, before tax and net of discounts', 'Exempt', 'No tax, for clients who are tax exempt', $sales['exempt'], false]; $grid[] = ['Sales, before tax and net of discounts', 'Non-taxable', 'No tax, for clients who are not exempt', $sales['nontaxable'], false]; if ($has_purchases) { foreach ($purchases['parts'] as $label => $part) { $grid[] = ['Tax paid on purchases', $label, '', $part['months'], false]; } $grid[] = ['Tax paid on purchases', 'Total tax paid', '', $paid_months, true]; $grid[] = ['Tax paid on purchases', 'Purchases it was paid on', 'Before tax', $purchases['purchases'], false]; $grid[] = ['Collected less paid', 'Net tax', 'For GST, HST and VAT returns that take off tax paid', $net_months, true]; } if (reportExporting() && ($_GET['table'] ?? 'tax') === 'tax') { $csv_columns = ['group' => ['label' => 'Section'], 'name' => ['label' => 'Figure'], 'registration' => ['label' => 'Registration']]; foreach ($columns as $i => [$label]) { $csv_columns["c$i"] = ['label' => $label, 'type' => 'money']; } $csv_columns['total'] = ['label' => (string) $year, 'type' => 'money']; $rows = []; foreach ($grid as [$group, $name, $sub, $months]) { $row = ['group' => $group, 'name' => $name, 'registration' => $group === 'Tax collected' ? ($sales['numbers'][$name] ?? '') : '', 'total' => round(array_sum($months), 2)]; foreach (reportSumColumns($months, $columns) as $i => $value) { $row["c$i"] = round($value, 2); } $rows[] = $row; } reportCsv('Tax Collected ' . $year . ' ' . TAX_REPORT_BASES[$basis], $csv_columns, $rows); } if (reportExporting('exempt')) { $rows = []; foreach ($sales['exempt_clients'] as $client) { $rows[] = ['client' => $client['name'], 'number' => $client['number'], 'expires' => $client['expires'], 'amount' => round($client['amount'], 2)]; } reportCsv("Exempt Sales $year", [ 'client' => ['label' => 'Client'], 'number' => ['label' => 'Certificate'], 'expires' => ['label' => 'Expires'], 'amount' => ['label' => 'Exempt sales', 'type' => 'money'], ], $rows); } require_once "includes/inc_report_layout.php"; $span = count($columns) + 2; $basis_note = $basis === 'invoiced' ? 'Counted on each invoice\'s date once it is sent, paid or not. Drafts, cancelled and non-billable invoices are left out.' : 'Counted as payments come in: each payment carries its share of its invoice\'s tax and sales, so a part-paid invoice counts only the part paid.'; $stats = [ ['label' => 'Tax collected', 'value' => reportMoney($tax_total), 'sub' => reportChangeHtml($tax_total, $prev_tax_total, 'up', $compare)], ['label' => 'Taxable sales', 'value' => reportMoney($sum($sales['taxable'])), 'sub' => 'Of ' . escapeHtml(reportMoney($sum($sales['sales']))) . ' in sales'], ['label' => 'Exempt sales', 'value' => reportMoney($sum($sales['exempt'])), 'sub' => '' . count($sales['exempt_clients']) . ' exempt client' . (count($sales['exempt_clients']) === 1 ? '' : 's') . ''], ['label' => 'Non-taxable sales', 'value' => reportMoney($sum($sales['nontaxable'])), 'sub' => 'No tax on the line'], ]; if ($has_purchases) { $stats[] = ['label' => 'Tax paid on purchases', 'value' => reportMoney($paid_total), 'sub' => 'On ' . $purchases['expenses'] . ' expense' . ($purchases['expenses'] === 1 ? '' : 's') . '']; $stats[] = ['label' => 'Net tax', 'value' => reportMoney($tax_total - $paid_total), 'sub' => 'Collected less paid']; } ?>
[$year, $years], 'controls' => reportSegmentControl('basis', $basis, TAX_REPORT_BASES) . reportSegmentControl('view', $view, ['quarter' => 'Quarterly', 'month' => 'Monthly']), 'subtitle' => ($current_year ? "$year to date" : (string) $year) . ' · ' . TAX_REPORT_BASES[$basis], 'export' => $sales['exempt_clients'] ? ['tax' => 'Tax by ' . $view, 'exempt' => 'Exempt sales by client'] : ['tax' => 'Tax by ' . $view], 'note' => escapeHtml($basis_note) . ' Sales are before tax and net of discounts.', 'print_meta' => TAX_REPORT_BASES[$basis] . ' basis', ]); ?>
$part) { if (abs($part['total']) < 0.005) { continue; } $series[] = ['label' => $label, 'data' => array_map(function ($m) use ($part, $months_shown) { return $m <= $months_shown ? round($part['months'][$m], 2) : null; }, range(1, 12)), 'tone' => reportPalette($i++), 'stack' => 'tax']; } echo reportChart([ 'type' => 'bar', 'labels' => array_map(function ($m) { return date('M', mktime(0, 0, 0, $m, 1)); }, range(1, 12)), 'series' => $series, 'stacked' => true, 'format' => 'money', ], 'sm', 'Tax collected per month, by part'); ?>
>
basis title=" – ">
No.
–' : reportMoney($value) ?>
$client) { ?>
Client Certificate Expires Exempt sales
– None on file' ?> – Expired