mirror of
https://github.com/itflow-org/itflow
synced 2026-12-02 17:18:59 +00:00
Settings stage 2: move Tickets, Projects, Quotes, Invoices and billing and Defaults onto the settings frame with sections and live next-number previews that refuse a number already in use, validate email addresses instead of blanking them, check the ticket close time and stop its PHP warnings, warn when late fees are on but reminders are off, limit the start page to real ITFlow pages and escape it where shown, keep archived default accounts, rename the Defaults fields to their columns, and keep the reminder, billing time, expense and mileage anchors
This commit is contained in:
@@ -1,27 +1,72 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Admin > Settings > Defaults (admin/settings_default.php):
|
||||
* edit_default_settings saves the start page, calendar, a new client's net
|
||||
* terms and hourly rate, and the accounts and payment methods. A start page
|
||||
* that isn't a page of ITFlow, a calendar or account that isn't there (an
|
||||
* archived account only if it is the one saved), a payment method not in
|
||||
* Admin > Payment Methods (but the one saved) or a rate that isn't one comes
|
||||
* back to the page saying so - nothing is saved. A setting not sent at all
|
||||
* keeps what it is - the accounts aren't on the page with accounting off.
|
||||
*/
|
||||
|
||||
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
|
||||
|
||||
if (isset($_POST['edit_default_settings'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$start_page = escapeSql($_POST['start_page']);
|
||||
$expense_account = intval($_POST['expense_account']);
|
||||
$payment_account = intval($_POST['payment_account']);
|
||||
$payment_method = escapeSql($_POST['payment_method']);
|
||||
$expense_payment_method = escapeSql($_POST['expense_payment_method']);
|
||||
$transfer_from_account = intval($_POST['transfer_from_account']);
|
||||
$transfer_to_account = intval($_POST['transfer_to_account']);
|
||||
$calendar = intval($_POST['calendar']);
|
||||
$net_terms = intval($_POST['net_terms']);
|
||||
$hourly_rate = floatval($_POST['hourly_rate']);
|
||||
$accounts = ['config_default_payment_account', 'config_default_expense_account', 'config_default_transfer_from_account', 'config_default_transfer_to_account'];
|
||||
$methods = ['config_default_payment_method', 'config_default_expense_payment_method'];
|
||||
$before = settingsCurrent(array_merge(['config_start_page', 'config_default_calendar', 'config_default_net_terms', 'config_default_hourly_rate'], $accounts, $methods));
|
||||
|
||||
mysqli_query($mysqli,"UPDATE settings SET config_start_page = '$start_page', config_default_expense_account = $expense_account, config_default_payment_account = $payment_account, config_default_payment_method = '$payment_method', config_default_expense_payment_method = '$expense_payment_method', config_default_transfer_from_account = $transfer_from_account, config_default_transfer_to_account = $transfer_to_account, config_default_calendar = $calendar, config_default_net_terms = $net_terms, config_default_hourly_rate = $hourly_rate WHERE company_id = 1");
|
||||
// What was sent, and what is saved for anything that wasn't
|
||||
$in = $_POST + array_map(function ($value) { return (string) $value; }, $before);
|
||||
|
||||
logAudit("Settings", "Edit", "$session_name edited default settings");
|
||||
$errors = [];
|
||||
$after = ['config_start_page' => trim((string) $in['config_start_page'])];
|
||||
if ($after['config_start_page'] !== (string) $before['config_start_page'] && ($problem = settingsStartPageProblem($after['config_start_page']))) {
|
||||
$errors['config_start_page'] = $problem;
|
||||
}
|
||||
|
||||
flashAlert("Default settings edited");
|
||||
$after['config_default_calendar'] = intval($in['config_default_calendar']);
|
||||
if ($after['config_default_calendar'] && !mysqli_num_rows(mysqli_query($mysqli, "SELECT calendar_id FROM calendars WHERE calendar_id = {$after['config_default_calendar']}"))) {
|
||||
$errors['config_default_calendar'] = 'That calendar isn\'t there any more.';
|
||||
}
|
||||
|
||||
$after['config_default_net_terms'] = intval($in['config_default_net_terms']);
|
||||
if (!isset(settingsNetTerms()[$after['config_default_net_terms']]) && $after['config_default_net_terms'] !== intval($before['config_default_net_terms'])) {
|
||||
$errors['config_default_net_terms'] = 'Pick the terms from the list.';
|
||||
}
|
||||
|
||||
$rate = billingNumberInput($in['config_default_hourly_rate']);
|
||||
if ($rate === null || $rate < 0 || $rate >= 1000000) {
|
||||
$errors['config_default_hourly_rate'] = 'An amount, such as 125.00 - 0 for none.';
|
||||
}
|
||||
$after['config_default_hourly_rate'] = $rate;
|
||||
|
||||
foreach ($accounts as $account) {
|
||||
$after[$account] = intval($in[$account]);
|
||||
if ($after[$account] && $after[$account] !== intval($before[$account])
|
||||
&& !mysqli_num_rows(mysqli_query($mysqli, "SELECT account_id FROM accounts WHERE account_id = {$after[$account]} AND account_archived_at IS NULL"))) {
|
||||
$errors[$account] = 'That account isn\'t there any more, or is archived.';
|
||||
}
|
||||
}
|
||||
|
||||
$payment_methods = paymentMethods();
|
||||
foreach ($methods as $method) {
|
||||
$after[$method] = trim((string) $in[$method]);
|
||||
if ($after[$method] !== '' && $after[$method] !== (string) $before[$method] && !in_array($after[$method], $payment_methods, true)) {
|
||||
$errors[$method] = 'Pick one from the list - they are in Payment methods.';
|
||||
}
|
||||
}
|
||||
|
||||
if ($errors) {
|
||||
settingsRefuse('default', $errors);
|
||||
}
|
||||
|
||||
settingsSave('default', $before, $after);
|
||||
|
||||
redirect();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user