Add useDynamicPricing property and getUnitPriceExVat method in XLVask helpers. Refactor parsing logic to use integer type casting for price and count.

This commit is contained in:
Jepp9350
2025-06-24 09:16:03 +02:00
parent dacb7ef4e0
commit c0ff18761d
4 changed files with 24 additions and 4 deletions
@@ -8,6 +8,7 @@ abstract class xlvask_product_parser
{
use xlvask_product_parser_t;
/**
* The setup method initializes the Original Product Name.
* This is required for the parser to function correctly.
@@ -8,6 +8,20 @@ use objects\products_o;
trait xlvask_product_parser_t
{
protected string $OriginalProductName;
/**
* This property indicates whether the parser is dynamic.
* When set to true, the parser will handle dynamic pricing.
* This should be set to true if the pricing of the product can change based on certain conditions,
* such as the amount of usage, time of day, or other factors.
* When this is set to true, the parser should implement logic to handle dynamic pricing.
* @example
* The "flowmeter" product parser uses this to calculate the price based on the amount of water used.
* * @note This is used to determine whether the parser should calculate a dynamic price or a static price.
* @see xlvask_product_parser_t::calculateDynamicPrice()
* When this is set to false, the parser should return a static price. (amount x price per unit)
* @var bool $useDynamicPricing
*/
protected bool $useDynamicPricing = false;
/**
@@ -40,5 +54,4 @@ trait xlvask_product_parser_t
*/
abstract protected function parse(xlvask_wash_item $wash_item, xlvask_usage_log $xlvask_usage_log): products_o;
}
@@ -229,7 +229,7 @@ class xlvask_wash_item extends xlvask_helper
// Check if the parameter is empty or matches the default values
return $param === null || $param === '' || $param === $this->default_string || $param === $this->default_int || $param === $this->default_bool || $param === $this->default_int_nullable || $param === $this->default_string_nullable || $param === $this->default_bool_nullable;
}
/**
* Get the product associated with this wash item.
@@ -352,4 +352,10 @@ class xlvask_wash_item extends xlvask_helper
// If either PriceIncVat or Count is not numeric, return 0
return 0.0;
}
public function getUnitPriceExVat(): float
{
// Calculate the unit price excluding VAT
return $this->getPriceExVat() / (float)$this->Count;
}
}
+2 -2
View File
@@ -754,8 +754,8 @@ class orders_o extends db
'',
'', //$washItem->OriginalProductName,
2285,
$washItem->getPriceExVat(),
$washItem->Count,
(int)$washItem->getUnitPriceExVat(),
(int)$washItem->Count,
$firstItemId === null ? null : $firstItemId, // Set the first item as the parent item (if applicable)
);
// Set the first item ID for the next item to link to (provided this is the first item)