mirror of
https://github.com/itflow-org/itflow
synced 2026-11-20 03:17:24 +00:00
License templates stage 2: templates carry the seats a license starts with, a renewal term, a vendor from the vendor templates and the product they are sold as (database 3.2.9); a license made from one starts with its seats, gets a renewal date worked out from the purchase date and uses the client's vendor from that vendor template, or one with the same name, or has one made from the template by someone who can add vendors; New License fills in the seats, vendor and renewal date from the template and keeps the renewal date in step with the purchase date until one is typed in; Renew starts on the template's term; new licenses can be made for several clients at once with an option to skip clients that already have one; the template page and list show the new fields and the list search covers vendor and product; the license quick look shows the product and price to Sales users; deleting a vendor template or product removes it from the templates that used it
This commit is contained in:
17
admin/database_updates/3.2.9.php
Normal file
17
admin/database_updates/3.2.9.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* ITFlow - Database update to version 3.2.9 (from 3.2.8)
|
||||
* Included by admin/database_updates.php - do not access directly
|
||||
*/
|
||||
|
||||
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
|
||||
|
||||
// What else a license made from a template starts with: its seats (blank for no limit), how
|
||||
// often it renews (1m, 3m, 6m, 1y, 2y or 3y - blank for not at all), the vendor template its
|
||||
// vendor comes from, and the product it is sold as
|
||||
mysqli_query($mysqli, "ALTER TABLE `software_templates`
|
||||
ADD `software_template_seats` int(11) DEFAULT NULL AFTER `software_template_notes`,
|
||||
ADD `software_template_term` varchar(10) DEFAULT NULL AFTER `software_template_seats`,
|
||||
ADD `software_template_vendor_template_id` int(11) NOT NULL DEFAULT 0 AFTER `software_template_term`,
|
||||
ADD `software_template_product_id` int(11) NOT NULL DEFAULT 0 AFTER `software_template_vendor_template_id`");
|
||||
@@ -3,7 +3,9 @@
|
||||
* A license template's fields - shared by its New and Edit windows
|
||||
* (software_template_add.php, software_template_edit.php), which set
|
||||
* $template (softwareTemplateRow(), or [] for a new one) before including it.
|
||||
* Posts what softwareTemplateFields() reads (functions/software_template.php).
|
||||
* Posts what softwareTemplateFields() reads (functions/software_template.php):
|
||||
* with the seats a license starts with, how often it renews, the vendor
|
||||
* template its vendor comes from and the product it is sold as.
|
||||
*
|
||||
* Should not be accessed directly.
|
||||
*/
|
||||
@@ -20,6 +22,25 @@ if ($license_type !== '' && !in_array($license_type, $license_types, true)) {
|
||||
$license_types[] = $license_type;
|
||||
}
|
||||
|
||||
$seats = $t['software_template_seats'] ?? null;
|
||||
$term = (string) ($t['software_template_term'] ?? '');
|
||||
$vendor_template_id = intval($t['software_template_vendor_template_id'] ?? 0);
|
||||
$product_id = intval($t['software_template_product_id'] ?? 0);
|
||||
|
||||
// Current vendor templates and products - and the one it has, even when archived since
|
||||
$vendor_templates = [];
|
||||
$sql = mysqli_query($mysqli, "SELECT vendor_template_id, vendor_template_name, vendor_template_description, vendor_template_archived_at FROM vendor_templates
|
||||
WHERE vendor_template_archived_at IS NULL OR vendor_template_id = $vendor_template_id ORDER BY vendor_template_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$vendor_templates[] = $row;
|
||||
}
|
||||
$products = [];
|
||||
$sql = mysqli_query($mysqli, "SELECT product_id, product_name, product_type, product_price, product_currency_code, product_frequency, product_seat_source, product_archived_at FROM products
|
||||
WHERE product_archived_at IS NULL OR product_id = $product_id ORDER BY product_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$products[] = $row;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="row g-3">
|
||||
@@ -67,6 +88,55 @@ if ($license_type !== '' && !in_array($license_type, $license_types, true)) {
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Seats</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-users"></i></span>
|
||||
<input type="number" class="form-control" name="seats" min="0" max="1000000" step="1" placeholder="No limit" value="<?= $seats === null ? '' : intval($seats) ?>">
|
||||
</div>
|
||||
<div class="form-text">What a license starts with - change it for each client.</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Renews every</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-redo-alt"></i></span>
|
||||
<select class="form-select" name="term">
|
||||
<option value="">- Doesn't renew -</option>
|
||||
<?php foreach (SOFTWARE_RENEWAL_TERMS as $value => $label) { ?>
|
||||
<option value="<?= escapeHtml($value) ?>" <?= $value === $term ? 'selected' : '' ?>><?= escapeHtml($label) ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-text">Its renewal date is worked out from when it was bought.</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Vendor</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-building"></i></span>
|
||||
<select class="form-select select2" name="vendor_template_id">
|
||||
<option value="0">- None -</option>
|
||||
<?php foreach ($vendor_templates as $row) { ?>
|
||||
<option value="<?= intval($row['vendor_template_id']) ?>" <?= intval($row['vendor_template_id']) === $vendor_template_id ? 'selected' : '' ?><?= selectOptionVendor($row['vendor_template_name'], $row['vendor_template_archived_at'] ? 'Archived' : (string) $row['vendor_template_description']) ?>><?= escapeHtml($row['vendor_template_name']) ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-text">From the vendor templates - the client's own vendor made from it, or one made for them.</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Sold as</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-box-open"></i></span>
|
||||
<select class="form-select select2" name="product_id">
|
||||
<option value="0">- None -</option>
|
||||
<?php foreach ($products as $row) {
|
||||
$type_icon = productTypes()[$row['product_type']]['icon'] ?? 'fa-wrench';
|
||||
$line = $row['product_archived_at'] ? 'Archived' : billingMoney($row['product_price'], $row['product_currency_code']) . ' · ' . productBilledText($row['product_frequency'], $row['product_seat_source']); ?>
|
||||
<option value="<?= intval($row['product_id']) ?>" <?= intval($row['product_id']) === $product_id ? 'selected' : '' ?><?= selectOptionData(['icon' => "fas $type_icon", 'description' => $line]) ?>><?= escapeHtml($row['product_name']) ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-text">From Products & Services - what you charge for it.</div>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<label class="form-label">Notes</label>
|
||||
<div class="input-group">
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
/*
|
||||
* New license for a client from a license template - from Admin > License
|
||||
* Templates and the template's page. The template gives it its name, type,
|
||||
* license type, summary and notes; this window the client, seats, key, order
|
||||
* reference and dates. It goes on the client's Licenses
|
||||
* (add_software_from_template, agent/post/software.php). &client_id= picks
|
||||
* the client.
|
||||
* license type, summary, notes and vendor, and starts its seats and renewal
|
||||
* date (its term from the purchase date, when left blank); this window the
|
||||
* client, seats, key, order reference and dates. It goes on the client's
|
||||
* Licenses (add_software_from_template, agent/post/software.php). &client_id=
|
||||
* picks the client.
|
||||
*/
|
||||
|
||||
require_once '../../includes/modal_header.php';
|
||||
@@ -22,7 +23,10 @@ if (!$template || $template['software_template_archived_at']) { ?>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body text-center text-secondary py-5">That license template is gone or archived.</div>
|
||||
<?php } else { ?>
|
||||
<?php } else {
|
||||
$term = (string) $template['software_template_term'];
|
||||
$vendor_name = $template['vendor_template_archived_at'] ? '' : (string) $template['vendor_template_name'];
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title text-truncate"><i class="fa fa-fw fa-cube me-2"></i>New license from <strong><?= escapeHtml($template['software_template_name']) ?></strong></h5>
|
||||
@@ -52,7 +56,7 @@ if (!$template || $template['software_template_archived_at']) { ?>
|
||||
<label class="form-label">Seats</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-users"></i></span>
|
||||
<input type="number" class="form-control" name="seats" min="0" step="1" placeholder="No limit">
|
||||
<input type="number" class="form-control" name="seats" min="0" step="1" placeholder="No limit" value="<?= $template['software_template_seats'] === null ? '' : intval($template['software_template_seats']) ?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
@@ -75,6 +79,7 @@ if (!$template || $template['software_template_archived_at']) { ?>
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-calendar-alt"></i></span>
|
||||
<input type="date" class="form-control" name="expire" max="2999-12-31">
|
||||
</div>
|
||||
<?php if (isset(SOFTWARE_RENEWAL_TERMS[$term])) { ?><div class="form-text">Blank is <?= escapeHtml(SOFTWARE_RENEWAL_TERMS[$term]) ?> after it was bought (or today).</div><?php } ?>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Order reference</label>
|
||||
@@ -84,7 +89,7 @@ if (!$template || $template['software_template_archived_at']) { ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="small text-secondary mt-3">Its name, type, license type, summary and notes come from the template. Put devices and users on it, and pick its vendor, from the client's Licenses.</div>
|
||||
<div class="small text-secondary mt-3">Its name, type, license type, summary and notes come from the template<?= $vendor_name !== '' ? ', and its vendor is the client\'s <strong>' . escapeHtml($vendor_name) . '</strong> - added for them if they haven\'t got it' : '' ?>. Put devices and users on it from the client's Licenses.</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="add_software_from_template" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Create</button>
|
||||
|
||||
109
admin/modals/software_template/software_template_use_several.php
Normal file
109
admin/modals/software_template/software_template_use_several.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* New licenses from a license template for several clients at once - from
|
||||
* Admin > License Templates and the template's page. Each client gets the
|
||||
* same license: its details and vendor from the template (the client's own
|
||||
* vendor made from the template's vendor template, or one made for them),
|
||||
* with the seats, dates and order reference given here once for all of them.
|
||||
* Keys and who is on each are put on from the client's Licenses. ?id= the
|
||||
* template. Made by make_licenses_from_template
|
||||
* (admin/post/software_template.php).
|
||||
*/
|
||||
|
||||
require_once '../../includes/modal_header.php';
|
||||
|
||||
$template = softwareTemplateRow($_GET['id'] ?? 0);
|
||||
|
||||
ob_start();
|
||||
|
||||
if (!$template || $template['software_template_archived_at']) { ?>
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-copy me-2"></i>New licenses</h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body text-center text-secondary py-5">That license template is gone or archived.</div>
|
||||
<?php } else {
|
||||
$software_template_id = intval($template['software_template_id']);
|
||||
$term = (string) $template['software_template_term'];
|
||||
$vendor_name = $template['vendor_template_archived_at'] ? '' : (string) $template['vendor_template_name'];
|
||||
|
||||
// The clients that already have a current one from it - said in the picker
|
||||
$has_one = [];
|
||||
$sql = mysqli_query($mysqli, "SELECT DISTINCT software_client_id FROM software WHERE software_template_id = $software_template_id AND software_archived_at IS NULL");
|
||||
while ($row = mysqli_fetch_row($sql)) {
|
||||
$has_one[intval($row[0])] = true;
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title text-truncate"><i class="fa fa-fw fa-copy me-2"></i>New licenses from <strong><?= escapeHtml($template['software_template_name']) ?></strong></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="software_template_id" value="<?= $software_template_id ?>">
|
||||
|
||||
<div class="modal-body">
|
||||
<div class="row g-3">
|
||||
<div class="col-12">
|
||||
<label class="form-label">Clients <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-users"></i></span>
|
||||
<select class="form-select select2" name="client_ids[]" multiple required data-placeholder="- Pick clients -">
|
||||
<?php
|
||||
$sql_clients = mysqli_query($mysqli, "SELECT client_id, client_name, client_abbreviation FROM clients WHERE client_archived_at IS NULL ORDER BY client_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql_clients)) {
|
||||
$client_option_id = intval($row['client_id']); ?>
|
||||
<option value="<?= $client_option_id ?>"<?= selectOptionClient($row['client_id'], $row['client_name'], $row['client_abbreviation'] ?? '') ?><?= isset($has_one[$client_option_id]) ? ' data-description="Already has one"' : '' ?>><?= escapeHtml($row['client_name']) ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" role="switch" name="skip_existing" value="1" id="softwareTemplateSkipExisting" checked>
|
||||
<label class="form-check-label" for="softwareTemplateSkipExisting">Skip clients that already have one</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Seats</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-users"></i></span>
|
||||
<input type="number" class="form-control" name="seats" min="0" step="1" placeholder="No limit" value="<?= $template['software_template_seats'] === null ? '' : intval($template['software_template_seats']) ?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Order reference</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-receipt"></i></span>
|
||||
<input type="text" class="form-control" name="purchase_reference" maxlength="200">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Purchased</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-shopping-cart"></i></span>
|
||||
<input type="date" class="form-control" name="purchase" max="2999-12-31">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Renews</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-calendar-alt"></i></span>
|
||||
<input type="date" class="form-control" name="expire" max="2999-12-31">
|
||||
</div>
|
||||
<?php if (isset(SOFTWARE_RENEWAL_TERMS[$term])) { ?><div class="form-text">Blank is <?= escapeHtml(SOFTWARE_RENEWAL_TERMS[$term]) ?> after it was bought (or today).</div><?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="small text-secondary mt-3">Each client gets the same license: its name, type, license type, summary and notes from the template<?= $vendor_name !== '' ? ', and the client\'s <strong>' . escapeHtml($vendor_name) . '</strong> as its vendor - added for those that haven\'t got it' : '' ?>. Keys, devices and users go on from each client's Licenses.</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="make_licenses_from_template" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Create</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php }
|
||||
|
||||
require_once '../../../includes/modal_footer.php';
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
/*
|
||||
* License templates (Admin > License Templates) - making, changing, copying,
|
||||
* archiving and deleting them. The work is in functions/software_template.php;
|
||||
* a license is made from one by add_software or add_software_from_template
|
||||
* archiving and deleting them, and making licenses from one for several
|
||||
* clients at once. The work is in functions/software_template.php; a single
|
||||
* license is made from one by add_software or add_software_from_template
|
||||
* (agent/post/software.php).
|
||||
*/
|
||||
|
||||
@@ -42,6 +43,50 @@ if (isset($_POST['add_software_template']) || isset($_POST['edit_software_templa
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['make_licenses_from_template'])) {
|
||||
|
||||
// The same license for each client picked - the seats, dates and order reference given once for all
|
||||
validateCSRFToken();
|
||||
|
||||
$row = softwareTemplateForRequest($_POST['software_template_id'] ?? 0);
|
||||
$software_template_id = intval($row['software_template_id']);
|
||||
if ($row['software_template_archived_at']) {
|
||||
flashAlert('That template is archived - restore it to make licenses from it.', 'error');
|
||||
redirect();
|
||||
}
|
||||
$client_ids = array_values(array_filter(array_map('intval', (array) ($_POST['client_ids'] ?? []))));
|
||||
if (!$client_ids) {
|
||||
flashAlert('Pick the clients to make one for.', 'error');
|
||||
redirect();
|
||||
}
|
||||
|
||||
$post = [
|
||||
'seats' => $_POST['seats'] ?? '',
|
||||
'purchase_reference' => $_POST['purchase_reference'] ?? '',
|
||||
'purchase' => $_POST['purchase'] ?? '',
|
||||
'expire' => $_POST['expire'] ?? '',
|
||||
];
|
||||
$result = softwareTemplateMakeForClients($software_template_id, $client_ids, $post, !empty($_POST['skip_existing']));
|
||||
|
||||
foreach ($result['made'] as $client_id => $software_id) {
|
||||
if (isset($result['vendors'][$client_id])) {
|
||||
$vendor_id = intval(getFieldById('software', $software_id, 'software_vendor_id'));
|
||||
logAudit("Vendor", "Create", "$session_name created vendor " . escapeSql((string) getFieldById('vendors', $vendor_id, 'vendor_name')) . " from a template for license " . escapeSql($row['software_template_name']), $client_id, $vendor_id);
|
||||
}
|
||||
logAudit("Software", "Create", "$session_name created license " . escapeSql($row['software_template_name']) . " from template " . escapeSql($row['software_template_name']), $client_id, $software_id);
|
||||
}
|
||||
|
||||
$made = count($result['made']);
|
||||
$skipped = count($result['skipped']);
|
||||
$vendors = count($result['vendors']);
|
||||
flashAlert(($made ? "Made $made license" . ($made === 1 ? '' : 's') : 'Made no licenses') . " from <strong>" . escapeHtml($row['software_template_name']) . "</strong>"
|
||||
. ($vendors ? ", adding vendor <strong>" . escapeHtml((string) $row['vendor_template_name']) . "</strong> for $vendors client" . ($vendors === 1 ? '' : 's') : '')
|
||||
. ($skipped ? " - skipped " . ($skipped === 1 ? escapeHtml(reset($result['skipped'])) . ", which already has one" : "$skipped clients that already have one") : ''), $made ? 'success' : 'warning');
|
||||
|
||||
redirect("software_template.php?software_template_id=$software_template_id");
|
||||
|
||||
}
|
||||
|
||||
if (isset($_GET['copy_software_template'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
@@ -157,6 +157,9 @@ if (isset($_GET['delete_vendor_template'])) {
|
||||
// If its a template reset all vendors based off this template to no template base
|
||||
mysqli_query($mysqli,"UPDATE vendors SET vendor_template_id = 0 WHERE vendor_template_id = $vendor_template_id");
|
||||
|
||||
// License templates that took their vendor from it no longer have one
|
||||
mysqli_query($mysqli, "UPDATE software_templates SET software_template_vendor_template_id = 0, software_template_updated_at = software_template_updated_at WHERE software_template_vendor_template_id = $vendor_template_id");
|
||||
|
||||
mysqli_query($mysqli,"DELETE FROM vendor_templates WHERE vendor_template_id = $vendor_template_id");
|
||||
|
||||
logAudit("Vendor Template", "Delete", "$session_name deleted vendor template $vendor_template_name");
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
|
||||
/*
|
||||
* One license template - what a license made from it starts with (its name,
|
||||
* version, summary, type, license type and notes), who made it and last
|
||||
* changed it, and its use: how many licenses have been made from it, for how
|
||||
* many clients, the seats on them, the ones renewing soon or lapsed, and the
|
||||
* latest of them. A new license for a client can be made from here. The work
|
||||
* is in functions/software_template.php.
|
||||
* version, summary, type, license type, seats, how often it renews, its vendor,
|
||||
* the product it is sold as and its notes), who made it and last changed it,
|
||||
* and its use: how many licenses have been made from it, for how many
|
||||
* clients, the seats on them, the ones renewing soon or lapsed, and the latest
|
||||
* of them. New licenses can be made from here for a client or several at
|
||||
* once. The work is in functions/software_template.php.
|
||||
*/
|
||||
|
||||
require_once "includes/inc_all_admin.php";
|
||||
@@ -41,11 +42,21 @@ while ($row = mysqli_fetch_assoc($sql)) {
|
||||
|
||||
$edit_url = "modals/software_template/software_template_edit.php?id=$software_template_id";
|
||||
$use_url = "modals/software_template/software_template_use.php?id=$software_template_id";
|
||||
$several_url = "modals/software_template/software_template_use_several.php?id=$software_template_id";
|
||||
|
||||
$term = (string) $template['software_template_term'];
|
||||
$vendor_name = (string) $template['vendor_template_name'];
|
||||
$product_name = (string) $template['product_name'];
|
||||
$facts = array_filter([
|
||||
'Type' => $template['software_template_type'] !== '' ? '<i class="fas fa-fw ' . $type_style['icon'] . ' text-secondary me-1"></i>' . escapeHtml($template['software_template_type']) : '',
|
||||
'License type' => (string) $template['software_template_license_type'] !== '' ? '<i class="fas fa-fw ' . softwareLicenseTypeIcon($template['software_template_license_type']) . ' text-secondary me-1"></i>' . escapeHtml($template['software_template_license_type']) : '',
|
||||
'Version' => escapeHtml((string) $template['software_template_version']),
|
||||
'Seats' => $template['software_template_seats'] !== null ? '<i class="fas fa-fw fa-users text-secondary me-1"></i>' . intval($template['software_template_seats']) : '',
|
||||
'Renews every' => isset(SOFTWARE_RENEWAL_TERMS[$term]) ? '<i class="fas fa-fw fa-redo-alt text-secondary me-1"></i>' . escapeHtml(SOFTWARE_RENEWAL_TERMS[$term]) . ' <span class="small text-secondary">- from when it was bought</span>' : '',
|
||||
'Vendor' => $vendor_name !== '' ? '<span class="d-inline-flex align-items-center gap-2">' . vendorTile($vendor_name, 'xs') . escapeHtml($vendor_name) . '</span>'
|
||||
. ($template['vendor_template_archived_at'] ? ' <span class="small text-secondary">- its vendor template is archived, so licenses from it get no vendor</span>' : '') : '',
|
||||
'Sold as' => $product_name !== '' ? '<a href="/agent/product.php?product_id=' . intval($template['software_template_product_id']) . '">' . escapeHtml($product_name) . '</a> <span class="small text-secondary">' . escapeHtml(softwareTemplatePriceText($template)) . '</span>'
|
||||
. ($template['product_archived_at'] ? ' <span class="small text-secondary">- archived</span>' : '') : '',
|
||||
]);
|
||||
|
||||
?>
|
||||
@@ -71,7 +82,13 @@ $facts = array_filter([
|
||||
</div>
|
||||
<div class="d-flex flex-wrap gap-2 d-print-none">
|
||||
<?php if (!$archived) { ?>
|
||||
<button type="button" class="btn btn-primary ajax-modal" data-modal-size="lg" data-modal-url="<?= $use_url ?>"><i class="fas fa-fw fa-plus me-2"></i>New license for a client</button>
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-primary ajax-modal" data-modal-size="lg" data-modal-url="<?= $use_url ?>"><i class="fas fa-fw fa-plus me-2"></i>New license for a client</button>
|
||||
<button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-label="More ways to make one"></button>
|
||||
<div class="dropdown-menu dropdown-menu-end">
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-size="lg" data-modal-url="<?= $several_url ?>"><i class="fas fa-fw fa-copy me-2"></i>For several clients</a>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<button type="button" class="btn btn-outline-secondary ajax-modal" data-modal-size="lg" data-modal-url="<?= $edit_url ?>"><i class="fas fa-fw fa-edit me-2"></i>Edit</button>
|
||||
<div class="dropdown">
|
||||
|
||||
@@ -4,8 +4,11 @@
|
||||
* Admin > License Templates - the licenses an MSP sells or looks after again
|
||||
* and again, ready to start a client's from: Microsoft 365 Business Premium,
|
||||
* an endpoint protection agent, a backup product. Each row shows what it is,
|
||||
* its type and license type, how many licenses have been made from it and for
|
||||
* how many clients, with their seats, when it was last used and last changed.
|
||||
* its type and license type, what a license from it starts with (seats, how
|
||||
* often it renews, its vendor, the product it is sold as), how many licenses
|
||||
* have been made from it and for how many clients, with their seats, when it
|
||||
* was last used and last changed. New licenses can be made from one for a
|
||||
* client or several at once.
|
||||
* A template can be changed, copied as the start of another, archived - not
|
||||
* offered for new licenses, while the licenses made from it stay - or
|
||||
* deleted. The work is in functions/software_template.php; the handlers are
|
||||
@@ -37,14 +40,19 @@ if (!isset($sortable_columns[$sort])) {
|
||||
}
|
||||
|
||||
$search = "(software_template_name LIKE '%$q%' OR software_template_version LIKE '%$q%' OR software_template_description LIKE '%$q%' OR software_template_type LIKE '%$q%'
|
||||
OR software_template_license_type LIKE '%$q%' OR software_template_notes LIKE '%$q%')";
|
||||
OR software_template_license_type LIKE '%$q%' OR software_template_notes LIKE '%$q%' OR vendor_template_name LIKE '%$q%' OR product_name LIKE '%$q%')";
|
||||
// Its vendor template and product - searched, and shown under the name
|
||||
$joins = "LEFT JOIN vendor_templates ON vendor_template_id = software_template_vendor_template_id AND software_template_vendor_template_id > 0
|
||||
LEFT JOIN products ON product_id = software_template_product_id AND software_template_product_id > 0";
|
||||
|
||||
// Its use is the current licenses made from it, for current clients - as softwareTemplateUsage() counts them
|
||||
$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS software_templates.software_template_id, software_template_name, software_template_version, software_template_description,
|
||||
software_template_type, software_template_license_type, software_template_notes, software_template_created_at, software_template_updated_at, software_template_archived_at,
|
||||
software_template_seats, software_template_term, vendor_template_name, product_name, product_price, product_currency_code, product_frequency, product_seat_source,
|
||||
COALESCE(software_template_updated_at, software_template_created_at) AS changed_at, COALESCE(updater.user_name, creator.user_name) AS changed_by,
|
||||
COALESCE(used.used_count, 0) AS used_count, used.last_used
|
||||
FROM software_templates
|
||||
$joins
|
||||
LEFT JOIN users creator ON creator.user_id = software_template_created_by AND software_template_created_by > 0
|
||||
LEFT JOIN users updater ON updater.user_id = software_template_updated_by AND software_template_updated_by > 0
|
||||
LEFT JOIN (
|
||||
@@ -64,7 +72,7 @@ while ($row = mysqli_fetch_assoc($sql)) {
|
||||
}
|
||||
$usage = softwareTemplateUsage(array_keys($rows));
|
||||
|
||||
$counts = mysqli_fetch_row(mysqli_query($mysqli, "SELECT COALESCE(SUM(software_template_archived_at IS NULL), 0), COALESCE(SUM(software_template_archived_at IS NOT NULL), 0) FROM software_templates WHERE $search"));
|
||||
$counts = mysqli_fetch_row(mysqli_query($mysqli, "SELECT COALESCE(SUM(software_template_archived_at IS NULL), 0), COALESCE(SUM(software_template_archived_at IS NOT NULL), 0) FROM software_templates $joins WHERE $search"));
|
||||
|
||||
$sort_link = function ($column, $label) use ($url_query_strings_sort, $sort, $disp, $order_icon) {
|
||||
return '<a class="text-reset text-decoration-none" href="?' . escapeHtml($url_query_strings_sort) . '&sort=' . $column . '&order=' . $disp . '">'
|
||||
@@ -92,7 +100,7 @@ $csrf = $_SESSION['csrf_token'];
|
||||
<div class="row g-2 align-items-center">
|
||||
<div class="col-lg-5 col-md-6">
|
||||
<div class="input-group">
|
||||
<input type="search" class="form-control" name="q" value="<?php if (isset($q)) { echo stripslashes(escapeHtml($q)); } ?>" placeholder="Search license templates..." title="Name, version, summary, type, license type or notes">
|
||||
<input type="search" class="form-control" name="q" value="<?php if (isset($q)) { echo stripslashes(escapeHtml($q)); } ?>" placeholder="Search license templates..." title="Name, version, summary, type, license type, notes, vendor or product">
|
||||
<button class="btn btn-dark" title="Search"><i class="fa fa-search"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -125,6 +133,13 @@ $csrf = $_SESSION['csrf_token'];
|
||||
$seats_text = $use && $use['seats'] ? $use['used'] . ' of ' . $use['seats'] . ' seats in use' : ($use && $use['used'] ? $use['used'] . ' seats in use' : '');
|
||||
$summary = trim((string) $row['software_template_description']);
|
||||
$edit_url = "modals/software_template/software_template_edit.php?id=$template_id";
|
||||
// What a license from it starts with
|
||||
$starts = array_filter([
|
||||
$row['software_template_seats'] !== null ? '<i class="fas fa-fw fa-users me-1"></i>' . intval($row['software_template_seats']) . ' seat' . (intval($row['software_template_seats']) === 1 ? '' : 's') : '',
|
||||
isset(SOFTWARE_RENEWAL_TERMS[(string) $row['software_template_term']]) ? '<i class="fas fa-fw fa-redo-alt me-1"></i>' . escapeHtml(SOFTWARE_RENEWAL_TERMS[$row['software_template_term']]) . ' term' : '',
|
||||
(string) $row['vendor_template_name'] !== '' ? '<i class="fas fa-fw fa-building me-1"></i>' . escapeHtml($row['vendor_template_name']) : '',
|
||||
(string) $row['product_name'] !== '' ? '<i class="fas fa-fw fa-box-open me-1"></i>' . escapeHtml($row['product_name']) . ' · ' . escapeHtml(softwareTemplatePriceText($row)) : '',
|
||||
]);
|
||||
?>
|
||||
<tr data-software-template-id="<?= $template_id ?>">
|
||||
<td class="ps-3">
|
||||
@@ -136,6 +151,9 @@ $csrf = $_SESSION['csrf_token'];
|
||||
<?php if ($summary !== '') { ?>
|
||||
<div class="small text-body-secondary"><?= escapeHtml($summary) ?></div>
|
||||
<?php } ?>
|
||||
<?php if ($starts) { ?>
|
||||
<div class="small text-body-secondary d-flex flex-wrap column-gap-3" data-template-starts><?php foreach ($starts as $start) { ?><span class="text-nowrap"><?= $start ?></span><?php } ?></div>
|
||||
<?php } ?>
|
||||
<?php if ($row['software_template_archived_at']) { ?>
|
||||
<div class="small text-body-secondary"><i class="fas fa-fw fa-archive me-1"></i>Archived <?= date('M j, Y', strtotime($row['software_template_archived_at'])) ?></div>
|
||||
<?php } ?>
|
||||
@@ -171,6 +189,9 @@ $csrf = $_SESSION['csrf_token'];
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-size="lg" data-modal-url="modals/software_template/software_template_use.php?id=<?= $template_id ?>">
|
||||
<i class="fas fa-fw fa-plus text-secondary me-2"></i>New license for a client
|
||||
</a>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-size="lg" data-modal-url="modals/software_template/software_template_use_several.php?id=<?= $template_id ?>">
|
||||
<i class="fas fa-fw fa-copy text-secondary me-2"></i>For several clients
|
||||
</a>
|
||||
<?php } ?>
|
||||
<a class="dropdown-item" href="post.php?copy_software_template=<?= $template_id ?>&csrf_token=<?= $csrf ?>" title="A new template starting from this one">
|
||||
<i class="fas fa-fw fa-copy text-secondary me-2"></i>Copy
|
||||
|
||||
Reference in New Issue
Block a user