diff --git a/controllers/admin/AdminCartsController.php b/controllers/admin/AdminCartsController.php
index f71cfd67d..3d10af263 100644
--- a/controllers/admin/AdminCartsController.php
+++ b/controllers/admin/AdminCartsController.php
@@ -161,13 +161,15 @@ class AdminCartsControllerCore extends AdminController
$time = time();
$kpis = array();
+ $daysForConversionRate = Configuration::get('PS_KPI_CONVERSION_RATE_NB_DAYS');
+
$helper = new HelperKpi();
$helper->id = 'box-conversion-rate';
$helper->icon = 'icon-sort-by-attributes-alt';
//$helper->chart = true;
$helper->color = 'color1';
$helper->title = $this->l('Conversion Rate', null, null, false);
- $helper->subtitle = $this->l('30 days', null, null, false);
+ $helper->subtitle = $daysForConversionRate.' '.$this->l('days', null, null, false);
if (ConfigurationKPI::get('CONVERSION_RATE_CHART') !== false) {
$helper->data = ConfigurationKPI::get('CONVERSION_RATE_CHART');
}
@@ -186,21 +188,23 @@ class AdminCartsControllerCore extends AdminController
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=abandoned_cart';
$kpis[] = $helper;
+ $daysForAvgOrderVal = Configuration::get('PS_ORDER_KPI_AVG_ORDER_VALUE_NB_DAYS');
$helper = new HelperKpi();
$helper->id = 'box-average-order';
$helper->icon = 'icon-money';
$helper->color = 'color3';
$helper->title = $this->l('Average Order Value', null, null, false);
- $helper->subtitle = $this->l('30 days', null, null, false);
+ $helper->subtitle = $daysForAvgOrderVal.' '.$this->l('days', null, null, false);
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=average_order_value';
$kpis[] = $helper;
+ $daysForProfitPerVisitor = Configuration::get('PS_ORDER_KPI_PER_VISITOR_PROFIT_NB_DAYS');
$helper = new HelperKpi();
$helper->id = 'box-net-profit-visitor';
$helper->icon = 'icon-user';
$helper->color = 'color4';
$helper->title = $this->l('Net Profit per Visitor', null, null, false);
- $helper->subtitle = $this->l('30 days', null, null, false);
+ $helper->subtitle = $daysForProfitPerVisitor.' '.$this->l('days', null, null, false);
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=netprofit_visit';
$kpis[] = $helper;
diff --git a/controllers/admin/AdminOrderPreferencesController.php b/controllers/admin/AdminOrderPreferencesController.php
index 67e25d177..4068a6f09 100644
--- a/controllers/admin/AdminOrderPreferencesController.php
+++ b/controllers/admin/AdminOrderPreferencesController.php
@@ -203,6 +203,22 @@ class AdminOrderPreferencesControllerCore extends AdminController
'list' => $displayCurrencyOptions,
'identifier' => 'value',
),
+ 'PS_ORDER_KPI_AVG_ORDER_VALUE_NB_DAYS' => array(
+ 'title' => $this->l('Days for Average Order Value KPI'),
+ 'hint' => $this->l('Set for last how many days, the \'Average order value\' in the KPI to be calculated.'),
+ 'type' => 'text',
+ 'validation' => 'isUnsignedInt',
+ 'class' => 'fixed-width-xl',
+ 'suffix' => $this->l('day(s)'),
+ ),
+ 'PS_ORDER_KPI_PER_VISITOR_PROFIT_NB_DAYS' => array(
+ 'title' => $this->l('Days for Net Profit Per Visitor KPI'),
+ 'hint' => $this->l('Set for last how many days, the \'Net Profit per Visitor\' in the KPI to be calculated.'),
+ 'type' => 'text',
+ 'validation' => 'isUnsignedInt',
+ 'class' => 'fixed-width-xl',
+ 'suffix' => $this->l('day(s)'),
+ ),
),
'submit' => array('title' => $this->l('Save'))
),
diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php
index 8b1d545c9..38e75a1ec 100644
--- a/controllers/admin/AdminOrdersController.php
+++ b/controllers/admin/AdminOrdersController.php
@@ -90,6 +90,18 @@ class AdminOrdersControllerCore extends AdminController
LEFT JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd ON (hbd.`id_order` = a.`id_order`)
LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbil ON (hbil.`id` = hbd.`id_hotel`)';
+ // Filters for KPIs because unable to filter orders by defult filters
+ if (Tools::getValue('orders_arrival_today')) {
+ $this->_where .= ' AND hbd.`is_refunded` = 0 AND hbd.`date_from` = \''.pSQL(date('Y-m-d')).' 00:00:00\' AND hbd.`id_status` != '.
+ (int) HotelBookingDetail::STATUS_CHECKED_IN.' AND hbd.`id_status` != '.(int) HotelBookingDetail::STATUS_CHECKED_OUT;
+ } elseif (Tools::getValue('orders_departures_today')) {
+ $this->_where .= ' AND hbd.`is_refunded` = 0 AND hbd.`date_to` = \''.pSQL(date('Y-m-d')).' 00:00:00\' AND hbd.`id_status` = '.
+ (int) HotelBookingDetail::STATUS_CHECKED_IN;
+ } elseif (Tools::getValue('orders_stay_over')) {
+ $this->_where .= ' AND hbd.`is_refunded` = 0 AND hbd.`is_back_order` = 0 AND hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_CHECKED_IN.'
+ AND hbd.`date_to` > \''.pSQL(date('Y-m-d')).' 00:00:00\'';
+ }
+
$this->_orderBy = 'id_order';
$this->_orderWay = 'DESC';
$this->_use_found_rows = true;
@@ -1861,65 +1873,12 @@ class AdminOrdersControllerCore extends AdminController
parent::postProcess();
}
- // KPIs on listing page
- // public function renderKpis()
- // {
- // $time = time();
- // $kpis = array();
-
- // $helper = new HelperKpi();
- // $helper->id = 'box-conversion-rate';
- // $helper->icon = 'icon-sort-by-attributes-alt';
- // //$helper->chart = true;
- // $helper->color = 'color1';
- // $helper->title = $this->l('Conversion Rate', null, null, false);
- // $helper->subtitle = $this->l('30 days', null, null, false);
- // if (ConfigurationKPI::get('CONVERSION_RATE_CHART') !== false) {
- // $helper->data = ConfigurationKPI::get('CONVERSION_RATE_CHART');
- // }
- // $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=conversion_rate';
- // $kpis[] = $helper->generate();
-
- // $helper = new HelperKpi();
- // $helper->id = 'box-carts';
- // $helper->icon = 'icon-shopping-cart';
- // $helper->color = 'color2';
- // $helper->title = $this->l('Abandoned Carts', null, null, false);
- // $helper->subtitle = $this->l('Today', null, null, false);
- // $helper->href = $this->context->link->getAdminLink('AdminCarts').'&action=filterOnlyAbandonedCarts';
- // $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=abandoned_cart';
- // $kpis[] = $helper->generate();
-
- // $helper = new HelperKpi();
- // $helper->id = 'box-average-order';
- // $helper->icon = 'icon-money';
- // $helper->color = 'color3';
- // $helper->title = $this->l('Average Order Value', null, null, false);
- // $helper->subtitle = $this->l('30 days', null, null, false);
- // $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=average_order_value';
- // $kpis[] = $helper->generate();
-
- // $helper = new HelperKpi();
- // $helper->id = 'box-net-profit-visit';
- // $helper->icon = 'icon-user';
- // $helper->color = 'color4';
- // $helper->title = $this->l('Net Profit per Visit', null, null, false);
- // $helper->subtitle = $this->l('30 days', null, null, false);
- // $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=netprofit_visit';
- // $kpis[] = $helper->generate();
-
- // $helper = new HelperKpiRow();
- // $helper->kpis = $kpis;
- // return $helper->generate();
- // }
-
// KPIs on view page
public function renderKpis()
{
+ $kpis = array();
$objOrder = new Order(Tools::getValue('id_order'));
if (Validate::isLoadedObject($objOrder)) {
- $kpis = array();
-
$helper = new HelperKpi();
$helper->id = 'box-order-date';
$helper->icon = 'icon-calendar';
@@ -1959,12 +1918,113 @@ class AdminOrdersControllerCore extends AdminController
Hook::exec('action'.$this->controller_name.'KPIListingModifier', array(
'kpis' => &$kpis,
));
+ } else {
+ $time = time();
+ $kpis = array();
- $helper = new HelperKpiRow();
- $helper->kpis = $kpis;
+ $helper = new HelperKpi();
+ $helper->id = 'box-total-sales';
+ $helper->icon = 'icon-money';
+ $helper->color = 'color4';
+ $helper->title = $this->l('Total Sales', null, null, false);
+ $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=total_sales';
+ $kpis[] = $helper;
- return $helper->generate();
+ $helper = new HelperKpi();
+ $helper->id = 'box-total-due-amount';
+ $helper->icon = 'icon-money';
+ $helper->color = 'color2';
+ $helper->title = $this->l('Total Due Amount', null, null, false);
+ $helper->href = $this->context->link->getAdminLink('AdminOrders').'&submitResetorder=1&due_amount_orders=1';
+ $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=total_due_amount';
+ $kpis[] = $helper;
+
+ $arivalDate = date('Y-m-d');
+ $helper = new HelperKpi();
+ $helper->id = 'box-today-arrivals';
+ $helper->icon = 'icon-user';
+ $helper->color = 'color1';
+ $helper->title = $this->l('Arrivals', null, null, false);
+ $helper->subtitle = $this->l('Today', null, null, false);
+ $helper->href = $this->context->link->getAdminLink('AdminOrders').'&orders_arrival_today=1';
+ $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=today_arrivals';
+ $kpis[] = $helper;
+
+ $departureDate = date('Y-m-d');
+ $helper = new HelperKpi();
+ $helper->id = 'box-today-departures';
+ $helper->icon = 'icon-user';
+ $helper->color = 'color2';
+ $helper->title = $this->l('Departures', null, null, false);
+ $helper->subtitle = $this->l('Today', null, null, false);
+ $helper->href = $this->context->link->getAdminLink('AdminOrders').'&orders_departures_today=1';
+ $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=today_departures';
+ $kpis[] = $helper;
+
+ $dateFrom = date('Y-m-d');
+ $dateTo = date('Y-m-d', strtotime('+1 day'));
+ $helper = new HelperKpi();
+ $helper->id = 'box-today-stay-over';
+ $helper->icon = 'icon-user';
+ $helper->color = 'color4';
+ $helper->title = $this->l('Stay Overs', null, null, false);
+ $helper->subtitle = $this->l('Today', null, null, false);
+ $helper->href = $this->context->link->getAdminLink('AdminOrders').'&orders_stay_over=1';
+ $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=today_stay_over';
+ $kpis[] = $helper;
+
+ $helper = new HelperKpi();
+ $helper->id = 'box-carts';
+ $helper->icon = 'icon-shopping-cart';
+ $helper->color = 'color2';
+ $helper->title = $this->l('Abandoned Carts', null, null, false);
+ $dateFrom = date(Context::getContext()->language->date_format_lite, strtotime('-2 day'));
+ $dateTo = date(Context::getContext()->language->date_format_lite, strtotime('-1 day'));
+ $helper->subtitle = sprintf($this->l('From %s to %s', null, null, false), $dateFrom, $dateTo);
+ $helper->href = $this->context->link->getAdminLink('AdminCarts').'&action=filterOnlyAbandonedCarts';
+ $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=abandoned_cart';
+ $kpis[] = $helper;
+
+ $daysForConversionRate = Configuration::get('PS_KPI_CONVERSION_RATE_NB_DAYS');
+ $helper = new HelperKpi();
+ $helper->id = 'box-conversion-rate';
+ $helper->icon = 'icon-sort-by-attributes-alt';
+ $helper->color = 'color1';
+ $helper->title = $this->l('Conversion Rate', null, null, false);
+ $helper->subtitle = $daysForConversionRate.' '.$this->l('days', null, null, false);
+ $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=conversion_rate';
+ $kpis[] = $helper;
+
+ $daysForAvgOrderVal = Configuration::get('PS_ORDER_KPI_AVG_ORDER_VALUE_NB_DAYS');
+ $helper = new HelperKpi();
+ $helper->id = 'box-average-order';
+ $helper->icon = 'icon-money';
+ $helper->color = 'color3';
+ $helper->title = $this->l('Average Order Value', null, null, false);
+ $helper->subtitle = $daysForAvgOrderVal.' '.$this->l('days', null, null, false);
+ $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=average_order_value';
+ $kpis[] = $helper;
+
+ $helper = new HelperKpi();
+ $helper->id = 'box-average-lead-time';
+ $helper->icon = 'icon-time';
+ $helper->color = 'color4';
+ $helper->title = $this->l('Average Lead Time', null, null, false);
+ $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=average_lead_time';
+ $kpis[] = $helper;
+
+ $helper = new HelperKpi();
+ $helper->id = 'box-average-guest-in-booking';
+ $helper->icon = 'icon-users';
+ $helper->color = 'color3';
+ $helper->title = $this->l('Average Guest Per Booking', null, null, false);
+ $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=average_guest_in_booking';
+ $kpis[] = $helper;
}
+
+ $helper = new HelperKpiRow();
+ $helper->kpis = $kpis;
+ return $helper->generate();
}
public function renderView()
diff --git a/controllers/admin/AdminStatsController.php b/controllers/admin/AdminStatsController.php
index 4b0f4ea0e..102394493 100644
--- a/controllers/admin/AdminStatsController.php
+++ b/controllers/admin/AdminStatsController.php
@@ -219,16 +219,15 @@ class AdminStatsControllerCore extends AdminStatsTabController
WHERE p.`booking_product` = 0');
}
- public static function getTotalSales($date_from, $date_to, $granularity = false, $id_hotel = false)
+ public static function getTotalSales($date_from = '', $date_to = '', $granularity = false, $id_hotel = false, $useTax = 0)
{
if ($granularity == 'day') {
$sales = array();
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(
- 'SELECT LEFT(`invoice_date`, 10) AS date, SUM(total_paid_tax_excl / o.`conversion_rate`) AS sales
+ 'SELECT LEFT(`invoice_date`, 10) AS date, ' . ($useTax ? 'SUM(o.`total_paid_tax_incl` / o.`conversion_rate`)' : 'SUM(o.`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 `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1'.
- ((int) $id_hotel ? ' AND o.`id_order` IN (SELECT id_order FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE id_hotel = '.(int)$id_hotel.')' : '').'
+ 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"' : '').((int) $id_hotel ? ' AND o.`id_order` IN (SELECT id_order FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE id_hotel = '.(int)$id_hotel.')' : '').'
GROUP BY LEFT(`invoice_date`, 10)'
);
@@ -240,11 +239,10 @@ class AdminStatsControllerCore extends AdminStatsTabController
} elseif ($granularity == 'month') {
$sales = array();
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(
- 'SELECT LEFT(`invoice_date`, 7) AS date, SUM(total_paid_tax_excl / o.`conversion_rate`) AS sales
+ 'SELECT LEFT(`invoice_date`, 7) AS date, ' . ($useTax ? 'SUM(total_paid_tax_incl / o.conversion_rate)' : '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 `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1'.
- ((int) $id_hotel ? ' AND o.`id_order` IN (SELECT id_order FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE id_hotel = '.(int)$id_hotel.')' : '').' GROUP BY LEFT(`invoice_date`, 7)'
+ 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"' : '').((int) $id_hotel ? ' AND o.`id_order` IN (SELECT id_order FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE id_hotel = '.(int)$id_hotel.')' : '').' GROUP BY LEFT(`invoice_date`, 7)'
);
foreach ($result as $row) {
@@ -254,11 +252,10 @@ class AdminStatsControllerCore extends AdminStatsTabController
return $sales;
} else {
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(
- 'SELECT SUM(total_paid_tax_excl / o.`conversion_rate`)
+ 'SELECT ' . ($useTax ? 'SUM(total_paid_tax_incl / o.conversion_rate)' : 'SUM(total_paid_tax_excl / o.conversion_rate)').'
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON o.current_state = os.id_order_state
- WHERE `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1'.
- ((int) $id_hotel ? ' AND o.`id_order` IN (SELECT id_order FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE id_hotel = '.(int)$id_hotel.')' : '')
+ 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"' : '').((int) $id_hotel ? ' AND o.`id_order` IN (SELECT id_order FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE id_hotel = '.(int)$id_hotel.')' : '')
);
}
}
@@ -750,20 +747,24 @@ class AdminStatsControllerCore extends AdminStatsTabController
break;
case 'average_order_value':
+ $daysForAvgOrderVal = Configuration::get('PS_ORDER_KPI_AVG_ORDER_VALUE_NB_DAYS');
+
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT
COUNT(o.`id_order`) as orders,
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(date('Y-m-d', strtotime('-31 day'))).' 00:00:00" AND "'.pSQL(date('Y-m-d', strtotime('-1 day'))).' 23:59:59" AND os.`logable` = 1
+ WHERE o.`invoice_date` BETWEEN "'.pSQL(date('Y-m-d', strtotime('-'.($daysForAvgOrderVal + 1).' day'))).' 00:00:00" AND "'.pSQL(date('Y-m-d', strtotime('-1 day'))).' 23:59:59" AND os.`logable` = 1
'.Shop::addSqlRestriction());
-
$value = Tools::displayPrice($row['orders'] ? $row['total_paid_tax_excl'] / $row['orders'] : 0, $currency);
+
break;
case 'netprofit_visit':
- $date_from = date('Y-m-d', strtotime('-31 day'));
+ $daysForProfitPerVisitor = Configuration::get('PS_ORDER_KPI_PER_VISITOR_PROFIT_NB_DAYS');
+
+ $date_from = date('Y-m-d', strtotime('-'.($daysForProfitPerVisitor + 1).' day'));
$date_to = date('Y-m-d', strtotime('-1 day'));
$total_visitors = AdminStatsController::getVisits(false, $date_from, $date_to);
@@ -890,7 +891,50 @@ class AdminStatsControllerCore extends AdminStatsTabController
$value = AdminStatsController::getTotalBannedCustomers();
break;
-
+ case 'total_sales':
+ $totalSales = AdminStatsController::getTotalSales('', '', false, false, 1);
+ if ($totalSales > 0) {
+ $value = Tools::displayPrice($totalSales, $currency);
+ } else {
+ $value = Tools::displayPrice(0, $currency);
+ }
+ break;
+ case 'today_arrivals':
+ $dateToday = date('Y-m-d');
+ $value = 0;
+ if ($arrivalsData = AdminStatsController::getArrivalsByDate($dateToday)) {
+ $value = $arrivalsData['total_arrivals'];
+ }
+ break;
+ case 'today_departures':
+ $dateToday = date('Y-m-d');
+ $value = 0;
+ if ($departureData = AdminStatsController::getDeparturesByDate($dateToday)) {
+ $value = $departureData['total_departures'];
+ }
+ break;
+ case 'today_stay_over':
+ $dateToday = date('Y-m-d');
+ $value = AdminStatsController::getStayOversByDate($dateToday);
+ break;
+ case 'total_due_amount':
+ $dateToday = date('Y-m-d');
+ $dueAmount = AdminStatsController::getTotalDueAmount('', '', false, 1);
+ if ($dueAmount > 0) {
+ $value = Tools::displayPrice($dueAmount, $currency);
+ } else {
+ $value = Tools::displayPrice(0, $currency);
+ }
+ break;
+ case 'average_lead_time':
+ $dateToday = date('Y-m-d');
+ $value = Tools::ps_round(AdminStatsController::getAverageLeadTime(), 2);
+ break;
+ case 'average_guest_in_booking':
+ $dateToday = date('Y-m-d');
+ $value = AdminStatsController::getAverageGuestsPerBooking();
+ $value = Tools::ps_round($value['avg_adults'], 2).''.$this->l('Adults').', '.Tools::ps_round($value['avg_children'], 2).''.$this->l('Children');
+ break;
default:
$value = false;
}
@@ -2266,4 +2310,52 @@ class AdminStatsControllerCore extends AdminStatsTabController
return $result;
}
+
+ // Get to totalo due amount in the orders
+ public static function getTotalDueAmount($dateFrom = '', $dateTo = '', $idHotel = false, $useTax = 0)
+ {
+ $objHotelBooking = new HotelBookingDetail();
+ $invalidOrderStates = $objHotelBooking->getOrderStatusToFreeBookedRoom();
+
+ $sql = 'SELECT (' . ($useTax ? 'SUM(o.`total_paid_tax_incl` / o.`conversion_rate`)' : 'SUM(o.`total_paid_tax_excl` / o.`conversion_rate`)') . ' - SUM(o.`total_paid_real` / o.`conversion_rate`))
+ FROM `'._DB_PREFIX_.'orders` o
+ LEFT JOIN `'._DB_PREFIX_.'order_state` os ON o.current_state = os.id_order_state
+ WHERE 1 ' . ($invalidOrderStates ? ' AND o.`current_state` NOT IN ('.implode(',', $invalidOrderStates).')' : '') . (($dateFrom && $dateTo) ? ' AND o.`date_add` BETWEEN "'.pSQL($dateFrom).' 00:00:00" AND "'.pSQL($dateTo).' 23:59:59"' : '')
+ .((int) $idHotel ? ' AND o.`id_order` IN (SELECT id_order FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE id_hotel = '.(int)$idHotel.')' : '');
+
+ return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
+ }
+
+ // Booking or Reservation Lead Time is the period of time (most typically measured in calendar days) between when a guest makes the reservation and the actual check-in/arrival date.
+ public static function getAverageLeadTime($dateFrom = '', $dateTo = '', $idHotel = false)
+ {
+ $sql = 'SELECT (SUM(DATEDIFF(hbd.`date_from`, hbd.`date_add`)) / COUNT(hbd.`id`)) FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
+ WHERE hbd.`is_refunded` = 0 AND hbd.`is_back_order` = 0'
+ .(($dateFrom && $dateTo) ? ' AND hbd.`date_add` BETWEEN "'.pSQL($dateFrom).' 00:00:00" AND "'.pSQL($dateTo).' 23:59:59"' : '')
+ .HotelBranchInformation::addHotelRestriction($idHotel, 'hbd');
+
+ return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
+ }
+
+ // This function is used to calculate the average number of guests per booking
+ /**
+ * This function is used to calculate the average number of guests per booking
+ * @param string $dateFrom : Date from in date range of booking creation
+ * @param string $dateTo : Date to in date range of booking creation
+ * @param boolean $idHotel: : Send id hotel if want to get for specific hotel
+ * @return array: of avg_adults and avg_children
+ */
+ public static function getAverageGuestsPerBooking($dateFrom = '', $dateTo = '', $idHotel = false)
+ {
+ $sql = 'SELECT (SUM(hbd.`adults`) / COUNT(hbd.`id`)) as avg_adults, (SUM(hbd.`children`) / COUNT(hbd.`id`)) as avg_children FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
+ WHERE hbd.`is_refunded` = 0 AND hbd.`is_back_order` = 0'
+ .(($dateFrom && $dateTo) ? ' AND hbd.`date_add` BETWEEN "'.pSQL($dateFrom).' 00:00:00" AND "'.pSQL($dateTo).' 23:59:59"' : '')
+ .HotelBranchInformation::addHotelRestriction($idHotel, 'hbd');
+
+ if ($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql)) {
+ return $result[0];
+ } else {
+ return array ('avg_adults' => 0, 'avg_children' => 0);
+ }
+ }
}
diff --git a/install/data/xml/configuration.xml b/install/data/xml/configuration.xml
index 007ea37e4..557f554f6 100644
--- a/install/data/xml/configuration.xml
+++ b/install/data/xml/configuration.xml
@@ -905,6 +905,12 @@
30
+
+ 30
+
+
+ 30
+
30