Vendor templates stage 4: add Reports > Vendor Templates showing per template the client vendors added in the period against the one before, clients with one, out of step and missing account numbers, coverage of the clients that should have it, and licenses, assets, cases and spend by permission, plus a by-client view of the vendors each should have and is missing, with CSV export, linked from the vendor templates list and template page

This commit is contained in:
johnnyq
2026-10-20 11:23:09 -04:00
parent 6bb830ed3f
commit 717c6234d5
5 changed files with 382 additions and 0 deletions

View File

@@ -597,6 +597,7 @@ If you are coming from 26.08 or earlier, the database update still has to be run
- Export and Import on Admin > Vendor Templates, and Export on a template's page and menu - a file to copy templates to another ITFlow, keep or share. Never an account number or PIN, and the account manager only when asked. A template already here by name can be left alone, added as well or replaced - replaced, it keeps its account number, PIN and who should have it, and the vendors made from it that still said what it did change with it.
- Maintenance > Starter Content: the starter vendor templates come with their support site, status page and the portal cases are opened in where they have one, and what support asks for - the tenant, the service tag, the serial number. Update brings the ones added before up to date: only those fields change, and the vendors made from them that still said what they did change with them. Phone numbers, hours and SLAs differ by region and contract, so they stay yours.
- A license template's file carries its vendor's status page and portal.
- Reports > Vendor Templates: for each template, the client vendors added from it in the period against the period before, the clients with one, how many of them are out of step with it or have no account number yet, and how many of the clients that should have one do - with, for anyone who can see Support, the licenses, assets and cases on its vendors, and for anyone who can see the books, what was spent with your own vendor from it. By client too: the vendors each should have, the ones missing, its vendors out of step or without an account number, and its open cases with them. One client can be picked, and each can be exported. How they are used, on Admin > Vendor Templates and a template's page, opens it.
- Templates can be copied, archived - not offered on New Vendor or Add to Clients, while the vendors made from them stay - restored and deleted. Deleted, its vendors and the license templates that used it stay, no longer linked to it.
- Make a template from it, in the menu of a client's vendor for an admin, starts a template from that vendor - leaving its account number, PIN and account manager, which are the client's own - and links the vendor to it, so other clients can have the same one.
- A vendor made from a template links to it from its page, for an admin.
@@ -1674,6 +1675,7 @@ If you are coming from 26.08 or earlier, the database update still has to be run
- `vendorTemplateFieldLabels()` and `vendorTemplateColumns()` have `status_page`, `portal`, `contact_phone` (country code and number) and `contact_email`; `VENDOR_TEMPLATE_SHARED` adds `status_page` and `portal`. `vendorTemplateFields()` reads them (a bad `contact_email` is refused), `vendorTemplateRowFields()` is built from the columns and takes a missing row as blank, and `vendorTemplateValueHtml()` links the sites. `vendorTemplateFormFields()` and `vendorFormSet()` (`status_page`, `portal`) carry them to vendors; the website, status page and portal are saved without their scheme or a trailing slash. `vendorWebsiteUrl()` returns '' for a scheme other than http or https.
- New `functions/vendor_template_transfer.php`: `VENDOR_TEMPLATE_FILE_FORMAT` (`itflow-vendor-templates`), `VENDOR_TEMPLATE_FILE_VERSION` (1), `VENDOR_TEMPLATE_FILE_FIELDS` and `VENDOR_TEMPLATE_FILE_MANAGER_FIELDS`, `vendorTemplatesExport($ids, $archived, $manager)`, `vendorTemplatesExportFileName()`, `vendorTemplateFileValue()`, `vendorTemplatesImportRead($contents, &$error)` (up to 1000), `vendorTemplatesImport($templates, $existing, $only_existing, $only_fields)` (`added`, `replaced`, `skipped`, `ids`, `followed`), `vendorTemplatesImportLogFollowed()`, `vendorTemplatesImportFollowedCount()` and `vendorTemplatesImportSummary()`. `admin/post/vendor_template.php`: `export_vendor_templates` (`vendor_template_ids[]`, `archived`, `manager`) and GET `export_vendor_template`, and `import_vendor_templates` (`file`, `existing` - `skip`, `copy` or `replace`), logged as Vendor Template Export and Import, and Vendor Edit on each vendor that followed. New `admin/modals/vendor_template/vendor_template_export.php` and `vendor_template_import.php`.
- `SOFTWARE_TEMPLATE_FILE_VENDOR_FIELDS` adds `status_page` and `portal`. The starter vendor templates (`starterContentVendorTemplates()`) are in the file's shape and load through the import; `update_starter_vendor_templates` (`starterUpdateVendorTemplates()`) replaces only `description`, `website`, `status_page`, `portal` and `notes`, logged as Starter Content Edit.
- Report: `agent/reports/vendor_templates.php` (`client_id` and the period; `export=csv` by template, `table=clients` by client), `vendor_templates` in `reportCatalog()` under Clients & Documentation, needing `module_client`. Licenses and assets need `module_support` with IT documentation on, cases `module_support` with ticketing on, and the spend `module_financial` with accounting on and no client picked.
- API: `vendors/create.php` and `update.php` take `vendor_status_page` and `vendor_portal`. The vendors export has Status Page and Support Portal columns (off by default), and the client export's vendors have them.
- Empty states: every list page sets `$empty_state` before including `includes/filter_footer.php`, and `includes/inc_empty_state.php` draws it with `emptyStateHtml()` (`functions/format.php`) when the list has nothing - `thing`, `icon`, `title`, `text`, `actions` (`label`, `modal` or `href`, `size`, `icon`; the first is the main one), `archived`, `view`, `filtered`, `views`, `match_title`, `match_text` and `clear_url`. `emptyStateFiltered($views)` reads the GET string for a search or filter, leaving out paging, sorting, `client_id`, `archived` and the page's views, and `emptyStateClearUrl($views)` is the page without them. `emptyStatePill($pills, $key, $default, $good)` builds a pill's own state from the page's pill array (`label`, `icon`, `title`, `alarm`), with a tick for `alarm` pills and the keys in `$good`. Files, notifications and racks call `emptyStateHtml()` in their own layout; files and notifications set `$empty_state_skip`. A page that sets nothing still gets one, worded from `$page_title`. The pages' own empty blocks (`.itflow-asset-empty` under a list) are gone. CSS: `.itflow-empty-state` with `-icon` (a grey round tile), `-title`, `-text` and `-actions`.
- Removed unused helpers and files:

View File

@@ -161,6 +161,7 @@ foreach (vendorTemplateFieldLabels() as $field) {
<a class="dropdown-item ajax-modal" href="#" data-modal-url="<?= $required_url ?>"><i class="fas fa-fw fa-clipboard-check me-2"></i>Who should have it</a>
<a class="dropdown-item" href="post.php?copy_vendor_template=<?= $vendor_template_id ?>&csrf_token=<?= $csrf ?>"><i class="fas fa-fw fa-copy me-2"></i>Copy</a>
<a class="dropdown-item" href="post.php?export_vendor_template=<?= $vendor_template_id ?>&csrf_token=<?= $csrf ?>" title="A file to import into another ITFlow - without account numbers or PINs"><i class="fas fa-fw fa-file-download me-2"></i>Export</a>
<a class="dropdown-item" href="/agent/reports/vendor_templates.php" title="Reports > Vendor Templates"><i class="fas fa-fw fa-chart-bar me-2"></i>How they are used</a>
<?php if ($archived) { ?>
<a class="dropdown-item" href="post.php?restore_vendor_template=<?= $vendor_template_id ?>&csrf_token=<?= $csrf ?>"><i class="fas fa-fw fa-redo me-2"></i>Restore</a>
<?php } else { ?>

View File

@@ -139,6 +139,9 @@ $csrf = $_SESSION['csrf_token'];
<i class="fas fa-fw fa-file-download text-secondary me-2"></i>Export
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="/agent/reports/vendor_templates.php">
<i class="fas fa-fw fa-chart-bar text-secondary me-2"></i>How they are used
</a>
<a class="dropdown-item" href="starter_content.php">
<i class="fas fa-fw fa-seedling text-secondary me-2"></i>Starter vendor templates
</a>

View File

@@ -0,0 +1,372 @@
<?php
/*
* Vendor Templates - for each template: how many client vendors were made
* from it in the period, against the period before; the clients with a
* current vendor from it, how many of those are out of step with it and how
* many have no account number yet; for one that every client (or the clients
* with a tag) should have, how many of them do; and what hangs off its
* vendors - for someone who sees Support, the current licenses and assets
* that name them and the cases logged with them in the period (and the ones
* still open), and for someone who sees the books, what was spent with our
* own vendor from it in the period. By client too - the templates each
* should have a vendor from, the ones missing, its vendors out of step or
* without an account number, and its open cases with them. One client when
* picked; everything but what was made, the cases and the spend is as it is
* now.
*/
require_once "includes/inc_report.php";
reportEnforce('vendor_templates');
$period = reportPeriod('last_90');
$client_id = reportClientId();
$admin = !empty($session_is_admin);
$sees_docs = reportFeatureOn('itdoc') && lookupUserPermission('module_support') >= 1;
$sees_cases = reportFeatureOn('ticketing') && lookupUserPermission('module_support') >= 1;
// What we spend with a vendor is the company's, not a client's - left out when one client is picked
$sees_spend = reportFeatureOn('accounting') && lookupUserPermission('module_financial') >= 1 && !$client_id;
// The current clients this user may see (the client picked)
$client_rows = [];
$sql = mysqli_query($mysqli, "SELECT client_id, client_name, client_abbreviation FROM clients WHERE client_archived_at IS NULL"
. ($client_id ? " AND client_id = $client_id" : '') . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$client_rows[intval($row['client_id'])] = $row;
}
$client_ids = array_keys($client_rows) ?: [0];
$in_clients = function ($column) use ($client_ids) {
return "$column IN (" . implode(',', $client_ids) . ")";
};
// Every current template, and archived ones a vendor was made from in the period
$made = "vendors.vendor_template_id > 0 AND " . $in_clients('vendors.vendor_client_id');
$templates = [];
$template_rows = [];
$sql = mysqli_query($mysqli, "SELECT * FROM vendor_templates
WHERE vendor_template_archived_at IS NULL OR vendor_template_id IN (SELECT vendors.vendor_template_id FROM vendors WHERE $made AND " . reportRangeSql('vendors.vendor_created_at', $period) . ")
ORDER BY vendor_template_name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$id = intval($row['vendor_template_id']);
$template_rows[$id] = $row;
$templates[$id] = ['id' => $id, 'template' => $row['vendor_template_name'], 'archived' => !empty($row['vendor_template_archived_at']),
'required' => $row['vendor_template_archived_at'] ? 0 : intval($row['vendor_template_required']), 'scope' => '',
'made' => 0, 'prev' => 0, 'clients' => 0, 'vendors' => 0, 'in_step' => 0, 'out' => 0, 'no_account' => 0, 'ours' => false,
'should' => null, 'have' => null, 'coverage' => null, 'licenses' => 0, 'assets' => 0, 'cases' => 0, 'open' => 0, 'spend' => null];
}
$required_tags = vendorTemplateRequiredTags(array_keys($templates));
// Made in the period, and the period before
foreach (['made' => false, 'prev' => true] as $key => $previous) {
$sql = mysqli_query($mysqli, "SELECT vendors.vendor_template_id, COUNT(*) FROM vendors WHERE $made AND " . reportRangeSql('vendors.vendor_created_at', $period, $previous) . " GROUP BY vendors.vendor_template_id");
while ($row = mysqli_fetch_row($sql)) {
if (isset($templates[intval($row[0])])) {
$templates[intval($row[0])][$key] = intval($row[1]);
}
}
}
// Each one's current vendors, for the clients counted - in step with it or not, with an account number or not
$by_client = [];
foreach ($client_rows as $id => $row) {
$by_client[$id] = ['client_id' => $id, 'client' => $row['client_name'], 'abbr' => (string) $row['client_abbreviation'],
'vendors' => 0, 'should' => 0, 'have' => 0, 'missing' => [], 'out' => 0, 'no_account' => 0, 'open' => 0];
}
$has_one = [];
$clients_of = [];
$sql = mysqli_query($mysqli, "SELECT vendors.* FROM vendors WHERE vendors.vendor_template_id > 0 AND vendor_archived_at IS NULL AND " . $in_clients('vendor_client_id'));
while ($vendor = mysqli_fetch_assoc($sql)) {
$id = intval($vendor['vendor_template_id']);
$cid = intval($vendor['vendor_client_id']);
if (!isset($templates[$id])) {
continue;
}
$out = (bool) vendorTemplateDifferences($template_rows[$id], $vendor);
$no_account = trim((string) $vendor['vendor_account_number']) === '';
$templates[$id]['vendors']++;
$templates[$id][$out ? 'out' : 'in_step']++;
$templates[$id]['no_account'] += $no_account ? 1 : 0;
$clients_of[$id][$cid] = true;
$has_one[$id][$cid] = true;
$by_client[$cid]['vendors']++;
$by_client[$cid]['out'] += $out ? 1 : 0;
$by_client[$cid]['no_account'] += $no_account ? 1 : 0;
}
foreach ($templates as $id => &$template) {
$template['clients'] = count($clients_of[$id] ?? []);
}
unset($template);
// Our own vendor from each, when every client is counted
if (!$client_id) {
$sql = mysqli_query($mysqli, "SELECT DISTINCT vendor_template_id FROM vendors WHERE vendor_template_id > 0 AND vendor_client_id = 0 AND vendor_archived_at IS NULL");
while ($row = mysqli_fetch_row($sql)) {
if (isset($templates[intval($row[0])])) {
$templates[intval($row[0])]['ours'] = true;
}
}
}
// What names their vendors - current licenses and assets, cases logged in the period and the ones open now
$from_template = function ($table, $vendor_column, $client_column, $where) use ($in_clients) {
global $mysqli;
$counts = [];
$sql = mysqli_query($mysqli, "SELECT vendors.vendor_template_id, COUNT(*) FROM $table JOIN vendors ON vendors.vendor_id = $table.$vendor_column
WHERE vendors.vendor_template_id > 0 AND $where AND " . $in_clients("$table.$client_column") . " GROUP BY vendors.vendor_template_id");
while ($row = mysqli_fetch_row($sql)) {
$counts[intval($row[0])] = intval($row[1]);
}
return $counts;
};
if ($sees_docs) {
foreach ($from_template('software', 'software_vendor_id', 'software_client_id', 'software_archived_at IS NULL') as $id => $count) {
if (isset($templates[$id])) {
$templates[$id]['licenses'] = $count;
}
}
foreach ($from_template('assets', 'asset_vendor_id', 'asset_client_id', 'asset_archived_at IS NULL') as $id => $count) {
if (isset($templates[$id])) {
$templates[$id]['assets'] = $count;
}
}
}
if ($sees_cases) {
foreach (['cases' => reportRangeSql('tickets.ticket_created_at', $period), 'open' => 'tickets.ticket_resolved_at IS NULL AND tickets.ticket_closed_at IS NULL'] as $key => $where) {
foreach ($from_template('tickets', 'ticket_vendor_id', 'ticket_client_id', "tickets.ticket_archived_at IS NULL AND $where") as $id => $count) {
if (isset($templates[$id])) {
$templates[$id][$key] = $count;
}
}
}
$sql = mysqli_query($mysqli, "SELECT tickets.ticket_client_id, COUNT(*) FROM tickets JOIN vendors ON vendors.vendor_id = tickets.ticket_vendor_id
WHERE vendors.vendor_template_id > 0 AND tickets.ticket_archived_at IS NULL AND tickets.ticket_resolved_at IS NULL AND tickets.ticket_closed_at IS NULL AND " . $in_clients('tickets.ticket_client_id') . "
GROUP BY tickets.ticket_client_id");
while ($row = mysqli_fetch_row($sql)) {
if (isset($by_client[intval($row[0])])) {
$by_client[intval($row[0])]['open'] = intval($row[1]);
}
}
}
// What we spent with our own vendor from each in the period - as Spend by Vendor counts it
if ($sees_spend) {
foreach ($templates as $id => &$template) {
$template['spend'] = $template['ours'] ? 0.0 : null;
}
unset($template);
$sql = mysqli_query($mysqli, "SELECT vendors.vendor_template_id, SUM(expense_amount) FROM expenses JOIN vendors ON vendors.vendor_id = expense_vendor_id
WHERE vendors.vendor_template_id > 0 AND vendors.vendor_client_id = 0 AND " . reportRangeSql('expense_date', $period) . " GROUP BY vendors.vendor_template_id");
while ($row = mysqli_fetch_row($sql)) {
if (isset($templates[intval($row[0])])) {
$templates[intval($row[0])]['spend'] = round(floatval($row[1]), 2);
}
}
}
// Who should have each - and which have one
foreach ($templates as $id => &$template) {
if (!$template['required']) {
continue;
}
$template['scope'] = vendorTemplateScopeText($template['required'], $required_tags[$id]);
$template['should'] = $template['have'] = 0;
$sql = mysqli_query($mysqli, "SELECT client_id FROM clients WHERE " . vendorTemplateScopeSql($template['required'], array_keys($required_tags[$id]))
. ($client_id ? " AND client_id = $client_id" : '') . clientScopeSql('clients.client_id'));
while ($row = mysqli_fetch_row($sql)) {
$cid = intval($row[0]);
$template['should']++;
if (isset($has_one[$id][$cid])) {
$template['have']++;
$by_client[$cid]['have']++;
} else {
$by_client[$cid]['missing'][] = $template['template'];
}
$by_client[$cid]['should']++;
}
$template['coverage'] = $template['should'] ? reportShare($template['have'], $template['should'], 1) : null;
}
unset($template);
foreach ($templates as &$row) {
$row['change'] = reportChange($row['made'], $row['prev']);
}
unset($row);
uasort($templates, function ($a, $b) {
return $b['clients'] <=> $a['clients'] ?: $b['made'] <=> $a['made'] ?: strcasecmp($a['template'], $b['template']);
});
$templates = array_values($templates);
// Only the clients something applies to - most missing first
$by_client = array_values(array_filter($by_client, function ($c) {
return $c['should'] || $c['vendors'];
}));
usort($by_client, function ($a, $b) {
return count($b['missing']) <=> count($a['missing']) ?: $b['out'] <=> $a['out'] ?: $b['no_account'] <=> $a['no_account'] ?: strcasecmp($a['client'], $b['client']);
});
$zero = function ($value, $tone = '') {
return $value ? '<span class="fw-semibold' . ($tone ? " text-$tone-emphasis" : '') . '">' . reportCount($value) . '</span>' : '<span class="itflow-report-zero">0</span>';
};
$columns = [
'template' => ['label' => 'Template', 'html' => function ($row) use ($admin) {
$name = escapeHtml($row['template']);
return ($admin ? '<a href="/admin/vendor_template.php?vendor_template_id=' . $row['id'] . '">' . $name . '</a>' : $name)
. ($row['archived'] ? ' <span class="badge text-bg-light border fw-normal">Archived</span>' : '');
}],
'scope' => ['label' => 'Required of', 'html' => function ($row) {
return $row['scope'] !== '' ? '<span class="small">' . escapeHtml($row['scope']) . '</span>' : '<span class="itflow-report-zero">–</span>';
}],
'made' => ['label' => 'Added', 'type' => 'count', 'title' => 'Client vendors made from it in the period'],
'change' => ['label' => 'Change', 'type' => 'percent', 'csv' => false, 'html' => function ($row) {
return $row['change'] === null ? '<span class="itflow-report-zero">–</span>' : '<span class="small">' . reportChangeHtml($row['made'], $row['prev'], 'up') . '</span>';
}],
'clients' => ['label' => 'Clients', 'type' => 'count', 'class' => 'fw-semibold', 'title' => 'Clients with a current vendor from it'],
'vendors' => ['label' => 'Vendors', 'type' => 'count', 'screen' => false],
'out' => ['label' => 'Out of step', 'type' => 'count', 'title' => 'Their vendors that say something other than the template does', 'html' => function ($row) use ($admin, $zero) {
if ($row['out'] && $admin) {
return '<a class="fw-semibold text-warning-emphasis" href="/admin/vendor_template.php?vendor_template_id=' . $row['id'] . '&amp;view=out#vendorTemplateVendors">' . reportCount($row['out']) . '</a>';
}
return $zero($row['out'], 'warning');
}],
'no_account' => ['label' => 'No account number', 'type' => 'count', 'title' => "Their vendors without the client's account number", 'html' => function ($row) use ($zero) {
return $zero($row['no_account'], 'warning');
}],
'should' => ['label' => 'Should have one', 'type' => 'count', 'screen' => false],
'have' => ['label' => 'Have one', 'type' => 'count', 'screen' => false],
'coverage' => ['label' => 'Coverage', 'type' => 'percent', 'title' => 'Of the clients that should have it, how many do', 'html' => function ($row) {
if ($row['coverage'] === null) {
return '<span class="itflow-report-zero">–</span>';
}
$tone = $row['coverage'] >= 100 ? 'success' : ($row['coverage'] >= 75 ? 'warning' : 'danger');
return '<div class="d-flex align-items-center justify-content-end gap-2"><div class="progress itflow-report-meter" style="width: 4rem" role="presentation">'
. '<div class="progress-bar bg-' . $tone . '" style="width: ' . round($row['coverage']) . '%"></div></div>'
. '<span class="small text-nowrap" title="' . $row['have'] . ' of ' . $row['should'] . ' clients">' . $row['have'] . ' of ' . $row['should'] . '</span></div>';
}],
];
if ($sees_docs) {
$columns['licenses'] = ['label' => 'Licenses', 'type' => 'count', 'title' => 'Current licenses from their vendors'];
$columns['assets'] = ['label' => 'Assets', 'type' => 'count', 'title' => 'Current assets bought from their vendors'];
}
if ($sees_cases) {
$columns['cases'] = ['label' => 'Cases', 'type' => 'count', 'title' => 'Tickets with their vendors on them, opened in the period'];
$columns['open'] = ['label' => 'Open cases', 'type' => 'count', 'title' => 'Tickets with their vendors on them, open now', 'html' => function ($row) use ($zero) {
return $zero($row['open'], 'warning');
}];
}
if ($sees_spend) {
$columns['spend'] = ['label' => 'Spent', 'type' => 'money', 'title' => 'Expenses with our own vendor from it in the period', 'html' => function ($row) {
return $row['spend'] === null ? '<span class="itflow-report-zero" title="Not one of our own vendors">–</span>' : ($row['spend'] ? reportMoney($row['spend']) : '<span class="itflow-report-zero">' . reportMoney(0) . '</span>');
}];
}
$client_columns = [
'client' => ['label' => 'Client', 'html' => function ($row) {
return reportClientCell($row['client_id'], $row['client'], $row['abbr'], 'vendors.php');
}],
'vendors' => ['label' => 'Vendors', 'type' => 'count', 'title' => 'Current vendors made from a template'],
'should' => ['label' => 'Should have', 'type' => 'count'],
'have' => ['label' => 'Have', 'type' => 'count'],
'missing' => ['label' => 'Missing', 'sort' => false, 'class' => 'itflow-report-text', 'csv' => function ($row) {
return implode(', ', $row['missing']);
}, 'html' => function ($row) {
return $row['missing'] ? '<span class="small text-warning-emphasis">' . escapeHtml(implode(', ', $row['missing'])) . '</span>' : ($row['should'] ? '<span class="small text-success"><i class="fas fa-check me-1"></i>None</span>' : '');
}],
'out' => ['label' => 'Out of step', 'type' => 'count', 'title' => 'Its vendors that say something other than their template', 'html' => function ($row) use ($zero) {
return $zero($row['out'], 'warning');
}],
'no_account' => ['label' => 'No account number', 'type' => 'count', 'html' => function ($row) use ($zero) {
return $zero($row['no_account'], 'warning');
}],
];
if ($sees_cases) {
$client_columns['open'] = ['label' => 'Open cases', 'type' => 'count', 'title' => 'Its tickets open now with a vendor from a template on them'];
}
$sum = function ($key) use ($templates) {
return array_sum(array_map('floatval', array_column($templates, $key)));
};
$made_total = intval($sum('made'));
$previous = intval($sum('prev'));
$vendor_total = intval($sum('vendors'));
$out_total = intval($sum('out'));
$should_total = intval($sum('should'));
$have_total = intval($sum('have'));
$totals = ['template' => 'Total', 'made' => $made_total, 'vendors' => $vendor_total, 'out' => $out_total, 'no_account' => intval($sum('no_account')), 'should' => $should_total, 'have' => $have_total,
'clients' => count(array_filter($by_client, function ($c) { return $c['vendors'] > 0; })), 'licenses' => intval($sum('licenses')), 'assets' => intval($sum('assets')),
'cases' => intval($sum('cases')), 'open' => intval($sum('open'))];
if ($sees_spend) {
$totals['spend'] = round($sum('spend'), 2);
}
$client_totals = ['client' => 'Total', 'vendors' => array_sum(array_column($by_client, 'vendors')), 'should' => array_sum(array_column($by_client, 'should')), 'have' => array_sum(array_column($by_client, 'have')),
'out' => array_sum(array_column($by_client, 'out')), 'no_account' => array_sum(array_column($by_client, 'no_account')), 'open' => array_sum(array_column($by_client, 'open'))];
if (reportExporting('clients')) {
reportCsv('Vendor Templates by Client', $client_columns, $by_client, $client_totals);
}
if (reportExporting()) {
reportCsv('Vendor Templates ' . $period['start'] . ' to ' . $period['end'], $columns, $templates, $totals);
}
require_once "includes/inc_report_layout.php";
$top = array_slice(array_filter($templates, function ($t) { return $t['clients'] > 0; }), 0, 12);
$fully = count(array_filter($by_client, function ($c) { return $c['should'] && !$c['missing']; }));
$with_required = count(array_filter($by_client, function ($c) { return $c['should']; }));
$stats = [
['label' => 'Vendors added', 'value' => reportCount($made_total), 'sub' => $previous || $made_total ? reportChangeHtml($made_total, $previous, 'up', 'the period before') : '<span class="text-body-tertiary">from a template</span>'],
['label' => 'In step', 'value_html' => $vendor_total ? reportRateHtml(reportShare($vendor_total - $out_total, $vendor_total, 1), 95, 80) : '-',
'sub' => $vendor_total ? ($out_total ? '<span class="text-warning-emphasis">' . reportCount($out_total) . ' out of step</span> <span class="text-body-tertiary">of ' . reportCount($vendor_total) . ' vendors</span>'
: '<span class="text-body-tertiary">Every one of the ' . reportCount($vendor_total) . ' vendors</span>') : '<span class="text-body-tertiary">No vendors from a template yet</span>'],
['label' => 'Have what they should', 'value_html' => $should_total ? reportRateHtml(reportShare($have_total, $should_total, 1), 100, 75) : '-',
'sub' => $should_total ? $fully . ' of ' . $with_required . ' <span class="text-body-tertiary">client' . ($with_required === 1 ? '' : 's') . ' have every one</span>' : '<span class="text-body-tertiary">No template is required of anyone</span>'],
];
if ($sees_spend) {
$stats[] = ['label' => 'Spent with them', 'value' => reportMoney($totals['spend']), 'sub' => '<span class="text-body-tertiary">our own vendors from a template</span>'];
} elseif ($sees_cases) {
$stats[] = ['label' => 'Open cases', 'value' => reportCount($totals['open']), 'tone' => $totals['open'] ? 'warning' : '', 'sub' => reportCount($totals['cases']) . ' <span class="text-body-tertiary">opened in the period</span>'];
}
?>
<div class="itflow-report">
<?php reportHeader('vendor_templates', [
'period' => $period,
'years' => reportPastYears("SELECT DISTINCT YEAR(vendor_created_at) AS y FROM vendors WHERE vendor_template_id > 0"),
'client' => $client_id,
'export' => ['' => 'By template', 'clients' => 'By client'],
'print_meta' => $client_id ? reportClientName($client_id) : '',
]); ?>
<?= reportStats($stats) ?>
<?php if ($top) { ?>
<?= reportSectionOpen('Most used', 'Clients with a vendor from each') ?>
<div class="card-body">
<?= reportChart(['type' => 'bar', 'horizontal' => true, 'labels' => array_column($top, 'template'),
'series' => [['label' => 'In step', 'tone' => 'accent', 'data' => array_column($top, 'in_step')], ['label' => 'Out of step', 'tone' => 'warning', 'data' => array_column($top, 'out')]],
'stacked' => true, 'format' => 'count'], '', 'Vendors from each, in step and out of step') ?>
</div>
</div>
<?php } ?>
<?= reportSectionOpen('By template', 'Most clients first', 'itflow-report-long') ?>
<?= reportTable($columns, $templates, ['empty' => 'There are no vendor templates yet.', 'totals' => $totals]) ?>
<div class="card-footer small text-body-secondary">
Added counts the client vendors made from each in the period; the rest count the current vendors from it, as they are now. Out of step is a vendor that says something other than its template
in the fields every client shares - not its account number, PIN or account manager. Coverage is how many of the clients a template is required of have a current vendor from it.
<?= $sees_docs ? 'Licenses and assets are the current ones naming a vendor from it.' : '' ?>
<?= $sees_cases ? 'Cases are the tickets with a vendor from it on them, opened in the period.' : '' ?>
<?= $sees_spend ? 'Spent is the expenses with our own vendor from it in the period, as Spend by Vendor counts them.' : '' ?>
</div>
</div>
<?= reportSectionOpen('By client', 'Most missing first') ?>
<?= reportTable($client_columns, $by_client, ['empty' => 'No client has a vendor from a template, or one it should have.', 'totals' => $client_totals]) ?>
</div>
</div>
<?php require_once "../../includes/footer.php"; ?>
<script src="/js/reports.js"></script>

View File

@@ -184,6 +184,10 @@ function reportCatalog() {
'title' => 'License Templates', 'icon' => 'fa-cube', 'module' => 'module_support', 'feature' => ['itdoc'],
'description' => 'How much each license template is used, the seats on its licenses against the ones bought, how many of the clients that should have one do, and how many are billed - by template and by client.',
],
'vendor_templates' => [
'title' => 'Vendor Templates', 'icon' => 'fa-building', 'module' => 'module_client', 'feature' => [],
'description' => 'How many clients have a vendor from each template, how many of the clients that should have one do, which are out of step with their template, and the licenses, assets, cases and spend on their vendors - by template and by client.',
],
'credential_rotation' => [
'title' => 'Credential Rotation', 'icon' => 'fa-key', 'module' => 'module_credential', 'feature' => ['itdoc'],
'description' => 'Passwords that have not changed in a while, oldest first.',