'trips.trip_date', 'user_name' => 'driver.user_name', 'trip_destination' => 'trips.trip_destination', 'client_name' => 'client_name', 'trip_miles' => 'trips.trip_miles']; if (!isset($sortable_columns[$sort])) { $sort = 'trip_date'; } // Everything but the pill, then the pill - the pill counts are over what the rest leave $filter_src = array_merge($_GET, ['dtf' => $dtf, 'dtt' => $dtt, 'show' => '', 'client' => $client_filter]); $where = tripFiltersSql($filter_src); $show_query = $shows[$show]['where'] ? "AND {$shows[$show]['where']}" : ''; $joins = tripJoinsSql(); $sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS trips.*, client_name, driver.user_name AS driver_name, driver.user_avatar AS driver_avatar, location_name, ticket_prefix, ticket_number, ticket_subject, ticket_resolved_at, ticket_closed_at, invoice_prefix, invoice_number, invoice_status FROM trips $joins LEFT JOIN invoices ON trips.trip_invoice_id > 0 AND invoice_id = trips.trip_invoice_id WHERE $where $show_query ORDER BY {$sortable_columns[$sort]} $order, trips.trip_id DESC LIMIT $record_from, $record_to"); $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); $trips = []; while ($row = mysqli_fetch_assoc($sql)) { $trips[] = $row; } // The pills, and the miles of what is listed $count_sql = []; foreach ($shows as $key => $s) { $count_sql[] = $key === '' ? 'COUNT(*)' : "COALESCE(SUM({$s['where']}), 0)"; } $row = mysqli_fetch_row(mysqli_query($mysqli, "SELECT " . implode(', ', $count_sql) . ", COALESCE(SUM(CASE WHEN 1 $show_query THEN trips.trip_miles END), 0) FROM trips $joins WHERE $where")); $counts = []; foreach (array_keys($shows) as $i => $key) { $counts[$key] = intval($row[$i]); } $listed_miles = floatval($row[count($shows)]); $stats = tripStats(); // The money - who is owed for their own vehicle (above the list on To pay back), and the rates $rules = tripRules(); $pay_back = tripPayBackOn(); $owed_total = $pay_back ? tripToClaimCount() : null; $owed = $show === 'to_pay' ? tripsToClaim($driver_filter) : []; $stat_money = function ($amount) { return escapeHtml(billingMoney($amount)); }; $filter_url = function ($changes) use ($client_page, $client_id) { $params = array_merge($_GET, $changes); unset($params['page']); if ($client_page) { $params['client_id'] = $client_id; } return '?' . http_build_query(array_filter($params, function ($v) { return $v !== '' && $v !== null; })); }; $date_url = function ($from, $to, $changes = []) use ($filter_url) { return $filter_url(array_merge(['canned_date' => 'custom', 'dtf' => $from, 'dtt' => $to], $changes)); }; $any_filter = $q || $driver_filter || ($client_filter && !$client_page) || $location_filter || $ticket_filter || $expense_filter || $invoice_filter || $show !== '' || $dtf !== '1970-01-01'; $add_url = 'modals/trip/trip_add.php' . ($client_page ? "?client_id=$client_id" : ''); ?>
This month
trip · % on the same days of
so far
trip
Yours this month
trip you drove
in their own vehicle Nothing waiting ·
For clients this year
0 ? round($stats['year_client_miles'] / $stats['year_miles'] * 100) . '% of the driving' : 'No driving yet this year' ?>

Tripsyours' ?>

$location_filter, 'ticket_id' => $ticket_filter, 'expense_id' => $expense_filter, 'invoice_id' => $invoice_filter] as $key => $value) { if ($value) { ?>
mileage expense'; } else { $invoice_row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT invoice_prefix, invoice_number FROM invoices WHERE invoice_id = $invoice_filter")); $filter_text = 'Billed on ' . escapeHtml($invoice_row ? $invoice_row['invoice_prefix'] . $invoice_row['invoice_number'] : 'an invoice since deleted') . ''; } ?>
$owed_driver) { ?>
is owed for trip, at 1 ? ', the oldest ' . $owed_driver['oldest'] . ' days ago' : '' ?>
Date Trip Client Site Driver
>
·
Our own
intval($row['trip_location_id'])])) . '">' . escapeHtml($row['location_name']) . '' : '-' ?> ' : ''; } if ($row['invoice_number'] !== null) { $marks[] = ''; } elseif (intval($row['trip_billable']) && intval($row['trip_client_id'])) { $marks[] = ''; } if ($marks) { ?>
trip count($trips) ? ' - the total is for all of them, not just this page' : '' ?>
'trips', 'icon' => 'fa-route', 'filtered' => $q || $driver_filter || ($client_filter && !$client_page) || $location_filter || $ticket_filter || $expense_filter || $invoice_filter || $dtf !== '1970-01-01', 'views' => ['show'], 'view' => emptyStatePill($shows, $show, '', ['to_pay', 'to_bill']), 'text' => 'Log the drive out to a client from their ticket - Log a trip, in its menu - or with New Trip here.', 'actions' => [['label' => 'New Trip', 'modal' => $add_url, 'size' => 'lg']], ]; require_once "../includes/filter_footer.php"; ?>