CASE FILES PROFESSIONAL — INVOICE SETUP & PAYMENT WORKFLOW

Existing GIB installation:
1. Back up the full application and database. Extract the GIB patch into the application root, replacing matching files. Do not replace config/installed.php or run a new install over an existing site.
2. Sign in as administrator and complete the database upgrade when prompted. The existing upgrade process creates a protected database safety backup first. This update allows an optional invoice client and an optional notification account; existing records and foreign-key relationships remain.
3. Open Finance & Billing > Invoice Setup & Settings. Administrators can edit; accounting can review. Invoice Setup controls the invoice-specific company name, logo, address, telephone, contact email, website, introductory text, license line and footer. Preview Invoice Template opens a sample without creating a financial record. Issued invoices retain their branding snapshots.
4. GIB includes supported settings adapted from the supplied FusionInvoice export: Net14, the company profile and logo, adapted invoice/reminder/overdue email wording, sender identity and supported reminder days. Missing settings use these defaults. To replace previously configured billing defaults, choose Apply Imported GIB Invoice Defaults under General & Terms. It does not change invoice numbers, balances, agency branding, users or gateway credentials. Commercial provides generic defaults with agency-specific identity and credentials blank.
5. Billing Email Delivery has separate From, Reply-To, CC and BCC fields. Select Use a separate SMTP account and enter its credentials to use a different mailbox/transport. If unchecked, Agency Setup SMTP is used with the billing sender; that SMTP provider must authorize the From address. SMTP passwords are entered after installation and saved encrypted. Account/case emails retain Agency Setup delivery.
6. Email Templates, Reminders, Overdue Emails and Receipts control wording and delivery choices. Issuing alone DOES NOT email the invoice. Send Invoice attempts email after the record commits and schedules enabled reminders. Defaults are 5/3/1 days before due and 1/3/5/10 days overdue; offsets and send hour are editable. Paid/void invoices do not receive reminders. Due messages are handled by the existing five-minute scheduler. Accepted means SMTP accepted a message, not guaranteed inbox delivery. Billing delivery history is shown on the invoice Email tab.
7. Payment Options configures Stripe or Authorize.net hosted card checkout and signed webhooks. Keys are not imported from FusionInvoice; enter your account credentials. Use Stripe test keys or Authorize.net sandbox first. Webhook endpoints are shown with this installation's domain/base path. Events are stored durably, verified and deduplicated. The webhook and Stripe return attempt immediate reconciliation; the scheduler remains the fallback. Browser return parameters alone never mark an invoice paid. No card number/CVV is collected by Case Files.
8. The 12 original payment methods are available, with Debit Card added: Cash, Credit Card, Online Payment, Paper Check, eCheck via DPX, Direct Deposit, Bill.com, Zelle, Melio, Venmo, Wire Transfer, Cashier's Check, Debit Card. Manual selection records funds received; it does not initiate a DPX/Zelle/etc transfer. Manual entries have an Email receipt to client checkbox. Verified online entries queue receipts when receipt email delivery is enabled. The master receipt setting and client email preferences apply.
9. Create an invoice with or without a case. Select an existing client, or No client. To email is displayed only for No client; CC/BCC are available for both. A draft may have no recipient; a valid email is required before Send Invoice. No client login account is created for email-only recipients. Email-only invoices use a random private invoice link limited to that invoice and its receipts. Changing that recipient replaces the link. Treat the link as private. Existing-client portal links continue to require the billed client's login.
10. Clients have My Invoices in the dashboard header, status filters including Paid / Settled and Void, and Pay Online on open invoices when a gateway is enabled. Unissued drafts and other clients' invoices remain unavailable.

Template and email links use the configured Case Files domain and subdirectory. Legacy FusionInvoice public URLs are replaced with the new invoice link. Billing recipient email is printed on the invoice; CC/BCC are not printed. Registered-client CC/BCC recipients receive copies but do not gain that client's portal account access.

Scope: supported invoice settings and workflow were adapted, not all 305 FusionInvoice settings or its entire application. Existing Case Files numbering controls remain; the 14 FusionInvoice numbering schemes, invoice/client history and non-USD currencies were not imported. Current invoice calculations are unchanged. Payment instructions (including any legacy fee wording) are editable text; this update does not add a processing fee automatically. The original custom invoice layout is adapted to Case Files data and can be customized through the supported branding/text fields; arbitrary Blade/PHP template code is not executed.

Verification: both editions parsed; actual business functions checked with simulated DB/provider transports for receipt selection, deduplication, sender routing, CC/BCC, guest links, client access, creation and scheduling. Webhook signatures and provider amount/currency/invoice checks tested using fixtures. Upgrade planning is idempotent. Desktop/tablet/phone layouts and printable invoice links checked. No real email or charge was sent. Native MySQL upgrade execution, production SMTP, provider sandbox transactions, live webhooks, PDF/Word exports and delivery need acceptance checks on the test host with your configured accounts before production use.

PAYMENT SETTINGS & INVOICE CREATION FOLLOW-UP
Payment credentials, enabled choices, Authorize.net environment and webhook instructions now have one editor: Invoice Setup & Settings > Payment Options. Agency Setup links there; stored keys and choices are retained. General API credentials remain in Agency Setup.
The imported GIB defaults button is restricted to GIB, records successful application transactionally, and hides afterward. Commercial never displays it. Repeated import requests are rejected.
New invoice creation explicitly initializes the invoice counter rather than depending on its database default. If a database exception occurs, the page gives the failing stage, SQLSTATE and numeric driver code. It does not expose SQL, credentials, recipient values or database exception text. A matching reference is written to the server error log.
The reported test-site exception cannot be identified from its original reference alone. Local creation checks pass with/without a client and case. If it persists after this patch and any prompted Database Upgrade, provide the new Diagnostic line; the native host database error is still needed to confirm the exact cause. No production database or payment account was accessed.

Generate AI field buttons are restricted to case creation/editing and reports. Invoice pages, invoice settings, billing contacts and notification email fields do not render these buttons. Research & AI functionality remains available within cases.

Invoice Setup now includes Invoice tagline. Enter replacement wording, or save it blank to omit the separate tagline below the agency name. GIB defaults to VERITAS NUNQUAM PERIT; Commercial defaults blank. Applies to template previews, drafts and newly issued invoices (HTML/PDF/Word). Existing issued invoices retain their saved branding. Text embedded in an uploaded logo is part of that image.

INVOICE CREATION ERROR 3569 FIX
The transaction query helper now preserves an existing terminal FOR UPDATE/FOR SHARE lock instead of appending a duplicate. This fixes the invoice-number query that produced Diagnostic: invoice number / HY000 / 3569. Queries without a lock still receive the transactional row lock. No database change is required for this fix.

MANUAL INVOICE REMINDER EMAILS
Email & Recurring includes Send Upcoming Invoice (issued/unpaid, due date in future) and Send Overdue Invoice (issued/unpaid, past due). Each uses its reminder or overdue template, including client template overrides, billing sender, CC/BCC, invoice link and PDF attachment choice. Preview the matching email before sending. These explicit sends work independently of automatic reminder enable switches; client email opt-out still applies. Sends attempt delivery after commit, with the existing scheduler fallback. Replay of the same request does not queue a second email. Paid/void invoices and invoices that no longer match the chosen type are excluded. Send Invoice retains its regular template.

Invoice Email & Recurring now groups Send Invoice, Send Upcoming Invoice and Send Overdue Invoice left-to-right in one action row (wrapping on narrow screens). Both reminder buttons remain visible; date/balance-ineligible buttons are disabled with explanatory tooltips. The email preview panels are removed. Each send retains its matching template and server-side eligibility checks.

Invoice, upcoming/reminder, overdue and custom receipt email bodies omit Case # / Client File # rows when those values are empty. Standalone invoices no longer print Case: Standalone. Filled references remain. This formatting happens when sending and does not rewrite saved email templates or invoice records. Use a separate line for each optional reference in custom templates.

INVOICE LINK EMAIL BUTTON
The {invoice_url} link renders as a View Invoice & Pay button in invoice, reminder, overdue and receipt HTML emails. The original body and full link are retained as the plain-text alternative. Templates remain plain text and their wording is escaped safely. Existing client portal links and private no-client links keep their respective access rules. Receipt download links are not replaced with invoice buttons. Agency/account mail remains unchanged.

INVOICE EMAIL DUE-DATE COLOURS
The invoice detail section in HTML billing emails is green more than three days before due, yellow/amber during the final three days including the due date, and red after the due date. The calculation uses the agency timezone and the current invoice due date when the email is sent. Dark readable text appears on a matching pale background. Blank Case/Client File rows remain omitted, and payment buttons and plain-text alternatives are retained. Existing delivered emails do not change colour later.

COMMERCIAL EMAIL DEFAULTS
Commercial includes editable generic invoice, upcoming reminder, overdue and receipt templates, with no Nick Francis/GIB contact details. Invoice Setup supplies Billing contact name, invoice contact email and phone through {billing_contact_name}, {billing_contact_email}, {billing_contact_phone}. Blank email/phone inherit Agency Setup; empty contact lines are omitted. Existing saved templates remain as configured. GIB keeps its existing templates.

INVOICE LIST EDIT & DELETE
Authorized financial staff with direct case access see View, Edit and Delete actions. Edit opens the invoice controls; issued invoices require the explicit Edit mode described below. Delete opens the standard Confirm Delete / Cancel popup. Eligible invoices are archived from active lists and links, marked void, pending emails cancelled and recurring schedules disabled. Native records remain for audit; numbering is never reset or reused. Invoices with payments, credits or unresolved checkout attempts cannot be deleted. Client users cannot edit or delete. No schema change is required.

SYSTEM DATE DISPLAY
Displayed dates use MM/DD/YYYY across screen text, dynamic record lists, invoice emails, SMS, invoice HTML/PDF/Word and report date headings/structured exports. Times and timezone labels retain their existing behaviour. Stored dates, API timestamps, calendar values, URLs, identifiers and native date/datetime input values remain in their required formats. The input calendar's visual presentation can follow browser/OS locale; the application uses en-US. Existing stored case and financial dates are unchanged.

ISSUED INVOICE EDIT MODE
Click Edit in the invoice list to explicitly enable editing an issued invoice. Normal View remains read-only for invoice details/lines. Edit mode permits dates, client/subject references, notes, discounts and manual line changes, then Finish Editing returns to normal view. Each issued revision retains an encrypted pre-edit snapshot and audit event. The invoice number, issued state and payment/credit ledger remain. Open/uncertain checkout attempts must be resolved before editing. Totals must remain positive and cannot be reduced below payments plus credits. Upcoming reminder schedules follow revised dates. Editing alone does not email the invoice.

USER ROLES & COMPANY CONTACTS
Users has separate Administrators, Case Managers, Investigators, Clients and Accounting tabs. Companies & Client Contacts groups independent client logins under one company. Create the company once, then add client contacts from its page or link existing accounts. Case Assignments and new invoices include company/contact selectors; invoice company identity and shared address inherit the company profile. Company selection is checked on save and does not grant another contact's cases or invoices. Existing accounts, memberships, assignments and issued billing snapshots remain. No new database schema change is needed.

COMPANY ACTIVE / INACTIVE
Administrators can make a company inactive from its profile or company list. This atomically marks every linked client account inactive and invalidates its existing sessions. Pending client notifications are cancelled; cases, invoices and assignments are retained. Linking a contact to an inactive company also disables that login, and inactive-company contacts cannot be individually enabled until the company is activated. Activate Company also activates every linked client account, including contacts that were previously individually inactive, clears their separation dates and invalidates old sessions. Previously cancelled notifications stay cancelled. No company/client records are deleted and no database schema change is required.
