Add unit tests for invoicing, orders normalization, gateway commands, and department complaints. Update schema bootstraps and improve agent command execution logic.
This commit is contained in:
@@ -363,7 +363,8 @@ class economic_v2_distribution_service
|
||||
$department_id = (int)$order['department_id'];
|
||||
$created_at = (string)$order['created_at'];
|
||||
|
||||
if (!$this->isDepartmentEligible($department_id)) {
|
||||
$order_is_included = $this->isOrderEligible($order);
|
||||
if (!$order_is_included) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -398,7 +399,7 @@ class economic_v2_distribution_service
|
||||
];
|
||||
}
|
||||
|
||||
$customers[$customer_number]['transactions'][] = $this->buildTransactionObject($order_id, $created_at, $department_id, $order_discount_total);
|
||||
$customers[$customer_number]['transactions'][] = $this->buildTransactionObject($order_id, $created_at, $department_id, $order_discount_total, $order_is_included);
|
||||
$customers[$customer_number]['meta']['customer_prices']['discount_total'] += $order_discount_total;
|
||||
if (!isset($customers[$customer_number]['meta']['customer_prices']['department_discount_totals'][$department_id])) {
|
||||
$customers[$customer_number]['meta']['customer_prices']['department_discount_totals'][$department_id] = 0.0;
|
||||
@@ -1044,7 +1045,7 @@ class economic_v2_distribution_service
|
||||
if (!$this->isSystemOrderCandidate($order, self::FIXED_PRICING_SYSTEM_ORDER_REFERENCE)) {
|
||||
continue;
|
||||
}
|
||||
} elseif (!$this->isDepartmentEligible($department_id)) {
|
||||
} elseif (!$this->isOrderEligible($order)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1087,7 +1088,13 @@ class economic_v2_distribution_service
|
||||
$groups[$group_key]['order_ids'][] = $order_id;
|
||||
|
||||
if (!isset($customer_transactions[$customer_number][$order_id])) {
|
||||
$customer_transactions[$customer_number][$order_id] = $this->buildTransactionObject($order_id, $created_at, $department_id);
|
||||
$customer_transactions[$customer_number][$order_id] = $this->buildTransactionObject(
|
||||
$order_id,
|
||||
$created_at,
|
||||
$department_id,
|
||||
null,
|
||||
$this->isOrderEligible($order)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1115,7 +1122,7 @@ class economic_v2_distribution_service
|
||||
if (!$this->isSystemOrderCandidate($order, self::WASH_SUBSCRIPTION_SYSTEM_ORDER_REFERENCE)) {
|
||||
continue;
|
||||
}
|
||||
} elseif (!$this->isDepartmentEligible($department_id)) {
|
||||
} elseif (!$this->isOrderEligible($order)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1179,7 +1186,13 @@ class economic_v2_distribution_service
|
||||
}
|
||||
|
||||
if ($matched_order && !isset($customer_transactions[$customer_number][$order_id])) {
|
||||
$customer_transactions[$customer_number][$order_id] = $this->buildTransactionObject($order_id, $created_at, $department_id);
|
||||
$customer_transactions[$customer_number][$order_id] = $this->buildTransactionObject(
|
||||
$order_id,
|
||||
$created_at,
|
||||
$department_id,
|
||||
null,
|
||||
$this->isOrderEligible($order)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1208,7 +1221,7 @@ class economic_v2_distribution_service
|
||||
global $db;
|
||||
$from = $db->escape_string($from_ts);
|
||||
$to = $db->escape_string($to_ts);
|
||||
$sql = "SELECT id, customer_id, department_id, created_at, reg_1, reference
|
||||
$sql = "SELECT id, customer_id, department_id, created_at, include_in_invoice, reg_1, reference
|
||||
FROM orders
|
||||
WHERE deleted_at IS NULL
|
||||
AND created_at >= '$from'
|
||||
@@ -1540,7 +1553,7 @@ class economic_v2_distribution_service
|
||||
];
|
||||
}
|
||||
|
||||
protected function buildTransactionObject(int $order_id, string $created_at, int $department_id, ?float $amount = null): array
|
||||
protected function buildTransactionObject(int $order_id, string $created_at, int $department_id, ?float $amount = null, ?bool $included = null): array
|
||||
{
|
||||
$order = (new orders_o())->select($order_id);
|
||||
return [
|
||||
@@ -1549,10 +1562,25 @@ class economic_v2_distribution_service
|
||||
'amount' => round((float)($amount ?? (float)$order->getNetAmount()), 5),
|
||||
'booked' => $order->isBooked(true),
|
||||
'department_id' => $department_id,
|
||||
'excluded' => !$this->isDepartmentEligible($department_id),
|
||||
'excluded' => !($included ?? $this->isDepartmentEligible($department_id)),
|
||||
];
|
||||
}
|
||||
|
||||
protected function isOrderEligible(array $order): bool
|
||||
{
|
||||
$department_id = (int)($order['department_id'] ?? 0);
|
||||
if ($department_id === self::SYSTEM_ORDER_DEPARTMENT_ID || $department_id <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$override = orders_o::normalizeNullableBooleanValue($order['include_in_invoice'] ?? null);
|
||||
if ($override !== null) {
|
||||
return $override;
|
||||
}
|
||||
|
||||
return $this->isDepartmentEligible($department_id);
|
||||
}
|
||||
|
||||
private function getCustomerName(int $customer_number): string
|
||||
{
|
||||
if (!isset($this->customer_name_cache[$customer_number])) {
|
||||
|
||||
Reference in New Issue
Block a user