Files
itflow/agent/modals/trip/trip_bulk_edit.php
johnnyq a2a0823163 Trips stage 2: mileage money - Trips and Mileage in Admin > Settings > Invoice with miles or kilometers, the rate an agent is paid back for their own vehicle and the expense category it goes under, and what a trip bills a client as a trip charge, a rate a mile beyond the distance the charge covers and the invoice line name; the trip form has In their own vehicle starting as the driver's latest trip and Bill the client starting as the ticket is billable, each showing what it pays back or bills; the list gets To pay back and To bill pills, an owed card (Owed to you for agents without financial access), who is owed what and marks on each row; Pay Mileage pays one driver for the ticked trips at the usual or a past rate as a mileage expense per client paid personally by them under the mileage category to a Mileage vendor made on first use, paid back there and then from an account or later with Reimburse; Unbilled Time has Travel to bill beside the expenses at an editable price going on the client's invoice with their tickets and expenses, billing every client includes trips and Not billable writes them off; the invoice gets a Travel card with Add Trips and Take off Invoice, and deleting the line or invoice makes a trip to bill again; paid back and billed trips keep their distance, driver, vehicle, client and billable and can't be deleted, and deleting the mileage expense puts its trips back to pay; bulk Set Vehicle, Set Billable and Pay Mileage; the trip quick look shows what it pays back and bills and the mileage expense lists its trips; dashboard Trips to bill and Mileage to pay back, client overview Trips to bill and the Unbilled Time count include trips; export Vehicle, Paid Back and Billing columns; the Mileage report and dashboard chart follow the unit and the report rate starts at the mileage rate; demo data with recent trips in own vehicles and billable when trips bill; database 3.0.4 with trip_own_vehicle, trip_expense_id, trip_billable, trip_invoice_id, trip_invoice_item_id and the mileage and trip billing settings; CHANGELOG updated
2026-10-16 20:35:51 -04:00

96 lines
4.9 KiB
PHP

<?php
/*
* Set the driver, client, vehicle or billable of the ticked trips - ?field=
* driver, client, vehicle or billable. A new client takes the site and
* ticket off a trip that was another client's. A trip paid back for keeps
* its driver and vehicle, one billed its client and billable. Posts
* bulk_edit_trips with field, value and trip_ids[].
*/
require_once '../../../includes/modal_header.php';
enforceUserPermission('module_financial', 2);
$trip_ids = array_values(array_unique(array_filter(array_map('intval', (array) ($_GET['trip_ids'] ?? [])))));
$count = count($trip_ids);
$field = (string) ($_GET['field'] ?? '');
$fields = [
'driver' => ['label' => 'Driver', 'icon' => 'fa-user'],
'client' => ['label' => 'Client', 'icon' => 'fa-building'],
'vehicle' => ['label' => 'Vehicle', 'icon' => 'fa-car-side'],
'billable' => ['label' => 'Billable', 'icon' => 'fa-file-invoice-dollar'],
];
if (!isset($fields[$field])) {
echo json_encode(['error' => 'Pick what to set from the Bulk Action menu.']);
exit;
}
if (!$count) {
echo json_encode(['error' => 'Tick the trips to change first.']);
exit;
}
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fas fa-fw <?= $fields[$field]['icon'] ?> me-2"></i>Set <?= $fields[$field]['label'] ?> <span class="fw-normal text-white-50 ms-1"><?= $count ?> trip<?= $count === 1 ? '' : 's' ?></span></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="field" value="<?= $field ?>">
<?php foreach ($trip_ids as $trip_id) { ?>
<input type="hidden" name="trip_ids[]" value="<?= $trip_id ?>">
<?php } ?>
<div class="modal-body">
<label class="form-label"><?= $fields[$field]['label'] ?><?= $field === 'driver' ? ' <strong class="text-danger">*</strong>' : '' ?></label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw <?= $fields[$field]['icon'] ?>"></i></span>
<?php if ($field === 'driver') { ?>
<select class="form-select select2" name="value" required>
<option value="">- Pick who drove -</option>
<?php foreach (tripDrivers() as $user_id => $driver) { ?>
<option value="<?= $user_id ?>"<?= selectOptionUser($user_id, $driver['user_name'], $driver['user_avatar'] ?? '') ?>><?= escapeHtml($driver['user_name']) ?></option>
<?php } ?>
</select>
<?php } elseif ($field === 'vehicle') { ?>
<select class="form-select" name="value">
<option value="1">Their own vehicle - paid back for the distance</option>
<option value="0">A company vehicle</option>
</select>
<?php } elseif ($field === 'billable') { ?>
<select class="form-select" name="value">
<option value="1">Bill the client for them</option>
<option value="0">Not billed - our cost</option>
</select>
<?php } else { ?>
<select class="form-select select2" name="value">
<option value="0">- Our own - not for a client -</option>
<?php
$sql = mysqli_query($mysqli, "SELECT client_id, client_name, client_abbreviation FROM clients WHERE client_archived_at IS NULL " . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC");
while ($row = mysqli_fetch_assoc($sql)) { ?>
<option value="<?= intval($row['client_id']) ?>"<?= selectOptionClient($row['client_id'], $row['client_name'], $row['client_abbreviation'] ?? '') ?>><?= escapeHtml($row['client_name']) ?></option>
<?php } ?>
</select>
<?php } ?>
</div>
<?php if ($field === 'client') { ?>
<div class="form-text">A trip that was another client's loses its site and ticket - they were that client's. Trips billed already keep their client.</div>
<?php } elseif ($field === 'billable') { ?>
<div class="form-text">Only trips for a client are billed. Trips billed already stay as they are.</div>
<?php } elseif ($field !== 'client') { ?>
<div class="form-text">Trips paid back for already stay as they are.</div>
<?php } ?>
</div>
<div class="modal-footer">
<button type="submit" name="bulk_edit_trips" class="btn btn-primary text-bold"><i class="fas fa-check me-2"></i>Set on <?= $count ?></button>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fas fa-times me-2"></i>Cancel</button>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';