From c98fa4bc8a106a9da23e4854cb461384003d1488 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Thu, 19 Nov 2026 19:23:23 -0500 Subject: [PATCH] Billing: pause a recurring invoice until a day it resumes by itself, copy a recurring invoice to another client, bulk pause, resume, next date and frequency on recurring invoices, the client's other unpaid invoices when adding a payment, one-off addresses when sending invoices and quotes, a notice before a sent quote runs out, Take a photo in the picture window, a client's overdue balance on their tickets, and drafts left more than a week singled out --- CHANGELOG.md | 13 ++- admin/database_updates/4.0.5.php | 21 ++++ agent/invoices.php | 22 ++-- agent/modals/expense/expense_form.php | 2 +- agent/modals/invoice/invoice_email.php | 26 ++--- agent/modals/payment/payment_add.php | 49 +++++++- agent/modals/quote/quote_email.php | 26 ++--- .../recurring_invoice_bulk.php | 97 ++++++++++++++++ .../recurring_invoice_copy.php | 79 +++++++++++++ agent/post/billing.php | 105 +++++++++++++++++- agent/post/invoice.php | 10 +- agent/post/quote.php | 10 +- agent/post/recurring_invoice.php | 78 ++++++++++++- agent/recurring_invoice.php | 16 ++- agent/recurring_invoices.php | 71 ++++++++++-- agent/ticket.php | 6 + cron/nightly_tasks.php | 26 ++++- db.sql | 1 + functions/billing.php | 104 ++++++++++++++++- functions/billing_email.php | 40 +++++++ functions/notifications.php | 2 +- js/picture_field.js | 30 ++++- 22 files changed, 758 insertions(+), 76 deletions(-) create mode 100644 admin/database_updates/4.0.5.php create mode 100644 agent/modals/recurring_invoice/recurring_invoice_bulk.php create mode 100644 agent/modals/recurring_invoice/recurring_invoice_copy.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fe672af0..d38e71e8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ This file documents all notable changes made to ITFlow. ### Upgrading to 26.12 -Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's thirty-seven database changes (3.6.6 to 4.0.4) in the same pass. They add four tables for RMM providers and their alerts, a setting for API keys in the address, a column marking the emails the mail queue clears once sent, a column and a table for agent banners, two columns for ticket statuses with a setting for the "ticket assigned" message, a column on tickets with a setting for the "no response" message, a table for who a ticket's email replies go to, the settings for Quick tickets, columns on recurring tickets and recurring invoices for booking and making them ahead, two columns on ticket replies for when their time was worked, the settings for cron alerts, a table and a setting for labor costs, a column on users for API / service accounts, columns on tickets and recurring tickets for how long booked work takes, a column each on recurring tickets and calendar events for repeating on a weekday, three columns on agents' settings for their calendar color, what their calendar shows and their own time zone, a table for the agents helping on a ticket, three columns on quote lines with three settings for what a quote line costs and how it is priced, a column each on quote lines and products with a setting for their pictures, two settings and a column on tickets for keeping project tickets apart, a table for your other offices with a column each on agents and invites for which one they work from, three settings for the emails and notices your agents get about their tickets, three settings for sending and reading Microsoft 365 mail through Microsoft Graph, five tables, four settings and a role permission for purchase orders, five settings for switching Dispatch, Bookkeeping, Purchasing, Trips and the calendar on and off, and eight tables, three columns and two settings for the Knowledge Base, who can read its articles, what its readers think of them and their files, a column on documents for how often each is reviewed, a column on agents' settings for compact rows, a table for reply drafts, a table for which tickets each agent has opened, two columns on contacts for an email that bounces, a table for credentials' earlier passwords, and change nothing that is there. Nothing else is required, but it is a big release, so take a backup before you update. Purchasing starts off - switch it on in Admin > Settings > Modules - and so does the Knowledge Base's public help center, in Admin > Settings > Knowledge Base. This release has thirteen security fixes - see Security. On Apache, ITFlow's own .htaccess now sends security headers: if you show ITFlow inside a frame on another website, it will now refuse to load there. On nginx, add the same headers to your server block if you want them - see Developer Updates. +Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's thirty-eight database changes (3.6.6 to 4.0.5) in the same pass. They add four tables for RMM providers and their alerts, a setting for API keys in the address, a column marking the emails the mail queue clears once sent, a column and a table for agent banners, two columns for ticket statuses with a setting for the "ticket assigned" message, a column on tickets with a setting for the "no response" message, a table for who a ticket's email replies go to, the settings for Quick tickets, columns on recurring tickets and recurring invoices for booking and making them ahead, two columns on ticket replies for when their time was worked, the settings for cron alerts, a table and a setting for labor costs, a column on users for API / service accounts, columns on tickets and recurring tickets for how long booked work takes, a column each on recurring tickets and calendar events for repeating on a weekday, three columns on agents' settings for their calendar color, what their calendar shows and their own time zone, a table for the agents helping on a ticket, three columns on quote lines with three settings for what a quote line costs and how it is priced, a column each on quote lines and products with a setting for their pictures, two settings and a column on tickets for keeping project tickets apart, a table for your other offices with a column each on agents and invites for which one they work from, three settings for the emails and notices your agents get about their tickets, three settings for sending and reading Microsoft 365 mail through Microsoft Graph, five tables, four settings and a role permission for purchase orders, five settings for switching Dispatch, Bookkeeping, Purchasing, Trips and the calendar on and off, and eight tables, three columns and two settings for the Knowledge Base, who can read its articles, what its readers think of them and their files, a column on documents for how often each is reviewed, a column on agents' settings for compact rows, a table for reply drafts, a table for which tickets each agent has opened, two columns on contacts for an email that bounces, a table for credentials' earlier passwords, a column on recurring invoices for a pause with an end, and change nothing that is there. Nothing else is required, but it is a big release, so take a backup before you update. Purchasing starts off - switch it on in Admin > Settings > Modules - and so does the Knowledge Base's public help center, in Admin > Settings > Knowledge Base. This release has thirteen security fixes - see Security. On Apache, ITFlow's own .htaccess now sends security headers: if you show ITFlow inside a frame on another website, it will now refuse to load there. On nginx, add the same headers to your server block if you want them - see Developer Updates. ### Security @@ -175,6 +175,15 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Racks: drag an item on a rack to another position, or across to the other side, and it moves there. Drag one of the client's assets from Not racked yet onto the rack and Add opens with it and where you dropped it filled in. While you drag, the rack shows where it would go, in red where something is in the way. - Credentials: Reused password, along the top of Credentials, picks out the logins whose password another of the same client's logins also has, each marked Reused, and a credential's quick look names the others. The passwords are compared as the page opens, with your vault key, and nothing about them is kept. - Credentials: a password that is changed is now kept as an earlier password, still encrypted. Earlier passwords in a credential's quick look shows when each was in use and who changed it, with the eye and copy buttons, and Put back makes one the password again when a change broke something. The newest ten are kept, agents with Delete access to credentials can delete one, and each one looked at is logged. +- Recurring invoices: Pause can now pause until a day - the recurring invoice runs again by itself that day, from its next date after it, and nothing is billed for the runs in between. Leave the day empty to pause until resumed, as before. Paused ones say until when on the list and their page. +- Recurring invoices: Copy to Another Client, in a recurring invoice's menu, makes the same one for another client - its lines, scope, category, discount, notes, how often and how it sends - starting on the day you pick. Lines billed per user or device count the new client's. A line counting license seats keeps its quantity, as the license is the first client's. Autopay isn't copied. +- Recurring invoices: tick them on the list and Bulk Action pauses them (until a day, or until resumed), resumes them, or changes their next date or how often they bill. +- Payments: Add Payment lists the client's other unpaid invoices, oldest due first, with what's owed on each and Pay this one - and says when some were due before this one. Batch Payment, beside them, pays several at once. +- Invoices and quotes: Send has Also send to, for an address that isn't one of the client's contacts - their accountant, say. It's for this once and isn't saved. A client with no contact to send to can now be sent one this way. +- Quotes: three days before a sent quote runs out with no answer, the people who can see quotes get a notification to follow it up. +- Expenses: on a phone or tablet, the picture window has Take a photo, which opens the camera straight away - for a receipt, and for every other picture and photo in ITFlow. +- Tickets: a ticket shows what its client owes on invoices past their due date, beside the client's name, to agents who can see invoices - with how many and how late the oldest is. It opens their overdue invoices. +- Invoices: a draft left more than a week says so on the invoices list, under its status, and Drafts left a week picks them out - In drafts counts them too. The nightly notice about drafts says how many have been left that long, and opens them. - Contacts and assets: an email already on another contact - now when changing a contact too - and a serial number or MAC address already on another asset are named as they're typed, with who or which, and where. - Modules: Admin > Settings > Modules has five more switches, to take out of ITFlow what your business doesn't use - Dispatch, which comes with Ticketing; Bookkeeping, Purchasing and Trips, which come with invoicing; and the Calendar. Each part is off while the one it comes with is, and shows faded under it. Switched off, a part leaves the menus, the dashboard, search, the reports and the API, and its pages and windows say it is off. Nothing in it is deleted - switched back on, it is all there. Dispatch, Bookkeeping, Trips and the Calendar start on, as before. - Bookkeeping: switch it off when your books are kept somewhere else. Accounts, Transactions, Transfers, Reconcile and the statement imports go, and nobody picks an account: payments and income go into the default payment account, and expenses come out of the default expense account - both in Admin > Settings > Defaults, or the first account when there's no default. An expense is paid by The business or Paid personally. The dashboard leaves out the account balances, and the Tax Package its Accounts section. @@ -367,6 +376,8 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Assets: `assetDetailsText()` in `functions/asset.php` - the asset as "Label: value" lines, for the Copy details buttons (`.clipboardjs`) on `agent/asset.php` and `agent/modals/asset/asset.php`. - Racks: `move_rack_unit` in `agent/post/rack.php` (`unit_id`, `unit_start`, `face`; height and depth kept; the rack's bounds and `rackUnitConflict()` checked; refused on an archived rack) is posted through `#rackMoveForm` by `agent/js/rack_drag.js`, loaded on `agent/rack.php` for agents who can edit. `agent/includes/rack_elevation.php` gives each bay `data-rack-drop` with its face, height and numbering, and each item `data-rack-unit`, `-start`, `-end` and `-name`, with `data-rack-drag` on the ones that move. An asset dropped opens `rack_device_add.php` with `asset_id`, `u` and `face`. `rackAssetDefaults()` in `functions/rack.php` is the height and depth an asset type starts from, for that window and the Not racked yet list. - Credentials: database 4.0.4 adds `password_history` (the encrypted `password_history_password` as it was on the credential, `_set_at`, `_replaced_at`, `_user_id`, and `_credential_id` with an `ON DELETE CASCADE` key to `credentials`). `credentialPasswordKeep()` in `functions/credential.php` copies the current password there and keeps the newest `CREDENTIAL_PASSWORD_HISTORY_KEEP` (10); `edit_credential`, `rotate_credential`, the API's `credentials/update` and the credential import call it before a password that wasn't empty changes. `credentialPasswordHistory()`, `credentialPasswordHistoryRow()` and `credentialPasswordHistoryReady()`. `get_credential_via_id` takes `history_id`, logged once in 5 minutes as a View; `credentialPasswordHtml()` takes the history id as `data-credential-history`, which `js/credentials.js` sends. `restore_credential_password` (Credential edit) and `delete_credential_password_history` (Credential delete) in `agent/post/credential.php`. `credentialReusedPasswords($where)` decrypts the passwords in `$where` and groups them by client and SHA-256 in memory; `credentialReusedPill()`, and the `reused` pill on `agent/credentials.php`. +- Recurring invoices: database 4.0.5 adds `recurring_invoices.recurring_invoice_paused_until` (`recurringPauseReady()`). `recurringInvoiceResumePaused()` (nightly, before the run that bills) sets status 1 and clears it once the day has come, moving the next date on with `recurringInvoiceCatchUp()`; `recurring_invoice_set_status` and `edit_recurring_invoice` clear it on a resume. `bulk_recurring_invoices` in `agent/post/billing.php` takes `bulk_action` (`pause` with `paused_until`, `resume`, `next_date`, `frequency`) and `recurring_invoice_ids[]`, from the list's bulk menu and `agent/modals/recurring_invoice/recurring_invoice_bulk.php` - also the single Pause on the list and the page. `copy_recurring_invoice` (`agent/post/recurring_invoice.php`, `recurring_invoice_copy.php`) copies the row and its lines, `item_seat_*` kept except for `license` seat lines, then runs `recurringInvoiceRefresh()`. +- Billing: `billingEmailExtraRecipients()`, `billingEmailMergeRecipients()` and `billingEmailExtraField()` in `functions/billing_email.php` - `email_invoice` and `email_quote` take `extra_emails` beside `contacts[]`, recipients with id 0. `billingClientOverdue()` for the ticket page (Sales read). `invoiceDraftAgePill()` and `INVOICE_DRAFT_STALE_DAYS` (7) - the `StaleDraft` status on `agent/invoices.php`. `QUOTE_EXPIRY_NUDGE_DAYS` (3) - the nightly `Quote Expiring` notification, a Sales type in `notificationTypeModules()`. `js/picture_field.js` adds a `capture="environment"` input behind Take a photo where the pointer is coarse. ## [26.11.8] diff --git a/admin/database_updates/4.0.5.php b/admin/database_updates/4.0.5.php new file mode 100644 index 000000000..dafb0e5e7 --- /dev/null +++ b/admin/database_updates/4.0.5.php @@ -0,0 +1,21 @@ + 0; + + if (!$has_paused_until) { + mysqli_query($mysqli, "ALTER TABLE `recurring_invoices` ADD `recurring_invoice_paused_until` date DEFAULT NULL AFTER `recurring_invoice_status`"); + } diff --git a/agent/invoices.php b/agent/invoices.php index 38634ebc3..8d24c3ae0 100644 --- a/agent/invoices.php +++ b/agent/invoices.php @@ -7,9 +7,11 @@ * sitting in drafts, and what came in over the last 30 days - each opens * the invoices behind it. The pills filter by where an invoice stands. Each * row has what is still owed on it and, while it is owed, how long until - * it is due or how late it is, and whether autopay pays it. ?status= takes Draft, Unpaid, Overdue, - * Paid and Cancelled - the dashboard, client pages and reports link with - * it. ?recurring_invoice_id= shows the invoices a recurring invoice made. + * it is due or how late it is, and whether autopay pays it - and a draft + * left more than a week says so. ?status= takes Draft, StaleDraft (drafts + * left more than INVOICE_DRAFT_STALE_DAYS), Unpaid, Overdue, Paid and + * Cancelled - the dashboard, client pages, reports and the nightly + * notification link with it. ?recurring_invoice_id= shows the invoices a recurring invoice made. */ // Default Column Sortby/Order Filter @@ -64,6 +66,8 @@ $open_sql = "invoice_status IN ('Sent', 'Viewed', 'Partial')"; $statuses = [ '' => ['label' => 'All', 'where' => ''], 'Draft' => ['label' => 'Draft', 'icon' => 'fa-pencil-ruler', 'where' => "invoice_status = 'Draft'", 'title' => 'Not sent yet - the client can\'t see them'], + 'StaleDraft' => ['label' => 'Drafts left a week', 'icon' => 'fa-hourglass-half', 'where' => "invoice_status = 'Draft' AND invoice_created_at < NOW() - INTERVAL " . INVOICE_DRAFT_STALE_DAYS . " DAY", + 'title' => 'Drafts made more than ' . INVOICE_DRAFT_STALE_DAYS . ' days ago and still not sent'], 'Unpaid' => ['label' => 'Unpaid', 'icon' => 'fa-hand-holding-usd', 'where' => $open_sql, 'title' => 'Sent, and not paid in full'], 'Overdue' => ['label' => 'Overdue', 'icon' => 'fa-exclamation-circle', 'where' => "$open_sql AND invoice_due < CURDATE()", 'title' => 'Past their due date and not paid in full'], 'Paid' => ['label' => 'Paid', 'icon' => 'fa-check-circle', 'where' => "invoice_status = 'Paid'"], @@ -126,8 +130,9 @@ $money = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COALESCE(SUM(CASE WHEN $open_sql AND balance > 0 AND invoice_due < CURDATE() THEN balance END), 0) AS overdue, COALESCE(SUM(CASE WHEN $open_sql AND balance > 0 AND invoice_due < CURDATE() THEN 1 END), 0) AS overdue_count, COALESCE(SUM(CASE WHEN invoice_status = 'Draft' THEN invoice_amount END), 0) AS draft, - COALESCE(SUM(CASE WHEN invoice_status = 'Draft' THEN 1 END), 0) AS draft_count - FROM (SELECT invoice_status, invoice_due, invoice_amount, invoice_amount - $paid_sql AS balance + COALESCE(SUM(CASE WHEN invoice_status = 'Draft' THEN 1 END), 0) AS draft_count, + COALESCE(SUM(CASE WHEN invoice_status = 'Draft' AND invoice_created_at < NOW() - INTERVAL " . INVOICE_DRAFT_STALE_DAYS . " DAY THEN 1 END), 0) AS draft_stale + FROM (SELECT invoice_status, invoice_due, invoice_amount, invoice_created_at, invoice_amount - $paid_sql AS balance FROM invoices WHERE 1 $money_scope) AS scoped")); $collected = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COALESCE(SUM(payment_amount), 0) AS amount, COUNT(*) AS payments FROM payments JOIN invoices ON payment_invoice_id = invoice_id @@ -173,7 +178,7 @@ $stat_money = function ($amount) use ($session_company_currency) {
In drafts
-
not sent yet
+
not sent yet · left over a week
@@ -310,7 +315,7 @@ $stat_money = function ($amount) use ($session_company_currency) { $alarm = $key === 'Overdue' && $counts[$key]; ?> > - + @@ -409,6 +414,7 @@ $stat_money = function ($amount) use ($session_company_currency) { +
diff --git a/agent/modals/invoice/invoice_email.php b/agent/modals/invoice/invoice_email.php index 1240b977f..0f7cf2596 100644 --- a/agent/modals/invoice/invoice_email.php +++ b/agent/modals/invoice/invoice_email.php @@ -83,16 +83,6 @@ ob_start(); + +
+
+ Their other unpaid invoices + · owed + Batch Payment +
+ +
due before this one.
+ + + 5) { ?> +
and more - see them all
+ +
+