Files
itflow/admin/database_updates/3.1.1.php
johnnyq afaaa5fc32 Taxes stage 1: Admin > Taxes rebuilt (renamed from Tax Rates) listing each rate with its whole percent, parts, description, registration number and usage (invoices, quotes, recurring invoices, products, clients), Current and Archived tabs showing what replaced a rate, Restore, Make default, and Delete only for a rate never used; rates made of parts (state and county, GST and QST) with parts charged on top of the ones above, the whole rate shown as typed, four decimal places and a registration number per rate or part printed with the company details on invoices, quotes and PDFs; changing the percent or parts of a rate on a sent invoice or quote makes a new rate of the same name and archives the old one, so billed lines keep the old rate while products, client rates, the default, recurring invoices and optionally drafts move to the new one, and archiving offers to move whatever still uses it; How lines are taxed settings for the default rate, taxing billed time, trips and expenses, and discounts taken off before tax (on by default, shared across lines by amount, paid, cancelled and answered documents never recalculated); clients get their own tax rate and tax exempt with certificate number and expiry on the Billing tab, new lines defaulting to the client's rate then the product's then the default and to no tax for exempt clients, exempt badge on the client header and overview, a warning with Take the tax off on open documents that still carry taxed lines for an exempt client, and Tax exempt with the certificate under the client on untaxed documents; totals, PDFs, guest and portal views show tax by part; Unbilled Time can bill at each client's usual rate and the ticket, Add Tickets, Add Expenses and Add Trips windows start on it; API client fields for rate and exemption and tax_id default on invoice item create; Tax Collected shows exact percents; demo taxes get parts and registration numbers, demo clients their rates and two nonprofits exemptions; database 3.1.1 makes tax_percent decimal(9,4) and adds tax description, registration and replaced-by, tax_components, client rate and exemption columns and the tax settings; new functions/tax.php and js/tax_form.js; changelog updated
2026-10-17 13:00:54 -04:00

53 lines
3.1 KiB
PHP

<?php
/*
* ITFlow - Database update to version 3.1.1 (from 3.1.0)
* Included by admin/database_updates.php - do not access directly
*/
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
// A rate to the ten-thousandth of a percent (Quebec's 9.975%) rather than
// a float, a description and the registration number the rate is charged
// under, and - when a rate in use was changed - the rate that took its place
// (functions/tax.php: taxChangeRate())
mysqli_query($mysqli, "ALTER TABLE `taxes`
MODIFY `tax_percent` decimal(9,4) NOT NULL DEFAULT 0.0000,
ADD COLUMN `tax_description` varchar(255) DEFAULT NULL AFTER `tax_percent`,
ADD COLUMN `tax_registration_number` varchar(100) DEFAULT NULL AFTER `tax_description`,
ADD COLUMN `tax_replaced_by` int(11) NOT NULL DEFAULT 0 AFTER `tax_registration_number`");
// A rate made of parts - state and county, GST and PST - each charged on
// the line, or on the line and the parts before it (compound), each with
// its own registration number if it has one (GST and QST do). A rate
// without parts is its own single part; with them, tax_percent is the
// whole rate they come to.
mysqli_query($mysqli, "CREATE TABLE IF NOT EXISTS `tax_components` (
`component_id` int(11) NOT NULL AUTO_INCREMENT,
`component_tax_id` int(11) NOT NULL,
`component_name` varchar(200) NOT NULL,
`component_percent` decimal(9,4) NOT NULL DEFAULT 0.0000,
`component_compound` tinyint(1) NOT NULL DEFAULT 0,
`component_registration_number` varchar(100) DEFAULT NULL,
`component_order` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`component_id`),
KEY `component_tax_id` (`component_tax_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci");
// A client's own rate (0: the company's default) and tax exemption, with
// the certificate it rests on and when that runs out
mysqli_query($mysqli, "ALTER TABLE `clients`
ADD COLUMN `client_default_tax_id` int(11) NOT NULL DEFAULT 0 AFTER `client_tax_id_number`,
ADD COLUMN `client_tax_exempt` tinyint(1) NOT NULL DEFAULT 0 AFTER `client_default_tax_id`,
ADD COLUMN `client_tax_exempt_number` varchar(200) DEFAULT NULL AFTER `client_tax_exempt`,
ADD COLUMN `client_tax_exempt_expires` date DEFAULT NULL AFTER `client_tax_exempt_number`");
// The default rate for new lines, whether billed time, trips and expenses
// are taxed, and discounts taken off before tax is worked out
mysqli_query($mysqli, "ALTER TABLE `settings`
ADD COLUMN `config_tax_default_id` int(11) NOT NULL DEFAULT 0 AFTER `config_invoice_show_tax_id`,
ADD COLUMN `config_tax_time` tinyint(1) NOT NULL DEFAULT 0 AFTER `config_tax_default_id`,
ADD COLUMN `config_tax_trips` tinyint(1) NOT NULL DEFAULT 0 AFTER `config_tax_time`,
ADD COLUMN `config_tax_expenses` tinyint(1) NOT NULL DEFAULT 0 AFTER `config_tax_trips`,
ADD COLUMN `config_tax_discount_before` tinyint(1) NOT NULL DEFAULT 1 AFTER `config_tax_expenses`");