- Refactor machine_1 drawing logic: optimize highlighted button rendering and deferred processing.
- Add branding management feature: API routes, payload handling, and OpenAPI schema updates. - Implement department branding logic: CRUD operations, validation, and permissions. - Add order deletion confirmation support with conflict handling and OpenAPI schema updates. - Enhance tests and API methods for improved order handling and branding workflows.
This commit is contained in:
@@ -154,6 +154,80 @@ class orders_o extends db
|
||||
// Save the object
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the data needed to decide whether deletion needs explicit confirmation.
|
||||
*
|
||||
* @return array{
|
||||
* requires_confirmation: bool,
|
||||
* protected_reasons: array<int, string>,
|
||||
* order_item_count: int,
|
||||
* attachment_count: int,
|
||||
* completed_at: mixed
|
||||
* }
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getDeleteProtectionSummary(): array
|
||||
{
|
||||
self::requireSelected();
|
||||
|
||||
$completedAt = $this->completed_at->value();
|
||||
$orderItemCount = $this->countActiveOrderItems();
|
||||
$attachmentCount = $this->countActiveOrderAttachments();
|
||||
$protectedReasons = [];
|
||||
|
||||
if ($completedAt !== null) {
|
||||
$protectedReasons[] = 'completed';
|
||||
}
|
||||
if ($orderItemCount > 0) {
|
||||
$protectedReasons[] = 'order_items';
|
||||
}
|
||||
if ($attachmentCount > 0) {
|
||||
$protectedReasons[] = 'attachments';
|
||||
}
|
||||
|
||||
return [
|
||||
'requires_confirmation' => count($protectedReasons) > 0,
|
||||
'protected_reasons' => $protectedReasons,
|
||||
'order_item_count' => $orderItemCount,
|
||||
'attachment_count' => $attachmentCount,
|
||||
'completed_at' => $completedAt,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
private function countActiveOrderItems(): int
|
||||
{
|
||||
self::requireSelected();
|
||||
global $db;
|
||||
|
||||
$orderId = (int)$this->id;
|
||||
$result = $db->query("SELECT COUNT(*) AS total FROM order_items WHERE order_id = {$orderId} AND deleted_at IS NULL");
|
||||
if ($result && $row = $result->fetch_assoc()) {
|
||||
return (int)($row['total'] ?? 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
private function countActiveOrderAttachments(): int
|
||||
{
|
||||
self::requireSelected();
|
||||
global $db;
|
||||
|
||||
$orderId = (int)$this->id;
|
||||
$result = $db->query("SELECT COUNT(*) AS total FROM object_attachments WHERE object_type = 'orders' AND object_id = {$orderId} AND deleted_at IS NULL");
|
||||
if ($result && $row = $result->fetch_assoc()) {
|
||||
return (int)($row['total'] ?? 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception If the order is not selected
|
||||
* This function is called when the order object is changed.
|
||||
@@ -278,6 +352,7 @@ class orders_o extends db
|
||||
}
|
||||
// Set the completed_at property to the current timestamp
|
||||
$this->completed_at->set(date('Y-m-d H:i:s'));
|
||||
$this->setPendingHandheldIndicator(false);
|
||||
$washCertificateCreated = $this->completeWashCertificateIfNeeded(
|
||||
$operator,
|
||||
(string)$this->completed_at->value()
|
||||
|
||||
Reference in New Issue
Block a user