Skip to content

Commit

Permalink
dashboard improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
lakshya chauhan committed Jan 12, 2022
1 parent 8a5c66f commit c14122e
Show file tree
Hide file tree
Showing 95 changed files with 5,595 additions and 811 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,19 @@
</script>

<div id="dashboard">
{$hookDashboardUnnamedOne}
<div class="row">
<div class="col-lg-12">
{if $warning}
<div class="alert alert-warning">{$warning}</div>
{/if}
<div id="calendar" class="panel">
<form action="{$action|escape}" method="post" id="calendar_form" name="calendar_form" class="form-inline">
<form action="{$action|escape}" method="get" id="calendar_form" name="calendar_form" class="form-inline">
<div class="btn-group">
<button type="button" name="submitDateDay" class="btn btn-default submitDateDay{if isset($preselect_date_range) && $preselect_date_range == 'day'} active{/if}">
<button type="button" name="submitDateDay" class="btn btn-default submitDateDay{if (!isset($preselect_date_range) || !$preselect_date_range) || (isset($preselect_date_range) && $preselect_date_range == 'day')} active{/if}">
{l s='Day'}
</button>
<button type="button" name="submitDateMonth" class="btn btn-default submitDateMonth{if (!isset($preselect_date_range) || !$preselect_date_range) || (isset($preselect_date_range) && $preselect_date_range == 'month')} active{/if}">
<button type="button" name="submitDateMonth" class="btn btn-default submitDateMonth {if isset($preselect_date_range) && $preselect_date_range == 'month'}active{/if}">
{l s='Month'}
</button>
<button type="button" name="submitDateYear" class="btn btn-default submitDateYear{if isset($preselect_date_range) && $preselect_date_range == 'year'} active{/if}">
Expand All @@ -57,10 +58,6 @@
<button type="button" name="submitDateYearPrev" class="btn btn-default submitDateYearPrev{if isset($preselect_date_range) && $preselect_date_range == 'prev-year'} active{/if}">
{l s='Year'}-1
</button>
<!--
<button type="submit" name="submitDateRealTime" class="hide btn btn-default submitDateRealTime {if $dashboard_use_push}active{/if}" value="{!$dashboard_use_push|intval}">
{l s='Real Time'}
</button> -->
</div>
<input type="hidden" name="datepickerFrom" id="datepickerFrom" value="{$date_from|escape}" class="form-control">
<input type="hidden" name="datepickerTo" id="datepickerTo" value="{$date_to|escape}" class="form-control">
Expand All @@ -87,30 +84,10 @@
<div class="col-md-4 col-lg-3" id="hookDashboardZoneOne">
{$hookDashboardZoneOne}
</div>
<div class="col-md-8 col-lg-7" id="hookDashboardZoneTwo">
{$hookDashboardZoneTwo}
</div>
<div class="col-md-12 col-lg-2">
{$hookDashboardZoneThree}
<section class="dash_links panel">
<h3><i class="icon-link"></i> {l s="Useful links"}</h3>
<dl>
<dt><a href="https://qloapps.com/qlo-reservation-system/" class="_blank">{l s="Official Documentation"}</a></dt>
<dd>{l s="Qloapps User Guide"}</dd>
</dl>
<dl>
<dt><a href="https://forums.qloapps.com/" class="_blank">{l s="Qloapps Forum"}</a></dt>
<dd>{l s="Connect with the Qloapps community"}</dd>
</dl>
<dl>
<dt><a href="https://qloapps.com/addons/" class="_blank">{l s="Qloapps Addons"}</a></dt>
<dd>{l s="Enhance your store Qloapps modules"}</dd>
</dl>
<dl>
<dt><a href="https://qloapps.com/contact/" class="_blank">{l s="Contact Us!"}</a></dt>
<dd>{l s="Contact us for any help"}</dd>
</dl>
</section>
<div class="col-md-8 col-lg-9" id="hookDashboardZoneTwo">
<div class='row'>
{$hookDashboardZoneTwo}
</div>
</div>
</div>
</div>
9 changes: 9 additions & 0 deletions classes/CustomerMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,13 @@ public function delete()
}
return parent::delete();
}

public static function getMessagesByDate($date)
{
return Db::getInstance()->getValue(
'SELECT COUNT(cm.`id_customer_message`)
FROM `'._DB_PREFIX_.'customer_message` cm
WHERE cm.`date_add` BETWEEN "'.pSQL($date).' 00:00:00" AND "'.pSQL($date).' 23:59:59"'
);
}
}
221 changes: 220 additions & 1 deletion controllers/admin/AdminStatsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ public function displayAjaxGetKpi()
}
$value .= '%';

// ConfigurationKPI::updateValue('CONVERSION_RATE_CHART', json_encode($data));
// ConfigurationKPI::updateValue('CONVERSION_RATE_CHART', Tools::jsonEncode($data));
ConfigurationKPI::updateValue('CONVERSION_RATE', $value);
ConfigurationKPI::updateValue('CONVERSION_RATE_EXPIRE', strtotime(date('Y-m-d 00:00:00', strtotime('+1 day'))));
break;
Expand Down Expand Up @@ -797,4 +797,223 @@ public function displayAjaxGetKpi()
}
die(json_encode(array('has_errors' => true)));
}

public static function getArrivalsByDate($date)
{
$totalArrivals = Db::getInstance()->getValue(
'SELECT COUNT(hbd.`id_room`)
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`is_refunded` = 0 AND hbd.`is_back_order` = 0
AND hbd.`date_from` BETWEEN "'.pSQL($date).' 00:00:00" AND "'.pSQL($date).' 23:59:59"'
);

$arrived = Db::getInstance()->getValue(
'SELECT COUNT(hbd.`id_room`)
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`is_refunded` = 0 AND hbd.`is_back_order` = 0
AND hbd.`date_from` BETWEEN "'.pSQL($date).' 00:00:00" AND "'.pSQL($date).' 23:59:59"
AND hbd.`id_status` = '.(int)HotelBookingDetail::STATUS_CHECKED_IN
);

return array('arrived' => $arrived, 'total_arrivals' => $totalArrivals);
}

public static function getDeparturesByDate($date)
{
$totalDepartures = Db::getInstance()->getValue(
'SELECT COUNT(hbd.`id_room`)
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`is_refunded` = 0 AND hbd.`is_back_order` = 0
AND hbd.`date_to` BETWEEN "'.pSQL($date).' 00:00:00" AND "'.pSQL($date).' 23:59:59"'
);

$departed = Db::getInstance()->getValue(
'SELECT COUNT(hbd.`id_room`)
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`is_refunded` = 0 AND hbd.`is_back_order` = 0
AND hbd.`date_to` BETWEEN "'.pSQL($date).' 00:00:00" AND "'.pSQL($date).' 23:59:59"
AND hbd.`id_status` = '.(int)HotelBookingDetail::STATUS_CHECKED_OUT
);

return array('departed' => $departed, 'total_departures' => $totalDepartures);
}

public static function getBookingsByDate($date)
{
return Db::getInstance()->getValue(
'SELECT COUNT(o.`id_order`)
FROM `'._DB_PREFIX_.'orders` o
WHERE o.`date_add` BETWEEN "'.pSQL($date).' 00:00:00" AND "'.pSQL($date).' 23:59:59"'
);
}

public static function getStayOversByDate($date)
{
return Db::getInstance()->getValue(
'SELECT COUNT(hbd.`id_room`)
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE 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).' 00:00:00"'
);
}

public static function getCancelledBookingsByDate($date)
{
return Db::getInstance()->getValue(
'SELECT COUNT(o.`id_order`)
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = o.`current_state`)
WHERE o.`date_upd` BETWEEN "'.pSQL($date).' 00:00:00" AND "'.pSQL($date).' 23:59:59"
AND o.`current_state` = '.(int)Configuration::get('PS_OS_CANCELED')
);
}

public static function getGuestsByDate($date)
{
return Db::getInstance()->getRow(
'SELECT SUM(hbd.`adult`) AS `adults`, SUM(hbd.`children`) AS `children`
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`is_refunded` = 0 AND hbd.`is_back_order` = 0
AND hbd.`date_from` BETWEEN "'.pSQL($date).' 00:00:00" AND "'.pSQL($date).' 23:59:59"'
);
}

public static function getTotalRooms()
{
return Db::getInstance()->getValue(
'SELECT COUNT("id") FROM `'._DB_PREFIX_.'htl_room_information`'
);
}

public static function getAvailPieChartData($date_from, $date_to)
{
$bookedRoomSql = 'SELECT hri.id FROM `'._DB_PREFIX_.'htl_booking_detail` as hbd LEFT JOIN
`'._DB_PREFIX_.'htl_room_information` as hri ON hbd.id_room = hri.id WHERE hbd.date_from BETWEEN "'
.pSQL($date_from).'" and "'.pSQL($date_to).'" OR hbd.date_to BETWEEN "'.pSQL($date_from).'" and "'
.pSQL($date_to).'" AND is_refunded = 0 AND is_back_order = 0';

$tempBookedRoomIds = Db::getInstance()->ExecuteS($bookedRoomSql);
$bookedRoomIds = array();
if (count($tempBookedRoomIds)) {
foreach ($tempBookedRoomIds as $value) {
if ($value['id']) {
$bookedRoomIds[] = $value['id'];
}
}
} else {
$bookedRoomIds[] = "0";
}

$availRoomSql = 'SELECT COUNT("id") FROM `'._DB_PREFIX_.'htl_room_information` WHERE id NOT IN
('.implode(',', $bookedRoomIds).') AND id_status != '.(int)HotelRoomInformation::STATUS_INACTIVE.
' AND id_status != '.(int)HotelRoomInformation::STATUS_TEMPORARY_INACTIVE;
$availRoomIds = Db::getInstance()->getValue($availRoomSql);

$inactiveSql = 'SELECT COUNT("id") FROM `'._DB_PREFIX_.'htl_room_information` WHERE id_status = 2 OR
id_status = 3';
$inactiveRoomIds = Db::getInstance()->getValue($inactiveSql);


$data = array();
$data['occupied'] = sprintf("%02d", count($tempBookedRoomIds));
$data['available'] = sprintf("%02d", $availRoomIds);
$data['inactive'] = sprintf("%02d", $inactiveRoomIds);
return $data;
}

public static function getAvailBarChartData($days, $date_from)
{
$newFromDate = $date_from;
$availability_data = array();
$from = strtotime($date_from." 00:00:00");
$to = min(time(), strtotime($date_from."+".$days." day 23:59:59"));

for ($date = $from; $date <= $to; $date = strtotime("+1 days", $date)) {
$newFromDate = date('Y-m-d', strtotime($newFromDate.'+'.($days/5).'days'));
$bookedRoomSql = 'SELECT hri.id FROM `'._DB_PREFIX_.
'htl_booking_detail` as hbd LEFT JOIN `'._DB_PREFIX_
.'htl_room_information` as hri ON hbd.id_room = hri.id WHERE hbd.date_from <= "'.pSQL($newFromDate)
.'" and hbd.date_to >= "'.pSQL(date('Y-m-d' ,strtotime($newFromDate."+1 days"))).'" AND is_refunded = 0 AND is_back_order = 0';

$tempBookedRoomIds = Db::getInstance()->ExecuteS($bookedRoomSql);
$bookedRoomIds = array();
if (count($tempBookedRoomIds)) {
foreach ($tempBookedRoomIds as $value) {
if ($value['id']) {
$bookedRoomIds[] = $value['id'];
}
}
} else {
$bookedRoomIds[] = "0";
}

$availRoomSql = 'SELECT COUNT("id") FROM `'._DB_PREFIX_.'htl_room_information` WHERE id NOT IN
('.implode(',', $bookedRoomIds).') AND id_status != '.(int)HotelRoomInformation::STATUS_INACTIVE.'
AND id_status != '.(int)HotelRoomInformation::STATUS_TEMPORARY_INACTIVE;
$availRoomIds = Db::getInstance()->getValue($availRoomSql);

$availability_data["values"][] = array($date, sprintf("%02d", $availRoomIds));
}
return $availability_data;
}

public static function getAverageDailyRate($dateFrom, $dateTo)
{
$result = Db::getInstance()->getRow(
'SELECT
SUM(hbd.`total_price_tax_excl`) AS `rooms_revenue`,
COUNT(hbd.`id_room`) AS `room_sold`
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`is_refunded` = 0 AND hbd.`is_back_order` = 0
AND hbd.`date_add` BETWEEN "'.pSQL($dateFrom).' 00:00:00" AND "'.pSQL($dateTo).' 23:59:59"'
);
return Tools::displayPrice($result['rooms_revenue'] ? $result['rooms_revenue'] / $result['room_sold'] : 0);
}

public static function getCancellationRate($dateFrom, $dateTo)
{
$numAllOrders = Db::getInstance()->getValue(
'SELECT COUNT(o.`id_order`) FROM `'._DB_PREFIX_.'orders` o
WHERE o.`date_add` BETWEEN "'.pSQL($dateFrom).' 00:00:00" AND "'.pSQL($dateTo).' 23:59:59"'
);

$numCancelledOrders = Db::getInstance()->getValue(
'SELECT COUNT(o.`id_order`) FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = o.`current_state`)
WHERE o.`date_add` BETWEEN "'.pSQL($dateFrom).' 00:00:00" AND "'.pSQL($dateTo).' 23:59:59"
AND o.`current_state` = '.(int)Configuration::get('PS_OS_CANCELED')
);

if ($numCancelledOrders != 0) {
return round(($numCancelledOrders / $numAllOrders) * 100, 2).'%';
} else {
return '0.00%';
}
}

public static function getRevenue($dateFrom, $dateTo)
{
$result = Db::getInstance()->getValue(
'SELECT SUM(`total_paid_tax_excl` / `conversion_rate`)
FROM `'._DB_PREFIX_.'orders`
WHERE `invoice_date` BETWEEN "'.pSQL($dateFrom).' 00:00:00" AND "'.pSQL($dateTo).' 23:59:59"'
);
return Tools::displayPrice($result ? $result : 0);
}

public static function getNightsStayed($dateFrom, $dateTo)
{
return Db::getInstance()->getValue(
'SELECT COUNT(a.`id`)
FROM `'._DB_PREFIX_.'htl_booking_detail` a
WHERE a.`is_refunded` = 0 AND a.`is_back_order` = 0
AND ((a.`id_status` = '.(int)HotelBookingDetail::STATUS_CHECKED_IN.'
AND a.`check_in` <= "'.pSQL($dateFrom).' 00:00:00" AND a.`check_out` > "'.pSQL($dateFrom).' 23:59:59") OR (
a.`id_status` = '.(int)HotelBookingDetail::STATUS_CHECKED_OUT.'
AND a.`check_in` >= "'.pSQL($dateFrom).' 00:00:00" AND a.`check_out` <= "'.pSQL($dateTo).' 23:59:59") OR (
a.`id_status` = '.(int)HotelBookingDetail::STATUS_CHECKED_IN.'
AND a.`check_in` <= "'.pSQL($dateTo).' 00:00:00" AND a.`check_out` > "'.pSQL($dateTo).' 23:59:59"))'
);
}
}
14 changes: 10 additions & 4 deletions install/models/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
* International Registered Trademark & Property of PrestaShop SA
*/

require_once (_PS_TOOL_DIR_.'defuse/php-encryption/defuse-crypto.phar');

class InstallModelInstall extends InstallAbstractModel
{
const SETTINGS_FILE = 'config/settings.inc.php';
Expand Down Expand Up @@ -71,7 +69,6 @@ public function generateSettingsFile($database_server, $database_login, $databas
$this->setError($this->language->l('%s folder is not writable (check permissions)', dirname(self::SETTINGS_FILE)));
return false;
}
$key = \Defuse\Crypto\Key::createNewRandomKey();

// Generate settings content and write file
$settings_constants = array(
Expand All @@ -85,12 +82,17 @@ public function generateSettingsFile($database_server, $database_login, $databas
'_PS_CACHE_ENABLED_' => '0',
'_COOKIE_KEY_' => Tools::passwdGen(56),
'_COOKIE_IV_' => Tools::passwdGen(8),
'_NEW_COOKIE_KEY_' => $key->saveToAsciiSafeString(),
'_PS_CREATION_DATE_' => date('Y-m-d'),
'_PS_VERSION_' => _PS_INSTALL_VERSION_,
'_QLOAPPS_VERSION_' => _QLO_INSTALL_VERSION_,
);

// If mcrypt is activated, add Rijndael 128 configuration
if (function_exists('mcrypt_encrypt')) {
$settings_constants['_RIJNDAEL_KEY_'] = Tools::passwdGen(mcrypt_get_key_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
$settings_constants['_RIJNDAEL_IV_'] = base64_encode(mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND));
}

$settings_content = "<?php\n";

foreach ($settings_constants as $constant => $value) {
Expand Down Expand Up @@ -665,9 +667,13 @@ public function getModulesList()
'wkfooterpaymentblock',
'wkfooternotificationblock',
'blocknavigationmenu',
'dashguestcycle',
'dashoccupancy',
'dashavailability',
'dashactivity',
'dashtrends',
'dashgoals',
'dashperformance',
'dashproducts',
'graphnvd3',
'statsdata',
Expand Down
Loading

0 comments on commit c14122e

Please sign in to comment.