mirror of
https://github.com/itflow-org/itflow
synced 2026-11-23 21:07:22 +00:00
QoL 82: Profit and Loss and Tax Collected show a card for each quarter on Quarterly in place of the chart, with each figure's change on the same quarter last year
This commit is contained in:
@@ -28,7 +28,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u
|
||||
- Pickers: as a page loaded, a picker's "nothing" choice showed as "- Anyone -" for a moment before it became "Anyone" - on the tickets list's filters and in pickers across the app and the client portal. It is "Anyone", in its quieter grey, from the start.
|
||||
- Lists: the date filter box - on tickets, invoices, quotes, expenses, the audit log and the rest - was empty as the page loaded, then filled in with All Time or its dates a moment later. It says so from the start.
|
||||
- Lists: the tabs along the top of the lists - Workstations, Network and Other on the assets list, a ticket's status, Admin > Users and the rest - and the tabs on an asset's, contact's or other record's page didn't change under the pointer. One that isn't picked now darkens its text when you point at it or tab to it.
|
||||
- Reports: switching Profit & Loss or Tax Collected to Quarterly changed the table but not the chart, which stayed by month - and Tax Collected opens on Quarterly. The chart now goes by quarter or month as the table does; this year's quarter under way shows what it has so far.
|
||||
- Reports: switching Profit & Loss or Tax Collected to Quarterly changed the table but not the chart, which stayed by month - and Tax Collected opens on Quarterly. Quarterly now has a card for each quarter in place of the chart: income, expenses and net profit on Profit & Loss, and taxable sales, tax collected and net tax on Tax Collected, each with its change on the same quarter last year. The quarter under way says So far and is compared with last year's to the same date, and quarters still to come are dimmed. Monthly keeps its chart.
|
||||
|
||||
### Developer Updates
|
||||
|
||||
@@ -46,7 +46,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u
|
||||
- `rmmAlertsCleanup()`, from `cron/nightly_tasks.php`, deletes alerts cleared more than `RMM_ALERTS_KEEP_DAYS` (180) ago. Only open ones are read, so the minute's poll no longer scans every alert there has been.
|
||||
- `js/itflow_select_early.js`, loaded in the `<head>` of `includes/header.php`, `client/includes/header.php`, `agent/client_onboarding.php`, `admin/getting_started.php` and `setup/index.php` (a file, as the portal allows no inline scripts), watches the page as it is parsed and takes the dashes off a `- None -` option of a `select.select2`, marking it `data-none="1"` - before the first paint, so the raw `<select>` shown until `js/itflow_select.js` runs in the footer already reads the same. It stops at `DOMContentLoaded`. `js/itflow_select.js` treats `data-none="1"` as the "nothing" choice alongside an empty value and the dashed label, and `css/itflow_custom.css` greys a single select showing it until the picker takes over (`:has(option:checked[data-none="1"])`).
|
||||
- `dateFilterLabel($dtf, $dtt)` in `functions/format.php` gives what `js/date_filter.js` shows for a range - `All Time` for 1970-01-01 to 2099-12-31 or no dates, otherwise `Y-m-d — Y-m-d`, a date that isn't one taken as no bound. The 18 pages with a `#dateFilter` write it as the box's `value`, from the same expressions as their hidden `dtf` and `dtt`. `js/date_filter.js` empties the box before it starts Flatpickr, which would otherwise try to read those words as dates, and `setDisplay()` writes them back in the same step.
|
||||
- `reportChartColumns($months, $columns, $months_shown)` in `functions/reports.php` sums a year's monthly amounts into `reportYearColumns()`'s columns for a chart, null for a column after `$months_shown` and the one under way summed as far as it has got. `agent/reports/profit_loss.php` and `agent/reports/tax_summary.php` use it, with the columns' labels, so their charts follow the Monthly / Quarterly switch.
|
||||
- `reportQuarters($year, $current_year)` in `functions/reports.php` gives a year's quarters - label, months, first and last month, `done`, `now` or `later`, and what each is compared with - and `reportQuarterSum($months, $quarter)` a quarter's share of a year of months. A report puts its `rows` (`label`, `now`, `prev`, `good`, `strong`) on each and `reportQuarterCards($quarters, $whole)` draws them, in the `.itflow-report-stats` strip, laid out by a container query on its own width: four across, two by two, or one a row. `agent/reports/profit_loss.php` and `agent/reports/tax_summary.php` show them on Quarterly in place of the chart, the latter adding up last year's tax paid on purchases for net tax. `reportChartColumns($months, $columns, $months_shown)` sums a year's months into a report's columns for a chart, null for a column still to come.
|
||||
|
||||
## [26.12]
|
||||
|
||||
|
||||
@@ -37,8 +37,10 @@ reportCategoryRows('Expense', $expenses_prev);
|
||||
|
||||
$income_total = reportGridTotals($income);
|
||||
$expense_total = reportGridTotals($expenses);
|
||||
$income_prev_total = reportGridTotals($income_prev)['total'];
|
||||
$expense_prev_total = reportGridTotals($expenses_prev)['total'];
|
||||
$income_prev_grid = reportGridTotals($income_prev);
|
||||
$expense_prev_grid = reportGridTotals($expenses_prev);
|
||||
$income_prev_total = $income_prev_grid['total'];
|
||||
$expense_prev_total = $expense_prev_grid['total'];
|
||||
|
||||
$profit = $income_total['total'] - $expense_total['total'];
|
||||
$profit_prev = $income_prev_total - $expense_prev_total;
|
||||
@@ -102,9 +104,23 @@ if (reportExporting()) {
|
||||
reportCsv("Profit and Loss $year", $csv_columns, $csv_rows);
|
||||
}
|
||||
|
||||
// The chart goes by month or quarter, as the table does - nothing for the months still to come
|
||||
// Quarterly has a card for each quarter in place of the chart - each against the same quarter last year
|
||||
$quarters = $view === 'quarter' ? reportQuarters($year, $current_year) : [];
|
||||
foreach ($quarters as &$quarter) {
|
||||
$in = reportQuarterSum($income_total['months'], $quarter);
|
||||
$out = reportQuarterSum($expense_total['months'], $quarter);
|
||||
$in_prev = reportQuarterSum($income_prev_grid['months'], $quarter);
|
||||
$out_prev = reportQuarterSum($expense_prev_grid['months'], $quarter);
|
||||
$quarter['rows'] = [
|
||||
['label' => 'Income', 'now' => $in, 'prev' => $in_prev, 'good' => 'up'],
|
||||
['label' => 'Expenses', 'now' => $out, 'prev' => $out_prev, 'good' => 'down'],
|
||||
['label' => 'Net profit', 'now' => $in - $out, 'prev' => $in_prev - $out_prev, 'good' => 'up', 'strong' => true],
|
||||
];
|
||||
}
|
||||
unset($quarter);
|
||||
|
||||
// The chart, on Monthly - nothing for the months still to come
|
||||
$months_shown = $current_year ? intval(date('n')) : 12;
|
||||
$period = $view === 'quarter' ? 'quarter' : 'month';
|
||||
$chart = [
|
||||
'income' => reportChartColumns($income_total['months'], $columns, $months_shown),
|
||||
'expenses' => reportChartColumns($expense_total['months'], $columns, $months_shown),
|
||||
@@ -162,20 +178,24 @@ $span = count($columns) + 4;
|
||||
'sub' => $margin_prev === null ? '<span class="text-body-tertiary">Nothing before to compare</span>' : escapeHtml(reportPercent($margin_prev)) . ' <span class="text-body-tertiary">' . escapeHtml($current_year ? 'same time last year' : 'in ' . ($year - 1)) . '</span>'],
|
||||
]) ?>
|
||||
|
||||
<?= reportSectionOpen("Income, expenses and profit by $period", escapeHtml((string) $year)) ?>
|
||||
<div class="card-body">
|
||||
<?= reportChart([
|
||||
'type' => 'bar',
|
||||
'labels' => array_column($columns, 0),
|
||||
'series' => [
|
||||
['label' => 'Income', 'data' => $chart['income'], 'tone' => 'success'],
|
||||
['label' => 'Expenses', 'data' => $chart['expenses'], 'tone' => 'danger'],
|
||||
['label' => 'Net profit', 'data' => $chart['profit'], 'tone' => 'accent', 'type' => 'line'],
|
||||
],
|
||||
'format' => 'money',
|
||||
], 'lg', "Income, expenses and net profit per $period") ?>
|
||||
<?php if ($quarters) { ?>
|
||||
<?= reportQuarterCards($quarters, true) ?>
|
||||
<?php } else { ?>
|
||||
<?= reportSectionOpen('Income, expenses and profit by month', escapeHtml((string) $year)) ?>
|
||||
<div class="card-body">
|
||||
<?= reportChart([
|
||||
'type' => 'bar',
|
||||
'labels' => array_column($columns, 0),
|
||||
'series' => [
|
||||
['label' => 'Income', 'data' => $chart['income'], 'tone' => 'success'],
|
||||
['label' => 'Expenses', 'data' => $chart['expenses'], 'tone' => 'danger'],
|
||||
['label' => 'Net profit', 'data' => $chart['profit'], 'tone' => 'accent', 'type' => 'line'],
|
||||
],
|
||||
'format' => 'money',
|
||||
], 'lg', 'Income, expenses and net profit per month') ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?= reportSectionOpen('Statement', escapeHtml($current_year ? 'Last year is ' . ($year - 1) . ' to ' . date('M j', strtotime($prev_to)) : 'Last year is ' . ($year - 1)), 'itflow-report-long') ?>
|
||||
<div class="table-responsive">
|
||||
|
||||
@@ -65,6 +65,37 @@ $paid_total = $sum($paid_months);
|
||||
$prev_tax_total = array_sum(array_column($prev['parts'], 'total'));
|
||||
$has_purchases = (bool) $purchases['parts'];
|
||||
|
||||
// Quarterly has a card for each quarter in place of the chart - each against the same quarter last year
|
||||
$quarters = $view === 'quarter' ? reportQuarters($year, $current_year) : [];
|
||||
if ($quarters) {
|
||||
$add_parts = function (array $parts) {
|
||||
$months = taxReportMonths();
|
||||
foreach ($parts as $part) {
|
||||
foreach ($part['months'] as $m => $amount) {
|
||||
$months[$m] += $amount;
|
||||
}
|
||||
}
|
||||
return $months;
|
||||
};
|
||||
$prev_tax_months = $add_parts($prev['parts']);
|
||||
$prev_paid_months = $has_purchases
|
||||
? $add_parts(taxReportPurchases(($year - 1) . '-01-01', $current_year ? dashboardShiftMonths(date('Y-m-d'), -12) : ($year - 1) . '-12-31')['parts'])
|
||||
: taxReportMonths();
|
||||
foreach ($quarters as &$quarter) {
|
||||
$collected = reportQuarterSum($tax_months, $quarter);
|
||||
$collected_prev = reportQuarterSum($prev_tax_months, $quarter);
|
||||
$quarter['rows'] = [
|
||||
['label' => 'Taxable', 'now' => reportQuarterSum($sales['taxable'], $quarter), 'prev' => reportQuarterSum($prev['taxable'], $quarter), 'good' => 'up'],
|
||||
['label' => 'Collected', 'now' => $collected, 'prev' => $collected_prev, 'good' => 'up', 'strong' => !$has_purchases],
|
||||
];
|
||||
if ($has_purchases) {
|
||||
$quarter['rows'][] = ['label' => 'Net tax', 'now' => $collected - reportQuarterSum($paid_months, $quarter),
|
||||
'prev' => $collected_prev - reportQuarterSum($prev_paid_months, $quarter), 'good' => 'up', 'strong' => true];
|
||||
}
|
||||
}
|
||||
unset($quarter);
|
||||
}
|
||||
|
||||
// A table row for each figure: [group, name, sub, months, emphasis]
|
||||
$grid = [];
|
||||
foreach ($sales['parts'] as $label => $part) {
|
||||
@@ -147,11 +178,12 @@ if ($has_purchases) {
|
||||
<div class="card"><div class="card-body"><?= reportEmpty($basis === 'invoiced' ? "No invoices were sent in $year." : "No payments came in during $year.", 'fa-percent', 'secondary') ?></div></div>
|
||||
<?php } else { ?>
|
||||
|
||||
<?php if ($tax_total != 0) { ?>
|
||||
<?= reportSectionOpen('Tax collected by ' . ($view === 'quarter' ? 'quarter' : 'month'), escapeHtml((string) $year)) ?>
|
||||
<?php if ($quarters) { ?>
|
||||
<?= reportQuarterCards($quarters) ?>
|
||||
<?php } elseif ($tax_total != 0) { ?>
|
||||
<?= reportSectionOpen('Tax collected by month', escapeHtml((string) $year)) ?>
|
||||
<div class="card-body">
|
||||
<?php
|
||||
// By month or quarter, as the table below is
|
||||
$months_shown = $current_year ? intval(date('n')) : 12;
|
||||
$series = [];
|
||||
$i = 0;
|
||||
@@ -167,7 +199,7 @@ if ($has_purchases) {
|
||||
'series' => $series,
|
||||
'stacked' => true,
|
||||
'format' => 'money',
|
||||
], 'sm', 'Tax collected per ' . ($view === 'quarter' ? 'quarter' : 'month') . ', by part');
|
||||
], 'sm', 'Tax collected per month, by part');
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -6813,6 +6813,67 @@ a.itflow-report-stat:focus-visible {
|
||||
color: var(--bs-secondary-color);
|
||||
}
|
||||
|
||||
/* A report's quarters on its Quarterly view (reportQuarterCards()) - a card each, in the same
|
||||
strip as the figures along the top: the quarter's lines with the change on last year's.
|
||||
Four across where they fit, two by two where they don't, one a row on a phone - never three
|
||||
and one. By the strip's own width, as the side menu changes how much there is */
|
||||
.itflow-report-quarters-wrap {
|
||||
container-type: inline-size;
|
||||
}
|
||||
.itflow-report-quarters {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
@container (min-width: 30rem) {
|
||||
.itflow-report-quarters {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
@container (min-width: 60rem) {
|
||||
.itflow-report-quarters {
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
.itflow-report-quarter {
|
||||
justify-content: flex-start;
|
||||
gap: .45rem;
|
||||
}
|
||||
.itflow-report-quarter-head {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: .45rem;
|
||||
font-size: .8rem;
|
||||
color: var(--bs-secondary-color);
|
||||
}
|
||||
.itflow-report-quarter-head strong {
|
||||
font-size: 1rem;
|
||||
color: var(--bs-body-color);
|
||||
}
|
||||
.itflow-report-quarter-rows {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) auto auto;
|
||||
align-items: baseline;
|
||||
gap: .2rem .5rem;
|
||||
font-size: .875rem;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.itflow-report-quarter-rows > span {
|
||||
white-space: nowrap;
|
||||
}
|
||||
.itflow-report-quarter-rows > span:nth-child(3n+1) {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.itflow-report-quarter-rows > span:nth-child(3n) {
|
||||
font-size: .8rem;
|
||||
}
|
||||
.itflow-report-quarter-foot {
|
||||
font-size: .75rem;
|
||||
color: var(--bs-tertiary-color);
|
||||
}
|
||||
.itflow-report-quarter.is-later {
|
||||
opacity: .55;
|
||||
}
|
||||
|
||||
.itflow-report-chart {
|
||||
position: relative;
|
||||
height: 260px;
|
||||
|
||||
@@ -1549,6 +1549,72 @@ function reportChartColumns(array $months, array $columns, $months_shown) {
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* A year's quarters, for a report's Quarterly view: label, months, first and last month,
|
||||
* whether it is 'done', 'now' (under way, this year) or 'later' (still to come), and what each
|
||||
* is compared with - the same quarter last year, or for the one under way, last year's to
|
||||
* today's date. reportQuarterCards() draws them once the report has put its 'rows' in.
|
||||
*/
|
||||
function reportQuarters($year, $current_year) {
|
||||
$month = $current_year ? intval(date('n')) : 12;
|
||||
$quarters = [];
|
||||
foreach (reportYearColumns('quarter') as $i => [$label, $first, $last]) {
|
||||
$state = $first > $month ? 'later' : ($current_year && $month <= $last ? 'now' : 'done');
|
||||
$quarters[$i] = [
|
||||
'label' => $label, 'first' => $first, 'last' => $last, 'state' => $state,
|
||||
'months' => date('M', mktime(0, 0, 0, $first, 1)) . ' – ' . date('M', mktime(0, 0, 0, $last, 1)),
|
||||
'compare' => "$label " . ($year - 1) . ($state === 'now' ? ' to ' . date('M j') : ''),
|
||||
'rows' => [],
|
||||
];
|
||||
}
|
||||
return $quarters;
|
||||
}
|
||||
|
||||
/** A quarter's share of a year's amounts by month. */
|
||||
function reportQuarterSum(array $months, array $quarter) {
|
||||
$sum = 0.0;
|
||||
for ($m = $quarter['first']; $m <= $quarter['last']; $m++) {
|
||||
$sum += $months[$m] ?? 0;
|
||||
}
|
||||
return $sum;
|
||||
}
|
||||
|
||||
/**
|
||||
* A report's quarters as a row of cards - its Quarterly view, in place of a chart that had
|
||||
* only four bars to show. Each card has the quarter's figures and how each compares with the
|
||||
* same quarter last year; the one under way says so, and the ones still to come are dimmed.
|
||||
* Each of a quarter's 'rows' is ['label' => .., 'now' => amount, 'prev' => amount,
|
||||
* 'good' => up | down, 'strong' => true for its bottom line]. $whole leaves off the cents.
|
||||
*/
|
||||
function reportQuarterCards(array $quarters, $whole = false) {
|
||||
$money = function ($amount) use ($whole) {
|
||||
return escapeHtml($whole ? reportMoneyWhole($amount) : reportMoney($amount));
|
||||
};
|
||||
$html = '<div class="itflow-report-quarters-wrap"><div class="card itflow-report-stats itflow-report-quarters">';
|
||||
foreach ($quarters as $quarter) {
|
||||
$later = $quarter['state'] === 'later';
|
||||
$html .= '<div class="itflow-report-stat itflow-report-quarter' . ($later ? ' is-later' : '') . '" data-report-quarter="' . escapeHtml($quarter['label']) . '">'
|
||||
. '<div class="itflow-report-quarter-head"><strong>' . escapeHtml($quarter['label']) . '</strong>' . escapeHtml($quarter['months'])
|
||||
. ($quarter['state'] === 'now' ? '<span class="badge rounded-pill text-bg-light border fw-normal ms-auto">So far</span>' : '') . '</div>';
|
||||
if ($later) {
|
||||
$html .= '<div class="itflow-report-quarter-foot">Still to come</div></div>';
|
||||
continue;
|
||||
}
|
||||
$html .= '<div class="itflow-report-quarter-rows">';
|
||||
foreach ($quarter['rows'] as $row) {
|
||||
$strong = !empty($row['strong']) ? ' fw-semibold' : '';
|
||||
$negative = $row['now'] < 0 ? ' text-danger' : '';
|
||||
$change = reportChange($row['now'], $row['prev']);
|
||||
$html .= '<span class="text-body-secondary' . $strong . '">' . escapeHtml($row['label']) . '</span>'
|
||||
. '<span class="text-end' . $strong . $negative . '">' . $money($row['now']) . '</span>'
|
||||
. '<span class="text-end">' . ($change === null ? '<span class="text-body-tertiary">–</span>'
|
||||
: ($change === 0 ? '<span class="text-body-secondary">0%</span>' : reportChangeHtml($row['now'], $row['prev'], $row['good'] ?? 'up'))) . '</span>';
|
||||
}
|
||||
$html .= '</div><div class="itflow-report-quarter-foot">vs ' . escapeHtml($quarter['compare']) . '</div></div>';
|
||||
}
|
||||
return $html . '</div></div>';
|
||||
}
|
||||
|
||||
/** One category's amounts summed into the report's columns. */
|
||||
function reportSumColumns(array $months, array $columns) {
|
||||
$out = [];
|
||||
|
||||
Reference in New Issue
Block a user