updated room status to constants

This commit is contained in:
shreesh arora
2021-05-20 18:20:35 +05:30
parent b7ef2391cc
commit 9f10eaac69
8 changed files with 52 additions and 91 deletions

View File

@@ -301,11 +301,11 @@
<div class="col-sm-7">
<select name="booking_order_status" class="form-control booking_order_status margin-bottom-5">
{foreach from=$hotel_order_status item=state}
<option value="{$state['id']|intval}" {if isset($data.id_status) && $state.id == $data.id_status} selected="selected" disabled="disabled"{/if}>{$state.status|escape}</option>
<option value="{$state['id_status']|intval}" {if isset($data.id_status) && $state.id_status == $data.id_status} selected="selected" disabled="disabled"{/if}>{$state.name|escape}</option>
{/foreach}
</select>
{if $data['id_status'] == 2}<span class="badge badge-success margin-bottom-5">{l s='checked in on'} {$data['check_in']|date_format:"%d-%m-%Y"}</span>{elseif $data['id_status'] == 3}<span class="badge badge-success margin-bottom-5">{l s='checked out on'} {$data['check_out']|date_format:"%d-%m-%Y"}</span>{/if}
{if $data['id_status'] == $hotel_order_status['STATUS_CHECKED_IN']['id_status']}<span class="badge badge-success margin-bottom-5">{l s='checked in on'} {$data['check_in']|date_format:"%d-%m-%Y"}</span>{elseif $data['id_status'] == $hotel_order_status['STATUS_CHECKED_OUT']['id_status']}<span class="badge badge-success margin-bottom-5">{l s='checked out on'} {$data['check_out']|date_format:"%d-%m-%Y"}</span>{/if}
{* field for the current date *}
<input class="room_status_date wk-input-date" type="text" name="status_date" value="{$data['date_from']|date_format:"%d-%m-%Y"}" readonly/>

View File

@@ -1548,7 +1548,7 @@ class AdminOrdersControllerCore extends AdminController
$bookingOrderInfo = $objBookingDetail->getBookingDataByOrderId($order->id);
// hotel booking statuses
$htlOrderStatus = HotelOrderStatus::getAllHotelOrderStatus();
$htlOrderStatus = HotelBookingDetail::getAllHotelOrderStatus();
$this->tpl_view_vars = array(
// refund info
@@ -3369,7 +3369,10 @@ class AdminOrdersControllerCore extends AdminController
if (!$newStatus) {
$this->errors[] = Tools::displayError('Invalid booking status found.');
} elseif ($newStatus == 2 || $newStatus == 3) {
} elseif (
$newStatus == HotelBookingDetail::STATUS_CHECKED_IN
|| $newStatus == HotelBookingDetail::STATUS_CHECKED_OUT
) {
if (!$statusDate || !Validate::isDate($statusDate)) {
$this->errors[] = Tools::displayError('Invalid dates found.');
} elseif ((strtotime($statusDate) < strtotime($dateFrom))
@@ -3383,22 +3386,22 @@ class AdminOrdersControllerCore extends AdminController
$objBookingDetail = new HotelBookingDetail();
if ($roomBookingInfo = $objBookingDetail->getRoomBookingData($idRoom, $idOrder)) {
// if admin choose Check-Out status
if ($newStatus == 3
if ($newStatus == HotelBookingDetail::STATUS_CHECKED_OUT
&& $roomBookingInfo['check_in'] == '0000-00-00 00:00:00'
) {
$this->errors[] = Tools::displayError('Room status must be set to Check-In before setting the room status to Check-Out.');
} elseif ($newStatus == 3
} elseif ($newStatus == HotelBookingDetail::STATUS_CHECKED_OUT
&& $roomBookingInfo['check_in'] != '0000-00-00 00:00:00'
&& strtotime($roomBookingInfo['check_in']) >= strtotime($statusDate)
) {
$this->errors[] = Tools::displayError('Check-Out date can not be before Check-In date').
'('.date('d-m-Y', strtotime($roomBookingInfo['check_in'])).')';
} elseif ($newStatus == 2 && $roomBookingInfo['check_out'] == '0000-00-00 00:00:00'
} elseif ($newStatus == HotelBookingDetail::STATUS_CHECKED_IN && $roomBookingInfo['check_out'] == '0000-00-00 00:00:00'
&& strtotime($roomBookingInfo['check_in']) >= strtotime($dateTo)
) {
$this->errors[] = Tools::displayError('Check-In date can not be after Check-Out date').
'('.date('d-m-Y', strtotime($roomBookingInfo['date_to'])).')';
} elseif ($newStatus == 2 && $roomBookingInfo['check_out'] != '0000-00-00 00:00:00'
} elseif ($newStatus == HotelBookingDetail::STATUS_CHECKED_IN && $roomBookingInfo['check_out'] != '0000-00-00 00:00:00'
&& strtotime($roomBookingInfo['check_out']) <= strtotime($statusDate)
) {
$this->errors[] = Tools::displayError('Check-In date can not be after Check-Out date').

View File

@@ -64,6 +64,10 @@ class HotelBookingDetail extends ObjectModel
public $date_add;
public $date_upd;
const STATUS_ALLOTED = 1;
const STATUS_CHECKED_IN = 2;
const STATUS_CHECKED_OUT = 3;
public static $definition = array(
'table' => 'htl_booking_detail',
'primary' => 'id',
@@ -273,7 +277,7 @@ class HotelBookingDetail extends ObjectModel
$sql = 'SELECT bd.`id_product`, bd.`id_room`, bd.`id_hotel`, bd.`id_customer`, bd.`booking_type`, bd.`id_status` AS booking_status, bd.`comment`, rf.`room_num`, bd.`date_from`, bd.`date_to`
FROM `'._DB_PREFIX_.'htl_booking_detail` AS bd
INNER JOIN `'._DB_PREFIX_.'htl_room_information` AS rf ON (rf.`id` = bd.`id_room`)
WHERE bd.`id_hotel`='.(int)$hotel_id.' AND bd.`id_product` ='.(int)$room_type['id_product'].' AND bd.`is_refunded` = 0 AND bd.`is_back_order` = 0 AND IF(bd.`id_status` = 3, bd.`date_from` <= \''.pSQL($date_from).'\' AND bd.`check_out` >= \''.pSQL($date_to).'\', bd.`date_from` <= \''.pSQL($date_from).'\' AND bd.date_to >= \''.pSQL($date_to).'\')';
WHERE bd.`id_hotel`='.(int)$hotel_id.' AND bd.`id_product` ='.(int)$room_type['id_product'].' AND bd.`is_refunded` = 0 AND bd.`is_back_order` = 0 AND IF(bd.`id_status` = '. self::STATUS_CHECKED_OUT .', bd.`date_from` <= \''.pSQL($date_from).'\' AND bd.`check_out` >= \''.pSQL($date_to).'\', bd.`date_from` <= \''.pSQL($date_from).'\' AND bd.date_to >= \''.pSQL($date_to).'\')';
$booked_rooms = Db::getInstance()->executeS($sql);
@@ -301,12 +305,12 @@ class HotelBookingDetail extends ObjectModel
if ($search_unavai) {
$sql1 = 'SELECT `id_product`, `id_hotel`, `room_num`, `comment` AS `room_comment`
FROM `'._DB_PREFIX_.'htl_room_information`
WHERE `id_hotel`='.(int)$hotel_id.' AND `id_product` ='.(int)$room_type['id_product'].' AND `id_status` = 2';
WHERE `id_hotel`='.(int)$hotel_id.' AND `id_product` ='.(int)$room_type['id_product'].' AND `id_status` = '. self::STATUS_CHECKED_IN;
$sql2 = 'SELECT hri.`id_product`, hri.`id_hotel`, hri.`room_num`, hri.`comment` AS `room_comment`
FROM `'._DB_PREFIX_.'htl_room_information` AS hri
INNER JOIN `'._DB_PREFIX_.'htl_room_disable_dates` AS hrdd ON (hrdd.`id_room_type` = hri.`id_product` AND hrdd. id_room = hri.`id`)
WHERE hri.`id_hotel`='.$hotel_id.' AND hri.`id_product` ='.$room_type['id_product'].' AND hri.`id_status` = 3 AND hrdd.`date_from` <= \''.pSql($date_from).'\' AND hrdd.`date_to` >= \''.pSql($date_to).'\'';
WHERE hri.`id_hotel`='.$hotel_id.' AND hri.`id_product` ='.$room_type['id_product'].' AND hri.`id_status` = '. self::STATUS_CHECKED_OUT .' AND hrdd.`date_from` <= \''.pSql($date_from).'\' AND hrdd.`date_to` >= \''.pSql($date_to).'\'';
$sql = $sql1.' UNION '.$sql2;
@@ -317,7 +321,7 @@ class HotelBookingDetail extends ObjectModel
if ($search_available) {
$exclude_ids = 'SELECT `id_room`
FROM `'._DB_PREFIX_.'htl_booking_detail`
WHERE `is_back_order` = 0 AND `is_refunded` = 0 AND IF(`id_status` = 3, (
WHERE `is_back_order` = 0 AND `is_refunded` = 0 AND IF(`id_status` = '. self::STATUS_CHECKED_OUT.', (
(DATE_FORMAT(`check_out`, "%Y-%m-%d") > \''.pSQL($date_from).'\' AND DATE_FORMAT(`check_out`, "%Y-%m-%d") <= \''.PSQL($date_to).'\') AND (
(`date_from` <= \''.pSQL($date_from).'\' AND `check_out` > \''.pSQL($date_from).'\' AND `check_out` <= \''.PSQL($date_to).'\') OR
(`date_from` >= \''.pSQL($date_from).'\' AND `check_out` > \''.pSQL($date_from).'\' AND `check_out` <= \''.pSQL($date_to).'\') OR
@@ -343,13 +347,13 @@ class HotelBookingDetail extends ObjectModel
SELECT hri.`id` AS id_room
FROM `'._DB_PREFIX_.'htl_room_information` AS hri
INNER JOIN `'._DB_PREFIX_.'htl_room_disable_dates` AS hrdd ON (hrdd.`id_room_type` = hri.`id_product` AND hrdd.`id_room` = hri.`id`)
WHERE hri.`id_hotel`='.(int)$hotel_id.' AND hri.`id_product` ='.(int)$room_type['id_product'].' AND hri.`id_status` = 3 AND (hrdd.`date_from` <= \''.pSql($date_to).'\' AND hrdd.`date_to` >= \''.pSql($date_from).'\')';
WHERE hri.`id_hotel`='.(int)$hotel_id.' AND hri.`id_product` ='.(int)$room_type['id_product'].' AND hri.`id_status` = '. self::STATUS_CHECKED_OUT .' AND (hrdd.`date_from` <= \''.pSql($date_to).'\' AND hrdd.`date_to` >= \''.pSql($date_from).'\')';
$selectAvailRoomSearch = 'SELECT ri.`id` AS `id_room`, ri.`id_product`, ri.`id_hotel`, ri.`room_num`, ri.`comment` AS `room_comment`';
$joinAvailRoomSearch = '';
$whereAvailRoomSearch = 'WHERE ri.`id_hotel`='.(int)$hotel_id.' AND ri.`id_product`='.(int)$room_type['id_product'].' AND ri.`id_status` != 2 AND ri.`id` NOT IN ('.$exclude_ids.')';
$whereAvailRoomSearch = 'WHERE ri.`id_hotel`='.(int)$hotel_id.' AND ri.`id_product`='.(int)$room_type['id_product'].' AND ri.`id_status` != '. self::STATUS_CHECKED_IN .' AND ri.`id` NOT IN ('.$exclude_ids.')';
$groupByAvailRoomSearch = '';
$orderByAvailRoomSearch = '';
@@ -385,10 +389,10 @@ class HotelBookingDetail extends ObjectModel
}
if ($search_partial) {
$sql1 = 'SELECT bd.`id_product`, bd.`id_room`, bd.`id_hotel`, bd.`id_customer`, bd.`booking_type`, bd.`id_status` AS booking_status, bd.`comment` AS `room_comment`, rf.`room_num`, bd.`date_from`, IF(bd.`id_status` = 3, bd.`check_out`, bd.`date_to`) AS `date_to`
$sql1 = 'SELECT bd.`id_product`, bd.`id_room`, bd.`id_hotel`, bd.`id_customer`, bd.`booking_type`, bd.`id_status` AS booking_status, bd.`comment` AS `room_comment`, rf.`room_num`, bd.`date_from`, IF(bd.`id_status` = '. self::STATUS_CHECKED_OUT .', bd.`check_out`, bd.`date_to`) AS `date_to`
FROM `'._DB_PREFIX_.'htl_booking_detail` AS bd
INNER JOIN `'._DB_PREFIX_.'htl_room_information` AS rf ON (rf.`id` = bd.`id_room`)
WHERE bd.`id_hotel`='.(int)$hotel_id.' AND bd.`id_product`='.(int)$room_type['id_product'].' AND rf.`id_status` != 2 AND bd.`is_back_order` = 0 AND bd.`is_refunded` = 0 AND IF(bd.`id_status` = 3, (
WHERE bd.`id_hotel`='.(int)$hotel_id.' AND bd.`id_product`='.(int)$room_type['id_product'].' AND rf.`id_status` != '. self::STATUS_CHECKED_IN .' AND bd.`is_back_order` = 0 AND bd.`is_refunded` = 0 AND IF(bd.`id_status` = '. self::STATUS_CHECKED_OUT .', (
(DATE_FORMAT(`check_out`, "%Y-%m-%d") > \''.pSQL($date_from).'\' AND DATE_FORMAT(`check_out`, "%Y-%m-%d") < \''.PSQL($date_to).'\') AND (
(bd.`date_from` <= \''.pSQL($date_from).'\' AND bd.`check_out` > \''.pSQL($date_from).'\' AND bd.`check_out` < \''.pSQL($date_to).'\') OR
(bd.`date_from` > \''.pSQL($date_from).'\' AND bd.`date_from` < \''.pSQL($date_to).'\' AND bd.`check_out` >= \''.pSQL($date_to).'\') OR
@@ -404,7 +408,7 @@ class HotelBookingDetail extends ObjectModel
FROM `'._DB_PREFIX_.'htl_room_information` AS hri
INNER JOIN `'._DB_PREFIX_.'htl_room_disable_dates` AS hrdd ON (hrdd.`id_room_type` = hri.`id_product` AND hrdd.`id_room` = hri.`id`)
WHERE hri.`id_hotel`='.(int)$hotel_id.' AND hri.`id_product`='.(int)$room_type['id_product'].' AND
hri.`id_status` = 3 AND (
hri.`id_status` = '. self::STATUS_CHECKED_OUT .' AND (
(hrdd.`date_from` <= \''.pSQL($date_from).'\' AND hrdd.`date_to` > \''.pSQL($date_from).'\' AND hrdd.`date_to` < \''.pSQL($date_to).'\') OR
(hrdd.`date_from` > \''.pSQL($date_from).'\' AND hrdd.`date_from` < \''.pSQL($date_to).'\' AND hrdd.`date_to` >= \''.pSQL($date_to).'\') OR
(hrdd.`date_from` > \''.pSQL($date_from).'\' AND hrdd.`date_from` < \''.pSQL($date_to).'\' AND hrdd.`date_to` < \''.pSQL($date_to).'\')
@@ -764,12 +768,12 @@ class HotelBookingDetail extends ObjectModel
$table = 'htl_booking_detail';
// create date to update in the table
if ($new_status == 2) {
if ($new_status == self::STATUS_CHECKED_IN) {
$data = array(
'id_status' => $new_status,
'check_in' => ($status_date > $date_to ? $date_to : $status_date)
);
} elseif ($new_status == 3) {
} elseif ($new_status == self::STATUS_CHECKED_OUT) {
$data = array(
'id_status' => $new_status,
'check_out' => ($status_date > $date_to ? $date_to : $status_date)
@@ -947,14 +951,14 @@ class HotelBookingDetail extends ObjectModel
if (isset($current_admin_cart_id) && $current_admin_cart_id) {
$sql = 'SELECT `id` AS `id_room`, `id_product`, `id_hotel`, `room_num`, `comment` AS `room_comment`
FROM `'._DB_PREFIX_.'htl_room_information`
WHERE `id_hotel`='.(int)$hotel_id.' AND `id_product`='.(int)$room_type.' AND id_status = 1
WHERE `id_hotel`='.(int)$hotel_id.' AND `id_product`='.(int)$room_type.' AND id_status = '. self::STATUS_ALLOTED .'
AND `id` NOT IN (SELECT `id_room` FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE `date_from` < \''.
pSQL($date_to).'\' AND `date_to` > \''.pSQL($date_from).'\' AND `is_refunded`=0 AND `is_back_order`=0)
AND `id` NOT IN (SELECT `id_room` FROM `'._DB_PREFIX_.'htl_cart_booking_data` WHERE `id_cart`='.
(int)$current_admin_cart_id.')';
} else {
$sql = 'SELECT `id` AS `id_room`, `id_product`, `id_hotel`, `room_num`, `comment` AS `room_comment`
FROM `'._DB_PREFIX_.'htl_room_information` WHERE `id_hotel`='.(int)$hotel_id.' AND `id_product`='.(int)$room_type.' AND id_status = 1 AND `id` NOT IN (SELECT `id_room` FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE `date_from` < \''.pSQL($date_to).'\' AND `date_to` > \''.pSQL($date_from).'\' AND `is_refunded`=0 AND `is_back_order`=0)';
FROM `'._DB_PREFIX_.'htl_room_information` WHERE `id_hotel`='.(int)$hotel_id.' AND `id_product`='.(int)$room_type.' AND id_status = '. self::STATUS_ALLOTED .' AND `id` NOT IN (SELECT `id_room` FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE `date_from` < \''.pSQL($date_to).'\' AND `date_to` > \''.pSQL($date_from).'\' AND `is_refunded`=0 AND `is_back_order`=0)';
}
$avail_rooms = Db::getInstance()->executeS($sql);
if ($avail_rooms) {
@@ -976,7 +980,7 @@ class HotelBookingDetail extends ObjectModel
public function getAvailableRoomsForSwapping($date_from, $date_to, $room_type, $hotel_id, $id_room)
{
$sql = 'SELECT `id` AS `id_room`, `id_product`, `id_hotel`, `room_num`, `comment` AS `room_comment` FROM `'._DB_PREFIX_.'htl_room_information` WHERE `id_hotel`='.(int)$hotel_id.' AND `id_product`='.(int)$room_type.
' AND `id_status` = 1 AND `id` IN (SELECT `id_room` FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE `date_from` = \''.pSQL($date_from).'\' AND `date_to` = \''.pSQL($date_to).'\' AND `id_room`!='.(int)$id_room.' AND `is_refunded`=0 AND `is_back_order`=0)';
' AND `id_status` = '. self::STATUS_ALLOTED .' AND `id` IN (SELECT `id_room` FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE `date_from` = \''.pSQL($date_from).'\' AND `date_to` = \''.pSQL($date_to).'\' AND `id_room`!='.(int)$id_room.' AND `is_refunded`=0 AND `is_back_order`=0)';
return Db::getInstance()->executeS($sql);
}
@@ -1660,7 +1664,7 @@ class HotelBookingDetail extends ObjectModel
$objHtlBooking->id_hotel = $objCartBooking->id_hotel;
$objHtlBooking->id_customer = $cart->id_customer;
$objHtlBooking->booking_type = $objCartBooking->booking_type;
$objHtlBooking->id_status = 1;
$objHtlBooking->id_status = self::STATUS_ALLOTED;
$objHtlBooking->comment = $objCartBooking->comment;
// For Back Order(Because of cart lock)
@@ -1762,6 +1766,27 @@ class HotelBookingDetail extends ObjectModel
return Db::getInstance()->getRow($sql);
}
public static function getAllHotelOrderStatus()
{
$moduleInstance = Module::getInstanceByName('hotelreservationsystem');
$pages = array(
'STATUS_ALLOTED' => array(
'id_status' => self::STATUS_ALLOTED,
'name' => $moduleInstance->l('Alloted', 'hotelreservationsystem')
),
'STATUS_CHECKED_IN' => array(
'id_status' => self::STATUS_CHECKED_IN,
'name' => $moduleInstance->l('Checked In', 'hotelreservationsystem')
),
'STATUS_CHECKED_OUT' => array(
'id_status' => self::STATUS_CHECKED_OUT,
'name' => $moduleInstance->l('Checked Out', 'hotelreservationsystem')
),
);
return $pages;
}
// Webservice funcions
public function getWsBookingExtraDemands()
{

View File

@@ -293,18 +293,6 @@ class HotelHelper
return true;
}
public function insertHotelOrderStatus()
{
$order_status_arr = array('Alloted','Checked In','Checked Out');
foreach ($order_status_arr as $key => $value) {
$obj_order_status = new HotelOrderStatus();
$obj_order_status->status = $value;
$obj_order_status->save();
}
return true;
}
public function insertHotelRoomAllotmentType()
{
$altment_type_arr = array('Random Allotment','Manual Allotment');

View File

@@ -1,46 +0,0 @@
<?php
/**
* 2010-2020 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <support@webkul.com>
* @copyright 2010-2020 Webkul IN
* @license https://store.webkul.com/license.html
*/
class HotelOrderStatus extends ObjectModel
{
public $id;
public $status;
public static $definition = array(
'table' => 'htl_order_status',
'primary' => 'id',
'fields' => array(
'status' => array('type' => self::TYPE_STRING),
),
);
/**
* [getAllHotelOrderStatus :: To get array all possible order statuses]
* @return [array|boolean] [If data found then Returns array of the order statuses else returns false]
*/
public static function getAllHotelOrderStatus()
{
$result = Db::getInstance()->executeS("SELECT * FROM `"._DB_PREFIX_."htl_order_status`");
if ($result) {
return $result;
}
return false;
}
}

View File

@@ -25,7 +25,6 @@ require_once 'classes/HotelImage.php';
require_once 'classes/HotelFeatures.php';
require_once 'classes/HotelBranchFeatures.php';
require_once 'classes/HotelRoomStatus.php';
require_once 'classes/HotelOrderStatus.php';
require_once 'classes/HotelRoomAllotmentType.php';
require_once 'classes/HotelBookingDetail.php';
require_once 'classes/HotelCartBookingData.php';

View File

@@ -669,7 +669,6 @@ class hotelreservationsystem extends Module
|| !$this->registerModuleHooks()
|| !$objHtlHelper->insertDefaultHotelEntries()
|| !$objHtlHelper->insertHotelRoomsStatus()
|| !$objHtlHelper->insertHotelOrderStatus()
|| !$objHtlHelper->insertHotelRoomAllotmentType()
) {
return false;
@@ -739,8 +738,7 @@ class hotelreservationsystem extends Module
`'._DB_PREFIX_.'htl_room_type_demand_price`,
`'._DB_PREFIX_.'htl_room_type_demand`,
`'._DB_PREFIX_.'htl_room_disable_dates`,
`'._DB_PREFIX_.'htl_access`,
`'._DB_PREFIX_.'htl_order_status`,'
`'._DB_PREFIX_.'htl_access`'
);
}

View File

@@ -361,9 +361,3 @@ CREATE TABLE IF NOT EXISTS `PREFIX_htl_access` (
`access` int(11) NOT NULL,
PRIMARY KEY (`id_profile`, `id_hotel`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `PREFIX_htl_order_status` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`status` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;