Rates, net terms and SLAs come from the client's contract, else the instance defaults: database 3.5.0 adds a default after-hours rate (Settings > Defaults, now Rates and terms), gives each client whose own rate, net terms or SLAs differ from the defaults an active Standard terms contract setting just those (12-month term renewing itself, starting the day the client was added or the day before its earliest contract, archived with an archived client), deletes per-client SLA assignments and drops clients.client_rate and client_net_terms; time bills at the contract's rate, its after-hours rate or the default after-hours rate, else the default rate, new invoices are due on the contract's net terms else the default, and new tickets get the contract's SLA else the default; a client's own terms still apply until the update runs; the client add and edit windows lose the rate, terms and SLA fields for a note saying what the client is billed on and where it comes from, the Clients list loses Set Hourly Rate and Set Net Terms and shows the contract's rate, the overview's Terms shows the after-hours rate and whether terms are a contract's or the defaults, a contract's page and document show what it leaves empty from another contract in force or the default so signed documents stay unchanged, contract windows show the defaults as placeholders, contract names take a proper possessive; the client import and API create make a Standard terms contract for a rate or terms that aren't the defaults (returning contract_id), API update reports them in not_kept; the client export gives the rates, terms and SLAs as billed; demo data puts each demo client's terms on a contract; changelog updated

This commit is contained in:
johnnyq
2026-10-27 22:22:34 -04:00
parent 954f1e3688
commit 1e5bffff3c
49 changed files with 859 additions and 648 deletions

View File

@@ -3,11 +3,11 @@
/*
* ITFlow - Ticket SLA helpers
*
* SLAs are optional at every level. A ticket only gets SLA targets when an
* assignment resolves for its client + priority (client-level assignments win,
* client 0 rows are the global default, and an assignment pointing at SLA 0 is
* an explicit "no SLA" override). Tickets with ticket_sla_id = 0 are simply
* ignored by the SLA cron, the list highlighting and the reports.
* SLAs are optional. A ticket only gets SLA targets when one resolves for its
* client + priority: the SLA its client's contract in force sets for the
* priority, else the default for the priority (sla_assignments, client 0 -
* Admin > SLAs). A client has none of its own. Tickets with ticket_sla_id = 0
* are simply ignored by the SLA cron, the list highlighting and the reports.
*
* Deadlines are computed ONCE at write time (creation / priority change /
* client change / manual SLA change) and stored on the ticket as
@@ -433,8 +433,9 @@ function syncTicketSlaClock($ticket_id)
// Resolve which SLA (if any) applies to a client + priority combination.
// Returns an sla_id, or 0 when no SLA applies. A contract in force for the
// client that sets an SLA for the priority comes first (contractSlaFor() in
// functions/contract_billing.php) - $with_contract false asks only the
// client's own and the global default, what applies without one.
// functions/contract_billing.php), else the default for the priority in
// Admin > SLAs (before the 3.5.0 update, the client's own first, as it was) -
// $with_contract false gives what applies without a contract.
function getTicketSlaId($client_id, $priority, $with_contract = true)
{
global $mysqli;
@@ -452,17 +453,12 @@ function getTicketSlaId($client_id, $priority, $with_contract = true)
$sla_id = null;
// Client-level assignment wins; a row pointing at SLA 0 is an explicit
// "no SLA for this client/priority" override of the global default
if ($client_id > 0) {
$sql = mysqli_query($mysqli, "SELECT sla_assignment_sla_id FROM sla_assignments WHERE sla_assignment_client_id = $client_id AND sla_assignment_priority = '$priority' LIMIT 1");
if (mysqli_num_rows($sql)) {
$sla_id = intval(mysqli_fetch_assoc($sql)['sla_assignment_sla_id']);
}
}
// Fall back to the global default (client 0)
if (is_null($sla_id)) {
// Before the 3.5.0 update, the client's own, as it was - one pointing at SLA 0 is "no SLA"
$legacy = $client_id > 0 && function_exists('billingClientLegacyTerms') ? billingClientLegacyTerms($client_id) : null;
if ($legacy && array_key_exists((string) $priority, $legacy['slas'])) {
$sla_id = $legacy['slas'][(string) $priority];
} else {
// Else the default for the priority, from Admin > SLAs (client 0) - a client has no SLAs of its own, only its contract's
$sql = mysqli_query($mysqli, "SELECT sla_assignment_sla_id FROM sla_assignments WHERE sla_assignment_client_id = 0 AND sla_assignment_priority = '$priority' LIMIT 1");
if (mysqli_num_rows($sql)) {
$sla_id = intval(mysqli_fetch_assoc($sql)['sla_assignment_sla_id']);