Remove outdated edge gateway object classes, add new agent implementation
Transitioned from obsolete gateway object classes (`edge_gateway_shell_action_jobs_o`, `edge_gateway_shell_events_o`, `edge_gateway_shell_sessions_o`, `edge_gateway_update_jobs_o`) to the new agent implementation (`edge-gateway-agent/agent.php`).
This commit is contained in:
@@ -318,6 +318,16 @@ class orders_o extends db
|
||||
self::objectChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function clearStripeInvoicing(): void
|
||||
{
|
||||
self::requireSelected();
|
||||
$this->stripe_module_orders->clear();
|
||||
self::objectChanged();
|
||||
}
|
||||
|
||||
public function addArray(array $order_array): orders_o
|
||||
{
|
||||
global $db, $response;
|
||||
@@ -375,10 +385,11 @@ class orders_o extends db
|
||||
* @param int|null $invoiceCollectionId The invoice collection id, if not set, the default invoice collection id will be used.
|
||||
* @throws Exception If the order is not selected
|
||||
*/
|
||||
public function assignToInvoiceCollection(int $invoiceCollectionId = null): void
|
||||
public function assignToInvoiceCollection(int $invoiceCollectionId = null, bool $notifyChanges = true): void
|
||||
{
|
||||
// If the invoice collection id is not set, get the default invoice collection id
|
||||
self::requireSelected();
|
||||
$previousInvoiceCollectionId = (int)$this->invoice_collection_id->value();
|
||||
// Get the customer
|
||||
$customer = new users_o();
|
||||
$customer_id = (int)$this->customer_id->value();
|
||||
@@ -391,7 +402,16 @@ class orders_o extends db
|
||||
$invoiceCollectionId = $invoiceCollectionId ?? $customer->getNewOrderInvoiceCollectionId();
|
||||
// Assign the order to the invoice collection
|
||||
$this->invoice_collection_id->set($invoiceCollectionId);
|
||||
self::objectChanged();
|
||||
if ($previousInvoiceCollectionId > 0 && $previousInvoiceCollectionId !== (int)$invoiceCollectionId) {
|
||||
$previousCollection = new collected_order_invoices_o();
|
||||
$previousCollection->select($previousInvoiceCollectionId);
|
||||
if ($previousCollection->exists()) {
|
||||
$previousCollection->objectChanged();
|
||||
}
|
||||
}
|
||||
if ($notifyChanges) {
|
||||
self::objectChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1378,14 +1398,91 @@ class orders_o extends db
|
||||
public function hasWashCertificateAttached(): bool
|
||||
{
|
||||
self::requireSelected();
|
||||
// Check if the order has a wash certificate attached
|
||||
$attachments = $this->listAttachments();
|
||||
foreach ( $attachments as $attachment ) {
|
||||
if ($attachment->isWashCertificate()) {
|
||||
return true; // Wash certificate found
|
||||
return $this->listWashCertificateAttachmentIds() !== [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int[]
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function listWashCertificateAttachmentIds(): array
|
||||
{
|
||||
self::requireSelected();
|
||||
|
||||
global $db;
|
||||
|
||||
$rawObjectType = trim((string)$this->table, '`');
|
||||
$objectTypes = array_values(array_unique([
|
||||
$db->escape_string($rawObjectType),
|
||||
$db->escape_string('`' . $rawObjectType . '`'),
|
||||
]));
|
||||
$quotedObjectTypes = "'" . implode("','", $objectTypes) . "'";
|
||||
$objectId = (int)$this->id;
|
||||
$sql = "SELECT id, content
|
||||
FROM object_attachments
|
||||
WHERE object_type IN ($quotedObjectTypes)
|
||||
AND object_id = $objectId
|
||||
AND deleted_at IS NULL";
|
||||
$result = $db->query($sql);
|
||||
if (!$result) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$attachmentIds = [];
|
||||
while ($row = $db->fetch_assoc($result)) {
|
||||
$content = json_decode((string)($row['content'] ?? ''), true);
|
||||
$other = is_array($content) ? ($content['other'] ?? null) : null;
|
||||
if (is_string($other) && strtolower($other) === 'wash_certificate') {
|
||||
$attachmentIds[] = (int)($row['id'] ?? 0);
|
||||
}
|
||||
}
|
||||
return false; // No wash certificate product found in the order items
|
||||
|
||||
return array_values(array_filter($attachmentIds, static fn(int $id): bool => $id > 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function regenerateAttachedWashCertificate(): bool
|
||||
{
|
||||
self::requireSelected();
|
||||
if (!$this->hasWashCertificateAttached()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->removeAttachedWashCertificates();
|
||||
$this->generateWashCertificate(
|
||||
$this->getSafetySealValue(),
|
||||
$this->resolveWashCertificateOperator(),
|
||||
$this->resolveWashCertificateDate()
|
||||
);
|
||||
|
||||
return $this->hasWashCertificateAttached();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function removeAttachedWashCertificates(): int
|
||||
{
|
||||
self::requireSelected();
|
||||
|
||||
$attachmentIds = $this->listWashCertificateAttachmentIds();
|
||||
if ($attachmentIds === []) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
global $db;
|
||||
|
||||
$escapedIds = array_map(static fn(int $id): int => (int)$id, $attachmentIds);
|
||||
$idList = implode(',', $escapedIds);
|
||||
$sql = "UPDATE object_attachments
|
||||
SET deleted_at = NOW()
|
||||
WHERE id IN ($idList)
|
||||
AND deleted_at IS NULL";
|
||||
$db->query($sql);
|
||||
|
||||
return count($escapedIds);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1439,6 +1536,42 @@ class orders_o extends db
|
||||
return self::normalizeSafetySealValue($this->safety_seal->value());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function resolveWashCertificateOperator(): ?string
|
||||
{
|
||||
self::requireSelected();
|
||||
|
||||
$cashierId = (int)$this->cashier_id->value();
|
||||
if ($cashierId <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$cashier = (new users_o())->select($cashierId);
|
||||
if (!$cashier->exists()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$displayName = trim((string)$cashier->display_name->value());
|
||||
return $displayName === '' ? null : $displayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function resolveWashCertificateDate(): string
|
||||
{
|
||||
self::requireSelected();
|
||||
|
||||
$candidate = $this->completed_at->value() ?: $this->created_at->value();
|
||||
if (is_string($candidate) && trim($candidate) !== '') {
|
||||
return $candidate;
|
||||
}
|
||||
|
||||
return date('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
@@ -1482,17 +1615,27 @@ class orders_o extends db
|
||||
if (!$department->exists()) {
|
||||
throw new Exception('Department not found');
|
||||
}
|
||||
// Get branding for the department
|
||||
$branding = (new branding_o())->select((int)$department->branding->value());
|
||||
if (!$branding->exists()) {
|
||||
throw new Exception('Branding not found');
|
||||
// Branding is optional; fall back to the department values when it is not configured.
|
||||
$branding = null;
|
||||
$brandingId = (int)($department->branding->value() ?? 0);
|
||||
if ($brandingId > 0) {
|
||||
$selectedBranding = (new branding_o())->select($brandingId);
|
||||
if ($selectedBranding->exists()) {
|
||||
$branding = $selectedBranding;
|
||||
}
|
||||
}
|
||||
// Get the customer for the order
|
||||
$customer = (new users_o())->getUserByCustomerNumber((int)$this->customer_id->value());
|
||||
$department_array = $department->asArray();
|
||||
$department_array['branding'] = $branding->asArray();
|
||||
$customer_array = $customer->asArray();
|
||||
$order_array = $this->asArray();
|
||||
$branding_array = $branding?->asArray() ?? [];
|
||||
$customer_number = (int)$customer->customer_number->value();
|
||||
$customer_name = trim((string)$customer->display_name->value());
|
||||
if ($customer_name === '') {
|
||||
$customer_name = (string)($customer_number > 0 ? $customer_number : $this->customer_id->value());
|
||||
}
|
||||
|
||||
$customer_address = '-';
|
||||
// Format the date as 17:35 02-12-2025
|
||||
$date = ($date instanceof DateTime ? $date : ($date !== null ? new DateTime($date) : new DateTime()));
|
||||
$date_formatted = ($date instanceof DateTime ? $date->format('d-m-Y') : date('d-m-Y'));
|
||||
@@ -1526,10 +1669,10 @@ class orders_o extends db
|
||||
'time' => $time_formatted,
|
||||
'carried_out_by' => ($operator ?? null),
|
||||
'department_id' => $department->id,
|
||||
'department_name' => $department_array['branding']['name'] ?: $department_array['name'],
|
||||
'department_address' => $department_array['branding']['address'] ?: $department_array['description'],
|
||||
'customer_name' => $customer->getCustomerName($customer_array['customer_number']),
|
||||
'customer_address' => $customer->getCustomerEcocomicData($customer_array['customer_number'])->economic_customer->address ?: '-',
|
||||
'department_name' => ($branding_array['name'] ?? null) ?: $department_array['name'],
|
||||
'department_address' => ($branding_array['address'] ?? null) ?: $department_array['description'],
|
||||
'customer_name' => $customer_name,
|
||||
'customer_address' => $customer_address,
|
||||
'wash_type' => 'ORDER_WASH'
|
||||
])
|
||||
->getHtml()
|
||||
|
||||
Reference in New Issue
Block a user