Fixed: review changes
This commit is contained in:
@@ -453,22 +453,6 @@ class CurrencyCore extends ObjectModel
|
||||
return self::$currencies[(int)($id)];
|
||||
}
|
||||
|
||||
/**
|
||||
* SQL expression giving the current rate of an order's currency relative to the default currency.
|
||||
* Reports divide order-currency amounts by it to express them in the default currency.
|
||||
*
|
||||
* @param string $orderAlias alias of the orders table in the query
|
||||
* @return string
|
||||
*/
|
||||
public static function getReportConversionRateSql($orderAlias = 'o')
|
||||
{
|
||||
$orderAlias = bqSQL($orderAlias);
|
||||
|
||||
return 'IFNULL((SELECT IF(cur_rate.`id_currency` = '.(int) Configuration::get('PS_CURRENCY_DEFAULT').', 1, NULLIF(cur_rate.`conversion_rate`, 0))
|
||||
FROM `'._DB_PREFIX_.'currency` cur_rate
|
||||
WHERE cur_rate.`id_currency` = '.$orderAlias.'.`id_currency`), 1)';
|
||||
}
|
||||
|
||||
public function getConversationRate()
|
||||
{
|
||||
return $this->id != (int)Configuration::get('PS_CURRENCY_DEFAULT') ? $this->conversion_rate : 1;
|
||||
|
||||
@@ -643,8 +643,8 @@ class CustomerCore extends ObjectModel
|
||||
public function getStats()
|
||||
{
|
||||
$result = Db::getInstance()->getRow('
|
||||
SELECT COUNT(`id_order`) AS nb_orders, SUM(`total_paid` / '.Currency::getReportConversionRateSql('o').') AS total_orders,
|
||||
SUM(o.`total_paid_real` / '.Currency::getReportConversionRateSql('o').') AS total_spent
|
||||
SELECT COUNT(`id_order`) AS nb_orders, SUM(`total_paid` / o.`conversion_rate`) AS total_orders,
|
||||
SUM(o.`total_paid_real` / o.`conversion_rate`) AS total_spent
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
WHERE o.`id_customer` = '.(int)$this->id.'
|
||||
AND o.valid = 1');
|
||||
|
||||
@@ -3286,17 +3286,17 @@ class OrderCore extends ObjectModel
|
||||
'SELECT o.`id_order`, o.`reference`, o.`id_customer`,
|
||||
CONCAT(c.`firstname`, " ", c.`lastname`) AS customer_name,
|
||||
c.`email`, a.`phone`,
|
||||
o.`total_paid_tax_incl` / '.Currency::getReportConversionRateSql('o').' AS total_charges,
|
||||
o.`total_paid_tax_incl` / o.`conversion_rate` AS total_charges,
|
||||
IFNULL((
|
||||
SELECT SUM(op.`amount`)
|
||||
FROM `'._DB_PREFIX_.'order_payment` op
|
||||
WHERE op.`order_reference` = o.`reference`
|
||||
), 0) / '.Currency::getReportConversionRateSql('o').' AS total_paid,
|
||||
), 0) / o.`conversion_rate` AS total_paid,
|
||||
(o.`total_paid_tax_incl` - IFNULL((
|
||||
SELECT SUM(op.`amount`)
|
||||
FROM `'._DB_PREFIX_.'order_payment` op
|
||||
WHERE op.`order_reference` = o.`reference`
|
||||
), 0)) / '.Currency::getReportConversionRateSql('o').' AS balance_due,
|
||||
), 0)) / o.`conversion_rate` AS balance_due,
|
||||
(
|
||||
SELECT MAX(op.`date_add`)
|
||||
FROM `'._DB_PREFIX_.'order_payment` op
|
||||
@@ -3335,7 +3335,7 @@ class OrderCore extends ObjectModel
|
||||
.')';
|
||||
|
||||
return (float) Db::getInstance()->getValue(
|
||||
'SELECT IFNULL(SUM(o.`total_discounts_tax_excl` / '.Currency::getReportConversionRateSql('o').'), 0)
|
||||
'SELECT IFNULL(SUM(o.`total_discounts_tax_excl` / o.`conversion_rate`), 0)
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
WHERE o.`valid` = 1
|
||||
AND o.`date_add` BETWEEN "'.$dateFrom.' 00:00:00" AND "'.$dateTo.' 23:59:59"'
|
||||
@@ -3371,8 +3371,8 @@ class OrderCore extends ObjectModel
|
||||
st.`name` AS state,
|
||||
COUNT(DISTINCT o.`id_order`) AS total_stays,
|
||||
SUM(DATEDIFF(hbd.`date_to`, hbd.`date_from`)) AS total_nights,
|
||||
IFNULL(SUM(hbd.`total_price_tax_incl` / '.Currency::getReportConversionRateSql('o').'), 0) AS lifetime_revenue,
|
||||
IFNULL(SUM(hbd.`total_price_tax_incl` / '.Currency::getReportConversionRateSql('o').') / NULLIF(COUNT(DISTINCT o.`id_order`), 0), 0) AS avg_spend_per_stay,
|
||||
IFNULL(SUM(hbd.`total_price_tax_incl` / o.`conversion_rate`), 0) AS lifetime_revenue,
|
||||
IFNULL(SUM(hbd.`total_price_tax_incl` / o.`conversion_rate`) / NULLIF(COUNT(DISTINCT o.`id_order`), 0), 0) AS avg_spend_per_stay,
|
||||
MAX(hbd.`date_from`) AS last_stay
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
INNER JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = o.`id_customer`)
|
||||
|
||||
@@ -226,7 +226,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
if ($granularity == 'day') {
|
||||
$sales = array();
|
||||
if ($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(
|
||||
'SELECT LEFT(`invoice_date`, 10) AS date, SUM(total_paid_tax_excl / '.Currency::getReportConversionRateSql('o').') AS sales
|
||||
'SELECT LEFT(`invoice_date`, 10) AS date, SUM(total_paid_tax_excl / o.`conversion_rate`) AS sales
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON o.current_state = os.id_order_state
|
||||
WHERE os.logable = 1'. (($date_from && $date_to) ? ' AND `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59"' : '').'
|
||||
@@ -255,7 +255,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
} elseif ($granularity == 'month') {
|
||||
$sales = array();
|
||||
if ($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(
|
||||
'SELECT LEFT(`invoice_date`, 7) AS date, SUM(total_paid_tax_excl / '.Currency::getReportConversionRateSql('o').') AS sales
|
||||
'SELECT LEFT(`invoice_date`, 7) AS date, SUM(total_paid_tax_excl / o.`conversion_rate`) AS sales
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON o.current_state = os.id_order_state
|
||||
WHERE os.logable = 1'. (($date_from && $date_to) ? ' AND `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59"' : '').'
|
||||
@@ -285,7 +285,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
return $sales;
|
||||
} else {
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(
|
||||
'SELECT SUM(total_paid_tax_excl / '.Currency::getReportConversionRateSql('o').'), t.`id_hotel`
|
||||
'SELECT SUM(total_paid_tax_excl / o.`conversion_rate`), t.`id_hotel`
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON o.current_state = os.id_order_state
|
||||
LEFT JOIN (
|
||||
@@ -466,7 +466,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
LEFT JOIN (
|
||||
SELECT pr.`id_product`,
|
||||
IFNULL(SUM(cp.`product_quantity`), 0) AS totalQuantitySold,
|
||||
IFNULL(SUM(cp.`product_price` * cp.`product_quantity`), 0) / '.Currency::getReportConversionRateSql('o').' AS totalPriceSold
|
||||
IFNULL(SUM(cp.`product_price` * cp.`product_quantity`), 0) / o.`conversion_rate` AS totalPriceSold
|
||||
FROM `'._DB_PREFIX_.'product` pr
|
||||
LEFT OUTER JOIN `'._DB_PREFIX_.'order_detail` cp ON pr.`id_product` = cp.`product_id`
|
||||
LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = cp.`id_order`
|
||||
@@ -712,8 +712,8 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
$orders = Db::getInstance()->ExecuteS('
|
||||
SELECT
|
||||
LEFT(`invoice_date`, 10) as date,
|
||||
total_paid_tax_incl / '.Currency::getReportConversionRateSql('o').' as total_paid_tax_incl,
|
||||
total_shipping_tax_excl / '.Currency::getReportConversionRateSql('o').' as total_shipping_tax_excl,
|
||||
total_paid_tax_incl / o.`conversion_rate` as total_paid_tax_incl,
|
||||
total_shipping_tax_excl / o.`conversion_rate` as total_shipping_tax_excl,
|
||||
o.module,
|
||||
ad.id_country,
|
||||
o.id_currency,
|
||||
@@ -996,7 +996,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT
|
||||
COUNT(o.`id_order`) as orders,
|
||||
SUM(o.`total_paid_tax_excl` / '.Currency::getReportConversionRateSql('o').') as total_paid_tax_excl
|
||||
SUM(o.`total_paid_tax_excl` / o.`conversion_rate`) as total_paid_tax_excl
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON os.`id_order_state` = o.`current_state`
|
||||
WHERE o.`invoice_date` BETWEEN "'.pSQL($dateFrom).' 00:00:00"
|
||||
@@ -1647,7 +1647,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
public static function getRevenue($dateFrom, $dateTo, $idHotel = false, $orderSource = '')
|
||||
{
|
||||
$sql = 'SELECT SUM(total_paid_tax_excl - refunded_amount)
|
||||
FROM (SELECT o.`total_paid_tax_excl` / '.Currency::getReportConversionRateSql('o').' AS total_paid_tax_excl,
|
||||
FROM (SELECT o.`total_paid_tax_excl` / o.`conversion_rate` AS total_paid_tax_excl,
|
||||
(SELECT IFNULL(SUM(orr.`refunded_amount`), 0) FROM`'._DB_PREFIX_.'order_return` orr WHERE orr.`id_order` = o.`id_order`) AS refunded_amount,
|
||||
(SELECT hbd.`id_hotel` FROM`'._DB_PREFIX_.'htl_booking_detail` hbd WHERE hbd.`id_order` = o.`id_order` LIMIT 1) AS id_hotel
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
@@ -1891,7 +1891,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
$cacheKey = 'AdminStats::getRoomsRevenueForDiscreteDates'.'_'.(int) $discreteDate['timestamp_from'].'_'.
|
||||
(!is_array($idHotel) ? (int) $idHotel : implode('_', $idHotel));
|
||||
if (!Cache::isStored($cacheKey) || !$useCache) {
|
||||
$sql = 'SELECT IFNULL(SUM((hbd.`total_price_tax_excl` / '.Currency::getReportConversionRateSql('o').') / DATEDIFF(hbd.`date_to`, hbd.`date_from`)), 0)
|
||||
$sql = 'SELECT IFNULL(SUM((hbd.`total_price_tax_excl` / o.`conversion_rate`) / DATEDIFF(hbd.`date_to`, hbd.`date_from`)), 0)
|
||||
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = hbd.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = hbd.`id_order`)
|
||||
@@ -1932,7 +1932,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
foreach ($discreteDates as $discreteDate) {
|
||||
$totalServicesRevenue = 0;
|
||||
// Calculate services revenue
|
||||
$servicesRevenueSql = 'SELECT SUM((rtspod.`total_price_tax_excl` / '.Currency::getReportConversionRateSql('o').') / DATEDIFF(hbd.`date_to`, hbd.`date_from`))
|
||||
$servicesRevenueSql = 'SELECT SUM((rtspod.`total_price_tax_excl` / o.`conversion_rate`) / DATEDIFF(hbd.`date_to`, hbd.`date_from`))
|
||||
FROM `'._DB_PREFIX_.'service_product_order_detail` rtspod
|
||||
LEFT JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
ON (rtspod.`id_htl_booking_detail` = hbd.`id`)
|
||||
@@ -2384,7 +2384,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
WHEN od.`purchase_supplier_price` <> "0.000000"
|
||||
THEN od.`purchase_supplier_price`
|
||||
WHEN od.`purchase_supplier_price` = "0.000000"
|
||||
THEN (od.`original_product_price` / '.Currency::getReportConversionRateSql('o').') * '.(int)Configuration::get('CONF_AVERAGE_PRODUCT_MARGIN').' / 100
|
||||
THEN (od.`original_product_price` / o.`conversion_rate`) * '.(int)Configuration::get('CONF_AVERAGE_PRODUCT_MARGIN').' / 100
|
||||
END
|
||||
), 0)
|
||||
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
@@ -2408,7 +2408,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
WHEN od.`purchase_supplier_price` <> "0.000000"
|
||||
THEN (od.`purchase_supplier_price` / (IF (od.`product_price_calculation_method` = '.Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY.', DATEDIFF(hbd.`date_to`, hbd.`date_from`), 1)))
|
||||
WHEN od.`purchase_supplier_price` = "0.000000"
|
||||
THEN ((od.`original_product_price` / '.Currency::getReportConversionRateSql('o').') * '.(int)Configuration::get('CONF_AVERAGE_PRODUCT_MARGIN').' / 100) / (IF (od.`product_price_calculation_method` = '.Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY.', DATEDIFF(hbd.`date_to`, hbd.`date_from`), 1))
|
||||
THEN ((od.`original_product_price` / o.`conversion_rate`) * '.(int)Configuration::get('CONF_AVERAGE_PRODUCT_MARGIN').' / 100) / (IF (od.`product_price_calculation_method` = '.Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY.', DATEDIFF(hbd.`date_to`, hbd.`date_from`), 1))
|
||||
END
|
||||
), 0)
|
||||
FROM `'._DB_PREFIX_.'service_product_order_detail` rtspod
|
||||
@@ -2713,7 +2713,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
$objHotelBooking = new HotelBookingDetail();
|
||||
$invalidOrderStates = $objHotelBooking->getOrderStatusToFreeBookedRoom();
|
||||
|
||||
$sql = 'SELECT SUM(IF(((o.`total_paid_tax_incl` / '.Currency::getReportConversionRateSql('o').') - (o.`total_paid_real` / '.Currency::getReportConversionRateSql('o').') > 0), ((o.`total_paid_tax_incl` / '.Currency::getReportConversionRateSql('o').') - (o.`total_paid_real` / '.Currency::getReportConversionRateSql('o').')), 0))
|
||||
$sql = 'SELECT SUM(IF(((o.`total_paid_tax_incl` / o.`conversion_rate`) - (o.`total_paid_real` / o.`conversion_rate`) > 0), ((o.`total_paid_tax_incl` / o.`conversion_rate`) - (o.`total_paid_real` / o.`conversion_rate`)), 0))
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON o.current_state = os.id_order_state
|
||||
WHERE 1 ' .
|
||||
|
||||
@@ -3952,8 +3952,8 @@ class HotelBookingDetail extends ObjectModel
|
||||
|
||||
$rows = Db::getInstance()->executeS(
|
||||
'SELECT DATE(o.`date_add`) AS grp_date,
|
||||
IFNULL(SUM(hbd.`total_price_tax_excl` / '.Currency::getReportConversionRateSql('o').'), 0) AS total_price_tax_excl,
|
||||
IFNULL(SUM((hbd.`total_price_tax_incl` - hbd.`total_price_tax_excl`) / '.Currency::getReportConversionRateSql('o').'), 0) AS total_tax,
|
||||
IFNULL(SUM(hbd.`total_price_tax_excl` / o.`conversion_rate`), 0) AS total_price_tax_excl,
|
||||
IFNULL(SUM((hbd.`total_price_tax_incl` - hbd.`total_price_tax_excl`) / o.`conversion_rate`), 0) AS total_tax,
|
||||
COUNT(*) AS rooms_booked,
|
||||
SUM(DATEDIFF(hbd.`date_to`, hbd.`date_from`)) AS room_nights
|
||||
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
@@ -4008,11 +4008,11 @@ class HotelBookingDetail extends ObjectModel
|
||||
$row = Db::getInstance()->getRow(
|
||||
'SELECT IFNULL(SUM(
|
||||
ROUND(hbd.`total_price_tax_excl` / NULLIF(DATEDIFF(hbd.`date_to`, hbd.`date_from`), 0), 6)
|
||||
/ '.Currency::getReportConversionRateSql('o').'
|
||||
/ o.`conversion_rate`
|
||||
), 0) AS total_price_tax_excl,
|
||||
IFNULL(SUM(
|
||||
ROUND((hbd.`total_price_tax_incl` - hbd.`total_price_tax_excl`) / NULLIF(DATEDIFF(hbd.`date_to`, hbd.`date_from`), 0), 6)
|
||||
/ '.Currency::getReportConversionRateSql('o').'
|
||||
/ o.`conversion_rate`
|
||||
), 0) AS total_tax
|
||||
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = hbd.`id_product`)
|
||||
@@ -4129,7 +4129,7 @@ class HotelBookingDetail extends ObjectModel
|
||||
' AND hbd.`id_status` != '.(int) self::STATUS_CHECKED_OUT);
|
||||
|
||||
return Db::getInstance()->executeS(
|
||||
'SELECT hbd.*, o.`with_occupancy`, o.`id_currency`, '.Currency::getReportConversionRateSql('o').' AS conversion_rate,
|
||||
'SELECT hbd.*, o.`with_occupancy`, o.`id_currency`, o.`conversion_rate`,
|
||||
CONCAT(c.`firstname`, " ", c.`lastname`) AS customer_name,
|
||||
DATEDIFF(hbd.`date_to`, hbd.`date_from`) AS los,
|
||||
IF(hbd.`check_in` > "0000-00-00 00:00:00", hbd.`check_in`, CONCAT(DATE(hbd.`date_from`), " ", hbd.`check_in_time`)) AS actual_checkin,
|
||||
@@ -4166,7 +4166,7 @@ class HotelBookingDetail extends ObjectModel
|
||||
$allStatuses = !empty($params['all_statuses']);
|
||||
|
||||
return Db::getInstance()->executeS(
|
||||
'SELECT hbd.*, o.`with_occupancy`, o.`id_currency`, '.Currency::getReportConversionRateSql('o').' AS conversion_rate,
|
||||
'SELECT hbd.*, o.`with_occupancy`, o.`id_currency`, o.`conversion_rate`,
|
||||
CONCAT(c.`firstname`, " ", c.`lastname`) AS customer_name,
|
||||
DATEDIFF(hbd.`date_to`, hbd.`date_from`) AS los,
|
||||
IF(hbd.`check_in` > "0000-00-00 00:00:00", hbd.`check_in`, CONCAT(DATE(hbd.`date_from`), " ", hbd.`check_in_time`)) AS actual_checkin,
|
||||
@@ -4201,7 +4201,7 @@ class HotelBookingDetail extends ObjectModel
|
||||
$idCustomer = isset($params['id_customer']) ? (int) $params['id_customer']: 0;
|
||||
|
||||
return Db::getInstance()->executeS(
|
||||
'SELECT hbd.*, o.`with_occupancy`, o.`id_currency`, '.Currency::getReportConversionRateSql('o').' AS conversion_rate,
|
||||
'SELECT hbd.*, o.`with_occupancy`, o.`id_currency`, o.`conversion_rate`,
|
||||
CONCAT(c.`firstname`, " ", c.`lastname`) AS customer_name,
|
||||
DATEDIFF(hbd.`date_to`, hbd.`date_from`) AS los,
|
||||
IF(hbd.`check_in` > "0000-00-00 00:00:00", hbd.`check_in`, CONCAT(DATE(hbd.`date_from`), " ", hbd.`check_in_time`)) AS actual_checkin,
|
||||
@@ -4255,7 +4255,7 @@ class HotelBookingDetail extends ObjectModel
|
||||
o.`total_paid_tax_incl` AS order_total,
|
||||
o.`total_paid_real` AS order_paid,
|
||||
(o.`total_paid_tax_incl` - o.`total_paid_real`) AS balance_due,
|
||||
o.`id_currency`, '.Currency::getReportConversionRateSql('o').' AS conversion_rate,
|
||||
o.`id_currency`, o.`conversion_rate`,
|
||||
hbd.`id_status`, hbd.`booking_type`, hbd.`date_add`,
|
||||
IFNULL(NULLIF(o.`source`, \'\'), \'(direct)\') AS order_source,
|
||||
(SELECT CONCAT(e.`firstname`, " ", e.`lastname`)
|
||||
@@ -4324,9 +4324,9 @@ class HotelBookingDetail extends ObjectModel
|
||||
IFNULL(NULLIF(o.`source`, \'\'), \'(direct)\') AS order_source,
|
||||
COUNT(*) AS rooms_booked,
|
||||
SUM(DATEDIFF(hbd.`date_to`, hbd.`date_from`)) AS room_nights,
|
||||
SUM(hbd.`total_price_tax_excl` / '.Currency::getReportConversionRateSql('o').') AS revenue_excl,
|
||||
SUM(hbd.`total_price_tax_incl` / '.Currency::getReportConversionRateSql('o').') AS revenue_incl,
|
||||
MAX(o.`total_discounts_tax_excl` / '.Currency::getReportConversionRateSql('o').') AS discount_amount,
|
||||
SUM(hbd.`total_price_tax_excl` / o.`conversion_rate`) AS revenue_excl,
|
||||
SUM(hbd.`total_price_tax_incl` / o.`conversion_rate`) AS revenue_incl,
|
||||
MAX(o.`total_discounts_tax_excl` / o.`conversion_rate`) AS discount_amount,
|
||||
IFNULL(MAX(ord_ref.`refunded_total`), 0) AS refund_amount,
|
||||
COUNT(*) AS total_rooms,
|
||||
SUM(CASE WHEN hbd.`id_status` = '.(int) self::STATUS_CANCELLED.' THEN 1 ELSE 0 END) AS cancelled_rooms
|
||||
@@ -4381,8 +4381,8 @@ class HotelBookingDetail extends ObjectModel
|
||||
return Db::getInstance()->executeS(
|
||||
'SELECT o.`payment` AS payment_method, o.`module`,
|
||||
COUNT(DISTINCT hbd.`id_order`) AS bookings,
|
||||
IFNULL(SUM(hbd.`total_price_tax_excl` / '.Currency::getReportConversionRateSql('o').'), 0) AS revenue_excl,
|
||||
IFNULL(SUM(hbd.`total_price_tax_incl` / '.Currency::getReportConversionRateSql('o').'), 0) AS revenue_incl
|
||||
IFNULL(SUM(hbd.`total_price_tax_excl` / o.`conversion_rate`), 0) AS revenue_excl,
|
||||
IFNULL(SUM(hbd.`total_price_tax_incl` / o.`conversion_rate`), 0) AS revenue_incl
|
||||
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
INNER JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = hbd.`id_order` AND o.`valid` = 1)
|
||||
WHERE hbd.`date_add` BETWEEN "'.$dateFrom.' 00:00:00" AND "'.$dateTo.' 23:59:59"'
|
||||
@@ -4418,9 +4418,9 @@ class HotelBookingDetail extends ObjectModel
|
||||
'SELECT hbd.`id_order`, o.`reference`, hbd.`id_customer`, hbd.`id_product`,
|
||||
CONCAT(c.`firstname`, " ", c.`lastname`) AS customer_name,
|
||||
hbd.`room_type_name`, hbd.`room_num`, hbd.`date_add`,
|
||||
hbd.`total_price_tax_excl` / '.Currency::getReportConversionRateSql('o').' AS taxable_amount,
|
||||
hbd.`total_price_tax_excl` / o.`conversion_rate` AS taxable_amount,
|
||||
tl.`name` AS tax_name, t.`rate` AS tax_rate,
|
||||
odt.`total_amount` / '.Currency::getReportConversionRateSql('o').' AS tax_amount,
|
||||
odt.`total_amount` / o.`conversion_rate` AS tax_amount,
|
||||
"room" AS revenue_source
|
||||
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
INNER JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = hbd.`id_order` AND o.`valid` = 1)
|
||||
|
||||
@@ -560,8 +560,8 @@ class HotelRoomType extends ObjectModel
|
||||
) AS total_rooms,
|
||||
COUNT(hbd.`id`) AS bookings,
|
||||
IFNULL(SUM(DATEDIFF(hbd.`date_to`, hbd.`date_from`)), 0) AS room_nights,
|
||||
IFNULL(SUM(hbd.`total_price_tax_excl` / '.Currency::getReportConversionRateSql('o').'), 0) AS room_revenue,
|
||||
IFNULL(SUM((hbd.`total_price_tax_incl` - hbd.`total_price_tax_excl`) / '.Currency::getReportConversionRateSql('o').'), 0) AS tax_amount,
|
||||
IFNULL(SUM(hbd.`total_price_tax_excl` / o.`conversion_rate`), 0) AS room_revenue,
|
||||
IFNULL(SUM((hbd.`total_price_tax_incl` - hbd.`total_price_tax_excl`) / o.`conversion_rate`), 0) AS tax_amount,
|
||||
COUNT(CASE WHEN hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_CANCELLED.' THEN hbd.`id` END) AS cancel_count
|
||||
FROM `'._DB_PREFIX_.'htl_room_type` hrt
|
||||
INNER JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = hrt.`id_product`)
|
||||
|
||||
@@ -672,7 +672,7 @@ class ServiceProductOrderDetail extends ObjectModel
|
||||
.HotelBranchInformation::addHotelRestriction($idsHotel, 'hbd');
|
||||
|
||||
return (float) Db::getInstance()->getValue(
|
||||
'SELECT IFNULL(SUM(spod.`total_price_tax_excl` / '.Currency::getReportConversionRateSql('o').'), 0)
|
||||
'SELECT IFNULL(SUM(spod.`total_price_tax_excl` / o.`conversion_rate`), 0)
|
||||
'.$baseFrom.' '.$baseWhere
|
||||
);
|
||||
}
|
||||
@@ -730,12 +730,12 @@ class ServiceProductOrderDetail extends ObjectModel
|
||||
spod.`name` AS service_name,
|
||||
IFNULL(cl.`name`, "") AS service_category,
|
||||
spod.`quantity`, sp.`allow_multiple_quantity`,
|
||||
(spod.`unit_price_tax_excl` / '.Currency::getReportConversionRateSql('o').') AS unit_price,
|
||||
(spod.`unit_price_tax_excl` / o.`conversion_rate`) AS unit_price,
|
||||
spod.`hotel_name`, hbd.`room_num`, hbd.`room_type_name`,
|
||||
hbd.`date_from`, hbd.`date_to`,
|
||||
(spod.`total_price_tax_excl` / '.Currency::getReportConversionRateSql('o').') AS total_price_tax_excl,
|
||||
((spod.`total_price_tax_incl` - spod.`total_price_tax_excl`) / '.Currency::getReportConversionRateSql('o').') AS tax_amount,
|
||||
(spod.`total_price_tax_incl` / '.Currency::getReportConversionRateSql('o').') AS total_price_tax_incl
|
||||
(spod.`total_price_tax_excl` / o.`conversion_rate`) AS total_price_tax_excl,
|
||||
((spod.`total_price_tax_incl` - spod.`total_price_tax_excl`) / o.`conversion_rate`) AS tax_amount,
|
||||
(spod.`total_price_tax_incl` / o.`conversion_rate`) AS total_price_tax_incl
|
||||
'.$baseFrom.'
|
||||
LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = o.`id_customer`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` sp ON (sp.`id_product` = spod.`id_product`)
|
||||
@@ -781,8 +781,8 @@ class ServiceProductOrderDetail extends ObjectModel
|
||||
|
||||
$rows = Db::getInstance()->executeS(
|
||||
'SELECT DATE(o.`date_add`) AS grp_date,
|
||||
IFNULL(SUM(spod.`total_price_tax_excl` / '.Currency::getReportConversionRateSql('o').'), 0) AS service_revenue,
|
||||
IFNULL(SUM((spod.`total_price_tax_incl` - spod.`total_price_tax_excl`) / '.Currency::getReportConversionRateSql('o').'), 0) AS total_tax
|
||||
IFNULL(SUM(spod.`total_price_tax_excl` / o.`conversion_rate`), 0) AS service_revenue,
|
||||
IFNULL(SUM((spod.`total_price_tax_incl` - spod.`total_price_tax_excl`) / o.`conversion_rate`), 0) AS total_tax
|
||||
'.$joins.'
|
||||
WHERE p.`active` = 1 AND o.`valid` = 1
|
||||
AND spod.`is_cancelled` = 0
|
||||
@@ -868,10 +868,10 @@ class ServiceProductOrderDetail extends ObjectModel
|
||||
'SELECT hbd.`id_order`, o.`reference`, hbd.`id_customer`, spod.`id_product`,
|
||||
CONCAT(c.`firstname`, " ", c.`lastname`) AS customer_name,
|
||||
spod.`name` AS room_type_name, hbd.`room_num`, spod.`date_add`,
|
||||
spod.`total_price_tax_excl` / '.Currency::getReportConversionRateSql('o').' AS taxable_amount,
|
||||
spod.`total_price_tax_excl` / o.`conversion_rate` AS taxable_amount,
|
||||
MAX(tl.`name`) AS tax_name,
|
||||
MAX(t.`rate`) AS tax_rate,
|
||||
(spod.`total_price_tax_incl` - spod.`total_price_tax_excl`) / '.Currency::getReportConversionRateSql('o').' AS tax_amount,
|
||||
(spod.`total_price_tax_incl` - spod.`total_price_tax_excl`) / o.`conversion_rate` AS tax_amount,
|
||||
"service" AS revenue_source
|
||||
FROM `'._DB_PREFIX_.'service_product_order_detail` spod
|
||||
INNER JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd ON (hbd.`id` = spod.`id_htl_booking_detail`)
|
||||
|
||||
@@ -148,13 +148,13 @@ class QloStatsServiceProducts extends ModuleGrid
|
||||
$this->query = '(SELECT od.`product_name` as `display_name`, p.`active`,
|
||||
od.`product_auto_add` as auto_add_to_cart,
|
||||
od.`product_price_addition_type` as price_addition_type,
|
||||
ROUND(IFNULL(SUM(spod.`total_price_tax_excl` / '.Currency::getReportConversionRateSql('o').'), 0), 2) / SUM(
|
||||
ROUND(IFNULL(SUM(spod.`total_price_tax_excl` / o.`conversion_rate`), 0), 2) / SUM(
|
||||
('.$applicableDaysSql.') * spod.`quantity`
|
||||
) AS avgPriceSold,
|
||||
IFNULL(SUM(
|
||||
('.$applicableDaysSql.') * spod.`quantity`
|
||||
), 0) AS totalQuantitySold,
|
||||
ROUND(IFNULL(SUM(spod.`total_price_tax_excl` / '.Currency::getReportConversionRateSql('o').'), 0), 2) AS totalPriceSold
|
||||
ROUND(IFNULL(SUM(spod.`total_price_tax_excl` / o.`conversion_rate`), 0), 2) AS totalPriceSold
|
||||
FROM '._DB_PREFIX_.'service_product_order_detail spod
|
||||
LEFT JOIN '._DB_PREFIX_.'product p ON (spod.`id_product` = p.`id_product`)
|
||||
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (p.id_product = pl.id_product AND pl.id_lang = '.(int)$this->getLang().')
|
||||
|
||||
@@ -201,7 +201,7 @@ class StatsBestCategories extends ModuleGrid
|
||||
)
|
||||
) AS totalOrders,
|
||||
(
|
||||
SELECT ROUND(SUM(total_paid_tax_excl / '.Currency::getReportConversionRateSql('o').'), 2)
|
||||
SELECT ROUND(SUM(total_paid_tax_excl / o.`conversion_rate`), 2)
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
WHERE o.valid = 1 AND `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59"
|
||||
AND (
|
||||
|
||||
@@ -153,7 +153,7 @@ 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) / '.Currency::getReportConversionRateSql('o').'), 2)
|
||||
SELECT ROUND(SUM(IFNULL(op.`amount`, 0) / o.`conversion_rate`), 2)
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_payment_detail` op ON o.id_order = op.id_order
|
||||
WHERE o.id_customer = c.id_customer
|
||||
|
||||
@@ -169,7 +169,7 @@ class StatsBestProducts extends ModuleGrid
|
||||
) AS totalRoomsBooked,
|
||||
(
|
||||
SELECT IFNULL(ROUND(
|
||||
SUM(hbd.`total_price_tax_excl` * DATEDIFF(LEAST(hbd.`date_to`, "'.pSQL($date_to).'"), GREATEST(hbd.`date_from`, "'.pSQL($date_from).'")) / ('.Currency::getReportConversionRateSql('o').' * DATEDIFF(hbd.`date_to`, hbd.`date_from`))) / SUM(DATEDIFF(LEAST(hbd.`date_to`, "'.pSQL($date_to).'"), GREATEST(hbd.`date_from`, "'.pSQL($date_from).'"))),
|
||||
SUM(hbd.`total_price_tax_excl` * DATEDIFF(LEAST(hbd.`date_to`, "'.pSQL($date_to).'"), GREATEST(hbd.`date_from`, "'.pSQL($date_from).'")) / (o.`conversion_rate` * DATEDIFF(hbd.`date_to`, hbd.`date_from`))) / SUM(DATEDIFF(LEAST(hbd.`date_to`, "'.pSQL($date_to).'"), GREATEST(hbd.`date_from`, "'.pSQL($date_from).'"))),
|
||||
2
|
||||
), 0)
|
||||
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
@@ -180,7 +180,7 @@ class StatsBestProducts extends ModuleGrid
|
||||
) AS sellingPrice,
|
||||
(
|
||||
SELECT IFNULL(ROUND(
|
||||
SUM(hbd.`total_price_tax_excl` * DATEDIFF(LEAST(hbd.`date_to`, "'.pSQL($date_to).'"), GREATEST(hbd.`date_from`, "'.pSQL($date_from).'")) / ('.Currency::getReportConversionRateSql('o').' * DATEDIFF(hbd.`date_to`, hbd.`date_from`))),
|
||||
SUM(hbd.`total_price_tax_excl` * DATEDIFF(LEAST(hbd.`date_to`, "'.pSQL($date_to).'"), GREATEST(hbd.`date_from`, "'.pSQL($date_from).'")) / (o.`conversion_rate` * DATEDIFF(hbd.`date_to`, hbd.`date_from`))),
|
||||
2
|
||||
), 0)
|
||||
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
|
||||
@@ -121,7 +121,7 @@ class StatsBestVouchers extends ModuleGrid
|
||||
public function getData()
|
||||
{
|
||||
$currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
|
||||
$this->query = 'SELECT SQL_CALC_FOUND_ROWS ocr.id_cart_rule, cr.code, ocr.name, COUNT(ocr.id_cart_rule) as total, ROUND(SUM(o.total_paid_real) / '.Currency::getReportConversionRateSql('o').',2) as ca
|
||||
$this->query = 'SELECT SQL_CALC_FOUND_ROWS ocr.id_cart_rule, cr.code, ocr.name, COUNT(ocr.id_cart_rule) as total, ROUND(SUM(o.total_paid_real) / o.`conversion_rate`,2) as ca
|
||||
FROM '._DB_PREFIX_.'order_cart_rule ocr
|
||||
LEFT JOIN '._DB_PREFIX_.'orders o ON o.id_order = ocr.id_order
|
||||
LEFT JOIN '._DB_PREFIX_.'cart_rule cr ON cr.id_cart_rule = ocr.id_cart_rule
|
||||
|
||||
@@ -159,7 +159,7 @@ class StatsForecast extends Module
|
||||
'.($this->context->cookie->stats_granularity == 42 ? $date_to_ginvoice : '').'
|
||||
COUNT(DISTINCT(o.`id_order`)) AS countOrders,
|
||||
SUM((SELECT IFNULL(SUM(DATEDIFF(hbd.`date_to`, hbd.`date_from`)), 0) FROM `'._DB_PREFIX_.'htl_booking_detail` hbd WHERE o.`id_order` = hbd.`id_order`)) AS totalRoomsBooked,
|
||||
SUM(o.`total_paid_tax_excl` / '.Currency::getReportConversionRateSql('o').') AS totalSales,
|
||||
SUM(o.`total_paid_tax_excl` / o.`conversion_rate`) AS totalSales,
|
||||
SUM((
|
||||
SELECT SUM(ROUND(IFNULL(DATEDIFF(hbd.`date_to`, hbd.`date_from`), 1) * (
|
||||
CASE
|
||||
@@ -716,7 +716,7 @@ class StatsForecast extends Module
|
||||
WHERE l.active = 1';
|
||||
$languages = Db::getInstance()->executeS($sql);
|
||||
foreach ($languages as $language) {
|
||||
$lang_values .= 'SUM(IF(o.id_lang = '.(int)$language['id_lang'].', total_paid_tax_excl / '.Currency::getReportConversionRateSql('o').', 0)) as '.pSQL($language['iso_code']).',';
|
||||
$lang_values .= 'SUM(IF(o.id_lang = '.(int)$language['id_lang'].', total_paid_tax_excl / o.`conversion_rate`, 0)) as '.pSQL($language['iso_code']).',';
|
||||
}
|
||||
$lang_values = rtrim($lang_values, ',');
|
||||
|
||||
@@ -752,7 +752,7 @@ class StatsForecast extends Module
|
||||
$ca['payment'] = array();
|
||||
}
|
||||
|
||||
$sql = 'SELECT z.name, SUM(o.`total_paid_tax_excl` / '.Currency::getReportConversionRateSql('o').') as total, COUNT(*) as nb
|
||||
$sql = 'SELECT z.name, SUM(o.`total_paid_tax_excl` / o.`conversion_rate`) as total, COUNT(*) as nb
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
LEFT JOIN `'._DB_PREFIX_.'address` a ON o.id_address_invoice = a.id_address
|
||||
LEFT JOIN `'._DB_PREFIX_.'country` c ON c.id_country = a.id_country
|
||||
@@ -765,7 +765,7 @@ class StatsForecast extends Module
|
||||
ORDER BY total DESC';
|
||||
$ca['zones'] = Db::getInstance()->executeS($sql);
|
||||
|
||||
$sql = 'SELECT cu.name, SUM(o.`total_paid_tax_excl` / '.Currency::getReportConversionRateSql('o').') as total, COUNT(*) as nb
|
||||
$sql = 'SELECT cu.name, SUM(o.`total_paid_tax_excl` / o.`conversion_rate`) as total, COUNT(*) as nb
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
LEFT JOIN `'._DB_PREFIX_.'currency` cu ON o.id_currency = cu.id_currency
|
||||
'.$join.'
|
||||
@@ -775,8 +775,8 @@ class StatsForecast extends Module
|
||||
ORDER BY total DESC';
|
||||
$ca['currencies'] = Db::getInstance()->executeS($sql);
|
||||
|
||||
$sql = 'SELECT SUM(total_paid_tax_excl / '.Currency::getReportConversionRateSql('o').') as total,
|
||||
SUM(total_paid_tax_incl / '.Currency::getReportConversionRateSql('o').') as total_incl, COUNT(*) AS nb
|
||||
$sql = 'SELECT SUM(total_paid_tax_excl / o.`conversion_rate`) as total,
|
||||
SUM(total_paid_tax_incl / o.`conversion_rate`) as total_incl, COUNT(*) AS nb
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
WHERE o.`id_order` IN ('.pSQL($idOrders).')';
|
||||
$ca['ventil'] = Db::getInstance()->getRow($sql);
|
||||
|
||||
@@ -84,7 +84,7 @@ class StatsProduct extends ModuleGraph
|
||||
public function getTotalRevenue($id_product)
|
||||
{
|
||||
$date_between = ModuleGraph::getDateBetween();
|
||||
$sql = 'SELECT SUM(hbd.`total_price_tax_excl` / '.Currency::getReportConversionRateSql('o').')
|
||||
$sql = 'SELECT SUM(hbd.`total_price_tax_excl` / o.`conversion_rate`)
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
INNER JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
ON (hbd.`id_order` = o.`id_order` AND hbd.`id_product` = '.(int) $id_product.')
|
||||
|
||||
@@ -193,7 +193,7 @@ class StatsSales extends ModuleGraph
|
||||
private function getTotals()
|
||||
{
|
||||
$idHotel = (int)Tools::getValue('id_hotel');
|
||||
$sql = 'SELECT COUNT(id_order) AS orderCount, IFNULL(ROUND(SUM(o.`total_paid_tax_excl` / '.Currency::getReportConversionRateSql('o').'), 2), 0) AS orderSum
|
||||
$sql = 'SELECT COUNT(id_order) AS orderCount, IFNULL(ROUND(SUM(total_paid_tax_excl), 2), 0) AS orderSum
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
'.((int)Tools::getValue('id_country') ? 'LEFT JOIN `'._DB_PREFIX_.'address` a ON o.`id_address_delivery` = a.`id_address`' : '').'
|
||||
WHERE o.valid = 1 AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
|
||||
@@ -253,7 +253,7 @@ class StatsSales extends ModuleGraph
|
||||
$this->_formats['y'] = 'd';
|
||||
}
|
||||
|
||||
$this->query = 'SELECT o.`invoice_date`, ROUND(o.`total_paid_tax_excl` / '.Currency::getReportConversionRateSql('o').') AS total_revenue
|
||||
$this->query = 'SELECT o.`invoice_date`, ROUND(total_paid_tax_excl) AS total_revenue
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
'.((int)$this->id_country ? 'LEFT JOIN `'._DB_PREFIX_.'address` a ON o.`id_address_delivery` = a.`id_address`' : '').'
|
||||
WHERE o.valid = 1
|
||||
|
||||
Reference in New Issue
Block a user