Accounts and transactions: each account gets a kind (checking, savings, credit card, cash, payment processor, other) with its own icon, and a credit card's balance reads as owed on the accounts page, its ledger, the dashboard and every account picker; the accounts page has cards for what the accounts hold, what is owed on cards and money in and out this month against the same days of last month with transfers left out, and each row shows its description, defaults, kind, currency, balance with opening balance, this month's in and out and latest line, with Pay the Card or Transfer from it, Archive once empty, an Archived pill with Restore, and Delete only for an account never used; New Account and Edit share one form with an editable opening balance that is logged, the currency locked once money is on the account, and every field checked; Transactions is rebuilt as each account's ledger with an account switcher or every account, In and Out columns, the running balance for one account, pills for money in, money out and transfers, category, client, kind, method and amount filters, search, footer totals and an export taking the same filters with Account, Who or What, Client, In and Out columns; Transfers fold into the Transfers pill of Transactions with the menu link and old transfers.php links kept, New Transfer, Pay the Card and Edit share one checked form with a Swap button that keeps both sides in step and takes the from account's currency, a transfer into a card is a card payment, and a new transfer quick look has Edit and Delete; archive and delete rules are enforced in the handlers, editing a transfer no longer takes the expense and revenue ids from the form, transfer legs record who entered them, and one balance rule leaving out archived rows is used everywhere; new functions/accounts.php and agent/modals/transfer/transfer.php, account_form.php and transfer_form.php, transfer_model.php removed; database 3.0.7 sets each account's kind from its name; demo data adds a Business Visa paid off monthly from Operating Checking; CHANGELOG updated

This commit is contained in:
johnnyq
2026-10-16 22:26:45 -04:00
parent 47969cd3c2
commit e7389a60be
30 changed files with 2082 additions and 1781 deletions

View File

@@ -0,0 +1,23 @@
<?php
/*
* ITFlow - Database update to version 3.0.7 (from 3.0.6)
* Included by admin/database_updates.php - do not access directly
*/
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
// What kind each account is (functions/accounts.php - 1 checking, 2
// savings, 3 credit card, 4 cash, 5 payment processor, 6 other), from
// its name for the ones already here. A credit card's balance reads as
// owed, and a transfer into one as paying it. Changeable afterwards.
// Accounts typed in 2023 carry the old account_types ids (10 to 39, the
// table dropped in 1.5.1): a liability (20s) is money owed, as a card is.
mysqli_query($mysqli, "UPDATE accounts SET account_type = CASE
WHEN LOWER(account_name) REGEXP 'saving|reserve' THEN 2
WHEN LOWER(account_name) REGEXP 'card|visa|amex|american express|mastercard|discover|credit' THEN 3
WHEN LOWER(account_name) REGEXP 'cash|petty' THEN 4
WHEN LOWER(account_name) REGEXP 'stripe|paypal|square|merchant|settlement|processor|gateway' THEN 5
WHEN account_type BETWEEN 20 AND 29 THEN 3
ELSE 1 END
WHERE account_type IS NULL OR account_type NOT BETWEEN 1 AND 6");

View File

@@ -31,6 +31,7 @@ function demoDataAccounts() {
['Operating Checking', 'Day to day business banking - client payments in, bills out', 18500.00],
['Business Savings', 'Tax and reserve holding', 42000.00],
['Merchant Settlement', 'Card and online payments waiting to be paid out', 0.00],
['Business Visa', 'Company card for subscriptions, supplies and meals', 0.00],
];
}
@@ -549,6 +550,7 @@ function demoEnsureAccounts($mysqli, $currency) {
'account_description' => $account[1],
'opening_balance' => number_format($account[2], 2, '.', ''),
'account_currency_code' => $currency,
'account_type' => accountTypeGuess($account[0]),
'account_created_at' => demoMonthDateTime(24, 1, 9, 0),
]);
}
@@ -3244,7 +3246,7 @@ function demoBuildBilling($mysqli, $profile, $index, $client_id, $vendor_id, $mo
'expense_currency_code' => $currency,
'expense_date' => demoMonthDate($month, 14),
'expense_reference' => 'INV-' . demoSerial($profile['abbreviation'] . $expense[0] . $month, 8),
'expense_payment_method' => 'Credit Card',
'expense_payment_method' => 'ACH',
'expense_vendor_id' => $context['org_vendors'][$expense[3]] ?? 0,
'expense_client_id' => $client_id,
'expense_category_id' => demoCategoryId($mysqli, $expense[2], 'Expense'),
@@ -3348,6 +3350,12 @@ function demoBuildCompanyFinancials($mysqli, $context, &$counts) {
['Conference and travel', 1450.00, 'Travel', 12, 18, 'Alcott and Reyes CPA'],
];
// The smaller, recurring costs go on the company card, paid off from the
// bank early the next month - so the card shows what is owed on it
$card_id = $context['accounts']['Business Visa'] ?? 0;
$card_categories = ['Software', 'Cloud and Hosting', 'Office Supplies', 'Meals', 'Shipping and Postage', 'Dues and Subscriptions', 'Telecom and Internet'];
$card_spent = [];
// Which purchases put hardware on the shelf, and what they bring in
$stock_lines = [
'UniFi shelf stock for the workshop' => ['Ubiquiti U6-Pro Access Point', 4],
@@ -3363,6 +3371,10 @@ function demoBuildCompanyFinancials($mysqli, $context, &$counts) {
// Payroll and rent creep up over two years rather than sitting flat
$drift = 1 + ((24 - $month) * 0.004);
$on_card = $card_id && in_array($cost[2], $card_categories, true);
if ($on_card) {
$card_spent[$month] = ($card_spent[$month] ?? 0) + round($cost[1] * $drift, 2);
}
$expense_id = starterInsert($mysqli, 'expenses', [
'expense_description' => $cost[0],
@@ -3370,11 +3382,12 @@ function demoBuildCompanyFinancials($mysqli, $context, &$counts) {
'expense_currency_code' => $currency,
'expense_date' => demoMonthDate($month, $cost[4]),
'expense_reference' => 'BILL-' . demoSerial('company' . $cost[0] . $month, 8),
'expense_payment_method' => $cost[0] === 'Payroll' ? 'ACH' : 'Credit Card',
// Payroll and the bills from the bank go by ACH, the card's own costs by card
'expense_payment_method' => $cost[0] !== 'Payroll' && ($on_card || !$card_id) ? 'Credit Card' : 'ACH',
'expense_vendor_id' => $vendors[$cost[5]] ?? 0,
'expense_client_id' => 0,
'expense_category_id' => demoCategoryId($mysqli, $cost[2], 'Expense'),
'expense_account_id' => $operating_id,
'expense_account_id' => $on_card ? $card_id : $operating_id,
'expense_created_at' => demoMonthDateTime($month, $cost[4], 17, 0),
]);
$counts['company']++;
@@ -3508,6 +3521,13 @@ function demoBuildCompanyFinancials($mysqli, $context, &$counts) {
}
}
// The card's statement paid in full from the bank on the 2nd of the next month
foreach ($card_spent as $month => $spent) {
if ($month > 0 && $spent > 0) {
demoTransfer($mysqli, $operating_id, $card_id, $spent, $currency, 'Bank Transfer', 'Business Visa statement paid in full', $month - 1, 2, $counts);
}
}
// Card settlements landing in the bank, and the quarterly tax reserve
$cash_id = $context['cash_account_id'];
for ($month = 24; $month >= 0; $month--) {