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']; ?>

Contract Templates

"> [], 'default' => []]; foreach (CONTRACT_SLA_PRIORITIES as $priority => $part) { $own = $slas[intval($row["contract_template_sla_{$part}_id"])] ?? null; $sla = $own ?: ($slas[$template_default_slas[$priority]] ?? null); if ($sla) { $sla_names[$own ? 'own' : 'default'][$sla['sla_name']][] = $priority; } } $sla_text = []; foreach ($sla_names as $whose => $names) { foreach ($names as $sla_name => $priorities) { $sla_text[] = "$sla_name (" . implode(', ', $priorities) . ($whose === 'default' ? ' - default' : '') . ')'; } } $net_text = function ($days) { return intval($days) ? 'Net ' . intval($days) : 'Due on receipt'; }; $cover = array_filter([ $row['contract_template_support_hours'], $row['contract_template_rate_standard'] !== null ? number_format((float) $row['contract_template_rate_standard'], 2) . '/hr' : ($template_defaults['rate'] > 0 ? number_format($template_defaults['rate'], 2) . '/hr (default)' : ''), $row['contract_template_net_terms'] !== null ? $net_text($row['contract_template_net_terms']) : $net_text($template_defaults['net_terms']) . ' (default)', ]); ?>
Cover
Archived
, days notice
The default rate and terms' ?>
No SLAs
0' ?>
'contract templates', 'icon' => 'fa-file-contract', 'filtered' => $q !== '', 'archived' => $show === 'archived', 'views' => ['show'], 'text' => 'The agreements you offer - Fully managed, Block hours, Break/fix - to start a client\'s contract from.', 'actions' => [['label' => 'New Template', 'modal' => 'modals/contract_template/contract_template_add.php', 'size' => 'lg']], ]; require_once "../includes/filter_footer.php"; ?>