Add support for closed_at field in order invoices

Introduce the closed_at field to track closure dates for order invoices. Updated validation, processing logic, and database integration to ensure correct handling of the new field. Adjusted related routes to pass and store the closed_at value where applicable.
This commit is contained in:
Jepp9350
2025-05-01 15:45:59 +02:00
parent 8ae3a35a91
commit 8d2fe8d75d
3 changed files with 39 additions and 7 deletions
@@ -104,7 +104,7 @@ class orderInvoicesRoute
(new logs_o())->add('orderInvoices', 'global', 1, $user->id, 'ADD_COLLECTED_INVOICE', 'User added a collected order invoice');
// Require the customer number, and validate its type and length
self::requireParameters(['customer_number']);
self::requireType((int)self::getParameter('customer_number'), 'int');
self::requireType((int)self::getParameter('customer_number'), self::type_int());
self::requireMinLength('customer_number', 1);
self::requireMaxLength('customer_number', 10);
// Require the customer number to be above 0
@@ -116,30 +116,47 @@ class orderInvoicesRoute
$name = null;
$notes = null;
$processor = null;
$closed_at = null;
// Check if the name is set
if (self::isParametersSet(['name'])) {
self::requireType((string)self::getParameter('name'), 'string');
self::requireType((string)self::getParameter('name'), self::type_string());
self::requireMinLength('name', 1);
self::requireMaxLength('name', 255);
$name = (string)self::getParameter('name');
}
// Check if the notes are set
if (self::isParametersSet(['notes'])) {
self::requireType((string)self::getParameter('notes'), 'string');
self::requireType((string)self::getParameter('notes'), self::type_string());
$notes = (string)self::getParameter('notes');
}
// Check if the processor is set
if (self::isParametersSet(['processor'])) {
self::requireType((int)self::getParameter('processor'), 'int');
self::requireType((int)self::getParameter('processor'), self::type_int());
$processor = (int)self::getParameter('processor');
}
// Check if the closed_at is set
if (self::isParametersSet(['closed_at'])) {
// Check if the closed date is set, and validate its type
if (!!self::getParameter('closed_at')) {
self::requireType((string)self::getParameter('closed_at'), self::type_string());
$closed_at = (string)self::getParameter('closed_at');
// Check if the closed date is valid
if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $closed_at)) {
$response->error('Invalid closed date format', 400);
}
// Set the time to 00:00:01z
$closed_at = date('Y-m-d H:i:s', strtotime($closed_at . ' 00:00:01'));
}
}
// Add the collected order invoice
$collected_order_invoices = new collected_order_invoices_o();
$collected_order_invoices->add(
$customer->id,
$name,
$notes,
$processor
$processor,
$closed_at ?: null,
);
$response->success($collected_order_invoices->asArray());
} else {