403Webshell
Server IP : 103.234.187.230  /  Your IP : 216.73.216.216
Web Server : Apache
System : Linux lserver42043-ind.megavelocity.net 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/b2bzend/application/models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/b2bzend/application/models/AccommodationModel.php
<?php

class Travel_Model_AccommodationModel {

    protected $db = NULL;
    public $intId = NULL;
    public $intAccomSysId = NULL;
    public $intLoggedinUserAgencySysId = '';
    public $baseUrl = '';
    //public $orderByField = 'TB_IC_Accomdation.AccomSysId';

    public $orderBy = 'DESC';

    /*     * ************************************ */

    public function __construct() {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $this->baseUrl = $request->getScheme() . '://' . $request->getHttpHost();
        $this->db = Zend_Db_Table::getDefaultAdapter();
    }

    public function __destruct() {
        $this->db->closeConnection();
    }

    public function init() {
        // parent::init();
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $this->baseUrl = $request->getScheme() . '://' . $request->getHttpHost();
    }

    public function addUpdateHotel($intLoggedinUserAgencySysId) {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        if ($request->isPost()) {
            try {
                //$this->db->beginTransaction();
                $post = $request->getPost();
//                echo"<pre>";print_r($post);
//                echo"<pre>";print_r($_FILES);die('data');
                if (isset($post['update_hotel_id']) && !empty($post['update_hotel_id'])) {
                    $IsHotelOnlyRates = (int) $_SESSION['sessionLogin_user']['agencyDetails']['IsHotelOnlyRates'];
                    $HotelRateType = ($IsHotelOnlyRates == 1) ? 2 : 1;
                    $currentDate = date('Y-m-d H:i:s');
                    $insert = array(
                        'IsAgentSpec' => true,
                        'ICSourceSysId' => $intLoggedinUserAgencySysId,
                        'Title' => isset($post['hotel_name']) && !empty($post['hotel_name']) ? $post['hotel_name'] : '',
                        'Stars' => isset($post['star_rating']) && !empty($post['star_rating']) ? $post['star_rating'] : '0',
                        'PropertyType' => isset($post['ProprtyType']) && !empty($post['ProprtyType']) ? $post['ProprtyType'] : '0',
                        'CitySysId' => isset($post['select_hotel_city']) && !empty($post['select_hotel_city']) ? $post['select_hotel_city'] : '0',
                        'ZoneSysId' => isset($post['AreaSysId']) && !empty($post['AreaSysId']) ? (int) $post['AreaSysId'] : '0',
                        'ShortName' => '',
                        'CheckinTime' => isset($post['CheckinTime']) && !empty($post['CheckinTime']) ? $post['CheckinTime'] : '',
                        'CheckOutTime' => isset($post['CheckOutTime']) && !empty($post['CheckOutTime']) ? $post['CheckOutTime'] : '',
                        'ZoneType' => '0',
                        'PlaceSysId_XRef' => '0', //need to understand
                        'Popularity' => '0', //need to understand
                        'StateSysId' => '0',
                        'SupplierSysId' => isset($post['hidden_selected_supplier_sys_id']) && !empty($post['hidden_selected_supplier_sys_id']) ? (int) $post['hidden_selected_supplier_sys_id'] : '',
                        'CurrencyType' => isset($post['CurrencyType']) && !empty($post['CurrencyType']) ? (int) $post['CurrencyType'] : 0,
                        'ContSysId' => isset($post['select_hotel_country']) && !empty($post['select_hotel_country']) ? $post['select_hotel_country'] : '0',
                        'UpdateDate' => $currentDate,
                        'ApproveDate' => '',
                        'ApproveBy' => '0',
                        'IsLocked' => '1',
                        'RateType' => isset($post['RateType']) ? (int) $post['RateType'] : null,
                        'IsApproved' => '0',
                        'IsActive' => '1',
                        'IsMarkForDel' => '0',
                        'MinStayNights' => (isset($post['MinStayNights']) && !empty($post['MinStayNights'])) ? (int) $post['MinStayNights'] : 0,
                        'SplitStayNights' => (isset($post['SplitStayNights']) && !empty($post['SplitStayNights'])) ? (int) $post['SplitStayNights'] : 0,
                        'HotelRateType' => isset($post['HotelRateType']) ? $post['HotelRateType'] : $HotelRateType,
                        'GoogleSheetId' => isset($post['GoogleSheetId']) ? $post['GoogleSheetId'] : '',
                    );
                    if (isset($post['ChildAge'])) {
                        $insert['ChildAge'] = (int) $post['ChildAge'];
                    }
                    $where = array('AccomSysId =?' => $post['update_hotel_id']);
                    $this->db->update('TB_IC_Accomdation', $insert, $where);
                    $intLastInsertId = $post['update_hotel_id'];
                    if (empty($intLastInsertId)) {
                        //                        $this->db->rollBack();
                    }
                } else {
                    $IsHotelOnlyRates = (int) $_SESSION['sessionLogin_user']['agencyDetails']['IsHotelOnlyRates'];
                    $HotelRateType = ($IsHotelOnlyRates == 1) ? 2 : 1;

                    $currentDate = date('Y-m-d H:i:s');
                    $insert = array(
                        'IsAgentSpec' => true,
                        'ICSourceSysId' => $intLoggedinUserAgencySysId,
                        'Title' => isset($post['hotel_name']) && !empty($post['hotel_name']) ? $post['hotel_name'] : '',
                        'Stars' => isset($post['star_rating']) && !empty($post['star_rating']) ? $post['star_rating'] : '0',
                        'PropertyType' => isset($post['ProprtyType']) && !empty($post['ProprtyType']) ? $post['ProprtyType'] : '0',
                        'CitySysId' => isset($post['select_hotel_city']) && !empty($post['select_hotel_city']) ? $post['select_hotel_city'] : '0',
                        'ZoneSysId' => isset($post['AreaSysId']) && !empty($post['AreaSysId']) ? (int) $post['AreaSysId'] : '0',
                        'ShortName' => '',
                        'CheckinTime' => isset($post['CheckinTime']) && !empty($post['CheckinTime']) ? $post['CheckinTime'] : '',
                        'CheckOutTime' => isset($post['CheckOutTime']) && !empty($post['CheckOutTime']) ? $post['CheckOutTime'] : '',
                        'ZoneType' => '0',
                        'PlaceSysId_XRef' => '0', //need to understand
                        'Popularity' => '0', //need to understand
                        'StateSysId' => '0',
                        'SupplierSysId' => isset($post['hidden_selected_supplier_sys_id']) && !empty($post['hidden_selected_supplier_sys_id']) ? $post['hidden_selected_supplier_sys_id'] : '',
                        'CurrencyType' => isset($post['CurrencyType']) && !empty($post['CurrencyType']) ? (int) $post['CurrencyType'] : 0,
                        'ContSysId' => isset($post['select_hotel_country']) && !empty($post['select_hotel_country']) ? $post['select_hotel_country'] : '0',
                        'UpdateDate' => $currentDate,
                        'ApproveDate' => '',
                        'ApproveBy' => '0',
                        'CreateDate' => $currentDate,
                        'IsLocked' => '1',
                        'RateType' => isset($post['RateType']) ? (int) $post['RateType'] : null,
                        'IsApproved' => '0',
                        'IsActive' => '1',
                        'IsMarkForDel' => '0',
                        'MinStayNights' => (isset($post['MinStayNights']) && !empty($post['MinStayNights'])) ? (int) $post['MinStayNights'] : 0,
                        'SplitStayNights' => (isset($post['SplitStayNights']) && !empty($post['SplitStayNights'])) ? (int) $post['SplitStayNights'] : 0,
                        'HotelRateType' => $HotelRateType,
                        'GoogleSheetId' => isset($post['GoogleSheetId']) ? $post['GoogleSheetId'] : '',
                    );
                    if (isset($post['NetRateType'])) {
                        $insert['NetRateType'] = (int) $post['NetRateType'];
                        $insert['RackCommission'] = ($post['NetRateType'] == 0) ? (float) $post['RackCommission'] : 0;
                    }
                    if (isset($post['weekend']) && !empty($post['weekend'])) {
                        $insert['WeekendDefine'] = implode(',', $post['weekend']);
                    }
                    if (isset($post['contact_email'])) {
                        $insert['EmailID'] = trim($post['contact_email']);
                    }
                    if (isset($post['mobile_number'])) {
                        $insert['PrimaryContact'] = isset($post['mobile_number']) && !empty($post['mobile_number']) ? $post['mobile_number'] : '';
                        $insert['countrycode'] = isset($post['countrycode']) && !empty($post['countrycode']) ? $post['countrycode'] : '';
                    }
                    if (isset($post['ChildAge'])) {
                        $insert['ChildAge'] = (int) $post['ChildAge'];
                    }
                    $this->db->insert('TB_IC_Accomdation', $insert);
                    $intLastInsertId = $this->db->lastInsertId('TB_IC_Accomdation');
                    if (empty($intLastInsertId)) {
                        //                        $this->db->rollBack();
                    }
                }
                $IsRemoveImage = isset($post['IsRemoveImage']) && !empty($post['IsRemoveImage']) ? $post['IsRemoveImage'] : 0;

                if (!empty($_FILES['imagemainbox']) || ($IsRemoveImage == 1)) {
                    if (!empty($_FILES['imagemainbox']['name']) || ($IsRemoveImage == 1)) {
                        $infomain = $_FILES['imagemainbox'];
                        $new_name = date('ymdhis');
                        $ext2 = Zend_Controller_Action_HelperBroker::getStaticHelper('General')->getFileExtension($infomain['name']);
                        $fileName1 = $intLoggedinUserAgencySysId . '_' . md5($new_name) . time() . "." . $ext2;
                        $hotelDetails = $this->hotelDetails($intLastInsertId, $intLoggedinUserAgencySysId);
                        $file_parts = pathinfo($fileName1);
                        $cool_extensions = array('jpg', 'png', 'jpeg', 'gif');
                        if (in_array($file_parts['extension'], $cool_extensions) || ($IsRemoveImage == 1)) {
                            if ($IsRemoveImage == 0) {
                                $image_path = 'img/hotel/hoteId_' . $intLastInsertId;
                                $DetailImg = IMAGE_PATH_URL_AWS . $image_path . '/' . $fileName1;
                                $data = array(
                                    'AgencySysId' => $intLoggedinUserAgencySysId,
                                    'image_path' => $image_path,
                                    'tags' => 'hotel,' . $intLastInsertId,
                                    'title' => $fileName1,
                                    'FILES' => $_FILES['imagemainbox'],
                                    'fileName' => $fileName1,
                                );
                                $toupload = Zend_Controller_Action_HelperBroker::getStaticHelper('FileUpload')->uploadToAWS($data);
                            } else {
                                $toupload['status'] = true;
                                $DetailImg = '';
                            }
                            if ($toupload['status'] == true) {
                                $insert_im = array('DetailImg' => $DetailImg);
                                $where = array('AccomSysId =?' => $intLastInsertId);
                                $this->db->update('TB_IC_Accomdation', $insert_im, $where);
                            }
                        }
                    }
                }

                if (!empty($_FILES['imagebox'])) {
                    for ($y = 0; $y < count($_FILES['imagebox']['name']); $y++) {
                        if ($_FILES['imagebox']['name'][$y] != '') {
                            $new_name = date('ymdhis');
                            $ext = Zend_Controller_Action_HelperBroker::getStaticHelper('General')->getFileExtension($_FILES['imagebox']['name'][$y]);
                            $fileName = $intLoggedinUserAgencySysId . '_' . $y . time() . "." . $ext;
                            $file_parts = pathinfo($fileName);
                            $cool_extensions = array('jpg', 'png', 'jpeg', 'gif');
                            if (in_array($file_parts['extension'], $cool_extensions)) {
                                $image_path = 'img/hotel/hoteId_' . $intLastInsertId;
                                $Details = IMAGE_PATH_URL_AWS . $image_path . '/' . $fileName;
                                $imagebox = array(
                                    'name' => $_FILES['imagebox']['name'][$y],
                                    'type' => $_FILES['imagebox']['type'][$y],
                                    'tmp_name' => $_FILES['imagebox']['tmp_name'][$y],
                                    'error' => $_FILES['imagebox']['error'][$y],
                                    'size' => $_FILES['imagebox']['size'][$y],
                                );
                                $data = array(
                                    'AgencySysId' => $intLoggedinUserAgencySysId,
                                    'image_path' => $image_path,
                                    'tags' => 'hotel,' . $intLastInsertId,
                                    'title' => $fileName,
                                    'FILES' => $imagebox,
                                    'fileName' => $fileName,
                                );
                                $toupload = Zend_Controller_Action_HelperBroker::getStaticHelper('FileUpload')->uploadToAWS($data);

                                if ($toupload['status'] == true) {
                                    $insert_image = array(
                                        'AccomSysId' => $intLastInsertId,
                                        'HotelCode' => $intLastInsertId,
                                        'Details' => $Details,
                                        'Seq' => $y,
                                        'CitySysId' => isset($post['select_hotel_city']) && !empty($post['select_hotel_city']) ? $post['select_hotel_city'] : '0',
                                        'ImgType' => '2',
                                        'UpdateDate' => $currentDate,
                                        'CreateDate' => $currentDate,
                                        'IsActive' => '1',
                                        'IsMarkForDel' => '0'
                                    );
                                    $this->db->insert('TB_IC_Accomdation_Images', $insert_image);
                                }
                            }
                        }
                    }
                }
                //                $this->db->commit();
                return $intLastInsertId;
            } catch (Exception $ex) {
                //                $this->db->rollBack();
                die($ex->getMessage());
            }
        }
    }

    public function addUpdateHotelTnc($intLoggedinUserAgencySysId) {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        if ($request->isPost()) {
            $post = $request->getPost();
            if (isset($post['update_hotel_id']) && !empty($post['update_hotel_id'])) {
                $where = array('AccomSysId =?' => $post['update_hotel_id']);
                $update = array(
                    'Inclusions' => isset($post['inclusions']) && !empty($post['inclusions']) ? html_entity_decode($post['inclusions']) : '',
                    'Exclusions' => isset($post['exclusions']) && !empty($post['exclusions']) ? html_entity_decode($post['exclusions']) : '',
                    'BookingTerms' => isset($post['booking_tc']) && !empty($post['booking_tc']) ? html_entity_decode($post['booking_tc']) : '',
                );
                $this->db->update('TB_IC_Accomdation', $update, $where);
                $intLastInsertId = $post['update_hotel_id'];
                return $intLastInsertId;
            } else {
                return 0;
            }
        }
    }

    public function UpdateHotelContact($intLoggedinUserAgencySysId) {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        if ($request->isPost()) {
            $post = $request->getPost();

            $insert = array(
                'PinCode' => isset($post['pin_code']) && !empty($post['pin_code']) ? $post['pin_code'] : '',
                'OtherContacts' => isset($post['web_address']) && !empty($post['web_address']) ? $post['web_address'] : '',
                'EmailID' => isset($post['email_1']) && !empty($post['email_1']) ? $post['email_1'] : '',
                'Address' => isset($post['postal_address']) && !empty($post['postal_address']) ? $post['postal_address'] : '',
                'PrimaryContact' => isset($post['mobile_number']) && !empty($post['mobile_number']) ? $post['mobile_number'] : '',
                'countrycode' => isset($post['countrycode']) && !empty($post['countrycode']) ? $post['countrycode'] : '',
                'SecondaryContact' => isset($post['phone_number']) && !empty($post['phone_number']) ? $post['phone_number'] : '',
                'FaxNo' => isset($post['fax_number']) && !empty($post['fax_number']) ? $post['fax_number'] : '',
                'GeoLat' => isset($post['latitude']) && !empty($post['latitude']) ? $post['latitude'] : '',
                'GeoLong' => isset($post['longitude']) && !empty($post['longitude']) ? $post['longitude'] : '',
                'Brief' => isset($post['aboutHotelBriefHtml']) && !empty($post['aboutHotelBriefHtml']) ? html_entity_decode($post['aboutHotelBriefHtml']) : '',
                    //                'Brief' => isset($post['brief']) && !empty($post['brief']) ? $post['brief'] : '',
            );

            try {
                $where = array('AccomSysId =?' => $post['update_hotel_id']);
                $this->db->update('TB_IC_Accomdation', $insert, $where);
                $intLastInsertId = $post['update_hotel_id'];
                return $intLastInsertId;
            } catch (Exception $ex) {
                die($ex->getMessage());
            }
        }
    }

    public function UpdateHotelFacility() {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $objHotel = new Travel_Model_TblHotel();
        $post = $request->getPost();
        $facilities_mask = $objHotel->createAccoAmenitiesMask($post['Facility']);
        try {

            $insert = array(
                'AccoAminitiesMask' => $facilities_mask,
                'CheckinTime' => $post['CheckinTime'],
                'CheckOutTime' => $post['CheckOutTime']
            );
            $where = array('AccomSysId =?' => $post['update_hotel_id']);
            $this->db->update('TB_IC_Accomdation', $insert, $where);
            $intLastInsertId = $post['update_hotel_id'];
            return $intLastInsertId;
        } catch (Exception $ex) {
            die($ex->getMessage());
        }
    }

    public function AddAroundProperty($intLoggedinUserAgencySysId) {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        if ($request->isPost()) {
            $post = $request->getPost();
            $currentDate = date('Y-m-d H:i:s');
            $hotelDetails = $this->hotelDetails($post['update_hotel_id'], $intLoggedinUserAgencySysId);
            $insert = array(
                'AccomSysId' => $post['update_hotel_id'],
                'NearByPlaceCat' => isset($post['NearByPlaceCat']) && !empty($post['NearByPlaceCat']) ? $post['NearByPlaceCat'] : '',
                'DistanceInKmTime' => isset($post['DistanceInKmTime']) && !empty($post['DistanceInKmTime']) ? $post['DistanceInKmTime'] : '',
                'Description' => isset($post['Description']) && !empty($post['Description']) ? $post['Description'] : '',
                'CitySysId' => isset($hotelDetails['CitySysId']) && !empty($hotelDetails['CitySysId']) ? $hotelDetails['CitySysId'] : '',
                'Title' => isset($hotelDetails['Title']) && !empty($hotelDetails['Title']) ? $hotelDetails['Title'] : '',
                'Latitude' => isset($hotelDetails['GeoLat']) && !empty($hotelDetails['GeoLat']) ? $hotelDetails['GeoLat'] : '',
                'Longitude' => isset($hotelDetails['GeoLong']) && !empty($hotelDetails['GeoLong']) ? $hotelDetails['GeoLong'] : '',
                'Address' => '',
                'UpdateDate' => $currentDate,
                'CreateDate' => $currentDate,
                'IsMarkForDel' => 0,
                'IsActive' => '1'
            );
            try {
                if (isset($post['update_AroundPId']) && !empty($post['update_AroundPId'])) {
                    $where = array('NearByPlaceSysId =?' => $post['update_AroundPId']);
                    $this->db->update('TB_IC_Accomdation_NearByPlaces', $insert, $where);
                    return true;
                } else {
                    $this->db->insert('TB_IC_Accomdation_NearByPlaces', $insert);
                    return true;
                }
            } catch (Exception $ex) {
                die($ex->getMessage());
            }
        }
    }

    public function AddHotelRoomDetails($intLoggedinUserAgencySysId, $HotelID = null) {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        if ($request->isPost()) {
            $post = $request->getPost();

//echo "<pre>";print_r($post);die;
            $hotelId = isset($HotelID) && !empty($HotelID) ? $HotelID : $post['update_hotel_id'];
            $currentDate = date('Y-m-d H:i:s');
            $roomAmenities = (isset($post['room_amenities']) && count($post['room_amenities'])) ? $post['room_amenities'] : array();
            $roomAmenitiesList = (isset($post['room_amenities_list']) && !empty($post['room_amenities_list'])) ? $post['room_amenities_list'] : array();
            $TblHotel = new Travel_Model_TblHotel();

            if (!empty($roomAmenitiesList)) {
                $AminityId = array();
                foreach ($roomAmenitiesList as $raKey => $raValue) {

                    $TblHotel->strCondition = " AND (AgencySysId = $intLoggedinUserAgencySysId OR AgencySysId is NULL) AND Title = '" . trim($raValue) . "'";
                    $getRoomAmenitiesList = $TblHotel->getRoomAmenitiesList();
                    if (!empty($getRoomAmenitiesList)) {
                        $AminityId[] = (int) $getRoomAmenitiesList[0]['AminityId'];
                    } else {
                        $insertRoomAminity = array(
                            'AgencySysId' => $intLoggedinUserAgencySysId,
                            'Title' => $raValue,
                            'Icon' => 1,
                            'UpdateDate' => $currentDate,
                            'CreateDate' => $currentDate,
                            'IsMarkForDel' => 0,
                            'IsActive' => 1,
                        );
                        $this->db->insert('TB_Master_Accom_RoomAminity', $insertRoomAminity);
                        $AminityId[] = $this->db->lastInsertId('TB_Master_Accom_RoomAminity');
                    }
                }
                if (!empty($AminityId)) {
                    $roomAmenities = array_merge($roomAmenities, $AminityId);
                }
            }
            $amenities = implode(",", $roomAmenities);
            $objHotel = new Travel_Model_TblHotel();
            $hotelDetails = $this->hotelDetails($hotelId, $intLoggedinUserAgencySysId);
            $amenitiesMask = $objHotel->createRoomAmenitiesMask($amenities);

            $insert = array(
                'AccomSysId' => $hotelId,
                'SourceSysId' => $intLoggedinUserAgencySysId,
                'Title' => '',
                'RoomType' => isset($post['RoomType']) && !empty($post['RoomType']) ? $post['RoomType'] : '',
                'EconomyType' => 0,
                'Qty' => isset($post['total_room']) && !empty($post['total_room']) ? $post['total_room'] : '',
                'BedType' => isset($post['BedType']) && !empty($post['BedType']) ? $post['BedType'] : 0,
                'ExtraBedType' => isset($post['ExtraBedType']) && !empty($post['ExtraBedType']) ? $post['ExtraBedType'] : 0,
                'RoomView' => isset($post['RoomView']) && !empty($post['RoomView']) ? $post['RoomView'] : 0,
                'RoomLenght' => isset($post['length']) && !empty($post['length']) ? $post['length'] : 0,
                'RoomBreadth' => isset($post['breadth']) && !empty($post['breadth']) ? $post['breadth'] : 0,
                'RoomSizeMeasurement' => isset($post['RoomSizeMeasurement']) && !empty($post['RoomSizeMeasurement']) ? $post['RoomSizeMeasurement'] : 0,
                'PaxCount' => isset($post['AdultBase']) && !empty($post['AdultBase']) ? $post['AdultBase'] : 2,
                'AllowChild' => isset($post['ChildBase']) && !empty($post['ChildBase']) ? $post['ChildBase'] : 2,
                'IsPetAllow' => 0,
                'MaxPetAllow' => 0,
                'AllowInfant' => 0,
                'MaxPaxCount' => isset($post['AdultMax']) && !empty($post['AdultMax']) ? $post['AdultMax'] : 3,
                'MaxAllowChild' => isset($post['ChildMax']) && !empty($post['ChildMax']) ? $post['ChildMax'] : 2,
                'MaxAllowGuest' => isset($post['GuestMax']) && !empty($post['GuestMax']) ? $post['GuestMax'] : 4,
                'MaxAllowInfant' => 0,
                'MealPlanType' => '',
                'AminitiesMask' => $amenitiesMask,
                'InclustionOptionsMask' => '',
                'OtherDetails' => isset($post['room_des']) && !empty($post['room_des']) ? $post['room_des'] : '',
                'UpdatedDate' => $currentDate,
                'CreateDate' => $currentDate,
                'ApproveDate' => EMPTY_DATE,
                'ApproveBy' => 0,
                'IsDelete' => 0,
                'IsActive' => '1',
                'IsApproved' => '0',
                'CancellationPolicy' => '',
            );
            // echo "<pre>";print_r($insert);die;
            try {
                if (isset($post['update_room_id']) && !empty($post['update_room_id'])) {
                    $where = array('ItemSysId =?' => $post['update_room_id']);
                    $this->db->update('TB_IC_Accomdation_Room', $insert, $where);
                    $LastInsertRoomId = $post['update_room_id'];
                    //return true;
                } else {
                    $this->db->insert('TB_IC_Accomdation_Room', $insert);
                    $LastInsertRoomId = $this->db->lastInsertId('TB_IC_Accomdation_Room');
                    //return true;
                }

                $intLastInsertId = $hotelId;
                if (empty($LastInsertRoomId)) {
                    $this->db->rollBack();
                }
                if (isset($_FILES['imagebox']['name']) && $_FILES['imagebox']['size'][0] > 0) {
                    $adapter = new Zend_File_Transfer_Adapter_Http();
                    $i = 1;
                    foreach ($adapter->getFileInfo() as $key => $info) {
                        $ext = Zend_Controller_Action_HelperBroker::getStaticHelper('General')->getFileExtension($info['name']);
                        $fileName = $intLoggedinUserAgencySysId . '_' . $i . time() . "." . $ext;
                        //                        if (!$adapter->receive($info['name'])) {
                        //                            $this->view->msg = $adapter->getMessages();
                        //                            return;
                        //                        }
                        $image_path = 'img/hotel/hoteId_' . $intLastInsertId . '/room/room_' . $LastInsertRoomId;
                        $Details = IMAGE_PATH_URL_AWS . $image_path . '/' . $fileName;
                        $data = array(
                            'AgencySysId' => $intLoggedinUserAgencySysId,
                            'image_path' => $image_path,
                            'tags' => 'Hotel,' . $intLastInsertId . ',Room,' . $LastInsertRoomId,
                            'title' => $fileName,
                            'FILES' => $info,
                            'fileName' => $fileName,
                        );

                        $toupload = Zend_Controller_Action_HelperBroker::getStaticHelper('FileUpload')->uploadToAWS($data);

                        if ($toupload['status'] == true) {
                            $insert_image = array(
                                'AccomSysId' => $intLastInsertId,
                                'ItemSysId' => $LastInsertRoomId,
                                'CitySysId' => isset($hotelDetails['CitySysId']) && !empty($hotelDetails['CitySysId']) ? $hotelDetails['CitySysId'] : '',
                                'TagTitle' => '',
                                'Details' => $Details,
                                'Seq' => $i,
                                'ImgType' => '2',
                                'UpdateDate' => $currentDate,
                                'CreateDate' => $currentDate,
                                'IsActive' => '1',
                                'IsMarkForDel' => '0'
                            );
                            $this->db->insert('TB_IC_Accomdation_Room_Images', $insert_image);
                        }

                        $i++;
                    }
                }
                return true;
            } catch (Exception $ex) {
                die($ex->getMessage());
            }
        }
    }

    public function AddHotelMultipleRoomDetails($intLoggedinUserAgencySysId, $HotelID = null, $post = array(), $checkRoomTitle = 0) {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        if ($request->isPost() || !empty($post)) {
            if (empty($post)) {
                $post = $request->getPost();
            }
            
            $LastInsertRoomId = array();
            $hotelId = isset($HotelID) && !empty($HotelID) ? $HotelID : $post['HotelId'];
            $currentDate = date('Y-m-d H:i:s');
            $RoomType = isset($post['RoomType']) ? explode(',', $post['RoomType']) : array();
            
            if ($hotelId > 0 && !empty($RoomType)) {
                foreach ($RoomType as $rkey => $rvalue) {

                    $RoomTypeId = (int) $rvalue;
                    if (!empty($rvalue) && empty((int) $rvalue)) {
                        $CheckRoomMaster = 0;
                        if($checkRoomTitle == 1){
                            $CheckRoomMaster = $this->CheckRoomMaster(trim($rvalue));
                        }
                        if(!empty($CheckRoomMaster)){
                            $RoomTypeId = $CheckRoomMaster;
                        }else{
                            $addMasterRoomData = array(
                                'Title' => $rvalue,
                                'CreateDate' => $currentDate,
                                'UpdateDate' => $currentDate,
                                'Icon' => '1',
                                'RoomGrMask' => '',
                                'IsActive' => 1,
                                'IsMarkForDel' => 0,
                                'AgencySysId' => $intLoggedinUserAgencySysId
                            );
                            $this->db->insert('TB_Master_RoomType', $addMasterRoomData);
                            $RoomTypeId = $this->db->lastInsertId('TB_Master_RoomType');
                        } 
                    }
                    
                    $ItemSysId = 0;
                    if($checkRoomTitle == 1){
                        $CheckAccomRoomExist = $this->CheckAccomRoomExist($hotelId, $RoomTypeId, $intLoggedinUserAgencySysId);
                        if(isset($CheckAccomRoomExist['ItemSysId']) && (int)$CheckAccomRoomExist['ItemSysId'] > 0){
                            $ItemSysId = $CheckAccomRoomExist['ItemSysId'];
                        } 
                    }
                    if(!empty($ItemSysId)){
                        $LastInsertRoomId[] = $ItemSysId.'__'.$RoomTypeId;
                    }else{
                        $insert = array(
                            'AccomSysId' => $hotelId,
                            'SourceSysId' => $intLoggedinUserAgencySysId,
                            'Title' => '',
                            'RoomType' => $RoomTypeId,
                            'EconomyType' => 0,
                            'Qty' => isset($post['total_room']) && !empty($post['total_room']) ? $post['total_room'] : 0,
                            'BedType' => 0,
                            'ExtraBedType' => 0,
                            'RoomView' => 0,
                            'RoomLenght' => 0,
                            'RoomBreadth' => 0,
                            'RoomSizeMeasurement' => 0,
                            'PaxCount' => 2,
                            'AllowChild' => 2,
                            'IsPetAllow' => 0,
                            'MaxPetAllow' => 0,
                            'AllowInfant' => 0,
                            'MaxPaxCount' => 3,
                            'MaxAllowChild' => 2,
                            'MaxAllowGuest' => 4,
                            'MaxAllowInfant' => 0,
                            'MealPlanType' => '',
                            'AminitiesMask' => '',
                            'InclustionOptionsMask' => '',
                            'OtherDetails' => '',
                            'UpdatedDate' => $currentDate,
                            'CreateDate' => $currentDate,
                            'ApproveDate' => EMPTY_DATE,
                            'ApproveBy' => 0,
                            'IsDelete' => 0,
                            'IsActive' => '1',
                            'IsApproved' => '0',
                            'CancellationPolicy' => '',
                        );
                        try {
                            $this->db->insert('TB_IC_Accomdation_Room', $insert);
                            $ItemSysId = $this->db->lastInsertId('TB_IC_Accomdation_Room');
                            $LastInsertRoomId[] = $ItemSysId.'__'.$RoomTypeId;
                        } catch (Exception $ex) {
                            die($ex->getMessage());
                        }
                    }
                    
                }
            }
            return $LastInsertRoomId;
        }
    }

    public function AroundPropertyList($hotel_id) {
        $select = $this->db->select();
        $selectarray = array('NearByPlaceSysId', 'AccomSysId', 'NearByPlaceCat', 'DistanceInKmTime', 'Description', 'IsMarkForDel', 'IsActive');
        $select->from(array('tb1' => "TB_IC_Accomdation_NearByPlaces"), $selectarray);
        $select->joinLeft(array('tb2' => "TB_IC_Accomdation"), "tb1.AccomSysId = tb2.AccomSysId", array('RateType'));
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->where("tb1.IsMarkForDel =?", 0);
        $select->order(array('NearByPlaceSysId DESC'));
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function AroundPropertyDetails($hotel_id, $NearByPlaceSysId) {
        $select = $this->db->select();
        $selectarray = array('NearByPlaceSysId', 'AccomSysId', 'NearByPlaceCat', 'DistanceInKmTime', 'Description', 'IsMarkForDel', 'IsActive');
        $select->from(array('tb1' => "TB_IC_Accomdation_NearByPlaces"), $selectarray);
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->where("tb1.NearByPlaceSysId =?", $NearByPlaceSysId);
        $result = $this->db->fetchRow($select);
        return $result;
    }

    public function AddHotelVillaRoomDetails($intLoggedinUserAgencySysId) {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        if ($request->isPost()) {
            $post = $request->getPost();
            $currentDate = date('Y-m-d H:i:s');
            $roomAmenities = isset($post['room_amenities']) && count($post['room_amenities']) > 0 ? $post['room_amenities'] : array();
            $amenities = implode(",", $roomAmenities);
            $objHotel = new Travel_Model_TblHotel();
            $hotelDetails = $this->hotelDetails($post['update_hotel_id'], $intLoggedinUserAgencySysId);
            $amenitiesMask = $objHotel->createRoomAmenitiesMask($amenities);
            $insert = array(
                'AccomSysId' => $post['update_hotel_id'],
                'SourceSysId' => $intLoggedinUserAgencySysId,
                'Title' => '',
                'RoomType' => isset($post['RoomType']) && !empty($post['RoomType']) ? $post['RoomType'] : '',
                'EconomyType' => 0,
                'Qty' => isset($post['total_room']) && !empty($post['total_room']) ? $post['total_room'] : '',
                'BedType' => isset($post['BedType']) && !empty($post['BedType']) ? $post['BedType'] : 0,
                'ExtraBedType' => isset($post['ExtraBedType']) && !empty($post['ExtraBedType']) ? $post['ExtraBedType'] : 0,
                'RoomView' => isset($post['RoomView']) && !empty($post['RoomView']) ? $post['RoomView'] : 0,
                'RoomLenght' => isset($post['length']) && !empty($post['length']) ? $post['length'] : 0,
                'RoomBreadth' => isset($post['breadth']) && !empty($post['breadth']) ? $post['breadth'] : 0,
                'RoomSizeMeasurement' => isset($post['RoomSizeMeasurement']) && !empty($post['RoomSizeMeasurement']) ? $post['RoomSizeMeasurement'] : 0,
                'PaxCount' => isset($post['AdultBase']) && !empty($post['AdultBase']) ? $post['AdultBase'] : 0,
                'AllowChild' => isset($post['ChildBase']) && !empty($post['ChildBase']) ? $post['ChildBase'] : 0,
                'IsPetAllow' => 0,
                'MaxPetAllow' => 0,
                'AllowInfant' => 0,
                'MaxPaxCount' => isset($post['AdultMax']) && !empty($post['AdultMax']) ? $post['AdultMax'] : 0,
                'MaxAllowChild' => isset($post['ChildMax']) && !empty($post['ChildMax']) ? $post['ChildMax'] : 0,
                'MaxAllowGuest' => isset($post['GuestMax']) && !empty($post['GuestMax']) ? $post['GuestMax'] : 0,
                'MaxAllowInfant' => 0,
                'MealPlanType' => '',
                'AminitiesMask' => $amenitiesMask,
                'InclustionOptionsMask' => '',
                'OtherDetails' => isset($post['room_des']) && !empty($post['room_des']) ? $post['room_des'] : '',
                'UpdatedDate' => $currentDate,
                'CreateDate' => $currentDate,
                'ApproveDate' => EMPTY_DATE,
                'ApproveBy' => 0,
                'IsDelete' => 0,
                'IsActive' => '1',
                'IsApproved' => '0',
                'CancellationPolicy' => '',
            );
            // echo "<pre>";print_r($insert);die;
            try {
                if (isset($post['update_room_id']) && !empty($post['update_room_id'])) {
                    $where = array('ItemSysId =?' => $post['update_room_id']);
                    $this->db->update('TB_IC_Accomdation_Villa_Room', $insert, $where);
                    $LastInsertRoomId = $post['update_room_id'];
                    //return true;
                } else {
                    $this->db->insert('TB_IC_Accomdation_Villa_Room', $insert);
                    $LastInsertRoomId = $this->db->lastInsertId('TB_IC_Accomdation_Villa_Room');
                    //return true;
                }

                $intLastInsertId = $post['update_hotel_id'];
                if (empty($LastInsertRoomId)) {
                    $this->db->rollBack();
                }
                if (isset($_FILES['imagebox']['name']) && $_FILES['imagebox']['size'][0] > 0) {
                    $adapter = new Zend_File_Transfer_Adapter_Http();
                    $i = 1;
                    foreach ($adapter->getFileInfo() as $key => $info) {
                        $ext = Zend_Controller_Action_HelperBroker::getStaticHelper('General')->getFileExtension($info['name']);
                        $fileName = $intLoggedinUserAgencySysId . '_' . $i . time() . "." . $ext;
                        $image_path = 'img/hotel/hoteId_' . $intLastInsertId . '/villaroom/room_' . $LastInsertRoomId;
                        $Details = IMAGE_PATH_URL_AWS . $image_path . '/' . $fileName;
                        $data = array(
                            'AgencySysId' => $intLoggedinUserAgencySysId,
                            'image_path' => $image_path,
                            'tags' => 'Hotel,' . $intLastInsertId . ',Villa Room,' . $LastInsertRoomId,
                            'title' => $fileName,
                            'FILES' => $info,
                            'fileName' => $fileName,
                        );

                        $toupload = Zend_Controller_Action_HelperBroker::getStaticHelper('FileUpload')->uploadToAWS($data);

                        if ($toupload['status'] == true) {
                            $insert_image = array(
                                'AccomSysId' => $intLastInsertId,
                                'ItemSysId' => $LastInsertRoomId,
                                'CitySysId' => isset($hotelDetails['CitySysId']) && !empty($hotelDetails['CitySysId']) ? $hotelDetails['CitySysId'] : '',
                                'TagTitle' => '',
                                'Details' => $Details,
                                'Seq' => $i,
                                'ImgType' => '2',
                                'UpdateDate' => $currentDate,
                                'CreateDate' => $currentDate,
                                'IsActive' => '1',
                                'IsMarkForDel' => '0'
                            );
                            $this->db->insert('TB_IC_Accomdation_Villa_Room_Images', $insert_image);
                        }

                        $i++;
                    }
                }
                return true;
            } catch (Exception $ex) {
                die($ex->getMessage());
            }
        }
    }

    public function HotelRoomDetailsList($hotel_id, $intLoggedinUserAgencySysId) {
        $select = $this->db->select();
        $selectarray = array('AccomSysId', 'ItemSysId', 'SourceSysId', 'RoomType', 'Qty', 'AminitiesMask', 'OtherDetails', 'InclustionOptionsMask', 'IsActive', 'IsDelete');
        $room_masterarray = array('RoomType as RoomTypeId', 'Title as RoomType');
        $select->from(array('tb1' => "TB_IC_Accomdation_Room"), $selectarray);
        $select->joinLeft(array('tb2' => "TB_Master_RoomType"), "tb1.RoomType = tb2.RoomType", $room_masterarray);
        $select->joinLeft(array('tb3' => "TB_IC_Accomdation"), "tb1.AccomSysId = tb3.AccomSysId", array('RateType', 'PropertyType'));
        $select->where("tb1.SourceSysId =?", $intLoggedinUserAgencySysId);
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->order(array('ItemSysId ASC'));
        $result = $this->db->fetchAll($select);
        $arrResult = array();
        if ($result) {
            foreach ($result as $k => $value) {
                $arrResult[$k]['room'] = $value;
                $arrResult[$k]['img'] = $this->HotelRoomImageList($value['AccomSysId'], $value['ItemSysId']);
            }
        }
        return $arrResult;
    }

    public function HotelVillaRoomDetailsList($hotel_id, $intLoggedinUserAgencySysId) {
        $select = $this->db->select();
        $selectarray = array('AccomSysId', 'ItemSysId', 'SourceSysId', 'RoomType', 'Qty', 'AminitiesMask', 'OtherDetails', 'InclustionOptionsMask', 'IsActive', 'IsDelete');
        $room_masterarray = array('RoomType as RoomTypeId', 'Title as RoomType');
        $select->from(array('tb1' => "TB_IC_Accomdation_Villa_Room"), $selectarray);
        $select->joinLeft(array('tb2' => "TB_Master_RoomType"), "tb1.RoomType = tb2.RoomType", $room_masterarray);
        $select->joinLeft(array('tb3' => "TB_IC_Accomdation"), "tb1.AccomSysId = tb3.AccomSysId", array('RateType'));
        $select->where("tb1.SourceSysId =?", $intLoggedinUserAgencySysId);
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->order(array('ItemSysId ASC'));
        $result = $this->db->fetchAll($select);
        $arrResult = array();
        if ($result) {
            foreach ($result as $k => $value) {
                $arrResult[$k]['room'] = $value;
                $arrResult[$k]['img'] = $this->HotelVillaRoomImageList($value['AccomSysId'], $value['ItemSysId']);
            }
        }
        return $arrResult;
    }

    public function searchroomList($hotel_id, $RoomTypeArr) {
        $select = $this->db->select();
        $selectarray = array('AccomSysId', 'ItemSysId', 'SourceSysId', 'RoomType');
        $room_masterarray = array('RoomType as RoomTypeId', 'Title as RoomType');
        $select->from(array('tb1' => "TB_IC_Accomdation_Room"), $selectarray);
        $select->joinLeft(array('tb2' => "TB_Master_RoomType"), "tb1.RoomType = tb2.RoomType", $room_masterarray);
        $select->where('tb1.RoomType IN(?)', $RoomTypeArr);
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->where("tb1.IsDelete =?", 0);
        $select->order(array('ItemSysId ASC'));
        $result = $this->db->fetchAll($select);

        return $result;
    }

    public function CheckRoomMaster($RoomType) {
        $select = $this->db->select();
        $selectarray = array('RoomType');
        $select->from(array('tb1' => "TB_Master_RoomType"), $selectarray);
        if (is_numeric($RoomType)) {
            $select->where("tb1.RoomType =?", $RoomType);
        } else {
            $select->where("tb1.Title =?", $RoomType);
        }
        $select->where("tb1.IsMarkForDel =?", 0);
        $result = $this->db->fetchRow($select);

        return $result['RoomType'];
    }

    public function AddSearchRoom($data) {
        try {
            $insert = $this->db->insert('TB_IC_Accomdation_Room', $data);
            return $this->db->lastInsertId('TB_IC_Accomdation_Room');
        } catch (Exception $e) {
            die('There has been an error. ' . $e->getMessage());
        }
        return 0;
    }

    public function InsertNewRoom($data) {
        try {
            $insert = $this->db->insert('TB_Master_RoomType', $data);
            return $this->db->lastInsertId('TB_Master_RoomType');
        } catch (Exception $e) {
            die('There has been an error. ' . $e->getMessage());
        }
        return 0;
    }

    public function UpdateInventoryExist($InvnItemSysId, $data) {
        try {
            return $this->db->update('TB_MP_Inventory_Accom', $data, array('InvnItemSysId = ?' => $InvnItemSysId));
        } catch (Exception $e) {
            die('There has been an error. ' . $e->getMessage());
        }
        return 0;
    }

    public function CheckInventoryExist($hotel_id, $EconomyType, $intLoggedinUserAgencySysId) {
        $select = $this->db->select();
        $selectarray = array('InvnItemSysId', 'AgencySysId');
        $selectAccomInventory = array('RoomSysId as EconomyType', 'AccomSysId', 'XRefItemSysId');
        $select->from(array('tb1' => "Tb_MP_Accomdation_Room_Inventory"), $selectAccomInventory);
        $select->joinLeft(array('tb11' => "TB_MP_Inventory_Accom"), "tb1.id = tb11.RoomInventorySysId", $selectarray);
        //$select->from(array('tb1' => "TB_MP_Inventory_Accom"), $selectarray);
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->where("tb1.RoomSysId =?", $EconomyType);
        $select->where("tb1.AgencySysId =?", $intLoggedinUserAgencySysId);
        $select->where("tb1.IsMarkForDelete =?", 0);
        $select->where("tb11.IsMarkForDelete =?", 0);
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function CheckInventoryRateExist($intLoggedinUserAgencySysId, $hotel_id, $XRateSessionKey, $XRefItemSysId) {
        $select = $this->db->select();
        $selectarray = array('InvnItemSysId', 'AgencySysId');
        $selectAccomInventory = array('RoomSysId as EconomyType', 'AccomSysId', 'XRefItemSysId');
        $select->from(array('tb1' => "Tb_MP_Accomdation_Room_Inventory"), $selectAccomInventory);
        $select->joinLeft(array('tb11' => "TB_MP_Inventory_Accom"), "tb1.id = tb11.RoomInventorySysId", $selectarray);
        $select->where("tb1.AgencySysId =?", $intLoggedinUserAgencySysId);
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->where("tb1.XRateSessionKey =?", $XRateSessionKey);
        $select->where("tb1.XRefItemSysId =?", $XRefItemSysId);
        $select->where("tb1.IsMarkForDelete =?", 0);
        $select->where("tb11.IsMarkForDelete =?", 0);
        $result = $this->db->fetchRow($select);
        return $result;
    }

    public function CheckAccomRoomExist($hotel_id, $RoomType, $intLoggedinUserAgencySysId) {
        $select = $this->db->select();
        $selectarray = array('ItemSysId');
        $select->from(array('tb1' => "TB_IC_Accomdation_Room"), $selectarray);
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->where("tb1.RoomType =?", $RoomType);
        $select->where("tb1.SourceSysId =?", $intLoggedinUserAgencySysId);
        $select->where("tb1.IsDelete =?", 0);
        $result = $this->db->fetchRow($select);
        return $result;
    }

    public function HotelRoomDetails($hotel_id, $intLoggedinUserAgencySysId, $roomId) {
        $select = $this->db->select();
        $selectarray = array('AccomSysId', 'ItemSysId', 'SourceSysId', 'RoomType', 'Qty', 'AminitiesMask', 'OtherDetails', 'InclustionOptionsMask', 'IsActive', 'IsDelete', 'BedType', 'ExtraBedType', 'RoomView', 'RoomLenght', 'RoomBreadth', 'RoomSizeMeasurement', 'PaxCount', 'MaxPaxCount', 'AllowChild', 'MaxAllowChild', 'MaxAllowGuest', 'CancellationPolicy');
        $room_masterarray = array('RoomType as RoomTypeId', 'Title as RoomType');
        $select->from(array('tb1' => "TB_IC_Accomdation_Room"), $selectarray);
        $select->joinLeft(array('tb2' => "TB_Master_RoomType"), "tb1.RoomType = tb2.RoomType", $room_masterarray);
        $select->where("tb1.SourceSysId =?", $intLoggedinUserAgencySysId);
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->where("tb1.ItemSysId =?", $roomId);
        $result = $this->db->fetchRow($select);
        return $result;
    }

    public function HotelVillaRoomDetails($hotel_id, $intLoggedinUserAgencySysId, $roomId) {
        $select = $this->db->select();
        $selectarray = array('AccomSysId', 'ItemSysId', 'SourceSysId', 'RoomType', 'Qty', 'AminitiesMask', 'OtherDetails', 'InclustionOptionsMask', 'IsActive', 'IsDelete', 'BedType', 'ExtraBedType', 'RoomView', 'RoomLenght', 'RoomBreadth', 'RoomSizeMeasurement', 'PaxCount', 'MaxPaxCount', 'AllowChild', 'MaxAllowChild', 'MaxAllowGuest', 'CancellationPolicy');
        $room_masterarray = array('RoomType as RoomTypeId', 'Title as RoomType');
        $select->from(array('tb1' => "TB_IC_Accomdation_Villa_Room"), $selectarray);
        $select->joinLeft(array('tb2' => "TB_Master_RoomType"), "tb1.RoomType = tb2.RoomType", $room_masterarray);
        $select->where("tb1.SourceSysId =?", $intLoggedinUserAgencySysId);
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->where("tb1.ItemSysId =?", $roomId);
        $result = $this->db->fetchRow($select);
        return $result;
    }

    public function getRoomQtyOnly($hotel_id, $intLoggedinUserAgencySysId, $roomId = 0) {
        $select = $this->db->select();
        $selectarray = array('ItemSysId', 'RoomType', 'Qty');
        $room_masterarray = array('RoomType as RoomTypeId', 'Title as RoomType');
        $select->from(array('tb1' => "TB_IC_Accomdation_Room"), $selectarray);
        $select->joinLeft(array('tb2' => "TB_Master_RoomType"), "tb1.RoomType = tb2.RoomType", $room_masterarray);
        $select->where("tb1.SourceSysId =?", $intLoggedinUserAgencySysId);
        $select->where("tb1.AccomSysId =?", $hotel_id);
        if ($roomId > 0) {
            $select->where("tb1.ItemSysId =?", $roomId);
        }
        $result = $this->db->fetchRow($select);
        return $result;
    }

    public function HotelList($intLoggedinUserAgencySysId) {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $post = $request->getPost();
        $Params = $request->getParams();
        $select = $this->db->select();
        $selecthotelarray = array('HotelRateType', 'AccomSysId', 'IsAgentSpec', 'ICSourceSysId', 'Title', 'Stars', 'PropertyType', 'CitySysId', 'ContSysId', 'UpdateDate', 'CreateDate', 'IsLocked', 'IsApproved', 'IsActive', 'IsMarkForDel', 'IsWebsite', 'EmailID', 'countrycode', 'PrimaryContact', 'SupplierSysId', 'CurrencyType', 'CheckinTime', 'CheckOutTime');
        $cityarray = array('CityId', 'Title as City_title', 'Code');
        //$roomarray = array('ItemSysId','AccomSysId','Qty');
        $countryarray = array('ContId', 'Title as Count_title');
        $select->from(array('tb1' => "TB_IC_Accomdation"), $selecthotelarray);
        $select->joinLeft(array('tb2' => "TB_Master_Geo_City"), "tb1.CitySysId = tb2.CityId", $cityarray);
        $select->joinLeft(array('tb3' => "TB_Master_Geo_Country"), "tb1.ContSysId = tb3.ContId", $countryarray);
        $select->joinLeft(array('tb4' => "TB_Agency_Area_Master"), "tb1.ZoneSysId = tb4.AreaSysId", array('Area as AreaName'));
        $select->joinLeft(array('tb5' => "TB_IC_Supplier"), "tb1.SupplierSysId = tb5.SupplierSysId", array('SupplierName'));
        $select->joinLeft(array('tb6' => "TB_Master_Currency"), "tb1.CurrencyType = tb6.CurrencyType", array('Symbol'));
        //$select->joinLeft(array('tb4' => "TB_IC_Accomdation_Room"), "tb1.AccomSysId = tb4.AccomSysId" , $roomarray);
        $select->where("tb1.ICSourceSysId =?", $intLoggedinUserAgencySysId);
        $select->where("tb1.IsMarkForDel =?", 0);
        //$select->where('tb1.ICSourceSysId IN(?)', array('3','4',$intLoggedinUserAgencySysId));
        if (isset($Params['DestinationId']) && $Params['DestinationId'] > 0) {
            $select->where("tb1.CitySysId =?", $Params['DestinationId']);
        }
        if (isset($Params['ProprtyType']) && $Params['ProprtyType'] > 0) {
            $select->where("tb1.PropertyType =?", $Params['ProprtyType']);
        }
        if (isset($post['hotelId']) && $post['hotelId'] > 0) {
            $select->where("tb1.AccomSysId =?", $post['hotelId']);
        }
        if (isset($Params['rating']) && $Params['rating'] > 0) {
            $select->where("tb1.Stars =?", $Params['rating']);
        }

        //$select->limit(10000,0);
        $select->order(array('tb1.AccomSysId DESC'));
        //$profiler   = $this->db->getProfiler($select);
        //$result = $this->db->fetchAll($select); 
        //echo $totalTime    = $profiler->getTotalElapsedSecs();
        //echo $queryCount   = $profiler->getTotalNumQueries();die;
        //echo "<pre>"; print_r($select); die;
        // echo $select; exit;
        return $select;
    }

    public function hotelDetails($hotel_id, $intLoggedinUserAgencySysId) {
        $select = $this->db->select();
        $selecthotelarray = array("HotelRateType", 'AccomSysId', 'IsAgentSpec', 'ICSourceSysId', 'Title', 'DetailImg', 'Stars', 'PropertyType', 'CheckinTime', 'CheckOutTime', 'CitySysId', 'ContSysId', 'PinCode', 'OtherContacts', 'EmailID', 'Address', 'PrimaryContact', 'SecondaryContact', 'FaxNo', 'GeoLat', 'GeoLong', 'UpdateDate', 'CreateDate', 'IsLocked', 'IsApproved', 'IsActive', 'IsMarkForDel', 'Brief', 'WeekendDefine', 'countrycode', 'ZoneSysId', 'MinStayNights', 'SplitStayNights', 'RateType', 'BookingTerms', 'CurrencyType', 'SupplierSysId', 'Inclusions', 'Exclusions', 'ChildAge', 'GoogleSheetId');
        $cityarray = array('CityId', 'Title as City_title', 'Code');
        $countryarray = array('ContId', 'Title as Count_title');
        $select->from(array('tb1' => "TB_IC_Accomdation"), $selecthotelarray);
        $select->joinLeft(array('tb2' => "TB_Master_Geo_City"), "tb1.CitySysId = tb2.CityId", $cityarray);
        $select->joinLeft(array('tb3' => "TB_Master_Geo_Country"), "tb1.ContSysId = tb3.ContId", $countryarray);
        $select->joinLeft(array('tb4' => "TB_Agency_Area_Master"), "tb1.ZoneSysId = tb4.AreaSysId", array('Area as AreaName'));
        $select->joinLeft(array('tb5' => "TB_IC_Supplier"), "tb1.SupplierSysId = tb5.SupplierSysId", array('SupplierName as suppliername'));
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->where("tb1.ICSourceSysId =?", $intLoggedinUserAgencySysId);
        $result = $this->db->fetchRow($select);
        return $result;
    }

    public function hotelDetailsRates($hotel_id, $intLoggedinUserAgencySysId) {
        $select = $this->db->select();
        $selecthotelarray = array('HotelRateType', 'AccomSysId', 'IsAgentSpec', 'ICSourceSysId', 'Title', 'DetailImg', 'Stars', 'PropertyType', 'CheckinTime', 'CheckOutTime', 'CitySysId', 'ContSysId', 'PinCode', 'OtherContacts', 'EmailID', 'Address', 'PrimaryContact', 'SecondaryContact', 'FaxNo', 'GeoLat', 'GeoLong', 'UpdateDate', 'CreateDate', 'IsLocked', 'IsApproved', 'IsActive', 'IsMarkForDel', 'Brief', 'WeekendDefine', 'RateType', 'CurrencyType', 'SupplierSysId', 'ChildAge', 'IsWebsite');
        $cityarray = array('CityId', 'Title as City_title', 'Code');
        $countryarray = array('ContId', 'Title as Count_title');
        $select->from(array('tb1' => "TB_IC_Accomdation"), $selecthotelarray);
        $select->joinLeft(array('tb2' => "TB_Master_Geo_City"), "tb1.CitySysId = tb2.CityId", $cityarray);
        $select->joinLeft(array('tb3' => "TB_Master_Geo_Country"), "tb1.ContSysId = tb3.ContId", $countryarray);
        $select->joinLeft(array('tb4' => "TB_Master_Currency"), "tb1.CurrencyType = tb4.CurrencyType", array('Symbol'));
        $select->joinLeft(array('tb5' => "TB_IC_Supplier"), "tb1.SupplierSysId = tb5.SupplierSysId", array('SupplierName'));
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->where('tb1.ICSourceSysId IN(?)', array('3', '4', $intLoggedinUserAgencySysId));
        //$select->where("tb1.ICSourceSysId =?", $intLoggedinUserAgencySysId);
        $result = $this->db->fetchRow($select);
        return $result;
    }

    public function HotelImageList($hotel_id) {
        $select = $this->db->select();
        $selectarray = array('AccomSysId', 'ImgIndex', 'Seq', 'TagTitle', 'ImgType', 'Details', 'IsMarkForDel');
        $select->from(array('tb1' => "TB_IC_Accomdation_Images"), $selectarray);
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->where("tb1.IsMarkForDel =?", 0);
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function UpdateHotelImageList() {
        $select = $this->db->select();
        $selectarray = array('AccomSysId', 'ImgIndex', 'Seq', 'TagTitle', 'ImgType', 'Details', 'IsMarkForDel');
        $selecthotelarray = array('AccomSysId', 'IsAgentSpec');

        $select->from(array('tb1' => "TB_IC_Accomdation"), $selecthotelarray);
        $select->join(array('tb2' => "TB_IC_Accomdation_Images"), "tb1.AccomSysId = tb2.AccomSysId", $selectarray);
        $select->where("tb2.IsMarkForDel =?", 0);
        $select->where("tb2.ImgType =?", 2);
        $select->where("tb1.IsAgentSpec =?", 1);
        $select->where("tb1.ICSourceSysId =?", 18);
        $select->where("tb1.IsMarkForDel =?", 0);
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function HotelRoomImageList($hotel_id, $room_id) {
        $select = $this->db->select();
        $selectarray = array('AccomSysId', 'ImgIndex', 'ItemSysId', 'Seq', 'TagTitle', 'ImgType', 'Details', 'IsMarkForDel');
        $select->from(array('tb1' => "TB_IC_Accomdation_Room_Images"), $selectarray);
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->where("tb1.ItemSysId =?", $room_id);
        $select->where("tb1.IsMarkForDel =?", 0);
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function HotelVillaRoomImageList($hotel_id, $room_id) {
        $select = $this->db->select();
        $selectarray = array('AccomSysId', 'ImgIndex', 'ItemSysId', 'Seq', 'TagTitle', 'ImgType', 'Details', 'IsMarkForDel');
        $select->from(array('tb1' => "TB_IC_Accomdation_Villa_Room_Images"), $selectarray);
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->where("tb1.ItemSysId =?", $room_id);
        $select->where("tb1.IsMarkForDel =?", 0);
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function DeleteHotelImg($hotel_id, $DeleteId) {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $post = $request->getPost();
        try {
            $this->db->beginTransaction();
            $insert = array(
                'IsMarkForDel' => '1'
            );
            $where = array('AccomSysId =?' => $hotel_id, 'ImgIndex =?' => $DeleteId);
            $this->db->update('TB_IC_Accomdation_Images', $insert, $where);
            $this->db->commit();
            return true;
        } catch (Exception $ex) {
            die($ex->getMessage());
        }
    }

    public function DeleteRoomImg($DeleteId) {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $post = $request->getPost();
        try {
            $this->db->beginTransaction();
            $insert = array(
                'IsMarkForDel' => '1'
            );
            $where = array('ImgIndex =?' => $DeleteId);
            $this->db->update('TB_IC_Accomdation_Room_Images', $insert, $where);
            $this->db->commit();
            return true;
        } catch (Exception $ex) {
            die($ex->getMessage());
        }
    }

    public function DeleteVillaRoomImg($DeleteId) {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $post = $request->getPost();
        try {
            $this->db->beginTransaction();
            $insert = array(
                'IsMarkForDel' => '1'
            );
            $where = array('ImgIndex =?' => $DeleteId);
            $this->db->update('TB_IC_Accomdation_Villa_Room_Images', $insert, $where);
            $this->db->commit();
            return true;
        } catch (Exception $ex) {
            die($ex->getMessage());
        }
    }

    public function DeleteAroundPro($DeleteId) {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $post = $request->getPost();
        try {
            $this->db->beginTransaction();
            $insert = array(
                'IsMarkForDel' => '1'
            );
            $where = array('NearByPlaceSysId =?' => $DeleteId);
            $this->db->update('TB_IC_Accomdation_NearByPlaces', $insert, $where);
            $this->db->commit();
            return true;
        } catch (Exception $ex) {
            die($ex->getMessage());
        }
    }

    public function DeleteCancellation() {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $post = $request->getPost();
        try {
            $this->db->beginTransaction();
            $insert = array(
                'IsMarkForDel' => '1'
            );
            $where = array('RoomCancelSysId =?' => $post['DeleteId']);
            $this->db->update('TB_IC_Accomdation_Room_CancellationPolicy', $insert, $where);
            $this->db->commit();
            return true;
        } catch (Exception $ex) {
            die($ex->getMessage());
        }
    }

    public function ActiveHotelContentRate() {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $post = $request->getPost();
        try {
            $this->db->beginTransaction();
            if ($post['type'] == 'content') {
                $insert = array(
                    'IsActive' => $post['val']
                );
            } else {
                $insert = array(
                    'IsPublished' => $post['val']
                );
            }

            $where = array('AccomSysId =?' => $post['hotel_id']);
            $this->db->update('TB_IC_Accomdation', $insert, $where);
            $this->db->commit();
            return true;
        } catch (Exception $ex) {
            die($ex->getMessage());
        }
    }

    public function IsActiveHotelInventoryHotel() {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $post = $request->getPost();
        try {
            $this->db->beginTransaction();
            $c = 1;
            if ((int) $post['c'] == 1) {
                $c = 0;
            }
            $insert = array(
                'IsActive' => $c
            );
            if (isset($post['d']) && !empty($post['d'])) {
                $getRoomInventoryIds = $this->getRoomInventoryIds($post['a'], $post['d']);
                $getRoomInventoryIdsArr = array_column($getRoomInventoryIds, 'id');
                if (!empty($getRoomInventoryIdsArr)) {
                    $XRefAccoSysId = $post['a'];
                    $SupplierSysId = $post['b'];
                    $InvIds = implode(',', $getRoomInventoryIdsArr);
                    $where = "RoomInventorySysId IN (" . $InvIds . ") AND XRefAccoSysId = $XRefAccoSysId AND SupplierSysId = $SupplierSysId ";
                }
            } else {
                $where = array('XRefAccoSysId =?' => $post['a'], 'SupplierSysId =?' => $post['b']);
            }

            $this->db->update('TB_MP_Inventory_Accom', $insert, $where);
            $insertRoom = array(
                'IsSaleStart' => $c,
                'IsActive' => $c
            );
            if (isset($post['d']) && !empty($post['d'])) {
                $whereRoom = array('AccomSysId =?' => $post['a'], 'SupplierSysId =?' => $post['b'], 'XRateSessionKey =?' => $post['d']);
            } else {
                $whereRoom = array('AccomSysId =?' => $post['a'], 'SupplierSysId =?' => $post['b']);
            }

            $this->db->update('Tb_MP_Accomdation_Room_Inventory', $insertRoom, $whereRoom);
            $this->db->commit();
            return true;
        } catch (Exception $ex) {
            die($ex->getMessage());
        }
    }

    public function IsDeleteHotelInventoryHotel() {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $post = $request->getPost();
        try {
            $this->db->beginTransaction();

            if (isset($post['c']) && !empty($post['c'])) {
                $getRoomInventoryIds = $this->getRoomInventoryIds($post['a'], $post['c']);
                $getRoomInventoryIdsArr = array_column($getRoomInventoryIds, 'id');

                if (!empty($getRoomInventoryIdsArr)) {
                    $XRefAccoSysId = $post['a'];
                    $SupplierSysId = $post['b'];
                    $InvIds = implode(',', $getRoomInventoryIdsArr);
//                    $where = "RoomInventorySysId IN (" . $InvIds . ") AND XRefAccoSysId = $XRefAccoSysId AND SupplierSysId = $SupplierSysId ";
                    $where = "RoomInventorySysId IN (" . $InvIds . ") AND XRefAccoSysId = $XRefAccoSysId ";
                    $insert = array(
                        'IsMarkForDelete' => 1
                    );
                    $this->db->update('TB_MP_Inventory_Accom', $insert, $where);
                    $insertRoom = array(
                        'IsMarkForDelete' => 1
                    );
//                    $whereRoom = array('AccomSysId =?' => $post['a'], 'SupplierSysId =?' => $post['b'], 'XRateSessionKey =?' => $post['c']);
                    $whereRoom = array('AccomSysId =?' => $post['a'], 'XRateSessionKey =?' => $post['c']);
                    $this->db->update('Tb_MP_Accomdation_Room_Inventory', $insertRoom, $whereRoom);
                    $this->db->commit();
                    return true;
                }
            }
            return false;
        } catch (Exception $ex) {
            die($ex->getMessage());
        }
    }

    public function IsWebsiteActiveHotel() {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $post = $request->getPost();
        try {
            $this->db->beginTransaction();
            $insert = array(
                'IsWebsite' => $post['val']
            );
            $where = array('AccomSysId =?' => $post['hotel_id']);
            $this->db->update('TB_IC_Accomdation', $insert, $where);
            $this->db->commit();
            return true;
        } catch (Exception $ex) {
            die($ex->getMessage());
        }
    }

    public function IsWebsiteActiveVisa($postData = array()) {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $post = !empty($postData) ? $postData : $request->getPost();
        try {
            $this->db->beginTransaction();
            $insert = array(
                'IsWebsite' => $post['val']
            );
            $where = array('InvnVisaAllSysId =?' => $post['visa_id']);
            $this->db->update('TB_MP_Inventory_Visa', $insert, $where);
            $this->db->commit();
            return true;
        } catch (Exception $ex) {
            die($ex->getMessage());
        }
    }

    public function BalockInventoryRate() {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $post = $request->getPost();
        try {
            $this->db->beginTransaction();
            $insert = array(
                'IsSaleStart' => $post['val']
            );
            $where = array('id =?' => $post['id']);
            $this->db->update('Tb_MP_Accomdation_Room_Inventory', $insert, $where);
            $this->db->commit();
            return true;
        } catch (Exception $ex) {
            die($ex->getMessage());
        }
    }

    public function ActiveInventoryRate() {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $post = $request->getPost();
        try {
            $this->db->beginTransaction();
            $insert = array(
                'IsActive' => $post['val']
            );
            $where = array('InvnItemSysId =?' => $post['InvnItemSysId']);
            $this->db->update('TB_MP_Inventory_Accom', $insert, $where);
            $this->db->commit();
            return true;
        } catch (Exception $ex) {
            die($ex->getMessage());
        }
    }

    public function SaleStartInventoryRate($intLoggedinUserAgencySysId) {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $post = $request->getPost();
        $strFromDate = Zend_Controller_Action_HelperBroker::getStaticHelper('DateFormat')->cal2Db($post['fromdate'], 'd-m-y');
        $strToDate = Zend_Controller_Action_HelperBroker::getStaticHelper('DateFormat')->cal2Db($post['ToDateLast'], 'd-m-y');
        $fromdate = date('Y-m-d', strtotime($strFromDate));
        $todate = date('Y-m-d', strtotime($strToDate));
        //print_r($post);die('ss');
        try {
            $this->db->beginTransaction();
            $insert = array(
                'IsSaleStart' => $post['val']
            );
            if (isset($post['XRefItemSysId']) && isset($post['EconomyType']) && isset($post['MealPlanType'])) {
                $where = array('AgencySysId =?' => $intLoggedinUserAgencySysId, 'AccomSysId =?' => $post['XRefAccoSysId'], 'XRefItemSysId =?' => $post['XRefItemSysId'], 'EconomyType =?' => $post['EconomyType'], 'MealPlanType =?' => $post['MealPlanType'], 'SupplierSysId=?' => $post['SupplierSysId'], 'FromDate >= ?' => $fromdate, 'FromDate <= ?' => $todate);
            } else {
                $where = array('AgencySysId =?' => $intLoggedinUserAgencySysId, 'AccomSysId =?' => $post['XRefAccoSysId'], 'SupplierSysId=?' => $post['SupplierSysId'], 'FromDate >= ?' => $fromdate, 'FromDate <= ?' => $todate);
            }
            $this->db->update('Tb_MP_Accomdation_Room_Inventory', $insert, $where);
            $this->db->commit();
            return true;
        } catch (Exception $ex) {
            die($ex->getMessage());
        }
    }

    public function AddHotelRateCard($intLoggedinUserAgencySysId, $intLoggedinUserId, $postData = array()) {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        if ($request->isPost()) {
            if (!empty($postData)) {
                $post = $postData;
            } else {
                $post = $request->getPost();
            }

            $currentDate = date("Y-m-d H:i:s");
            $check_room_type = isset($post['check_room_type']) && !empty($post['check_room_type']) ? $post['check_room_type'] : '';
            $check_meal_type = isset($post['check_meal_type']) && !empty($post['check_meal_type']) ? $post['check_meal_type'] : '';
            $B2CMarkup = isset($post['B2CMarkup']) && !empty($post['B2CMarkup']) ? $post['B2CMarkup'] : 0;
            $B2BMarkup = isset($post['B2BMarkup']) && !empty($post['B2BMarkup']) ? $post['B2BMarkup'] : 0;
            $room_id = isset($post['room_id']) && !empty($post['room_id']) ? $post['room_id'] : '';
            $RoomType = isset($post['RoomType']) && !empty($post['RoomType']) ? $post['RoomType'] : '';
            $room_type_id = isset($post['room_type_id']) && !empty($post['room_type_id']) ? $post['room_type_id'] : '';
            $allocation = isset($post['allocation']) && !empty($post['allocation']) ? $post['allocation'] : '';
            $BookingType = isset($post['BookingType']) && !empty($post['BookingType']) ? $post['BookingType'] : '';
            $check_tax_type = isset($post['check_tax_type']) && !empty($post['check_tax_type']) ? $post['check_tax_type'] : '';
            $age_paid = isset($post['age_paid']) && !empty($post['age_paid']) ? $post['age_paid'] : '';
            $sg_pub_wd = isset($post['sg_pub_wd']) && !empty($post['sg_pub_wd']) ? ($post['sg_pub_wd']) : '';
            $sg_pub_wk = isset($post['sg_pub_wk']) && !empty($post['sg_pub_wk']) ? ($post['sg_pub_wk']) : '';
            $sg_net_wd = isset($post['sg_net_wd']) && !empty($post['sg_net_wd']) ? ($post['sg_net_wd']) : '';
            $sg_net_wk = isset($post['sg_net_wk']) && !empty($post['sg_net_wk']) ? ($post['sg_net_wk']) : '';
            $db_pub_wd = isset($post['db_pub_wd']) && !empty($post['db_pub_wd']) ? ($post['db_pub_wd']) : '';
            $db_pub_wk = isset($post['db_pub_wk']) && !empty($post['db_pub_wk']) ? ($post['db_pub_wk']) : '';
            $db_net_wd = isset($post['db_net_wd']) && !empty($post['db_net_wd']) ? ($post['db_net_wd']) : '';
            $db_net_wk = isset($post['db_net_wk']) && !empty($post['db_net_wk']) ? ($post['db_net_wk']) : '';
            $tri_pub_wd = isset($post['tri_pub_wd']) && !empty($post['tri_pub_wd']) ? ($post['tri_pub_wd']) : '';
            $tri_pub_wk = isset($post['tri_pub_wk']) && !empty($post['tri_pub_wk']) ? ($post['tri_pub_wk']) : '';
            $tri_net_wd = isset($post['tri_net_wd']) && !empty($post['tri_net_wd']) ? ($post['tri_net_wd']) : '';
            $tri_net_wk = isset($post['tri_net_wk']) && !empty($post['tri_net_wk']) ? ($post['tri_net_wk']) : '';
            $ex_wbed_pub_wd = isset($post['ex_wbed_pub_wd']) && !empty($post['ex_wbed_pub_wd']) ? ($post['ex_wbed_pub_wd']) : '';
            $ex_wbed_pub_wk = isset($post['ex_wbed_pub_wk']) && !empty($post['ex_wbed_pub_wk']) ? ($post['ex_wbed_pub_wk']) : '';
            $ex_wbed_net_wd = isset($post['ex_wbed_net_wd']) && !empty($post['ex_wbed_net_wd']) ? ($post['ex_wbed_net_wd']) : '';
            $ex_wbed_net_wk = isset($post['ex_wbed_net_wk']) && !empty($post['ex_wbed_net_wk']) ? ($post['ex_wbed_net_wk']) : '';
            $chpaid_pub_wd = isset($post['chpaid_pub_wd']) && !empty($post['chpaid_pub_wd']) ? ($post['chpaid_pub_wd']) : '';
            $chpaid_pub_wk = isset($post['chpaid_pub_wk']) && !empty($post['chpaid_pub_wk']) ? ($post['chpaid_pub_wk']) : '';
            $chpaid_net_wd = isset($post['chpaid_net_wd']) && !empty($post['chpaid_net_wd']) ? ($post['chpaid_net_wd']) : '';
            $chpaid_net_wk = isset($post['chpaid_net_wk']) && !empty($post['chpaid_net_wk']) ? ($post['chpaid_net_wk']) : '';
            $sg_tax_wd = isset($post['sg_tax_wd']) && !empty($post['sg_tax_wd']) ? ($post['sg_tax_wd']) : '';
            $sg_tax_wk = isset($post['sg_tax_wk']) && !empty($post['sg_tax_wk']) ? ($post['sg_tax_wk']) : '';
            $db_tax_wd = isset($post['db_tax_wd']) && !empty($post['db_tax_wd']) ? ($post['db_tax_wd']) : '';
            $db_tax_wk = isset($post['db_tax_wk']) && !empty($post['db_tax_wk']) ? ($post['db_tax_wk']) : '';
            $ex_wbed_tax_wd = isset($post['ex_wbed_tax_wd']) && !empty($post['ex_wbed_tax_wd']) ? ($post['ex_wbed_tax_wd']) : '';
            $ex_wbed_tax_wk = isset($post['ex_wbed_tax_wk']) && !empty($post['ex_wbed_tax_wk']) ? ($post['ex_wbed_tax_wk']) : '';
            $tri_tax_wd = isset($post['tri_tax_wd']) && !empty($post['tri_tax_wd']) ? ($post['tri_tax_wd']) : '';
            $tri_tax_wk = isset($post['tri_tax_wk']) && !empty($post['tri_tax_wk']) ? ($post['tri_tax_wk']) : '';
            $chpaid_tax_wd = isset($post['chpaid_tax_wd']) && !empty($post['chpaid_tax_wd']) ? ($post['chpaid_tax_wd']) : '';
            $chpaid_tax_wk = isset($post['chpaid_tax_wk']) && !empty($post['chpaid_tax_wk']) ? ($post['chpaid_tax_wk']) : '';
            $check_tax_sg = isset($post['check_tax_sg']) && !empty($post['check_tax_sg']) ? ($post['check_tax_sg']) : '';
            $check_tax_db = isset($post['check_tax_db']) && !empty($post['check_tax_db']) ? ($post['check_tax_db']) : '';
            $check_tax_tri = isset($post['check_tax_tri']) && !empty($post['check_tax_tri']) ? ($post['check_tax_tri']) : '';
            $check_tax_ex = isset($post['check_tax_ex']) && !empty($post['check_tax_ex']) ? ($post['check_tax_ex']) : '';
            $check_tax_chpaid = isset($post['check_tax_chpaid']) && !empty($post['check_tax_chpaid']) ? ($post['check_tax_chpaid']) : '';
            $check_markup_sg = isset($post['check_markup_sg']) && !empty($post['check_markup_sg']) ? ($post['check_markup_sg']) : '';
            $check_markup_db = isset($post['check_markup_db']) && !empty($post['check_markup_db']) ? ($post['check_markup_db']) : '';
            $check_markup_tri = isset($post['check_markup_tri']) && !empty($post['check_markup_tri']) ? ($post['check_markup_tri']) : '';
            $check_markup_ex = isset($post['check_markup_ex']) && !empty($post['check_markup_ex']) ? ($post['check_markup_ex']) : '';
            $check_markup_chpaid = isset($post['check_markup_chpaid']) && !empty($post['check_markup_chpaid']) ? ($post['check_markup_chpaid']) : '';
            $ext_adult = isset($post['ext_adult']) && !empty($post['ext_adult']) ? $post['ext_adult'] : '0';
            $ext_child = isset($post['ext_child']) && !empty($post['ext_child']) ? $post['ext_child'] : '0';
            $weekend = isset($post['weekend']) && !empty($post['weekend']) ? $post['weekend'] : '';
            $weekend = implode(',', $weekend);
            $SessionKeyOld = isset($post['SessionKey']) && !empty($post['SessionKey']) ? $post['SessionKey'] : '';
            $hotel_id = $post['update_hotel_id'];
            $UpdateHotelData = array('UpdateDate' => $currentDate);
            if ($weekend) {
                $UpdateHotelData['WeekendDefine'] = $weekend;
            }
            $whereH = array('AccomSysId =?' => $hotel_id);
            $this->db->update('TB_IC_Accomdation', $UpdateHotelData, $whereH);

            $from_dt = isset($post['from_dt']) && !empty($post['from_dt']) ? $post['from_dt'] : '0';
            $to_dt = isset($post['to_dt']) && !empty($post['to_dt']) ? $post['to_dt'] : '0';
            $strFromDate = Zend_Controller_Action_HelperBroker::getStaticHelper('DateFormat')->cal2Db($from_dt, 'd/m/y');
            $strToDate = Zend_Controller_Action_HelperBroker::getStaticHelper('DateFormat')->cal2Db($to_dt, 'd/m/y');
            if ($SessionKeyOld != '') {
                $sessionKey = $SessionKeyOld;
            } else {
                $sessionKey = $this->getMaxXRateSessionKey();
            }

            $weekends = isset($post['weekend']) && !empty($post['weekend']) ? $post['weekend'] : '';
            $strToDates = date("Y-m-d", strtotime("+1 day", strtotime($strToDate)));
            $begin = new DateTime($strFromDate);
            $end = new DateTime($strToDates);
            $interval = DateInterval::createFromDateString('1 day');
            $getHotelRateTypeArray = $this->getHotelRateType($hotel_id, $intLoggedinUserAgencySysId);
            $isInventory = true;
            if (isset($getHotelRateTypeArray['HotelRateType']) && $getHotelRateTypeArray['HotelRateType'] == 2) {
                $isInventory = false;
            }
            $CurrencyType = isset($getHotelRateTypeArray['CurrencyType']) ? $getHotelRateTypeArray['CurrencyType'] : 0;
            $SupplierSysId = isset($getHotelRateTypeArray['SupplierSysId']) ? $getHotelRateTypeArray['SupplierSysId'] : 0;
            if ($CurrencyType > 0) {
                $post['currency_type'] = $CurrencyType;
            }
            if ($SupplierSysId > 0) {
                $post['hidden_selected_supplier_sys_id'] = $SupplierSysId;
            }
            $period = new DatePeriod($begin, $interval, $end);
            if ($room_id) {
                $RoomKey = 0;
                $LetKey = 0;
                $queryVals = array();
                foreach ($room_id as $k => $val) {
                    if (isset($check_meal_type[$k])) {
                        if ($isInventory == true) {
                            foreach ($period as $dt) {
                                $where = array('AccomSysId =?' => $post['update_hotel_id'], 'FromDate =? ' => $dt->format("Y-m-d"), 'XRefItemSysId =? ' => $room_id[$k][0], 'RoomSysId =? ' => $room_type_id[$k][0], 'SupplierSysId =?' => $post['hidden_selected_supplier_sys_id'], 'AgencySysId =?' => $intLoggedinUserAgencySysId);
                                $insert_im = array('IsMarkForDelete' => 1, 'IsActive' => 0);
                                $this->db->update('Tb_MP_Accomdation_Room_Inventory', $insert_im, $where);
                                $insert = [
                                    'FromDate' => $dt->format("Y-m-d"),
                                    'Todate' => $strToDate,
                                    'XRateSessionKey' => $sessionKey,
                                    'PublishQty' => $allocation[$k][0],
                                    'NetInHandQty' => $allocation[$k][0],
                                    'BlockQty' => 0,
                                    'SoldQty' => 0,
                                    'UpdatedDate' => $currentDate,
                                    'CreatedDate' => $currentDate,
                                    'AccomSysId' => (int) $post['update_hotel_id'],
                                    'RoomSysId' => (int) $room_type_id[$k][0],
                                    'SupplierSysId' => (int) $post['hidden_selected_supplier_sys_id'],
                                    'AgencySysId' => $intLoggedinUserAgencySysId,
                                    'XRefItemSysId' => (int) $room_id[$k][0],
                                    'IsMarkForDelete' => 0,
                                    'IsActive' => 1,
                                    'IsSaleStart' => 1,
                                    'BookingType' => (isset($BookingType[$k])) ? (int) $BookingType[$k] : 0,
                                ];
                                $this->db->insert('Tb_MP_Accomdation_Room_Inventory', $insert);
                                $id = $this->db->lastInsertId();
                                $queryVals = array();
                                foreach ($check_meal_type[$k] as $key => $value) {
                                    if (in_array($dt->format("D"), $weekends)) {
                                        $queryVals[] = "(" . (int) $intLoggedinUserAgencySysId . ","
                                                . '\'' . $weekend . '\'' . ","
                                                . (int) $value . ","
                                                . '1' . ","
                                                . (float) $B2CMarkup . ","
                                                . (float) $B2BMarkup . ","
                                                . (isset($sg_pub_wk[$value][$k]) && $sg_pub_wk[$value][$k] == '' ? 'NULL' : (float) $sg_pub_wk[$value][$k]) . ","
                                                . (isset($sg_net_wk[$value][$k]) && $sg_net_wk[$value][$k] == '' ? 'NULL' : (float) $sg_net_wk[$value][$k]) . ","
                                                . (isset($check_tax_sg[$k][0]) ? $check_tax_sg[$k][0] : '0') . ","
                                                . (isset($sg_tax_wk[$value][$k]) && $sg_tax_wd[$value][$k] != '' ? (float) $sg_tax_wd[$value][$k] : '0') . ","
                                                . (isset($db_pub_wk[$value][$k]) && $db_pub_wk[$value][$k] == '' ? 'NULL' : (float) $db_pub_wk[$value][$k]) . ","
                                                . (isset($db_net_wk[$value][$k]) && $db_net_wk[$value][$k] == '' ? 'NULL' : (float) $db_net_wk[$value][$k]) . ","
                                                . (isset($check_tax_db[$k][0]) ? $check_tax_db[$k][0] : '0') . ","
                                                . (isset($db_tax_wk[$value][$k]) && $db_tax_wd[$value][$k] != '' ? (float) $db_tax_wd[$value][$k] : '0') . ","
                                                . (isset($ex_wbed_pub_wk[$value][$k]) && $ex_wbed_pub_wk[$value][$k] == '' ? 'NULL' : (float) $ex_wbed_pub_wk[$value][$k]) . ","
                                                . (isset($ex_wbed_net_wk[$value][$k]) && $ex_wbed_net_wk[$value][$k] == '' ? 'NULL' : (float) $ex_wbed_net_wk[$value][$k]) . ","
                                                . (isset($check_tax_ex[$k][0]) ? (float) $check_tax_ex[$k][0] : '0') . ","
                                                . (isset($ex_wbed_tax_wk[$value][$k]) && $ex_wbed_tax_wd[$value][$k] != '' ? (float) $ex_wbed_tax_wd[$value][$k] : '0') . ","
                                                . (isset($tri_pub_wk[$value][$k]) && $tri_pub_wk[$value][$k] == '' ? 'NULL' : (float) $tri_pub_wk[$value][$k]) . ","
                                                . (isset($tri_net_wk[$value][$k]) && $tri_net_wk[$value][$k] == '' ? 'NULL' : (float) $tri_net_wk[$value][$k]) . ","
                                                . (isset($check_tax_tri[$k][0]) ? (float) $check_tax_tri[$k][0] : '0') . ","
                                                . (isset($tri_tax_wk[$value][$k]) && $tri_tax_wd[$value][$k] != '' ? (float) $tri_tax_wd[$value][$k] : '0') . ","
                                                . (isset($age_paid[$k][0]) && !empty($age_paid[$k][0]) ? (float) $age_paid[$k][0] : '0') . ","
                                                . (isset($chpaid_pub_wk[$value][$k]) && $chpaid_pub_wk[$value][$k] == '' ? 'NULL' : (float) $chpaid_pub_wk[$value][$k]) . ","
                                                . (isset($chpaid_net_wk[$value][$k]) && $chpaid_net_wk[$value][$k] == '' ? 'NULL' : (float) $chpaid_net_wk[$value][$k]) . ","
                                                . (isset($check_tax_chpaid[$k][0]) ? (float) $check_tax_chpaid[$k][0] : '0') . ","
                                                . (isset($chpaid_tax_wk[$value][$k]) && $chpaid_tax_wd[$value][$k] != '' ? (float) $chpaid_tax_wd[$value][$k] : '0') . ","
                                                . (isset($post['ratetype']) && ($post['ratetype'] == 'NR') ? '1' : '0') . ","
                                                . (isset($post['rr_type']) && !empty($post['rr_type']) ? (int) $post['rr_type'] : '0') . ","
                                                . (isset($post['rr_value']) && !empty($post['rr_value']) ? (int) $post['rr_value'] : '0') . ","
                                                . '\'' . $currentDate . '\'' . ","
                                                . '\'' . $currentDate . '\'' . ","
                                                . (int) $post['update_hotel_id'] . ","
                                                . (int) $id . ","
                                                . (int) $room_id[$k][0] . ","
                                                . (isset($post['currency_type']) && !empty($post['currency_type']) ? $post['currency_type'] : '0') . ","
                                                . (isset($post['hidden_selected_supplier_sys_id']) && !empty($post['hidden_selected_supplier_sys_id']) ? $post['hidden_selected_supplier_sys_id'] : '0') . ","
                                                . (isset($check_markup_sg[$k][0]) ? (float) $check_markup_sg[$k][0] : '0') . ","
                                                . (isset($check_markup_db[$k][0]) ? (float) $check_markup_db[$k][0] : '0') . ","
                                                . (isset($check_markup_tri[$k][0]) ? (float) $check_markup_tri[$k][0] : '0') . ","
                                                . (isset($check_markup_ex[$k][0]) ? (float) $check_markup_ex[$k][0] : '0') . ","
                                                . (isset($check_markup_chpaid[$k][0]) ? (float) $check_markup_chpaid[$k][0] : '0') . ","
                                                . '1' . ","
                                                . '0' . ")";
                                    } else {
                                        $queryVals[] = "(" . (int) $intLoggedinUserAgencySysId . ","
                                                . '\'' . $weekend . '\'' . ","
                                                . (int) $value . ","
                                                . '1' . ","
                                                . (float) $B2CMarkup . ","
                                                . (float) $B2BMarkup . ","
                                                . (isset($sg_pub_wd[$value][$k]) && $sg_pub_wd[$value][$k] == '' ? 'NULL' : (float) $sg_pub_wd[$value][$k]) . ","
                                                . (isset($sg_net_wd[$value][$k]) && $sg_net_wd[$value][$k] == '' ? 'NULL' : (float) $sg_net_wd[$value][$k]) . ","
                                                . (isset($check_tax_sg[$k][0]) ? $check_tax_sg[$k][0] : '0') . ","
                                                . (isset($sg_tax_wd[$value][$k]) && $sg_tax_wd[$value][$k] != '' ? (float) $sg_tax_wd[$value][$k] : '0') . ","
                                                . (isset($db_pub_wd[$value][$k]) && $db_pub_wd[$value][$k] == '' ? 'NULL' : (float) $db_pub_wd[$value][$k]) . ","
                                                . (isset($db_net_wd[$value][$k]) && $db_net_wd[$value][$k] == '' ? 'NULL' : (float) $db_net_wd[$value][$k]) . ","
                                                . (isset($check_tax_db[$k][0]) ? $check_tax_db[$k][0] : '0') . ","
                                                . (isset($db_tax_wd[$value][$k]) && $db_tax_wd[$value][$k] != '' ? (float) $db_tax_wd[$value][$k] : '0') . ","
                                                . (isset($ex_wbed_pub_wd[$value][$k]) && $ex_wbed_pub_wd[$value][$k] == '' ? 'NULL' : (float) $ex_wbed_pub_wd[$value][$k]) . ","
                                                . (isset($ex_wbed_net_wd[$value][$k]) && $ex_wbed_net_wd[$value][$k] == '' ? 'NULL' : (float) $ex_wbed_net_wd[$value][$k]) . ","
                                                . (isset($check_tax_ex[$k][0]) ? (float) $check_tax_ex[$k][0] : '0') . ","
                                                . (isset($ex_wbed_tax_wd[$value][$k]) && $ex_wbed_tax_wd[$value][$k] != '' ? (float) $ex_wbed_tax_wd[$value][$k] : '0') . ","
                                                . (isset($tri_pub_wd[$value][$k]) && $tri_pub_wd[$value][$k] == '' ? 'NULL' : (float) $tri_pub_wd[$value][$k]) . ","
                                                . (isset($tri_net_wd[$value][$k]) && $tri_net_wd[$value][$k] == '' ? 'NULL' : (float) $tri_net_wd[$value][$k]) . ","
                                                . (isset($check_tax_tri[$k][0]) ? (float) $check_tax_tri[$k][0] : '0') . ","
                                                . (isset($tri_tax_wd[$value][$k]) && $tri_tax_wd[$value][$k] != '' ? (float) $tri_tax_wd[$value][$k] : '0') . ","
                                                . (isset($age_paid[$k][0]) && !empty($age_paid[$k][0]) ? (float) $age_paid[$k][0] : '0') . ","
                                                . (isset($chpaid_pub_wd[$value][$k]) && $chpaid_pub_wd[$value][$k] == '' ? 'NULL' : (float) $chpaid_pub_wd[$value][$k]) . ","
                                                . (isset($chpaid_net_wd[$value][$k]) && $chpaid_net_wd[$value][$k] == '' ? 'NULL' : (float) $chpaid_net_wd[$value][$k]) . ","
                                                . (isset($check_tax_chpaid[$k][0]) ? (float) $check_tax_chpaid[$k][0] : '0') . ","
                                                . (isset($chpaid_tax_wd[$value][$k]) && $chpaid_tax_wd[$value][$k] != '' ? (float) $chpaid_tax_wd[$value][$k] : '0') . ","
                                                . (isset($post['ratetype']) && ($post['ratetype'] == 'NR') ? '1' : '0') . ","
                                                . (isset($post['rr_type']) && !empty($post['rr_type']) ? (int) $post['rr_type'] : '0') . ","
                                                . (isset($post['rr_value']) && !empty($post['rr_value']) ? (int) $post['rr_value'] : '0') . ","
                                                . '\'' . $currentDate . '\'' . ","
                                                . '\'' . $currentDate . '\'' . ","
                                                . (int) $post['update_hotel_id'] . ","
                                                . (int) $id . ","
                                                . (int) $room_id[$k][0] . ","
                                                . (isset($post['currency_type']) && !empty($post['currency_type']) ? $post['currency_type'] : '0') . ","
                                                . (isset($post['hidden_selected_supplier_sys_id']) && !empty($post['hidden_selected_supplier_sys_id']) ? $post['hidden_selected_supplier_sys_id'] : '0') . ","
                                                . (isset($check_markup_sg[$k][0]) ? (float) $check_markup_sg[$k][0] : '0') . ","
                                                . (isset($check_markup_db[$k][0]) ? (float) $check_markup_db[$k][0] : '0') . ","
                                                . (isset($check_markup_tri[$k][0]) ? (float) $check_markup_tri[$k][0] : '0') . ","
                                                . (isset($check_markup_ex[$k][0]) ? (float) $check_markup_ex[$k][0] : '0') . ","
                                                . (isset($check_markup_chpaid[$k][0]) ? (float) $check_markup_chpaid[$k][0] : '0') . ","
                                                . '1' . ","
                                                . '0' . ")";
                                    }
                                }
                                $abdcs = "INSERT INTO TB_MP_Inventory_Accom (\"AgencySysId\",\"WeekendDefine\",\"MealPlanType\",\"MarkType\",\"B2CMarkup\",
                                \"B2BMarkup\",\"SOccupCost\",\"NetSOccupCost\",\"IsTaxOnSOccupCost\",\"TaxSOccupCost\",\"DOccupCost\",\"NetDOccupCost\",\"IsTaxOnDOccupCost\",\"TaxDOccupCost\",
                                \"ExtraBedCost\",\"NetExtraBedCost\",\"IsTaxOnExtraBedCost\",\"TaxExtraBedCost\",\"TriOccupCost\",\"NetTriOccupCost\",\"IsTaxOnTriOccupCost\",\"TaxTriOccupCost\",
                                \"ChildAgeLimit\",\"ExtraWOBedCost\",\"NetExtraWOBedCost\",\"IsTaxOnExtraWOBedCost\",\"TaxExtraWOBedCost\",\"RateType\",\"RackCommissionType\",\"RackCommission\",
                                \"UpdatedDate\",\"CreatedDate\",\"XRefAccoSysId\",\"RoomInventorySysId\",\"XRefItemSysId\",\"TrxCurrency\",\"SupplierSysId\",\"IsAllowMarkupSO\",\"IsAllowMarkupDO\",\"IsAllowMarkupTO\",\"IsAllowMarkupEB\",\"IsAllowMarkupWOB\",\"IsActive\",\"IsMarkForDelete\")
                                VALUES " . implode(",", $queryVals);
                                $ret = $this->db->query($abdcs);
                                $LetKey++;
                            }
                        } else {
                            if ($RoomKey == 0) {
                                $where = array('AccomSysId =?' => $post['update_hotel_id'], 'XRateSessionKey = ?' => $SessionKeyOld, 'AgencySysId =?' => $intLoggedinUserAgencySysId);
                                //echo "<pre>";print_r($where);exit;
                                $insert_im = array('IsMarkForDelete' => 1, 'IsActive' => 0);
                                $this->db->update('Tb_MP_Accomdation_Room_Inventory', $insert_im, $where);
                            }

                            $insert = [
                                'FromDate' => $strFromDate,
                                'Todate' => $strToDate,
                                'XRateSessionKey' => $sessionKey,
                                'PublishQty' => $allocation[$k][0],
                                'NetInHandQty' => $allocation[$k][0],
                                'BlockQty' => 0,
                                'SoldQty' => 0,
                                'UpdatedDate' => $currentDate,
                                'CreatedDate' => $currentDate,
                                'AccomSysId' => (int) $post['update_hotel_id'],
                                'RoomSysId' => (int) $room_type_id[$k][0],
                                'SupplierSysId' => (int) $post['hidden_selected_supplier_sys_id'],
                                'AgencySysId' => $intLoggedinUserAgencySysId,
                                'XRefItemSysId' => (int) $room_id[$k][0],
                                'IsMarkForDelete' => 0,
                                'IsActive' => 1,
                                'IsSaleStart' => 1,
                                'BookingType' => (isset($BookingType[$k])) ? (int) $BookingType[$k] : 0,
                            ];
                            $this->db->insert('Tb_MP_Accomdation_Room_Inventory', $insert);
                            $id = $this->db->lastInsertId();
                            $queryVals = array();
                            foreach ($check_meal_type[$k] as $key => $value) {
                                $addHotelData = array(
                                    "AgencySysId" => (int) $intLoggedinUserAgencySysId,
                                    "WeekendDefine" => $weekend,
                                    "MealPlanType" => (int) $value,
                                    "MarkType" => 1,
                                    "B2CMarkup" => (float) $B2CMarkup,
                                    "B2BMarkup" => (float) $B2BMarkup,
                                    "SOccupCost" => (isset($sg_pub_wd[$value][$k]) && $sg_pub_wd[$value][$k] == '' ? 0 : (float) $sg_pub_wd[$value][$k]),
                                    "NetSOccupCost" => (isset($sg_net_wd[$value][$k]) && $sg_net_wd[$value][$k] == '' ? 0 : (float) $sg_net_wd[$value][$k]),
                                    "IsTaxOnSOccupCost" => (isset($check_tax_sg[$k][0]) ? $check_tax_sg[$k][0] : '0'),
                                    "TaxSOccupCost" => (isset($sg_tax_wd[$value][$k]) && $sg_tax_wd[$value][$k] != '' ? (float) $sg_tax_wd[$value][$k] : '0'),
                                    "DOccupCost" => (isset($db_pub_wd[$value][$k]) && $db_pub_wd[$value][$k] == '' ? 0 : (float) $db_pub_wd[$value][$k]),
                                    "NetDOccupCost" => (isset($db_net_wd[$value][$k]) && $db_net_wd[$value][$k] == '' ? 0 : (float) $db_net_wd[$value][$k]),
                                    "IsTaxOnDOccupCost" => (isset($check_tax_db[$k][0]) ? $check_tax_db[$k][0] : '0'),
                                    "TaxDOccupCost" => (isset($db_tax_wd[$value][$k]) && $db_tax_wd[$value][$k] != '' ? (float) $db_tax_wd[$value][$k] : '0'),
                                    "ExtraBedCost" => (isset($ex_wbed_pub_wd[$value][$k]) && $ex_wbed_pub_wd[$value][$k] == '' ? 0 : (float) $ex_wbed_pub_wd[$value][$k]),
                                    "NetExtraBedCost" => (isset($ex_wbed_net_wd[$value][$k]) && $ex_wbed_net_wd[$value][$k] == '' ? 0 : (float) $ex_wbed_net_wd[$value][$k]),
                                    "IsTaxOnExtraBedCost" => (isset($check_tax_ex[$k][0]) ? (float) $check_tax_ex[$k][0] : '0'),
                                    "TaxExtraBedCost" => (isset($ex_wbed_tax_wd[$value][$k]) && $ex_wbed_tax_wd[$value][$k] != '' ? (float) $ex_wbed_tax_wd[$value][$k] : '0'),
                                    "TriOccupCost" => (isset($tri_pub_wd[$value][$k]) && $tri_pub_wd[$value][$k] == '' ? 0 : (float) $tri_pub_wd[$value][$k]),
                                    "NetTriOccupCost" => (isset($tri_net_wd[$value][$k]) && $tri_net_wd[$value][$k] == '' ? 0 : (float) $tri_net_wd[$value][$k]),
                                    "IsTaxOnTriOccupCost" => (isset($check_tax_tri[$k][0]) ? (float) $check_tax_tri[$k][0] : '0'),
                                    "TaxTriOccupCost" => (isset($tri_tax_wd[$value][$k]) && $tri_tax_wd[$value][$k] != '' ? (float) $tri_tax_wd[$value][$k] : '0'),
                                    "ChildAgeLimit" => (isset($age_paid[$k][0]) && !empty($age_paid[$k][0]) ? (float) $age_paid[$k][0] : '0'),
                                    "ExtraWOBedCost" => (isset($chpaid_pub_wd[$value][$k]) && $chpaid_pub_wd[$value][$k] == '' ? 0 : (float) $chpaid_pub_wd[$value][$k]),
                                    "NetExtraWOBedCost" => (isset($chpaid_net_wd[$value][$k]) && $chpaid_net_wd[$value][$k] == '' ? 0 : (float) $chpaid_net_wd[$value][$k]),
                                    "IsTaxOnExtraWOBedCost" => (isset($check_tax_chpaid[$k][0]) ? (float) $check_tax_chpaid[$k][0] : '0'),
                                    "TaxExtraWOBedCost" => (isset($chpaid_tax_wd[$value][$k]) && $chpaid_tax_wd[$value][$k] != '' ? (float) $chpaid_tax_wd[$value][$k] : '0'),
                                    "RateType" => (isset($post['ratetype']) && ($post['ratetype'] == 'NR') ? '1' : '0'),
                                    "RackCommissionType" => (isset($post['rr_type']) && !empty($post['rr_type']) ? (int) $post['rr_type'] : '0'),
                                    "RackCommission" => (isset($post['rr_value']) && !empty($post['rr_value']) ? (int) $post['rr_value'] : '0'),
                                    "UpdatedDate" => $currentDate,
                                    "CreatedDate" => $currentDate,
                                    "XRefAccoSysId" => (int) $post['update_hotel_id'],
                                    "RoomInventorySysId" => (int) $id,
                                    "XRefItemSysId" => (int) $room_id[$k][0],
                                    "TrxCurrency" => (isset($post['currency_type']) && !empty($post['currency_type']) ? $post['currency_type'] : '0'),
                                    "SupplierSysId" => (isset($post['hidden_selected_supplier_sys_id']) && !empty($post['hidden_selected_supplier_sys_id']) ? $post['hidden_selected_supplier_sys_id'] : '0'),
                                    "IsAllowMarkupSO" => (isset($check_markup_sg[$k][0]) ? (float) $check_markup_sg[$k][0] : '0'),
                                    "IsAllowMarkupDO" => (isset($check_markup_db[$k][0]) ? (float) $check_markup_db[$k][0] : '0'),
                                    "IsAllowMarkupTO" => (isset($check_markup_tri[$k][0]) ? (float) $check_markup_tri[$k][0] : '0'),
                                    "IsAllowMarkupEB" => (isset($check_markup_ex[$k][0]) ? (float) $check_markup_ex[$k][0] : '0'),
                                    "IsAllowMarkupWOB" => (isset($check_markup_chpaid[$k][0]) ? (float) $check_markup_chpaid[$k][0] : '0'),
                                    "IsActive" => 1,
                                    "IsMarkForDelete" => 0,
                                    "WkSOccupCost" => (isset($sg_pub_wk[$value][$k]) && $sg_pub_wk[$value][$k] == '' ? 0 : (float) $sg_pub_wk[$value][$k]),
                                    "WkNetSOccupCost" => (isset($sg_net_wk[$value][$k]) && $sg_net_wk[$value][$k] == '' ? 0 : (float) $sg_net_wk[$value][$k]),
                                    "WkDOccupCost" => (isset($db_pub_wk[$value][$k]) && $db_pub_wk[$value][$k] == '' ? 0 : (float) $db_pub_wk[$value][$k]),
                                    "WkNetDOccupCost" => (isset($db_net_wk[$value][$k]) && $db_net_wk[$value][$k] == '' ? 0 : (float) $db_net_wk[$value][$k]),
                                    "WkExtraBedCost" => (isset($ex_wbed_pub_wk[$value][$k]) && $ex_wbed_pub_wk[$value][$k] == '' ? 0 : (float) $ex_wbed_pub_wk[$value][$k]),
                                    "WkNetExtraBedCost" => (isset($ex_wbed_net_wk[$value][$k]) && $ex_wbed_net_wk[$value][$k] == '' ? 0 : (float) $ex_wbed_net_wk[$value][$k]),
                                    "WkTriOccupCost" => (isset($tri_pub_wk[$value][$k]) && $tri_pub_wk[$value][$k] == '' ? 0 : (float) $tri_pub_wk[$value][$k]),
                                    "WkNetTriOccupCost" => (isset($tri_net_wk[$value][$k]) && $tri_net_wk[$value][$k] == '' ? 0 : (float) $tri_net_wk[$value][$k]),
                                    "WkExtraWOBedCost" => (isset($chpaid_pub_wk[$value][$k]) && $chpaid_pub_wk[$value][$k] == '' ? 0 : (float) $chpaid_pub_wk[$value][$k]),
                                    "WkNetExtraWOBedCost" => (isset($chpaid_net_wk[$value][$k]) && $chpaid_net_wk[$value][$k] == '' ? 0 : (float) $chpaid_net_wk[$value][$k])
                                );
                                //echo "<pre>";print_r($addHotelData);exit;
                                $this->db->insert('TB_MP_Inventory_Accom', $addHotelData);
                                $LetKey++;
                            }
                            $RoomKey++;
                        }
                    }
                }
                if (isset($update_InvnItemSysId) && isset($invtId_arr)) {
                    $restInvtId = (array_diff_key($update_InvnItemSysId, $invtId_arr));
                    if ($restInvtId) {
                        foreach ($restInvtId as $update) {
                            $where = array('InvnItemSysId =?' => $update);
                            $this->db->update('TB_MP_Inventory_Accom', array('IsMarkForDelete' => 1), $where);
                        }
                    }
                }

                return array("status" => true, "HotelType" => $isInventory, 'SessionKey' => $sessionKey);
            }
        }
    }

    public function UpdateIndividualRateCard($insert, $intLoggedinUserAgencySysId, $intLoggedinUserId) {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        if ($request->isPost()) {
            $post = $request->getPost();
            //echo '<pre>';print_r($post);die('dddd');
            if (!empty($post['InvnItemSysId']) && $post['InvnItemSysId'] > 0) {
                $where = array('InvnItemSysId =?' => $post['InvnItemSysId'], 'XRefAccoSysId =?' => $post['hotel_id'], 'MealPlanType =?' => $post['MealPlanType'], 'SupplierSysId =?' => $post['SupplierSysId'], 'AgencySysId =?' => $intLoggedinUserAgencySysId);
                return $update = $this->db->update('TB_MP_Inventory_Accom', $insert, $where);
            } else {
                $getRTDTSR = self::getRatedetailsSingleRow($post['hotel_id'], $post['XRefItemSysId'], $post['EconomyType'], $post['MealPlanType'], $post['SupplierSysId'], $intLoggedinUserAgencySysId);
                //echo '<pre>';print_r($getRTDTSR);die('adadad');

                $currentDate = date('Y-m-d H:i:s');
                if (in_array(date("D", strtotime($post['fromdate'])), explode(',', $getRTDTSR['WeekendDefine']))) {
                    $insert = array(
                        'XRefAccoSysId' => $post['hotel_id'],
                        'AgencySysId' => $intLoggedinUserAgencySysId,
                        'XRateSessionKey' => $getRTDTSR['XRateSessionKey'],
                        'FromDate' => date("Y-m-d", strtotime($post['fromdate'])), //FromDate
                        'ToDate' => date("Y-m-d", strtotime($post['fromdate'])), //ToDate
                        'InventoryType' => '1',
                        'Title' => $getRTDTSR['Title'],
                        'EconomyType' => $post['EconomyType'], //d
                        'CostCurrency' => $getRTDTSR['CostCurrency'], //CostCurrency
                        'RackCommissionType' => '0', //RackCommissionType
                        'SupplierSysId' => $getRTDTSR['SupplierSysId'], //SupplierSysId
                        'ChildAgeLimit' => $getRTDTSR['ChildAgeLimit'], //ChildAgeLimit
                        'InfantAgeLimit' => $getRTDTSR['InfantAgeLimit'], //InfantAgeLimit
                        'XRefItemSysId' => $post['XRefItemSysId'], //d
                        'MealPlanType' => $post['MealPlanType'], // d
                        'RateType' => isset($post['ratetype']) && !empty($post['ratetype']) ? $post['ratetype'] : '0', //RateType
                        'RackCommission' => isset($post['rr_value']) && !empty($post['rr_value']) ? $post['rr_value'] : '0', //RackCommission
                        'PublishQty' => isset($post['allocation']) && !empty($post['allocation']) ? ($post['allocation']) : '0',
                        'DailyRoomLimit' => isset($post['allocation']) && !empty($post['allocation']) ? ($post['allocation']) : '0',
                        'SOccupCost' => isset($post['sg_pub_wk']) && !empty($post['sg_pub_wk']) ? ($post['sg_pub_wk']) : null,
                        'NetSOccupCost' => isset($post['sg_net_wk']) && !empty($post['sg_net_wk']) ? ($post['sg_net_wk']) : null,
                        'DOccupCost' => isset($post['db_pub_wk']) && !empty($post['db_pub_wk']) ? ($post['db_pub_wk']) : null,
                        'NetDOccupCost' => isset($post['db_net_wk']) && !empty($post['db_net_wk']) ? ($post['db_net_wk']) : null,
                        //'TriOccupCost' => isset($post['tri_pub_wk']) && !empty($post['tri_pub_wk']) ? ($post['tri_pub_wk']) : null,
                        //'NetTriOccupCost' => isset($post['tri_net_wk']) && !empty($post['tri_net_wk']) ? ($post['tri_net_wk']) : null,
                        'ExtraBedCost' => isset($post['ex_wbed_pub_wk']) && !empty($post['ex_wbed_pub_wk']) ? ($post['ex_wbed_pub_wk']) : null,
                        'NetExtraBedCost' => isset($post['ex_wbed_net_wk']) && !empty($post['ex_wbed_net_wk']) ? ($post['ex_wbed_net_wk']) : null,
                        'ExtraWOBedCost' => isset($post['chpaid_pub_wk']) && !empty($post['chpaid_pub_wk']) ? ($post['chpaid_pub_wk']) : null,
                        'NetExtraWOBedCost' => isset($post['chpaid_net_wk']) && !empty($post['chpaid_net_wk']) ? ($post['chpaid_net_wk']) : null,
                        'IsExtraMealAdultCost' => isset($post['ext_adult']) && !empty($post['ext_adult']) ? ($post['ext_adult']) : '0',
                        'IsExtraMealChildCost' => isset($post['ext_child']) && !empty($post['ext_child']) ? ($post['ext_child']) : '0',
                        'IsTaxOnSOccupCost' => isset($post['check_tax_sg']) && !empty($post['check_tax_sg']) ? ($post['check_tax_sg']) : '0',
                        'IsTaxOnDOccupCost' => isset($post['check_tax_db']) && !empty($post['check_tax_db']) ? ($post['check_tax_db']) : '0',
                        'IsTaxOnTriOccupCost' => isset($post['check_tax_tri']) && !empty($post['check_tax_tri']) ? ($post['check_tax_tri']) : '0',
                        'IsTaxOnExtraBedCost' => isset($post['check_tax_ex']) && !empty($post['check_tax_ex']) ? ($post['check_tax_ex']) : '0',
                        'IsTaxOnExtraWOBedCost' => isset($post['check_tax_chpaid']) && !empty($post['check_tax_chpaid']) ? ($post['check_tax_chpaid']) : '0',
                        'TaxSOccupCost' => isset($post['sg_tax_wk']) && !empty($post['sg_tax_wk']) ? ($post['sg_tax_wk']) : '0',
                        'TaxDOccupCost' => isset($post['db_tax_wk']) && !empty($post['db_tax_wk']) ? ($post['db_tax_wk']) : '0',
                        'TaxExtraBedCost' => isset($post['tri_tax_wk']) && !empty($post['tri_tax_wk']) ? ($post['tri_tax_wk']) : '0',
                        'TaxTriOccupCost' => isset($post['ex_wbed_tax_wk']) && !empty($post['ex_wbed_tax_wk']) ? ($post['ex_wbed_tax_wk']) : '0',
                        'TaxExtraWOBedCost' => isset($post['chpaid_tax_wk']) && !empty($post['chpaid_tax_wk']) ? ($post['chpaid_tax_wk']) : '0',
                        'CreatorSysId' => $intLoggedinUserId,
                        'UpdateDate' => $currentDate,
                        'CreateDate' => $currentDate,
                        'ApproveDate' => $currentDate,
                        'WeekendDefine' => $getRTDTSR['WeekendDefine'],
                        'IsMarkForDelete' => 0,
                        'IsActive' => '1',
                    );
                } else {
                    $insert = array(
                        'XRefAccoSysId' => $post['hotel_id'],
                        'AgencySysId' => $intLoggedinUserAgencySysId,
                        'XRateSessionKey' => $getRTDTSR['XRateSessionKey'],
                        'FromDate' => date("Y-m-d", strtotime($post['fromdate'])), //FromDate
                        'ToDate' => date("Y-m-d", strtotime($post['fromdate'])), //ToDate
                        'InventoryType' => '1',
                        'Title' => $getRTDTSR['Title'],
                        'EconomyType' => $post['EconomyType'], //d
                        'CostCurrency' => $getRTDTSR['CostCurrency'], //CostCurrency
                        'RackCommissionType' => '0', //RackCommissionType
                        'SupplierSysId' => $getRTDTSR['SupplierSysId'], //SupplierSysId
                        'ChildAgeLimit' => $getRTDTSR['ChildAgeLimit'], //ChildAgeLimit
                        'InfantAgeLimit' => $getRTDTSR['InfantAgeLimit'], //InfantAgeLimit
                        'XRefItemSysId' => $post['XRefItemSysId'], //d
                        'MealPlanType' => $post['MealPlanType'], // d
                        'RateType' => isset($post['ratetype']) && !empty($post['ratetype']) ? $post['ratetype'] : '0', //RateType
                        'RackCommission' => isset($post['rr_value']) && !empty($post['rr_value']) ? $post['rr_value'] : '0', //RackCommission
                        'PublishQty' => isset($post['allocation']) && !empty($post['allocation']) ? ($post['allocation']) : '0',
                        'DailyRoomLimit' => isset($post['allocation']) && !empty($post['allocation']) ? ($post['allocation']) : '0',
                        'SOccupCost' => isset($post['sg_pub_wd']) && !empty($post['sg_pub_wd']) ? ($post['sg_pub_wd']) : null,
                        'NetSOccupCost' => isset($post['sg_net_wd']) && !empty($post['sg_net_wd']) ? ($post['sg_net_wd']) : null,
                        'DOccupCost' => isset($post['db_pub_wd']) && !empty($post['db_pub_wd']) ? ($post['db_pub_wd']) : null,
                        'NetDOccupCost' => isset($post['db_net_wd']) && !empty($post['db_net_wd']) ? ($post['db_net_wd']) : null,
                        //'TriOccupCost' => isset($post['tri_pub_wd']) && !empty($post['tri_pub_wd']) ? ($post['tri_pub_wd']) : null,
                        //'NetTriOccupCost' => isset($post['tri_net_wd']) && !empty($post['tri_net_wd']) ? ($post['tri_net_wd']) : null,
                        'ExtraBedCost' => isset($post['ex_wbed_pub_wd']) && !empty($post['ex_wbed_pub_wd']) ? ($post['ex_wbed_pub_wd']) : null,
                        'NetExtraBedCost' => isset($post['ex_wbed_net_wd']) && !empty($post['ex_wbed_net_wd']) ? ($post['ex_wbed_net_wd']) : null,
                        'ExtraWOBedCost' => isset($post['chpaid_pub_wd']) && !empty($post['chpaid_pub_wd']) ? ($post['chpaid_pub_wd']) : null,
                        'NetExtraWOBedCost' => isset($post['chpaid_net_wd']) && !empty($post['chpaid_net_wd']) ? ($post['chpaid_net_wd']) : null,
                        'IsExtraMealAdultCost' => isset($post['ext_adult']) && !empty($post['ext_adult']) ? ($post['ext_adult']) : '0',
                        'IsExtraMealChildCost' => isset($post['ext_child']) && !empty($post['ext_child']) ? ($post['ext_child']) : '0',
                        'IsTaxOnSOccupCost' => isset($post['check_tax_sg']) && !empty($post['check_tax_sg']) ? ($post['check_tax_sg']) : '0',
                        'IsTaxOnDOccupCost' => isset($post['check_tax_db']) && !empty($post['check_tax_db']) ? ($post['check_tax_db']) : '0',
                        'IsTaxOnTriOccupCost' => isset($post['check_tax_tri']) && !empty($post['check_tax_tri']) ? ($post['check_tax_tri']) : '0',
                        'IsTaxOnExtraBedCost' => isset($post['check_tax_ex']) && !empty($post['check_tax_ex']) ? ($post['check_tax_ex']) : '0',
                        'IsTaxOnExtraWOBedCost' => isset($post['check_tax_chpaid']) && !empty($post['check_tax_chpaid']) ? ($post['check_tax_chpaid']) : '0',
                        'TaxSOccupCost' => isset($post['sg_tax_wd']) && !empty($post['sg_tax_wd']) ? ($post['sg_tax_wd']) : '0',
                        'TaxDOccupCost' => isset($post['db_tax_wd']) && !empty($post['db_tax_wd']) ? ($post['db_tax_wd']) : '0',
                        'TaxExtraBedCost' => isset($post['tri_tax_wd']) && !empty($post['tri_tax_wd']) ? ($post['tri_tax_wd']) : '0',
                        'TaxTriOccupCost' => isset($post['ex_wbed_tax_wd']) && !empty($post['ex_wbed_tax_wd']) ? ($post['ex_wbed_tax_wd']) : '0',
                        'TaxExtraWOBedCost' => isset($post['chpaid_tax_wd']) && !empty($post['chpaid_tax_wd']) ? ($post['chpaid_tax_wd']) : '0',
                        'CreatorSysId' => $intLoggedinUserId,
                        'UpdateDate' => $currentDate,
                        'CreateDate' => $currentDate,
                        'ApproveDate' => $currentDate,
                        'WeekendDefine' => $getRTDTSR['WeekendDefine'],
                        'IsMarkForDelete' => 0,
                        'IsActive' => '1',
                    );
                }
                //echo '<pre>';print_r($insert);die('dddd');
                return $update = $this->db->insert('TB_MP_Inventory_Accom', $insert);
            }
        }
    }

    public function UpdateBulkIndividualRateCard($intLoggedinUserAgencySysId, $intLoggedinUserId) {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        if ($request->isPost()) {

            $post = $request->getPost();
            $where = array('XRefAccoSysId =?' => $post['hotel_id'], 'FromDate >=? ' => date('Y-m-d', strtotime($post['fromdate'])), 'FromDate <=? ' => date('Y-m-d', strtotime($post['todate'])), 'XRefItemSysId =? ' => $post['XRefItemSysId'], 'EconomyType =? ' => $post['EconomyType'], 'MealPlanType =? ' => $post['MealPlanType'], 'AgencySysId =?' => $intLoggedinUserAgencySysId);
            $insert_im = array('IsMarkForDelete' => 1, 'IsActive' => 0);
            $update = $this->db->update('TB_MP_Inventory_Accom', $insert_im, $where);
            $getRTDTSR = self::getRatedetailsSingleRow($post['hotel_id'], $post['XRefItemSysId'], $post['EconomyType'], $post['MealPlanType'], $intLoggedinUserAgencySysId);

            $strFromDate = Zend_Controller_Action_HelperBroker::getStaticHelper('DateFormat')->cal2Db($post['fromdate'], 'd-m-y');
            $strToDate = Zend_Controller_Action_HelperBroker::getStaticHelper('DateFormat')->cal2Db($post['todate'], 'd-m-y');
            //$FromDate = date('D', strtotime($strFromDate));
            $currentDate = date('Y-m-d H:i:s');

            $strToDates = date("Y-m-d", strtotime("+1 day", strtotime($strToDate)));
            $begin = new DateTime($strFromDate);
            $end = new DateTime($strToDates);
            $interval = DateInterval::createFromDateString('1 day');
            $period = new DatePeriod($begin, $interval, $end);
            foreach ($period as $dt) {
                if (in_array($dt->format("D"), explode(',', $getRTDTSR['WeekendDefine']))) {
                    $insert = array(
                        'XRefAccoSysId' => $post['hotel_id'],
                        'AgencySysId' => $intLoggedinUserAgencySysId,
                        'XRateSessionKey' => $getRTDTSR['XRateSessionKey'],
                        'FromDate' => $dt->format("Y-m-d"), //FromDate
                        'ToDate' => date("Y-m-d", strtotime($strToDate)), //ToDate
                        'InventoryType' => '1',
                        'Title' => $getRTDTSR['Title'],
                        'EconomyType' => $post['EconomyType'], //d
                        'CostCurrency' => $getRTDTSR['CostCurrency'], //CostCurrency
                        'RackCommissionType' => '0', //RackCommissionType
                        'SupplierSysId' => $getRTDTSR['SupplierSysId'], //SupplierSysId
                        'ChildAgeLimit' => $getRTDTSR['ChildAgeLimit'], //ChildAgeLimit
                        'InfantAgeLimit' => $getRTDTSR['InfantAgeLimit'], //InfantAgeLimit
                        'XRefItemSysId' => $post['XRefItemSysId'], //d
                        'MealPlanType' => $post['MealPlanType'], // d
                        'RateType' => isset($post['ratetype']) && !empty($post['ratetype']) ? $post['ratetype'] : '0', //RateType
                        'RackCommission' => isset($post['rr_value']) && !empty($post['rr_value']) ? $post['rr_value'] : '0', //RackCommission
                        'PublishQty' => isset($post['allocation']) && !empty($post['allocation']) ? ($post['allocation']) : '0',
                        'DailyRoomLimit' => isset($post['allocation']) && !empty($post['allocation']) ? ($post['allocation']) : '0',
                        'SOccupCost' => isset($post['sg_pub_wk']) && !empty($post['sg_pub_wk']) ? ($post['sg_pub_wk']) : null,
                        'NetSOccupCost' => isset($post['sg_net_wk']) && !empty($post['sg_net_wk']) ? ($post['sg_net_wk']) : null,
                        'DOccupCost' => isset($post['db_pub_wk']) && !empty($post['db_pub_wk']) ? ($post['db_pub_wk']) : null,
                        'NetDOccupCost' => isset($post['db_net_wk']) && !empty($post['db_net_wk']) ? ($post['db_net_wk']) : null,
                        //'TriOccupCost' => isset($post['tri_pub_wk']) && !empty($post['tri_pub_wk']) ? ($post['tri_pub_wk']) : null,
                        //'NetTriOccupCost' => isset($post['tri_net_wk']) && !empty($post['tri_net_wk']) ? ($post['tri_net_wk']) : null,
                        'ExtraBedCost' => isset($post['ex_wbed_pub_wk']) && !empty($post['ex_wbed_pub_wk']) ? ($post['ex_wbed_pub_wk']) : null,
                        'NetExtraBedCost' => isset($post['ex_wbed_net_wk']) && !empty($post['ex_wbed_net_wk']) ? ($post['ex_wbed_net_wk']) : null,
                        'ExtraWOBedCost' => isset($post['chpaid_pub_wk']) && !empty($post['chpaid_pub_wk']) ? ($post['chpaid_pub_wk']) : null,
                        'NetExtraWOBedCost' => isset($post['chpaid_net_wk']) && !empty($post['chpaid_net_wk']) ? ($post['chpaid_net_wk']) : null,
                        'IsExtraMealAdultCost' => isset($post['ext_adult']) && !empty($post['ext_adult']) ? ($post['ext_adult']) : '0',
                        'IsExtraMealChildCost' => isset($post['ext_child']) && !empty($post['ext_child']) ? ($post['ext_child']) : '0',
                        'IsTaxOnSOccupCost' => '0',
                        'IsTaxOnDOccupCost' => '0',
                        //'IsTaxOnTriOccupCost' => '0',
                        'IsTaxOnExtraBedCost' => '0',
                        'IsTaxOnExtraWOBedCost' => '0',
                        'CreatorSysId' => $intLoggedinUserId,
                        'UpdateDate' => $currentDate,
                        'CreateDate' => $currentDate,
                        'ApproveDate' => $currentDate,
                        'WeekendDefine' => $getRTDTSR['WeekendDefine'],
                        'IsMarkForDelete' => 0,
                        'IsActive' => '1',
                    );
                } else {
                    $insert = array(
                        'XRefAccoSysId' => $post['hotel_id'],
                        'AgencySysId' => $intLoggedinUserAgencySysId,
                        'XRateSessionKey' => $getRTDTSR['XRateSessionKey'],
                        'FromDate' => $dt->format("Y-m-d"), //FromDate
                        'ToDate' => date("Y-m-d", strtotime($post['fromdate'])), //ToDate
                        'InventoryType' => '1',
                        'Title' => $getRTDTSR['Title'],
                        'EconomyType' => $post['EconomyType'], //d
                        'CostCurrency' => $getRTDTSR['CostCurrency'], //CostCurrency
                        'RackCommissionType' => '0', //RackCommissionType
                        'SupplierSysId' => $getRTDTSR['SupplierSysId'], //SupplierSysId
                        'ChildAgeLimit' => $getRTDTSR['ChildAgeLimit'], //ChildAgeLimit
                        'InfantAgeLimit' => $getRTDTSR['InfantAgeLimit'], //InfantAgeLimit
                        'XRefItemSysId' => $post['XRefItemSysId'], //d
                        'MealPlanType' => $post['MealPlanType'], // d
                        'RateType' => isset($post['ratetype']) && !empty($post['ratetype']) ? $post['ratetype'] : '0', //RateType
                        'RackCommission' => isset($post['rr_value']) && !empty($post['rr_value']) ? $post['rr_value'] : '0', //RackCommission
                        'PublishQty' => isset($post['allocation']) && !empty($post['allocation']) ? ($post['allocation']) : '0',
                        'DailyRoomLimit' => isset($post['allocation']) && !empty($post['allocation']) ? ($post['allocation']) : '0',
                        'SOccupCost' => isset($post['sg_pub_wd']) && !empty($post['sg_pub_wd']) ? ($post['sg_pub_wd']) : null,
                        'NetSOccupCost' => isset($post['sg_net_wd']) && !empty($post['sg_net_wd']) ? ($post['sg_net_wd']) : null,
                        'DOccupCost' => isset($post['db_pub_wd']) && !empty($post['db_pub_wd']) ? ($post['db_pub_wd']) : null,
                        'NetDOccupCost' => isset($post['db_net_wd']) && !empty($post['db_net_wd']) ? ($post['db_net_wd']) : null,
                        //'TriOccupCost' => isset($post['tri_pub_wd']) && !empty($post['tri_pub_wd']) ? ($post['tri_pub_wd']) : null,
                        //'NetTriOccupCost' => isset($post['tri_net_wd']) && !empty($post['tri_net_wd']) ? ($post['tri_net_wd']) : null,
                        'ExtraBedCost' => isset($post['ex_wbed_pub_wd']) && !empty($post['ex_wbed_pub_wd']) ? ($post['ex_wbed_pub_wd']) : null,
                        'NetExtraBedCost' => isset($post['ex_wbed_net_wd']) && !empty($post['ex_wbed_net_wd']) ? ($post['ex_wbed_net_wd']) : null,
                        'ExtraWOBedCost' => isset($post['chpaid_pub_wd']) && !empty($post['chpaid_pub_wd']) ? ($post['chpaid_pub_wd']) : null,
                        'NetExtraWOBedCost' => isset($post['chpaid_net_wd']) && !empty($post['chpaid_net_wd']) ? ($post['chpaid_net_wd']) : null,
                        'IsExtraMealAdultCost' => isset($post['ext_adult']) && !empty($post['ext_adult']) ? ($post['ext_adult']) : '0',
                        'IsExtraMealChildCost' => isset($post['ext_child']) && !empty($post['ext_child']) ? ($post['ext_child']) : '0',
                        'IsTaxOnSOccupCost' => '0',
                        'IsTaxOnDOccupCost' => '0',
                        //'IsTaxOnTriOccupCost' => '0',
                        'IsTaxOnExtraBedCost' => '0',
                        'IsTaxOnExtraWOBedCost' => '0',
                        'CreatorSysId' => $intLoggedinUserId,
                        'UpdateDate' => $currentDate,
                        'CreateDate' => $currentDate,
                        'ApproveDate' => $currentDate,
                        'WeekendDefine' => $getRTDTSR['WeekendDefine'],
                        'IsMarkForDelete' => 0,
                        'IsActive' => '1',
                    );
                }
                //echo '<pre>';print_r($insert);echo '</pre>';
                $this->db->insert('TB_MP_Inventory_Accom', $insert);
            }

            return true;
        }
    }

    public function checkDuplicateRate($AccomSysId, $AgencySysId, $strFromDate, $strToDate) {
        $select = $this->db->select();
        $hotelname = array('ICSourceSysId', 'ContSysId');
        $selectarray = array('id', 'AccomSysId', 'SupplierSysId', 'CONVERT(VARCHAR(24),FromDate,111) as FromDate');
        $select->from(array('tb1' => "Tb_MP_Accomdation_Room_Inventory"), $selectarray);
        $select->joinLeft(array('tb4' => "TB_IC_Accomdation"), "tb1.AccomSysId = tb4.AccomSysId", $hotelname);
        if (($strFromDate != '' && trim($strFromDate) != '____-__-__') && ($strToDate != '' && trim($strToDate) != '____-__-__')) {
            $select->where("tb1.FromDate <= '$strFromDate' AND tb1.ToDate >= '$strToDate'");
        }
        $select->where("tb1.AccomSysId =?", $AccomSysId);
        $select->where("tb1.AgencySysId =?", $AgencySysId);
        $select->where("tb1.IsMarkForDelete =?", 0);
        $result = $this->db->fetchRow($select);
        return $result;
    }

    public function getRatedetailsSingleRowNew($hotel_id, $XRefItemSysId, $EconomyType, $MealPlanType, $SupplierSysId, $intLoggedinUserAgencySysId, $InvnItemSysId = NULL) {
        $select = $this->db->select();
        $selectarray = array('XRateSessionKey', 'XRefAccoSysId', 'XRefItemSysId', 'AgencySysId', 'Title', 'CostCurrency', 'SupplierSysId', 'ChildAgeLimit', 'InfantAgeLimit', 'WeekendDefine');
        $selectarrayInv = array('id', 'PublishQty as DailyRoomLimit', 'RoomSysId as EconomyType', 'CONVERT(VARCHAR(24),FromDate,111) as FromDate');
        $select->from(array('tb1' => "Tb_MP_Accomdation_Room_Inventory"), $selectarrayInv);
        $select->joinLeft(array('tb11' => "TB_MP_Inventory_Accom"), "tb1.id = tb11.RoomInventorySysId", array('*'));
        //$select->from(array('tb1' => "TB_MP_Inventory_Accom"), $selectarray);
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->where("tb1.XRefItemSysId =?", $XRefItemSysId);
        $select->where("tb1.RoomSysId =?", $EconomyType);
        $select->where("tb11.MealPlanType =?", $MealPlanType);
        $select->where("tb1.SupplierSysId =?", $SupplierSysId);
        $select->where("tb1.AgencySysId =?", $intLoggedinUserAgencySysId);
        if (!empty($InvnItemSysId)) {
            $select->where("tb11.InvnItemSysId =?", $InvnItemSysId);
        }
        $select->where("tb1.IsMarkForDelete =?", 0);
        $select->where("tb11.IsMarkForDelete =?", 0);
        //echo $select;die;
        $result = $this->db->fetchRow($select);
        return $result;
    }

    public function getRatedetailsSingleRow($hotel_id, $XRefItemSysId, $EconomyType, $MealPlanType, $SupplierSysId, $intLoggedinUserAgencySysId, $InvnItemSysId = NULL) {
        $select = $this->db->select();
        $selectarray = array('XRateSessionKey', 'XRefAccoSysId', 'XRefItemSysId', 'AgencySysId', 'Title', 'CostCurrency', 'SupplierSysId', 'ChildAgeLimit', 'InfantAgeLimit', 'WeekendDefine');
        $selectarrayInv = array('id', 'PublishQty as DailyRoomLimit', 'RoomSysId as EconomyType', 'CONVERT(VARCHAR(24),FromDate,111) as FromDate');
        $select->from(array('tb1' => "Tb_MP_Accomdation_Room_Inventory"), $selectarrayInv);
        $select->joinLeft(array('tb11' => "TB_MP_Inventory_Accom"), "tb1.id = tb11.RoomInventorySysId", array('*'));
        //$select->from(array('tb1' => "TB_MP_Inventory_Accom"), $selectarray);
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->where("tb1.XRefItemSysId =?", $XRefItemSysId);
        $select->where("tb1.RoomSysId =?", $EconomyType);
        $select->where("tb11.MealPlanType =?", $MealPlanType);
        $select->where("tb1.SupplierSysId =?", $SupplierSysId);
        $select->where("tb1.AgencySysId =?", $intLoggedinUserAgencySysId);
        //        if (!empty($InvnItemSysId)) {
        //            $select->where("tb1.InvnItemSysId =?", $InvnItemSysId);
        //        }
        $select->where("tb1.IsMarkForDelete =?", 0);
        $select->where("tb11.IsMarkForDelete =?", 0);
        //echo $select;die;
        $result = $this->db->fetchRow($select);
        return $result;
    }

    public function AddHotelCalcellation($intLoggedinUserAgencySysId, $intLoggedinUserId) {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        if ($request->isPost()) {
            try {
                $this->db->beginTransaction();
                $post = $request->getPost();
//                echo '<pre>';print_r($post);die;
                $before_days = isset($post['before_days']) && !empty($post['before_days']) ? $post['before_days'] : '';
                $value_type = isset($post['value_type']) && !empty($post['value_type']) ? $post['value_type'] : '';
                $per_value = isset($post['per_value']) && !empty($post['per_value']) ? $post['per_value'] : '';
                $RoomCancelSysId = isset($post['RoomCancelSysId']) && !empty($post['RoomCancelSysId']) ? $post['RoomCancelSysId'] : array();
                $currentDate = date('Y-m-d H:i:s');
                $GetCurrency = $this->GetCurrency($post['update_hotel_id']);
                //echo '<pre>';print_r($post['remarks']);die;
                $room_type = isset($post['room_type']) ? $post['room_type'] : array();
                $roomindex = 0;
                if (!empty($room_type)) {
                    foreach ($room_type as $rk => $rval) {
                        if ($value_type) {
                            foreach ($value_type as $k => $val) {
                                if (isset($RoomCancelSysId[$rval]) && !empty($RoomCancelSysId[$rval]) && isset($RoomCancelSysId[$rval][$k]) && $RoomCancelSysId[$rval][$k] > 0) {
                                    $insert = array(
                                        'ItemSysId' => $rval,
                                        'Accosysid' => isset($post['update_hotel_id']) ? $post['update_hotel_id'] : '',
                                        'AgencySysId' => $intLoggedinUserAgencySysId,
                                        'CreatorSysId' => $intLoggedinUserId,
                                        'ChBeforeDays' => isset($before_days[$k]) ? $before_days[$k] : '',
                                        'ChargeType' => isset($value_type[$k]) ? $value_type[$k] : '',
                                        'Charge' => isset($per_value[$k]) ? $per_value[$k] : '',
                                        'Currency' => isset($GetCurrency['TrxCurrency']) ? $GetCurrency['TrxCurrency'] : '',
                                        'Remarks' => isset($post['remarks']) ? $post['remarks'] : 'NA',
                                        'BookingTermCond' => isset($post['booking_tc']) ? $post['booking_tc'] : 'NA',
                                        'Fromdate' => EMPTY_DATE,
                                        'Todate' => EMPTY_DATE,
                                        'UpdatedOn' => $currentDate,
                                        'IsMarkForDel' => 0,
                                        'IsActive' => '1',
                                    );
                                    $where = array('RoomCancelSysId =?' => $RoomCancelSysId[$rval][$k]);
                                    $this->db->update('TB_IC_Accomdation_Room_CancellationPolicy', $insert, $where);
                                } else {
                                    $insert = array(
                                        'ItemSysId' => $rval,
                                        'Accosysid' => isset($post['update_hotel_id']) ? $post['update_hotel_id'] : '',
                                        'AgencySysId' => $intLoggedinUserAgencySysId,
                                        'CreatorSysId' => $intLoggedinUserId,
                                        'ChBeforeDays' => isset($before_days[$k]) ? $before_days[$k] : '',
                                        'ChargeType' => isset($value_type[$k]) ? $value_type[$k] : '',
                                        'Charge' => isset($per_value[$k]) ? $per_value[$k] : '',
                                        'Currency' => isset($GetCurrency['TrxCurrency']) ? $GetCurrency['TrxCurrency'] : '',
                                        'Remarks' => isset($post['remarks']) ? $post['remarks'] : 'NA',
                                        'BookingTermCond' => isset($post['booking_tc']) ? $post['booking_tc'] : 'NA',
                                        'Fromdate' => EMPTY_DATE,
                                        'Todate' => EMPTY_DATE,
                                        'CreatedOn' => $currentDate,
                                        'UpdatedOn' => $currentDate,
                                        'IsMarkForDel' => 0,
                                        'IsActive' => '1',
                                        'roomindex' => $roomindex
                                    );
                                    //echo '<pre>';print_r($insert);
                                    $this->db->insert('TB_IC_Accomdation_Room_CancellationPolicy', $insert);
                                }
                            }
                        }
                        $roomindex = $rval;
                    }
                }
                //echo '<pre>';print_r($post);die();
                $this->db->commit();
                return true;
            } catch (Exception $ex) {
                $this->db->rollBack();
                die($ex->getMessage());
            }
        }
    }

    public function HotelrateCardList($hotel_id, $intLoggedinUserAgencySysId) {
        $select = $this->db->select();
        $selectarray = array('XRefAccoSysId', 'AgencySysId', 'XRateSessionKey', 'CONVERT(VARCHAR(24),FromDate,103) as FromDate', 'CONVERT(VARCHAR(24),ToDate,103) as ToDate', 'CostCurrency', 'RateType', 'RackCommissionType', 'RackCommission', 'SupplierSysId', 'EconomyType', 'MealPlanType', 'DailyRoomLimit', 'WeekendDefine');
        $supplarray = array('SupplierName');
        $curarray = array('Symbol as CurrencySymbol');
        $hotelname = array('Title as hotelName');
        $select->from(array('tb1' => "TB_MP_Inventory_Accom"), $selectarray);
        $select->joinLeft(array('tb2' => "TB_IC_Supplier"), "tb1.SupplierSysId = tb2.SupplierSysId", $supplarray);
        $select->joinLeft(array('tb3' => "TB_Master_Currency"), "tb1.CostCurrency = tb3.CurrencyType", $curarray);
        $select->joinLeft(array('tb4' => "TB_IC_Accomdation"), "tb1.XRefAccoSysId = tb4.AccomSysId", $hotelname);
        $select->where("tb1.XRefAccoSysId =?", $hotel_id);
        $select->where("tb1.AgencySysId =?", $intLoggedinUserAgencySysId);
        $select->where("tb1.IsMarkForDelete =?", 0);
        //$select->group(array('tb1.XRefAccoSysId','tb1.XRateSessionKey','tb1.AgencySysId','tb1.FromDate','tb1.ToDate','tb1.CostCurrency','tb1.RateType','tb1.RackCommissionType','tb1.RackCommission','tb1.SupplierSysId','tb2.SupplierName','tb3.Symbol','tb4.Title'));
        //$select->group(array('tb1.XRateSessionKey'));
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function HotelrateCardListUpdateDates($hotel_id, $intLoggedinUserAgencySysId) {
        $params = Zend_Controller_Front::getInstance()->getRequest()->getParams();
        //print_r($params);die;
        $select = $this->db->select();
        $selectarray = array('XRefAccoSysId', 'AgencySysId', 'XRateSessionKey', 'CONVERT(VARCHAR(24),FromDate,111) as FromDate', 'CONVERT(VARCHAR(24),ToDate,111) as ToDate', 'Title', 'CostCurrency', 'RateType', 'RackCommissionType', 'RackCommission', 'SupplierSysId', 'EconomyType', 'MealPlanType', 'DailyRoomLimit', 'WeekendDefine', 'SOccupCost', 'NetSOccupCost', 'DOccupCost', 'NetDOccupCost', 'TriOccupCost', 'NetTriOccupCost', 'ExtraBedCost', 'NetExtraBedCost', 'ExtraWOBedCost', 'NetExtraWOBedCost', 'PublishQty', 'NetExtraBedWeekendCost', 'NetExtraWOBedWeekendCost', 'NetTriWeekendCost', 'NetDOWeekendCost', 'NetSOWeekendCost', 'ExtraBedWeekendCost', 'ExtraWOBedWeekendCost', 'TriWeekendCost', 'DOWeekendCost', 'SOWeekendCost', 'ChildAgeLimit', 'InfantAgeLimit', 'XRefItemSysId', 'CreatorSysId', 'UpdateDate', 'CreateDate', 'ApproveDate');
        $supplarray = array('SupplierName');
        $curarray = array('Symbol as CurrencySymbol');
        $hotelname = array('Title as hotelName');
        $select->from(array('tb1' => "TB_MP_Inventory_Accom"), $selectarray);
        $select->joinLeft(array('tb2' => "TB_IC_Supplier"), "tb1.SupplierSysId = tb2.SupplierSysId", $supplarray);
        $select->joinLeft(array('tb3' => "TB_Master_Currency"), "tb1.CostCurrency = tb3.CurrencyType", $curarray);
        $select->joinLeft(array('tb4' => "TB_IC_Accomdation"), "tb1.XRefAccoSysId = tb4.AccomSysId", $hotelname);
        $select->where("tb1.XRefAccoSysId =?", $hotel_id);
        $select->where("tb1.AgencySysId =?", $intLoggedinUserAgencySysId);
        $select->where("tb1.XRefItemSysId =?", $params['XRefItemSysId']);
        $select->where("tb1.EconomyType =?", $params['EconomyType']);
        $select->where("tb1.MealPlanType =?", $params['MealPlanType']);
        $select->where("tb1.SupplierSysId =?", $params['SupplierSysId']);
        $select->where("tb1.IsMarkForDelete =?", 0);
        //$select->group(array('tb1.XRefAccoSysId','tb1.XRateSessionKey','tb1.AgencySysId','tb1.FromDate','tb1.ToDate','tb1.CostCurrency','tb1.RateType','tb1.RackCommissionType','tb1.RackCommission','tb1.SupplierSysId','tb2.SupplierName','tb3.Symbol','tb4.Title'));
        //$select->group(array('tb1.XRateSessionKey'));
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function RoomArray($hotelId, $XRateSessionKey) {
        $sqlroom = " SELECT distinct(EconomyType) AS EconomyType,MealPlanType,XRateSessionKey
            FROM TB_MP_Inventory_Accom
            WHERE 1=1  ";
        $sqlroom .= " AND TB_MP_Inventory_Accom.XRefAccoSysId = " . $hotelId;
        $sqlroom .= " AND TB_MP_Inventory_Accom.XRateSessionKey = '" . $XRateSessionKey . "'";
        $sqlroom .= " ORDER BY MealPlanType ";
        $result = $this->db->query($sqlroom)->fetchAll();
        $data = array();
        foreach ($result as $key => $vl) {
            $data[$vl['EconomyType']][] = array('MealPlanType' => $vl['MealPlanType']);
        }
        return $data;
    }

    public function GetSupplierArray($hotelId) {
        $sql = " SELECT distinct(TB_MP_Inventory_Accom.SupplierSysId) AS SupplierSysId,TB_IC_Supplier.SupplierName
            FROM TB_MP_Inventory_Accom
            INNER JOIN  TB_IC_Supplier ON TB_MP_Inventory_Accom.SupplierSysId = TB_IC_Supplier.SupplierSysId
            WHERE 1=1  ";
        $sql .= " AND TB_MP_Inventory_Accom.XRefAccoSysId = " . $hotelId;
        //$sqlroom .= " ORDER BY MealPlanType ";
        $result = $this->db->query($sql)->fetchAll();
        $data = array();
        foreach ($result as $key => $vl) {
            $data[$vl['SupplierSysId']][] = array('SupplierName' => $vl['SupplierName'], 'SupplierSysId' => $vl['SupplierSysId']);
        }
        return $data;
    }

    public function HotelrateCardByAgList($intLoggedinUserAgencySysId) {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $post = $request->getPost();
        $select = $this->db->select();
        $selectarray = array('InvnItemSysId', 'XRefItemSysId', 'XRefAccoSysId', 'AgencySysId', 'XRateSessionKey', 'CONVERT(VARCHAR(24),FromDate,103) as FromDate', 'CONVERT(VARCHAR(24),ToDate,103) as ToDate', 'CostCurrency', 'RateType', 'RackCommissionType', 'RackCommission', 'SupplierSysId', 'EconomyType', 'MealPlanType', 'CreateDate', 'DailyRoomLimit', 'WeekendDefine');
        $supplarray = array('SupplierName');
        $curarray = array('Symbol as CurrencySymbol');
        $hotelname = array('Title as hotelName', 'ICSourceSysId');
        $cityarray = array('CityId', 'Title as City_title');
        $select->from(array('tb1' => "TB_MP_Inventory_Accom"), $selectarray);
        $select->joinLeft(array('tb2' => "TB_IC_Supplier"), "tb1.SupplierSysId = tb2.SupplierSysId", $supplarray);
        $select->joinLeft(array('tb3' => "TB_Master_Currency"), "tb1.CostCurrency = tb3.CurrencyType", $curarray);
        $select->joinLeft(array('tb4' => "TB_IC_Accomdation"), "tb1.XRefAccoSysId = tb4.AccomSysId", $hotelname);
        $select->joinLeft(array('tb5' => "TB_Master_Geo_City"), "tb4.CitySysId = tb5.CityId", $cityarray);
        $select->where("tb1.AgencySysId =?", $intLoggedinUserAgencySysId);
        $select->where("tb1.IsMarkForDelete =?", 0);
        $select->where("tb1.WeekendDefine IS NULL");
        //$select->group(array('tb1.XRefAccoSysId','tb1.InvnItemSysId','tb1.IsSaleStart','tb1.XRateSessionKey','tb1.AgencySysId','tb1.FromDate','tb1.ToDate','tb1.CostCurrency','tb1.RateType','tb1.RackCommissionType','tb1.RackCommission','tb1.SupplierSysId','tb2.SupplierName','tb3.Symbol','tb4.Title','tb1.CreateDate','tb4.ICSourceSysId','tb5.CityId','tb5.Title','tb1.XRefItemSysId','tb1.EconomyType','tb1.MealPlanType','tb1.DailyRoomLimit'));
        //$select->group('tb1.XRefAccoSysId');
        if (isset($post['DestinationId']) && $post['DestinationId'] > 0) {
            $select->where("tb4.CitySysId =?", $post['DestinationId']);
        }
        if (isset($post['hotelId']) && $post['hotelId'] > 0) {
            $select->where("tb1.XRefAccoSysId =?", $post['hotelId']);
        }
        if (isset($post['rating']) && $post['rating'] > 0) {
            $select->where("tb4.Stars =?", $post['rating']);
        }
        $select->order(array('tb1.CreateDate DESC'));
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function HotelrateCardByAgListByHotelOptimizedNew($intLoggedinUserAgencySysId, $AccomSysId = 0, $fetch = '', $XRateSessionKey = '', $filterData = array(), $pageNumber = 0) {

        $select = $this->db->select();
        $orderbyForPage1 = '';
        if ($pageNumber == 1) {
            $orderbyForPage1 = 'ORDER BY FromDate ASC';
        }


        $condition = '';
        if ($XRateSessionKey != '') {
            $condition = " AND TBMPARI.XRateSessionKey = '$XRateSessionKey'";
        }
        $dateFrom = (isset($filterData['dateFrom']) && trim($filterData['dateFrom']) != '____-__-__') ? $filterData['dateFrom'] : '';
        $dateTo = (isset($filterData['dateTo']) && trim($filterData['dateTo']) != '____-__-__') ? $filterData['dateTo'] : '';
        if ($dateFrom != '' && $dateTo != '') {
            //$select->where("tb1.FromDate <= '$dateFrom' AND tb1.ToDate >= '$dateTo'");
            $condition = " AND TBMPARI.FromDate = '$dateFrom' AND TBMPARI.ToDate = '$dateTo'";
        }
        $selectarray = array('Title as hotelName', 'RateType', 'AccomSysId', 'Stars', 'UpdateDate', 'HotelRateType', ''
            . ' ( SELECT "TBMPARI"."AccomSysId",MIN(TBMPARI.FromDate) AS FromDate,MAX(TBMPARI.FromDate) AS MaxFromDate,'
            . ' TBMPARI.ToDate, TBMPARI.RoomSysId, TBMPARI.XRateSessionKey,TBMPIA.MealPlanType,TBMRT.Title as RoomName,TBMAMT.Title as MealPlanTitle,TBMPIA.XRefItemSysId, '
            . ' TBMPIA.B2BMarkup,TBMPIA.B2CMarkup,TBMPIA.NetSOccupCost,TBMPIA.WkNetSOccupCost,TBMPIA.NetDOccupCost,TBMPIA.WkNetDOccupCost, '
            . ' TBMPIA.NetExtraBedCost,TBMPIA.WkNetExtraBedCost,TBMPIA.NetTriOccupCost,TBMPIA.WkNetTriOccupCost, '
            . ' TBMPIA.NetExtraWOBedCost,TBMPIA.WkNetExtraWOBedCost,TBMPIA.WeekendDefine,TBMPIA.IsActive as IsActiveRate, TBMPIA.PromotionsSysId,TBMPIA.IsPromotionalRate,TBAAP.FromBookingDate,TBAAP.ToBookingDate,TBAAP.IsNight,TBAAP.MinNight,TBAAP.MaxNight,TBAAP.IsMinRoom,TBAAP.MinRoom '
            . ' FROM "Tb_MP_Accomdation_Room_Inventory" AS "TBMPARI" '
            . ' LEFT JOIN TB_MP_Inventory_Accom AS TBMPIA ON TBMPARI.id = TBMPIA.RoomInventorySysId '
            . ' LEFT JOIN TB_Master_RoomType AS TBMRT ON TBMPARI.RoomSysId = TBMRT.RoomType '
            . ' LEFT JOIN TB_Master_Accom_MealType AS TBMAMT ON TBMPIA.MealPlanType = TBMAMT.MealTypeId '
            . ' LEFT JOIN Tb_Agency_Accom_Promotions AS TBAAP ON TBMPIA.PromotionsSysId = TBAAP.AccomPromotionsSysId '
            . ' WHERE  (TBMPARI.AccomSysId=TBICA.AccomSysId) AND TBMPARI.IsMarkForDelete = 0 AND TBMPIA.IsMarkForDelete = 0 '
            . $condition . ' GROUP BY TBMPARI.AccomSysId,TBMPARI.RoomSysId,TBMPARI.XRateSessionKey,TBMPARI.ToDate,TBMPIA.MealPlanType,TBMRT.Title,TBMAMT.Title,
                    TBMPIA.XRefItemSysId,TBMPIA.B2BMarkup,TBMPIA.B2CMarkup,TBMPIA.NetSOccupCost,TBMPIA.WkNetSOccupCost,TBMPIA.NetDOccupCost,TBMPIA.WkNetDOccupCost,TBMPIA.NetExtraBedCost,
                    TBMPIA.WkNetExtraBedCost,TBMPIA.NetTriOccupCost,TBMPIA.WkNetTriOccupCost,TBMPIA.NetExtraWOBedCost,TBMPIA.WkNetExtraWOBedCost,TBMPIA.WeekendDefine,TBMPIA.IsActive, TBMPIA.PromotionsSysId,TBMPIA.IsPromotionalRate,TBAAP.FromBookingDate,TBAAP.ToBookingDate,TBAAP.IsNight,TBAAP.MinNight,TBAAP.MaxNight,TBAAP.IsMinRoom,TBAAP.MinRoom  '
            . $orderbyForPage1 . ' FOR JSON PATH ) AS RoomInventory '
            . '');
        $select->from(array('TBICA' => "TB_IC_Accomdation"), $selectarray);
        $select->joinLeft(array('TBMGC' => "TB_Master_Geo_City"), "TBICA.CitySysId = TBMGC.CityId", array('Title as CityTitle'));
        $select->joinLeft(array('TBICS' => "TB_IC_Supplier"), "TBICA.SupplierSysId = TBICS.SupplierSysId", array('SupplierName'));
        $select->joinLeft(array('TBMC' => "TB_Master_Currency"), "TBICA.CurrencyType = TBMC.CurrencyType", array('Symbol as CurrencySymbol'));
        $select->where("TBICA.ICSourceSysId =?", $intLoggedinUserAgencySysId);
        if ($AccomSysId > 0) {
            $select->where("TBICA.AccomSysId =?", $AccomSysId);
        } else {
            $select->where("TBICA.IsMarkForDel = 0 AND (
                SELECT COUNT(*) FROM Tb_MP_Accomdation_Room_Inventory AS TBMPARI
                INNER JOIN TB_MP_Inventory_Accom AS TBMPIA ON TBMPARI.id = TBMPIA.RoomInventorySysId
                WHERE TBMPARI.AccomSysId = TBICA.AccomSysId AND TBMPARI.IsMarkForDelete = 0 AND TBMPIA.IsMarkForDelete = 0 $condition ) > 0");
        }
        if (isset($filterData['DestinationId']) && (int) $filterData['DestinationId'] > 0) {
            $select->where("TBICA.CitySysId =?", (int) $filterData['DestinationId']);
        }
        if (isset($filterData['hotelId']) && (int) $filterData['hotelId'] > 0) {
            $select->where("TBICA.AccomSysId =?", (int) $filterData['hotelId']);
        }
        if (isset($filterData['rating']) && (int) $filterData['rating'] > 0) {
            $select->where("TBICA.Stars =?", (int) $filterData['rating']);
        }

        $select->order(array('TBICA.UpdateDate DESC'));
//        echo $select;die;
        if ($fetch == 'all') {
            $result = $this->db->fetchAll($select);
            return $result;
        } else {
            return $select;
        }
    }

    public function HotelrateCardByAgListByHotelOptimized($intLoggedinUserAgencySysId, $AccomSysId = 0, $fetch = '') {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $post = $request->getPost();
        if (isset($post['hotelId']) && $post['hotelId'] > 0) {
            $AccomSysId = $post['hotelId'];
        }

        $Params = $request->getParams();
        $select = $this->db->select();
        $selectarray = array('InvnItemSysId', 'XRefItemSysId', 'XRefAccoSysId AS hotelId', 'AgencySysId', 'CreatedDate', 'RackCommission', 'MealPlanType', 'IsActive AS InvIsActive', 'MarkType', 'B2BMarkup', 'B2CMarkup');
        $RoomInventory = array('FromDate as TfromDate', 'RoomSysId', 'AccomSysId', 'XRateSessionKey', 'CONVERT(VARCHAR(24),FromDate,111) as FromDate', 'CONVERT(VARCHAR(24),ToDate,111) as ToDate', 'BookingType', 'PromotionsSysId');
        $supplarray = array('SupplierName');
        $curarray = array('Symbol as CurrencySymbol');
        $hotelname = array('Title as hotelName', 'ICSourceSysId', 'ContSysId', 'Stars', 'IsWebsite', 'IsActive', 'SupplierSysId', 'PropertyType', 'HotelRateType');
        $cityarray = array('CityId', 'Title as City_title');
        $countryarray = array('ContId', 'Title as country_title');
        $select->from(array('tb1' => "Tb_MP_Accomdation_Room_Inventory"), $RoomInventory);
        $select->joinInner(array('b' => new Zend_Db_Expr('(SELECT MIN(id) as INNERid FROM Tb_MP_Accomdation_Room_Inventory where IsMarkForDelete = 0 GROUP BY AccomSysId,RoomSysId,XRateSessionKey)')), "tb1.id= b.INNERid");
        //$select->joinInner(array('c' => new Zend_Db_Expr('(SELECT MIN(RoomInventorySysId) as InnRoomInventorySysId FROM TB_MP_Inventory_Accom where IsMarkForDelete = 0 GROUP BY XRefAccoSysId,MealPlanType,RoomInventorySysId)')), "tb1.RoomInventorySysId= c.InnRoomInventorySysId");
        $select->joinLeft(array('tb11' => "TB_MP_Inventory_Accom"), "tb1.id = tb11.RoomInventorySysId", $selectarray);

        //        $select->joinLeft(array('tb3' => "TB_Master_Currency"), "tb1.TrxCurrency = tb3.CurrencyType", $curarray);
        $select->joinLeft(array('tb4' => "TB_IC_Accomdation"), "tb1.AccomSysId = tb4.AccomSysId", $hotelname);
        $select->joinLeft(array('tb2' => "TB_IC_Supplier"), "tb4.SupplierSysId = tb2.SupplierSysId", $supplarray);
        $select->joinLeft(array('tb5' => "TB_Master_Geo_City"), "tb4.CitySysId = tb5.CityId", $cityarray);
        $select->joinLeft(array('tb6' => "TB_Master_Geo_Country"), "tb4.ContSysId = tb6.ContId", $countryarray);
        $select->joinLeft(array('tb7' => "TB_Master_RoomType"), "tb1.RoomSysId = tb7.RoomType", array("Title as EcomyType"));
        $select->joinLeft(array('tb8' => "TB_Master_Accom_MealType"), "tb11.MealPlanType = tb8.MealTypeId", array("Title as MealPlanTitle"));
        $select->where("tb1.AgencySysId =?", $intLoggedinUserAgencySysId);
        $select->where("tb1.IsMarkForDelete =?", 0);
        $select->where("tb11.IsMarkForDelete =?", 0);
        $select->where("tb1.PromotionsSysId is NULL");
        if (isset($Params['DestinationId']) && $Params['DestinationId'] > 0) {
            $select->where("tb4.CitySysId =?", $Params['DestinationId']);
        }
        $dateFrom = isset($post['dateFrom']) ? $post['dateFrom'] : '';
        $dateTo = isset($post['dateTo']) ? $post['dateTo'] : '';
        if (($dateFrom != '' && trim($dateFrom) != '____-__-__') && ($dateTo != '' && trim($dateTo) != '____-__-__')) {
            $select->where("tb1.FromDate <= '$dateFrom' AND tb1.ToDate >= '$dateTo'");
        }
        if ($AccomSysId > 0) {
            $select->where("tb11.XRefAccoSysId =?", $AccomSysId);
        }
        if (isset($Params['rating']) && $Params['rating'] > 0) {
            $select->where("tb4.Stars =?", $Params['rating']);
        }
        $select->order(array('tb1.FromDate ASC'));
        if ($fetch == 'all') {
            $result = $this->db->fetchAll($select);
            return $result;
        } else {
            return $select;
        }
        //$result = $this->db->fetchAll($select);
        //        echo "<pre>";print_r($result);die;
        //   echo $select; exit;
    }

    public function HotelrateCardByAgListByHotel($intLoggedinUserAgencySysId) {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $post = $request->getPost();
        $select = $this->db->select();
        $selectarray = array('InvnItemSysId', 'XRefItemSysId', 'SupplierSysId', 'XRefAccoSysId AS hotelId', 'AgencySysId', 'XRateSessionKey', 'CreateDate', 'CONVERT(VARCHAR(24),FromDate,111) as FromDate', 'CONVERT(VARCHAR(24),ToDate,111) as ToDate', 'CostCurrency', 'RackCommission', 'EconomyType', 'MealPlanType', 'SoldQty', 'BlockQty', 'NetInHandQty');
        $selectarrayInv = array('id', 'AccomSysId AS hotelId', 'PublishQty as DailyRoomLimit', 'RoomSysId as EconomyType', 'CONVERT(VARCHAR(24),FromDate,111) as FromDate', 'BlockQty', 'SoldQty', 'NetInHandQty');
        $supplarray = array('SupplierName');
        $curarray = array('Symbol as CurrencySymbol');
        $hotelname = array('Title as hotelName', 'ICSourceSysId', 'ContSysId');
        $cityarray = array('CityId', 'Title as City_title');
        $countryarray = array('ContId', 'Title as country_title');
        $select->from(array('tb1' => "Tb_MP_Accomdation_Room_Inventory"), $selectarrayInv);
        $select->joinLeft(array('tb11' => "TB_MP_Inventory_Accom"), "tb1.id = tb11.RoomInventorySysId", array('*'));
        //$select->from(array('tb1' => "TB_MP_Inventory_Accom"), $selectarray);
        $select->joinLeft(array('tb2' => "TB_IC_Supplier"), "tb1.SupplierSysId = tb2.SupplierSysId", $supplarray);
        $select->joinLeft(array('tb3' => "TB_Master_Currency"), "tb11.TrxCurrency = tb3.CurrencyType", $curarray);
        $select->joinLeft(array('tb4' => "TB_IC_Accomdation"), "tb1.AccomSysId = tb4.AccomSysId", $hotelname);
        $select->joinLeft(array('tb5' => "TB_Master_Geo_City"), "tb4.CitySysId = tb5.CityId", $cityarray);
        $select->joinLeft(array('tb6' => "TB_Master_Geo_Country"), "tb4.ContSysId = tb6.ContId", $countryarray);
        $select->where("tb1.AgencySysId =?", $intLoggedinUserAgencySysId);
        $select->where("tb1.IsMarkForDelete =?", 0);
        $select->where("tb11.IsMarkForDelete =?", 0);
        if (isset($post['DestinationId']) && $post['DestinationId'] > 0) {
            $select->where("tb4.CitySysId =?", $post['DestinationId']);
        }
        if (isset($post['hotelId']) && $post['hotelId'] > 0) {
            $select->where("tb1.AccomSysId =?", $post['hotelId']);
        }
        if (isset($post['rating']) && $post['rating'] > 0) {
            $select->where("tb4.Stars =?", $post['rating']);
        }
        if (isset($this->searchHotelinv['hotelId']) && $this->searchHotelinv['hotelId'] > 0) {
            $select->where("tb1.AccomSysId =?", $this->searchHotelinv['hotelId']);
        }
        if (isset($this->searchHotelinv['EconomyType']) && $this->searchHotelinv['EconomyType'] > 0) {
            $select->where("tb1.RoomSysId =?", $this->searchHotelinv['EconomyType']);
        }
        if (isset($this->searchHotelinv['FromDate']) && !empty($this->searchHotelinv['FromDate']) && isset($this->searchHotelinv['ToDate']) && !empty($this->searchHotelinv['ToDate'])) {
            $select->where("tb1.FromDate between '" . $this->searchHotelinv['FromDate'] . "' AND '" . $this->searchHotelinv['ToDate'] . "'");
        }

        if (isset($this->searchHotelinv['OrderBy']) && !empty($this->searchHotelinv['OrderBy'])) {
            $select->order(array($this->searchHotelinv['OrderBy']));
        } else {
            $select->order(array('tb1.CreateDate DESC'));
        }

        // $result = $this->db->fetchAll($select);
        //echo '<pre>';print_r($post);echo '</pre>';
        //return $select;
        //        $sql = " SELECT TB_MP_Inventory_Accom.XRefAccoSysId AS hotelId,TB_MP_Inventory_Accom.XRateSessionKey,TB_MP_Inventory_Accom.SupplierSysId,CONVERT(VARCHAR(24),TB_MP_Inventory_Accom.FromDate,111) as FromDate,CONVERT(VARCHAR(24),TB_MP_Inventory_Accom.ToDate,111) as ToDate,CONVERT(VARCHAR(24),TB_MP_Inventory_Accom.CreateDate,120) as CreateDate,TB_IC_Supplier.SupplierName,TB_IC_Accomdation.CitySysId,TB_IC_Accomdation.ContSysId,TB_IC_Accomdation.ICSourceSysId,TB_IC_Accomdation.Title,TB_Master_Geo_City.Title as City_title,TB_Master_Geo_Country.Title as country_title
        //            FROM TB_MP_Inventory_Accom 
        //            INNER JOIN  TB_IC_Accomdation ON TB_MP_Inventory_Accom.XRefAccoSysId = TB_IC_Accomdation.AccomSysId
        //            INNER JOIN  TB_Master_Geo_City ON TB_IC_Accomdation.CitySysId = TB_Master_Geo_City.CityId
        //            INNER JOIN  TB_Master_Geo_Country ON TB_IC_Accomdation.ContSysId = TB_Master_Geo_Country.ContId
        //            INNER JOIN  TB_IC_Supplier ON TB_MP_Inventory_Accom.SupplierSysId = TB_IC_Supplier.SupplierSysId
        //            WHERE 1=1  ";
        //        if(!empty($intLoggedinUserAgencySysId)) {
        //            $sql .=" AND TB_MP_Inventory_Accom.AgencySysId = " . $intLoggedinUserAgencySysId;
        //        }
        //        if (isset($post['hotelId']) && $post['hotelId'] > 0) {
        //            $sql .=" AND TB_MP_Inventory_Accom.XRefAccoSysId = " . $post['hotelId'];
        //        }
        //        if (isset($post['DestinationId']) && $post['DestinationId'] > 0) {
        //            $sql .=" AND TB_IC_Accomdation.CitySysId = " . $post['DestinationId'];
        //        }
        //        $sql .= " AND TB_MP_Inventory_Accom.IsMarkForDelete = '0' ";
        //        $sql .= " ORDER BY TB_MP_Inventory_Accom.CreateDate DESC";
        //        $result2 = $this->db->query($sql)->fetchAll();
        //        echo $select;die;
        //         $result = $this->db->fetchAll($select);
        //         echo "<pre>";print_r($result);die;
        return $select;
    }

    public function HotelrateCardByAgListNew($intLoggedinUserAgencySysId, $getData = array()) {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $post = $request->getPost();
        if (empty($post)) {
            $post = $getData;
        }
        $my_arr = array();
        $result = array();
        $rowFromDate = array();
        if ($request->isPost() || !empty($post)) {
            $strFromDate = Zend_Controller_Action_HelperBroker::getStaticHelper('DateFormat')->cal2Db($post['fromdate'], 'd-m-y');
            $strToDate = Zend_Controller_Action_HelperBroker::getStaticHelper('DateFormat')->cal2Db($post['todate'], 'd-m-y');
            $select = $this->db->select();
            $selectarray = array('InvnItemSysId', 'XRefItemSysId', 'XRefAccoSysId', 'AgencySysId', 'InfantAgeLimit', 'XRateSessionKey', 'CONVERT(VARCHAR(24),FromDate,111) as FromDate', 'CONVERT(VARCHAR(24),ToDate,111) as ToDate', 'CostCurrency', 'RateType', 'RackCommissionType', 'RackCommission', 'SupplierSysId', 'EconomyType', 'MealPlanType', 'CreateDate', 'DailyRoomLimit', 'SOccupCost', 'NetSOccupCost', 'SOWeekendCost', 'NetSOWeekendCost', 'DOccupCost', 'NetDOccupCost', 'DOWeekendCost', 'NetDOWeekendCost', 'TriOccupCost', 'NetTriOccupCost', 'TriWeekendCost', 'NetTriWeekendCost', 'WeekendDefine', 'BlockQty', 'IsActive');
            $selectarrayInv = array('id', 'PublishQty as DailyRoomLimit', 'RoomSysId as EconomyType', 'CONVERT(VARCHAR(24),FromDate,111) as FromDate', 'CONVERT(VARCHAR,FromDate,23) as mFromDate', 'IsSaleStart', 'NetInHandQty', 'SoldQty', 'BlockQty', 'PublishQty', 'AccomSysId');
            $supplarray = array('SupplierName');
            $curarray = array('Symbol as CurrencySymbol');
            $hotelname = array('Title as hotelName', 'ICSourceSysId');
            $cityarray = array('CityId', 'Title as City_title');
            $select->from(array('tb1' => "Tb_MP_Accomdation_Room_Inventory"), $selectarrayInv);
            $select->joinLeft(array('tb11' => "TB_MP_Inventory_Accom"), "tb1.id = tb11.RoomInventorySysId", array('*'));
            $select->joinLeft(array('tb2' => "TB_IC_Supplier"), "tb1.SupplierSysId = tb2.SupplierSysId", $supplarray);
            $select->joinLeft(array('tb3' => "TB_Master_Currency"), "tb11.TrxCurrency = tb3.CurrencyType", $curarray);
            $select->joinLeft(array('tb4' => "TB_IC_Accomdation"), "tb1.AccomSysId = tb4.AccomSysId", $hotelname);
            $select->joinLeft(array('tb5' => "TB_Master_Geo_City"), "tb4.CitySysId = tb5.CityId", $cityarray);
            $select->where("tb1.AgencySysId =?", $intLoggedinUserAgencySysId);
            if ((int) $post['hotel_id'] > 0) {
                $select->where("tb1.AccomSysId =?", $post['hotel_id']);
            }
            if ((int) $post['room_type'] > 0) {
                $select->where("tb1.RoomSysId =?", $post['room_type']);
            }
            if ((int) $post['SupplierSysId'] > 0) {
                $select->where("tb1.SupplierSysId =?", $post['SupplierSysId']);
            }
            $select->where("tb1.IsMarkForDelete =?", 0);
            $select->where("tb11.IsMarkForDelete =?", 0);
            if (isset($post['fromdate']) && $post['fromdate'] > 0) {
                $fromdate = date('Y-m-d', strtotime($strFromDate));
                $select->where("tb1.FromDate >= ?", $fromdate);
            }
            if (isset($post['todate']) && $post['todate'] > 0) {
                $todate = date('Y-m-d', strtotime($strToDate));
                $select->where("tb1.FromDate <= ?", $todate);
            }
            if (isset($post['rating']) && $post['rating'] > 0) {
                $select->where("tb4.Stars =?", $post['rating']);
            }
            $select->order(array('tb1.FromDate ASC'));
            //            echo $select;die;
            $datewiseArray = array();
            $result = $this->db->fetchAll($select);
            if ($result) {
                foreach ($result as $index => $row) {
                    if (isset($getData['show_room_name']) && $getData['show_room_name'] == True) {
                        $MealPlanType = Zend_Controller_Action_HelperBroker::getStaticHelper('Hotel')->getMealName($row['MealPlanType']);
                        $roomtype = Zend_Controller_Action_HelperBroker::getStaticHelper('Hotel')->getRoomTypeWhereRate($row['EconomyType']);
                    } else {
                        $MealPlanType = $row['MealPlanType'];
                        $roomtype = $row['EconomyType'];
                    }
                    $roomtypeUnique = $roomtype . '(' . $MealPlanType . ')';
                    $rowFromDate[] = $row['FromDate'];
                    $IsSaleStartArr[] = $row['IsSaleStart'];
                    $IsSaleStartRoomWiseArr[$row['EconomyType']] += $row['IsSaleStart'];
                    if ($post['ratetype'] == 1) {
                        $my_arr[$roomtypeUnique][] = array('SupplierSysId' => $row['SupplierSysId'], 'InvnItemSysId' => $row['InvnItemSysId'], 'XRefItemSysId' => $row['XRefItemSysId'], 'MealPlanType' => $row['MealPlanType'], 'EconomyType' => $row['EconomyType'], 'FromDate' => $row['FromDate'], 'pubrate' => $row['SOccupCost'], 'netrate' => $row['NetSOccupCost'], 'pubWeekend' => $row['SOWeekendCost'], 'netWeekend' => $row['NetSOWeekendCost'], 'WeekendDefine' => $row['WeekendDefine'], 'BlockQty' => $row['BlockQty'], 'IsActive' => $row['IsActive'], 'IsSaleStart' => $row['IsSaleStart'], 'id' => $row['id']);
                    }
                    if ($post['ratetype'] == 2) {
                        $my_arr[$roomtypeUnique][] = array('SupplierSysId' => $row['SupplierSysId'], 'InvnItemSysId' => $row['InvnItemSysId'], 'XRefItemSysId' => $row['XRefItemSysId'], 'MealPlanType' => $row['MealPlanType'], 'EconomyType' => $row['EconomyType'], 'FromDate' => $row['FromDate'], 'pubrate' => $row['DOccupCost'], 'netrate' => $row['NetDOccupCost'], 'pubWeekend' => $row['DOWeekendCost'], 'netWeekend' => $row['NetDOWeekendCost'], 'WeekendDefine' => $row['WeekendDefine'], 'BlockQty' => $row['BlockQty'], 'IsActive' => $row['IsActive'], 'IsSaleStart' => $row['IsSaleStart'], 'id' => $row['id']);
                    }
                    if ($post['ratetype'] == 3) {
                        $my_arr[$roomtypeUnique][] = array('SupplierSysId' => $row['SupplierSysId'], 'InvnItemSysId' => $row['InvnItemSysId'], 'XRefItemSysId' => $row['XRefItemSysId'], 'MealPlanType' => $row['MealPlanType'], 'EconomyType' => $row['EconomyType'], 'FromDate' => $row['FromDate'], 'pubrate' => $row['TriOccupCost'], 'netrate' => $row['NetTriOccupCost'], 'pubWeekend' => $row['TriWeekendCost'], 'netWeekend' => $row['NetTriWeekendCost'], 'WeekendDefine' => $row['WeekendDefine'], 'BlockQty' => $row['BlockQty'], 'IsActive' => $row['IsActive'], 'IsSaleStart' => $row['IsSaleStart'], 'id' => $row['id']);
                    }
                    $datewiseArray[$row['mFromDate']][$roomtype] = array(
                        'HotelName' => $row['hotelName'] . ' (' . $roomtype . ')',
                        'EconomyType' => $row['EconomyType'],
                        'FromDate' => $row['FromDate'],
                        'IsSaleStart' => $row['IsSaleStart'],
                        'BlockQty' => $row['BlockQty'],
                        'SoldQty' => $row['SoldQty'],
                        'NetInHandQty' => $row['NetInHandQty'],
                        'PublishQty' => $row['PublishQty'],
                        'AccomSysId' => $row['AccomSysId'],
                    );
                }
            }
        }
        $IsSaleStart = !empty($IsSaleStartArr) && (array_sum($IsSaleStartArr) > 0) ? 1 : 0;
        //        echo '<pre>';print_r($my_arr);echo '</pre>';die;
        $dataarray = array('my_arr' => $my_arr, 'rowFromDate' => array_unique($rowFromDate), 'IsSaleStart' => $IsSaleStart, 'IsSaleStartRoomWiseArr' => $IsSaleStartRoomWiseArr, 'InfantAgeLimit' => (isset($result[0]['InfantAgeLimit']) ? $result[0]['InfantAgeLimit'] : '0'), 'datewiseArray' => $datewiseArray);
        //echo '<pre>';print_r($dataarray);echo '</pre>';die;
        return $dataarray;
    }

    public function HotelrateCardCalculation($intLoggedinUserAgencySysId) {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $post = $request->getPost();
        //print_r($post);
        $my_arr = array();
        $result = array();
        $rowFromDate = array();
        if ($request->isPost()) {
            $select = $this->db->select();
            $selectarray = array('InvnItemSysId', 'XRefItemSysId', 'XRefAccoSysId', 'AgencySysId', 'XRateSessionKey', 'CONVERT(VARCHAR(24),FromDate,111) as FromDate', 'CONVERT(VARCHAR(24),ToDate,111) as ToDate', 'CostCurrency', 'RateType', 'RackCommissionType', 'RackCommission', 'SupplierSysId', 'EconomyType', 'MealPlanType', 'CreateDate', 'DailyRoomLimit', 'SOccupCost', 'NetSOccupCost', 'SOWeekendCost', 'NetSOWeekendCost', 'DOccupCost', 'NetDOccupCost', 'DOWeekendCost', 'NetDOWeekendCost', 'TriOccupCost', 'NetTriOccupCost', 'TriWeekendCost', 'NetTriWeekendCost', 'WeekendDefine', 'BlockQty', 'IsActive');
            $supplarray = array('SupplierName');
            $curarray = array('Symbol as CurrencySymbol');
            $hotelname = array('Title as hotelName', 'ICSourceSysId');
            $cityarray = array('CityId', 'Title as City_title');
            $select->from(array('tb1' => "TB_MP_Inventory_Accom"), $selectarray);
            $select->joinLeft(array('tb2' => "TB_IC_Supplier"), "tb1.SupplierSysId = tb2.SupplierSysId", $supplarray);
            $select->joinLeft(array('tb3' => "TB_Master_Currency"), "tb1.CostCurrency = tb3.CurrencyType", $curarray);
            $select->joinLeft(array('tb4' => "TB_IC_Accomdation"), "tb1.XRefAccoSysId = tb4.AccomSysId", $hotelname);
            $select->joinLeft(array('tb5' => "TB_Master_Geo_City"), "tb4.CitySysId = tb5.CityId", $cityarray);
            $select->where("tb1.AgencySysId =?", $intLoggedinUserAgencySysId);
            //$select->where("tb1.XRefAccoSysId =?", $post['hotel_id']);
            $select->where("tb1.IsMarkForDelete =?", 0);

            if (isset($post['fromdate']) && $post['fromdate'] > 0) {
                $fromdate = date('Y-m-d', strtotime($post['fromdate']));
                $select->where("tb1.FromDate >= ?", $fromdate);
            }
            if (isset($post['todate']) && $post['todate'] > 0) {
                $todate = date('Y-m-d', strtotime($post['todate']));
                $select->where("tb1.FromDate <= ?", $todate);
            }
            if (isset($post['rating']) && $post['rating'] > 0) {
                $select->where("tb4.Stars =?", $post['rating']);
            }
            $select->order(array('tb1.FromDate ASC'));
            $result = $this->db->fetchAll($select);
            $data = array();
            $data2 = array();
            foreach ($result as $index => $row) {
                $data[$row['XRefAccoSysId']][] = $row;
            }
            foreach ($data as $hotel => $rows) {
                foreach ($rows as $in => $rowss) {
                    $MealPlanType = Zend_Controller_Action_HelperBroker::getStaticHelper('Hotel')->getMealName($rowss['MealPlanType']);
                    $roomtype = Zend_Controller_Action_HelperBroker::getStaticHelper('Hotel')->getRoomTypeWhereRate($rowss['EconomyType']);
                    $roomtypeUnique = $roomtype . '(' . $MealPlanType . ')';
                    $data2[$hotel][$roomtypeUnique][] = $rowss;
                }
            }

            if ($data2) {
                foreach ($data2 as $hotelId => $val) {
                    echo '<hr>' . $hotelId . '<br>';
                    if ($val) {
                        foreach ($val as $Room => $value) {
                            $SOccupCost = 0;
                            $DOccupCost = 0;
                            $TriOccupCost = 0;
                            $NetSOccupCost = 0;
                            $NetDOccupCost = 0;
                            $NetTriOccupCost = 0;
                            foreach ($value as $k => $values) {
                                $SOccupCost += $values['SOccupCost'];
                                $DOccupCost += $values['DOccupCost'];
                                $TriOccupCost += $values['TriOccupCost'];
                                $NetSOccupCost += $values['NetSOccupCost'];
                                $NetDOccupCost += $values['NetDOccupCost'];
                                $NetTriOccupCost += $values['NetTriOccupCost'];
                            }
                            echo $Room . ' Single=' . $NetSOccupCost . ' Double=' . $NetDOccupCost . ' Triple=' . $NetTriOccupCost . '<br>';
                            //echo '<pre>';print_r($SOccupCost);echo '</pre>';
                        }
                    }
                }
            }
            echo '<pre>';
            print_r($data2);
            echo '</pre>';
            die;
        }

        //echo '<pre>';print_r($my_arr);echo '</pre>';die;
        //$dataarray = array('my_arr'=>$my_arr,'rowFromDate'=>array_unique($rowFromDate),'IsSaleStart'=>isset($result[0]['IsSaleStart'])?$result[0]['IsSaleStart']:'0');
        //return $dataarray;
    }

    public function UpdateMealPlan($MealPlanType) {
        $select = $this->db->select('*');
        $select->from(array('tb1' => "TB_MP_Inventory_Accom"));
        $select->where("tb1.MealPlanType =?", $MealPlanType);
        $select->where("tb1.IsMarkForDelete =?", 0);
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function UpdateXRateSessionKey() {
        $select = $this->db->select();
        $array = array('DISTINCT(FromDate)', 'XRateSessionKey');
        $select->from(array('tb1' => "TB_MP_Inventory_Accom"), $array);
        $select->where("tb1.IsMarkForDelete =?", 0);
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function UpdateXRefItemSysId($intLoggedinUserAgencySysId) {
        $select = $this->db->select();
        $selectarray = array('DISTINCT(EconomyType)');
        $select->from(array('tb1' => "TB_MP_Inventory_Accom"), $selectarray);
        $select->where("tb1.IsMarkForDelete =?", 0);
        $select->where("tb1.XRefItemSysId =?", 0);
        //$select->where("tb1.AgencySysId =?", $intLoggedinUserAgencySysId);
        $result = $this->db->fetchAll($select);
        /* if($result){
          foreach ($result as $key => $value) {
          $XRefAccoSysId[] = $value['XRefAccoSysId'];
          }
          } */
        return $result;
    }

    public function TB_IC_Accomdation_Room($XRefAccoSysId, $intLoggedinUserAgencySysId) {
        $select = $this->db->select();
        $selectarray = array('DISTINCT(AccomSysId)', 'ItemSysId');
        $select->from(array('tb1' => "TB_IC_Accomdation_Room"), $selectarray);
        $select->where('tb1.AccomSysId IN(?)', $XRefAccoSysId);
        $select->where("tb1.SourceSysId =?", $intLoggedinUserAgencySysId);
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function HotelRateDeBySessionKey($hotel_id, $intLoggedinUserAgencySysId, $SessionKey) {
        $select = $this->db->select();
        $selectarrayInv = array('id', 'AccomSysId', 'AgencySysId', 'XRateSessionKey', 'CONVERT(VARCHAR(24),FromDate,103) as FromDate', 'CONVERT(VARCHAR(24),Todate,103) as ToDate', 'RoomSysId as EconomyType', 'SupplierSysId');
        $supplarray = array('SupplierName');
        $curarray = array('Symbol as CurrencySymbol');
        //$select->from(array('tb1' => "TB_MP_Inventory_Accom"), $selectarray);
        $select->from(array('tb1' => "Tb_MP_Accomdation_Room_Inventory"), $selectarrayInv);
        $select->joinLeft(array('tb11' => "TB_MP_Inventory_Accom"), "tb1.id = tb11.RoomInventorySysId", array('*'));
        $select->joinLeft(array('tb2' => "TB_IC_Supplier"), "tb1.SupplierSysId = tb2.SupplierSysId", $supplarray);
        $select->joinLeft(array('tb3' => "TB_Master_Currency"), "tb11.TrxCurrency = tb3.CurrencyType", $curarray);
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->where("tb1.AgencySysId =?", $intLoggedinUserAgencySysId);
        $select->where("tb1.IsMarkForDelete =?", 0);
        $select->where("tb11.IsMarkForDelete =?", 0);
        $select->where("tb1.XRateSessionKey =?", $SessionKey);
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function HotelRateDeByInvnItemSysId($hotel_id, $intLoggedinUserAgencySysId, $InvnItemSysId) {
        $select = $this->db->select();
        $selectarray = array('InvnItemSysId', 'XRefAccoSysId', 'AgencySysId', 'XRefItemSysId', 'XRateSessionKey', 'CONVERT(VARCHAR(24),FromDate,103) as FromDate', 'CONVERT(VARCHAR(24),ToDate,103) as ToDate', 'MealPlanType', 'EconomyType', 'CostCurrency', 'RateType', 'RackCommissionType', 'RackCommission', 'SupplierSysId', 'SOccupCost', 'NetSOccupCost', 'DOccupCost', 'NetDOccupCost', 'TriOccupCost', 'NetTriOccupCost', 'ExtraBedCost', 'NetExtraBedCost', 'ExtraWOBedCost', 'NetExtraWOBedCost', 'PublishQty', 'NetExtraBedWeekendCost', 'NetExtraWOBedWeekendCost', 'NetTriWeekendCost', 'NetDOWeekendCost', 'NetSOWeekendCost', 'ExtraBedWeekendCost', 'ExtraWOBedWeekendCost', 'TriWeekendCost', 'DOWeekendCost', 'SOWeekendCost', 'ChildAgeLimit', 'InfantAgeLimit', 'IsExtraMealAdultCost', 'IsExtraMealChildCost', 'DailyRoomLimit', 'WeekendDefine', 'BlockQty', 'IsActive', 'IsTaxOnTriOccupCost', 'IsTaxOnDOccupCost', 'IsTaxOnSOccupCost', 'IsTaxOnExtraBedCost', 'IsTaxOnExtraWOBedCost', 'TaxTriOccupCost', 'TaxDOccupCost', 'TaxSOccupCost', 'TaxExtraBedCost', 'TaxExtraWOBedCost');
        $supplarray = array('SupplierName');
        $curarray = array('Symbol as CurrencySymbol');
        $selectarrayInv = array('IsSaleStart', 'id', 'PublishQty as DailyRoomLimit', 'RoomSysId as EconomyType', 'CONVERT(VARCHAR(24),FromDate,111) as FromDate');
        $select->from(array('tb1' => "Tb_MP_Accomdation_Room_Inventory"), $selectarrayInv);
        $select->joinLeft(array('tb11' => "TB_MP_Inventory_Accom"), "tb1.id = tb11.RoomInventorySysId", array('*'));
        $select->joinLeft(array('tb2' => "TB_IC_Supplier"), "tb1.SupplierSysId = tb2.SupplierSysId", $supplarray);
        $select->joinLeft(array('tb3' => "TB_Master_Currency"), "tb11.TrxCurrency = tb3.CurrencyType", $curarray);
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->where("tb1.AgencySysId =?", $intLoggedinUserAgencySysId);
        $select->where("tb1.IsMarkForDelete =?", 0);
        $select->where("tb11.IsMarkForDelete =?", 0);
        $select->where("tb11.InvnItemSysId =?", $InvnItemSysId);

        $result = $this->db->fetchRow($select);
        return $result;
    }

    public function HotelRateListByRoomId($hotel_id, $intLoggedinUserAgencySysId, $RoomId, $SessionKey = '') {
        $select = $this->db->select();
        $selectarray = array('id', 'AccomSysId', 'AgencySysId', 'XRefItemSysId', 'CONVERT(VARCHAR(24),FromDate,103) as FromDate', 'MealPlanType', 'TrxCurrency', 'RateType', 'RackCommissionType', 'RackCommission', 'SupplierSysId', 'SOccupCost', 'NetSOccupCost', 'DOccupCost', 'NetDOccupCost', 'TriOccupCost', 'NetTriOccupCost', 'ExtraBedCost', 'NetExtraBedCost', 'ExtraWOBedCost', 'NetExtraWOBedCost', 'PublishQty', 'NetExtraBedWeekendCost', 'NetExtraWOBedWeekendCost', 'NetTriWeekendCost', 'NetDOWeekendCost', 'NetSOWeekendCost', 'ExtraBedWeekendCost', 'ExtraWOBedWeekendCost', 'TriWeekendCost', 'DOWeekendCost', 'SOWeekendCost', 'ChildAgeLimit', 'InfantAgeLimit', 'IsTaxOnTriOccupCost', 'IsTaxOnDOccupCost', 'IsTaxOnSOccupCost', 'IsTaxOnExtraBedCost', 'IsTaxOnExtraWOBedCost', 'IsExtraMealAdultCost', 'IsExtraMealChildCost', 'DailyRoomLimit');
        $selectarrayInv = array('id', 'PublishQty as DailyRoomLimit', 'BookingType', 'XRateSessionKey', 'FromDate');
        $supplarray = array('SupplierName');
        $curarray = array('Symbol as CurrencySymbol');
        $select->from(array('tb1' => "Tb_MP_Accomdation_Room_Inventory"), $selectarrayInv);
        $select->joinLeft(array('tb11' => "TB_MP_Inventory_Accom"), "tb1.id = tb11.RoomInventorySysId", array('*'));
        $select->joinLeft(array('tb2' => "TB_IC_Supplier"), "tb1.SupplierSysId = tb2.SupplierSysId", $supplarray);
        //$select->joinLeft(array('tb3' => "TB_Master_Currency"), "tb1.TrxCurrency = tb3.CurrencyType", $curarray);
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->where("tb1.AgencySysId =?", $intLoggedinUserAgencySysId);
        $select->where("tb1.IsMarkForDelete =?", 0);
        $select->where("tb11.IsMarkForDelete =?", 0);
        $select->where("tb1.XRefItemSysId =?", $RoomId);
        if (!empty($SessionKey)) {
            $select->where("tb1.XRateSessionKey =?", $SessionKey);
        }
        //        echo $select;die;
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function GetCurrency($hotel_id) {
        $select = $this->db->select();
        $selectarray = array('TrxCurrency');
        $curarray = array('Symbol as CurrencySymbol');
        $select->from(array('tb1' => "TB_MP_Inventory_Accom"), $selectarray);
        $select->joinLeft(array('tb3' => "TB_Master_Currency"), "tb1.TrxCurrency = tb3.CurrencyType", $curarray);
        $select->where("tb1.XRefAccoSysId =?", $hotel_id);
        $select->where("tb1.IsMarkForDelete =?", 0);
        $result = $this->db->fetchRow($select);
        return $result;
    }

    public function GetRateExist($hotel_id, $intLoggedinUserAgencySysId) {
        $select = $this->db->select();
        $hotelname = array('ICSourceSysId', 'ContSysId');
        $selectarray = array('id', 'AccomSysId', 'SupplierSysId', 'CONVERT(VARCHAR(24),FromDate,111) as FromDate');
        $select->from(array('tb1' => "Tb_MP_Accomdation_Room_Inventory"), $selectarray);
        $select->joinLeft(array('tb4' => "TB_IC_Accomdation"), "tb1.AccomSysId = tb4.AccomSysId", $hotelname);
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->where("tb1.AgencySysId =?", $intLoggedinUserAgencySysId);
        $select->where("tb1.IsMarkForDelete =?", 0);
        $result = $this->db->fetchRow($select);
        return $result;
    }

    public function getMaxXRateSessionKey() {
        if (function_exists('com_create_guid') === true) {
            return trim(com_create_guid(), '{}');
        }
        return sprintf('%04X%04X%04X%04X%04X%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));

        //        $select = $this->db->select()
        //            ->from(array('t' => 'TB_MP_Inventory_Accom'), array(new Zend_Db_Expr('MAX(InvnItemSysId) as InvnItemSysId')));
        //        $row = $this->db->fetchRow($select);
        //        if (!$row) {
        //            return false;
        //        } else {
        //            return $row['InvnItemSysId'];
        //        }
    }

    public function getMaxDate($hotel_id, $intLoggedinUserAgencySysId) {
        $select = $this->db->select()
                ->from(array('t' => 'Tb_MP_Accomdation_Room_Inventory'), array(new Zend_Db_Expr('MAX(FromDate) as MaxToDate')));
        $select->where("t.AccomSysId =?", $hotel_id);
        $select->where("t.AgencySysId =?", $intLoggedinUserAgencySysId);
        $row = $this->db->fetchRow($select);
        if (!$row) {
            return false;
        } else {
            return (array) $row['MaxToDate'];
        }
    }

    public function getMinDate($hotel_id, $intLoggedinUserAgencySysId, $SessionKey = 0) {
        $select = $this->db->select()
                ->from(array('t' => 'Tb_MP_Accomdation_Room_Inventory'), array(new Zend_Db_Expr('MIN(CONVERT(VARCHAR(24),FromDate,111)) as MinDate')));
        $select->where("t.AccomSysId =?", $hotel_id);
        $select->where("t.AgencySysId =?", $intLoggedinUserAgencySysId);
        if ($SessionKey > 0) {
            $select->where("t.XRateSessionKey =?", $SessionKey);
        }

        //        echo $select;die;
        $row = $this->db->fetchRow($select);
        if (!$row) {
            return false;
        } else {
            return $row['MinDate'];
        }
    }

    public function getMaximumDate($hotel_id, $XRateSessionKey, $intLoggedinUserAgencySysId) {
        $select = $this->db->select()
                ->from(array('t' => 'TB_MP_Inventory_Accom'), array(new Zend_Db_Expr('MAX(CONVERT(VARCHAR(24),FromDate,111)) as MaxDate')));
        $select->where("t.XRefAccoSysId =?", $hotel_id);
        $select->where("t.AgencySysId =?", $intLoggedinUserAgencySysId);
        $select->where("t.XRateSessionKey =?", $XRateSessionKey);
        $row = $this->db->fetchRow($select);

        if (!$row) {
            return false;
        } else {
            return $row['MaxDate'];
        }
    }

    public function getMaximumDateSession($hotel_id, $EconomyType, $MealPlanType, $SupplierSysId, $intLoggedinUserAgencySysId) {
        $select = $this->db->select()
                ->from(array('t' => 'TB_MP_Inventory_Accom'), array(new Zend_Db_Expr('MAX(CONVERT(VARCHAR(24),FromDate,111)) as MaxDate')));
        $select->where("t.XRefAccoSysId =?", $hotel_id);
        $select->where("t.AgencySysId =?", $intLoggedinUserAgencySysId);
        $select->where('t.EconomyType IN(?)', array(explode(',', $EconomyType)));
        $select->where("t.MealPlanType IN(?)", array(explode(',', $MealPlanType)));
        $select->where("t.SupplierSysId =?", $SupplierSysId);
        $row = $this->db->fetchRow($select);

        if (!$row) {
            return false;
        } else {
            return $row['MaxDate'];
        }
    }

    public function getMinimumDateSession($hotel_id, $EconomyType, $MealPlanType, $SupplierSysId, $intLoggedinUserAgencySysId) {
        $select = $this->db->select()
                ->from(array('t' => 'TB_MP_Inventory_Accom'), array(new Zend_Db_Expr('MIN(CONVERT(VARCHAR(24),FromDate,111)) as MinDate')));
        $select->where("t.XRefAccoSysId =?", $hotel_id);
        $select->where("t.AgencySysId =?", $intLoggedinUserAgencySysId);
        $select->where('t.EconomyType IN(?)', array(explode(',', $EconomyType)));
        $select->where("t.MealPlanType IN(?)", array(explode(',', $MealPlanType)));
        $select->where("t.SupplierSysId =?", $SupplierSysId);
        $row = $this->db->fetchRow($select);

        if (!$row) {
            return false;
        } else {
            return $row['MinDate'];
        }
    }

    public function CancellationList($hotel_id, $intLoggedinUserAgencySysId) {
        $select = $this->db->select();
        $selectarray = array('RoomCancelSysId', 'AgencySysId', 'ItemSysId', 'Accosysid', 'ChBeforeDays', 'ChargeType', 'Charge', 'Remarks', 'BookingTermCond', 'IsMarkForDel', 'IsActive', 'CreatedOn', 'roomindex');
        $roomarray = array('ItemSysId', 'RoomType');
        $room_masterarray = array('RoomType as RoomTypeId', 'Title as RoomType');
        $select->from(array('tb1' => "TB_IC_Accomdation_Room_CancellationPolicy"), $selectarray);
        $select->joinleft(array('tb3' => "TB_IC_Accomdation_Room"), "tb1.ItemSysId = tb3.ItemSysId", $roomarray);
        $select->joinleft(array('tb2' => "TB_Master_RoomType"), "tb3.RoomType = tb2.RoomType", $room_masterarray);
        $select->where("tb1.Accosysid =?", $hotel_id);
        $select->where("tb1.AgencySysId =?", $intLoggedinUserAgencySysId);
        $select->where("tb1.IsMarkForDel =?", 0);
        //$select->group(array('tb1.RoomCancelSysId','tb1.ItemSysId','tb1.AgencySysId','tb1.Accosysid','tb1.ChBeforeDays','tb1.ChargeType','tb1.Charge','tb1.Remarks','tb1.BookingTermCond','tb1.IsMarkForDel','tb1.IsActive','tb1.CreatedOn','tb2.RoomType','tb2.Title','tb3.ItemSysId','tb3.RoomType'));

        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function CancelDeByItemSysId($hotel_id, $intLoggedinUserAgencySysId, $ItemSysId) {
        $select = $this->db->select();
        $selectarray = array('RoomCancelSysId', 'AgencySysId', 'ItemSysId', 'Accosysid', 'ChBeforeDays', 'ChargeType', 'Charge', 'Remarks', 'BookingTermCond', 'IsMarkForDel', 'IsActive', 'CreatedOn');
        $roomarray = array('ItemSysId', 'RoomType');
        $room_masterarray = array('RoomType as RoomTypeId', 'Title as RoomType');

        $select->from(array('tb1' => "TB_IC_Accomdation_Room_CancellationPolicy"), $selectarray);
        $select->joinleft(array('tb3' => "TB_IC_Accomdation_Room"), "tb1.ItemSysId = tb3.ItemSysId", $roomarray);
        $select->joinleft(array('tb2' => "TB_Master_RoomType"), "tb3.RoomType = tb2.RoomType", $room_masterarray);
        $select->where("tb1.Accosysid =?", $hotel_id);
        $select->where("tb1.ItemSysId =?", $ItemSysId);
        $select->where("tb1.AgencySysId =?", $intLoggedinUserAgencySysId);
        $select->where("tb1.IsMarkForDel =?", 0);
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function CancelSubDeByItemSysId($hotel_id, $intLoggedinUserAgencySysId, $ItemSysId) {
        $select = $this->db->select();
        $selectarray = array('RoomCancelSysId', 'AgencySysId', 'ItemSysId', 'Accosysid', 'ChBeforeDays', 'ChargeType', 'Charge', 'Remarks', 'BookingTermCond', 'IsMarkForDel', 'IsActive', 'CreatedOn');
        $roomarray = array('ItemSysId', 'RoomType');
        $room_masterarray = array('RoomType as RoomTypeId', 'Title as RoomType');

        $select->from(array('tb1' => "TB_IC_Accomdation_Room_CancellationPolicy"), $selectarray);
        $select->joinleft(array('tb3' => "TB_IC_Accomdation_Room"), "tb1.ItemSysId = tb3.ItemSysId", $roomarray);
        $select->joinleft(array('tb2' => "TB_Master_RoomType"), "tb3.RoomType = tb2.RoomType", $room_masterarray);
        $select->where("tb1.Accosysid =?", $hotel_id);
        $select->where("tb1.roomindex =?", $ItemSysId);
        $select->where("tb1.AgencySysId =?", $intLoggedinUserAgencySysId);
        $select->where("tb1.IsMarkForDel =?", 0);
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function CancelDeByItemSysIdWithSubItem($hotel_id, $intLoggedinUserAgencySysId, $ItemSysId) {
        $select = $this->db->select();
        $selectarray = array('RoomCancelSysId', 'AgencySysId', 'ItemSysId', 'Accosysid', 'ChBeforeDays', 'ChargeType', 'Charge', 'Remarks', 'BookingTermCond', 'IsMarkForDel', 'IsActive', 'CreatedOn');
        $roomarray = array('ItemSysId', 'RoomType');
        $room_masterarray = array('RoomType as RoomTypeId', 'Title as RoomType');

        $select->from(array('tb1' => "TB_IC_Accomdation_Room_CancellationPolicy"), $selectarray);
        $select->joinleft(array('tb11' => "TB_IC_Accomdation_Room_CancellationPolicy"), "tb1.ItemSysId = tb11.roomindex", array('ItemSysId as SubItemSysId'));
        $select->joinleft(array('tb3' => "TB_IC_Accomdation_Room"), "tb1.ItemSysId = tb3.ItemSysId", $roomarray);
        $select->joinleft(array('tb2' => "TB_Master_RoomType"), "tb3.RoomType = tb2.RoomType", $room_masterarray);
        $select->joinleft(array('tb31' => "TB_IC_Accomdation_Room"), "tb11.ItemSysId = tb31.ItemSysId", array('RoomType as SubRoomType'));
        $select->joinleft(array('tb21' => "TB_Master_RoomType"), "tb31.RoomType = tb21.RoomType", array('RoomType as SubRoomTypeId', 'Title as SubRoomType'));

        $select->where("tb1.Accosysid =?", $hotel_id);
        $select->where("tb1.ItemSysId =?", $ItemSysId);
        $select->where("tb1.AgencySysId =?", $intLoggedinUserAgencySysId);
        $select->where("tb1.IsMarkForDel =?", 0);
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function getUserList() {
        $select = $this->db->select()
                ->from("SabirTest");
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function addSabirTesting() {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        if ($request->isPost()) {
            try {
                $data = $request->getPost();
                $insert = array(
                    'FirstName' => isset($data['fname']) ? $data['fname'] : '',
                    'LastName' => isset($data['lname']) ? $data['lname'] : '',
                    'Age' => isset($data['age']) ? $data['age'] : '',
                );
                $this->db->insert('SabirTest', $insert);
                return true;
            } catch (Exception $ex) {
                $this->db->rollBack();
                die($ex->getMessage());
            }
        }
    }

    public function HotelrateCardListLastDate($hotel_id, $intLoggedinUserAgencySysId, $SessionKey = '') {
        $select = $this->db->select();
        $selectarray = array('XRefAccoSysId', 'AgencySysId', 'TrxCurrency', 'RateType', 'RackCommissionType', 'RackCommission', 'SupplierSysId', 'MealPlanType', 'WeekendDefine');
        $selectAccomInventory = array('FromDate', 'AccomSysId', 'RoomSysId', 'Todate');
        $supplarray = array('SupplierName');
        $curarray = array('Symbol as CurrencySymbol');
        $hotelname = array('Title as hotelName');
        $select->from(array('tb1' => "Tb_MP_Accomdation_Room_Inventory"), $selectAccomInventory);
        $select->joinLeft(array('tb11' => "TB_MP_Inventory_Accom"), "tb1.id = tb11.RoomInventorySysId", array('*'));
        $select->joinLeft(array('tb2' => "TB_IC_Supplier"), "tb1.SupplierSysId = tb2.SupplierSysId", $supplarray);
        $select->joinLeft(array('tb3' => "TB_Master_Currency"), "tb11.TrxCurrency = tb3.CurrencyType", $curarray);
        $select->joinLeft(array('tb4' => "TB_IC_Accomdation"), "tb1.AccomSysId = tb4.AccomSysId", $hotelname);
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->where("tb1.AgencySysId =?", $intLoggedinUserAgencySysId);
        if ($SessionKey > 0) {
            $select->where("tb1.XRateSessionKey =?", $SessionKey);
        }

        $select->where("tb1.IsMarkForDelete =?", 0);
        $select->where("tb11.IsMarkForDelete =?", 0);
        $select->order(array('tb1.FromDate DESC'));
        //$select->group(array('tb1.XRefAccoSysId','tb1.XRateSessionKey','tb1.AgencySysId','tb1.FromDate','tb1.ToDate','tb1.CostCurrency','tb1.RateType','tb1.RackCommissionType','tb1.RackCommission','tb1.SupplierSysId','tb2.SupplierName','tb3.Symbol','tb4.Title'));
        //$select->group(array('tb1.XRateSessionKey'));
//                echo $select;die;
        $result = $this->db->fetchRow($select);
        return $result;
    }

    public function HotelBedTypeDetails() {
        $select = $this->db->select();
        $selectarray = array('*');
        $select->from(array('tb1' => "TB_Master_BedType"), $selectarray);
        $select->where("tb1.IsMarkForDel =?", '0');
        $select->where("tb1.IsActive =?", '1');
        $select->order(array('tb1.BedType ASC'));
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function HotelRoomViewDetails() {
        $select = $this->db->select();
        $selectarray = array('*');
        $select->from(array('tb1' => "TB_Master_RoomView"), $selectarray);
        $select->where("tb1.IsMarkForDel =?", '0');
        $select->where("tb1.IsActive =?", '1');
        $select->order(array('tb1.RoomViewId ASC'));
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function runmyquery() {
        $getMaxXRateSessionKey = $this->getMaxXRateSessionKey();
        $objPackage = new Travel_Model_TblPackage();
        $select = $this->db->select();
        $selectarray = array('*');
        $select->from(array('tb1' => "TB_MP_Inventory_Accom__________________22062022"), $selectarray);
        $select->where("tb1.XRefAccoSysId =?", '476773');
        $select->where("tb1.IsMarkForDelete =?", '0');
        $select->order(array('tb1.InvnItemSysId ASC'));
        $result = $this->db->fetchAll($select);
        die('stop');
        $resultArray = array();
        foreach ($result as $key => $value) {
            $resultArray[$value['FromDate']->format('Y-m-d')][$value['EconomyType']][] = $value;
        }
        //echo "<pre>";print_r($resultArray);die;
        foreach ($resultArray as $key1 => $value1) {
            foreach ($value1 as $key2 => $value2) {
                $insertRoomInventory = [
                    'AccomSysId' => (int) $value2[0]['XRefAccoSysId'],
                    'AgencySysId' => (int) $value2[0]['AgencySysId'],
                    'RoomSysId' => (int) $value2[0]['EconomyType'],
                    'SupplierSysId' => (int) $value2[0]['SupplierSysId'],
                    'FromDate' => $value2[0]['FromDate']->format('Y-m-d H:i'),
                    'PublishQty' => (int) $value2[0]['PublishQty'],
                    'BlockQty' => (int) $value2[0]['BlockQty'],
                    'SoldQty' => (int) $value2[0]['SoldQty'],
                    'NetInHandQty' => (int) $value2[0]['NetInHandQty'],
                    'UpdatedDate' => $value2[0]['UpdateDate']->format('Y-m-d H:i'),
                    'CreatedDate' => $value2[0]['CreateDate']->format('Y-m-d H:i'),
                    'IsActive' => (int) $value2[0]['IsActive'],
                    'IsMarkForDelete' => (int) $value2[0]['IsMarkForDelete'],
                    'XRefItemSysId' => (int) $value2[0]['XRefItemSysId'],
                    'IsSaleStart' => (int) $value2[0]['IsSaleStart'],
                    'XRateSessionKey' => $getMaxXRateSessionKey,
                    'Todate' => $value2[0]['ToDate']->format('Y-m-d H:i')
                ];
                $id = $objPackage->insertData('Tb_MP_Accomdation_Room_Inventory', $insertRoomInventory);
                foreach ($value2 as $key3 => $value3) {
                    $insertInventoryAccom = [
                        'AgencySysId' => (int) $value3['AgencySysId'],
                        'WeekendDefine' => $value3['WeekendDefine'],
                        'MealPlanType' => (int) $value3['MealPlanType'],
                        'MarkType' => 1,
                        'B2CMarkup' => 0,
                        'B2BMarkup' => 0,
                        'SOccupCost' => (float) $value3['SOccupCost'],
                        'NetSOccupCost' => (float) $value3['NetSOccupCost'],
                        'IsTaxOnSOccupCost' => (int) $value3['IsTaxOnSOccupCost'],
                        'TaxSOccupCost' => (float) $value3['TaxSOccupCost'],
                        'DOccupCost' => (float) $value3['DOccupCost'],
                        'NetDOccupCost' => (float) $value3['NetDOccupCost'],
                        'IsTaxOnDOccupCost' => (int) $value3['IsTaxOnDOccupCost'],
                        'TaxDOccupCost' => (float) $value3['TaxDOccupCost'],
                        'ExtraBedCost' => (float) $value3['ExtraBedCost'],
                        'NetExtraBedCost' => (float) $value3['NetExtraBedCost'],
                        'IsTaxOnExtraBedCost' => (int) $value3['IsTaxOnExtraBedCost'],
                        'TaxExtraBedCost' => (float) $value3['TaxExtraBedCost'],
                        'TriOccupCost' => (float) $value3['TriOccupCost'],
                        'NetTriOccupCost' => (float) $value3['NetTriOccupCost'],
                        'IsTaxOnTriOccupCost' => (int) $value3['IsTaxOnTriOccupCost'],
                        'TaxTriOccupCost' => (float) $value3['TaxTriOccupCost'],
                        'ChildAgeLimit' => $value3['ChildAgeLimit'],
                        'ExtraWOBedCost' => $value3['ExtraWOBedCost'],
                        'NetExtraWOBedCost' => $value3['NetExtraWOBedCost'],
                        'IsTaxOnExtraWOBedCost' => (int) $value3['IsTaxOnExtraWOBedCost'],
                        'TaxExtraWOBedCost' => $value3['TaxExtraWOBedCost'],
                        'RateType' => $value3['RateType'] == 'NR' ? 1 : 0,
                        'RackCommissionType' => (int) $value3['RackCommissionType'],
                        'RackCommission' => (float) $value3['RackCommission'],
                        'UpdatedDate' => $value3['UpdateDate']->format('Y-m-d H:i'),
                        'CreatedDate' => $value3['CreateDate']->format('Y-m-d H:i'),
                        'IsActive' => $value3['IsActive'],
                        'IsMarkForDelete' => $value3['IsMarkForDelete'],
                        'XRefAccoSysId' => (int) $value3['XRefAccoSysId'],
                        'RoomInventorySysId' => $id,
                        'XRefItemSysId' => (int) $value3['XRefItemSysId'],
                        'TrxCurrency' => (int) $value3['CostCurrency'],
                        'SupplierSysId' => (int) $value3['SupplierSysId'],
                    ];
                    //                    echo "<pre>";print_r($insertInventoryAccom);die;
                    $objPackage->insertData('TB_MP_Inventory_Accom', $insertInventoryAccom);
                }
            }
        }
        echo "done";
        die;
    }

    public function getRoomInventoryIds($hotel_id, $SessionKey, $XRefItemSysId = 0) {
        $select = $this->db->select()
                ->from(array('t' => 'Tb_MP_Accomdation_Room_Inventory'), array('id'));
        $select->where("t.AccomSysId =?", $hotel_id);
        $select->where("t.XRateSessionKey =?", $SessionKey);
        if ($XRefItemSysId > 0) {
            $select->where("t.XRefItemSysId =?", $XRefItemSysId);
        }
        $row = $this->db->fetchAll($select);
        return $row;
    }

    public function getCityAutoSuggest($where) {

        $where = trim($where);
        $response = array();
        $arrCity = array('CityId', 'Title as cityTitle', 'Alias as cityAlias', 'ContSysId');
        $select = $this->db->select();
        $select->from(array('tbl' => "TB_Master_Geo_City"), $arrCity);
        $select->where($where);
        $select->where("tbl.IsActive = ?", 1);
        $select->where("tbl.IsApproved = ?", 1);
        $result = $this->db->fetchAll($select);

        if (count($result) > 0) {
            foreach ($result as $row) {
                $response[] = array('cityTitle' => $row['cityTitle'], 'CityId' => $row['CityId'], 'label' => $row['cityTitle']);
            }
        }
        return $response;
    }

    public function getAccommodationRoomType($where) {

        $where = trim($where);
        $response = array();
        $arrCity = array('RoomType');
        $select = $this->db->select();
        $select->from(array('tbl' => "TB_Master_RoomType"), $arrCity);
        $select->where("tbl.RoomType = ?", $where);
        $select->where("tbl.IsActive = ?", 1);
        $result = $this->db->fetchRow($select);

        if (count($result) > 0) {
            foreach ($result as $row) {
                $response[] = array('RoomType' => $row['RoomType']);
            }
        }
        return $response;
    }

    public function CheckHotelRoomMaster($hotel_id, $roomtype) {
        $select = $this->db->select()
                ->from(array('t' => 'TB_IC_Accomdation_Room'), array('ItemSysId'));
        $select->where("t.AccomSysId =?", $hotel_id);
        $select->where("t.RoomType =?", $roomtype);
        $row = $this->db->fetchRow($select);
        return $row;
    }

    public function mealPlanRates($hotel_id, $intLoggedinUserAgencySysId) {
        $selectarray = array('*');
        $select = $this->db->select()
                ->from(array('t' => 'Tb_Agency_Accom_Meal_Plan_Rate'), $selectarray);
        $select->where("t.AcoomSysId =?", $hotel_id);
        $select->where("t.AgencySysId =?", $intLoggedinUserAgencySysId);
        $select->where("t.IsActive =?", 1);
        $select->where("t.IsMarkForDelete =?", 0);
        $row = $this->db->fetchAll($select);
        return $row;
    }

    public function getpromotionList($hotel_id, $intLoggedinUserAgencySysId, $column = array(), $filterData = array(), $OnlyPropo = 0) {
        $selectarray = (!empty($column)) ? $column : array('*');
        $select = $this->db->select()
                ->from(array('t' => 'Tb_Agency_Accom_Promotions'), $selectarray);
        $select->joinLeft(array('t3' => "TB_IC_Accomdation_Room"), "t.RoomType = t3.RoomType AND t.AcoomSysId = t3.AccomSysId", array(''));
        $select->joinLeft(array('t2' => "TB_Master_RoomType"), "t3.RoomType = t2.RoomType", array('title'));
        $select->where("t.AcoomSysId =?", $hotel_id);
        $select->where("t.AgencySysId =?", $intLoggedinUserAgencySysId);
        if (isset($filterData['RoomType']) && !empty($filterData['RoomType'])) {
            $select->where("t.RoomType =?", (int) $filterData['RoomType']);
        }
        if (isset($filterData['MealType']) && !empty($filterData['MealType'])) {
            $select->where("t.MealType =?", (int) $filterData['MealType']);
        }
        if (isset($filterData['IsActive'])) {
            $select->where("t.IsActive =?", (int) $filterData['IsActive']);
        }
        if (isset($filterData['MinRoom']) && $filterData['MinRoom'] > 0) {
            $MinRoom = (int) $filterData['MinRoom'];
            $select->where("t.MinRoom <= $MinRoom OR IsMinRoom = 0");
        }
        if ($OnlyPropo == 1) {
            $select->where("t.PromotionType !=?", 3);
        }
        $select->where("t.IsMarkForDelete =?", 0);
//        echo $select;die;
        $row = $this->db->fetchAll($select);
        return $row;
    }

    public function checkPromotionInHotel($hotel_id, $intLoggedinUserAgencySysId, $OnlyPropo = 0) {
        $selectarray = array('AccomPromotionsSysId');
        $select = $this->db->select()
                ->from(array('t' => 'Tb_Agency_Accom_Promotions'), $selectarray);
        $select->where("t.AcoomSysId =?", $hotel_id);
        $select->where("t.AgencySysId =?", $intLoggedinUserAgencySysId);
        $select->where("t.IsMarkForDelete =?", 0);
        $select->where("t.IsActive =?", 1);
        if ($OnlyPropo == 1) {
            $select->where("t.PromotionType !=?", 3);
        }
        $row = $this->db->fetchRow($select);
        return $row;
    }

    public function getpromotionByID($promotion_id, $hotel_id, $intLoggedinUserAgencySysId) {
        $selectarray = array('*');
        $select = $this->db->select()
                ->from(array('t' => 'Tb_Agency_Accom_Promotions'), $selectarray);
        $select->where("t.AccomPromotionsSysId =?", $promotion_id);
        $select->orwhere("t.PromotionsSysId = ?", $promotion_id);
        $select->where("t.AcoomSysId =?", $hotel_id);
        $select->where("t.AgencySysId =?", $intLoggedinUserAgencySysId);
        $select->where("t.IsMarkForDelete =?", 0);
        $row = $this->db->fetchAll($select);
        return $row;
    }

    public function getPromotionRateType($promotion_id, $hotel_id, $intLoggedinUserAgencySysId) {
        $selectarray = array('FromDate', 'ToDate', 'RoomSysId');
        $select = $this->db->select();
        $select->from(array('tb1' => 'Tb_MP_Accomdation_Room_Inventory'), $selectarray);
        $select->joinInner(array('tb2' => "TB_MP_Inventory_Accom"), "tb1.id = tb2.RoomInventorySysId", array('*'));
        $select->joinLeft(array('tb3' => "TB_Master_RoomType"), "tb1.RoomSysId = tb3.RoomType", array("Title as RoomTitle"));
        $select->joinLeft(array('tb4' => "TB_Master_Accom_MealType"), "tb2.MealPlanType = tb4.MealTypeId", array("Title as MealPlanTitle"));
        $select->orwhere("tb1.PromotionsSysId = ?", $promotion_id);
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->where("tb1.AgencySysId =?", $intLoggedinUserAgencySysId);
        $select->where("tb1.IsMarkForDelete =?", 0);
        $select->where("tb2.IsMarkForDelete =?", 0);
        $select->order(array("tb2.InvnItemSysId ASC"));

        $row = $this->db->fetchAll($select);
        return $row;
    }

    public function getSuppliersbyAgent($intLoggedinUserId, $intLoggedinUserAgencySysId) {
        $sql = " SELECT distinct(TB_IC_Supplier.SupplierSysId), TB_IC_Supplier.SupplierName FROM TB_IC_Supplier "
                . " RIGHT JOIN TB_MP_Inventory_Accom ON TB_MP_Inventory_Accom.SupplierSysId=TB_IC_Supplier.SupplierSysId WHERE 1 =1 AND TB_IC_Supplier.IsDelete='0' ";

        if (!empty($intLoggedinUserAgencySysId)) {
            $sql .= " AND TB_IC_Supplier.XRefAgencySysId = " . $intLoggedinUserAgencySysId;
        }

        if (!empty($intLoggedinUserId)) {
            $sql .= " AND TB_IC_Supplier.AgentSysId = " . $intLoggedinUserId;
        }

        $sql .= " ORDER BY TB_IC_Supplier.SupplierName ";

        return $this->db->query($sql)->fetchAll();
    }

    public function getHotelRateType($hotel_id, $intLoggedinUserAgencySysId) {
        $select = $this->db->select();
        $selecthotelarray = array('AccomSysId', 'RateType', 'HotelRateType', 'CurrencyType', 'SupplierSysId', 'WeekendDefine', 'NetRateType', 'RackCommission');
        $select->from(array('tb1' => "TB_IC_Accomdation"), $selecthotelarray);
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->where("tb1.ICSourceSysId =?", $intLoggedinUserAgencySysId);
        $result = $this->db->fetchRow($select);
        return $result;
    }

    public function CheckMealPlan($hotel_id, $intLoggedinUserAgencySysId) {
        $select = $this->db->select();
        $select->from(array('tb1' => "Tb_Agency_Accom_Meal_Plan_Rate"), array('meal_type'));
        $select->where("tb1.AcoomSysId =?", $hotel_id);
        $select->where("tb1.IsActive =?", 1);
        $select->where("tb1.IsMarkForDelete =?", 0);
        $select->where("tb1.AgencySysId =?", $intLoggedinUserAgencySysId);
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function checkHotelRoomInventoryRate($intLoggedinUserAgencySysId, $hotel_id, $FromDate, $ToDate, $RoomSysId = 0, $MealPlanType = 0, $IsPromotionalRateNull = 0) {
        $select = $this->db->select();
        $select->from(array('tb1' => "Tb_MP_Accomdation_Room_Inventory"), array('id', 'XRateSessionKey', 'FromDate', 'ToDate', 'RoomSysId'));
        $select->joinInner(array('tb2' => "TB_MP_Inventory_Accom"), "tb1.id = tb2.RoomInventorySysId", array('DOccupCost', 'MealPlanType','InvnItemSysId'));
        $select->joinInner(array('tb3' => "TB_IC_Accomdation"), "tb1.AccomSysId = tb3.AccomSysId", array());
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->where("((tb1.FromDate >= '$FromDate' AND tb1.FromDate <= '$ToDate' AND tb3.HotelRateType = 1) OR (('$FromDate' BETWEEN tb1.FromDate AND tb1.ToDate OR '$ToDate' BETWEEN tb1.FromDate AND tb1.ToDate OR tb1.FromDate BETWEEN '$FromDate' AND '$ToDate' OR tb1.ToDate BETWEEN '$FromDate' AND '$ToDate') AND tb3.HotelRateType = 2))");
        if ($RoomSysId > 0) {
            $select->where("tb1.RoomSysId =?", $RoomSysId);
        }
        if ($MealPlanType > 0) {
            $select->where("tb2.MealPlanType =?", $MealPlanType);
        }
        if ($IsPromotionalRateNull == 1) {
            $select->where("tb2.IsPromotionalRate IS NULL");
        }
        $select->where("tb1.IsMarkForDelete =?", 0);
        $select->where("tb2.IsMarkForDelete =?", 0);
        $select->where("tb1.AgencySysId =?", $intLoggedinUserAgencySysId);
//        echo $select;die;
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function getRoomInventoryIdsRates($hotel_id, $SessionKey, $XRefItemSysId, $MealPlanType = 0) {
        $select = $this->db->select();
        $select->from(array('tb1' => 'Tb_MP_Accomdation_Room_Inventory'), array('id', 'FromDate', 'RoomSysId', 'PublishQty', 'NetInHandQty', 'BlockQty', 'SoldQty'));
        $select->joinInner(array('tb2' => "TB_MP_Inventory_Accom"), "tb1.id = tb2.RoomInventorySysId", array('*'));
        $select->joinInner(array('tb3' => "TB_IC_Accomdation"), "tb1.AccomSysId = tb3.AccomSysId", array('HotelRateType', 'SupplierSysId as HotelSupplierSysId'));
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->where("tb1.XRateSessionKey =?", $SessionKey);
        $select->where("tb1.XRefItemSysId =?", $XRefItemSysId);
        if ($MealPlanType > 0) {
            $select->where("tb2.MealPlanType =?", $MealPlanType);
        }
        $select->where("tb1.IsMarkForDelete =?", 0);
        $select->where("tb2.IsMarkForDelete =?", 0);
        $row = $this->db->fetchAll($select);
//        echo "<pre>";print_r($row);die;
        return $row;
    }

    public function getRoomInventoryIdsRatesForUpdate($hotel_id, $SessionKey, $XRefItemSysId, $MealPlanType = 0) {
        $select = $this->db->select();
        $select->from(array('tb1' => 'Tb_MP_Accomdation_Room_Inventory'), array('id', 'FromDate'));
        $select->joinInner(array('tb2' => "TB_MP_Inventory_Accom"), "tb1.id = tb2.RoomInventorySysId", array('InvnItemSysId', 'WeekendDefine', 'MealPlanType', 'MarkType', 'B2CMarkup', 'B2BMarkup', 'SOccupCost', 'NetSOccupCost', 'IsTaxOnSOccupCost', 'TaxSOccupCost', 'DOccupCost', 'NetDOccupCost', 'IsTaxOnDOccupCost', 'TaxDOccupCost', 'ExtraBedCost', 'NetExtraBedCost', 'IsTaxOnExtraBedCost', 'TaxExtraBedCost', 'TriOccupCost', 'NetTriOccupCost', 'IsTaxOnTriOccupCost', 'TaxTriOccupCost', 'ChildAgeLimit', 'ExtraWOBedCost', 'NetExtraWOBedCost', 'IsTaxOnExtraWOBedCost', 'TaxExtraWOBedCost', 'RateType', 'RackCommissionType', 'RackCommission', 'UpdatedDate', 'CreatedDate', 'IsActive', 'IsMarkForDelete', 'XRefAccoSysId', 'AgencySysId', 'RoomInventorySysId', 'XRefItemSysId', 'SupplierSysId', 'TrxCurrency', 'IsAllowMarkupSO', 'IsAllowMarkupDO', 'IsAllowMarkupTO', 'IsAllowMarkupEB', 'IsAllowMarkupWOB', 'WkSOccupCost', 'WkNetSOccupCost', 'WkDOccupCost', 'WkNetDOccupCost', 'WkExtraBedCost', 'WkNetExtraBedCost', 'WkTriOccupCost', 'WkNetTriOccupCost', 'WkExtraWOBedCost', 'WkNetExtraWOBedCost'));
        $select->joinInner(array('tb3' => "TB_IC_Accomdation"), "tb1.AccomSysId = tb3.AccomSysId", array('HotelRateType'));
        $select->where("tb1.AccomSysId =?", $hotel_id);
        $select->where("tb1.XRateSessionKey =?", $SessionKey);
        $select->where("tb1.XRefItemSysId =?", $XRefItemSysId);
        if ($MealPlanType > 0) {
            $select->where("tb2.MealPlanType =?", $MealPlanType);
        }
        $select->where("tb1.IsMarkForDelete =?", 0);
        $select->where("tb2.IsMarkForDelete =?", 0);
        $row = $this->db->fetchAll($select);
//        echo "<pre>";print_r($row);die;
        return $row;
    }

    public function AddUpdateHotelRateOnly($intLoggedinUserAgencySysId, $postData = array()) {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $status = false;
        if ($request->isPost()) {
            if (!empty($postData)) {
                $post = $postData;
            } else {
                $post = $request->getPost();
            }
            $queryVals = array();
            $AccomSysId = $post['AccomSysId'];
            $XRateSessionKey = $post['XRateSessionKey'];
            $XRefItemSysId = $post['XRefItemSysId'];
            $RoomSysId = $post['RoomSysId'];
            $MealPlanType = $post['MealPlanType'];
            $getRoomInventoryIds = $this->getRoomInventoryIdsRatesForUpdate($AccomSysId, $XRateSessionKey, $XRefItemSysId, $MealPlanType);
            $currentDate = date('Y-m-d H:i');
            $InvnItemSysId = array();
            foreach ($getRoomInventoryIds as $key => $value) {

                $weekend = $value['WeekendDefine'];
                $weekends = explode(',', $weekend);
                //echo "<pre>";print_r($getRoomInventoryIds);die;

                $InvnItemSysId[] = $value['InvnItemSysId'];
                $value['B2BMarkup'] = (float) $post['B2BMarkup'];
                $value['B2CMarkup'] = (float) $post['B2CMarkup'];
                unset($value['MasterId']);
                if ($value['HotelRateType'] == 1) {

                    unset($value['id']);
                    unset($value['HotelRateType']);
                    unset($value['UpdatedDate']);
                    unset($value['CreatedDate']);
                    unset($value['WeekendDefine']);
                    unset($value['InvnItemSysId']);
                    unset($value['WkSOccupCost']);
                    unset($value['WkNetSOccupCost']);
                    unset($value['WkDOccupCost']);
                    unset($value['WkNetDOccupCost']);
                    unset($value['WkExtraBedCost']);
                    unset($value['WkNetExtraBedCost']);
                    unset($value['WkTriOccupCost']);
                    unset($value['WkNetTriOccupCost']);
                    unset($value['WkExtraWOBedCost']);
                    unset($value['WkNetExtraWOBedCost']);

                    if (in_array($value['FromDate']->format("D"), $weekends)) {
                        unset($value['FromDate']);

                        $value['SOccupCost'] = ($post['WkNetSOccupCost'] != '') ? (float) $post['WkNetSOccupCost'] : 'NULL';
                        $value['NetSOccupCost'] = ($post['WkNetSOccupCost'] != '') ? (float) $post['WkNetSOccupCost'] : 'NULL';
                        $value['DOccupCost'] = ($post['WkNetDOccupCost'] != '') ? (float) $post['WkNetDOccupCost'] : 'NULL';
                        $value['NetDOccupCost'] = ($post['WkNetDOccupCost'] != '') ? (float) $post['WkNetDOccupCost'] : 'NULL';
                        $value['ExtraBedCost'] = ($post['WkNetExtraBedCost'] != '') ? (float) $post['WkNetExtraBedCost'] : 'NULL';
                        $value['NetExtraBedCost'] = ($post['WkNetExtraBedCost'] != '') ? (float) $post['WkNetExtraBedCost'] : 'NULL';
                        $value['TriOccupCost'] = ($post['WkNetTriOccupCost'] != '') ? (float) $post['WkNetTriOccupCost'] : 'NULL';
                        $value['NetTriOccupCost'] = ($post['WkNetTriOccupCost'] != '') ? (float) $post['WkNetTriOccupCost'] : 'NULL';
                        $value['ExtraWOBedCost'] = ($post['WkNetExtraWOBedCost'] != '') ? (float) $post['WkNetExtraWOBedCost'] : 'NULL';
                        $value['NetExtraWOBedCost'] = ($post['WkNetExtraWOBedCost'] != '') ? (float) $post['WkNetExtraWOBedCost'] : 'NULL';
                        $valuesString = implode(',', array_values($value));
                        $valuesString .= ',\'' . $weekend . '\'';
                        $valuesString .= ',\'' . $currentDate . '\'';
                        $valuesString .= ',\'' . $currentDate . '\'';
                        $queryVals[] = '(' . $valuesString . ')';
                    } else {
                        unset($value['FromDate']);

                        $value['SOccupCost'] = ($post['NetSOccupCost'] != '') ? (float) $post['NetSOccupCost'] : 'NULL';
                        $value['NetSOccupCost'] = ($post['NetSOccupCost'] != '') ? (float) $post['NetSOccupCost'] : 'NULL';
                        $value['DOccupCost'] = ($post['NetDOccupCost'] != '') ? (float) $post['NetDOccupCost'] : 'NULL';
                        $value['NetDOccupCost'] = ($post['NetDOccupCost'] != '') ? (float) $post['NetDOccupCost'] : 'NULL';
                        $value['ExtraBedCost'] = ($post['NetExtraBedCost'] != '') ? (float) $post['NetExtraBedCost'] : 'NULL';
                        $value['NetExtraBedCost'] = ($post['NetExtraBedCost'] != '') ? (float) $post['NetExtraBedCost'] : 'NULL';
                        $value['TriOccupCost'] = ($post['NetTriOccupCost'] != '') ? (float) $post['NetTriOccupCost'] : 'NULL';
                        $value['NetTriOccupCost'] = ($post['NetTriOccupCost'] != '') ? (float) $post['NetTriOccupCost'] : 'NULL';
                        $value['ExtraWOBedCost'] = ($post['NetExtraWOBedCost'] != '') ? (float) $post['NetExtraWOBedCost'] : 'NULL';
                        $value['NetExtraWOBedCost'] = ($post['NetExtraWOBedCost'] != '') ? (float) $post['NetExtraWOBedCost'] : 'NULL';
                        $valuesString = implode(',', array_values($value));
                        $valuesString .= ',\'' . $weekend . '\'';
                        $valuesString .= ',\'' . $currentDate . '\'';
                        $valuesString .= ',\'' . $currentDate . '\'';
                        $queryVals[] = '(' . $valuesString . ')';
                    }
                } else {
                    unset($value['FromDate']);
                    unset($value['id']);
                    unset($value['HotelRateType']);
                    unset($value['UpdatedDate']);
                    unset($value['CreatedDate']);
                    unset($value['WeekendDefine']);
                    unset($value['InvnItemSysId']);

                    $value['SOccupCost'] = ($post['NetSOccupCost'] != '') ? (float) $post['NetSOccupCost'] : 'NULL';
                    $value['NetSOccupCost'] = ($post['NetSOccupCost'] != '') ? (float) $post['NetSOccupCost'] : 'NULL';
                    $value['DOccupCost'] = ($post['NetDOccupCost'] != '') ? (float) $post['NetDOccupCost'] : 'NULL';
                    $value['NetDOccupCost'] = ($post['NetDOccupCost'] != '') ? (float) $post['NetDOccupCost'] : 'NULL';
                    $value['ExtraBedCost'] = ($post['NetExtraBedCost'] != '') ? (float) $post['NetExtraBedCost'] : 'NULL';
                    $value['NetExtraBedCost'] = ($post['NetExtraBedCost'] != '') ? (float) $post['NetExtraBedCost'] : 'NULL';
                    $value['TriOccupCost'] = ($post['NetTriOccupCost'] != '') ? (float) $post['NetTriOccupCost'] : 'NULL';
                    $value['NetTriOccupCost'] = ($post['NetTriOccupCost'] != '') ? (float) $post['NetTriOccupCost'] : 'NULL';
                    $value['ExtraWOBedCost'] = ($post['NetExtraWOBedCost'] != '') ? (float) $post['NetExtraWOBedCost'] : 'NULL';
                    $value['NetExtraWOBedCost'] = ($post['NetExtraWOBedCost'] != '') ? (float) $post['NetExtraWOBedCost'] : 'NULL';

                    $value['WkSOccupCost'] = ($post['WkNetSOccupCost'] != '') ? (float) $post['WkNetSOccupCost'] : 'NULL';
                    $value['WkNetSOccupCost'] = ($post['WkNetSOccupCost'] != '') ? (float) $post['WkNetSOccupCost'] : 'NULL';
                    $value['WkDOccupCost'] = ($post['WkNetDOccupCost'] != '') ? (float) $post['WkNetDOccupCost'] : 'NULL';
                    $value['WkNetDOccupCost'] = ($post['WkNetDOccupCost'] != '') ? (float) $post['WkNetDOccupCost'] : 'NULL';
                    $value['WkExtraBedCost'] = ($post['WkNetExtraBedCost'] != '') ? (float) $post['WkNetExtraBedCost'] : 'NULL';
                    $value['WkNetExtraBedCost'] = ($post['WkNetExtraBedCost'] != '') ? (float) $post['WkNetExtraBedCost'] : 'NULL';
                    $value['WkTriOccupCost'] = ($post['WkNetTriOccupCost'] != '') ? (float) $post['WkNetTriOccupCost'] : 'NULL';
                    $value['WkNetTriOccupCost'] = ($post['WkNetTriOccupCost'] != '') ? (float) $post['WkNetTriOccupCost'] : 'NULL';
                    $value['WkExtraWOBedCost'] = ($post['WkNetExtraWOBedCost'] != '') ? (float) $post['WkNetExtraWOBedCost'] : 'NULL';
                    $value['WkNetExtraWOBedCost'] = ($post['WkNetExtraWOBedCost'] != '') ? (float) $post['WkNetExtraWOBedCost'] : 'NULL';

                    $valuesString = implode(',', array_values($value));
                    $valuesString .= ',\'' . $weekend . '\'';
                    $valuesString .= ',\'' . $currentDate . '\'';
                    $valuesString .= ',\'' . $currentDate . '\'';
                    $queryVals[] = '(' . $valuesString . ')';
                }
            }

            if (!empty($InvnItemSysId) && !empty($queryVals)) {
                $where = array(
                    'InvnItemSysId IN (?) ' => $InvnItemSysId,
                );
                $updateData = array('IsMarkForDelete' => 1, 'IsActive' => 0);
                $update_id = $this->db->update('TB_MP_Inventory_Accom', $updateData, $where);
                if ($getRoomInventoryIds[0]['HotelRateType'] == 1) {
                    $abdcs = "INSERT INTO TB_MP_Inventory_Accom (\"MealPlanType\",\"MarkType\",\"B2CMarkup\",
                    \"B2BMarkup\",\"SOccupCost\",\"NetSOccupCost\",\"IsTaxOnSOccupCost\",\"TaxSOccupCost\",\"DOccupCost\",\"NetDOccupCost\",\"IsTaxOnDOccupCost\",\"TaxDOccupCost\",
                    \"ExtraBedCost\",\"NetExtraBedCost\",\"IsTaxOnExtraBedCost\",\"TaxExtraBedCost\",\"TriOccupCost\",\"NetTriOccupCost\",\"IsTaxOnTriOccupCost\",\"TaxTriOccupCost\",
                    \"ChildAgeLimit\",\"ExtraWOBedCost\",\"NetExtraWOBedCost\",\"IsTaxOnExtraWOBedCost\",\"TaxExtraWOBedCost\",\"RateType\",\"RackCommissionType\",\"RackCommission\",
                    \"IsActive\",\"IsMarkForDelete\",\"XRefAccoSysId\",\"AgencySysId\",\"RoomInventorySysId\",\"XRefItemSysId\",\"SupplierSysId\",\"TrxCurrency\",\"IsAllowMarkupSO\",\"IsAllowMarkupDO\",\"IsAllowMarkupTO\",\"IsAllowMarkupEB\",\"IsAllowMarkupWOB\",
                    \"WeekendDefine\",\"UpdatedDate\",\"CreatedDate\")
                    VALUES " . implode(",", $queryVals);
//                    echo $abdcs;die;
                } else {
                    $abdcs = "INSERT INTO TB_MP_Inventory_Accom (\"MealPlanType\",\"MarkType\",\"B2CMarkup\",
                    \"B2BMarkup\",\"SOccupCost\",\"NetSOccupCost\",\"IsTaxOnSOccupCost\",\"TaxSOccupCost\",\"DOccupCost\",\"NetDOccupCost\",\"IsTaxOnDOccupCost\",\"TaxDOccupCost\",
                    \"ExtraBedCost\",\"NetExtraBedCost\",\"IsTaxOnExtraBedCost\",\"TaxExtraBedCost\",\"TriOccupCost\",\"NetTriOccupCost\",\"IsTaxOnTriOccupCost\",\"TaxTriOccupCost\",
                    \"ChildAgeLimit\",\"ExtraWOBedCost\",\"NetExtraWOBedCost\",\"IsTaxOnExtraWOBedCost\",\"TaxExtraWOBedCost\",\"RateType\",\"RackCommissionType\",\"RackCommission\",
                    \"IsActive\",\"IsMarkForDelete\",\"XRefAccoSysId\",\"AgencySysId\",\"RoomInventorySysId\",\"XRefItemSysId\",\"SupplierSysId\",\"TrxCurrency\",\"IsAllowMarkupSO\",\"IsAllowMarkupDO\",\"IsAllowMarkupTO\",\"IsAllowMarkupEB\",\"IsAllowMarkupWOB\",
                    \"WkSOccupCost\",\"WkNetSOccupCost\",\"WkDOccupCost\",\"WkNetDOccupCost\",\"WkExtraBedCost\",\"WkNetExtraBedCost\",\"WkTriOccupCost\",\"WkNetTriOccupCost\",\"WkExtraWOBedCost\",\"WkNetExtraWOBedCost\",
                    \"WeekendDefine\",\"UpdatedDate\",\"CreatedDate\")
                    VALUES " . implode(",", $queryVals);
                }


                try {
                    $ret = $this->db->query($abdcs);
                    $status = true;
                } catch (Exception $ex) {
                    echo $ex->getMessage();
                    die;
                }

                $UpdateHotelData = array('UpdateDate' => $currentDate);
                $whereH = array('AccomSysId =?' => $AccomSysId);
                $this->db->update('TB_IC_Accomdation', $UpdateHotelData, $whereH);
            }
            echo json_encode(array('status' => $status));
            exit;
        }
        echo json_encode(array('status' => $status));
        exit;
    }

    public function AddHotelRateCardIndividual($intLoggedinUserAgencySysId, $intLoggedinUserId, $postData = array()) {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        if ($request->isPost()) {
            if (!empty($postData)) {
                $post = $postData;
            } else {
                $post = $request->getPost();
            }

            $currentDate = date("Y-m-d H:i:s");
            $check_room_type = isset($post['check_room_type']) && !empty($post['check_room_type']) ? $post['check_room_type'] : '';
            $check_meal_type = isset($post['check_meal_type']) && !empty($post['check_meal_type']) ? $post['check_meal_type'] : '';
            $B2CMarkup = isset($post['B2CMarkup']) && !empty($post['B2CMarkup']) ? $post['B2CMarkup'] : 0;
            $B2BMarkup = isset($post['B2BMarkup']) && !empty($post['B2BMarkup']) ? $post['B2BMarkup'] : 0;
            $room_id = isset($post['room_id']) && !empty($post['room_id']) ? $post['room_id'] : '';
            $RoomType = isset($post['RoomType']) && !empty($post['RoomType']) ? $post['RoomType'] : '';
            $room_type_id = isset($post['room_type_id']) && !empty($post['room_type_id']) ? $post['room_type_id'] : '';
            $allocation = isset($post['allocation']) && !empty($post['allocation']) ? $post['allocation'] : '';
            $BookingType = isset($post['BookingType']) && !empty($post['BookingType']) ? $post['BookingType'] : '';
            $check_tax_type = isset($post['check_tax_type']) && !empty($post['check_tax_type']) ? $post['check_tax_type'] : '';
            $age_paid = isset($post['age_paid']) && !empty($post['age_paid']) ? $post['age_paid'] : '';
            $sg_pub_wd = isset($post['sg_pub_wd']) && !empty($post['sg_pub_wd']) ? ($post['sg_pub_wd']) : '';
            $sg_pub_wk = isset($post['sg_pub_wk']) && !empty($post['sg_pub_wk']) ? ($post['sg_pub_wk']) : '';
            $sg_net_wd = isset($post['sg_net_wd']) && !empty($post['sg_net_wd']) ? ($post['sg_net_wd']) : '';
            $sg_net_wk = isset($post['sg_net_wk']) && !empty($post['sg_net_wk']) ? ($post['sg_net_wk']) : '';
            $db_pub_wd = isset($post['db_pub_wd']) && !empty($post['db_pub_wd']) ? ($post['db_pub_wd']) : '';
            $db_pub_wk = isset($post['db_pub_wk']) && !empty($post['db_pub_wk']) ? ($post['db_pub_wk']) : '';
            $db_net_wd = isset($post['db_net_wd']) && !empty($post['db_net_wd']) ? ($post['db_net_wd']) : '';
            $db_net_wk = isset($post['db_net_wk']) && !empty($post['db_net_wk']) ? ($post['db_net_wk']) : '';
            $tri_pub_wd = isset($post['tri_pub_wd']) && !empty($post['tri_pub_wd']) ? ($post['tri_pub_wd']) : '';
            $tri_pub_wk = isset($post['tri_pub_wk']) && !empty($post['tri_pub_wk']) ? ($post['tri_pub_wk']) : '';
            $tri_net_wd = isset($post['tri_net_wd']) && !empty($post['tri_net_wd']) ? ($post['tri_net_wd']) : '';
            $tri_net_wk = isset($post['tri_net_wk']) && !empty($post['tri_net_wk']) ? ($post['tri_net_wk']) : '';
            $ex_wbed_pub_wd = isset($post['ex_wbed_pub_wd']) && !empty($post['ex_wbed_pub_wd']) ? ($post['ex_wbed_pub_wd']) : '';
            $ex_wbed_pub_wk = isset($post['ex_wbed_pub_wk']) && !empty($post['ex_wbed_pub_wk']) ? ($post['ex_wbed_pub_wk']) : '';
            $ex_wbed_net_wd = isset($post['ex_wbed_net_wd']) && !empty($post['ex_wbed_net_wd']) ? ($post['ex_wbed_net_wd']) : '';
            $ex_wbed_net_wk = isset($post['ex_wbed_net_wk']) && !empty($post['ex_wbed_net_wk']) ? ($post['ex_wbed_net_wk']) : '';
            $chpaid_pub_wd = isset($post['chpaid_pub_wd']) && !empty($post['chpaid_pub_wd']) ? ($post['chpaid_pub_wd']) : '';
            $chpaid_pub_wk = isset($post['chpaid_pub_wk']) && !empty($post['chpaid_pub_wk']) ? ($post['chpaid_pub_wk']) : '';
            $chpaid_net_wd = isset($post['chpaid_net_wd']) && !empty($post['chpaid_net_wd']) ? ($post['chpaid_net_wd']) : '';
            $chpaid_net_wk = isset($post['chpaid_net_wk']) && !empty($post['chpaid_net_wk']) ? ($post['chpaid_net_wk']) : '';
            $sg_tax_wd = isset($post['sg_tax_wd']) && !empty($post['sg_tax_wd']) ? ($post['sg_tax_wd']) : '';
            $sg_tax_wk = isset($post['sg_tax_wk']) && !empty($post['sg_tax_wk']) ? ($post['sg_tax_wk']) : '';
            $db_tax_wd = isset($post['db_tax_wd']) && !empty($post['db_tax_wd']) ? ($post['db_tax_wd']) : '';
            $db_tax_wk = isset($post['db_tax_wk']) && !empty($post['db_tax_wk']) ? ($post['db_tax_wk']) : '';
            $ex_wbed_tax_wd = isset($post['ex_wbed_tax_wd']) && !empty($post['ex_wbed_tax_wd']) ? ($post['ex_wbed_tax_wd']) : '';
            $ex_wbed_tax_wk = isset($post['ex_wbed_tax_wk']) && !empty($post['ex_wbed_tax_wk']) ? ($post['ex_wbed_tax_wk']) : '';
            $tri_tax_wd = isset($post['tri_tax_wd']) && !empty($post['tri_tax_wd']) ? ($post['tri_tax_wd']) : '';
            $tri_tax_wk = isset($post['tri_tax_wk']) && !empty($post['tri_tax_wk']) ? ($post['tri_tax_wk']) : '';
            $chpaid_tax_wd = isset($post['chpaid_tax_wd']) && !empty($post['chpaid_tax_wd']) ? ($post['chpaid_tax_wd']) : '';
            $chpaid_tax_wk = isset($post['chpaid_tax_wk']) && !empty($post['chpaid_tax_wk']) ? ($post['chpaid_tax_wk']) : '';
            $check_tax_sg = isset($post['check_tax_sg']) && !empty($post['check_tax_sg']) ? ($post['check_tax_sg']) : '';
            $check_tax_db = isset($post['check_tax_db']) && !empty($post['check_tax_db']) ? ($post['check_tax_db']) : '';
            $check_tax_tri = isset($post['check_tax_tri']) && !empty($post['check_tax_tri']) ? ($post['check_tax_tri']) : '';
            $check_tax_ex = isset($post['check_tax_ex']) && !empty($post['check_tax_ex']) ? ($post['check_tax_ex']) : '';
            $check_tax_chpaid = isset($post['check_tax_chpaid']) && !empty($post['check_tax_chpaid']) ? ($post['check_tax_chpaid']) : '';
            $check_markup_sg = isset($post['check_markup_sg']) && !empty($post['check_markup_sg']) ? ($post['check_markup_sg']) : '';
            $check_markup_db = isset($post['check_markup_db']) && !empty($post['check_markup_db']) ? ($post['check_markup_db']) : '';
            $check_markup_tri = isset($post['check_markup_tri']) && !empty($post['check_markup_tri']) ? ($post['check_markup_tri']) : '';
            $check_markup_ex = isset($post['check_markup_ex']) && !empty($post['check_markup_ex']) ? ($post['check_markup_ex']) : '';
            $check_markup_chpaid = isset($post['check_markup_chpaid']) && !empty($post['check_markup_chpaid']) ? ($post['check_markup_chpaid']) : '';
            $ext_adult = isset($post['ext_adult']) && !empty($post['ext_adult']) ? $post['ext_adult'] : '0';
            $ext_child = isset($post['ext_child']) && !empty($post['ext_child']) ? $post['ext_child'] : '0';
            $weekend = isset($post['weekend']) && !empty($post['weekend']) ? $post['weekend'] : '';
            $weekend = implode(',', $weekend);
            $SessionKeyOld = isset($post['SessionKey']) && !empty($post['SessionKey']) ? $post['SessionKey'] : '0';
            $hotel_id = $post['update_hotel_id'];
            if ($weekend) {
                $where = array('AccomSysId =?' => $hotel_id);
                $this->db->update('TB_IC_Accomdation', array('WeekendDefine' => $weekend), $where);
            }

            $from_dt = isset($post['from_dt']) && !empty($post['from_dt']) ? $post['from_dt'] : '0';
            $to_dt = isset($post['to_dt']) && !empty($post['to_dt']) ? $post['to_dt'] : '0';
            $strFromDate = Zend_Controller_Action_HelperBroker::getStaticHelper('DateFormat')->cal2Db($from_dt, 'd/m/y');
            $strToDate = Zend_Controller_Action_HelperBroker::getStaticHelper('DateFormat')->cal2Db($to_dt, 'd/m/y');
            $sessionKey = $this->getMaxXRateSessionKey();
            $weekends = isset($post['weekend']) && !empty($post['weekend']) ? $post['weekend'] : '';
            $strToDates = date("Y-m-d", strtotime("+1 day", strtotime($strToDate)));
            $begin = new DateTime($strFromDate);
            $end = new DateTime($strToDates);
            $interval = DateInterval::createFromDateString('1 day');
            $getHotelRateTypeArray = $this->getHotelRateType($hotel_id, $intLoggedinUserAgencySysId);
            $isInventory = true;
            if (isset($getHotelRateTypeArray['HotelRateType']) && $getHotelRateTypeArray['HotelRateType'] == 2) {
                $isInventory = false;
            }
            $CurrencyType = isset($getHotelRateTypeArray['CurrencyType']) ? $getHotelRateTypeArray['CurrencyType'] : 0;
            $SupplierSysId = isset($getHotelRateTypeArray['SupplierSysId']) ? $getHotelRateTypeArray['SupplierSysId'] : 0;
            if ($CurrencyType > 0) {
                $post['currency_type'] = $CurrencyType;
            }
            if ($SupplierSysId > 0) {
                $post['hidden_selected_supplier_sys_id'] = $SupplierSysId;
            }
            $period = new DatePeriod($begin, $interval, $end);
            if ($room_id) {
                $RoomKey = 0;
                $LetKey = 0;
                $queryVals = array();
                foreach ($room_id as $k => $val) {
                    if (isset($check_meal_type[$k])) {
                        if ($isInventory == true) {
                            foreach ($period as $dt) {
                                $where = array('AccomSysId =?' => $post['update_hotel_id'], 'FromDate =? ' => $dt->format("Y-m-d"), 'XRefItemSysId =? ' => $room_id[$k][0], 'RoomSysId =? ' => $room_type_id[$k][0], 'SupplierSysId =?' => $post['hidden_selected_supplier_sys_id'], 'AgencySysId =?' => $intLoggedinUserAgencySysId);
                                $insert_im = array('IsMarkForDelete' => 1, 'IsActive' => 0);
                                $this->db->update('Tb_MP_Accomdation_Room_Inventory', $insert_im, $where);
                                $insert = [
                                    'FromDate' => $dt->format("Y-m-d"),
                                    'Todate' => $strToDate,
                                    'XRateSessionKey' => $sessionKey,
                                    'PublishQty' => $allocation[$k][0],
                                    'NetInHandQty' => $allocation[$k][0],
                                    'BlockQty' => 0,
                                    'SoldQty' => 0,
                                    'UpdatedDate' => $currentDate,
                                    'CreatedDate' => $currentDate,
                                    'AccomSysId' => (int) $post['update_hotel_id'],
                                    'RoomSysId' => (int) $room_type_id[$k][0],
                                    'SupplierSysId' => (int) $post['hidden_selected_supplier_sys_id'],
                                    'AgencySysId' => $intLoggedinUserAgencySysId,
                                    'XRefItemSysId' => (int) $room_id[$k][0],
                                    'IsMarkForDelete' => 0,
                                    'IsActive' => 1,
                                    'IsSaleStart' => 1,
                                    'BookingType' => (isset($BookingType[$k])) ? (int) $BookingType[$k] : 0,
                                ];
                                $this->db->insert('Tb_MP_Accomdation_Room_Inventory', $insert);
                                $id = $this->db->lastInsertId();
                                $queryVals = array();
                                foreach ($check_meal_type[$k] as $key => $value) {
                                    if (in_array($dt->format("D"), $weekends)) {
                                        $queryVals[] = "(" . (int) $intLoggedinUserAgencySysId . ","
                                                . '\'' . $weekend . '\'' . ","
                                                . (int) $value . ","
                                                . '1' . ","
                                                . (float) $B2CMarkup . ","
                                                . (float) $B2BMarkup . ","
                                                . (isset($sg_pub_wk[$value][$k]) && $sg_pub_wk[$value][$k] == '' ? 0 : (float) $sg_pub_wk[$value][$k]) . ","
                                                . (isset($sg_net_wk[$value][$k]) && $sg_net_wk[$value][$k] == '' ? 0 : (float) $sg_net_wk[$value][$k]) . ","
                                                . (isset($check_tax_sg[$k][0]) ? $check_tax_sg[$k][0] : '0') . ","
                                                . (isset($sg_tax_wk[$value][$k]) && $sg_tax_wd[$value][$k] != '' ? (float) $sg_tax_wd[$value][$k] : '0') . ","
                                                . (isset($db_pub_wk[$value][$k]) && $db_pub_wk[$value][$k] == '' ? 0 : (float) $db_pub_wk[$value][$k]) . ","
                                                . (isset($db_net_wk[$value][$k]) && $db_net_wk[$value][$k] == '' ? 0 : (float) $db_net_wk[$value][$k]) . ","
                                                . (isset($check_tax_db[$k][0]) ? $check_tax_db[$k][0] : '0') . ","
                                                . (isset($db_tax_wk[$value][$k]) && $db_tax_wd[$value][$k] != '' ? (float) $db_tax_wd[$value][$k] : '0') . ","
                                                . (isset($ex_wbed_pub_wk[$value][$k]) && $ex_wbed_pub_wk[$value][$k] == '' ? 0 : (float) $ex_wbed_pub_wk[$value][$k]) . ","
                                                . (isset($ex_wbed_net_wk[$value][$k]) && $ex_wbed_net_wk[$value][$k] == '' ? 0 : (float) $ex_wbed_net_wk[$value][$k]) . ","
                                                . (isset($check_tax_ex[$k][0]) ? (float) $check_tax_ex[$k][0] : '0') . ","
                                                . (isset($ex_wbed_tax_wk[$value][$k]) && $ex_wbed_tax_wd[$value][$k] != '' ? (float) $ex_wbed_tax_wd[$value][$k] : '0') . ","
                                                . (isset($tri_pub_wk[$value][$k]) && $tri_pub_wk[$value][$k] == '' ? 0 : (float) $tri_pub_wk[$value][$k]) . ","
                                                . (isset($tri_net_wk[$value][$k]) && $tri_net_wk[$value][$k] == '' ? 0 : (float) $tri_net_wk[$value][$k]) . ","
                                                . (isset($check_tax_tri[$k][0]) ? (float) $check_tax_tri[$k][0] : '0') . ","
                                                . (isset($tri_tax_wk[$value][$k]) && $tri_tax_wd[$value][$k] != '' ? (float) $tri_tax_wd[$value][$k] : '0') . ","
                                                . (isset($age_paid[$k][0]) && !empty($age_paid[$k][0]) ? (float) $age_paid[$k][0] : '0') . ","
                                                . (isset($chpaid_pub_wk[$value][$k]) && $chpaid_pub_wk[$value][$k] == '' ? 0 : (float) $chpaid_pub_wk[$value][$k]) . ","
                                                . (isset($chpaid_net_wk[$value][$k]) && $chpaid_net_wk[$value][$k] == '' ? 0 : (float) $chpaid_net_wk[$value][$k]) . ","
                                                . (isset($check_tax_chpaid[$k][0]) ? (float) $check_tax_chpaid[$k][0] : '0') . ","
                                                . (isset($chpaid_tax_wk[$value][$k]) && $chpaid_tax_wd[$value][$k] != '' ? (float) $chpaid_tax_wd[$value][$k] : '0') . ","
                                                . (isset($post['ratetype']) && ($post['ratetype'] == 'NR') ? '1' : '0') . ","
                                                . (isset($post['rr_type']) && !empty($post['rr_type']) ? (int) $post['rr_type'] : '0') . ","
                                                . (isset($post['rr_value']) && !empty($post['rr_value']) ? (int) $post['rr_value'] : '0') . ","
                                                . '\'' . $currentDate . '\'' . ","
                                                . '\'' . $currentDate . '\'' . ","
                                                . (int) $post['update_hotel_id'] . ","
                                                . (int) $id . ","
                                                . (int) $room_id[$k][0] . ","
                                                . (isset($post['currency_type']) && !empty($post['currency_type']) ? $post['currency_type'] : '0') . ","
                                                . (isset($post['hidden_selected_supplier_sys_id']) && !empty($post['hidden_selected_supplier_sys_id']) ? $post['hidden_selected_supplier_sys_id'] : '0') . ","
                                                . (isset($check_markup_sg[$k][0]) ? (float) $check_markup_sg[$k][0] : '0') . ","
                                                . (isset($check_markup_db[$k][0]) ? (float) $check_markup_db[$k][0] : '0') . ","
                                                . (isset($check_markup_tri[$k][0]) ? (float) $check_markup_tri[$k][0] : '0') . ","
                                                . (isset($check_markup_ex[$k][0]) ? (float) $check_markup_ex[$k][0] : '0') . ","
                                                . (isset($check_markup_chpaid[$k][0]) ? (float) $check_markup_chpaid[$k][0] : '0') . ","
                                                . '1' . ","
                                                . '0' . ")";
                                    } else {
                                        $queryVals[] = "(" . (int) $intLoggedinUserAgencySysId . ","
                                                . '\'' . $weekend . '\'' . ","
                                                . (int) $value . ","
                                                . '1' . ","
                                                . (float) $B2CMarkup . ","
                                                . (float) $B2BMarkup . ","
                                                . (isset($sg_pub_wd[$value][$k]) && $sg_pub_wd[$value][$k] == '' ? 0 : (float) $sg_pub_wd[$value][$k]) . ","
                                                . (isset($sg_net_wd[$value][$k]) && $sg_net_wd[$value][$k] == '' ? 0 : (float) $sg_net_wd[$value][$k]) . ","
                                                . (isset($check_tax_sg[$k][0]) ? $check_tax_sg[$k][0] : '0') . ","
                                                . (isset($sg_tax_wd[$value][$k]) && $sg_tax_wd[$value][$k] != '' ? (float) $sg_tax_wd[$value][$k] : '0') . ","
                                                . (isset($db_pub_wd[$value][$k]) && $db_pub_wd[$value][$k] == '' ? 0 : (float) $db_pub_wd[$value][$k]) . ","
                                                . (isset($db_net_wd[$value][$k]) && $db_net_wd[$value][$k] == '' ? 0 : (float) $db_net_wd[$value][$k]) . ","
                                                . (isset($check_tax_db[$k][0]) ? $check_tax_db[$k][0] : '0') . ","
                                                . (isset($db_tax_wd[$value][$k]) && $db_tax_wd[$value][$k] != '' ? (float) $db_tax_wd[$value][$k] : '0') . ","
                                                . (isset($ex_wbed_pub_wd[$value][$k]) && $ex_wbed_pub_wd[$value][$k] == '' ? 0 : (float) $ex_wbed_pub_wd[$value][$k]) . ","
                                                . (isset($ex_wbed_net_wd[$value][$k]) && $ex_wbed_net_wd[$value][$k] == '' ? 0 : (float) $ex_wbed_net_wd[$value][$k]) . ","
                                                . (isset($check_tax_ex[$k][0]) ? (float) $check_tax_ex[$k][0] : '0') . ","
                                                . (isset($ex_wbed_tax_wd[$value][$k]) && $ex_wbed_tax_wd[$value][$k] != '' ? (float) $ex_wbed_tax_wd[$value][$k] : '0') . ","
                                                . (isset($tri_pub_wd[$value][$k]) && $tri_pub_wd[$value][$k] == '' ? 0 : (float) $tri_pub_wd[$value][$k]) . ","
                                                . (isset($tri_net_wd[$value][$k]) && $tri_net_wd[$value][$k] == '' ? 0 : (float) $tri_net_wd[$value][$k]) . ","
                                                . (isset($check_tax_tri[$k][0]) ? (float) $check_tax_tri[$k][0] : '0') . ","
                                                . (isset($tri_tax_wd[$value][$k]) && $tri_tax_wd[$value][$k] != '' ? (float) $tri_tax_wd[$value][$k] : '0') . ","
                                                . (isset($age_paid[$k][0]) && !empty($age_paid[$k][0]) ? (float) $age_paid[$k][0] : '0') . ","
                                                . (isset($chpaid_pub_wd[$value][$k]) && $chpaid_pub_wd[$value][$k] == '' ? 0 : (float) $chpaid_pub_wd[$value][$k]) . ","
                                                . (isset($chpaid_net_wd[$value][$k]) && $chpaid_net_wd[$value][$k] == '' ? 0 : (float) $chpaid_net_wd[$value][$k]) . ","
                                                . (isset($check_tax_chpaid[$k][0]) ? (float) $check_tax_chpaid[$k][0] : '0') . ","
                                                . (isset($chpaid_tax_wd[$value][$k]) && $chpaid_tax_wd[$value][$k] != '' ? (float) $chpaid_tax_wd[$value][$k] : '0') . ","
                                                . (isset($post['ratetype']) && ($post['ratetype'] == 'NR') ? '1' : '0') . ","
                                                . (isset($post['rr_type']) && !empty($post['rr_type']) ? (int) $post['rr_type'] : '0') . ","
                                                . (isset($post['rr_value']) && !empty($post['rr_value']) ? (int) $post['rr_value'] : '0') . ","
                                                . '\'' . $currentDate . '\'' . ","
                                                . '\'' . $currentDate . '\'' . ","
                                                . (int) $post['update_hotel_id'] . ","
                                                . (int) $id . ","
                                                . (int) $room_id[$k][0] . ","
                                                . (isset($post['currency_type']) && !empty($post['currency_type']) ? $post['currency_type'] : '0') . ","
                                                . (isset($post['hidden_selected_supplier_sys_id']) && !empty($post['hidden_selected_supplier_sys_id']) ? $post['hidden_selected_supplier_sys_id'] : '0') . ","
                                                . (isset($check_markup_sg[$k][0]) ? (float) $check_markup_sg[$k][0] : '0') . ","
                                                . (isset($check_markup_db[$k][0]) ? (float) $check_markup_db[$k][0] : '0') . ","
                                                . (isset($check_markup_tri[$k][0]) ? (float) $check_markup_tri[$k][0] : '0') . ","
                                                . (isset($check_markup_ex[$k][0]) ? (float) $check_markup_ex[$k][0] : '0') . ","
                                                . (isset($check_markup_chpaid[$k][0]) ? (float) $check_markup_chpaid[$k][0] : '0') . ","
                                                . '1' . ","
                                                . '0' . ")";
                                    }
                                }
                                $abdcs = "INSERT INTO TB_MP_Inventory_Accom (\"AgencySysId\",\"WeekendDefine\",\"MealPlanType\",\"MarkType\",\"B2CMarkup\",
                                \"B2BMarkup\",\"SOccupCost\",\"NetSOccupCost\",\"IsTaxOnSOccupCost\",\"TaxSOccupCost\",\"DOccupCost\",\"NetDOccupCost\",\"IsTaxOnDOccupCost\",\"TaxDOccupCost\",
                                \"ExtraBedCost\",\"NetExtraBedCost\",\"IsTaxOnExtraBedCost\",\"TaxExtraBedCost\",\"TriOccupCost\",\"NetTriOccupCost\",\"IsTaxOnTriOccupCost\",\"TaxTriOccupCost\",
                                \"ChildAgeLimit\",\"ExtraWOBedCost\",\"NetExtraWOBedCost\",\"IsTaxOnExtraWOBedCost\",\"TaxExtraWOBedCost\",\"RateType\",\"RackCommissionType\",\"RackCommission\",
                                \"UpdatedDate\",\"CreatedDate\",\"XRefAccoSysId\",\"RoomInventorySysId\",\"XRefItemSysId\",\"TrxCurrency\",\"SupplierSysId\",\"IsAllowMarkupSO\",\"IsAllowMarkupDO\",\"IsAllowMarkupTO\",\"IsAllowMarkupEB\",\"IsAllowMarkupWOB\",\"IsActive\",\"IsMarkForDelete\")
                                VALUES " . implode(",", $queryVals);
                                $ret = $this->db->query($abdcs);
                                $LetKey++;
                            }
                        } else {
                            $where = array('AccomSysId =?' => $post['update_hotel_id'], 'XRateSessionKey = ?' => $SessionKeyOld, 'AgencySysId =?' => $intLoggedinUserAgencySysId);
                            //echo "<pre>";print_r($where);exit;
                            $insert_im = array('IsMarkForDelete' => 1, 'IsActive' => 0);
                            $this->db->update('Tb_MP_Accomdation_Room_Inventory', $insert_im, $where);
                            $insert = [
                                'FromDate' => $strFromDate,
                                'Todate' => $strToDate,
                                'XRateSessionKey' => $sessionKey,
                                'PublishQty' => $allocation[$k][0],
                                'NetInHandQty' => $allocation[$k][0],
                                'BlockQty' => 0,
                                'SoldQty' => 0,
                                'UpdatedDate' => $currentDate,
                                'CreatedDate' => $currentDate,
                                'AccomSysId' => (int) $post['update_hotel_id'],
                                'RoomSysId' => (int) $room_type_id[$k][0],
                                'SupplierSysId' => (int) $post['hidden_selected_supplier_sys_id'],
                                'AgencySysId' => $intLoggedinUserAgencySysId,
                                'XRefItemSysId' => (int) $room_id[$k][0],
                                'IsMarkForDelete' => 0,
                                'IsActive' => 1,
                                'IsSaleStart' => 1,
                                'BookingType' => (isset($BookingType[$k])) ? (int) $BookingType[$k] : 0,
                            ];
                            $this->db->insert('Tb_MP_Accomdation_Room_Inventory', $insert);
                            $id = $this->db->lastInsertId();
                            $queryVals = array();
                            foreach ($check_meal_type[$k] as $key => $value) {
                                $addHotelData = array(
                                    "AgencySysId" => (int) $intLoggedinUserAgencySysId,
                                    "WeekendDefine" => $weekend,
                                    "MealPlanType" => (int) $value,
                                    "MarkType" => 1,
                                    "B2CMarkup" => (float) $B2CMarkup,
                                    "B2BMarkup" => (float) $B2BMarkup,
                                    "SOccupCost" => (isset($sg_pub_wd[$value][$k]) && $sg_pub_wd[$value][$k] == '' ? 0 : (float) $sg_pub_wd[$value][$k]),
                                    "NetSOccupCost" => (isset($sg_net_wd[$value][$k]) && $sg_net_wd[$value][$k] == '' ? 0 : (float) $sg_net_wd[$value][$k]),
                                    "IsTaxOnSOccupCost" => (isset($check_tax_sg[$k][0]) ? $check_tax_sg[$k][0] : '0'),
                                    "TaxSOccupCost" => (isset($sg_tax_wd[$value][$k]) && $sg_tax_wd[$value][$k] != '' ? (float) $sg_tax_wd[$value][$k] : '0'),
                                    "DOccupCost" => (isset($db_pub_wd[$value][$k]) && $db_pub_wd[$value][$k] == '' ? 0 : (float) $db_pub_wd[$value][$k]),
                                    "NetDOccupCost" => (isset($db_net_wd[$value][$k]) && $db_net_wd[$value][$k] == '' ? 0 : (float) $db_net_wd[$value][$k]),
                                    "IsTaxOnDOccupCost" => (isset($check_tax_db[$k][0]) ? $check_tax_db[$k][0] : '0'),
                                    "TaxDOccupCost" => (isset($db_tax_wd[$value][$k]) && $db_tax_wd[$value][$k] != '' ? (float) $db_tax_wd[$value][$k] : '0'),
                                    "ExtraBedCost" => (isset($ex_wbed_pub_wd[$value][$k]) && $ex_wbed_pub_wd[$value][$k] == '' ? 0 : (float) $ex_wbed_pub_wd[$value][$k]),
                                    "NetExtraBedCost" => (isset($ex_wbed_net_wd[$value][$k]) && $ex_wbed_net_wd[$value][$k] == '' ? 0 : (float) $ex_wbed_net_wd[$value][$k]),
                                    "IsTaxOnExtraBedCost" => (isset($check_tax_ex[$k][0]) ? (float) $check_tax_ex[$k][0] : '0'),
                                    "TaxExtraBedCost" => (isset($ex_wbed_tax_wd[$value][$k]) && $ex_wbed_tax_wd[$value][$k] != '' ? (float) $ex_wbed_tax_wd[$value][$k] : '0'),
                                    "TriOccupCost" => (isset($tri_pub_wd[$value][$k]) && $tri_pub_wd[$value][$k] == '' ? 0 : (float) $tri_pub_wd[$value][$k]),
                                    "NetTriOccupCost" => (isset($tri_net_wd[$value][$k]) && $tri_net_wd[$value][$k] == '' ? 0 : (float) $tri_net_wd[$value][$k]),
                                    "IsTaxOnTriOccupCost" => (isset($check_tax_tri[$k][0]) ? (float) $check_tax_tri[$k][0] : '0'),
                                    "TaxTriOccupCost" => (isset($tri_tax_wd[$value][$k]) && $tri_tax_wd[$value][$k] != '' ? (float) $tri_tax_wd[$value][$k] : '0'),
                                    "ChildAgeLimit" => (isset($age_paid[$k][0]) && !empty($age_paid[$k][0]) ? (float) $age_paid[$k][0] : '0'),
                                    "ExtraWOBedCost" => (isset($chpaid_pub_wd[$value][$k]) && $chpaid_pub_wd[$value][$k] == '' ? 0 : (float) $chpaid_pub_wd[$value][$k]),
                                    "NetExtraWOBedCost" => (isset($chpaid_net_wd[$value][$k]) && $chpaid_net_wd[$value][$k] == '' ? 0 : (float) $chpaid_net_wd[$value][$k]),
                                    "IsTaxOnExtraWOBedCost" => (isset($check_tax_chpaid[$k][0]) ? (float) $check_tax_chpaid[$k][0] : '0'),
                                    "TaxExtraWOBedCost" => (isset($chpaid_tax_wd[$value][$k]) && $chpaid_tax_wd[$value][$k] != '' ? (float) $chpaid_tax_wd[$value][$k] : '0'),
                                    "RateType" => (isset($post['ratetype']) && ($post['ratetype'] == 'NR') ? '1' : '0'),
                                    "RackCommissionType" => (isset($post['rr_type']) && !empty($post['rr_type']) ? (int) $post['rr_type'] : '0'),
                                    "RackCommission" => (isset($post['rr_value']) && !empty($post['rr_value']) ? (int) $post['rr_value'] : '0'),
                                    "UpdatedDate" => $currentDate,
                                    "CreatedDate" => $currentDate,
                                    "XRefAccoSysId" => (int) $post['update_hotel_id'],
                                    "RoomInventorySysId" => (int) $id,
                                    "XRefItemSysId" => (int) $room_id[$k][0],
                                    "TrxCurrency" => (isset($post['currency_type']) && !empty($post['currency_type']) ? $post['currency_type'] : '0'),
                                    "SupplierSysId" => (isset($post['hidden_selected_supplier_sys_id']) && !empty($post['hidden_selected_supplier_sys_id']) ? $post['hidden_selected_supplier_sys_id'] : '0'),
                                    "IsAllowMarkupSO" => (isset($check_markup_sg[$k][0]) ? (float) $check_markup_sg[$k][0] : '0'),
                                    "IsAllowMarkupDO" => (isset($check_markup_db[$k][0]) ? (float) $check_markup_db[$k][0] : '0'),
                                    "IsAllowMarkupTO" => (isset($check_markup_tri[$k][0]) ? (float) $check_markup_tri[$k][0] : '0'),
                                    "IsAllowMarkupEB" => (isset($check_markup_ex[$k][0]) ? (float) $check_markup_ex[$k][0] : '0'),
                                    "IsAllowMarkupWOB" => (isset($check_markup_chpaid[$k][0]) ? (float) $check_markup_chpaid[$k][0] : '0'),
                                    "IsActive" => 1,
                                    "IsMarkForDelete" => 0,
                                    "WkSOccupCost" => (isset($sg_pub_wk[$value][$k]) && $sg_pub_wk[$value][$k] == '' ? 0 : (float) $sg_pub_wk[$value][$k]),
                                    "WkNetSOccupCost" => (isset($sg_net_wk[$value][$k]) && $sg_net_wk[$value][$k] == '' ? 0 : (float) $sg_net_wk[$value][$k]),
                                    "WkDOccupCost" => (isset($db_pub_wk[$value][$k]) && $db_pub_wk[$value][$k] == '' ? 0 : (float) $db_pub_wk[$value][$k]),
                                    "WkNetDOccupCost" => (isset($db_net_wk[$value][$k]) && $db_net_wk[$value][$k] == '' ? 0 : (float) $db_net_wk[$value][$k]),
                                    "WkExtraBedCost" => (isset($ex_wbed_pub_wk[$value][$k]) && $ex_wbed_pub_wk[$value][$k] == '' ? 0 : (float) $ex_wbed_pub_wk[$value][$k]),
                                    "WkNetExtraBedCost" => (isset($ex_wbed_net_wk[$value][$k]) && $ex_wbed_net_wk[$value][$k] == '' ? 0 : (float) $ex_wbed_net_wk[$value][$k]),
                                    "WkTriOccupCost" => (isset($tri_pub_wk[$value][$k]) && $tri_pub_wk[$value][$k] == '' ? 0 : (float) $tri_pub_wk[$value][$k]),
                                    "WkNetTriOccupCost" => (isset($tri_net_wk[$value][$k]) && $tri_net_wk[$value][$k] == '' ? 0 : (float) $tri_net_wk[$value][$k]),
                                    "WkExtraWOBedCost" => (isset($chpaid_pub_wk[$value][$k]) && $chpaid_pub_wk[$value][$k] == '' ? 0 : (float) $chpaid_pub_wk[$value][$k]),
                                    "WkNetExtraWOBedCost" => (isset($chpaid_net_wk[$value][$k]) && $chpaid_net_wk[$value][$k] == '' ? 0 : (float) $chpaid_net_wk[$value][$k])
                                );
                                //echo "<pre>";print_r($addHotelData);exit;
                                $this->db->insert('TB_MP_Inventory_Accom', $addHotelData);
                                $LetKey++;
                            }
                            $RoomKey++;
                        }
                    }
                }
                if (isset($update_InvnItemSysId) && isset($invtId_arr)) {
                    $restInvtId = (array_diff_key($update_InvnItemSysId, $invtId_arr));
                    if ($restInvtId) {
                        foreach ($restInvtId as $update) {
                            $where = array('InvnItemSysId =?' => $update);
                            $this->db->update('TB_MP_Inventory_Accom', array('IsMarkForDelete' => 1), $where);
                        }
                    }
                }

                return array("status" => true, "HotelType" => $isInventory, 'SessionKey' => $sessionKey);
            }
        }
    }

    public function IsGtxNetworkActiveVisa($postData = array()) {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $post = !empty($postData) ? $postData : $request->getPost();
        try {
            $this->db->beginTransaction();
            $insert = array(
                'IsGTXNetwork' => $post['val']
            );
            $where = array('InvnVisaAllSysId =?' => $post['visa_id']);
            $where1 = array('VisaSysId =?' => $post['visa_id']);
            if ($post['val'] == 0) {
                $dataArrMarketPlace = array(
                    'IsActive' => 0,
                    'IsWeb' => 0,
                );
            } else {
                $dataArrMarketPlace = array(
                    'IsActive' => 1
                );
            }
            $this->db->update('TB_Visa_Mapping_Network_Web', $dataArrMarketPlace, $where1);

            $this->db->update('TB_MP_Inventory_Visa', $insert, $where);
            $this->db->commit();
            return true;
        } catch (Exception $ex) {
            die($ex->getMessage());
        }
    }

    public function getAccomRoomDetails($hotel_id, $intLoggedinUserAgencySysId, $roomId = 0) {
        $select = $this->db->select();
        $selectarray = array('ItemSysId', 'RoomType', 'Qty');
        $room_masterarray = array('RoomType as RoomTypeId', 'Title as RoomType');
        $select->from(array('tb1' => "TB_IC_Accomdation_Room"), $selectarray);
        $select->joinLeft(array('tb2' => "TB_Master_RoomType"), "tb1.RoomType = tb2.RoomType", $room_masterarray);
        $select->joinLeft(array('tb3' => "TB_IC_Accomdation"), "tb1.AccomSysId = tb3.AccomSysId", array('RateType', 'NetRateType', 'ChildAge', 'CurrencyType', 'SupplierSysId', 'WeekendDefine', 'RackCommission'));
        $select->where("tb1.SourceSysId =?", $intLoggedinUserAgencySysId);
        $select->where("tb1.AccomSysId =?", $hotel_id);
        if ($roomId > 0) {
            $select->where("tb1.ItemSysId =?", $roomId);
        }
        $result = $this->db->fetchAll($select);
        return $result;
    }
    
    public function CheckUpdateHotelDetail($AgencySysId,$post) {
        $HotelId = (int)$post['HotelId'];
        if ($HotelId > 0) {
            $getHotelRateTypeArray = $this->getHotelRateType($HotelId, $AgencySysId);
            if(!empty($getHotelRateTypeArray)){
                $insert = array(
                    'Title' => isset($post['HotelName']) && !empty($post['HotelName']) ? $post['HotelName'] : '',
                    'Stars' => isset($post['HotelStar']) && !empty($post['HotelStar']) ? $post['HotelStar'] : '',
                );
                try {
                    $where = array('ICSourceSysId =?' => $AgencySysId,'AccomSysId =?' => $HotelId);
                    $this->db->update('TB_IC_Accomdation', $insert, $where);
                    return $HotelId;
                } catch (Exception $ex) {
                    return 0;
                }
            }else{
                return 0;
            }
            
        }
    }
    
    
}

Youez - 2016 - github.com/yon3zu
LinuXploit