update hotel wise access in stats modules

This commit is contained in:
Shreesh Arora
2023-10-26 09:44:08 +05:30
parent ce93a9826f
commit 2a71b6b7bd
7 changed files with 181 additions and 115 deletions

View File

@@ -221,8 +221,11 @@ class StatsBestCategories extends ModuleGrid
AND hbd.`date_to` > "'.pSQL($date_from).'" AND hbd.`date_from` < "'.pSQL($date_to).'"
) AS totalOperatingCost
FROM `'._DB_PREFIX_.'htl_branch_info` hbi
INNER JOIN `'._DB_PREFIX_.'htl_access` ha
ON (hbi.`id` = ha.`id_hotel`)
LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbil
ON (hbil.`id` = hbi.`id` AND hbil.`id_lang` = '.(int)$id_lang .')
WHERE ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1
GROUP BY (hbi.`id`)';
if (Validate::IsName($this->_sort)) {

View File

@@ -209,7 +209,10 @@ class StatsBestProducts extends ModuleGrid
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 .')
WHERE p.`booking_product` = 1';
INNER JOIN `'._DB_PREFIX_.'htl_access` ha
ON (hbil.`id` = ha.`id_hotel`)
WHERE p.`booking_product` = 1
AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1';
if (Validate::IsName($this->_sort)) {
$this->query .= ' ORDER BY `'.bqSQL($this->_sort).'`';

View File

@@ -62,8 +62,10 @@ class StatsCatalog extends Module
IFNULL(SUM(p.`price`) / COUNT(p.`price`), 0) AS average_price
FROM `'._DB_PREFIX_.'product` p
INNER JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (hrt.`id_product` = p.`id_product`)
INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hrt.`id_hotel` = ha.`id_hotel`)
'.$this->join.'
WHERE p.`active` = 1
AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1
'.$this->where;
if ($this->id_hotel) {
$sql .= ' AND hrt.`id_hotel` = '.(int)$this->id_hotel;
@@ -80,8 +82,10 @@ class StatsCatalog extends Module
LEFT JOIN `'._DB_PREFIX_.'page_type` pt ON (pt.`id_page_type` = p.`id_page_type`)
LEFT JOIN `'._DB_PREFIX_.'category` cl ON (cl.`id_category` = p.`id_object`)
LEFT JOIN `'._DB_PREFIX_.'htl_branch_info` hbi ON (hbi.`id_category` = cl.`id_category`)
INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hbi.`id` = ha.`id_hotel`)
'.$this->join.'
WHERE pt.`name` = "'.pSQL('category').'"
AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1
'.$this->where;
if ($this->id_hotel) {
@@ -101,8 +105,10 @@ class StatsCatalog extends Module
LEFT JOIN `'._DB_PREFIX_.'page` pa ON p.`id_product` = pa.`id_object`
LEFT JOIN `'._DB_PREFIX_.'page_type` pt ON (pt.`id_page_type` = pa.`id_page_type` AND pt.`name` IN ("product.php", "product"))
LEFT JOIN `'._DB_PREFIX_.'page_viewed` pv ON pv.`id_page` = pa.`id_page`
INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hrt.`id_hotel` = ha.`id_hotel`)
'.$this->join.'
WHERE product_shop.`active` = 1
AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1
'.$this->where;
if ($this->id_hotel) {
@@ -120,9 +126,11 @@ class StatsCatalog extends Module
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`
INNER JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (p.`id_product` = hrt.`id_product`)
INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hrt.`id_hotel` = ha.`id_hotel`)
'.Shop::addSqlAssociation('product', 'p').'
'.$this->join.'
WHERE pt.`name` IN ("product.php", "product")
AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1
AND product_shop.`active` = 1
'.$this->where;
@@ -154,6 +162,9 @@ class StatsCatalog extends Module
WHERE hrt.`id_hotel` = hbi.`id`
) AS room_type_images
FROM `'._DB_PREFIX_.'htl_branch_info` hbi
INNER JOIN `'._DB_PREFIX_.'htl_access` ha
ON (hbi.`id` = ha.`id_hotel`)
WHERE ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1
) AS t
'.($this->id_hotel ? ' WHERE t.`id` = '.(int) $this->id_hotel : '')
);
@@ -164,7 +175,9 @@ class StatsCatalog extends Module
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(
'SELECT IFNULL(SUM(DATEDIFF(hbd.`date_to`, hbd.`date_from`)), 0)
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
'.($this->id_hotel ? ' WHERE hbd.`id_hotel` = '.(int) $this->id_hotel : '')
INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hbd.`id_hotel` = ha.`id_hotel`)
WHERE ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1
'.($this->id_hotel ? ' AND hbd.`id_hotel` = '.(int) $this->id_hotel : '')
);
}
@@ -175,9 +188,11 @@ class StatsCatalog extends Module
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`
INNER JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (p.`id_product` = hrt.`id_product`)
INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hrt.`id_hotel` = ha.`id_hotel`)
'.Shop::addSqlAssociation('product', 'p').'
'.$this->join.'
WHERE o.valid = 1
AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1
'.$this->where.'
AND product_shop.`active` = 1';
if ($this->id_hotel) {
@@ -195,10 +210,12 @@ class StatsCatalog extends Module
FROM `'._DB_PREFIX_.'product` p
'.Shop::addSqlAssociation('product', 'p').'
INNER JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (p.`id_product` = hrt.`id_product`)
INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hrt.`id_hotel` = ha.`id_hotel`)
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.'
WHERE product_shop.`active` = 1
AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1
'.(count($precalc2) ? 'AND p.`id_product` NOT IN ('.implode(',', $precalc2).')' : '').'
'.$this->where;
if ($this->id_hotel) {
@@ -212,7 +229,7 @@ class StatsCatalog extends Module
public function hookAdminStatsModules($params)
{
$objBranchInfo = new HotelBranchInformation();
$hotels = $objBranchInfo->hotelBranchesInfo((int)$this->context->language->id);
$hotels = $objBranchInfo->getProfileAccessedHotels($this->context->employee->id_profile, 1);
$product_token = Tools::getAdminToken('AdminProducts'.(int)Tab::getIdFromClassName('AdminProducts').(int)$this->context->employee->id);
$irow = 0;
@@ -223,6 +240,7 @@ class StatsCatalog extends Module
$result1 = $this->getQuery1();
$total = $result1['total'];
$average_price = $result1['average_price'];
$available_images = $this->getAvailableImages();
@@ -257,7 +275,7 @@ class StatsCatalog extends Module
<select name="id_hotel" onchange="$(\'#hotelForm\').submit();">
<option value="0">'.$this->l('All').'</option>';
foreach ($hotels as $hotel) {
$html .= '<option value="'.$hotel['id'].'"'.($id_hotel == $hotel['id'] ? ' selected="selected"' : '').'>'.
$html .= '<option value="'.$hotel['id_hotel'].'"'.($id_hotel == $hotel['id_hotel'] ? ' selected="selected"' : '').'>'.
$hotel['hotel_name'].'
</option>';
}

View File

@@ -699,8 +699,12 @@ class StatsCheckUp extends Module
WHERE hri.`id_hotel` = hbi.`id`
) AS totalRooms
FROM `'._DB_PREFIX_.'htl_branch_info` hbi
INNER JOIN `'._DB_PREFIX_.'htl_access` ha
ON (hbi.`id` = ha.`id_hotel`)
LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbil
ON (hbil.`id` = hbi.`id` AND hbil.`id_lang` = '.(int) $id_lang .')
WHERE ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1
GROUP BY (hbi.`id`)
ORDER BY '.$order_by;
return Db::getInstance()->executeS($sql);
@@ -741,7 +745,10 @@ class StatsCheckUp extends Module
ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int) $id_lang.')
LEFT JOIN '._DB_PREFIX_.'htl_room_type hrt
ON (hrt.`id_product` = p.`id_product`)
INNER JOIN `'._DB_PREFIX_.'htl_access` ha
ON (hrt.`id_hotel` = ha.`id_hotel`)
WHERE hrt.`id_hotel` = '.(int) $this->id_hotel.'
AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1
ORDER BY '.$order_by;
return Db::getInstance()->executeS($sql);

View File

@@ -170,7 +170,10 @@ class StatsForecast extends Module
WHERE hbd.`id_order` = o.`id_order`
)) AS totalOperatingCost
FROM '._DB_PREFIX_.'orders o
INNER JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd ON (hbd.`id_order` = o.`id_order`)
INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hbd.`id_hotel` = ha.`id_hotel`)
WHERE o.`valid` = 1
AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
'.Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o').'
GROUP BY '.$date_from_ginvoice
@@ -330,33 +333,48 @@ class StatsForecast extends Module
$sql = 'SELECT COUNT(DISTINCT c.`id_cart`)
FROM '._DB_PREFIX_.'cart c
INNER JOIN `'._DB_PREFIX_.'htl_cart_booking_data` hcbd ON (hcbd.`id_cart` = c.`id_cart`)
INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hcbd.`id_hotel` = ha.`id_hotel`)
WHERE c.`id_customer` != 0
AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1
AND (c.`date_add` BETWEEN '.ModuleGraph::getDateBetween().' OR c.`date_upd` BETWEEN '.ModuleGraph::getDateBetween().')';
$carts_registered = Db::getInstance()->getValue($sql);
$sql = 'SELECT COUNT(DISTINCT c.`id_cart`)
FROM '._DB_PREFIX_.'cart c
INNER JOIN `'._DB_PREFIX_.'htl_cart_booking_data` hcbd ON (hcbd.`id_cart` = c.`id_cart`)
INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hcbd.`id_hotel` = ha.`id_hotel`)
WHERE c.`id_customer` = 0
AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1
AND (c.`date_add` BETWEEN '.ModuleGraph::getDateBetween().' OR c.`date_upd` BETWEEN '.ModuleGraph::getDateBetween().')';
$carts_unregistered = Db::getInstance()->getValue($sql);
$sql = 'SELECT COUNT(*)
FROM '._DB_PREFIX_.'orders o
INNER JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd ON (hbd.`id_order` = o.`id_order`)
INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hbd.`id_hotel` = ha.`id_hotel`)
WHERE o.`valid` = 1
AND o.`date_add` BETWEEN '.ModuleGraph::getDateBetween();
AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1
AND o.`date_add` BETWEEN '.ModuleGraph::getDateBetween();
$orders = Db::getInstance()->getValue($sql);
$sql = 'SELECT COUNT(*)
FROM '._DB_PREFIX_.'orders o
INNER JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd ON (hbd.`id_order` = o.`id_order`)
INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hbd.`id_hotel` = ha.`id_hotel`)
INNER JOIN '._DB_PREFIX_.'customer c ON c.`id_customer` = o.`id_customer`
WHERE o.`valid` = 1 AND c.`is_guest` = 0
AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1
AND o.`date_add` BETWEEN '.ModuleGraph::getDateBetween();
$orders_registered = Db::getInstance()->getValue($sql);
$sql = 'SELECT COUNT(*)
FROM '._DB_PREFIX_.'orders o
INNER JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd ON (hbd.`id_order` = o.`id_order`)
INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hbd.`id_hotel` = ha.`id_hotel`)
INNER JOIN '._DB_PREFIX_.'customer c ON c.`id_customer` = o.`id_customer`
WHERE o.`valid` = 1 AND c.`is_guest` = 1
AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1
AND o.`date_add` BETWEEN '.ModuleGraph::getDateBetween();
$orders_unregistered = Db::getInstance()->getValue($sql);

View File

@@ -114,13 +114,17 @@ class StatsProduct extends ModuleGraph
{
$sql = 'SELECT p.`id_product`, p.reference, pl.`name`,
(SELECT COUNT(hri.`id`) FROM `'._DB_PREFIX_.'htl_room_information` hri WHERE hri.`id_product` = p.`id_product`) AS total_rooms
FROM `'._DB_PREFIX_.'product` p';
if (Tools::getValue('id_hotel')) {
$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.')
FROM `'._DB_PREFIX_.'product` p
INNER JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (hrt.`id_product` = p.`id_product`)
INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hrt.`id_hotel` = ha.`id_hotel`)
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`';
AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1';
if (Tools::getValue('id_hotel')) {
$sql .= ' AND hrt.`id_hotel` = '.(int)Tools::getValue('id_hotel');
}
$sql .= ' ORDER BY pl.`name`';
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
}
@@ -169,104 +173,111 @@ class StatsProduct extends ModuleGraph
</ul>
</div>';
if ($id_product = (int)Tools::getValue('id_product')) {
if (Tools::getValue('export')) {
if (Tools::getValue('exportType') == 1) {
$this->csvExport(array(
'layers' => 2,
'type' => 'line',
'option' => '1-'.$id_product
));
} elseif (Tools::getValue('exportType') == 2) {
$this->csvExport(array(
'type' => 'pie',
'option' => '3-'.$id_product
));
$objRoomType = new HotelRoomType();
if ($roomTypeInfo = $objRoomType->getRoomTypeInfoByIdProduct($id_product)) {
$objBranchInfo = new HotelBranchInformation();
$hotels = $objBranchInfo->getProfileAccessedHotels($this->context->employee->id_profile, 1, 1);
if (in_array($roomTypeInfo['id_hotel'], $hotels)) {
if (Tools::getValue('export')) {
if (Tools::getValue('exportType') == 1) {
$this->csvExport(array(
'layers' => 2,
'type' => 'line',
'option' => '1-'.$id_product
));
} elseif (Tools::getValue('exportType') == 2) {
$this->csvExport(array(
'type' => 'pie',
'option' => '3-'.$id_product
));
}
}
$product = new Product($id_product, false, $this->context->language->id);
$total_orders = $this->getTotalOrders($product->id);
$total_room_nights = $this->getTotalRoomNights($product->id);
$total_revenue = $this->getTotalRevenue($product->id);
$total_views = $this->getTotalViews($product->id);
$this->html .= '<h4>'.$product->name.' - '.$this->l('Details').'</h4>
<div class="row row-margin-bottom">
<div class="col-lg-12">
<div class="col-lg-8">
'.$this->engine(array(
'layers' => 2,
'type' => 'line',
'option' => '1-'.$id_product,
'has_label_y' => true,
)).'
</div>
<div class="col-lg-4">
<ul class="list-unstyled">
<li>'.$this->l('Total orders:').' '.$total_orders.'</li>
<li>'.$this->l('Total room nights:').' '.$total_room_nights.'</li>
<li>'.$this->l('Revenue:').' '.Tools::displayprice($total_revenue, $currency).'</li>
<li>'.$this->l('Total views:').' '.$total_views.'</li>
<li>'.$this->l('Conversion rate:').' '.sprintf('%0.2f', ($total_views ? $total_orders / $total_views : 0) * 100).'%</li>
</ul>
<a class="btn btn-default export-csv" href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=1">
<i class="icon-cloud-download"></i> '.$this->l('CSV Export').'
</a>
</div>
</div>
</div>';
if ($has_attribute = $product->hasAttributes() && $total_orders) {
$this->html .= '
<h3 class="space">'.$this->l('Attribute sales distribution').'</h3>
<center>'.$this->engine(array('type' => 'pie', 'option' => '3-'.$id_product)).'</center><br />
<a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=2"><img src="../img/admin/asterisk.gif" alt=""/>'.$this->l('CSV Export').'</a>';
}
if ($total_orders) {
$sales = $this->getSales($id_product);
$this->html .= '
<h4>'.$this->l('Sales').'</h4>
<div style="overflow-y:scroll;height:'.min(400, (count($sales) + 1) * 32).'px">
<table class="table">
<thead>
<tr>
<th>
<span class="title_box active">'.$this->l('Date').'</span>
</th>
<th>
<span class="title_box active">'.$this->l('Order').'</span>
</th>
<th>
<span class="title_box active">'.$this->l('Customer').'</span>
</th>
'.($has_attribute ? '<th><span class="title_box active">'.$this->l('Attribute').'</span></th>' : '').'
<th>
<span class="title_box active">'.$this->l('Room nights booked').'</span>
</th>
<th>
<span class="title_box active">'.$this->l('Revenue').'</span>
</th>
</tr>
</thead>
<tbody>';
$token_order = Tools::getAdminToken('AdminOrders'.(int)Tab::getIdFromClassName('AdminOrders').(int)$this->context->employee->id);
$token_customer = Tools::getAdminToken('AdminCustomers'.(int)Tab::getIdFromClassName('AdminCustomers').(int)$this->context->employee->id);
foreach ($sales as $sale) {
$this->html .= '
<tr>
<td>'.Tools::displayDate($sale['date_add'], null, false).'</td>
<td class="text-left"><a href="?tab=AdminOrders&id_order='.$sale['id_order'].'&vieworder&token='.$token_order.'" target="_blank">#'.(int)$sale['id_order'].'</a></td>
<td class="text-left"><a href="?tab=AdminCustomers&id_customer='.$sale['id_customer'].'&viewcustomer&token='.$token_customer.'" target="_blank">'.$sale['firstname'].' '.$sale['lastname'].' (#'.(int) $sale['id_customer'].')'.'</a></td>
'.($has_attribute ? '<td>'.$sale['product_name'].'</td>' : '').'
<td>'.(int)$sale['total_booked'].'</td>
<td>'.Tools::displayprice($sale['total'], $currency).'</td>
</tr>';
}
$this->html .= '
</tbody>
</table>
</div>';
}
}
}
$product = new Product($id_product, false, $this->context->language->id);
$total_orders = $this->getTotalOrders($product->id);
$total_room_nights = $this->getTotalRoomNights($product->id);
$total_revenue = $this->getTotalRevenue($product->id);
$total_views = $this->getTotalViews($product->id);
$this->html .= '<h4>'.$product->name.' - '.$this->l('Details').'</h4>
<div class="row row-margin-bottom">
<div class="col-lg-12">
<div class="col-lg-8">
'.$this->engine(array(
'layers' => 2,
'type' => 'line',
'option' => '1-'.$id_product,
'has_label_y' => true,
)).'
</div>
<div class="col-lg-4">
<ul class="list-unstyled">
<li>'.$this->l('Total orders:').' '.$total_orders.'</li>
<li>'.$this->l('Total room nights:').' '.$total_room_nights.'</li>
<li>'.$this->l('Revenue:').' '.Tools::displayprice($total_revenue, $currency).'</li>
<li>'.$this->l('Total views:').' '.$total_views.'</li>
<li>'.$this->l('Conversion rate:').' '.sprintf('%0.2f', ($total_views ? $total_orders / $total_views : 0) * 100).'%</li>
</ul>
<a class="btn btn-default export-csv" href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=1">
<i class="icon-cloud-download"></i> '.$this->l('CSV Export').'
</a>
</div>
</div>
</div>';
if ($has_attribute = $product->hasAttributes() && $total_orders) {
$this->html .= '
<h3 class="space">'.$this->l('Attribute sales distribution').'</h3>
<center>'.$this->engine(array('type' => 'pie', 'option' => '3-'.$id_product)).'</center><br />
<a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=2"><img src="../img/admin/asterisk.gif" alt=""/>'.$this->l('CSV Export').'</a>';
}
if ($total_orders) {
$sales = $this->getSales($id_product);
$this->html .= '
<h4>'.$this->l('Sales').'</h4>
<div style="overflow-y:scroll;height:'.min(400, (count($sales) + 1) * 32).'px">
<table class="table">
<thead>
<tr>
<th>
<span class="title_box active">'.$this->l('Date').'</span>
</th>
<th>
<span class="title_box active">'.$this->l('Order').'</span>
</th>
<th>
<span class="title_box active">'.$this->l('Customer').'</span>
</th>
'.($has_attribute ? '<th><span class="title_box active">'.$this->l('Attribute').'</span></th>' : '').'
<th>
<span class="title_box active">'.$this->l('Room nights booked').'</span>
</th>
<th>
<span class="title_box active">'.$this->l('Revenue').'</span>
</th>
</tr>
</thead>
<tbody>';
$token_order = Tools::getAdminToken('AdminOrders'.(int)Tab::getIdFromClassName('AdminOrders').(int)$this->context->employee->id);
$token_customer = Tools::getAdminToken('AdminCustomers'.(int)Tab::getIdFromClassName('AdminCustomers').(int)$this->context->employee->id);
foreach ($sales as $sale) {
$this->html .= '
<tr>
<td>'.Tools::displayDate($sale['date_add'], null, false).'</td>
<td class="text-left"><a href="?tab=AdminOrders&id_order='.$sale['id_order'].'&vieworder&token='.$token_order.'" target="_blank">#'.(int)$sale['id_order'].'</a></td>
<td class="text-left"><a href="?tab=AdminCustomers&id_customer='.$sale['id_customer'].'&viewcustomer&token='.$token_customer.'" target="_blank">'.$sale['firstname'].' '.$sale['lastname'].' (#'.(int) $sale['id_customer'].')'.'</a></td>
'.($has_attribute ? '<td>'.$sale['product_name'].'</td>' : '').'
<td>'.(int)$sale['total_booked'].'</td>
<td>'.Tools::displayprice($sale['total'], $currency).'</td>
</tr>';
}
$this->html .= '
</tbody>
</table>
</div>';
}
} else {
$objBranchInfo = new HotelBranchInformation();
$hotels = $objBranchInfo->hotelBranchesInfo((int)$this->context->language->id);
$hotels = $objBranchInfo->getProfileAccessedHotels($this->context->employee->id_profile, 1);
$this->html .= '
<form action="#" method="post" id="hotelsForm" class="form-horizontal">
<div class="row row-margin-bottom">
@@ -279,7 +290,7 @@ class StatsProduct extends ModuleGraph
<select name="id_hotel" onchange="$(\'#hotelsForm\').submit();">
<option value="0">'.$this->l('All').'</option>';
foreach ($hotels as $hotel) {
$this->html .= '<option value="'.$hotel['id'].'"'.($id_hotel == $hotel['id'] ? ' selected="selected"' : '').'>'.$hotel['hotel_name'].'</option>';
$this->html .= '<option value="'.$hotel['id_hotel'].'"'.($id_hotel == $hotel['id_hotel'] ? ' selected="selected"' : '').'>'.$hotel['hotel_name'].'</option>';
}
$this->html .= '
</select>

View File

@@ -82,7 +82,8 @@ class StatsSales extends ModuleGraph
}
$objHotelBranchInformation = new HotelBranchInformation();
$hotelsInfo = $objHotelBranchInformation->hotelsNameAndId();
$hotelsInfo = $objHotelBranchInformation->getProfileAccessedHotels($this->context->employee->id_profile, 1);
$this->html = '
<div class="panel-heading">
'.$this->displayName.'
@@ -109,7 +110,7 @@ class StatsSales extends ModuleGraph
<select name="id_hotel">
<option value="0"'.((!Tools::getValue('id_order_state')) ? ' selected="selected"' : '').'>'.$this->l('All hotels').'</option>';
foreach ($hotelsInfo as $hotel) {
$this->html .= '<option value="'.$hotel['id'].'"'.(($hotel['id'] == Tools::getValue('id_hotel')) ? ' selected="selected"' : '').'>'.$hotel['hotel_name'].'</option>';
$this->html .= '<option value="'.$hotel['id_hotel'].'"'.(($hotel['id_hotel'] == Tools::getValue('id_hotel')) ? ' selected="selected"' : '').'>'.$hotel['hotel_name'].'</option>';
}
$this->html .= '</select>
</div>';
@@ -192,19 +193,17 @@ class StatsSales extends ModuleGraph
{
$sql = 'SELECT COUNT(id_order) AS orderCount, ROUND(SUM(total_paid_real), 2) AS orderSum
FROM (
SELECT o.`id_order`, (o.`total_paid_real` / o.`conversion_rate`) AS total_paid_real,
(
SELECT hbd.`id_hotel`
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`id_order` = o.`id_order`
LIMIT 1
) AS id_hotel
SELECT o.`id_order`, (o.`total_paid_real` / o.`conversion_rate`) AS total_paid_real, hbd.`id_hotel`
FROM `'._DB_PREFIX_.'orders` o
INNER JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd ON (hbd.`id_order` = o.`id_order`)
INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hbd.`id_hotel` = ha.`id_hotel`)
'.((int)Tools::getValue('id_country') ? 'LEFT JOIN `'._DB_PREFIX_.'address` a ON o.`id_address_delivery` = a.`id_address`' : '').'
WHERE o.`valid` = 1
AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1
'.Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o').'
'.((int)Tools::getValue('id_country') ? ' AND a.`id_country` = '.(int)Tools::getValue('id_country') : '').'
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
GROUP BY o.`id_order`
) AS t
'.((int)Tools::getValue('id_hotel') ? ' WHERE id_hotel = '.(int)Tools::getValue('id_hotel') : '');
@@ -242,8 +241,11 @@ class StatsSales extends ModuleGraph
LIMIT 1
) AS id_hotel
FROM `'._DB_PREFIX_.'orders` o
INNER JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd ON (hbd.`id_order` = o.`id_order`)
INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hbd.`id_hotel` = ha.`id_hotel`)
'.((int)$this->id_country ? 'LEFT JOIN `'._DB_PREFIX_.'address` a ON o.`id_address_delivery` = a.`id_address`' : '').'
WHERE o.`valid` = 1
AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1
'.Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o').'
'.((int)$this->id_country ? ' AND a.`id_country` = '.(int)$this->id_country : '').'
AND o.`invoice_date` BETWEEN';
@@ -319,6 +321,8 @@ class StatsSales extends ModuleGraph
LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int)$this->getLang().')
LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON os.`id_order_state` = oh.`id_order_state`
LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = oh.`id_order`
INNER JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd ON (hbd.`id_order` = o.`id_order`)
INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hbd.`id_hotel` = ha.`id_hotel`)
'.((int)$this->id_country ? 'LEFT JOIN `'._DB_PREFIX_.'address` a ON o.id_address_delivery = a.id_address' : '').'
WHERE oh.`id_order_history` = (
SELECT ios.`id_order_history`
@@ -327,8 +331,10 @@ class StatsSales extends ModuleGraph
ORDER BY ios.`date_add` DESC, oh.`id_order_history` DESC
LIMIT 1
)
AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1
'.((int)$this->id_country ? 'AND a.id_country = '.(int)$this->id_country : '').'
AND o.`date_add` BETWEEN '.ModuleGraph::getDateBetween().'
GROUP BY o.`id_order`
) AS t
'.(((int) $this->id_hotel) ? ' WHERE id_hotel = '.(int) $this->id_hotel : '').'
GROUP BY t.`id_order_state`';