Files
itflow/api/v1/trips/create.php
johnnyq ecbb974fff API stage 3, calendar events, trips, accounts and money, contracts, and files and folders: calendars can be read, and calendar events read with their attendees, created once or repeating for a client or nobody, changed, sent as invitations, skipped for a day of a series and deleted, following calendarEventCan(); trips can be read, logged, changed and deleted through tripSave() and tripDelete(), anyone their own and someone else's with Financial; accounts can be read with their balances, added, changed, archived, unarchived and deleted while nothing is on them, other income and transfers read, recorded, changed and deleted, and recurring expenses read, set up, changed, paused and resumed, recorded now, moved on past missed runs and deleted, keeping reconciled lines as they were; contracts can be read with their prepaid hours and signing state, added, changed, made active, renewed, cancelled and deleted, sent for signature or the link sent again, the request withdrawn, prepaid hours added with a draft invoice or deleted, tickets' time drawn or put back, and the billing recurring invoice made, linked or unlinked; a client's files can be read, uploaded as base64, downloaded, renamed, moved, archived, unarchived and deleted once archived, and folders read, made, renamed, moved and deleted with their contents moved up; new api/v1/form_input.php builds a save function's input from the API's field names; the upload allow-list moves from agent/post/file.php into fileUploadExtensions() so Upload Files and the API check the same list; enforce_api_rbac.php maps the new resources, lets events, calendars and trips check their own rules, puts the new state changes at Modify and treats files/download as a read; 26.11.9 changelog entries
2026-11-13 23:51:10 -05:00

53 lines
2.0 KiB
PHP

<?php
/*
* API - Trips - Create
* POST /api/v1/trips/create.php
*
* Log a trip, as New Trip does - by the key's own agent unless trip_user_id says
* who drove; logging one for someone else needs Modify on Financial. The distance
* is the odometer readings' difference when both are sent, else trip_miles one
* way, doubled for a round trip.
*
* Parameters (POST, JSON body):
* api_key required - Your API key
* trip_destination required - Where it went
* trip_purpose required - What it was for
* trip_miles required without odometer readings - The distance one way
* trip_date optional - Y-m-d, today if left out
* trip_source optional - Where it started; your company's address if left out
* round_trip optional - 1: there and back
* trip_start_odometer, trip_end_odometer optional - Whole numbers
* client_id optional - The client it was for
* trip_location_id optional - One of the client's sites
* trip_ticket_id optional - One of the client's tickets
* trip_user_id optional - Who drove
* trip_own_vehicle optional - 1: their own car, paid back for the distance
* trip_billable optional - 1: to bill to the client
*/
require_once '../validate_api_key.php';
require_once '../require_post_method.php';
$insert_id = false;
require_once 'trip_model.php';
$error = '';
$trip_id = intval(tripSave($trip_in, 0, $error));
if (!$trip_id) {
http_response_code(400);
$return_arr['success'] = "False";
$return_arr['message'] = $error . '.';
echo json_encode($return_arr);
exit();
}
$insert_id = $trip_id;
$row = tripRow($trip_id, false);
$label = escapeSql(tripLabel($row));
logAudit("Trip", "Create", "Logged the trip $label via API ($api_key_name)", intval($row['trip_client_id']), $trip_id);
logAudit("API", "Success", "Logged the trip $label via API ($api_key_name)", intval($row['trip_client_id']));
// Output
require_once '../create_output.php';