Fixed: Issues of TREVPAR and GOPPAR
This commit is contained in:
@@ -1553,7 +1553,8 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getTotalRevenueForDiscreteDates($dateFrom, $dateTo = null, $idHotel = null, $useCache = true)
|
||||
// Calculate total services revenue (services and demands)
|
||||
public static function getServicesRevenueForDiscreteDates($dateFrom, $dateTo = null, $idHotel = null, $useCache = true)
|
||||
{
|
||||
$dateTo = !$dateTo ? date('Y-m-d', strtotime('+1 day', strtotime($dateFrom))) : $dateTo;
|
||||
|
||||
@@ -1571,41 +1572,53 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
|
||||
$result = array();
|
||||
foreach ($discreteDates as $discreteDate) {
|
||||
$cacheKey = 'AdminStats::getTotalRevenueForDiscreteDates'.'_'.(int) $discreteDate['timestamp_from'].'_'.
|
||||
(!is_array($idHotel) ? (int) $idHotel : implode('_', $idHotel));
|
||||
if (!Cache::isStored($cacheKey) || !$useCache) {
|
||||
$sql = 'SELECT SUM((current_parts / total_parts) * total_paid_tax_excl) AS total_revenue
|
||||
FROM (
|
||||
SELECT o.`id_order`,
|
||||
o.`total_paid_tax_excl` / o.`conversion_rate` AS total_paid_tax_excl,
|
||||
(
|
||||
SELECT SUM(DATEDIFF(hbd.`date_to`, hbd.`date_from`))
|
||||
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
INNER JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = hbd.`id_product`)
|
||||
WHERE hbd.`id_order` = o.`id_order`
|
||||
AND p.`active` = 1 AND hbd.`is_refunded` = 0 AND o.`valid` = 1'.
|
||||
(!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '').'
|
||||
) AS total_parts,
|
||||
(
|
||||
SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
INNER JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = hbd.`id_product`)
|
||||
WHERE hbd.`id_order` = o.`id_order`
|
||||
AND hbd.`date_from` <= "'.pSQL($discreteDate['date_from']).' 00:00:00" AND hbd.`date_to` >= "'.pSQL($discreteDate['date_to']).' 00:00:00"
|
||||
AND p.`active` = 1 AND hbd.`is_refunded` = 0 AND o.`valid` = 1'.
|
||||
(!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '').'
|
||||
) AS current_parts
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
HAVING total_parts IS NOT NULL AND current_parts > 0
|
||||
ORDER BY o.`id_order`
|
||||
) AS t';
|
||||
$totalServicesRevenue = 0;
|
||||
// Calculate services revenue
|
||||
$servicesRevenueSql = 'SELECT SUM((rtspod.`total_price_tax_excl` / o.`conversion_rate`) / DATEDIFF(hbd.`date_to`, hbd.`date_from`))
|
||||
FROM `'._DB_PREFIX_.'htl_room_type_service_product_order_detail` rtspod
|
||||
LEFT JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
ON (rtspod.`id_htl_booking_detail` = hbd.`id`)
|
||||
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`)
|
||||
WHERE p.`active` = 1
|
||||
AND hbd.`is_refunded` = 0
|
||||
AND hbd.`date_from` < "'.pSQL($discreteDate['date_to']).' 00:00:00" AND hbd.`date_to` > "'.pSQL($discreteDate['date_from']).' 00:00:00"'.
|
||||
(!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '');
|
||||
|
||||
$value = Db::getInstance()->getValue($sql);
|
||||
$value = !$value ? 0: (float) $value;
|
||||
Cache::store($cacheKey, $value);
|
||||
if ($servicesRevenue = Db::getInstance()->getValue($servicesRevenueSql)) {
|
||||
$totalServicesRevenue += $servicesRevenue;
|
||||
}
|
||||
|
||||
$result[$discreteDate['timestamp_from']] = Cache::retrieve($cacheKey);
|
||||
// Calculate demands revenue
|
||||
$demandsRevenueSql = 'SELECT SUM((hdmd.`total_price_tax_excl` / o.`conversion_rate`) / DATEDIFF(hbd.`date_to`, hbd.`date_from`))
|
||||
FROM `'._DB_PREFIX_.'htl_booking_demands` hdmd
|
||||
LEFT JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
ON (hdmd.`id_htl_booking` = hbd.`id`)
|
||||
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`)
|
||||
WHERE p.`active` = 1
|
||||
AND hbd.`is_refunded` = 0
|
||||
AND hbd.`date_from` < "'.pSQL($discreteDate['date_to']).' 00:00:00" AND hbd.`date_to` > "'.pSQL($discreteDate['date_from']).' 00:00:00"'.
|
||||
(!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '');
|
||||
|
||||
if ($demandsRevenue = Db::getInstance()->getValue($demandsRevenueSql)) {
|
||||
$totalServicesRevenue += $demandsRevenue;
|
||||
}
|
||||
|
||||
$result[$discreteDate['timestamp_from']] = $totalServicesRevenue;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getTotalRevenueForDiscreteDates($dateFrom, $dateTo = null, $idHotel = null, $useCache = true)
|
||||
{
|
||||
$result = array();
|
||||
$servicesRevenueByDates = self::getServicesRevenueForDiscreteDates($dateFrom, $dateTo, $idHotel);
|
||||
if ($roomsRevenueByDates = self::getRoomsRevenueForDiscreteDates($dateFrom, $dateTo, $idHotel)) {
|
||||
foreach ($roomsRevenueByDates as $key => $value) {
|
||||
$result[$key] = (isset($servicesRevenueByDates[$key]) ? $servicesRevenueByDates[$key] : 0) + $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
@@ -2061,17 +2074,16 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
$roomsSql = 'SELECT
|
||||
IFNULL(SUM(
|
||||
CASE
|
||||
WHEN od.`original_wholesale_price` <> "0.000000"
|
||||
THEN od.`original_wholesale_price`
|
||||
WHEN p.`wholesale_price` <> "0.000000"
|
||||
THEN p.`wholesale_price`
|
||||
WHEN od.`purchase_supplier_price` <> "0.000000"
|
||||
THEN od.`purchase_supplier_price`
|
||||
WHEN od.`purchase_supplier_price` = "0.000000"
|
||||
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
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p
|
||||
ON (p.`id_product` = hbd.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` od
|
||||
ON (od.`id_order_detail` = hbd.`id_order_detail`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = hbd.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = hbd.`id_order_detail`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (od.`id_order` = o.`id_order`)
|
||||
WHERE p.`active` = 1
|
||||
AND hbd.`is_refunded` = 0
|
||||
AND hbd.`date_from` < "'.pSQL($discreteDate['date_to']).' 00:00:00" AND hbd.`date_to` > "'.pSQL($discreteDate['date_from']).' 00:00:00"'.
|
||||
@@ -2085,19 +2097,18 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
$servicesSql = 'SELECT
|
||||
IFNULL(SUM(
|
||||
CASE
|
||||
WHEN od.`original_wholesale_price` <> "0.000000"
|
||||
THEN od.`original_wholesale_price`
|
||||
WHEN p.`wholesale_price` <> "0.000000"
|
||||
THEN p.`wholesale_price`
|
||||
WHEN od.`purchase_supplier_price` <> "0.000000"
|
||||
THEN (od.`purchase_supplier_price` / (IF (od.`product_price_calculation_method` = '.Product::PRICE_CALCULATION_METHOD_PER_BOOKING.', DATEDIFF(hbd.`date_to`, hbd.`date_from`), 1)))
|
||||
WHEN od.`purchase_supplier_price` = "0.000000"
|
||||
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_PER_BOOKING.', DATEDIFF(hbd.`date_to`, hbd.`date_from`), 1))
|
||||
END
|
||||
), 0)
|
||||
FROM `'._DB_PREFIX_.'htl_room_type_service_product_order_detail` rtspod
|
||||
LEFT JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
ON (rtspod.`id_htl_booking_detail` = hbd.`id`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p
|
||||
ON (p.`id_product` = hbd.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` od
|
||||
ON (od.`id_order_detail` = rtspod.`id_order_detail`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = rtspod.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = rtspod.`id_order_detail`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (od.`id_order` = o.`id_order`)
|
||||
WHERE p.`active` = 1
|
||||
AND hbd.`is_refunded` = 0
|
||||
AND hbd.`date_from` < "'.pSQL($discreteDate['date_to']).' 00:00:00" AND hbd.`date_to` > "'.pSQL($discreteDate['date_from']).' 00:00:00"'.
|
||||
|
||||
Reference in New Issue
Block a user