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:
johnnyq
2026-10-18 20:23:27 -04:00
parent f74ad10dd8
commit 0c12459eaf
16 changed files with 595 additions and 65 deletions

View File

@@ -56,12 +56,18 @@ if (isset($_POST['add_software'])) {
enforceClientAccess();
$set = softwareFormSet($_POST, $client_id);
if ($set === null) {
if (trim((string) ($_POST['name'] ?? '')) === '') {
flashAlert('A license needs a name.', 'error');
redirect();
}
// A template's vendor the client hasn't got yet is made for them from its vendor template - by someone who can add vendors
$vendor_made = false;
if (preg_match('/^template:(\d+)$/', (string) ($_POST['vendor'] ?? ''), $match)) {
$_POST['vendor'] = softwareVendorFromTemplate($match[1], $client_id, intval(lookupUserPermission('module_client')) >= 2, $vendor_made);
}
$set = softwareFormSet($_POST, $client_id);
// Started from a template, it remembers which
mysqli_query($mysqli, "INSERT INTO software SET $set, software_client_id = $client_id, software_template_id = " . softwareTemplateLiveId($_POST['software_template_id'] ?? 0));
$software_id = mysqli_insert_id($mysqli);
@@ -71,10 +77,14 @@ if (isset($_POST['add_software'])) {
tagSetForRecord('license', $software_id, (array) ($_POST['tags'] ?? []));
$name = trim($_POST['name']);
$vendor_name = $vendor_made ? (string) getFieldById('vendors', $_POST['vendor'], 'vendor_name') : '';
if ($vendor_made) {
logAudit("Vendor", "Create", "$session_name created vendor " . escapeSql($vendor_name) . " from a template for license " . escapeSql($name), $client_id, intval($_POST['vendor']));
}
logAudit("Software", "Create", "$session_name created license " . escapeSql($name . softwareSeatChangeText($changes)), $client_id, $software_id);
$warning = softwareSeatWarning($software_id);
flashAlert("License <strong>$name</strong> created" . ($keys_added ? " with $keys_added key" . ($keys_added === 1 ? '' : 's') : '') . $warning, $warning ? 'warning' : 'success');
flashAlert("License <strong>$name</strong> created" . ($keys_added ? " with $keys_added key" . ($keys_added === 1 ? '' : 's') : '') . ($vendor_made ? ", and vendor <strong>" . escapeHtml($vendor_name) . "</strong> added for the client" : '') . $warning, $warning ? 'warning' : 'success');
redirect();
@@ -96,15 +106,20 @@ if (isset($_POST['add_software_from_template'])) {
redirect();
}
$template = softwareTemplateRow($_POST['software_template_id'] ?? 0);
$software_id = softwareTemplateMakeLicense($_POST['software_template_id'] ?? 0, $client_id, $_POST);
$software_id = softwareTemplateMakeLicense($_POST['software_template_id'] ?? 0, $client_id, $_POST, intval(lookupUserPermission('module_client')) >= 2, $vendor_made);
if (!$software_id) {
flashAlert('That license template is gone or archived.', 'error');
redirect();
}
$vendor_id = intval(getFieldById('software', $software_id, 'software_vendor_id'));
$vendor_name = $vendor_made ? (string) getFieldById('vendors', $vendor_id, 'vendor_name') : '';
if ($vendor_made) {
logAudit("Vendor", "Create", "$session_name created vendor " . escapeSql($vendor_name) . " from a template for license " . escapeSql($template['software_template_name']), $client_id, $vendor_id);
}
logAudit("Software", "Create", "$session_name created license " . escapeSql($template['software_template_name']) . " from template " . escapeSql($template['software_template_name']), $client_id, $software_id);
flashAlert("License <strong>" . escapeHtml($template['software_template_name']) . "</strong> created from template <strong>" . escapeHtml($template['software_template_name']) . "</strong> - put its devices and users on it");
flashAlert("License <strong>" . escapeHtml($template['software_template_name']) . "</strong> created from template <strong>" . escapeHtml($template['software_template_name']) . "</strong>" . ($vendor_made ? ", with vendor <strong>" . escapeHtml($vendor_name) . "</strong> added for the client" : '') . " - put its devices and users on it");
redirect("/agent/software.php?client_id=$client_id");