Module switches: Dispatch, Bookkeeping, Purchasing, Trips and Calendar can be switched off in Admin > Settings > Modules, Dispatch coming with ticketing and the other three with invoicing, each hidden from menus, dashboard, search, reports and the API and refused on its pages, windows and handlers while off; Purchasing starts off unless already in use, Bookkeeping off posts the default accounts in place of account pickers, database 3.9.4, new moduleOn, moduleOffText and bookkeepingAccount helpers, purchase order settings tile summary, 26.11.9 changelog entries

This commit is contained in:
johnnyq
2026-11-18 14:27:16 -05:00
parent 00724866e3
commit 9bcf0e433b
108 changed files with 772 additions and 167 deletions

View File

@@ -351,6 +351,10 @@ function tripLastStart() {
function tripSave(array $in, $trip_id = 0, &$error = '') {
global $mysqli, $session_user_id;
$error = '';
if (!moduleOn('trips')) {
$error = moduleOffText('trips');
return 0;
}
$trip_id = intval($trip_id);
$existing = $trip_id ? tripRow($trip_id) : null;
if ($trip_id && !$existing) {
@@ -468,6 +472,10 @@ function tripSave(array $in, $trip_id = 0, &$error = '') {
function tripDelete($trip_id, &$error = '') {
global $mysqli;
$error = '';
if (!moduleOn('trips')) {
$error = moduleOffText('trips');
return null;
}
$row = tripRow($trip_id);
if (!$row) {
$error = 'That trip no longer exists, or is not one you can see';
@@ -492,6 +500,9 @@ function tripDelete($trip_id, &$error = '') {
/** The trips of a ticket, a site or a client - newest first, scoped. For the cards that list them. */
function tripsFor($column, $id, $limit = 10) {
global $mysqli;
if (!moduleOn('trips')) {
return [];
}
if (!in_array($column, ['trip_ticket_id', 'trip_location_id', 'trip_client_id', 'trip_expense_id', 'trip_invoice_id'], true)) {
return [];
}
@@ -510,6 +521,9 @@ function tripsFor($column, $id, $limit = 10) {
/** How many trips and miles a ticket, site or client has - [count, miles], scoped. */
function tripTotalsFor($column, $id) {
global $mysqli;
if (!moduleOn('trips')) {
return [0, 0.0];
}
if (!in_array($column, ['trip_ticket_id', 'trip_location_id', 'trip_client_id', 'trip_expense_id', 'trip_invoice_id'], true)) {
return [0, 0.0];
}
@@ -711,6 +725,9 @@ function tripClaimSql() {
*/
function tripsToClaim($user_id = 0, array $ids = []) {
global $mysqli;
if (!moduleOn('trips')) {
return [];
}
$user_id = intval($user_id);
$ids = array_filter(array_map('intval', $ids));
$rate = tripRules()['rate'];
@@ -740,6 +757,9 @@ function tripsToClaim($user_id = 0, array $ids = []) {
/** How many trips are waiting to be paid back for, their distance and drivers, and what that comes to at the rate - for the list and the dashboard. */
function tripToClaimCount() {
global $mysqli;
if (!moduleOn('trips')) {
return ['count' => 0, 'miles' => 0.0, 'agents' => 0, 'value' => 0.0];
}
$row = mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*), COALESCE(SUM(trip_miles), 0), COUNT(DISTINCT trip_user_id)
FROM trips LEFT JOIN clients ON client_id = trips.trip_client_id WHERE " . tripClaimSql() . ' ' . tripScopeSql()));
$miles = round(floatval($row[1]), 1);
@@ -757,6 +777,10 @@ function tripToClaimCount() {
function tripClaim($user_id, array $trip_ids, array $opts, &$error = '') {
global $mysqli, $session_user_id, $session_company_currency;
$error = '';
if (!moduleOn('trips')) {
$error = moduleOffText('trips');
return null;
}
$user_id = intval($user_id);
$driver = $trip_ids ? (tripsToClaim($user_id, $trip_ids)[$user_id] ?? null) : null;
if (!$user_id || !$driver) {
@@ -833,6 +857,9 @@ function tripUnbilledSql() {
*/
function tripUnbilled($client_id = 0, array $ids = []) {
global $mysqli;
if (!moduleOn('trips')) {
return [];
}
$client_id = intval($client_id);
$ids = array_filter(array_map('intval', $ids));
$rows = [];
@@ -852,6 +879,9 @@ function tripUnbilled($client_id = 0, array $ids = []) {
/** How many trips are waiting to be billed, and what they come to - every client the agent can see, or one - for the menu, the dashboard and the client's overview. */
function tripUnbilledCount($client_id = 0) {
global $mysqli;
if (!moduleOn('trips')) {
return ['count' => 0, 'value' => 0.0];
}
$client_id = intval($client_id);
$rules = tripRules();
$row = mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*), COALESCE(SUM(ROUND({$rules['charge']} + {$rules['bill_rate']} * GREATEST(0, trip_miles - {$rules['included']}), 2)), 0)
@@ -925,6 +955,10 @@ function tripBillLine(array $trip) {
function tripBillInvoice($client_id, array $prices, array $opts, &$error = '') {
global $mysqli;
$error = '';
if (!moduleOn('trips')) {
$error = moduleOffText('trips');
return null;
}
$client_id = intval($client_id);
$by = (string) ($opts['by'] ?? 'ITFlow');
$trips = $prices ? tripUnbilled($client_id, array_keys($prices)) : [];
@@ -1058,6 +1092,9 @@ function tripUnbill($trip_id, &$error = '') {
/** The trips billed on an invoice - each with what its line bills before tax. */
function tripsOnInvoice($invoice_id) {
global $mysqli;
if (!moduleOn('trips')) {
return [];
}
$invoice_id = intval($invoice_id);
$rows = [];
$sql = mysqli_query($mysqli, "SELECT trips.*, driver.user_name AS driver_name, ticket_prefix, ticket_number, ticket_subject, item_subtotal