Add safety seal support to orders and related logic for wash certificates
- Introduced `safety_seal` column in the `orders` table. - Updated order creation and completion logic to handle safety seal values. - Enhanced order and booking classes to manage safety seal attachment and retrieval. - Added tests to validate safety seal functionality in order processing.
This commit is contained in:
@@ -159,6 +159,7 @@ class ordersRoute
|
||||
...(!empty($data['booking_id']) ? ['booking_id' => (int)$data['booking_id']] : []), // Optional booking ID
|
||||
'created_at' => $createdAt, // Default to current time if not set
|
||||
...(array_key_exists('include_in_invoice', $data) ? ['include_in_invoice' => $includeInInvoice] : []),
|
||||
...(array_key_exists('safety_seal', $data) ? ['safety_seal' => orders_o::normalizeSafetySealValue($data['safety_seal'])] : []),
|
||||
];
|
||||
// Create the order
|
||||
//$order = (new orders_o())->add((int)$data['customer_id'], $user->id, $data['reference'], $data['notes'], (int)$data['department_id'], (string)$reg_1, (string)$reg_2, (string)$reg_3);
|
||||
@@ -477,7 +478,7 @@ class ordersRoute
|
||||
$response->error('Order not found', 400);
|
||||
}
|
||||
// Mark the order as completed
|
||||
$order->markAsCompleted();
|
||||
$order->markAsCompleted((string)$user->display_name->value());
|
||||
// Log the incident
|
||||
(new logs_o())->add('orders', $order->department_id->value(), 1, $user->id, 'MARK_ORDER_AS_COMPLETED', 'Successfully marked an order as completed (ID: ' . $data['id'] . ')');
|
||||
// Return a success message
|
||||
@@ -518,7 +519,10 @@ class ordersRoute
|
||||
|
||||
$department = (new departments_o())->selectId((int)$order->department_id->value());
|
||||
if (!$department->isStripeConfigured()) {
|
||||
$response->error('Department is not configured for Stripe payments', 400);
|
||||
$response->error([
|
||||
'message' => 'Card payments are not ready for this department. Open Stripe setup and choose a terminal location.',
|
||||
'code' => 'stripe_terminal_setup_required',
|
||||
], 409);
|
||||
}
|
||||
|
||||
$readerId = trim((string)($data['reader'] ?? ''));
|
||||
@@ -970,6 +974,7 @@ class ordersRoute
|
||||
'po',
|
||||
'reference',
|
||||
'notes',
|
||||
'safety_seal',
|
||||
'reg_1',
|
||||
'reg_2',
|
||||
'reg_3',
|
||||
@@ -1003,6 +1008,9 @@ class ordersRoute
|
||||
if (isset($data['notes'])) {
|
||||
$order->notes->set((string)$data['notes']);
|
||||
}
|
||||
if (array_key_exists('safety_seal', $data)) {
|
||||
$order->setSafetySealValue($data['safety_seal']);
|
||||
}
|
||||
// Register the change
|
||||
$order->objectChanged();
|
||||
// Return a success message
|
||||
@@ -1042,6 +1050,9 @@ class ordersRoute
|
||||
if (isset($data['po'])) {
|
||||
$order->po->set((string)$data['po']);
|
||||
}
|
||||
if (array_key_exists('safety_seal', $data)) {
|
||||
$order->setSafetySealValue($data['safety_seal']);
|
||||
}
|
||||
// If the lane is set, validate it
|
||||
if (isset($data['lane'])) {
|
||||
$order->lane->set((int)$data['lane']);
|
||||
@@ -1108,7 +1119,7 @@ class ordersRoute
|
||||
}
|
||||
|
||||
$field = is_string($data['field']) ? trim($data['field']) : '';
|
||||
$allowedLegacyFields = ['reference', 'notes', 'reg_1', 'reg_2', 'reg_3'];
|
||||
$allowedLegacyFields = ['reference', 'notes', 'safety_seal', 'reg_1', 'reg_2', 'reg_3'];
|
||||
|
||||
if ($field === '' || !in_array($field, $allowedLegacyFields, true)) {
|
||||
$displayField = is_scalar($data['field']) || $data['field'] === null
|
||||
@@ -1200,6 +1211,7 @@ class ordersRoute
|
||||
$order['pending_handheld'] = (bool)($pendingHandheldByOrderId[$orderId] ?? false);
|
||||
$order['attachments'] = $attachmentsByOrderId[$orderId] ?? [];
|
||||
$order['po'] = $order['po'] ?? null;
|
||||
$order['safety_seal'] = $order['safety_seal'] ?? null;
|
||||
$order['lane'] = $order['lane'] ?? null;
|
||||
}
|
||||
unset($order);
|
||||
|
||||
Reference in New Issue
Block a user