diff --git a/services/nginx/app/modules/xlvask/helpers/xlvask_product_parser.php b/services/nginx/app/modules/xlvask/helpers/xlvask_product_parser.php index 1ff101c7..4109ad6a 100644 --- a/services/nginx/app/modules/xlvask/helpers/xlvask_product_parser.php +++ b/services/nginx/app/modules/xlvask/helpers/xlvask_product_parser.php @@ -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. diff --git a/services/nginx/app/modules/xlvask/helpers/xlvask_product_parser_t.php b/services/nginx/app/modules/xlvask/helpers/xlvask_product_parser_t.php index c77b8d62..199f0dde 100644 --- a/services/nginx/app/modules/xlvask/helpers/xlvask_product_parser_t.php +++ b/services/nginx/app/modules/xlvask/helpers/xlvask_product_parser_t.php @@ -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; - } \ No newline at end of file diff --git a/services/nginx/app/modules/xlvask/helpers/xlvask_wash_item.php b/services/nginx/app/modules/xlvask/helpers/xlvask_wash_item.php index 3d53e6af..02503b36 100644 --- a/services/nginx/app/modules/xlvask/helpers/xlvask_wash_item.php +++ b/services/nginx/app/modules/xlvask/helpers/xlvask_wash_item.php @@ -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; + } } \ No newline at end of file diff --git a/services/nginx/app/objects/orders_o.php b/services/nginx/app/objects/orders_o.php index d56f73f7..7ec806e6 100644 --- a/services/nginx/app/objects/orders_o.php +++ b/services/nginx/app/objects/orders_o.php @@ -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)