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:
@@ -485,7 +485,7 @@ class collected_order_invoices_o extends db
|
||||
* @return self The created object
|
||||
* @throws Exception If the object was not created successfully
|
||||
*/
|
||||
public function add(int $customer_number, ?string $name = null, ?string $notes = null, ?int $processor = null): self
|
||||
public function add(int $customer_number, ?string $name = null, ?string $notes = null, ?int $processor = null, ?string $closed_at = null): self
|
||||
{
|
||||
global /** @var db $db */
|
||||
$db;
|
||||
@@ -500,13 +500,21 @@ class collected_order_invoices_o extends db
|
||||
if (!empty($processor)) {
|
||||
$processor = $db->escape_string($processor);
|
||||
}
|
||||
if (!empty($closed_at)) {
|
||||
$closed_at = $db->escape_string($closed_at);
|
||||
// Check if the closed_at date is in the correct format (YYYY-MM-DD HH:MM:SS)
|
||||
if (!preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $closed_at)) {
|
||||
throw new Exception('Closed at date is not in the correct format');
|
||||
}
|
||||
}
|
||||
// Require the customer number to be of a valid customer
|
||||
self::requireValidCustomer($customer_number);
|
||||
// Add the object
|
||||
$tmp_id = self::add_object([
|
||||
'customer_number' => (int)$customer_number,
|
||||
'name' => $name,
|
||||
'notes' => $notes
|
||||
'notes' => $notes,
|
||||
...(!empty($closed_at) ? ['closed_at' => (string)$closed_at] : []),
|
||||
]);
|
||||
self::select((int)$tmp_id);
|
||||
self::requireSelected();
|
||||
|
||||
Reference in New Issue
Block a user