Files
itflow/api/v1/recurring_expenses/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

52 lines
2.4 KiB
PHP

<?php
/*
* API - Recurring Expenses - Create
* POST /api/v1/recurring_expenses/create.php
*
* Set up a bill that comes round, as New Recurring Expense does
* (recurringExpenseSave()) - recorded as an expense on each date by the nightly
* run, and on to the next.
*
* Parameters (POST, JSON body):
* api_key required - Your API key
* recurring_expense_vendor_id required - One of your vendors
* recurring_expense_amount required - Each time
* recurring_expense_frequency required - month, quarter or year
* recurring_expense_next_date required - The first one, Y-m-d
* recurring_expense_account_id required - The account it is paid from
* recurring_expense_category_id required - An expense category
* recurring_expense_end_date optional - The last day it runs
* recurring_expense_client_id optional - The client it is for
* recurring_expense_billing optional - bill (to the client, at the markup), covered (by recurring_expense_recurring_invoice_id) or none
* recurring_expense_markup, recurring_expense_recurring_invoice_id optional
* recurring_expense_tax_id, recurring_expense_tax_amount optional - The tax in it
* recurring_expense_payment_method, recurring_expense_reference, recurring_expense_description optional
*/
require_once '../validate_api_key.php';
require_once '../require_post_method.php';
require_once 'recurring_expense_map.php';
$insert_id = false;
$in = apiFormInput($recurring_expense_map);
$in['billing'] = $recurring_expense_billing(null);
if (intval($in['client_id'] ?? 0) && !apiUserCanAccessClient($in['client_id'])) {
apiDeny("The user linked to this API key does not have access to the target client for this write.");
}
$error = '';
$id = intval(recurringExpenseSave($in, 0, $error));
if (!$id) {
apiFormRefuse($error);
}
$insert_id = $id;
$row = recurringExpenseRow($id, false);
$label = escapeSql(recurringExpenseLabel($row));
logAudit("Recurring Expense", "Create", "Created the recurring expense $label via API ($api_key_name)", intval($row['recurring_expense_client_id']), $id);
logAudit("API", "Success", "Created the recurring expense $label via API ($api_key_name)", intval($row['recurring_expense_client_id']));
// Output
require_once '../create_output.php';