Files
itflow/admin/database_updates/3.0.0.php
johnnyq 94413424e4 Expenses stage 2: recurring expenses on a real schedule - monthly, quarterly or yearly on the day of the month they started on with the 31st falling back to a shorter month's last day, an optional end date for leases and financing after which they stop by themselves, the nightly run recording each one due today or missed by up to 7 nights dated the day it was due and telling the team about each with a link to it, one notice the day one falls too far behind in place of the nightly nag, Record Now dated today when early or the due date when late and safe to press twice, Move On to skip missed runs, Pause and Resume, a rebuilt list with cost a month, the next 30 days, running and need a look along the top, Active, Next 7 days, Late, Paused, Ended and All pills and vendor, category and client filters, a quick look with the schedule in words, the next dates, this year's total and the expenses it recorded, one New and Edit form that says the schedule as it is set and fills in from the vendor's last expense, recorded expenses carrying the payment method and reference and linked back with a filter and icon on the expenses list and a Recorded by line in their quick look, the dashboard figure, cash flow forecast and expense, recurring revenue and spend by vendor reports counting quarterly ones and end dates, the vendor page opening the quick look, demo data standing costs on their own days with insurance quarterly and linked to their history, fixes for edits moving the next date, new monthly ones starting in the picked month, recorded expenses losing the payment method, no way to pause and the list's date filter using the creation date, delete now needing full financial access, database 3.0.0 with frequency as month, quarter or year, anchor day and end date, the old day and month columns dropped and expense_recurring_expense_id backfilled, CHANGELOG updated
2026-10-16 18:02:00 -04:00

36 lines
2.3 KiB
PHP

<?php
/*
* ITFlow - Database update to version 3.0.0 (from 2.9.9)
* Included by admin/database_updates.php - do not access directly
*/
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
// Recurring expenses on the recurring invoice schedule (functions/expenses.php):
// month, quarter or year, on the day of the month it started on, with an
// optional end date for leases and financing. 1 was monthly, 2 yearly.
mysqli_query($mysqli, "ALTER TABLE `recurring_expenses`
MODIFY `recurring_expense_frequency` varchar(10) NOT NULL DEFAULT 'month',
ADD COLUMN `recurring_expense_anchor_day` tinyint(2) NOT NULL DEFAULT 0 AFTER `recurring_expense_frequency`,
ADD COLUMN `recurring_expense_end_date` date DEFAULT NULL AFTER `recurring_expense_next_date`");
mysqli_query($mysqli, "UPDATE recurring_expenses SET recurring_expense_frequency = IF(recurring_expense_frequency = '2', 'year', 'month')");
// Each keeps the day of the month its next date is on - the nightly run
// moved it a month on from the day it ran, so that is the day it really
// runs on. The old day and month fields go.
mysqli_query($mysqli, "UPDATE recurring_expenses SET recurring_expense_anchor_day = DAY(recurring_expense_next_date)");
mysqli_query($mysqli, "ALTER TABLE `recurring_expenses` DROP COLUMN `recurring_expense_day`, DROP COLUMN `recurring_expense_month`");
// The expenses a recurring expense made link back to it
mysqli_query($mysqli, "ALTER TABLE `expenses` ADD COLUMN `expense_recurring_expense_id` int(11) DEFAULT NULL AFTER `expense_refund_of_id`");
// The ones the nightly run already made carried its vendor, category,
// client and description - linked from the day the recurring expense was set up
mysqli_query($mysqli, "UPDATE expenses
JOIN recurring_expenses ON recurring_expense_vendor_id = expense_vendor_id AND recurring_expense_category_id = expense_category_id
AND recurring_expense_client_id = expense_client_id AND recurring_expense_description = expense_description
SET expense_recurring_expense_id = recurring_expense_id
WHERE expense_recurring_expense_id IS NULL AND expense_vendor_id > 0 AND expense_amount > 0
AND COALESCE(recurring_expense_description, '') <> '' AND expense_date >= DATE(recurring_expense_created_at)");