fixed issues
This commit is contained in:
@@ -3183,6 +3183,28 @@ class OrderCore extends ObjectModel
|
||||
|
||||
// ── REPORT METHODS ────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Builds the hotel WHERE fragment for report queries.
|
||||
*
|
||||
* @param int|array|false $idsHotel
|
||||
* @param string $alias
|
||||
* @return string
|
||||
*/
|
||||
protected static function hotelFilter($idsHotel, $alias)
|
||||
{
|
||||
if (defined('_PS_ADMIN_DIR_')) {
|
||||
return HotelBranchInformation::addHotelRestriction($idsHotel, $alias);
|
||||
}
|
||||
if (!$idsHotel) {
|
||||
return '';
|
||||
}
|
||||
$ids = array_filter(array_map('intval', is_array($idsHotel) ? $idsHotel : array($idsHotel)));
|
||||
if (!$ids) {
|
||||
return '';
|
||||
}
|
||||
return ' AND `'.bqSQL($alias).'`.`id_hotel` IN ('.implode(',', $ids).')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Orders with unpaid balance for the outstanding-payments report.
|
||||
*
|
||||
@@ -3193,12 +3215,12 @@ class OrderCore extends ObjectModel
|
||||
{
|
||||
$dateFrom = pSQL($params['date_from']);
|
||||
$dateTo = pSQL(isset($params['date_to']) ? $params['date_to'] : $params['date_from']);
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : false;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idOrder = isset($params['id_order']) ? (int) $params['id_order'] : 0;
|
||||
|
||||
$hotelExists = $idHotel
|
||||
? ' AND EXISTS (SELECT 1 FROM `'._DB_PREFIX_.'htl_booking_detail` hbd WHERE hbd.`id_order` = o.`id_order`'
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd').')'
|
||||
$hotelFilter = self::hotelFilter($idsHotel, 'hbd');
|
||||
$hotelExists = $hotelFilter
|
||||
? ' AND EXISTS (SELECT 1 FROM `'._DB_PREFIX_.'htl_booking_detail` hbd WHERE hbd.`id_order` = o.`id_order`'.$hotelFilter.')'
|
||||
: '';
|
||||
|
||||
return Db::getInstance()->executeS(
|
||||
@@ -3237,41 +3259,22 @@ class OrderCore extends ObjectModel
|
||||
* Total order-level discounts applied to hotel orders in the date range.
|
||||
* Returns positive number representing the discount amount.
|
||||
*
|
||||
* @param array $params date_from, date_to, id_hotel, id_customer, granularity ('day'|false)
|
||||
* @return float|array scalar when no granularity, timestamp => float when granularity='day'
|
||||
* @param array $params date_from, date_to, id_hotel, id_customer
|
||||
* @return float
|
||||
*/
|
||||
public static function getTotalDiscounts(array $params)
|
||||
{
|
||||
$dateFrom = pSQL($params['date_from']);
|
||||
$dateTo = pSQL(isset($params['date_to']) ? $params['date_to'] : $params['date_from']);
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : false;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idCustomer = isset($params['id_customer']) ? (int) $params['id_customer'] : 0;
|
||||
$granularity = isset($params['granularity']) ? $params['granularity'] : false;
|
||||
|
||||
$hotelExists = ' AND EXISTS (
|
||||
SELECT 1 FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
WHERE hbd.`id_order` = o.`id_order`'
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd')
|
||||
.self::hotelFilter($idsHotel, 'hbd')
|
||||
.')';
|
||||
|
||||
if ($granularity === 'day') {
|
||||
$rows = Db::getInstance()->executeS(
|
||||
'SELECT LEFT(o.`invoice_date`, 10) AS grp,
|
||||
IFNULL(SUM(o.`total_discounts_tax_excl` / o.`conversion_rate`), 0) AS amt
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
WHERE o.`valid` = 1
|
||||
AND o.`date_add` BETWEEN "'.$dateFrom.' 00:00:00" AND "'.$dateTo.' 23:59:59"'
|
||||
.($idCustomer ? ' AND o.`id_customer` = '.$idCustomer : '')
|
||||
.$hotelExists.'
|
||||
GROUP BY LEFT(o.`date_add`, 10)'
|
||||
);
|
||||
$result = array();
|
||||
foreach ($rows as $row) {
|
||||
$result[strtotime($row['grp'])] = (float) $row['amt'];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
return (float) Db::getInstance()->getValue(
|
||||
'SELECT IFNULL(SUM(o.`total_discounts_tax_excl` / o.`conversion_rate`), 0)
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
@@ -3293,7 +3296,7 @@ class OrderCore extends ObjectModel
|
||||
{
|
||||
$dateFrom = isset($params['date_from']) ? pSQL($params['date_from']) : '';
|
||||
$dateTo = isset($params['date_to']) ? pSQL($params['date_to']) : '';
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : false;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idProduct = isset($params['id_product']) ? (int) $params['id_product'] : 0;
|
||||
$idLang = isset($params['id_lang']) ? (int) $params['id_lang'] : 0;
|
||||
if (!$idLang) {
|
||||
@@ -3325,7 +3328,7 @@ class OrderCore extends ObjectModel
|
||||
LEFT JOIN `'._DB_PREFIX_.'state` st ON (st.`id_state` = a.`id_state`)
|
||||
WHERE o.`valid` = 1'
|
||||
.($idProduct ? ' AND hbd.`id_product` = '.$idProduct : '')
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd').'
|
||||
.self::hotelFilter($idsHotel, 'hbd').'
|
||||
GROUP BY c.`id_customer`'
|
||||
.($dateFrom && $dateTo
|
||||
? ' HAVING MAX(IF(hbd.`date_from` <= "'.$dateTo.'" AND hbd.`date_to` > "'.$dateFrom.'", 1, 0)) = 1'
|
||||
|
||||
@@ -3893,52 +3893,92 @@ class HotelBookingDetail extends ObjectModel
|
||||
// ── REPORT METHODS ────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Total room revenue (tax excl) for a date range, filtered by invoice_date.
|
||||
* Builds the hotel WHERE fragment for report queries.
|
||||
* Admin context: uses addHotelRestriction (employee-profile filtered).
|
||||
* Non-admin context: builds IN (...) directly from the supplied IDs.
|
||||
*
|
||||
* @param int|array|false $idsHotel Scalar ID, array of IDs, or false for no filter
|
||||
* @param string $alias SQL table alias
|
||||
* @return string
|
||||
*/
|
||||
private static function hotelFilter($idsHotel, $alias)
|
||||
{
|
||||
if (defined('_PS_ADMIN_DIR_')) {
|
||||
return HotelBranchInformation::addHotelRestriction($idsHotel, $alias);
|
||||
}
|
||||
if (!$idsHotel) {
|
||||
return '';
|
||||
}
|
||||
$ids = array_filter(array_map('intval', is_array($idsHotel) ? $idsHotel : array($idsHotel)));
|
||||
if (!$ids) {
|
||||
return '';
|
||||
}
|
||||
return ' AND `'.bqSQL($alias).'`.`id_hotel` IN ('.implode(',', $ids).')';
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Per-day booking summary keyed by booking-creation date (date_add).
|
||||
* Returns room revenue, tax, rooms booked, and room nights for each day bookings were placed.
|
||||
*
|
||||
* @param array $params date_from, date_to, id_hotel, id_product, id_room, id_order, id_customer
|
||||
* @return float
|
||||
* @return array timestamp => ['total_price_tax_excl' => float, 'total_tax' => float, 'rooms_booked' => int, 'room_nights' => int]
|
||||
*/
|
||||
public static function getTotalRoomRevenue(array $params)
|
||||
public static function getDatewiseSummary(array $params)
|
||||
{
|
||||
$dateFrom = pSQL($params['date_from']);
|
||||
$dateTo = pSQL(isset($params['date_to']) ? $params['date_to'] : $params['date_from']);
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : false;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idProduct = isset($params['id_product']) ? (int) $params['id_product'] : 0;
|
||||
$idRoom = isset($params['id_room']) ? (int) $params['id_room'] : 0;
|
||||
$idOrder = isset($params['id_order']) ? (int) $params['id_order'] : 0;
|
||||
$idCustomer = isset($params['id_customer']) ? (int) $params['id_customer'] : 0;
|
||||
|
||||
$value = Db::getInstance()->getValue(
|
||||
'SELECT IFNULL(SUM(hbd.`total_price_tax_excl` / o.`conversion_rate`), 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`)
|
||||
WHERE p.`active` = 1
|
||||
AND o.`valid` = 1
|
||||
AND hbd.`is_refunded` = 0
|
||||
AND o.`invoice_date` BETWEEN "'.$dateFrom.' 00:00:00" AND "'.$dateTo.' 23:59:59"'
|
||||
.($idProduct ? ' AND hbd.`id_product` = '.$idProduct : '')
|
||||
$whereFilters = ($idProduct ? ' AND hbd.`id_product` = '.$idProduct : '')
|
||||
.($idRoom ? ' AND hbd.`id_room` = '.$idRoom : '')
|
||||
.($idOrder ? ' AND hbd.`id_order` = '.$idOrder : '')
|
||||
.($idCustomer ? ' AND hbd.`id_customer` = '.$idCustomer : '')
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd')
|
||||
);
|
||||
.self::hotelFilter($idsHotel, 'hbd');
|
||||
|
||||
return (float) $value;
|
||||
$rows = Db::getInstance()->executeS(
|
||||
'SELECT DATE(o.`date_add`) AS grp_date,
|
||||
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,
|
||||
SUM(CASE WHEN hbd.`is_refunded` = 0 AND hbd.`is_cancelled` = 0 THEN 1 ELSE 0 END) AS rooms_booked,
|
||||
SUM(CASE WHEN hbd.`is_refunded` = 0 AND hbd.`is_cancelled` = 0
|
||||
THEN DATEDIFF(hbd.`date_to`, hbd.`date_from`) ELSE 0 END) AS room_nights
|
||||
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`)
|
||||
WHERE p.`active` = 1 AND o.`valid` = 1
|
||||
AND o.`date_add` BETWEEN "'.$dateFrom.' 00:00:00" AND "'.$dateTo.' 23:59:59"'
|
||||
.$whereFilters.'
|
||||
GROUP BY DATE(o.`date_add`)'
|
||||
);
|
||||
$result = array();
|
||||
foreach ($rows as $row) {
|
||||
$ts = strtotime($row['grp_date']);
|
||||
$result[$ts] = array(
|
||||
'total_price_tax_excl' => (float) $row['total_price_tax_excl'],
|
||||
'total_tax' => (float) $row['total_tax'],
|
||||
'rooms_booked' => (int) $row['rooms_booked'],
|
||||
'room_nights' => (int) $row['room_nights'],
|
||||
);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Daily room revenue + tax amount split, keyed by Unix timestamp.
|
||||
* Used by revenue report daily table (needs excl + tax columns per day).
|
||||
* Daily room revenue + tax amount split keyed by occupancy date (pro-rated per night).
|
||||
*
|
||||
* @param array $params date_from, date_to, id_hotel, id_product, id_room, id_order, id_customer
|
||||
* @return array timestamp => ['room_revenue' => float, 'tax_amount' => float]
|
||||
* @return array timestamp => ['total_price_tax_excl' => float, 'total_tax' => float]
|
||||
*/
|
||||
public static function getDatewiseRoomRevenueTax(array $params)
|
||||
public static function getDatewiseRevenue(array $params)
|
||||
{
|
||||
$dateFrom = $params['date_from'];
|
||||
$dateTo = isset($params['date_to']) ? $params['date_to'] : $params['date_from'];
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : false;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idProduct = isset($params['id_product']) ? (int) $params['id_product'] : 0;
|
||||
$idRoom = isset($params['id_room']) ? (int) $params['id_room'] : 0;
|
||||
$idOrder = isset($params['id_order']) ? (int) $params['id_order'] : 0;
|
||||
@@ -3951,36 +3991,7 @@ class HotelBookingDetail extends ObjectModel
|
||||
.($idRoom ? ' AND hbd.`id_room` = '.$idRoom : '')
|
||||
.($idOrder ? ' AND hbd.`id_order` = '.$idOrder : '')
|
||||
.($idCustomer ? ' AND hbd.`id_customer` = '.$idCustomer : '')
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd');
|
||||
|
||||
if (isset($params['date_type']) && $params['date_type'] === 'created') {
|
||||
$rows = Db::getInstance()->executeS(
|
||||
'SELECT DATE(o.`date_add`) AS grp_date,
|
||||
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,
|
||||
SUM(CASE WHEN hbd.`is_refunded` = 0 AND hbd.`is_cancelled` = 0 THEN 1 ELSE 0 END) AS rooms_booked,
|
||||
SUM(CASE WHEN hbd.`is_refunded` = 0 AND hbd.`is_cancelled` = 0
|
||||
THEN DATEDIFF(hbd.`date_to`, hbd.`date_from`) ELSE 0 END) AS room_nights
|
||||
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`)
|
||||
WHERE p.`active` = 1 AND o.`valid` = 1
|
||||
AND o.`date_add` BETWEEN "'.pSQL($dateFrom).' 00:00:00" AND "'.pSQL($dateTo).' 23:59:59"'
|
||||
.$whereFilters.'
|
||||
GROUP BY DATE(o.`date_add`)'
|
||||
);
|
||||
$result = array();
|
||||
foreach ($rows as $row) {
|
||||
$ts = strtotime($row['grp_date']);
|
||||
$result[$ts] = array(
|
||||
'room_revenue' => (float) $row['room_revenue'],
|
||||
'tax_amount' => (float) $row['tax_amount'],
|
||||
'rooms_booked' => (int) $row['rooms_booked'],
|
||||
'room_nights' => (int) $row['room_nights'],
|
||||
);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
.self::hotelFilter($idsHotel, 'hbd');
|
||||
|
||||
while ($current <= $dateTo) {
|
||||
$nextDay = date('Y-m-d', strtotime('+1 day', strtotime($current)));
|
||||
@@ -3989,11 +4000,11 @@ class HotelBookingDetail extends ObjectModel
|
||||
'SELECT IFNULL(SUM(
|
||||
ROUND(hbd.`total_price_tax_excl` / NULLIF(DATEDIFF(hbd.`date_to`, hbd.`date_from`), 0), 6)
|
||||
/ o.`conversion_rate`
|
||||
), 0) AS room_revenue,
|
||||
), 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)
|
||||
/ o.`conversion_rate`
|
||||
), 0) AS tax_amount
|
||||
), 0) AS total_tax
|
||||
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`)
|
||||
@@ -4004,8 +4015,8 @@ class HotelBookingDetail extends ObjectModel
|
||||
.$whereFilters
|
||||
);
|
||||
$result[$ts] = array(
|
||||
'room_revenue' => (float) $row['room_revenue'],
|
||||
'tax_amount' => (float) $row['tax_amount'],
|
||||
'total_price_tax_excl' => (float) $row['total_price_tax_excl'],
|
||||
'total_tax' => (float) $row['total_tax'],
|
||||
);
|
||||
$current = $nextDay;
|
||||
}
|
||||
@@ -4023,7 +4034,7 @@ class HotelBookingDetail extends ObjectModel
|
||||
{
|
||||
$dateFrom = $params['date_from'];
|
||||
$dateTo = isset($params['date_to']) ? $params['date_to'] : $params['date_from'];
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : false;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idProduct = isset($params['id_product']) ? (int) $params['id_product'] : 0;
|
||||
$idRoom = isset($params['id_room']) ? (int) $params['id_room'] : 0;
|
||||
$idCustomer = isset($params['id_customer']) ? (int) $params['id_customer'] : 0;
|
||||
@@ -4042,7 +4053,7 @@ class HotelBookingDetail extends ObjectModel
|
||||
.($idProduct ? ' AND hbd.`id_product` = '.$idProduct : '')
|
||||
.($idRoom ? ' AND hbd.`id_room` = '.$idRoom : '')
|
||||
.($idCustomer ? ' AND hbd.`id_customer` = '.$idCustomer : '')
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd')
|
||||
.self::hotelFilter($idsHotel, 'hbd')
|
||||
);
|
||||
$current = date('Y-m-d', strtotime('+1 day', strtotime($current)));
|
||||
}
|
||||
@@ -4060,7 +4071,7 @@ class HotelBookingDetail extends ObjectModel
|
||||
{
|
||||
$dateFrom = $params['date_from'];
|
||||
$dateTo = isset($params['date_to']) ? $params['date_to'] : $params['date_from'];
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : false;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idProduct = isset($params['id_product']) ? (int) $params['id_product'] : 0;
|
||||
$idRoom = isset($params['id_room']) ? (int) $params['id_room'] : 0;
|
||||
$idCustomer = isset($params['id_customer']) ? (int) $params['id_customer'] : 0;
|
||||
@@ -4080,7 +4091,7 @@ class HotelBookingDetail extends ObjectModel
|
||||
.($idProduct ? ' AND hbd.`id_product` = '.$idProduct : '')
|
||||
.($idRoom ? ' AND hbd.`id_room` = '.$idRoom : '')
|
||||
.($idCustomer ? ' AND hbd.`id_customer` = '.$idCustomer : '')
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd')
|
||||
.self::hotelFilter($idsHotel, 'hbd')
|
||||
);
|
||||
$current = date('Y-m-d', strtotime('+1 day', strtotime($current)));
|
||||
}
|
||||
@@ -4099,7 +4110,7 @@ class HotelBookingDetail extends ObjectModel
|
||||
{
|
||||
$dateFrom = pSQL($params['date_from']);
|
||||
$dateTo = pSQL(isset($params['date_to']) ? $params['date_to'] : $params['date_from']);
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : false;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idProduct = isset($params['id_product']) ? (int) $params['id_product'] : 0;
|
||||
$idRoom = isset($params['id_room']) ? (int) $params['id_room'] : 0;
|
||||
$idCustomer = isset($params['id_customer']) ? (int) $params['id_customer'] : 0;
|
||||
@@ -4129,7 +4140,7 @@ class HotelBookingDetail extends ObjectModel
|
||||
.($idProduct ? ' AND hbd.`id_product` = '.$idProduct : '')
|
||||
.($idRoom ? ' AND hbd.`id_room` = '.$idRoom : '')
|
||||
.($idCustomer ? ' AND hbd.`id_customer` = '.$idCustomer : '')
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd')
|
||||
.self::hotelFilter($idsHotel, 'hbd')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4144,7 +4155,7 @@ class HotelBookingDetail extends ObjectModel
|
||||
{
|
||||
$dateFrom = pSQL($params['date_from']);
|
||||
$dateTo = pSQL(isset($params['date_to']) ? $params['date_to'] : $params['date_from']);
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : false;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idProduct = isset($params['id_product']) ? (int) $params['id_product'] : 0;
|
||||
$idRoom = isset($params['id_room']) ? (int) $params['id_room'] : 0;
|
||||
$idCustomer = isset($params['id_customer']) ? (int) $params['id_customer'] : 0;
|
||||
@@ -4166,7 +4177,7 @@ class HotelBookingDetail extends ObjectModel
|
||||
.($idProduct ? ' AND hbd.`id_product` = '.$idProduct : '')
|
||||
.($idRoom ? ' AND hbd.`id_room` = '.$idRoom : '')
|
||||
.($idCustomer ? ' AND hbd.`id_customer` = '.$idCustomer : '')
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd')
|
||||
.self::hotelFilter($idsHotel, 'hbd')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4182,7 +4193,7 @@ class HotelBookingDetail extends ObjectModel
|
||||
$today = pSQL(date('Y-m-d'));
|
||||
$dateFrom = isset($params['date_from']) ? pSQL($params['date_from']) : $today;
|
||||
$dateTo = isset($params['date_to']) ? pSQL($params['date_to']) : $today;
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : false;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idProduct = isset($params['id_product']) ? (int) $params['id_product'] : 0;
|
||||
$idRoom = isset($params['id_room']) ? (int) $params['id_room'] : 0;
|
||||
$idCustomer = isset($params['id_customer']) ? (int) $params['id_customer']: 0;
|
||||
@@ -4203,7 +4214,7 @@ class HotelBookingDetail extends ObjectModel
|
||||
.($idProduct ? ' AND hbd.`id_product` = '.$idProduct : '')
|
||||
.($idRoom ? ' AND hbd.`id_room` = '.$idRoom : '')
|
||||
.($idCustomer ? ' AND hbd.`id_customer` = '.$idCustomer : '')
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd')
|
||||
.self::hotelFilter($idsHotel, 'hbd')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4218,7 +4229,7 @@ class HotelBookingDetail extends ObjectModel
|
||||
{
|
||||
$dateFrom = pSQL($params['date_from']);
|
||||
$dateTo = pSQL(isset($params['date_to']) ? $params['date_to'] : $params['date_from']);
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : false;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idCustomer = isset($params['id_customer']) ? (int) $params['id_customer'] : 0;
|
||||
$idProduct = isset($params['id_product']) ? (int) $params['id_product'] : 0;
|
||||
$idStatus = isset($params['id_status']) ? (int) $params['id_status'] : 0;
|
||||
@@ -4245,6 +4256,7 @@ class HotelBookingDetail extends ObjectModel
|
||||
(o.`total_paid_tax_incl` - o.`total_paid_real`) AS balance_due,
|
||||
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`)
|
||||
FROM `'._DB_PREFIX_.'order_history` oh
|
||||
INNER JOIN `'._DB_PREFIX_.'employee` e ON (e.`id_employee` = oh.`id_employee`)
|
||||
@@ -4267,7 +4279,7 @@ class HotelBookingDetail extends ObjectModel
|
||||
.($idStatus ? ' AND hbd.`id_status` = '.$idStatus : '')
|
||||
.($bookingType ? ' AND hbd.`booking_type` = '.$bookingType : '')
|
||||
.($idOrderState ? ' AND o.`current_state` = '.$idOrderState : '')
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd').'
|
||||
.self::hotelFilter($idsHotel, 'hbd').'
|
||||
ORDER BY hbd.`date_add` DESC'
|
||||
);
|
||||
}
|
||||
@@ -4282,16 +4294,20 @@ class HotelBookingDetail extends ObjectModel
|
||||
{
|
||||
$dateFrom = pSQL($params['date_from']);
|
||||
$dateTo = pSQL(isset($params['date_to']) ? $params['date_to'] : $params['date_from']);
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : false;
|
||||
$idCustomer = isset($params['id_customer']) ? (int) $params['id_customer'] : 0;
|
||||
$bookingType = isset($params['booking_type']) ? (int) $params['booking_type'] : 0;
|
||||
$hotelRestriction = HotelBranchInformation::addHotelRestriction($idHotel, 'hbd');
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idCustomer = isset($params['id_customer']) ? (int) $params['id_customer'] : 0;
|
||||
$bookingSource = isset($params['booking_source']) ? pSQL($params['booking_source']) : '';
|
||||
$hotelRestriction = self::hotelFilter($idsHotel, 'hbd');
|
||||
|
||||
$dateToNext = pSQL(date('Y-m-d', strtotime('+1 day', strtotime($dateTo))));
|
||||
|
||||
$sourceFilter = $bookingSource
|
||||
? ' WHERE per_order.`order_source` = \''.$bookingSource.'\''
|
||||
: '';
|
||||
|
||||
$rows = Db::getInstance()->executeS(
|
||||
'SELECT
|
||||
per_order.`booking_type`,
|
||||
per_order.`order_source`,
|
||||
COUNT(*) AS bookings,
|
||||
SUM(per_order.`rooms_booked`) AS rooms_booked,
|
||||
SUM(per_order.`room_nights`) AS room_nights,
|
||||
@@ -4303,7 +4319,8 @@ class HotelBookingDetail extends ObjectModel
|
||||
SUM(per_order.`cancelled_rooms`) AS cancellations
|
||||
FROM (
|
||||
SELECT
|
||||
hbd.`id_order`, hbd.`booking_type`,
|
||||
hbd.`id_order`,
|
||||
IFNULL(NULLIF(o.`source`, \'\'), \'(direct)\') AS order_source,
|
||||
SUM(CASE WHEN hbd.`is_cancelled` = 0 AND hbd.`is_refunded` = 0 THEN 1 ELSE 0 END) AS rooms_booked,
|
||||
SUM(CASE WHEN hbd.`is_cancelled` = 0 AND hbd.`is_refunded` = 0
|
||||
THEN DATEDIFF(hbd.`date_to`, hbd.`date_from`) ELSE 0 END) AS room_nights,
|
||||
@@ -4324,24 +4341,18 @@ class HotelBookingDetail extends ObjectModel
|
||||
) ord_ref ON (ord_ref.`id_order` = hbd.`id_order`)
|
||||
WHERE hbd.`date_from` < "'.$dateToNext.'"
|
||||
AND hbd.`date_to` > "'.$dateFrom.'"'
|
||||
.($idCustomer ? ' AND hbd.`id_customer` = '.$idCustomer : '')
|
||||
.($bookingType ? ' AND hbd.`booking_type` = '.$bookingType : '')
|
||||
.($idCustomer ? ' AND hbd.`id_customer` = '.$idCustomer : '')
|
||||
.$hotelRestriction.'
|
||||
GROUP BY hbd.`id_order`
|
||||
) AS per_order
|
||||
GROUP BY per_order.`booking_type`
|
||||
) AS per_order'
|
||||
.$sourceFilter.'
|
||||
GROUP BY per_order.`order_source`
|
||||
ORDER BY revenue_incl DESC'
|
||||
);
|
||||
|
||||
$moduleInstance = Module::getInstanceByName('hotelreservationsystem');
|
||||
$labels = array(
|
||||
self::ALLOTMENT_AUTO => $moduleInstance->l('Online / Direct', 'hotelreservationsystem'),
|
||||
self::ALLOTMENT_MANUAL => $moduleInstance->l('Walk-in / Admin', 'hotelreservationsystem'),
|
||||
);
|
||||
$totalRevExcl = array_sum(array_column($rows, 'revenue_excl'));
|
||||
foreach ($rows as &$row) {
|
||||
$type = (int) $row['booking_type'];
|
||||
$row['channel_label'] = isset($labels[$type]) ? $labels[$type] : $moduleInstance->l('Other', 'hotelreservationsystem');
|
||||
$row['channel_label'] = $row['order_source'];
|
||||
$row['tax_amount'] = (float) $row['revenue_incl'] - (float) $row['revenue_excl'];
|
||||
$row['net_revenue'] = (float) $row['revenue_excl'] - (float) $row['discount_amount'];
|
||||
$row['adr'] = (float) $row['room_nights'] > 0
|
||||
@@ -4365,7 +4376,7 @@ class HotelBookingDetail extends ObjectModel
|
||||
{
|
||||
$dateFrom = pSQL($params['date_from']);
|
||||
$dateTo = pSQL(isset($params['date_to']) ? $params['date_to'] : $params['date_from']);
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : false;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idCustomer = isset($params['id_customer']) ? (int) $params['id_customer'] : 0;
|
||||
$bookingType = isset($params['booking_type']) ? (int) $params['booking_type'] : 0;
|
||||
|
||||
@@ -4381,7 +4392,7 @@ class HotelBookingDetail extends ObjectModel
|
||||
AND hbd.`date_add` BETWEEN "'.$dateFrom.' 00:00:00" AND "'.$dateTo.' 23:59:59"'
|
||||
.($idCustomer ? ' AND hbd.`id_customer` = '.$idCustomer : '')
|
||||
.($bookingType ? ' AND hbd.`booking_type` = '.$bookingType : '')
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd').'
|
||||
.self::hotelFilter($idsHotel, 'hbd').'
|
||||
GROUP BY o.`payment`, o.`module`
|
||||
ORDER BY revenue_incl DESC'
|
||||
);
|
||||
@@ -4398,10 +4409,10 @@ class HotelBookingDetail extends ObjectModel
|
||||
{
|
||||
$dateFrom = pSQL($params['date_from']);
|
||||
$dateTo = pSQL(isset($params['date_to']) ? $params['date_to'] : $params['date_from']);
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : false;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idProduct = isset($params['id_product']) ? (int) $params['id_product'] : 0;
|
||||
$idTax = isset($params['id_tax']) ? (int) $params['id_tax'] : 0;
|
||||
$revenueSource = isset($params['revenue_source']) ? $params['revenue_source'] : 'room';
|
||||
$revenueSource = isset($params['revenue_source']) ? $params['revenue_source'] : 'all';
|
||||
$idLang = isset($params['id_lang']) ? (int) $params['id_lang'] : 0;
|
||||
if (!$idLang) {
|
||||
$idLang = Context::getContext()->language->id;
|
||||
@@ -4425,7 +4436,7 @@ class HotelBookingDetail extends ObjectModel
|
||||
WHERE hbd.`date_add` BETWEEN "'.$dateFrom.' 00:00:00" AND "'.$dateTo.' 23:59:59"'
|
||||
.($idProduct ? ' AND hbd.`id_product` = '.$idProduct : '')
|
||||
.($idTax ? ' AND t.`id_tax` = '.$idTax : '')
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd');
|
||||
.self::hotelFilter($idsHotel, 'hbd');
|
||||
|
||||
if ($revenueSource === 'service') {
|
||||
return ServiceProductOrderDetail::getTaxBreakdown($params);
|
||||
@@ -4457,7 +4468,7 @@ class HotelBookingDetail extends ObjectModel
|
||||
{
|
||||
$dateFrom = pSQL($params['date_from']);
|
||||
$dateTo = pSQL(isset($params['date_to']) ? $params['date_to'] : $params['date_from']);
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : null;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idCustomer = isset($params['id_customer']) ? (int) $params['id_customer'] : 0;
|
||||
$idProduct = isset($params['id_product']) ? (int) $params['id_product'] : 0;
|
||||
$idLang = Context::getContext()->language->id;
|
||||
@@ -4501,8 +4512,8 @@ class HotelBookingDetail extends ObjectModel
|
||||
AND orr.`date_add` BETWEEN "'.$dateFrom.' 00:00:00" AND "'.$dateTo.' 23:59:59"'
|
||||
. ($idCustomer ? ' AND hbd.`id_customer` = '.$idCustomer : '')
|
||||
. ($idProduct ? ' AND hbd.`id_product` = '.$idProduct : '')
|
||||
. HotelBranchInformation::addHotelRestriction($idHotel, 'hbd').'
|
||||
GROUP BY ord.`id_htl_booking`
|
||||
. self::hotelFilter($idsHotel, 'hbd').'
|
||||
GROUP BY ord.`id_htl_booking`, orr.`id_order_return`
|
||||
ORDER BY orr.`date_add` DESC'
|
||||
);
|
||||
}
|
||||
@@ -4526,62 +4537,28 @@ class HotelBookingDetail extends ObjectModel
|
||||
*/
|
||||
public static function getDatewiseCancellations(array $params)
|
||||
{
|
||||
$dateFrom = $params['date_from'];
|
||||
$dateTo = isset($params['date_to']) ? $params['date_to'] : $params['date_from'];
|
||||
|
||||
$result = array();
|
||||
$current = $dateFrom;
|
||||
while ($current <= $dateTo) {
|
||||
$result[strtotime($current)] = 0;
|
||||
$current = date('Y-m-d', strtotime('+1 day', strtotime($current)));
|
||||
}
|
||||
|
||||
$rows = self::getCancellations(array_merge($params, array('detailed_info' => true)));
|
||||
$result = array();
|
||||
$rows = self::getCancellations(array_merge($params, array('detailed_info' => true)));
|
||||
foreach ($rows as $row) {
|
||||
$ts = strtotime(date('Y-m-d', strtotime($row['cancellation_date'])));
|
||||
if (isset($result[$ts])) {
|
||||
$result[$ts]++;
|
||||
}
|
||||
$result[$ts] = isset($result[$ts]) ? $result[$ts] + 1 : 1;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count of distinct orders (new bookings) created in a date range.
|
||||
*
|
||||
* @param array $params date_from, date_to, id_hotel, id_product, id_customer, granularity ('day'|'month'|false)
|
||||
* @return int|array
|
||||
* @param array $params date_from, date_to, id_hotel, id_product, id_customer
|
||||
* @return int
|
||||
*/
|
||||
public static function getTotalBookings(array $params)
|
||||
{
|
||||
$dateFrom = pSQL($params['date_from']);
|
||||
$dateTo = pSQL(isset($params['date_to']) ? $params['date_to'] : $params['date_from']);
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : false;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idProduct = isset($params['id_product']) ? (int) $params['id_product'] : 0;
|
||||
$idCustomer = isset($params['id_customer']) ? (int) $params['id_customer']: 0;
|
||||
$granularity = isset($params['granularity']) ? $params['granularity'] : false;
|
||||
|
||||
if ($granularity === 'day') {
|
||||
return self::getDatewiseBookings($params);
|
||||
}
|
||||
|
||||
if ($granularity === 'month') {
|
||||
$rows = Db::getInstance()->executeS(
|
||||
'SELECT LEFT(hbd.`date_add`, 7) AS grp, COUNT(DISTINCT hbd.`id_order`) AS cnt
|
||||
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
WHERE hbd.`date_add` BETWEEN "'.$dateFrom.' 00:00:00" AND "'.$dateTo.' 23:59:59"'
|
||||
.($idProduct ? ' AND hbd.`id_product` = '.$idProduct : '')
|
||||
.($idCustomer ? ' AND hbd.`id_customer` = '.$idCustomer : '')
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd').'
|
||||
GROUP BY LEFT(hbd.`date_add`, 7)'
|
||||
);
|
||||
$result = array();
|
||||
foreach ($rows as $row) {
|
||||
$result[strtotime($row['grp'].'-01')] = (int) $row['cnt'];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
$countExpr = (isset($params['count_rows']) && $params['count_rows'])
|
||||
? 'hbd.`id`'
|
||||
@@ -4593,7 +4570,7 @@ class HotelBookingDetail extends ObjectModel
|
||||
WHERE hbd.`date_add` BETWEEN "'.$dateFrom.' 00:00:00" AND "'.$dateTo.' 23:59:59"'
|
||||
.($idProduct ? ' AND hbd.`id_product` = '.$idProduct : '')
|
||||
.($idCustomer ? ' AND hbd.`id_customer` = '.$idCustomer : '')
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd')
|
||||
.self::hotelFilter($idsHotel, 'hbd')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4607,8 +4584,9 @@ class HotelBookingDetail extends ObjectModel
|
||||
{
|
||||
$dateFrom = pSQL($params['date_from']);
|
||||
$dateTo = pSQL(isset($params['date_to']) ? $params['date_to'] : $params['date_from']);
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : false;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idProduct = isset($params['id_product']) ? (int) $params['id_product'] : 0;
|
||||
$idRoom = isset($params['id_room']) ? (int) $params['id_room'] : 0;
|
||||
|
||||
return (int) Db::getInstance()->getValue(
|
||||
'SELECT IFNULL(SUM(DATEDIFF(hbd.`date_to`, hbd.`date_from`)), 0)
|
||||
@@ -4621,7 +4599,8 @@ class HotelBookingDetail extends ObjectModel
|
||||
AND hbd.`is_cancelled` = 0
|
||||
AND o.`invoice_date` BETWEEN "'.$dateFrom.' 00:00:00" AND "'.$dateTo.' 23:59:59"'
|
||||
.($idProduct ? ' AND hbd.`id_product` = '.$idProduct : '')
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd')
|
||||
.($idRoom ? ' AND hbd.`id_room` = '.$idRoom : '')
|
||||
.self::hotelFilter($idsHotel, 'hbd')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4635,7 +4614,7 @@ class HotelBookingDetail extends ObjectModel
|
||||
{
|
||||
$dateFrom = $params['date_from'];
|
||||
$dateTo = isset($params['date_to']) ? $params['date_to'] : $params['date_from'];
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : false;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idProduct = isset($params['id_product']) ? (int) $params['id_product'] : 0;
|
||||
$idCustomer = isset($params['id_customer']) ? (int) $params['id_customer'] : 0;
|
||||
|
||||
@@ -4649,7 +4628,7 @@ class HotelBookingDetail extends ObjectModel
|
||||
WHERE hbd.`date_add` BETWEEN "'.pSQL($current).' 00:00:00" AND "'.pSQL($current).' 23:59:59"'
|
||||
.($idProduct ? ' AND hbd.`id_product` = '.$idProduct : '')
|
||||
.($idCustomer ? ' AND hbd.`id_customer` = '.$idCustomer : '')
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd')
|
||||
.self::hotelFilter($idsHotel, 'hbd')
|
||||
);
|
||||
$current = date('Y-m-d', strtotime('+1 day', strtotime($current)));
|
||||
}
|
||||
@@ -4663,20 +4642,15 @@ class HotelBookingDetail extends ObjectModel
|
||||
* @param array $params date_from, date_to, id_hotel, id_status (optional)
|
||||
* @return array [$timestamp => int]
|
||||
*/
|
||||
public static function getOccupiedRoomsForDiscreteDates(array $params)
|
||||
public static function getDatewiseOccupiedRooms(array $params)
|
||||
{
|
||||
$dateFrom = $params['date_from'];
|
||||
$dateTo = isset($params['date_to']) ? $params['date_to'] : $params['date_from'];
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : null;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idStatus = isset($params['id_status']) ? (int) $params['id_status'] : null;
|
||||
$idProduct = isset($params['id_product']) ? (int) $params['id_product'] : 0;
|
||||
|
||||
// Delegate to AdminStatsController only when no additional filters need own SQL
|
||||
if ($idStatus === null && !$idProduct) {
|
||||
return AdminStatsController::getOccupiedRoomsForDiscreteDates($dateFrom, $dateTo, $idHotel ?: null);
|
||||
}
|
||||
|
||||
$hotelFilter = HotelBranchInformation::addHotelRestriction($idHotel, 'hbd');
|
||||
$hotelFilter = self::hotelFilter($idsHotel, 'hbd');
|
||||
$statusFilter = $idStatus !== null ? ' AND hbd.`id_status` = '.$idStatus : '';
|
||||
$productFilter = $idProduct ? ' AND hri.`id_product` = '.$idProduct : '';
|
||||
$result = array();
|
||||
@@ -4722,20 +4696,6 @@ class HotelBookingDetail extends ObjectModel
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Per-day room revenue (excl. tax). Thin wrapper over getDatewiseRoomRevenueTax.
|
||||
*
|
||||
* @param array $params same as getDatewiseRoomRevenueTax
|
||||
* @return array [$timestamp => float]
|
||||
*/
|
||||
public static function getDatewiseRoomRevenue(array $params)
|
||||
{
|
||||
$result = array();
|
||||
foreach (self::getDatewiseRoomRevenueTax($params) as $ts => $day) {
|
||||
$result[$ts] = $day['room_revenue'];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
/**
|
||||
* Returns all Guest Registration Card sections and their fields.
|
||||
* Modules may add, remove, or reorder sections/fields via the hook.
|
||||
|
||||
@@ -332,6 +332,28 @@ class HotelRoomInformation extends ObjectModel
|
||||
|
||||
// ── REPORT METHODS ────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Builds the hotel WHERE fragment for report queries.
|
||||
*
|
||||
* @param int|array|false $idsHotel
|
||||
* @param string $alias
|
||||
* @return string
|
||||
*/
|
||||
private static function hotelFilter($idsHotel, $alias)
|
||||
{
|
||||
if (defined('_PS_ADMIN_DIR_')) {
|
||||
return HotelBranchInformation::addHotelRestriction($idsHotel, $alias);
|
||||
}
|
||||
if (!$idsHotel) {
|
||||
return '';
|
||||
}
|
||||
$ids = array_filter(array_map('intval', is_array($idsHotel) ? $idsHotel : array($idsHotel)));
|
||||
if (!$ids) {
|
||||
return '';
|
||||
}
|
||||
return ' AND `'.bqSQL($alias).'`.`id_hotel` IN ('.implode(',', $ids).')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Room type list for filter dropdowns in reports.
|
||||
*
|
||||
@@ -340,7 +362,7 @@ class HotelRoomInformation extends ObjectModel
|
||||
*/
|
||||
public static function getRoomTypes(array $params)
|
||||
{
|
||||
$idHotel = isset($params['id_hotel']) ? (int) $params['id_hotel'] : 0;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idLang = !empty($params['id_lang']) ? (int) $params['id_lang'] : (int) Context::getContext()->language->id;
|
||||
|
||||
return Db::getInstance()->executeS(
|
||||
@@ -350,7 +372,7 @@ class HotelRoomInformation extends ObjectModel
|
||||
INNER JOIN `'._DB_PREFIX_.'product_lang` pl
|
||||
ON (pl.`id_product` = p.`id_product` AND pl.`id_lang` = '.$idLang.')
|
||||
WHERE p.`active` = 1 AND p.`booking_product` = 1'
|
||||
. ($idHotel ? ' AND hri.`id_hotel` = '.$idHotel : '')
|
||||
. self::hotelFilter($idsHotel, 'hri')
|
||||
. ' ORDER BY pl.`name`'
|
||||
);
|
||||
}
|
||||
@@ -366,7 +388,7 @@ class HotelRoomInformation extends ObjectModel
|
||||
{
|
||||
$dateFrom = pSQL($params['date_from']);
|
||||
$dateTo = pSQL(isset($params['date_to']) ? $params['date_to'] : $params['date_from']);
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : false;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idProduct = isset($params['id_product']) ? (int) $params['id_product'] : 0;
|
||||
$idLang = isset($params['id_lang']) ? (int) $params['id_lang'] : 0;
|
||||
if (!$idLang) {
|
||||
@@ -382,7 +404,7 @@ class HotelRoomInformation extends ObjectModel
|
||||
INNER JOIN `'._DB_PREFIX_.'product_lang` pl
|
||||
ON (pl.`id_product` = hri.`id_product` AND pl.`id_lang` = '.(int) $idLang.')
|
||||
WHERE 1'
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hri')
|
||||
.self::hotelFilter($idsHotel, 'hri')
|
||||
.($idProduct ? ' AND hri.`id_product` = '.$idProduct : '').'
|
||||
GROUP BY hri.`id_product`'
|
||||
);
|
||||
@@ -398,7 +420,7 @@ class HotelRoomInformation extends ObjectModel
|
||||
INNER JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = hbd.`id_order` AND o.`valid` = 1)
|
||||
WHERE hbd.`is_refunded` = 0 AND hbd.`is_cancelled` = 0
|
||||
AND hbd.`date_from` < "'.$dateToNext.'" AND hbd.`date_to` > "'.$dateFrom.'"'
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd')
|
||||
.self::hotelFilter($idsHotel, 'hbd')
|
||||
.($idProduct ? ' AND hbd.`id_product` = '.$idProduct : '')
|
||||
);
|
||||
|
||||
@@ -448,12 +470,12 @@ class HotelRoomInformation extends ObjectModel
|
||||
* @param array $params date_from, date_to, id_hotel, id_product, id_lang, housekeeping_installed
|
||||
* @return array
|
||||
*/
|
||||
public static function getRoomStatusForReports(array $params)
|
||||
public static function getRoomStatus(array $params)
|
||||
{
|
||||
$dateFrom = pSQL($params['date_from']);
|
||||
$dateTo = pSQL(isset($params['date_to']) ? $params['date_to'] : $params['date_from']);
|
||||
$dateToNext = pSQL(date('Y-m-d', strtotime('+1 day', strtotime($dateTo))));
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : false;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idProduct = isset($params['id_product']) ? (int) $params['id_product'] : 0;
|
||||
$idLang = isset($params['id_lang']) ? (int) $params['id_lang'] : 0;
|
||||
$housekeepingInstalled = !empty($params['housekeeping_installed']);
|
||||
@@ -500,7 +522,7 @@ class HotelRoomInformation extends ObjectModel
|
||||
LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = bkgs.`id_customer`)
|
||||
WHERE p.`active` = 1 AND p.`booking_product` = 1'
|
||||
.($idProduct ? ' AND hri.`id_product` = '.$idProduct : '')
|
||||
.($idHotel ? HotelBranchInformation::addHotelRestriction($idHotel, 'hri') : '').'
|
||||
.self::hotelFilter($idsHotel, 'hri').'
|
||||
ORDER BY hbil.`hotel_name`, pl.`name`, hri.`room_num`'
|
||||
);
|
||||
}
|
||||
@@ -513,7 +535,7 @@ class HotelRoomInformation extends ObjectModel
|
||||
*/
|
||||
public static function getDistinctFloors(array $params = array())
|
||||
{
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : false;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idProduct = isset($params['id_product']) ? (int) $params['id_product'] : 0;
|
||||
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
|
||||
@@ -523,7 +545,7 @@ class HotelRoomInformation extends ObjectModel
|
||||
ON (p.`id_product` = hri.`id_product` AND p.`active` = 1 AND p.`booking_product` = 1)
|
||||
WHERE hri.`floor` != "" AND hri.`floor` IS NOT NULL'
|
||||
.($idProduct ? ' AND hri.`id_product` = '.$idProduct : '')
|
||||
.($idHotel ? HotelBranchInformation::addHotelRestriction($idHotel, 'hri') : '').'
|
||||
.self::hotelFilter($idsHotel, 'hri').'
|
||||
ORDER BY hri.`floor`'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -458,6 +458,28 @@ class HotelRoomType extends ObjectModel
|
||||
|
||||
// ── REPORT METHODS ────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Builds the hotel WHERE fragment for report queries.
|
||||
*
|
||||
* @param int|array|false $idsHotel
|
||||
* @param string $alias
|
||||
* @return string
|
||||
*/
|
||||
private static function hotelFilter($idsHotel, $alias)
|
||||
{
|
||||
if (defined('_PS_ADMIN_DIR_')) {
|
||||
return HotelBranchInformation::addHotelRestriction($idsHotel, $alias);
|
||||
}
|
||||
if (!$idsHotel) {
|
||||
return '';
|
||||
}
|
||||
$ids = array_filter(array_map('intval', is_array($idsHotel) ? $idsHotel : array($idsHotel)));
|
||||
if (!$ids) {
|
||||
return '';
|
||||
}
|
||||
return ' AND `'.bqSQL($alias).'`.`id_hotel` IN ('.implode(',', $ids).')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Performance metrics per room type: revenue, ADR, RevPAR, occupancy, LOS.
|
||||
* Used by room-type performance report tab.
|
||||
@@ -469,7 +491,7 @@ class HotelRoomType extends ObjectModel
|
||||
{
|
||||
$dateFrom = pSQL($params['date_from']);
|
||||
$dateTo = pSQL(isset($params['date_to']) ? $params['date_to'] : $params['date_from']);
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : false;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idProduct = isset($params['id_product']) ? (int) $params['id_product'] : 0;
|
||||
$idLang = isset($params['id_lang']) ? (int) $params['id_lang'] : 0;
|
||||
if (!$idLang) {
|
||||
@@ -504,7 +526,7 @@ class HotelRoomType extends ObjectModel
|
||||
LEFT JOIN `'._DB_PREFIX_.'orders` o
|
||||
ON (o.`id_order` = hbd.`id_order` AND o.`valid` = 1)
|
||||
WHERE p.`active` = 1 AND p.`booking_product` = 1'
|
||||
.($idHotel ? HotelBranchInformation::addHotelRestriction($idHotel, 'hrt') : '')
|
||||
.self::hotelFilter($idsHotel, 'hrt')
|
||||
.($idProduct ? ' AND hrt.`id_product` = '.$idProduct : '').'
|
||||
GROUP BY hrt.`id_product`, hrt.`id_hotel`
|
||||
ORDER BY room_revenue DESC'
|
||||
|
||||
@@ -584,25 +584,46 @@ class ServiceProductOrderDetail extends ObjectModel
|
||||
|
||||
// ── REPORT METHODS ────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Builds the hotel WHERE fragment for report queries.
|
||||
*
|
||||
* @param int|array|false $idsHotel
|
||||
* @param string $alias
|
||||
* @return string
|
||||
*/
|
||||
private static function hotelFilter($idsHotel, $alias)
|
||||
{
|
||||
if (defined('_PS_ADMIN_DIR_')) {
|
||||
return HotelBranchInformation::addHotelRestriction($idsHotel, $alias);
|
||||
}
|
||||
if (!$idsHotel) {
|
||||
return '';
|
||||
}
|
||||
$ids = array_filter(array_map('intval', is_array($idsHotel) ? $idsHotel : array($idsHotel)));
|
||||
if (!$ids) {
|
||||
return '';
|
||||
}
|
||||
return ' AND `'.bqSQL($alias).'`.`id_hotel` IN ('.implode(',', $ids).')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Total service revenue (tax excl) for a date range, filtered by invoice_date.
|
||||
*
|
||||
* @param array $params date_from, date_to, id_hotel, id_product, id_room, id_order,
|
||||
* id_customer, id_category, id_service_product, granularity ('day'|'month'|false), id_lang
|
||||
* @return float|array
|
||||
* id_customer, id_category, id_service_product, id_lang
|
||||
* @return float
|
||||
*/
|
||||
public static function getTotalServiceRevenue(array $params)
|
||||
public static function getTotalRevenue(array $params)
|
||||
{
|
||||
$dateFrom = pSQL($params['date_from']);
|
||||
$dateTo = pSQL(isset($params['date_to']) ? $params['date_to'] : $params['date_from']);
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : false;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idProduct = isset($params['id_product']) ? (int) $params['id_product'] : 0;
|
||||
$idRoom = isset($params['id_room']) ? (int) $params['id_room'] : 0;
|
||||
$idOrder = isset($params['id_order']) ? (int) $params['id_order'] : 0;
|
||||
$idCustomer = isset($params['id_customer']) ? (int) $params['id_customer'] : 0;
|
||||
$idCategory = isset($params['id_category']) ? (int) $params['id_category'] : 0;
|
||||
$idServiceProduct = isset($params['id_service_product']) ? (int) $params['id_service_product'] : 0;
|
||||
$granularity = isset($params['granularity']) ? $params['granularity'] : false;
|
||||
$idLang = isset($params['id_lang']) ? (int) $params['id_lang'] : 0;
|
||||
if (!$idLang) {
|
||||
$idLang = Context::getContext()->language->id;
|
||||
@@ -629,23 +650,7 @@ class ServiceProductOrderDetail extends ObjectModel
|
||||
.($idCustomer ? ' AND hbd.`id_customer` = '.$idCustomer : '')
|
||||
.($idServiceProduct ? ' AND spod.`id_product` = '.$idServiceProduct : '')
|
||||
.($idCategory ? ' AND spod.`id_product` IN (SELECT `id_product` FROM `'._DB_PREFIX_.'product` WHERE `id_category_default` = '.$idCategory.')' : '')
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd');
|
||||
|
||||
if ($granularity === 'day' || $granularity === 'month') {
|
||||
$groupLen = $granularity === 'month' ? 7 : 10;
|
||||
$tsSuffix = $granularity === 'month' ? '-01' : '';
|
||||
$rows = Db::getInstance()->executeS(
|
||||
'SELECT LEFT(o.`invoice_date`, '.$groupLen.') AS grp,
|
||||
IFNULL(SUM(spod.`total_price_tax_excl` / o.`conversion_rate`), 0) AS amt
|
||||
'.$baseFrom.' '.$baseWhere.'
|
||||
GROUP BY LEFT(o.`invoice_date`, '.$groupLen.')'
|
||||
);
|
||||
$result = array();
|
||||
foreach ($rows as $row) {
|
||||
$result[strtotime($row['grp'].$tsSuffix)] = (float) $row['amt'];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
.self::hotelFilter($idsHotel, 'hbd');
|
||||
|
||||
return (float) Db::getInstance()->getValue(
|
||||
'SELECT IFNULL(SUM(spod.`total_price_tax_excl` / o.`conversion_rate`), 0)
|
||||
@@ -665,7 +670,7 @@ class ServiceProductOrderDetail extends ObjectModel
|
||||
{
|
||||
$dateFrom = pSQL($params['date_from']);
|
||||
$dateTo = pSQL(isset($params['date_to']) ? $params['date_to'] : $params['date_from']);
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : false;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idProduct = isset($params['id_product']) ? (int) $params['id_product'] : 0;
|
||||
$idRoom = isset($params['id_room']) ? (int) $params['id_room'] : 0;
|
||||
$idOrder = isset($params['id_order']) ? (int) $params['id_order'] : 0;
|
||||
@@ -698,7 +703,7 @@ class ServiceProductOrderDetail extends ObjectModel
|
||||
.($idCustomer ? ' AND hbd.`id_customer` = '.$idCustomer : '')
|
||||
.($idServiceProduct ? ' AND spod.`id_product` = '.$idServiceProduct : '')
|
||||
.($idCategory ? ' AND spod.`id_product` IN (SELECT `id_product` FROM `'._DB_PREFIX_.'product` WHERE `id_category_default` = '.$idCategory.')' : '')
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd');
|
||||
.self::hotelFilter($idsHotel, 'hbd');
|
||||
|
||||
return Db::getInstance()->executeS(
|
||||
'SELECT spod.`id_service_product_order_detail`, spod.`date_add`,
|
||||
@@ -728,13 +733,13 @@ class ServiceProductOrderDetail extends ObjectModel
|
||||
* Used by revenue report daily table.
|
||||
*
|
||||
* @param array $params date_from, date_to, id_hotel, id_product, id_room, id_order, id_customer
|
||||
* @return array timestamp => ['service_revenue' => float, 'tax_amount' => float]
|
||||
* @return array timestamp => ['service_revenue' => float, 'total_tax' => float]
|
||||
*/
|
||||
public static function getDatewiseServiceRevenueTax(array $params)
|
||||
public static function getDatewiseRevenue(array $params)
|
||||
{
|
||||
$dateFrom = $params['date_from'];
|
||||
$dateTo = isset($params['date_to']) ? $params['date_to'] : $params['date_from'];
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : false;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idProduct = isset($params['id_product']) ? (int) $params['id_product'] : 0;
|
||||
$idRoom = isset($params['id_room']) ? (int) $params['id_room'] : 0;
|
||||
$idOrder = isset($params['id_order']) ? (int) $params['id_order'] : 0;
|
||||
@@ -747,7 +752,7 @@ class ServiceProductOrderDetail extends ObjectModel
|
||||
.($idRoom ? ' AND hbd.`id_room` = '.$idRoom : '')
|
||||
.($idOrder ? ' AND hbd.`id_order` = '.$idOrder : '')
|
||||
.($idCustomer ? ' AND hbd.`id_customer` = '.$idCustomer : '')
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd');
|
||||
.self::hotelFilter($idsHotel, 'hbd');
|
||||
|
||||
$joins =
|
||||
'FROM `'._DB_PREFIX_.'service_product_order_detail` spod
|
||||
@@ -759,7 +764,7 @@ class ServiceProductOrderDetail extends ObjectModel
|
||||
$rows = Db::getInstance()->executeS(
|
||||
'SELECT DATE(o.`date_add`) AS grp_date,
|
||||
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 tax_amount
|
||||
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
|
||||
@@ -771,7 +776,7 @@ class ServiceProductOrderDetail extends ObjectModel
|
||||
$ts = strtotime($row['grp_date']);
|
||||
$result[$ts] = array(
|
||||
'service_revenue' => (float) $row['service_revenue'],
|
||||
'tax_amount' => (float) $row['tax_amount'],
|
||||
'total_tax' => (float) $row['total_tax'],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -834,7 +839,7 @@ class ServiceProductOrderDetail extends ObjectModel
|
||||
{
|
||||
$dateFrom = pSQL($params['date_from']);
|
||||
$dateTo = pSQL(isset($params['date_to']) ? $params['date_to'] : $params['date_from']);
|
||||
$idHotel = isset($params['id_hotel']) ? $params['id_hotel'] : false;
|
||||
$idsHotel = isset($params['ids_hotel']) ? $params['ids_hotel'] : (isset($params['id_hotel']) ? $params['id_hotel'] : false);
|
||||
$idTax = isset($params['id_tax']) ? (int) $params['id_tax'] : 0;
|
||||
$idLang = isset($params['id_lang']) ? (int) $params['id_lang'] : 0;
|
||||
if (!$idLang) {
|
||||
@@ -862,7 +867,7 @@ class ServiceProductOrderDetail extends ObjectModel
|
||||
AND (spod.`total_price_tax_incl` - spod.`total_price_tax_excl`) > 0
|
||||
AND spod.`date_add` BETWEEN "'.$dateFrom.' 00:00:00" AND "'.$dateTo.' 23:59:59"'
|
||||
.($idTax ? ' AND t.`id_tax` = '.$idTax : '')
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd').'
|
||||
.self::hotelFilter($idsHotel, 'hbd').'
|
||||
GROUP BY spod.`id_service_product_order_detail`
|
||||
ORDER BY spod.`date_add` ASC'
|
||||
);
|
||||
|
||||
@@ -376,14 +376,13 @@ class QloHotelReports extends Module
|
||||
));
|
||||
|
||||
if ($report === 'revenue') {
|
||||
$dailyRoomDetailed = HotelBookingDetail::getDatewiseRoomRevenueTax(array_merge($baseParams, array('date_type' => 'created')));
|
||||
$dailyServiceData = ServiceProductOrderDetail::getDatewiseServiceRevenueTax($baseParams);
|
||||
$dailyBookings = HotelBookingDetail::getTotalBookings(array(
|
||||
$dailyRoomDetailed = HotelBookingDetail::getDatewiseSummary($baseParams);
|
||||
$dailyServiceData = ServiceProductOrderDetail::getDatewiseRevenue($baseParams);
|
||||
$dailyBookings = HotelBookingDetail::getDatewiseBookings(array(
|
||||
'date_from' => $dateFrom,
|
||||
'date_to' => $dateTo,
|
||||
'id_hotel' => $idHotel ?: false,
|
||||
'id_product' => $idProduct,
|
||||
'granularity' => 'day',
|
||||
));
|
||||
$dailyRefunds = HotelBookingDetail::getDatewiseRefunds($baseParams);
|
||||
|
||||
@@ -399,10 +398,10 @@ class QloHotelReports extends Module
|
||||
while ($curDate <= $dateTo) {
|
||||
$timestamp = strtotime($curDate);
|
||||
$roomData = isset($dailyRoomDetailed[$timestamp]) ? $dailyRoomDetailed[$timestamp]
|
||||
: array('room_revenue' => 0.0, 'tax_amount' => 0.0, 'rooms_booked' => 0, 'room_nights' => 0);
|
||||
$svcDay = isset($dailyServiceData[$timestamp]) ? $dailyServiceData[$timestamp] : array('service_revenue' => 0.0, 'tax_amount' => 0.0);
|
||||
$roomRev = $roomData['room_revenue'];
|
||||
$taxAmt = $roomData['tax_amount'] + $svcDay['tax_amount'];
|
||||
: array('total_price_tax_excl' => 0.0, 'total_tax' => 0.0, 'rooms_booked' => 0, 'room_nights' => 0);
|
||||
$svcDay = isset($dailyServiceData[$timestamp]) ? $dailyServiceData[$timestamp] : array('service_revenue' => 0.0, 'total_tax' => 0.0);
|
||||
$roomRev = $roomData['total_price_tax_excl'];
|
||||
$taxAmt = $roomData['total_tax'] + $svcDay['total_tax'];
|
||||
$svcRev = $svcDay['service_revenue'];
|
||||
$refund = isset($dailyRefunds[$timestamp]) ? (float) $dailyRefunds[$timestamp] : 0.0;
|
||||
$bkgs = isset($dailyBookings[$timestamp]) ? $dailyBookings[$timestamp] : 0;
|
||||
@@ -566,22 +565,22 @@ class QloHotelReports extends Module
|
||||
));
|
||||
|
||||
if ($report === 'occupancy') {
|
||||
$dailyOccupied = HotelBookingDetail::getOccupiedRoomsForDiscreteDates($baseParams);
|
||||
$dailyBooked = HotelBookingDetail::getOccupiedRoomsForDiscreteDates(
|
||||
$dailyOccupied = HotelBookingDetail::getDatewiseOccupiedRooms($baseParams);
|
||||
$dailyBooked = HotelBookingDetail::getDatewiseOccupiedRooms(
|
||||
array_merge($baseParams, array('id_status' => HotelBookingDetail::STATUS_ALLOTED))
|
||||
);
|
||||
$dailyCheckedIn = HotelBookingDetail::getOccupiedRoomsForDiscreteDates(
|
||||
$dailyCheckedIn = HotelBookingDetail::getDatewiseOccupiedRooms(
|
||||
array_merge($baseParams, array('id_status' => HotelBookingDetail::STATUS_CHECKED_IN))
|
||||
);
|
||||
|
||||
if ($idProduct) {
|
||||
$totalRooms = (int) AdminStatsController::getTotalRooms($idHotel ?: null, 1, $idProduct);
|
||||
$dailyRevenue = HotelBookingDetail::getDatewiseRoomRevenue($baseParams);
|
||||
$dailyRevenue = HotelBookingDetail::getDatewiseRevenue($baseParams);
|
||||
$dailyAvailable = array();
|
||||
$dailyAdr = array();
|
||||
foreach ($dailyOccupied as $ts => $occ) {
|
||||
$dailyAvailable[$ts] = max(0, $totalRooms - $occ);
|
||||
$rev = isset($dailyRevenue[$ts]) ? (float) $dailyRevenue[$ts] : 0.0;
|
||||
$rev = isset($dailyRevenue[$ts]) ? (float) $dailyRevenue[$ts]['total_price_tax_excl'] : 0.0;
|
||||
$dailyAdr[$ts] = $occ ? round($rev / $occ, 2) : 0.0;
|
||||
}
|
||||
} else {
|
||||
@@ -636,7 +635,7 @@ class QloHotelReports extends Module
|
||||
|
||||
$perPage = 20;
|
||||
$page = max(1, (int) Tools::getValue('rooms_page', 1));
|
||||
$allRooms = HotelRoomInformation::getRoomStatusForReports(array(
|
||||
$allRooms = HotelRoomInformation::getRoomStatus(array(
|
||||
'date_from' => $dateFrom,
|
||||
'date_to' => $dateTo,
|
||||
'id_hotel' => $idHotel ?: false,
|
||||
@@ -757,23 +756,22 @@ class QloHotelReports extends Module
|
||||
}
|
||||
|
||||
if ($report === 'source' || $report === 'payment-method') {
|
||||
$bookingType = (int) Tools::getValue('booking_type', 0);
|
||||
$bookingSource = pSQL(Tools::getValue('booking_source', ''));
|
||||
$filterBaseUrl = $baseUrl . '&tab=' . $report
|
||||
. ($idHotel ? '&id_hotel=' . $idHotel : '')
|
||||
. ($bookingType ? '&booking_type=' . $bookingType : '');
|
||||
|
||||
. ($idHotel ? '&id_hotel=' . $idHotel : '')
|
||||
. ($bookingSource ? '&booking_source=' . $bookingSource : '');
|
||||
|
||||
$baseParams = array(
|
||||
'date_from' => $dateFrom,
|
||||
'date_to' => $dateTo,
|
||||
'id_hotel' => $idHotel ?: false,
|
||||
'booking_type' => $bookingType,
|
||||
'date_from' => $dateFrom,
|
||||
'date_to' => $dateTo,
|
||||
'id_hotel' => $idHotel ?: false,
|
||||
'booking_source' => $bookingSource,
|
||||
);
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
'filter_base_url' => $filterBaseUrl,
|
||||
'filter_booking_type' => $bookingType,
|
||||
'export_url' => $filterBaseUrl . '&export=1',
|
||||
'filter_base_url' => $filterBaseUrl,
|
||||
'filter_booking_source' => $bookingSource,
|
||||
'export_url' => $filterBaseUrl . '&export=1',
|
||||
));
|
||||
|
||||
if ($report === 'source') {
|
||||
@@ -860,8 +858,8 @@ class QloHotelReports extends Module
|
||||
$occupancyByDay = AdminStatsController::getOccupancyRateForDiscreteDates($dateFrom, $dateTo, $idHotel ?: null);
|
||||
$adrByDay = AdminStatsController::getAverageDailyRateForDiscreteDates($dateFrom, $dateTo, $idHotel ?: null);
|
||||
$revenueByDay = AdminStatsController::getRoomsRevenueForDiscreteDates($dateFrom, $dateTo, $idHotel ?: null);
|
||||
$roomsSoldByDay = HotelBookingDetail::getOccupiedRoomsForDiscreteDates($baseParams);
|
||||
$checkedInByDay = HotelBookingDetail::getOccupiedRoomsForDiscreteDates(
|
||||
$roomsSoldByDay = HotelBookingDetail::getDatewiseOccupiedRooms($baseParams);
|
||||
$checkedInByDay = HotelBookingDetail::getDatewiseOccupiedRooms(
|
||||
array_merge($baseParams, array('id_status' => HotelBookingDetail::STATUS_CHECKED_IN))
|
||||
);
|
||||
$totalRooms = AdminStatsController::getTotalRooms($idHotel ?: null, 1);
|
||||
@@ -898,7 +896,7 @@ class QloHotelReports extends Module
|
||||
$cancels = HotelBookingDetail::getTotalCancellations($hotelParams);
|
||||
$roomNights = HotelBookingDetail::getTotalRoomNights($hotelParams);
|
||||
$roomRevenue = array_sum(AdminStatsController::getRoomsRevenueForDiscreteDates($dateFrom, $dateTo, $hotelId));
|
||||
$extraRev = ServiceProductOrderDetail::getTotalServiceRevenue($hotelParams);
|
||||
$extraRev = ServiceProductOrderDetail::getTotalRevenue($hotelParams);
|
||||
$obRows = Order::getOutstandingBalance($hotelParams);
|
||||
$hotelRows[] = array(
|
||||
'hotel_name' => $hotel['hotel_name'],
|
||||
@@ -1099,11 +1097,6 @@ class QloHotelReports extends Module
|
||||
HotelBookingDetail::STATUS_CHECKED_IN => $this->l('Checked In'),
|
||||
HotelBookingDetail::STATUS_CHECKED_OUT => $this->l('Checked Out'),
|
||||
);
|
||||
$sourceLabels = array(
|
||||
HotelBookingDetail::ALLOTMENT_AUTO => $this->l('Online / Direct'),
|
||||
HotelBookingDetail::ALLOTMENT_MANUAL => $this->l('Walk-in / Admin'),
|
||||
);
|
||||
|
||||
header('Content-Disposition: attachment; filename="reservation-report-'.$dateFrom.'-to-'.$dateTo.'.csv"');
|
||||
$out = fopen('php://output', 'w');
|
||||
fputs($out, "\xEF\xBB\xBF");
|
||||
@@ -1141,7 +1134,7 @@ class QloHotelReports extends Module
|
||||
$row['adults'],
|
||||
$row['children'],
|
||||
number_format((float) $row['unit_price_tax_excl'], _PS_PRICE_DISPLAY_PRECISION_, '.', ''),
|
||||
isset($sourceLabels[$row['booking_type']]) ? $sourceLabels[$row['booking_type']] : $row['booking_type'],
|
||||
$row['order_source'],
|
||||
isset($statusLabels[$row['id_status']]) ? $statusLabels[$row['id_status']] : $row['id_status'],
|
||||
number_format((float) $row['total_price_tax_excl'], _PS_PRICE_DISPLAY_PRECISION_, '.', ''),
|
||||
number_format((float) $row['tax_amount'], _PS_PRICE_DISPLAY_PRECISION_, '.', ''),
|
||||
@@ -1303,11 +1296,11 @@ class QloHotelReports extends Module
|
||||
));
|
||||
}
|
||||
} else {
|
||||
$dailyRoomDetailed = HotelBookingDetail::getDatewiseRoomRevenueTax(array_merge($baseParams, array('date_type' => 'created')));
|
||||
$dailyServiceData = ServiceProductOrderDetail::getDatewiseServiceRevenueTax($baseParams);
|
||||
$dailyBookings = HotelBookingDetail::getTotalBookings(array(
|
||||
$dailyRoomDetailed = HotelBookingDetail::getDatewiseSummary($baseParams);
|
||||
$dailyServiceData = ServiceProductOrderDetail::getDatewiseRevenue($baseParams);
|
||||
$dailyBookings = HotelBookingDetail::getDatewiseBookings(array(
|
||||
'date_from' => $dateFrom, 'date_to' => $dateTo,
|
||||
'id_hotel' => $idHotel ?: false, 'id_product' => $idProduct, 'granularity' => 'day',
|
||||
'id_hotel' => $idHotel ?: false, 'id_product' => $idProduct,
|
||||
));
|
||||
$dailyRefunds = HotelBookingDetail::getDatewiseRefunds($baseParams);
|
||||
|
||||
@@ -1325,12 +1318,12 @@ class QloHotelReports extends Module
|
||||
while ($csvDate <= $dateTo) {
|
||||
$timestamp = strtotime($csvDate);
|
||||
$roomData = isset($dailyRoomDetailed[$timestamp]) ? $dailyRoomDetailed[$timestamp]
|
||||
: array('room_revenue' => 0.0, 'tax_amount' => 0.0, 'rooms_booked' => 0, 'room_nights' => 0);
|
||||
$svcDay = isset($dailyServiceData[$timestamp]) ? $dailyServiceData[$timestamp] : array('service_revenue' => 0.0, 'tax_amount' => 0.0);
|
||||
: array('total_price_tax_excl' => 0.0, 'total_tax' => 0.0, 'rooms_booked' => 0, 'room_nights' => 0);
|
||||
$svcDay = isset($dailyServiceData[$timestamp]) ? $dailyServiceData[$timestamp] : array('service_revenue' => 0.0, 'total_tax' => 0.0);
|
||||
$svcRev = $svcDay['service_revenue'];
|
||||
$refundAmt = isset($dailyRefunds[$timestamp]) ? (float) $dailyRefunds[$timestamp] : 0.0;
|
||||
$roomRevExcl = (float) $roomData['room_revenue'];
|
||||
$taxAmt = (float) $roomData['tax_amount'] + $svcDay['tax_amount'];
|
||||
$roomRevExcl = (float) $roomData['total_price_tax_excl'];
|
||||
$taxAmt = (float) $roomData['total_tax'] + $svcDay['total_tax'];
|
||||
$collection = $roomRevExcl + $svcRev;
|
||||
$netRevenue = $collection;
|
||||
$roomsBooked = (int) $roomData['rooms_booked'];
|
||||
@@ -1402,7 +1395,7 @@ class QloHotelReports extends Module
|
||||
));
|
||||
}
|
||||
} elseif ($report === 'room-status') {
|
||||
$rows = HotelRoomInformation::getRoomStatusForReports(array(
|
||||
$rows = HotelRoomInformation::getRoomStatus(array(
|
||||
'date_from' => $dateFrom,
|
||||
'date_to' => $dateTo,
|
||||
'id_hotel' => $idHotel ?: false,
|
||||
@@ -1476,20 +1469,20 @@ class QloHotelReports extends Module
|
||||
}
|
||||
} else {
|
||||
$totalRoomsOcc = (int) AdminStatsController::getTotalRooms($idHotel ?: null, 1, $idProduct ?: null);
|
||||
$dailyAllOcc = HotelBookingDetail::getOccupiedRoomsForDiscreteDates($baseParams);
|
||||
$dailyBooked = HotelBookingDetail::getOccupiedRoomsForDiscreteDates(
|
||||
$dailyAllOcc = HotelBookingDetail::getDatewiseOccupiedRooms($baseParams);
|
||||
$dailyBooked = HotelBookingDetail::getDatewiseOccupiedRooms(
|
||||
array_merge($baseParams, array('id_status' => HotelBookingDetail::STATUS_ALLOTED))
|
||||
);
|
||||
$dailyCheckedIn = HotelBookingDetail::getOccupiedRoomsForDiscreteDates(
|
||||
$dailyCheckedIn = HotelBookingDetail::getDatewiseOccupiedRooms(
|
||||
array_merge($baseParams, array('id_status' => HotelBookingDetail::STATUS_CHECKED_IN))
|
||||
);
|
||||
if ($idProduct) {
|
||||
$dailyRevenue = HotelBookingDetail::getDatewiseRoomRevenue($baseParams);
|
||||
$dailyRevenue = HotelBookingDetail::getDatewiseRevenue($baseParams);
|
||||
$dailyAvailable = array();
|
||||
$dailyAdrOcc = array();
|
||||
foreach ($dailyAllOcc as $ts => $occ) {
|
||||
$dailyAvailable[$ts] = max(0, $totalRoomsOcc - $occ);
|
||||
$rev = isset($dailyRevenue[$ts]) ? (float) $dailyRevenue[$ts] : 0.0;
|
||||
$rev = isset($dailyRevenue[$ts]) ? (float) $dailyRevenue[$ts]['total_price_tax_excl'] : 0.0;
|
||||
$dailyAdrOcc[$ts] = $occ ? round($rev / $occ, 2) : 0.0;
|
||||
}
|
||||
} else {
|
||||
@@ -1752,8 +1745,8 @@ class QloHotelReports extends Module
|
||||
|
||||
if ($report === 'daily-summary') {
|
||||
$totalRoomsProp = AdminStatsController::getTotalRooms($idHotel ?: null, 1);
|
||||
$roomsSoldByDay = HotelBookingDetail::getOccupiedRoomsForDiscreteDates($baseParams);
|
||||
$checkedInByDay = HotelBookingDetail::getOccupiedRoomsForDiscreteDates(
|
||||
$roomsSoldByDay = HotelBookingDetail::getDatewiseOccupiedRooms($baseParams);
|
||||
$checkedInByDay = HotelBookingDetail::getDatewiseOccupiedRooms(
|
||||
array_merge($baseParams, array('id_status' => HotelBookingDetail::STATUS_CHECKED_IN))
|
||||
);
|
||||
$arrivalsByDay = HotelBookingDetail::getDatewiseArrivals($baseParams);
|
||||
@@ -1815,7 +1808,7 @@ class QloHotelReports extends Module
|
||||
$cancelRate = $bookings > 0 ? round($cancels / $bookings * 100, 1) : 0.0;
|
||||
$roomNights = (int) HotelBookingDetail::getTotalRoomNights($hotelParams);
|
||||
$roomRevenue = array_sum(AdminStatsController::getRoomsRevenueForDiscreteDates($dateFrom, $dateTo, (int) $hotel['id']));
|
||||
$extraRev = (float) ServiceProductOrderDetail::getTotalServiceRevenue($hotelParams);
|
||||
$extraRev = (float) ServiceProductOrderDetail::getTotalRevenue($hotelParams);
|
||||
$grossRevenue = $roomRevenue + $extraRev;
|
||||
$occupancy = round(AdminStatsController::getAverageOccupancyRate($dateFrom, $dateTo, (int) $hotel['id']), 1);
|
||||
$avgLos = ($bookings > 0 && $roomNights > 0) ? round($roomNights / $bookings, 1) : 0.0;
|
||||
|
||||
@@ -149,7 +149,7 @@
|
||||
<td class="text-right">{$reservation.children|intval}</td>
|
||||
<td class="text-right">{displayPrice price=$reservation.unit_price_tax_excl currency=$reservation.id_currency}</td>
|
||||
<td>
|
||||
{if isset($booking_sources[$reservation.booking_type])}{$booking_sources[$reservation.booking_type]|escape:'html':'UTF-8'}{else}{l s='Other' mod='qlohotelreports'}{/if}
|
||||
{$reservation.order_source|escape:'html':'UTF-8'}
|
||||
</td>
|
||||
<td>
|
||||
{if isset($booking_statuses[$reservation.id_status])}{$booking_statuses[$reservation.id_status]|escape:'html':'UTF-8'}{else}{$reservation.id_status|intval}{/if}
|
||||
|
||||
@@ -45,11 +45,9 @@
|
||||
<div class="row">
|
||||
<label class="col-xs-3">{l s='Booking Source' mod='qlohotelreports'}</label>
|
||||
<div class="col-xs-9">
|
||||
<select name="booking_type" class="form-control">
|
||||
<option value="0"{if !$filter_booking_type} selected="selected"{/if}>{l s='All Sources' mod='qlohotelreports'}</option>
|
||||
<option value="1"{if $filter_booking_type == 1} selected="selected"{/if}>{l s='Online / Direct' mod='qlohotelreports'}</option>
|
||||
<option value="2"{if $filter_booking_type == 2} selected="selected"{/if}>{l s='Walk-in / Admin' mod='qlohotelreports'}</option>
|
||||
</select>
|
||||
<input type="text" name="booking_source" class="form-control"
|
||||
value="{$filter_booking_source|escape:'html':'UTF-8'}"
|
||||
placeholder="{l s='All sources' mod='qlohotelreports'}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="actions">
|
||||
|
||||
Reference in New Issue
Block a user