diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a63ba5fe..abbb82b03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ This file documents all notable changes made to ITFlow. ### Upgrading to 26.11 -Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's database changes (2.7.9 to 3.4.1) in the same pass. Nothing else is required. +Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's database changes (2.7.9 to 3.4.2) in the same pass. Nothing else is required. This is a big release, with sixty database steps in one go, so take a backup before you update. @@ -33,6 +33,10 @@ Ticket statuses keep their names, colours, order and SLA settings, and every one Payment methods are all offered for money in and out, as before, until you say one is only for one of them (see New Features, Payment Methods). Methods that payments, income or expenses were recorded with but that aren't in Admin > Payment Methods - ACH from a bank import, say - are listed there to add with one click. +Contracts and contract templates keep their names, dates, rates, support hours and terms. Their response and resolution hours become an SLA from Admin > SLAs for each ticket priority - one you already have with the same hours, or a new one named for the template or contract and the priority, such as "Gold - High" - and Urgent takes High's, as there were no urgent hours. A renewal frequency becomes a term: Annually is 1 year, 2 Year is 2 years and so on, each renewing itself, and Manual is 1 year that is only renewed by hand. Net terms become a number of days, so "Net 30" is 30, and ones without a number are left empty, which means the client's own apply. Fully Managed and Partially Managed become Fully managed and Co-managed, Break/Fix stays, and any other type is Other. A contract's status becomes Active, Draft, Ended or Cancelled: Pending is a draft, Expired is ended, and anything that isn't one of those is active. Each has 30 days' notice, and no owner, contact or template until you give it one. + +The first nightly run after the update deals with active contracts whose end date has passed (see New Features, Contracts). One that renews itself is renewed term by term until it is current, and one that doesn't is marked ended. Agents are notified in ITFlow about the ones due soon, and the owner is emailed once a contract has one. Look over Contracts once after the update if end dates weren't kept up to date. + Every account is given a kind - checking, savings, credit card, cash or payment processor - guessed from its name: Visa, Amex or card is a credit card, savings or reserve is savings, cash or petty cash is cash, and Stripe, PayPal, Square or merchant is a payment processor. An account given a liability type back when accounts had types (2023) is a credit card, so what is on it reads as owed. Anything else is checking. Change any that came out wrong with Edit on the Accounts page. An account's balance now leaves out archived payments, income and expenses everywhere, so the Accounts page can show less or more than before (see Bug Fixes). No account is reconciled after the update. The first statement you reconcile on each can start from the bank's balance on the day it starts, bringing everything before it forward as reconciled, or from the account's opening balance (see New Features, Accounts and transactions). Transfers already made out of a cash account count as having taken everything in it up to then to the bank, so the first deposit you make after the update only offers the checks and cash taken in since the last one. Taxes keep their names and rates, now kept to four decimal places. No client has a rate of its own or is tax exempt, and there is no default rate, so new lines start untaxed as before until you pick one in Admin > Taxes. Billed time, trips and expenses stay untaxed until you switch them on there. Discounts now come off before tax on invoices and quotes that are still open, the next time they are edited (see Breaking Changes, Taxes). No expense has tax recorded on it until you add it, so Tax Collected shows no tax paid on purchases for the months before. @@ -1133,6 +1137,19 @@ If you are coming from 26.08 or earlier, the database update still has to be run - Delete a method nothing used; one that was used is merged into another instead - its records change to the method you pick, which takes its place as a default too. For two names for one thing, "Card" and "Credit Card". - Methods records were paid by but that aren't in the list - from a bank import, an older version or demo data - are named at the top with how much they are used, to add with one click. - New and Edit are one window, with an icon in front of every field. +- **Contracts** (new) + - Contracts, under Billing in the menu and in each client's menu, keeps every agreement with a client: its type (Fully managed, Co-managed, Block hours, Time and materials, Break/fix, Project or Other), its term, start and end, whether it renews itself and the notice needed to end it, support hours, rates, net terms and an SLA for each ticket priority from Admin > SLAs. Leave a rate, the net terms or an SLA empty and the client's own apply. + - Along the top of the list: how many are in force, ending soon without renewing, renewing soon (a good time to review them with the client) and drafts. Tabs for Active, Due soon, Drafts, Ended and All, with search, filters for type and client, and sorting by name, client, type, start, end or owner. Each row says when it renews or ends, and when notice is due. The menu shows how many are due soon. + - New Contract can start from a template, which fills in the type, term, renewal, notice, cover and terms, and any of them can be changed after. Pick the client, a contact there and the agent who looks after it. The end date follows the start and the term until you change it, and the window says when notice is due. Save it as active, or as a draft to make active when it is signed. Copy starts a new contract from an existing one. + - A contract's page shows where it stands (draft, starts soon, active, renews soon, ends soon, ended or cancelled) and how far through its term it is. It also shows what the contract covers, with the SLA for each priority, the terms and internal notes, the client, contact and owner, and its history. + - Renew sets a new last day, a term on by default. Cancel takes the last day it is in force and why, and it doesn't renew after that. Make active takes the day a draft starts and sets its end a term later. + - Every night, a contract that renews itself is renewed for another term once it ends, and one that doesn't is marked ended. A month before its notice date, its owner is emailed what it is, when notice is due and a link to it, and agents are notified in ITFlow. This happens once a term. + - The client overview lists contracts ending or renewing soon under Needs attention, and shows the contract in force in the Financial row. + - Deleting a client deletes its contracts. It used to fail while the client had one (see Bug Fixes). +- **Contract Templates** (rebuilt) + - Admin > Contract Templates shows each template with its type, its term and renewal, the notice, its cover (support hours, rate and net terms), the SLA for each priority and how many contracts were started from it. Tabs for the ones in use and the archived ones; search; sort by name, term or contracts. + - New and Edit are one window with Template, Cover and Terms tabs and an icon in front of every field. A template has the same terms as a contract, without the client and dates. + - Copy makes "Name (copy)". Archive takes a template off New Contract and keeps it, and Restore brings it back. Delete leaves the contracts started from it as they are. ### Bug Fixes @@ -1333,6 +1350,9 @@ If you are coming from 26.08 or earlier, the database update still has to be run - Payment methods: renaming one left every record that used it under the old name, so lists, filters and reports split it in two, and deleting one left its records with a name that couldn't be picked again. - Payments: editing a payment made online (recorded as Stripe), or one with a method no longer in the list, showed no method and couldn't be saved without picking another. - Payment methods: the same name could be added twice, and the description had no label. +- Clients: a client with a contract couldn't be deleted, because the database refused it. +- Contract templates: the after-hours rate of a new template was never saved, rates were cut to whole amounts, and net terms written as "Net 30", as the field suggested, were saved as 0. +- Contract templates: Edit showed the rates empty, so saving a template set them to 0. ### Developer Updates @@ -1929,6 +1949,7 @@ If you are coming from 26.08 or earlier, the database update still has to be run - Debug: new `functions/system_health.php`. `healthChecks()` returns the sections in order (`key`, `title`, `icon`, `items`), each item from `healthItem($label, $level, $value, $fix, $url, $action, $private)` - level `ok`, `info`, `warning` or `danger`, `fix` as HTML, `private` leaving the value out of the report. `healthSummary($sections)` counts them by level and lists the warnings and problems, problems first. `healthDatabaseTables($exact)` reads sizes and InnoDB's row estimates from `information_schema.TABLES` in one query, or counts each table with `$exact` (`debug.php?exact=1`); `healthStructureDifferences()` compares `information_schema.COLUMNS` with `db.sql`, ignoring integer display widths (`healthColumnType()`); `healthUploads($seconds)` counts uploads by top-level folder and stops at the time given, marked `partial`. `healthReport()` is the plain-text report. Every read goes through `healthQuery()` / `healthRow()`, which answer null instead of throwing, so a column the database doesn't have yet costs a line, not the page. The certificate is read from `$config_base_url`'s host (`healthBaseHost()`, `healthCertificate()`), never `HTTP_HOST`; HTTPS counts `X-Forwarded-Proto`; the required extensions come from `setupRequiredExtensions()` in `setup/setup_checks.php` so setup and Debug agree; mail uses `mailQueueHealth()` and `mailQueueSummary()`; updates use `shellCommandsAvailable()` and `commandPath('git')`. `admin/debug.php` no longer closes the database before the footer, uses `reportStats()` for the figures along the top, and the copy button is the shared `.clipboardjs` one, targeting the report's textarea. New CSS: `.itflow-debug-section-icon`, `.itflow-debug-item`, `.itflow-debug-fix`, `.itflow-debug-attention`, `.itflow-debug-bar`, `.itflow-debug-stats`. No database change. - Ticket statuses: database 3.4.0 adds `ticket_statuses.ticket_status_description` varchar(255) and `ticket_status_client_reply` tinyint(1) (1, the default, sends the ticket back to Open when the client replies; 0 leaves it), gives the five built-in statuses their descriptions where they have none, and numbers `ticket_status_order` 1, 2, 3... in the order they already showed in. New `functions/ticket_status.php`: `ticketStatusBuiltIns()` (ids 1-5 with icon, meaning and what sets them), `ticketStatusIsBuiltIn()`, `ticketStatusRow()`, `ticketStatusesAll()` (once a page, in order), `ticketStatusAbout()`, `ticketStatusColor()`, `ticketStatusBadgeHtml()` (text colour from `tagTextColor()`, the description as its title), `ticketStatusOptions($keep)`, `ticketStatusTicketCounts()`, `ticketStatusMoveTargets()`, `ticketStatusFromInput()` (a built-in keeps its name, stays on and takes `getTicketStatusSlaLock()` and client reply 1 whatever is posted), `ticketStatusProblem()` (a name, not taken), `ticketStatusCreate()`, `ticketStatusUpdate()` (returns the from-to changes, syncs its tickets' SLA clocks when pausing changes), `ticketStatusMoveTickets()`, `ticketStatusSetActive()`, `ticketStatusDelete()`, `ticketStatusReorder()` and `ticketStatusAfterClientReply($status_id)`, which `cron/ticket_email_parser.php` and `client/post.php` now use instead of setting status 2. `ticketStatusColumnsReady()` keeps all of it working before 3.4.0 has run. `ticketStatusHtml()` draws through `ticketStatusBadgeHtml()`, and the dashboard, client overview, ticket page, Ticket Aging and Client Review reports use it instead of their own badges. `admin/post/ticket_status.php` adds `move_ticket_status`, `reorder_ticket_statuses` (POST, JSON), `switch_on_ticket_status`, `switch_off_ticket_status` (POST, `move_to`) and `delete_ticket_status` as POST with `move_to` - the GET delete is gone. The add and edit windows share `admin/modals/ticket_status/ticket_status_form.php` with `js/ticket_status_form.js`; `ticket_status_remove.php` is the switch-off and delete window. Quick picker options take a `title` (`js/quick_pick.js`), which the status picker sets to the description. New CSS: `.itflow-ticket-status`. - Payment methods: database 3.4.1 adds `payment_methods.payment_method_use` tinyint(1) (0 money in and out - every method so far, 1 money in, 2 money out) and `payment_method_archived_at`. New `functions/payment_method.php`: `PAYMENT_METHOD_USES`, `PAYMENT_METHOD_ONLINE` ('Stripe', what online card payments are recorded as - its name can't be changed), `paymentMethodUsageColumns()` (every column a method is kept in by name: `payment_method`, `revenue_payment_method`, `expense_payment_method`, `recurring_expense_payment_method`, `reimbursement_payment_method`, `transfer_method`, `recurring_payment_method`), `paymentMethodRow()`, `paymentMethodsAll()`, `paymentMethodUsage()` (one UNION ALL, counts and the last date per name), `paymentMethodUsageText()`, `paymentMethodsNotSetUp()`, `paymentMethodDefaults()`, `paymentMethodDefaultFor()`, `paymentMethodSetDefault()`, `paymentMethodFromInput()`, `paymentMethodProblem()` (a name, not taken), `paymentMethodCreate()`, `paymentMethodRename()` (every column above and both defaults, case-insensitively), `paymentMethodUpdate()` (returns the from-to changes and how many records were renamed; drops a default the new use rules out), `paymentMethodSetArchived()`, `paymentMethodDelete()` (refuses a used method without another to merge into) and `paymentMethodAddNames()`. `paymentMethods($way = '', $with_archived = false)` moves here from `functions/billing.php` - `'in'` for payments and income, `'out'` for expenses, `''` for transfers; archived ones only for filters - and every picker and check passes its way: the payment, income, expense, recurring expense, reimbursement, mileage claim, bulk edit and import windows, `incomeImportMethod()`, the expense and income save functions, and Settings > Defaults. `paymentMethodColumnsReady()` keeps it working before 3.4.1 has run. The payment window keeps a payment's own method among the choices. `admin/post/payment_method.php` adds `default_payment_method` (GET, `way` in or out), `archive_payment_method`, `restore_payment_method`, `delete_payment_method` as POST with `move_to` (the GET delete is gone) and `add_payment_method_names`. The add and edit windows share `admin/modals/payment_method/payment_method_form.php`; `payment_method_delete.php` is the delete and merge window. +- Contracts: database 3.4.2 adds to `contract_templates` and `contracts` `{prefix}_term_months` int (12), `_auto_renew` tinyint(1) (1), `_notice_days` int (30) and `_sla_low_id`, `_sla_medium_id`, `_sla_high_id`, `_sla_urgent_id` int (0, the client's own), and to `contracts` `contract_template_id`, `contract_contact_id`, `contract_owner_id`, `contract_created_by` int, `contract_notes` text, `contract_renewed_at`, `contract_reminded_at`, `contract_cancelled_at` datetime and `contract_cancel_reason` varchar(255). It turns the `_sla_{low,medium,high}_{response,resolution}_time` hours into SLA ids - an unarchived `slas` row with the same minutes, or a new one - and `_renewal_frequency` into the term and auto-renew, then drops those seven columns from both tables. It makes `_net_terms` int (the digits of the old text, or NULL), sets `_type` to a key of `CONTRACT_TYPES` and `contract_status` to Draft, Active, Ended or Cancelled, and re-adds `contracts_ibfk_1` with ON DELETE CASCADE. New `functions/contract.php`: `CONTRACT_TYPES` (key => label, icon, about), `CONTRACT_TERMS`, `CONTRACT_REMINDER_DAYS` (30), `CONTRACT_SLA_PRIORITIES`, `contractsReady()` (keeps every page and the nightly job working before 3.4.2 has run), `contractRow()` (with the client, contact, owner and template names), `contractTemplateRow()`, `contractTemplates()`, `contractTypeLabel()`, `contractTermLabel()`, `contractTermEnd($start, $months)` (a term less a day - `termEnd()` in `js/contract_form.js` matches it), `contractNextEnd()`, `contractNoticeDate()`, `contractReminderDate()`, `contractState()` and `contractStateHtml()`, `contractViews()`, `contractSlaChoices($keep)`, `contractSlaTargets()`, `contractFromInput($in, 'contract'|'template')` (returns the fields and an error; checks the client in scope, the contact at that client, an active agent as owner and listed SLAs, and purifies the terms), `contractTermsSetSql($f, $prefix)` (shared by contracts and templates), `contractSetSql()`, `contractCreate()`, `contractUpdate()` (returns the changes; a new end date clears `contract_reminded_at`), `contractActivate()`, `contractRenew()`, `contractCancel()`, `contractsNightly($today)` (returns renewed, ended and reminded counts; `cron/nightly_tasks.php` runs it and logs them), `contractRemind()`, `contractClientCount()` and `contractClientActive()`. New `agent/contracts.php`, `agent/contract.php`, `agent/post/contract.php` (`add_contract`, `edit_contract`, `activate_contract`, `renew_contract`, `cancel_contract` POST with Sales Modify, and `delete_contract` GET with Sales Delete), and `agent/modals/contract/` (the add, copy and edit windows share `contract_form.php` with `js/contract_form.js`, plus `contract_activate.php`, `contract_renew.php` and `contract_cancel.php`). `admin/post/contract_template.php` is rewritten on `contractFromInput()` and adds `copy_contract_template`; deleting a template sets its contracts' `contract_template_id` to 0. The template add and edit windows share `admin/modals/contract_template/contract_template_form.php`. `auditLogKinds()` has a Contract kind, the client overview has Contracts ending and Contracts renewing attention items and a contract in the Financial row, and `agent/post/client.php` deletes a client's contracts with it. ### Library Updates diff --git a/admin/contract_templates.php b/admin/contract_templates.php index 2bceb7e62..c9fbc93b3 100644 --- a/admin/contract_templates.php +++ b/admin/contract_templates.php @@ -1,21 +1,66 @@ 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"; -// Search query -$sql = mysqli_query( - $mysqli, - "SELECT SQL_CALC_FOUND_ROWS * FROM contract_templates - WHERE contract_template_name LIKE '%$q%' OR contract_template_type LIKE '%$q%' - OR contract_template_description LIKE '%$q%' - ORDER BY $sort $order LIMIT $record_from, $record_to" -); +$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 : ''; -$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); +$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(); + +$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']; ?> @@ -24,133 +69,110 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));