From c814eaa6d8b447ce69e55c0aab0b8c9402aa32b4 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Mon, 16 Nov 2026 12:42:38 -0500 Subject: [PATCH] Contract rates of 0 are a rate of nothing rather than the default: contractFromInput saves an entered 0 as 0.00 and only an empty rate as NULL, for contracts, contract templates and the API; contractTicketRate, contractTermsOn, contractUsualTerms, contractClientTerms and the clients list rate treat a rate as set when it is not NULL instead of above 0, and contractClientTerms gives null for no after-hours rate so a 0 after-hours rate shows on the client overview, terms note and export; the no-rate warnings on Unbilled Time, Unbilled Tickets, Time Detail by Client and the bill-a-ticket window only flag a 0 rate from the default; the contract and template forms say a rate of 0 bills that time at nothing; existing contracts have no 0 rates stored so nothing changes for them; 26.11.9 changelog entries --- CHANGELOG.md | 2 ++ .../contract_template_form.php | 2 +- agent/client_overview.php | 2 +- agent/clients.php | 2 +- agent/modals/client/client_terms_note.php | 2 +- agent/modals/contract/contract_form.php | 2 +- agent/modals/ticket/ticket_invoice_add.php | 2 +- agent/reports/client_ticket_time_detail.php | 2 +- agent/reports/tickets_unbilled.php | 5 +++-- agent/unbilled_time.php | 7 ++++--- functions/client_export.php | 2 +- functions/contract.php | 4 ++-- functions/contract_billing.php | 18 +++++++++--------- 13 files changed, 28 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd2d554e7..bd44f4a4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - API: accounts can be read with their balances, added, changed, archived, unarchived and deleted while nothing is on them; other income and transfers between accounts can be read, recorded, changed and deleted; recurring expenses can be read, set up, changed, paused and resumed, recorded now, moved on past missed runs and deleted. A line cleared on a reconciled statement keeps its date, amount and account. - API: contracts can be read - one with its prepaid hours and where its signing stands - added, changed, made active, renewed, cancelled and deleted, sent for signature or sent the link again, and the request withdrawn. Prepaid hours can be added, with a draft invoice for them, and deleted, done tickets' time drawn on them and a ticket's hours put back, and the recurring invoice that bills a contract made, linked or unlinked. Countersigning and contract PDFs stay in ITFlow. - API: a client's files can be read, uploaded, downloaded, renamed, moved, archived, unarchived and deleted once archived, and its folders read, made, renamed, moved and deleted - what is in a deleted folder moves up. An upload comes base64 in the request, so the server's upload size caps it. +- Contracts: an hourly or after-hours rate of 0 is now a rate of nothing - time it covers bills at no charge - where 0 used to be taken as empty, so the default rate applied. Leave a rate empty for the default, as before. A plan that covers business-hours time and bills after hours, say, is a contract with an hourly rate of 0 and an after-hours rate. Unbilled Time and its reports show such a contract's tickets at its rate, not as having no rate, and the client's terms show the after-hours rate even when it is 0. ### Bug Fixes @@ -90,6 +91,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - `fileUploadExtensions()` (`functions/files.php`) is the list of file kinds Files take, which `agent/post/file.php` held inline; Upload Files and `files/create` both check against it. `files/create` takes the file base64 in the JSON body (`file_data`), as `validate_api_key.php` reads the body as JSON, stores it under the same unguessable name an upload gets and reads its type from the file. `files/download` answers with the file itself, `application/octet-stream` and `nosniff`, as an attachment. - `enforce_api_rbac.php` maps `accounts`, `revenues`, `transfers` and `recurring_expenses` to `module_financial`, `contracts` and `contract_hours` to `module_sales`, `files` and `folders` to `module_support`, and `events`, `calendars` and `trips` to `''` - their endpoints check `calendarEventCan()` and `tripCanEdit()` as the pages do. `skip`, `record`, `move_on`, `activate`, `withdraw`, `draw`, `put_back`, `recurring` and `unlink` are at level 2, and `download.php` reads, at level 1 and not a write. - `php_flag engine off` in `uploads/.htaccess`, its `backups`, `expenses`, `tmp` and `canned_responses` folders and `scripts/.htaccess` is wrapped in ``. Apache only knows `php_flag` under mod_php - with PHP-FPM through `mod_proxy_fcgi` it stops on the line and answers every request in the folder with a 500. Under FPM, PHP still can't run there: `uploads/.htaccess` denies `.php`, `.phtml`, `.phar` and the rest by name, and the other five deny everything. +- A contract's or contract template's rate of 0 is kept: `contractFromInput()` saves an entered 0 as `0.00` and only an empty field as `NULL`. `contractTicketRate()`, `contractTermsOn()`, `contractUsualTerms()`, `contractClientTerms()` and the clients list treat a rate as set when it isn't `NULL`, rather than above 0, and `contractClientTerms()` gives `null` for no after-hours rate rather than 0. The no-rate warnings on Unbilled Time, Unbilled Tickets, Time Detail by Client and the bill-a-ticket window are for a rate of 0 from the default only (`default_rate`). Contracts saved before kept no 0 rates - 0 was saved as `NULL` - so nothing changes for them. ## [26.11.8] diff --git a/admin/modals/contract_template/contract_template_form.php b/admin/modals/contract_template/contract_template_form.php index 910f2491c..c5118ac6e 100644 --- a/admin/modals/contract_template/contract_template_form.php +++ b/admin/modals/contract_template/contract_template_form.php @@ -145,7 +145,7 @@ $tab = 'templateTab' . bin2hex(random_bytes(3)); - While the contract is in force, time bills at these rates - the after-hours one for tickets opened outside business hours - and new invoices are due on these terms. Leave one empty and the default in Admin > Settings > Defaults applies. + While the contract is in force, time bills at these rates - the after-hours one for tickets opened outside business hours - and new invoices are due on these terms. Leave one empty and the default in Admin > Settings > Defaults applies - a rate of 0 bills that time at nothing. $part) { ?>
diff --git a/agent/client_overview.php b/agent/client_overview.php index 6af138702..a3b652660 100644 --- a/agent/client_overview.php +++ b/agent/client_overview.php @@ -593,7 +593,7 @@ $money_format = function ($amount) use ($currency_format, $client_currency_code, ?> Terms /hr - 0 ? ', ' . $money_format($overview_after) . '/hr after hours' : '' ?> + From diff --git a/agent/clients.php b/agent/clients.php index bb9128d76..5faec8735 100644 --- a/agent/clients.php +++ b/agent/clients.php @@ -297,7 +297,7 @@ if ($clients) { if (contractsReady()) { $rate_today = date('Y-m-d'); $sql_rates = mysqli_query($mysqli, "SELECT contract_client_id AS id, contract_rate_standard AS rate, contract_name FROM contracts - WHERE contract_client_id IN ($page_ids) AND contract_status IN ('Active', 'Ended', 'Cancelled') AND contract_archived_at IS NULL AND contract_rate_standard > 0 + WHERE contract_client_id IN ($page_ids) AND contract_status IN ('Active', 'Ended', 'Cancelled') AND contract_archived_at IS NULL AND contract_rate_standard IS NOT NULL AND contract_start_date IS NOT NULL AND contract_start_date <= '$rate_today' AND (contract_end_date IS NULL OR contract_end_date >= '$rate_today' OR (contract_status = 'Active' AND contract_auto_renew = 1)) ORDER BY contract_start_date DESC, contract_id DESC"); diff --git a/agent/modals/client/client_terms_note.php b/agent/modals/client/client_terms_note.php index b1264b538..859d56bec 100644 --- a/agent/modals/client/client_terms_note.php +++ b/agent/modals/client/client_terms_note.php @@ -27,7 +27,7 @@ $terms_note_from = count($terms_note_names) > 1 ? implode(', ', array_slice($ter
Rates, net terms and SLAs
- /hr 0 ? ', ' . $terms_note_money($terms_note['after_hours'][0]) . '/hr after hours' : '' ?>, + /hr, - 1 ? ', the contracts in force, with the defaults for anything they leave empty.' : ', the contract in force, with the defaults for anything it leaves empty.') : 'the defaults, as no contract in force sets them.' ?>
diff --git a/agent/modals/contract/contract_form.php b/agent/modals/contract/contract_form.php index c76da8add..af867937e 100644 --- a/agent/modals/contract/contract_form.php +++ b/agent/modals/contract/contract_form.php @@ -308,7 +308,7 @@ $tab = 'contractTab' . bin2hex(random_bytes(3));
- While the contract is in force, time bills at these rates - the after-hours one for tickets opened outside business hours - and new invoices are due on these terms. Leave one empty and the default in Admin > Settings > Defaults applies. + While the contract is in force, time bills at these rates - the after-hours one for tickets opened outside business hours - and new invoices are due on these terms. Leave one empty and the default in Admin > Settings > Defaults applies - a rate of 0 bills that time at nothing. $part) { ?> diff --git a/agent/modals/ticket/ticket_invoice_add.php b/agent/modals/ticket/ticket_invoice_add.php index 1b623e09d..25b23f5c3 100644 --- a/agent/modals/ticket/ticket_invoice_add.php +++ b/agent/modals/ticket/ticket_invoice_add.php @@ -187,7 +187,7 @@ ob_start(); -
0 ? ($row['default_rate'] ? 'The default rate - no contract in force sets one.' : escapeHtml(ucfirst($row['rate_note'])) . '.') : 'No rate - no contract in force sets one, and there is no default.' ?>
+
0 || !$row['default_rate'] ? ($row['default_rate'] ? 'The default rate - no contract in force sets one.' : escapeHtml(ucfirst($row['rate_note'])) . '.') : 'No rate - no contract in force sets one, and there is no default.' ?>
diff --git a/agent/reports/client_ticket_time_detail.php b/agent/reports/client_ticket_time_detail.php index b34432198..bf56f407f 100644 --- a/agent/reports/client_ticket_time_detail.php +++ b/agent/reports/client_ticket_time_detail.php @@ -141,7 +141,7 @@ $hours = function ($seconds) { h logged · h to bill 1) { ?>· rates vary · - 0) { ?>· /h · + 0 || !$client['default_rate']) { ?>· /h ·
diff --git a/agent/reports/tickets_unbilled.php b/agent/reports/tickets_unbilled.php index 3642e06d0..d5a4e3ec4 100644 --- a/agent/reports/tickets_unbilled.php +++ b/agent/reports/tickets_unbilled.php @@ -51,7 +51,8 @@ $rate_html = function ($row) { if (count($row['rates'] ?? []) > 1) { return 'Varies'; } - if ($row['rate'] <= 0) { + // No rate is none from a contract and no default - a contract's rate of 0 is one + if ($row['rate'] <= 0 && $row['default_rate']) { return 'No rate'; } $source = $row['rate_source'] ?? ''; @@ -118,7 +119,7 @@ if (reportExporting()) { require_once "includes/inc_report_layout.php"; $no_time = count(array_filter($tickets, function ($t) { return $t['billable_hours'] <= 0; })); -$no_rate = count(array_filter($tickets, function ($t) { return $t['rate'] <= 0; })); +$no_rate = count(array_filter($tickets, function ($t) { return $t['rate'] <= 0 && $t['default_rate']; })); $over_30 = array_filter($tickets, function ($t) { return $t['waiting'] > 30; }); ?> diff --git a/agent/unbilled_time.php b/agent/unbilled_time.php index a1c55997b..20bd3e434 100644 --- a/agent/unbilled_time.php +++ b/agent/unbilled_time.php @@ -61,7 +61,8 @@ foreach ($clients as $c) { $total['value'] += $c['value']; $total['oldest'] = max($total['oldest'], $c['oldest']); $total['no_time'] += $c['no_time']; - $total['no_rate'] += $c['tickets'] && $c['rate'] <= 0 ? 1 : 0; + // No rate is none from a contract and no default - a contract's rate of 0 is one + $total['no_rate'] += $c['tickets'] && $c['rate'] <= 0 && $c['default_rate'] ? 1 : 0; $total['expenses'] += count($c['expenses'] ?? []); $total['expense_value'] += $c['expense_value'] ?? 0; $total['expense_cost'] += $c['expense_cost'] ?? 0; @@ -116,7 +117,7 @@ $hours_text = function ($hours) { of time - 0 ? $money($this_client['rate']) . ' an hour' . (in_array($this_client['rate_source'] ?? '', ['contract', 'after_hours'], true) ? ', ' . escapeHtml($this_client['rate_note']) : '') : 'no rate set')) : 'At each client\'s hourly rate' ?> + 0 || !$this_client['default_rate']) ? $money($this_client['rate']) . ' an hour' . (in_array($this_client['rate_source'] ?? '', ['contract', 'after_hours'], true) ? ', ' . escapeHtml($this_client['rate_note']) : '') : 'no rate set')) : 'At each client\'s hourly rate' ?>
@@ -450,7 +451,7 @@ $hours_text = function ($hours) { - 1) { ?> Each its own - 0) { ?> + 0 || !$c['default_rate']) { ?> Settings > Defaults">default' : (in_array($c['rate_source'] ?? '', ['contract', 'after_hours'], true) ? '
contract
' : '') ?> No rate diff --git a/functions/client_export.php b/functions/client_export.php index 6182701bd..4eadea789 100644 --- a/functions/client_export.php +++ b/functions/client_export.php @@ -464,7 +464,7 @@ function clientExportRows($dataset, $client_id, $options) { 'name' => $row['client_name'], 'abbreviation' => $row['client_abbreviation'], 'industry' => $row['client_type'], 'website' => $row['client_website'], 'referral' => $row['client_referral'], 'lead' => clientExportYes($row['client_lead']), 'tags' => clientExportTags('client_tags', 'client_id', [$client_id])[$client_id] ?? '', - 'hourly_rate' => $terms ? sprintf('%.2f', $terms['rate']['rate']) : '', 'after_hours_rate' => $terms && $terms['after_hours'][0] > 0 ? sprintf('%.2f', $terms['after_hours'][0]) : '', + 'hourly_rate' => $terms ? sprintf('%.2f', $terms['rate']['rate']) : '', 'after_hours_rate' => $terms && $terms['after_hours'][0] !== null ? sprintf('%.2f', $terms['after_hours'][0]) : '', 'net_terms' => $terms ? $terms['net_terms'][0] : '', 'terms_from' => $terms ? (($terms['rate']['contract_name'] ?: ($terms['net_terms'][1] ?: $terms['after_hours'][1])) ?: 'The defaults') : '', 'currency' => $billing ? $row['client_currency_code'] : '', 'tax_id' => $billing ? $row['client_tax_id_number'] : '', diff --git a/functions/contract.php b/functions/contract.php index 24333432b..6810a2ab7 100644 --- a/functions/contract.php +++ b/functions/contract.php @@ -394,8 +394,8 @@ function contractFromInput(array $in, $kind = 'contract') { return null; } $number = function_exists('billingNumberInput') ? billingNumberInput($value) : (is_numeric($value) ? floatval($value) : null); - // A rate of nothing is no rate - the default applies - return $number === null ? false : (round($number, 2) == 0 ? null : round($number, 2)); + // Empty is no rate of its own - the default applies - and 0 is a rate of nothing: time it covers bills at 0 + return $number === null ? false : round($number, 2) + 0; }; $hours = function ($key) use ($in) { $value = trim(str_replace(',', '', (string) ($in[$key] ?? ''))); diff --git a/functions/contract_billing.php b/functions/contract_billing.php index bbcf2abb2..91f2cfd22 100644 --- a/functions/contract_billing.php +++ b/functions/contract_billing.php @@ -102,7 +102,7 @@ function contractTermsOn($client_id, $date, $what = '') { if (!contractInForceOn($row, $date)) { continue; } - if ($what === 'rate' && floatval($row['contract_rate_standard']) <= 0 && floatval($row['contract_rate_after_hours']) <= 0) { + if ($what === 'rate' && $row['contract_rate_standard'] === null && $row['contract_rate_after_hours'] === null) { continue; } if ($what === 'net' && $row['contract_net_terms'] === null) { @@ -157,11 +157,11 @@ function contractUsualTerms(array $row, $date = null) { continue; } $name = (string) $other['contract_name']; - if (!isset($found['rate']) && floatval($other['contract_rate_standard']) > 0) { + if (!isset($found['rate']) && $other['contract_rate_standard'] !== null) { $usual['rate'] = [floatval($other['contract_rate_standard']), $name]; $found['rate'] = true; } - if (!isset($found['after_hours']) && floatval($other['contract_rate_after_hours']) > 0) { + if (!isset($found['after_hours']) && $other['contract_rate_after_hours'] !== null) { $usual['after_hours'] = [floatval($other['contract_rate_after_hours']), $name]; $found['after_hours'] = true; } @@ -266,9 +266,9 @@ function contractTicketRate(array $ticket) { $in_force = array_values(array_filter(contractTermsContracts($ticket['ticket_client_id'] ?? 0), function ($row) use ($done) { return contractInForceOn($row, $done); })); - // A rate of nothing is no rate - the default applies + // An empty rate is none of its own - the default applies; 0 is a rate of nothing $after_rates = array_filter($in_force, function ($row) { - return floatval($row['contract_rate_after_hours']) > 0; + return $row['contract_rate_after_hours'] !== null; }); if (($after_rates || $defaults['after_hours'] > 0) && contractAfterHours($ticket['ticket_created_at'] ?? '')) { foreach ($after_rates as $row) { @@ -279,7 +279,7 @@ function contractTicketRate(array $ticket) { 'note' => 'the default after-hours rate - opened outside business hours']; } foreach ($in_force as $row) { - if (floatval($row['contract_rate_standard']) > 0) { + if ($row['contract_rate_standard'] !== null) { return ['rate' => floatval($row['contract_rate_standard']), 'source' => 'contract', 'contract_id' => intval($row['contract_id']), 'contract_name' => $row['contract_name'], 'note' => contractPossessive($row['contract_name']) . " rate"]; } @@ -329,7 +329,7 @@ function contractNetTermsWhose($client_id, $date) { /* * A client's terms today, each with where it comes from - for the pages * that show them: ['rate' => contractClientRate(), 'after_hours' => [rate, - * contract name or ''] (rate 0: none, the hourly rate applies), 'net_terms' + * contract name or ''] (rate null: none, the hourly rate applies), 'net_terms' * => [days, contract name or ''], 'slas' => [priority => [sla_id, contract * name or '']]]. */ @@ -337,9 +337,9 @@ function contractClientTerms($client_id) { $client_id = intval($client_id); $today = date('Y-m-d'); $defaults = billingDefaults(); - $after = [$defaults['after_hours'], '']; + $after = [$defaults['after_hours'] > 0 ? $defaults['after_hours'] : null, '']; foreach (contractsInForce($client_id) as $row) { - if (floatval($row['contract_rate_after_hours']) > 0) { + if ($row['contract_rate_after_hours'] !== null) { $after = [floatval($row['contract_rate_after_hours']), $row['contract_name']]; break; }