Contract Templates - the agreements you offer, to start a client's * contract from: its type, term, renewal and notice, support hours, rates, * net terms, an SLA for each ticket priority, and the terms themselves. * Each row says what it sets and how many contracts were started from it. * Tabs for the ones in use and the archived ones. The work is in * functions/contract.php; the handlers are admin/post/contract_template.php. */ // Default Column Sort by Filter $sort = "contract_template_name"; $order = "ASC"; require_once "includes/inc_all_admin.php"; $views = [ '' => ['label' => 'In use', 'icon' => 'fa-file-contract', 'where' => 'contract_template_archived_at IS NULL', 'title' => 'Offered on a new contract'], 'archived' => ['label' => 'Archived', 'icon' => 'fa-archive', 'where' => 'contract_template_archived_at IS NOT NULL', 'title' => 'Kept, but not offered'], ]; $show = (string) ($_GET['show'] ?? ''); $show = isset($views[$show]) ? $show : ''; $sortable_columns = [ 'contract_template_name' => "contract_template_name $order", 'contract_template_type' => "contract_template_type $order, contract_template_name ASC", 'contract_template_term_months' => "contract_template_term_months $order, contract_template_name ASC", 'contracts' => "n_contracts $order, contract_template_name ASC", ]; if (!isset($sortable_columns[$sort])) { $sort = 'contract_template_name'; } $rows = []; $num_rows = [0]; $view_counts = ['' => 0, 'archived' => 0]; if (contractsReady()) { $filters = "(contract_template_name LIKE '%$q%' OR contract_template_description LIKE '%$q%' OR contract_template_support_hours LIKE '%$q%')"; $sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS contract_templates.*, (SELECT COUNT(*) FROM contracts WHERE contracts.contract_template_id = contract_templates.contract_template_id) AS n_contracts FROM contract_templates WHERE $filters AND {$views[$show]['where']} ORDER BY {$sortable_columns[$sort]} LIMIT $record_from, $record_to"); $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); while ($row = mysqli_fetch_assoc($sql)) { $rows[] = $row; } $counts = mysqli_fetch_row(mysqli_query($mysqli, "SELECT " . implode(', ', array_map(function ($v) { return "COALESCE(SUM({$v['where']}), 0)"; }, $views)) . " FROM contract_templates WHERE $filters")); $view_counts = array_combine(array_keys($views), array_map('intval', $counts)); } $slas = contractSlaChoices(); // What a template leaves empty, a contract made from it gets from the defaults (Admin > Settings > Defaults, Admin > SLAs) - shown as such $template_defaults = billingDefaults(); $template_default_slas = []; foreach (CONTRACT_SLA_PRIORITIES as $priority => $part) { $template_default_slas[$priority] = intval(getTicketSlaId(0, $priority, false)); } $sort_link = function ($column, $label) use ($url_query_strings_sort, $sort, $disp, $order_icon) { return '' . $label . ($sort === $column ? " $order_icon" : '') . ''; }; $pill_url = function ($view) { return '?' . http_build_query(array_filter(['q' => $_GET['q'] ?? '', 'show' => $view])); }; $csrf = $_SESSION['csrf_token']; ?>
| = $sort_link('contract_template_name', 'Template') ?> | = $sort_link('contract_template_term_months', 'Term') ?> | Cover | = $sort_link('contracts', 'Contracts') ?> | |
|---|---|---|---|---|
|
= $name ?>
= escapeHtml(contractTypeLabel($row['contract_template_type'])) ?>= trim((string) $row['contract_template_description']) !== '' ? ' - ' . escapeHtml($row['contract_template_description']) : '' ?>
Archived = date('M j, Y', strtotime($row['contract_template_archived_at'])) ?>
|
= escapeHtml(contractTermLabel($row['contract_template_term_months'])) ?>
= intval($row['contract_template_auto_renew']) ? 'Renews itself' : 'Renewed by hand' ?>, = intval($row['contract_template_notice_days']) ?> days notice
|
= $cover ? escapeHtml(implode(' · ', $cover)) : 'The default rate and terms' ?>
No SLAs
|
= intval($row['n_contracts']) ?: '0' ?> |
|