Merge pull request #573 from abhishek-webkul/fix-stats-2

Change catalog evaluation module and fix stats issues
This commit is contained in:
Rohit Jain
2023-03-07 13:03:58 +05:30
committed by GitHub
5 changed files with 388 additions and 63 deletions

View File

@@ -686,6 +686,24 @@
<configuration id="ROOM_TYPE_CHECKUP_TOTAL_ROOMS_GT" name="ROOM_TYPE_CHECKUP_TOTAL_ROOMS_GT">
<value>3</value>
</configuration>
<configuration id="SERVICE_CHECKUP_DESCRIPTIONS_SHORT_LT" name="SERVICE_CHECKUP_DESCRIPTIONS_SHORT_LT">
<value>50</value>
</configuration>
<configuration id="SERVICE_CHECKUP_DESCRIPTIONS_SHORT_GT" name="SERVICE_CHECKUP_DESCRIPTIONS_GT">
<value>150</value>
</configuration>
<configuration id="SERVICE_CHECKUP_IMAGES_LT" name="SERVICE_CHECKUP_IMAGES_LT">
<value>1</value>
</configuration>
<configuration id="SERVICE_CHECKUP_IMAGES_GT" name="SERVICE_CHECKUP_IMAGES_GT">
<value>2</value>
</configuration>
<configuration id="SERVICE_CHECKUP_ORDERS_LT" name="SERVICE_CHECKUP_ORDERS_LT">
<value>1</value>
</configuration>
<configuration id="SERVICE_CHECKUP_ORDERS_GT" name="SERVICE_CHECKUP_ORDERS_GT">
<value>2</value>
</configuration>
<configuration id="FOOTER_CMS" name="FOOTER_CMS">
<value>0_3|0_4</value>
</configuration>

View File

@@ -202,7 +202,7 @@ class StatsBestProducts extends ModuleGrid
FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
ON (pl.`id_product` = p.`id_product` AND pl.`id_lang` = '.(int) $id_lang .')
LEFT JOIN `'._DB_PREFIX_.'htl_room_type` hrt
INNER JOIN `'._DB_PREFIX_.'htl_room_type` hrt
ON (hrt.`id_product` = p.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbil
ON (hbil.`id` = hrt.`id_hotel` AND hbil.`id_lang` = '.(int) $id_lang .')

View File

@@ -46,7 +46,7 @@ class StatsCatalog extends Module
parent::__construct();
$this->displayName = $this->l('Catalog statistics');
$this->displayName = $this->l('Hotel statistics');
$this->description = $this->l('Adds a tab containing general statistics about your catalog to the Stats dashboard.');
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => '1.7.0.99');
}
@@ -119,7 +119,7 @@ class StatsCatalog extends Module
LEFT JOIN `'._DB_PREFIX_.'page` pa ON pv.`id_page` = pa.`id_page`
LEFT JOIN `'._DB_PREFIX_.'page_type` pt ON pt.`id_page_type` = pa.`id_page_type`
LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = pa.`id_object`
LEFT JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (p.`id_product` = hrt.`id_product`)
INNER JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (p.`id_product` = hrt.`id_product`)
'.Shop::addSqlAssociation('product', 'p').'
'.$this->join.'
WHERE pt.`name` IN ("product.php", "product")
@@ -149,7 +149,7 @@ class StatsCatalog extends Module
FROM `'._DB_PREFIX_.'image` i
LEFT JOIN `'._DB_PREFIX_.'product` p
ON (p.`id_product` = i.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'htl_room_type` hrt
INNER JOIN `'._DB_PREFIX_.'htl_room_type` hrt
ON (hrt.`id_product` = i.`id_product`)
WHERE hrt.`id_hotel` = hbi.`id`
) AS room_type_images
@@ -174,7 +174,7 @@ class StatsCatalog extends Module
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON o.`id_order` = od.`id_order`
LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = od.`product_id`
LEFT JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (p.`id_product` = hrt.`id_product`)
INNER JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (p.`id_product` = hrt.`id_product`)
'.Shop::addSqlAssociation('product', 'p').'
'.$this->join.'
WHERE o.valid = 1
@@ -194,7 +194,7 @@ class StatsCatalog extends Module
$sql = 'SELECT p.id_product, pl.name, pl.link_rewrite
FROM `'._DB_PREFIX_.'product` p
'.Shop::addSqlAssociation('product', 'p').'
LEFT JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (p.`id_product` = hrt.`id_product`)
INNER JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (p.`id_product` = hrt.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
ON (pl.`id_product` = p.`id_product` AND pl.id_lang = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').')
'.$this->join.'
@@ -293,7 +293,7 @@ class StatsCatalog extends Module
if (count($products_nb) && count($products_nb) < 50) {
$html .= '
<div class="panel-heading">'.$this->l('Room types never booked').'</div>
<div class="col-sm-12"><div class="panel-heading">'.$this->l('Room types never booked').'</div></div>
<table class="table">
<thead>
<tr>

View File

@@ -91,6 +91,8 @@ class StatsCheckUp extends Module
.$this->displayName.'
</div>';
$activeTab = 'hotels';
if (Tools::isSubmit('submitCheckupRoomType')) {
$confs = array(
'ROOM_TYPE_CHECKUP_DESCRIPTIONS_LT',
@@ -129,6 +131,25 @@ class StatsCheckUp extends Module
$this->html .= $this->displayConfirmation($this->l('Configuration updated.'));
}
if (Tools::isSubmit('submitCheckupService')) {
$confs = array(
'SERVICE_CHECKUP_DESCRIPTIONS_SHORT_LT',
'SERVICE_CHECKUP_DESCRIPTIONS_SHORT_GT',
'SERVICE_CHECKUP_IMAGES_LT',
'SERVICE_CHECKUP_IMAGES_GT',
'SERVICE_CHECKUP_ORDERS_LT',
'SERVICE_CHECKUP_ORDERS_GT',
);
foreach ($confs as $confname) {
Configuration::updateValue($confname, (int)Tools::getValue($confname));
}
$this->html .= $this->displayConfirmation($this->l('Configuration updated.'));
$activeTab = 'services';
}
if (Tools::isSubmit('submitCheckupOrder')) {
$this->context->cookie->checkup_order = (int)Tools::getValue('submitCheckupOrder');
$this->html .= $this->displayConfirmation($this->l('Configuration updated.'));
@@ -142,6 +163,35 @@ class StatsCheckUp extends Module
$this->id_hotel = (int) Tools::getValue('id_hotel');
}
$this->html .= '
<ul class="nav nav-tabs">
<li '.($activeTab == 'hotels' ? 'class="active"' : '').'>
<a href="#statscheckup_hotels" data-toggle="tab">
<span>'.$this->l('Hotels').'</span>
</a>
</li>
<li '.($activeTab == 'services' ? 'class="active"' : '').'>
<a href="#statscheckup_services" data-toggle="tab">
<span>'.$this->l('Services').'</span>
</a>
</li>
</ul>
<div class="tab-content panel panel-sm">
<div class="tab-pane '.($activeTab == 'hotels' ? 'active' : '').'" id="statscheckup_hotels">
'.$this->getHotelsTab().'
</div>
<div class="tab-pane '.($activeTab == 'services' ? 'active' : '').'" id="statscheckup_services">
'.$this->getServicesTab().'
</div>
</div>
';
return $this->html;
}
private function getHotelsTab()
{
$employee = Context::getContext()->employee;
$prop30 = ((strtotime($employee->stats_date_to.' 23:59:59') - strtotime($employee->stats_date_from.' 00:00:00')) / 60 / 60 / 24) / 30;
@@ -187,7 +237,7 @@ class StatsCheckUp extends Module
'TOTAL_ROOMS' => array('name' => $this->l('Total rooms'), 'text' => $this->l('rooms')),
);
$this->html .= '
$hotelsHtml = '
<form action="'.Tools::safeOutput(AdminController::$currentIndex.'&token='.Tools::getValue('token').'&module='.$this->name.($this->id_hotel ? '&id_hotel='.$this->id_hotel : '')).'" method="post" class="checkup form-horizontal">
<table class="table checkup">
<thead>
@@ -200,7 +250,7 @@ class StatsCheckUp extends Module
foreach ($array_conf as $conf => $translations) {
$confKeyLt = ($this->id_hotel ? 'ROOM_TYPE' : 'HOTEL').'_CHECKUP_'.$conf.'_LT';
$confKeyGt = ($this->id_hotel ? 'ROOM_TYPE' : 'HOTEL').'_CHECKUP_'.$conf.'_GT';
$this->html .= '
$hotelsHtml .= '
<tbody>
<tr>
<td>
@@ -227,7 +277,7 @@ class StatsCheckUp extends Module
</tr>
</tbody>';
}
$this->html .= '</table>
$hotelsHtml .= '</table>
<button type="submit" name="'.($this->id_hotel ? 'submitCheckupRoomType' : 'submitCheckupHotel').'" class="btn btn-default pull-right">
<i class="icon-save"></i> '.$this->l('Save').'
</button>
@@ -251,12 +301,12 @@ class StatsCheckUp extends Module
<thead>
<tr>
<th><span class="title_box active">'.$this->l('ID').'</span></th>
<th><span class="title_box active">'.$this->l('Room type').'</span></th>
<th><span class="title_box active">'.(!$this->id_hotel ? $this->l('Hotel') : $this->l('Room type')).'</span></th>
<th class="center"><span class="title_box active">'.$this->l('Active').'</span></th>';
foreach ($languages as $language) {
$this->html .= '<th><span class="title_box active">'.$this->l('Desc.').' ('.Tools::strtoupper($language['iso_code']).')</span></th>';
$hotelsHtml .= '<th><span class="title_box active">'.$this->l('Desc.').' ('.Tools::strtoupper($language['iso_code']).')</span></th>';
}
$this->html .= '
$hotelsHtml .= '
<th class="center"><span class="title_box active">'.$this->l('Images').'</span></th>
<th class="center"><span class="title_box active">'.$this->l('Orders').'</span></th>
<th class="center"><span class="title_box active">'.$this->l('Total rooms').'</span></th>
@@ -280,17 +330,6 @@ class StatsCheckUp extends Module
);
foreach ($result as $row) {
$row['stock'] = 0;
if ($roomTypeInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($row['id_product'])) {
$bookingParams['hotel_id'] = $roomTypeInfo['id_hotel'];
$bookingParams['id_room_type'] = $row['id_product'];
if ($booking_data = $objBookingDtl->getBookingData($bookingParams)) {
if (isset($booking_data['stats']['num_avail'])) {
$row['stock'] = $booking_data['stats']['num_avail'];
}
}
}
$totals['products']++;
$scores = array(
'active' => ($row['active'] ? 2 : 0),
@@ -302,7 +341,7 @@ class StatsCheckUp extends Module
$totals['images'] += (int)$scores['images'];
$totals['orders'] += (int)$scores['orders'];
$totals['total_rooms'] += (int)$scores['total_rooms'];
$descriptions = $this->getDescriptions($row['id_object']);
$descriptions = $this->getDescriptions($this->id_hotel ? 'room_type' : 'hotel', $row['id_object']);
foreach ($descriptions as $description) {
if (isset($description['iso_code']) && isset($description['description'])) {
$row['desclength_'.$description['iso_code']] = Tools::strlen(strip_tags($description['description']));
@@ -321,16 +360,16 @@ class StatsCheckUp extends Module
} else {
$objectLink = $this->context->link->getAdminLink('AdminAddHotel').'&updatehtl_branch_info&id='.$row['id_object'];
}
$this->html .= '
$hotelsHtml .= '
<tr>
<td>'.$row['id_object'].'</td>
<td><a href="'.$objectLink.'" target="_blank">'.Tools::substr($row['object_name'], 0, 42).'</a></td>
<td class="center">'.$array_colors[$scores['active']].'</td>';
foreach ($languages as $language) {
if (isset($row['desclength_'.$language['iso_code']])) {
$this->html .= '<td class="center">'.(int)$row['desclength_'.$language['iso_code']].' '.$array_colors[$scores['description_'.$language['iso_code']]].'</td>';
$hotelsHtml .= '<td class="center">'.(int)$row['desclength_'.$language['iso_code']].' '.$array_colors[$scores['description_'.$language['iso_code']]].'</td>';
} else {
$this->html .= '<td>0 '.$array_colors[0].'</td>';
$hotelsHtml .= '<td>0 '.$array_colors[0].'</td>';
}
}
@@ -339,7 +378,7 @@ class StatsCheckUp extends Module
$objectViewLink = $this->context->link->getAdminLink('AdminStats').'&module='.$this->name.'&id_hotel='.$row['id_object'];
}
$this->html .= '
$hotelsHtml .= '
<td class="center">'.(int)$row['nbImages'].' '.$array_colors[$scores['images']].'</td>
<td class="center">'.(int)$row['nbOrders'].' '.$array_colors[$scores['orders']].'</td>
<td class="center">'.(int)$row['totalRooms'].' '.$array_colors[$scores['total_rooms']].'</td>
@@ -348,7 +387,7 @@ class StatsCheckUp extends Module
</tr>';
}
$this->html .= '</tbody>';
$hotelsHtml .= '</tbody>';
$totals['active'] = $totals['active'] / $totals['products'];
$totals['active'] = ($totals['active'] < 1 ? 0 : ($totals['active'] > 1.5 ? 2 : 1));
@@ -365,15 +404,15 @@ class StatsCheckUp extends Module
$totals['average'] = array_sum($totals) / $divisor;
$totals['average'] = ($totals['average'] < 1 ? 0 : ($totals['average'] > 1.5 ? 2 : 1));
$this->html .= '
$hotelsHtml .= '
<tfoot>
<tr>
<th colspan="2"></th>
<th class="center"><span class="title_box active">'.$this->l('Active').'</span></th>';
foreach ($languages as $language) {
$this->html .= '<th class="center"><span class="title_box active">'.$this->l('Desc.').' ('.Tools::strtoupper($language['iso_code']).')</span></th>';
$hotelsHtml .= '<th class="center"><span class="title_box active">'.$this->l('Desc.').' ('.Tools::strtoupper($language['iso_code']).')</span></th>';
}
$this->html .= '
$hotelsHtml .= '
<th class="center"><span class="title_box active">'.$this->l('Images').'</span></th>
<th class="center"><span class="title_box active">'.$this->l('Orders').'</span></th>
<th class="center"><span class="title_box active">'.$this->l('Total rooms').'</span></th>
@@ -384,19 +423,248 @@ class StatsCheckUp extends Module
<td colspan="2"></td>
<td class="center">'.$array_colors[$totals['active']].'</td>';
foreach ($languages as $language) {
$this->html .= '<td class="center">'.$array_colors[$totals['description_'.$language['iso_code']]].'</td>';
$hotelsHtml .= '<td class="center">'.$array_colors[$totals['description_'.$language['iso_code']]].'</td>';
}
$this->html .= '
$hotelsHtml .= '
<td class="center">'.$array_colors[$totals['images']].'</td>
<td class="center">'.$array_colors[$totals['orders']].'</td>
<td class="center">'.$array_colors[$totals['total_rooms']].'</td>
<td class="center">'.$array_colors[$totals['average']].'</td>
'.(!$this->id_hotel ? '<td></td>' : '').'
</tr>
'.($this->id_hotel ? '
<tr>
<td colspan="100%">
<a class="btn btn-default" href="'.$this->context->link->getAdminLink('AdminStats').'&module='.$this->name.''.'">
<i class="icon-arrow-circle-left"></i> '.$this->l('Back').'
</a>
</td>
</tr>' : '').'
</tfoot>
</table></div>';
return $this->html;
return $hotelsHtml;
}
private function getServicesTab()
{
$employee = Context::getContext()->employee;
$prop30 = ((strtotime($employee->stats_date_to.' 23:59:59') - strtotime($employee->stats_date_from.' 00:00:00')) / 60 / 60 / 24) / 30;
// Get languages
$sql = 'SELECT l.*
FROM '._DB_PREFIX_.'lang l'
.Shop::addSqlAssociation('lang', 'l');
$languages = Db::getInstance()->executeS($sql);
$array_colors = array(
0 => '<img src="../modules/'.$this->name.'/img/red.png" alt="'.$this->l('Bad').'" title="'.$this->l('Bad').'" />',
1 => '<img src="../modules/'.$this->name.'/img/orange.png" alt="'.$this->l('Average').'" title="'.$this->l('Average').'" />',
2 => '<img src="../modules/'.$this->name.'/img/green.png" alt="'.$this->l('Good').'" title="'.$this->l('Good').'" />'
);
$divisor = 4;
$totals = array('services' => 0, 'active' => 0, 'images' => 0, 'orders' => 0, 'associated_room_types' => 0);
foreach ($languages as $language) {
$divisor++;
$totals['description_'.$language['iso_code']] = 0;
}
// set data from here
$result = $this->getServiceStats();
if (!$result) {
return $this->l('No service was found.');
}
$array_conf = array(
'DESCRIPTIONS_SHORT' => array('name' => $this->l('Descriptions'), 'text' => $this->l('chars (without HTML)')),
'IMAGES' => array('name' => $this->l('Images'), 'text' => $this->l('images')),
'ORDERS' => array('name' => $this->l('Orders'), 'text' => $this->l('orders / month')),
);
$servicesHtml = '
<form action="'.Tools::safeOutput(AdminController::$currentIndex.'&token='.Tools::getValue('token').'&module='.$this->name).'" method="post" class="checkup form-horizontal">
<table class="table checkup">
<thead>
<tr>
<th></th>
<th><span class="title_box active">'.$array_colors[0].' '.$this->l('Not enough').'</span></th>
<th><span class="title_box active">'.$array_colors[2].' '.$this->l('Alright').'</span></th>
</tr>
</thead>';
foreach ($array_conf as $conf => $translations) {
$confKeyLt = 'SERVICE_CHECKUP_'.$conf.'_LT';
$confKeyGt = 'SERVICE_CHECKUP_'.$conf.'_GT';
$servicesHtml .= '
<tbody>
<tr>
<td>
<label class="control-label col-lg-12">'.$translations['name'].'</label>
</td>
<td>
<div class="row">
<div class="col-lg-11 input-group">
<span class="input-group-addon">'.$this->l('Less than').'</span>
<input type="text" name="'.$confKeyLt.'" value="'.Tools::safeOutput(Tools::getValue($confKeyLt, Configuration::get($confKeyLt))).'" />
<span class="input-group-addon">'.$translations['text'].'</span>
</div>
</div>
</td>
<td>
<div class="row">
<div class="col-lg-12 input-group">
<span class="input-group-addon">'.$this->l('Greater than').'</span>
<input type="text" name="'.$confKeyGt.'" value="'.Tools::safeOutput(Tools::getValue($confKeyGt, Configuration::get($confKeyGt))).'" />
<span class="input-group-addon">'.$translations['text'].'</span>
</div>
</div>
</td>
</tr>
</tbody>';
}
$servicesHtml .= '</table>
<button type="submit" name="submitCheckupService" class="btn btn-default pull-right">
<i class="icon-save"></i> '.$this->l('Save').'
</button>
</form>
<form action="'.Tools::safeOutput(AdminController::$currentIndex.'&token='.Tools::getValue('token').'&module='.$this->name).'" method="post" class="form-horizontal alert">
<div class="row">
<div class="col-lg-12">
<label class="control-label pull-left">'.$this->l('Order by').'</label>
<div class="col-lg-3">
<select name="submitCheckupOrder" onchange="this.form.submit();">
<option value="'.self::ORDER_BY_ID.'">'.$this->l('ID').'</option>
<option value="'.self::ORDER_BY_NAME.'" '.($this->context->cookie->checkup_order == self::ORDER_BY_NAME ? 'selected="selected"' : '').'>'.$this->l('Name').'</option>
<option value="'.self::ORDER_BY_ORDERS.'" '.($this->context->cookie->checkup_order == self::ORDER_BY_ORDERS ? 'selected="selected"' : '').'>'.$this->l('Orders').'</option>
</select>
</div>
</div>
</div>
</form>
<div style="overflow-x:auto">
<table class="table checkup2">
<thead>
<tr>
<th><span class="title_box active">'.$this->l('ID').'</span></th>
<th><span class="title_box active">'.$this->l('Service').'</span></th>
<th class="center"><span class="title_box active">'.$this->l('Active').'</span></th>
<th class="center"><span class="title_box active">'.$this->l('Associated room types').'</span></th>';
foreach ($languages as $language) {
$servicesHtml .= '<th class="center"><span class="title_box active">'.$this->l('Desc.').' ('.Tools::strtoupper($language['iso_code']).')</span></th>';
}
$servicesHtml .= '
<th class="center"><span class="title_box active">'.$this->l('Images').'</span></th>
<th class="center"><span class="title_box active">'.$this->l('Orders').'</span></th>
<th class="center"><span class="title_box active">'.$this->l('Overall status').'</span></th>
'.(!$this->id_hotel ? '<th class="center"><span class="title_box active">'.$this->l('Action').'</span></th>' : '').'
</tr>
</thead>
<tbody>';
$confCheckup = array(
'IMAGES_LT' => Configuration::get('SERVICE_CHECKUP_IMAGES_LT'),
'IMAGES_GT' => Configuration::get('SERVICE_CHECKUP_IMAGES_GT'),
'ORDERS_LT' => Configuration::get('SERVICE_CHECKUP_ORDERS_LT'),
'ORDERS_GT' => Configuration::get('SERVICE_CHECKUP_ORDERS_GT'),
'DESCRIPTIONS_SHORT_LT' => Configuration::get('SERVICE_CHECKUP_DESCRIPTIONS_SHORT_LT'),
'DESCRIPTIONS_SHORT_GT' => Configuration::get('SERVICE_CHECKUP_DESCRIPTIONS_SHORT_GT'),
);
foreach ($result as $row) {
$totals['services']++;
$scores = array(
'active' => ($row['active'] ? 2 : 0),
'images' => ($row['nbImages'] < $confCheckup['IMAGES_LT'] ? 0 : ($row['nbImages'] > $confCheckup['IMAGES_GT'] ? 2 : 1)),
'orders' => (($row['nbOrders'] * $prop30 < $confCheckup['ORDERS_LT']) ? 0 : (($row['nbOrders'] * $prop30 > $confCheckup['ORDERS_GT']) ? 2 : 1)),
);
$totals['active'] += (int)$scores['active'];
$totals['images'] += (int)$scores['images'];
$totals['orders'] += (int)$scores['orders'];
$descriptions = $this->getDescriptions('service', $row['id_object']);
foreach ($descriptions as $description) {
if (isset($description['iso_code']) && isset($description['description_short'])) {
$row['desclength_'.$description['iso_code']] = Tools::strlen(strip_tags($description['description_short']));
}
if (isset($description['iso_code'])) {
$scores['description_'.$description['iso_code']] = ($row['desclength_'.$description['iso_code']] < $confCheckup['DESCRIPTIONS_SHORT_LT'] ? 0 : ($row['desclength_'.$description['iso_code']] > $confCheckup['DESCRIPTIONS_SHORT_GT'] ? 2 : 1));
$totals['description_'.$description['iso_code']] += $scores['description_'.$description['iso_code']];
}
}
$scores['average'] = array_sum($scores) / $divisor;
$scores['average'] = ($scores['average'] < 1 ? 0 : ($scores['average'] > 1.5 ? 2 : 1));
$objectLink = $this->context->link->getAdminLink('AdminNormalProducts').'&updateproduct&id_product='.$row['id_object'];
$servicesHtml .= '
<tr>
<td>'.$row['id_object'].'</td>
<td><a href="'.$objectLink.'" target="_blank">'.Tools::substr($row['object_name'], 0, 42).'</a></td>
<td class="center">'.$array_colors[$scores['active']].'</td>
<td class="center">'.$row['nbAssociatedRoomTypes'].'</td>';
foreach ($languages as $language) {
if (isset($row['desclength_'.$language['iso_code']])) {
$servicesHtml .= '<td class="center">'.(int)$row['desclength_'.$language['iso_code']].' '.$array_colors[$scores['description_'.$language['iso_code']]].'</td>';
} else {
$servicesHtml .= '<td class="center">0 '.$array_colors[0].'</td>';
}
}
$servicesHtml .= '
<td class="center">'.(int)$row['nbImages'].' '.$array_colors[$scores['images']].'</td>
<td class="center">'.(int)$row['nbOrders'].' '.$array_colors[$scores['orders']].'</td>
<td class="center">'.$array_colors[$scores['average']].'</td>
</tr>';
}
$servicesHtml .= '</tbody>';
$totals['active'] = $totals['active'] / $totals['services'];
$totals['active'] = ($totals['active'] < 1 ? 0 : ($totals['active'] > 1.5 ? 2 : 1));
$totals['images'] = $totals['images'] / $totals['services'];
$totals['images'] = ($totals['images'] < 1 ? 0 : ($totals['images'] > 1.5 ? 2 : 1));
$totals['orders'] = $totals['orders'] / $totals['services'];
$totals['orders'] = ($totals['orders'] < 1 ? 0 : ($totals['orders'] > 1.5 ? 2 : 1));
$totals['associated_room_types'] = $totals['associated_room_types'] / $totals['services'];
$totals['associated_room_types'] = ($totals['associated_room_types'] < 1 ? 0 : ($totals['associated_room_types'] > 1.5 ? 2 : 1));
foreach ($languages as $language) {
$totals['description_'.$language['iso_code']] = $totals['description_'.$language['iso_code']] / $totals['services'];
$totals['description_'.$language['iso_code']] = ($totals['description_'.$language['iso_code']] < 1 ? 0 : ($totals['description_'.$language['iso_code']] > 1.5 ? 2 : 1));
}
$totals['average'] = array_sum($totals) / $divisor;
$totals['average'] = ($totals['average'] < 1 ? 0 : ($totals['average'] > 1.5 ? 2 : 1));
$servicesHtml .= '
<tfoot>
<tr>
<th colspan="2"></th>
<th class="center"><span class="title_box active">'.$this->l('Active').'</span></th>
<th class="center"><span class="title_box active">'.$this->l('Associated room types').'</span></th>';
foreach ($languages as $language) {
$servicesHtml .= '<th class="center"><span class="title_box active">'.$this->l('Desc.').' ('.Tools::strtoupper($language['iso_code']).')</span></th>';
}
$servicesHtml .= '
<th class="center"><span class="title_box active">'.$this->l('Images').'</span></th>
<th class="center"><span class="title_box active">'.$this->l('Orders').'</span></th>
<th class="center"><span class="title_box active">'.$this->l('Overall status').'</span></th>
'.(!$this->id_hotel ? '<th></th>' : '').'
</tr>
<tr>
<td colspan="2"></td>
<td class="center">'.$array_colors[$totals['active']].'</td>
<td class="center">NA</td>';
foreach ($languages as $language) {
$servicesHtml .= '<td class="center">'.$array_colors[$totals['description_'.$language['iso_code']]].'</td>';
}
$servicesHtml .= '
<td class="center">'.$array_colors[$totals['images']].'</td>
<td class="center">'.$array_colors[$totals['orders']].'</td>
<td class="center">'.$array_colors[$totals['average']].'</td>
</tr>
</tfoot>
</table></div>';
return $servicesHtml;
}
public function getHotelStats()
@@ -479,20 +747,49 @@ class StatsCheckUp extends Module
return Db::getInstance()->executeS($sql);
}
public function getDescriptions($id_object)
public function getServiceStats()
{
if ($this->id_hotel) {
return Db::getInstance()->executeS(
'SELECT l.`iso_code`, pl.`description`
FROM '._DB_PREFIX_.'product_lang pl
LEFT JOIN '._DB_PREFIX_.'lang l
ON pl.`id_lang` = l.`id_lang`
LEFT JOIN '._DB_PREFIX_.'htl_room_type hrt
ON (hrt.`id_product` = pl.`id_product`)
WHERE hrt.`id_hotel` = '.(int) $this->id_hotel.'
AND pl.`id_product` = '.(int) $id_object
);
} else {
$date_from = date('Y-m-d', strtotime($this->context->employee->stats_date_from));
$date_to = date('Y-m-d', strtotime($this->context->employee->stats_date_to));
$id_lang = $this->context->language->id;
$order_by = 'p.`id_product`';
if ($this->context->cookie->checkup_order == self::ORDER_BY_NAME) {
$order_by = 'object_name';
} elseif ($this->context->cookie->checkup_order == self::ORDER_BY_ORDERS) {
$order_by = 'nbOrders DESC';
}
$sql = 'SELECT p.`id_product` AS id_object, p.`active`, pl.`name` AS object_name,
(
SELECT COUNT(*)
FROM '._DB_PREFIX_.'image i
WHERE i.`id_product` = p.`id_product`
) AS nbImages,
(
SELECT COUNT(DISTINCT rsod.`id_order`) FROM `'._DB_PREFIX_.'htl_room_type_service_product_order_detail` rsod
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = rsod.`id_order`)
LEFT JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd ON (hbd.`id` = rsod.`id_htl_booking_detail`)
WHERE rsod.`id_product` = p.`id_product` AND o.`valid` = 1
AND hbd.`date_to` > "'.pSQL($date_from).'" AND hbd.`date_from` < "'.pSQL($date_to).'"
) AS nbOrders,
(
SELECT COUNT(*)
FROM `'._DB_PREFIX_.'htl_room_type_service_product` rsp
WHERE rsp.`id_product` = p.`id_product`
) AS nbAssociatedRoomTypes
FROM '._DB_PREFIX_.'product p
LEFT JOIN '._DB_PREFIX_.'product_lang pl
ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int) $id_lang.')
WHERE p.`booking_product` = 0
ORDER BY '.$order_by;
return Db::getInstance()->executeS($sql);
}
public function getDescriptions($object_type, $id_object = null)
{
if ($object_type == 'hotel') {
return Db::getInstance()->executeS(
'SELECT l.`iso_code`, hbil.`description`
FROM '._DB_PREFIX_.'htl_branch_info_lang hbil
@@ -500,6 +797,27 @@ class StatsCheckUp extends Module
ON hbil.`id_lang` = l.`id_lang`
WHERE hbil.`id` = '.(int) $id_object
);
} elseif ($object_type == 'room_type') {
return Db::getInstance()->executeS(
'SELECT l.`iso_code`, pl.`description`
FROM '._DB_PREFIX_.'product_lang pl
LEFT JOIN '._DB_PREFIX_.'lang l
ON pl.`id_lang` = l.`id_lang`
INNER JOIN '._DB_PREFIX_.'htl_room_type hrt
ON (hrt.`id_product` = pl.`id_product`)
WHERE hrt.`id_hotel` = '.(int) $this->id_hotel.'
AND pl.`id_product` = '.(int) $id_object
);
} elseif ($object_type == 'service') {
return Db::getInstance()->executeS(
'SELECT l.`iso_code`, pl.`description_short`
FROM '._DB_PREFIX_.'product p
LEFT JOIN '._DB_PREFIX_.'product_lang pl
ON (pl.`id_product` = p.`id_product`)
LEFT JOIN '._DB_PREFIX_.'lang l
ON pl.`id_lang` = l.`id_lang`
WHERE p.`booking_product` = 0'
);
}
}
}

View File

@@ -119,6 +119,7 @@ class StatsProduct extends ModuleGraph
$sql .= ' INNER JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (hrt.`id_product` = p.`id_product` AND hrt.`id_hotel` = '.(int)Tools::getValue('id_hotel').')';
}
$sql .= ' LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang`='.(int)$this->context->language->id.')
WHERE p.`booking_product` = 1
ORDER BY pl.`name`';
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
@@ -302,20 +303,8 @@ class StatsProduct extends ModuleGraph
</thead>
<tbody>';
$bookingParams = array();
$bookingParams['date_from'] = $dateFrom;
$bookingParams['date_to'] = $dateTo;
foreach ($this->getProducts($this->context->language->id) as $product) {
$availRooms = 0;
if ($roomTypeInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($product['id_product'])) {
$bookingParams['hotel_id'] = $roomTypeInfo['id_hotel'];
$bookingParams['id_room_type'] = $product['id_product'];
if ($booking_data = $objBookingDtl->getBookingData($bookingParams)) {
if (isset($booking_data['stats']['num_avail'])) {
$availRooms = $booking_data['stats']['num_avail'];
}
}
}
// get room types info
foreach ($this->getProducts() as $product) {
$this->html .= '
<tr>
<td>