From f98ba4fad250774f220a2e5e25e7a157a5124f52 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Thu, 30 Nov 2023 15:18:16 +0530 Subject: [PATCH] Fix currency conversion in admin statas page --- classes/order/Order.php | 6 +++++- modules/statsbestcategories/statsbestcategories.php | 2 +- modules/statsbestcustomers/statsbestcustomers.php | 3 +-- modules/statsbestproducts/statsbestproducts.php | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/classes/order/Order.php b/classes/order/Order.php index 79ba75e60..ef8d66f2a 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -1815,7 +1815,11 @@ class OrderCore extends ObjectModel $order_payment->order_reference = $this->reference; $order_payment->id_currency = ($currency ? $currency->id : $this->id_currency); // we kept the currency rate for historization reasons - $order_payment->conversion_rate = ($currency ? $currency->conversion_rate : 1); + $order_payment->conversion_rate = ( + $currency ? + $currency->conversion_rate : + (new Currency($this->id_currency))->getConversationRate() + ); // if payment_method is define, we used this $order_payment->payment_method = ($payment_method ? $payment_method : $this->payment); $order_payment->payment_type = ($payment_type ? $payment_type : $this->payment_type); diff --git a/modules/statsbestcategories/statsbestcategories.php b/modules/statsbestcategories/statsbestcategories.php index 1b6feb710..a4371a847 100644 --- a/modules/statsbestcategories/statsbestcategories.php +++ b/modules/statsbestcategories/statsbestcategories.php @@ -195,7 +195,7 @@ class StatsBestCategories extends ModuleGrid AND hbd.`date_to` > "'.pSQL($date_from).'" AND hbd.`date_from` < "'.pSQL($date_to).'" ) AS totalOrders, ( - SELECT IFNULL(SUM(ROUND((DATEDIFF(LEAST(hbd.`date_to`, "'.pSQL($date_to).'"), GREATEST(hbd.`date_from`, "'.pSQL($date_from).'")) / DATEDIFF(hbd.`date_to`, hbd.`date_from`)) * hbd.`total_price_tax_excl`, 2)), 0) + SELECT IFNULL(SUM(ROUND((DATEDIFF(LEAST(hbd.`date_to`, "'.pSQL($date_to).'"), GREATEST(hbd.`date_from`, "'.pSQL($date_from).'")) / DATEDIFF(hbd.`date_to`, hbd.`date_from`)) * (hbd.`total_price_tax_excl` / o.`conversion_rate`), 2)), 0) FROM `'._DB_PREFIX_.'htl_booking_detail` hbd LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = hbd.`id_order`) diff --git a/modules/statsbestcustomers/statsbestcustomers.php b/modules/statsbestcustomers/statsbestcustomers.php index 56c672e7e..1386b1c0c 100644 --- a/modules/statsbestcustomers/statsbestcustomers.php +++ b/modules/statsbestcustomers/statsbestcustomers.php @@ -153,10 +153,9 @@ class StatsBestCustomers extends ModuleGrid $this->query = 'SELECT SQL_CALC_FOUND_ROWS c.`id_customer`, c.`lastname`, c.`firstname`, c.`email`, COUNT(co.`id_connections`) as totalVisits, IFNULL(( - SELECT ROUND(SUM(IFNULL(op.`amount`, 0) / cu.conversion_rate), 2) + SELECT ROUND(SUM(IFNULL(op.`amount`, 0) / o.`conversion_rate`), 2) FROM `'._DB_PREFIX_.'orders` o LEFT JOIN `'._DB_PREFIX_.'order_payment` op ON o.reference = op.order_reference - LEFT JOIN `'._DB_PREFIX_.'currency` cu ON o.id_currency = cu.id_currency WHERE o.id_customer = c.id_customer AND o.invoice_date BETWEEN '.$this->getDate().' AND o.valid diff --git a/modules/statsbestproducts/statsbestproducts.php b/modules/statsbestproducts/statsbestproducts.php index fbfff36f1..7fbb37087 100644 --- a/modules/statsbestproducts/statsbestproducts.php +++ b/modules/statsbestproducts/statsbestproducts.php @@ -179,7 +179,7 @@ class StatsBestProducts extends ModuleGrid AND hbd.`date_to` > "'.pSQL($date_from).'" AND hbd.`date_from` < "'.pSQL($date_to).'" ) AS sellingPrice, ( - SELECT IFNULL(SUM(ROUND((DATEDIFF(LEAST(hbd.`date_to`, "'.pSQL($date_to).'"), GREATEST(hbd.`date_from`, "'.pSQL($date_from).'")) / DATEDIFF(hbd.`date_to`, hbd.`date_from`)) * hbd.`total_price_tax_excl`, 2)), 0) + SELECT IFNULL(SUM(ROUND((DATEDIFF(LEAST(hbd.`date_to`, "'.pSQL($date_to).'"), GREATEST(hbd.`date_from`, "'.pSQL($date_from).'")) / DATEDIFF(hbd.`date_to`, hbd.`date_from`)) * (hbd.`total_price_tax_excl` / o.`conversion_rate`) , 2)), 0) FROM `'._DB_PREFIX_.'htl_booking_detail` hbd LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = hbd.`id_order`)