Enhance orders_o and InvoicingPeriodRoute: expand duplicate detection logic by including additional registration fields, refine duplicate filtering criteria, and update transaction handling flag for possible duplicates. Add new xlvask_parser_ikke_ht_dysebom_mellom_bil_trailer parser and integrate it into xlvask_helpers.

This commit is contained in:
Jepp9350
2025-07-06 13:38:34 +02:00
parent 112f28228d
commit 7a8edd0f28
4 changed files with 37 additions and 5 deletions
@@ -0,0 +1,26 @@
<?php
namespace helpers;
use Exception;
use objects\products_o;
class xlvask_parser_ikke_ht_dysebom_mellom_bil_trailer extends xlvask_product_parser
{
use xlvask_product_parser_t;
public function __construct()
{
$this->setup('ikke_ht_dysebom_mellom_bil_trailer');
}
/**
* @inheritDoc
* @throws Exception
*/
protected function parse(xlvask_wash_item $wash_item, xlvask_usage_log $xlvask_usage_log): products_o
{
return (new products_o())->select(64); // Irrelevant product ID
}
}
@@ -50,6 +50,7 @@ require_once WD . '/modules/xlvask/helpers/xlvask_parser_ikke_ht_dysebom_p_tag.p
require_once WD . '/modules/xlvask/helpers/xlvask_parser_ht_osc_sider.php';
require_once WD . '/modules/xlvask/helpers/xlvask_parser_kun_b_rster_ved_hytten.php';
require_once WD . '/modules/xlvask/helpers/xlvask_parser_h_nger.php';
require_once WD . '/modules/xlvask/helpers/xlvask_parser_ikke_ht_dysebom_mellom_bil_trailer.php';
use helpers\xlvask_cache;
use helpers\xlvask_create_customer;
+9 -4
View File
@@ -971,7 +971,7 @@ class orders_o extends db
// Prepare the SQL query to find orders with possible duplicates in the date range
$dateFrom = $db->escape_string($dateFrom);
$dateTo = $db->escape_string($dateTo);
$sql = "SELECT id, customer_id, reg_1, created_at FROM $this->table WHERE created_at BETWEEN '$dateFrom' AND '$dateTo' AND deleted_at IS NULL";
$sql = "SELECT id, customer_id, reg_1, reg_2, reg_3, created_at FROM $this->table WHERE created_at BETWEEN '$dateFrom' AND '$dateTo' AND deleted_at IS NULL";
$result = $db->query($sql);
if ($result->num_rows === 0) {
return []; // No orders found in the date range
@@ -981,30 +981,35 @@ class orders_o extends db
$tmp = [
'id' => (int)$row['id'],
'reg_1' => (string)$row['reg_1'],
'reg_2' => (string)$row['reg_2'] ?? '',
'reg_3' => (string)$row['reg_3'] ?? '',
'created_at' => (string)$row['created_at'],
];
// Add the order to the list
$orders[$tmp['reg_1']][] = [
'id' => $tmp['id'],
'reg_1' => $tmp['reg_1'],
'reg_2' => (string)$row['reg_2'] ?? '',
'reg_3' => (string)$row['reg_3'] ?? '',
'created_at' => $tmp['created_at'],
'object' => (new orders_o())->select((int)$tmp['id'])
];
}
// Filter out orders with more than one entry for the same registration number (in a 24 hour period)
// Filter out orders with more than one entry for the same registration numbers (in a 24 hour period)
$possibleDuplicates = [];
// Loop through the registration numbers
foreach ( $orders as $reg_1 => $orderList ) {
// If there are more than one order for the same registration number, add it to the possible duplicates
if (count($orderList) > 1) {
// Loop through the orders and check if they are within 24 hours of each other
$filteredOrders = [];
foreach ( $orderList as $order ) {
// Check if the order is within 24 hours of the first order
// Check if the order is within 24 hours of the previous order (if any)
if (empty($filteredOrders)) {
$filteredOrders[] = $order; // Add the first order
} else {
// Check if the order is within 24 hours of the first order
// Check if the order is within 24 hours of the previous order
$firstOrderTime = strtotime($filteredOrders[0]['created_at']);
$currentOrderTime = strtotime($order['created_at']);
if ($currentOrderTime - $firstOrderTime <= 86400) { // 86400 seconds = 24 hours
@@ -500,7 +500,7 @@ class InvoicingPeriodRoute
// Construct the transaction object from the order
return $transaction['object'];
}, $order),
true, // Requires action because there are possible duplicates
false, // Requires action because there are possible duplicates
$customer['id'] ?? null // Use the id from the customer object if available
);
}