diff --git a/classes/order/Order.php b/classes/order/Order.php index 79ba75e60..d5ec08a55 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -34,6 +34,10 @@ class OrderCore extends ObjectModel const ORDER_PAYMENT_TYPE_FULL = 1; const ORDER_PAYMENT_TYPE_ADVANCE = 2; + //Consts for: In the order list in which currency prices should be displayed + const ORDER_LIST_PRICE_DISPLAY_IN_PAYMENT_CURRENCY = 1; + const ORDER_LIST_PRICE_DISPLAY_IN_DEFAULT_CURRENCY = 2; + /** @var int Delivery address id */ public $id_address_delivery; @@ -1835,6 +1839,10 @@ class OrderCore extends ObjectModel } } + // Whenever payment is adding in any order then set a cumulative conversion rate for the payment currency in the order + $this->conversion_rate = $order_payment->getCumulativeConversionRate($this->reference, $this->id_currency); + $this->save(); + return $res; } @@ -2660,4 +2668,4 @@ class OrderCore extends ObjectModel { $this->transaction_id = $transactionId; } -} \ No newline at end of file +} diff --git a/classes/order/OrderPayment.php b/classes/order/OrderPayment.php index 247f981c1..bb8b8a5ec 100644 --- a/classes/order/OrderPayment.php +++ b/classes/order/OrderPayment.php @@ -148,4 +148,15 @@ class OrderPaymentCore extends ObjectModel return new OrderInvoice((int)$res); } + + /** + * Provides the cumulative conversion rate for a given order in any currency + * @param [string] $order_reference + * @param [int] $idCurrency + * @return float + */ + public function getCumulativeConversionRate($order_reference, $idCurrency) + { + return Db::getInstance()->getValue('SELECT (SUM(`conversion_rate`) / COUNT(*)) FROM `'._DB_PREFIX_.'order_payment` WHERE `order_reference` = \''.pSQL($order_reference).'\' AND `id_currency` = '.(int)$idCurrency); + } } diff --git a/controllers/admin/AdminOrderPreferencesController.php b/controllers/admin/AdminOrderPreferencesController.php index 21b31f6a7..d0be09ba2 100644 --- a/controllers/admin/AdminOrderPreferencesController.php +++ b/controllers/admin/AdminOrderPreferencesController.php @@ -58,6 +58,18 @@ class AdminOrderPreferencesControllerCore extends AdminController ) ); + // Options to display currency in order list + $displayCurrencyOptions = array( + array( + 'value' => Order::ORDER_LIST_PRICE_DISPLAY_IN_PAYMENT_CURRENCY, + 'name' => $this->l('Payment currency') + ), + array( + 'value' => Order::ORDER_LIST_PRICE_DISPLAY_IN_DEFAULT_CURRENCY, + 'name' => $this->l('Default currency') + ) + ); + $this->fields_options = array( 'order_restrict' => array( 'title' => $this->l('Order Restrict'), @@ -159,6 +171,15 @@ class AdminOrderPreferencesControllerCore extends AdminController 'cast' => 'intval', 'type' => 'bool' ), + 'PS_ORDER_LIST_PRICE_DISPLAY_CURRENCY' => array( + 'title' => $this->l('Display order list prices in'), + 'hint' => $this->l('Choose the currency in which you want the prices in the order list to be displayed.'), + 'validation' => 'isInt', + 'type' => 'select', + 'cast' => 'intval', + 'list' => $displayCurrencyOptions, + 'identifier' => 'value', + ), ), 'submit' => array('title' => $this->l('Save')) ), diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 63a271ecd..d1a9c1719 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -58,11 +58,14 @@ class AdminOrdersControllerCore extends AdminController $this->context = Context::getContext(); $this->_select = ' - (a.total_paid - a.total_paid_real) AS `amount_due`, a.source AS order_source, + IF('.((Configuration::get('PS_ORDER_LIST_PRICE_DISPLAY_CURRENCY') == Order::ORDER_LIST_PRICE_DISPLAY_IN_DEFAULT_CURRENCY)? 1 : 0).', (a.total_paid_tax_incl / a.conversion_rate), total_paid_tax_incl) AS total_paid_tax_incl, + IF('.((Configuration::get('PS_ORDER_LIST_PRICE_DISPLAY_CURRENCY') == Order::ORDER_LIST_PRICE_DISPLAY_IN_DEFAULT_CURRENCY)? 1 : 0).', ((a.total_paid - a.total_paid_real) / a.conversion_rate), (a.total_paid - a.total_paid_real)) AS amount_due, + a.source AS order_source, a.id_currency, a.id_order AS id_pdf, CONCAT(c.`firstname`, \' \', c.`lastname`) AS `customer`, osl.`name` AS `osname`, os.`color`, + cu.iso_code AS currency, IF((SELECT so.id_order FROM `'._DB_PREFIX_.'orders` so WHERE so.id_customer = a.id_customer AND so.id_order < a.id_order LIMIT 1) > 0, 0, 1) as new, IF(a.valid, 1, 0) badge_success, hbil.`hotel_name`, @@ -77,6 +80,7 @@ class AdminOrdersControllerCore extends AdminController $this->_join = ' LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = a.`id_customer`) + LEFT JOIN `'._DB_PREFIX_.'currency` cu ON (cu.`id_currency` = a.`id_currency`) LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = a.`current_state`) LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int) $this->context->language->id.') LEFT JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd ON (hbd.`id_order` = a.`id_order`) @@ -200,6 +204,11 @@ class AdminOrdersControllerCore extends AdminController 'payment' => array( 'title' => $this->l('Payment') ), + 'currency' => array( + 'title' => $this->l('Payment Currency'), + 'hint' => $this->l('This is the currency in which customer made the payment'), + 'havingFilter' => true, + ), 'osname' => array( 'title' => $this->l('Status'), 'type' => 'select', @@ -5494,4 +5503,4 @@ class AdminOrdersControllerCore extends AdminController } } } -} \ No newline at end of file +} diff --git a/install/data/xml/configuration.xml b/install/data/xml/configuration.xml index 935de20ba..f7814e17a 100644 --- a/install/data/xml/configuration.xml +++ b/install/data/xml/configuration.xml @@ -224,6 +224,9 @@ 3 + + 1 + 0 @@ -906,4 +909,4 @@ 1 - \ No newline at end of file +