diff --git a/classes/Language.php b/classes/Language.php index f7c7b8c91..976b4ec79 100644 --- a/classes/Language.php +++ b/classes/Language.php @@ -908,7 +908,7 @@ class LanguageCore extends ObjectModel } if ($version == null) { - $version = _PS_VERSION_; + $version = _QLOAPPS_VERSION_; } $lang_pack = false; 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..efe584010 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -47,6 +47,8 @@ class AdminOrdersControllerCore extends AdminController protected $hotelsArray = array(); protected $roomTypesArray = array(); protected $roomsArray = array(); + protected $orderCurrenciesArray = array(); + public function __construct() { @@ -90,6 +92,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 +1875,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 +1920,123 @@ 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'; + $helper->tooltip = $this->l('Total sales/revenue of all the orders created.', null, null, false); + $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'; + $helper->tooltip = $this->l('Total due amount of all the orders created.', null, null, false); + $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'; + $helper->tooltip = $this->l('Total number of arrivals for today.', null, null, false); + $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'; + $helper->tooltip = $this->l('Total number of departures for today.', null, null, false); + $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'; + $helper->tooltip = $this->l('Total number of stay overs for today.', null, null, false); + $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'; + $helper->tooltip = $this->l('Total number of abandoned carts in given period of time.', null, null, false); + $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'; + $helper->tooltip = $this->l('Percentage of visits that resulted in an order/booking in given period of time.', null, null, false); + $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'; + $helper->tooltip = $this->l('Total average order value without tax in given period of time.', null, null, false); + $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'; + $helper->tooltip = $this->l('Average number of days between the time guests book their rooms and the time guest schedule to arrive at the hotel.', null, null, false); + $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'; + $helper->tooltip = $this->l('Average number of guests per booking.', null, null, false); + $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..2de11a362 100644 --- a/controllers/admin/AdminStatsController.php +++ b/controllers/admin/AdminStatsController.php @@ -224,27 +224,33 @@ class AdminStatsControllerCore extends AdminStatsTabController 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, SUM(total_paid_tax_excl / o.conversion_rate) AS sales, + ( + SELECT hbd.`id_hotel` + FROM`'._DB_PREFIX_.'htl_booking_detail` hbd + WHERE hbd.`id_order` = o.`id_order` LIMIT 1 + ) AS id_hotel FROM `'._DB_PREFIX_.'orders` o 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`, 10)' + 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"' : '').' GROUP BY LEFT(`invoice_date`, 10) HAVING 1 '.HotelBranchInformation::addHotelRestriction($id_hotel) ); foreach ($result as $row) { $sales[strtotime($row['date'])] = $row['sales']; } - return $sales; } 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, SUM(total_paid_tax_excl / o.conversion_rate) AS sales, + ( + SELECT hbd.`id_hotel` + FROM`'._DB_PREFIX_.'htl_booking_detail` hbd + WHERE hbd.`id_order` = o.`id_order` LIMIT 1 + ) AS id_hotel FROM `'._DB_PREFIX_.'orders` o 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"' : '').' GROUP BY LEFT(`invoice_date`, 7) HAVING 1 '.HotelBranchInformation::addHotelRestriction($id_hotel) ); foreach ($result as $row) { @@ -254,11 +260,15 @@ 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 SUM(total_paid_tax_excl / o.conversion_rate), + ( + SELECT hbd.`id_hotel` + FROM`'._DB_PREFIX_.'htl_booking_detail` hbd + WHERE hbd.`id_order` = o.`id_order` LIMIT 1 + ) AS id_hotel FROM `'._DB_PREFIX_.'orders` o 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"' : '').' HAVING 1 '.HotelBranchInformation::addHotelRestriction($id_hotel) ); } } @@ -467,13 +477,17 @@ class AdminStatsControllerCore extends AdminStatsTabController od.`purchase_supplier_price` > 0, od.`purchase_supplier_price`, (od.`original_product_price` / `conversion_rate`) * '.(int)Configuration::get('CONF_AVERAGE_PRODUCT_MARGIN').' / 100 - )) as total_purchase_price + )) as total_purchase_price, + ( + SELECT hbd.`id_hotel` + FROM`'._DB_PREFIX_.'htl_booking_detail` hbd + WHERE hbd.`id_order` = o.`id_order` LIMIT 1 + ) AS id_hotel FROM `'._DB_PREFIX_.'orders` o LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON o.id_order = od.id_order 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.')' : '').Shop::addSqlRestriction(false, 'o').' - GROUP BY LEFT(`invoice_date`, 10)'); + WHERE `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1'.' + GROUP BY LEFT(`invoice_date`, 10) HAVING 1 '.HotelBranchInformation::addHotelRestriction($id_hotel)); foreach ($result as $row) { $purchases[strtotime($row['date'])] = $row['total_purchase_price']; @@ -481,17 +495,22 @@ class AdminStatsControllerCore extends AdminStatsTabController return $purchases; } else { - return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' - SELECT SUM(od.`product_quantity` * IF( - od.`purchase_supplier_price` > 0, - od.`purchase_supplier_price`, - (od.`original_product_price` / `conversion_rate`) * '.(int)Configuration::get('CONF_AVERAGE_PRODUCT_MARGIN').' / 100 - )) as total_purchase_price - FROM `'._DB_PREFIX_.'orders` o - LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON o.id_order = od.id_order - 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.')' : '').Shop::addSqlRestriction(false, 'o')); + return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue( + 'SELECT SUM(od.`product_quantity` * IF( + od.`purchase_supplier_price` > 0, + od.`purchase_supplier_price`, + (od.`original_product_price` / `conversion_rate`) * '.(int)Configuration::get('CONF_AVERAGE_PRODUCT_MARGIN').' / 100 + )), + ( + SELECT hbd.`id_hotel` + FROM`'._DB_PREFIX_.'htl_booking_detail` hbd + WHERE hbd.`id_order` = o.`id_order` LIMIT 1 + ) AS id_hotel + FROM `'._DB_PREFIX_.'orders` o + LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON o.id_order = od.id_order + 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 HAVING 1 '.HotelBranchInformation::addHotelRestriction($id_hotel) + ); } } @@ -505,15 +524,19 @@ class AdminStatsControllerCore extends AdminStatsTabController total_paid_tax_incl / o.conversion_rate as total_paid_tax_incl, total_shipping_tax_excl / o.conversion_rate as total_shipping_tax_excl, o.module, - hbd.id_country, + ad.id_country, o.id_currency, - c.id_reference as carrier_reference + c.id_reference as carrier_reference, + ( + SELECT hbd.`id_hotel` + FROM`'._DB_PREFIX_.'htl_booking_detail` hbd + WHERE hbd.`id_order` = o.`id_order` LIMIT 1 + ) AS id_hotel FROM `'._DB_PREFIX_.'orders` o - LEFT JOIN `'._DB_PREFIX_.'address` hbd ON o.id_address_delivery = hbd.id_address + LEFT JOIN `'._DB_PREFIX_.'address` ad ON o.id_address_delivery = ad.id_address LEFT JOIN `'._DB_PREFIX_.'carrier` c ON o.id_carrier = c.id_carrier 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.')' : '').Shop::addSqlRestriction(false, 'o')); + WHERE `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1 HAVING 1'.HotelBranchInformation::addHotelRestriction($id_hotel)); foreach ($orders as $order) { // Add flat fees for this order @@ -590,7 +613,7 @@ class AdminStatsControllerCore extends AdminStatsTabController $visitors = AdminStatsController::getVisits( true, date('Y-m-d', strtotime('-'.($nbDaysConversionRate + 1).' day')), - date('Y-m-d', strtotime('-1 day')), + date('Y-m-d', strtotime('+1 day')), false /*'day'*/ ); @@ -750,20 +773,28 @@ 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 + SUM(o.`total_paid_tax_excl` / o.`conversion_rate`) as total_paid_tax_excl, + ( + SELECT hbd.`id_hotel` + FROM`'._DB_PREFIX_.'htl_booking_detail` hbd + WHERE hbd.`id_order` = o.`id_order` LIMIT 1 + ) AS id_hotel FROM `'._DB_PREFIX_.'orders` o 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 - '.Shop::addSqlRestriction()); + 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 HAVING 1 '.HotelBranchInformation::addHotelRestriction(false)); + $value = Tools::displayPrice($row['orders'] ? $row['total_paid_tax_excl'] / $row['orders'] : 0, $currency).' ('.$this->l('tax excl.').')'; - $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 +921,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 +2340,56 @@ 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`)), + ( + SELECT hbd.`id_hotel` + FROM`'._DB_PREFIX_.'htl_booking_detail` hbd + WHERE hbd.`id_order` = o.`id_order` LIMIT 1 + ) AS id_hotel + FROM `'._DB_PREFIX_.'orders` o + 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"' : '').' HAVING 1 '.HotelBranchInformation::addHotelRestriction($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 diff --git a/install/models/install.php b/install/models/install.php index 533bfd233..052bc3d00 100644 --- a/install/models/install.php +++ b/install/models/install.php @@ -339,7 +339,7 @@ class InstallModelInstall extends InstallAbstractModel if (InstallSession::getInstance()->safe_mode) { Language::checkAndAddLanguage($iso, false, true, $params_lang); } else { - Language::downloadAndInstallLanguagePack($iso, _PS_INSTALL_VERSION_, $params_lang); + Language::downloadAndInstallLanguagePack($iso, _QLO_INSTALL_VERSION_, $params_lang); } Language::loadLanguages();