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/controllers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/b2bzend/application/controllers/HotelProposalController.php
<?php

/* * ***************
 * Zend Framework
 * @category   Zend
 * @package    Zend_Controller_Action
 * @copyright  Copyright (c) 2008-2014 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: DbTable.php 8862 2012-03-16 15:36:00Z thomas $
 * @author     Md Sabir(sabir@catpl.co.in).
 * Deals with the Hotel booking comes through CRM emails to customer
 *
 * Create Date 19-06-2025
 * Update Date 19-06-2025
 * *** */

class HotelProposalController extends Catabatic_ValidateCustomer
{

    public $AgencySysId = '';
    public $AgentSysId = '';
    public $baseUrl = '';
    public $_objFlight;
    public $CurrencyId;
    public $CurrencyTitle;
    public $CurrencyRate;
    public $BITLYAPIKEY;
    public $BITLYLOGIN;
    public $SMSFORMAT;
    public $SMSSENDER;
    public $SMSAPIKEY;
    public $SMSMETHOD;
    public $SMSURL;
    public $_HtmlPurifier;

    public function init()
    {
        error_reporting(1);
        $this->_helper->layout->setLayout('layout-hotel-proposal');

        $request = Zend_Controller_Front::getInstance()->getRequest();
        $this->baseUrl = $request->getScheme() . '://' . $request->getHttpHost();

        ############## For HTML Purifer ####################
        $this->_HtmlPurifier = new Zend_Filter_HtmlPurifier();
        $this->SMSURL = Catabatic_Helper::getSMSURL();
        $this->SMSMETHOD = Catabatic_Helper::getSMSMETHOD();
        $this->SMSAPIKEY = Catabatic_Helper::getSMSAPIKEY();
        $this->SMSSENDER = Catabatic_Helper::getSMSSENDER();
        $this->SMSFORMAT = Catabatic_Helper::getSMSFORMAT();
        $this->BITLYLOGIN = 'gpurwar';
        $this->BITLYAPIKEY = 'R_c1c94b5c789249d5a59d585bc0e7ef80';
        $this->CurrencyRate = 1;
        $this->CurrencyTitle = 'INR';
        $this->CurrencyId = 1;
        $this->_objFlight = new Travel_Model_TblFlight();
    }


    public function viewFlightProposalCheckAction()
    {
        $objFlight = new Travel_Model_TblFlight();
        $TPSysId = base64_decode($this->_request->getParam('id'));
        $isagency = ($this->_request->getParam('isagency'));
        Zend_Session::namespaceUnset('isagencySession');
        $isagencySession = new Zend_Session_Namespace('isagencySession');
        $isagencySession->params = $isagency;

        $traceIDData = $objFlight->GetFlightTempDataByTPSysId($TPSysId);
        // print_r($isagency);
        // print_r($traceIDData);
        // die;
        if ($traceIDData) {
            if ($isagency == 1) {
                //$this->_redirect('/flight-proposal/view-flight-proposal-new/id/' . $traceIDData['TraceId']);
                $this->_redirect('/flight/search-result-new/SearchID/' . $traceIDData['TraceId']);
            } else {
                $this->_redirect('/flight-proposal/view-flight-proposal-new/id/' . $traceIDData['TraceId']);
            }
        } else {
            die('Invalid link');
        }
    }

    public function viewHotelProposalAction()
    {
        try {
            $objFlight = new Travel_Model_TblFlight();
            $getData = $this->getRequest()->getParams();
            $isCustomer = isset($getData['cust']) ? $getData['cust'] : 0;
            $SearchQueryid = isset($getData['SearchQueryid']) ? $getData['SearchQueryid'] : '';
            $traceID  = $this->view->traceID = ($this->_request->getParam('searchID'));
            $TPSysId  = $this->view->TPSysId = ($this->_request->getParam('TPSys'));

            // if ($isCustomer == 1) {
            //     $isagencySession = new Zend_Session_Namespace('isagencySession');
            //     $isagencySession->params = $isCustomer;
            // }
            $FlightTempData = $objFlight->GetFlightTempData($traceID);
            $arrUrlData = json_decode($FlightTempData['APIBookingData'], true);

            $FlightBookingData = [];

            $SearchParams = $this->view->searchParams = $arrUrlData['SearchParams'];
            $searchdata = $this->view->searchdata = $arrUrlData['searchdata'];
            $selectedRoom = $arrUrlData['selectedRoom'];
            $bookingAllowed = $this->view->bookingAllowed = isset($SearchParams['bookingAllowed']) ? $SearchParams['bookingAllowed'] : 0;
            $leadId     = $SearchParams['TPSysId'];
            $nights = (int) $SearchParams['hotelTotalNights'];
            $rooms = (int) $SearchParams['hotelTotalRooms'];
            $objFlightProposal = new Travel_Model_TblFlightProposal();
            $crmcustomerObj = new Travel_Model_CRM_Customer();
            $arrAgencyDetails = $this->view->arrAgencyDetails = $objFlightProposal->getProposalAgencyDetails($leadId, 'query');
            $AgencySysId = $arrAgencyDetails['AgencySysId'];
            $AgentSysId = $arrAgencyDetails['AgentSysId'];
            $getAgencyDetail = $crmcustomerObj->GetAgencyDetailById($AgencySysId);
            $SecurityKey = isset($getAgencyDetail['SecurityKey']) ? $getAgencyDetail['SecurityKey'] : 0;
            $crmcusttravelplan = new Travel_Model_CRM_CustomerTravelPlan();
            $arrAgentDetail = $this->view->arrAgentDetail = $crmcusttravelplan->getAgentDetails($AgentSysId);
            $this->view->IsCheckWallet  = $IsCheckWallet = isset($getAgencyDetail['IsCheckWallet']) ? $getAgencyDetail['IsCheckWallet'] : 0;
            $SelectedHID = [];
            $SelectedROOMID = [];
            $SelectedEMRoomWise = [];
            $SelectedExtraMarkup = [];
            // echo "<pre>";
            // print_r(json_encode($selectedRoom));
            // die;
            if ($selectedRoom) {
                foreach ($selectedRoom as $key => $val) {

                    $parts = explode("-", $key);
                    if (isset($parts[1]) && !empty($parts[1])) {
                        $SelectedHID[] = $parts[1];
                    }
                    $ExtraMarkup_ = 0;
                    $discountVal_ = 0;
                    if ($val['room']) {

                        foreach ($val['room'] as $room => $value) {

                            if ($value['Rooms']) {
                                foreach ($value['Rooms'] as $Rooms => $values) {

                                    $SelectedROOMID[$parts[1]][$values['RoomId']][$values['id']] = $values['id'];

                                    $ExtraMarkup = isset($values['ExtraMarkup']) ? $values['ExtraMarkup'] : 0;
                                    $ExtraMarkupOnGST = isset($values['ExtraMarkupOnGST']) ? $values['ExtraMarkupOnGST'] : 0;
                                    $ExtraMarkup_ += ($ExtraMarkup + $ExtraMarkupOnGST);
                                    $discountVal_ += !empty($values['discountVal']) ? $values['discountVal'] : 0;

                                    $SelectedEMRoomWise[$parts[1]][$values['RoomId']][$values['id']] = ['ExtraMarkup' => $ExtraMarkup, 'ExtraMarkupOnGST' => $ExtraMarkupOnGST, 'discountVal' => !empty($values['discountVal']) ? $values['discountVal'] : 0];
                                }
                            }
                        }
                    }

                    $SelectedExtraMarkup[$parts[1]] = ['ExtraMarkup' => ($ExtraMarkup_ / $rooms / $nights), 'discountVal' => ($discountVal_ / $rooms / $nights)];
                }
            }
            // echo "<pre>";
            // print_r(($SelectedEMRoomWise));
            // echo "<pre>";
            // print_r(($SelectedROOMID));
            // die;
            if (count($SelectedHID) > 0) {
                $searchPreferences = $searchdata['APIpost']['searchQuery']['searchPreferences'];
                $searchPreferences['hids'] = $SelectedHID;
                // $searchPreferences['fsc'] = true;
                $searchPreferences['ratings'] = [];
                $searchdata['APIpost']['searchQuery']['searchPreferences'] = $searchPreferences;
                unset($searchdata['APIpost']['searchQuery']['searchCriteria']['city']);
                // $searchdata['APIpost']['sync'] = true;
            }

            $this->view->baseUrl = $this->baseUrl;
            $this->view->SelectedROOMID = json_encode($SelectedROOMID);
            $this->view->SelectedEMRoomWise = json_encode($SelectedEMRoomWise);

            // echo "<pre>";
            // print_r(($searchdata));
            // echo "<pre>";
            // print_r(($selectedRoom));
            // die;
            $URL = GTX_API_URL . '/hotel/v2/searchquery';
            $getData['SecurityKey'] = $SecurityKey;
            if (empty($SearchQueryid)) {
                $apiResponse = Zend_Controller_Action_HelperBroker::getStaticHelper("Hotel")->apiHttpRequest($searchdata, $getData, $URL);
                $searchids = $this->view->searchids = (isset($apiResponse['searchids']) && $apiResponse['searchids']) ? json_encode($apiResponse['searchids']) : [];
                //$searchids = $this->view->searchids = json_encode(['GTX1750320283700']);
            }


            if ($this->getRequest()->isXmlHttpRequest()) {
                $searchNew = ['SearchQueryid' => $SearchQueryid];
                $URL = GTX_API_URL . '/hotel/v2/search';
                $getData['SecurityKey'] = $SecurityKey;
                $Response = Zend_Controller_Action_HelperBroker::getStaticHelper("Hotel")->apiHttpRequest($searchNew, $getData, $URL);

                $ResultStatus = isset($Response['status']) ? $Response['status'] : false;
                $result = isset($Response['result']) ? $Response['result'] : [];


                if ($ResultStatus == 1) {
                    $MinPriceRange = $Response['MinPriceRange'];
                    $MaxPriceRange = $Response['MaxPriceRange'];
                    $arrRange = $this->renderRanges($this->getRanges($MinPriceRange, $MaxPriceRange, count($result)));
                    $Response['PriceRange'] = $arrRange;

                    if ($result) {
                        $resultNew = [];
                        foreach ($result as $keys => $value) {
                            $averageRoomPrice = isset($value['averageRoomPrice']) ? $value['averageRoomPrice'] : 0;
                            $HotelId = isset($value['HotelId']) ? $value['HotelId'] : '';
                            $HotelId = substr(strstr($HotelId, '-'), 1);
                            $SelectedExtraMarkup = isset($SelectedExtraMarkup[$HotelId]) ? $SelectedExtraMarkup[$HotelId] : [];

                            $ExtraMarkup = isset($SelectedExtraMarkup['ExtraMarkup']) ? $SelectedExtraMarkup['ExtraMarkup'] : 0;
                            $discountVal = isset($SelectedExtraMarkup['discountVal']) ? $SelectedExtraMarkup['discountVal'] : 0;
                            $resultNew[$keys] = $value;
                            // $resultNew[$keys]['averageRoomPrice__'] = round((($averageRoomPrice)), 2);
                            $resultNew[$keys]['averageRoomPrice'] = round((($averageRoomPrice + $ExtraMarkup) - $discountVal), 2);
                        }
                        $Response['result'] = $resultNew;
                    }

                    // echo "<pre>";
                    // print_r(($result));
                    // die;
                    echo json_encode($Response);
                    exit;
                } else {
                    echo json_encode(['status' => false]);
                    exit;
                }
            }
        } catch (Exception $e) {
            //echo $e->getMessage();
            $response = array('success' => false, 'message' => 'URL expired. please get another proposal');
            echo json_encode($response);
            exit;
        }
    }


    public function getApiHotelInfoAction()
    {
        $this->_helper->viewRenderer->setNoRender(true);
        //$this->_helper->layout->disableLayout();


        if ($this->_request->isXmlHttpRequest()) {
            $post = json_decode(file_get_contents('php://input'), true);
            $searchID = $post['hotelData']['SearchHotelTraceId'];
            $searchIDSearch = $post['searchID'];
            $SelectedROOMID = (isset($post['SelectedROOMID']) && !empty($post['SelectedROOMID'])) ? json_decode($post['SelectedROOMID'], 1) : [];
            $SelectedEMRoomWise = (isset($post['SelectedEMRoomWise']) && !empty($post['SelectedEMRoomWise'])) ? json_decode($post['SelectedEMRoomWise'], 1) : [];

            // echo "<pre>SelectedROOMID";
            // print_r(($SelectedROOMID));
            // die;

            $objTempFlight = new Travel_Model_TblFlight();
            $FlightTempData = $objTempFlight->GetFlightTempData($searchIDSearch);
            $arrUrlData = json_decode($FlightTempData['APIBookingData'], true);
            $SearchParams = $arrUrlData['SearchParams'];

            $leadId     = $SearchParams['TPSysId'];
            $objFlightProposal = new Travel_Model_TblFlightProposal();
            $crmcustomerObj = new Travel_Model_CRM_Customer();
            $arrAgencyDetails = $this->view->arrAgencyDetails = $objFlightProposal->getProposalAgencyDetails($leadId, 'query');
            $AgencySysId = $arrAgencyDetails['AgencySysId'];
            $AgentSysId = $arrAgencyDetails['AgentSysId'];
            $getAgencyDetail = $crmcustomerObj->GetAgencyDetailById($AgencySysId);
            $SecurityKey = isset($getAgencyDetail['SecurityKey']) ? $getAgencyDetail['SecurityKey'] : 0;



            $B2BSearch = $arrUrlData['B2BSearch'];
            $hotelCityTitle = $SearchParams['hotelCityTitle'];
            $nights = (int) $SearchParams['hotelTotalNights'];
            $rooms = (int) $SearchParams['hotelTotalRooms'];
            $tboCountryCode = $SearchParams['tboCountryCode'];
            $AdultPax = (int) $SearchParams['totalMemberCount']['AdultPax'];
            $ChildPax = (int) $SearchParams['totalMemberCount']['ChildPax'];
            $MemberCount = ($AdultPax + $ChildPax);
            $hotelCityTitle = $SearchParams['hotelCityTitle'];
            $HotelId = $post['hotelData']['HotelId'];
            $ICSourceSysId = $post['hotelData']['ICSourceSysId'];
            if ($tboCountryCode != 'IN') {
                $interNationalSearch = true;
            } else {
                $interNationalSearch = false;
            }

            $request = [
                'request' => ['id' => $HotelId],
                'searchID' => $searchID,
                'MemberCount' => $MemberCount,
                'destination' => $hotelCityTitle,
                'nights' => $nights,
                'rooms' => $rooms,
                'ICSourceSysId' => $ICSourceSysId,
                'PlanType' => 2,
                'MPType' => 1,
                'B2B' => $B2BSearch,
                'interNationalSearch' => $interNationalSearch,
                'APIMode' => ($AgencySysId == 1) ? 1 : 0,
            ];

            Zend_Session::namespaceUnset('HotelDetails_' . $HotelId . ' ');
            if ($ICSourceSysId == 7) {
                $apiResponse = Zend_Controller_Action_HelperBroker::getStaticHelper("Hotel")->getHotelDetails($request, $SecurityKey);
                $status = isset($apiResponse['status']) ? $apiResponse['status'] : false;
                if ($status == 1) {
                    $HotelId = isset($apiResponse['HotelDetails']['HotelId']) ? $apiResponse['HotelDetails']['HotelId'] : '';
                    $RoomInfo = isset($apiResponse['RoomInfo']) ? $apiResponse['RoomInfo'] : '';
                    $HotelId = substr(strstr($HotelId, '-'), 1);
                    $SelectedROOMID = isset($SelectedROOMID[$HotelId]) ? $SelectedROOMID[$HotelId] : [];
                    $SelectedEMRoomWise = isset($SelectedEMRoomWise[$HotelId]) ? $SelectedEMRoomWise[$HotelId] : [];


                    $RoomInfoFiltered = [];
                    if ($RoomInfo) {
                        foreach ($RoomInfo as $room => $value) {
                            $RoomId = $value['RoomId'];

                            $SelectedR = isset($SelectedROOMID[$RoomId]) ? $SelectedROOMID[$RoomId] : [];
                            $SelectedEMR = isset($SelectedEMRoomWise[$RoomId]) ? $SelectedEMRoomWise[$RoomId] : [];
                            // $SelectedEMR = isset($SelectedEMRoomWise) ? $SelectedEMRoomWise : [];

                            // echo "<pre>SelectedR";
                            // print_r(($SelectedR));
                            // echo "<pre>SelectedEMR";
                            // print_r(($SelectedEMR));
                            $FilterRoom = [];
                            if ($value['Rooms']) {
                                foreach ($value['Rooms'] as $Rooms => $values) {

                                    // echo "<pre>";
                                    // print_r(($values['id']));
                                    // echo "<pre>==";
                                    // print_r(($SelectedROOMID));
                                    // die;
                                    if (!empty($SelectedROOMID) && isset($SelectedR[$values['id']]) && !empty($SelectedR[$values['id']])) {

                                        $CostToCustomer = isset($values['CostToCustomer']) ? $values['CostToCustomer'] : 0;
                                        $HotelRoomPrice = isset($values['HotelRoomPrice']) ? $values['HotelRoomPrice'] : 0;
                                        $pernightperroomprice = isset($values['pernightperroomprice']) ? $values['pernightperroomprice'] : 0;
                                        $FixedMarkUp = isset($values['FixedMarkUp']) ? $values['FixedMarkUp'] : 0;
                                        $GSTOnMarkUp = isset($values['GSTOnMarkUp']) ? $values['GSTOnMarkUp'] : 0;
                                        $ExtraMarkup = isset($SelectedEMR[$values['id']]['ExtraMarkup']) ? ($SelectedEMR[$values['id']]['ExtraMarkup'] / $nights) : 0;
                                        $ExtraMarkupOnGST = isset($SelectedEMR[$values['id']]['ExtraMarkupOnGST']) ? ($SelectedEMR[$values['id']]['ExtraMarkupOnGST'] / $nights) : 0;
                                        $discountVal = isset($SelectedEMR[$values['id']]['discountVal']) ? ($SelectedEMR[$values['id']]['discountVal'] / $nights) : 0;
                                        $FilterRoom[$Rooms] = $values;
                                        $FilterRoom[$Rooms]['FixedMarkUp'] = ($ExtraMarkup + $FixedMarkUp);
                                        $FilterRoom[$Rooms]['GSTOnMarkUp'] = ($ExtraMarkupOnGST + $GSTOnMarkUp);
                                        $FilterRoom[$Rooms]['ExtraMarkup'] = ($ExtraMarkup);
                                        $FilterRoom[$Rooms]['ExtraMarkupOnGST'] = ($ExtraMarkupOnGST);
                                        $FilterRoom[$Rooms]['Discounts'] = $discountVal;
                                        $FilterRoom[$Rooms]['HotelRoomPrice'] = round(($HotelRoomPrice + $ExtraMarkupOnGST + $ExtraMarkup), 2);
                                        $FilterRoom[$Rooms]['CostToCustomer'] = round(($CostToCustomer + $ExtraMarkupOnGST + $ExtraMarkup), 2);
                                        $FilterRoom[$Rooms]['pernightperroomprice_'] = ($pernightperroomprice);
                                        $FilterRoom[$Rooms]['pernightperroomprice'] = (($pernightperroomprice + $ExtraMarkupOnGST + $ExtraMarkup) - $discountVal);
                                    }
                                }
                            }

                            // echo "<pre>==";
                            // print_r(($FilterRoom));
                            if ($FilterRoom) {
                                $RoomInfoFiltered[$room] = $value;
                                $RoomInfoFiltered[$room]['Rooms'] = array_values($FilterRoom);
                            }
                        }
                    }
                    // echo "<pre>RoomInfoFiltered";
                    // print_r(($RoomInfoFiltered));
                    // die;
                    if (!empty($RoomInfoFiltered)) {
                        $apiResponse['RoomInfo'] = array_values($RoomInfoFiltered);
                    }
                }
                //die;

                // echo "<pre>";
                // print_r(json_encode($apiResponse));
                // echo "<pre>apiResponse";
                // print_r(($apiResponse));


                $HotelDetails = new Zend_Session_Namespace('HotelDetails_' . $HotelId . ' ');
                $HotelDetails->params = $apiResponse;
            } else {
                $apiResponse['status'] = true;
                $apiResponse['message'] = 'SUCCESS';
                $apiResponse['RoomInfo'] = $post['hotelData']['HotelRoomFaciality'];
                $apiResponse['RoomCombinations'] = [];
                $apiResponse['roomGroupby'] = [];
                $apiResponse['HotelDetails'] = $post['hotelData']['HotelDetails'];
                $HotelDetails = new Zend_Session_Namespace('HotelDetails_' . $HotelId . ' ');
                $HotelDetails->params = $apiResponse;
            }

            // echo "<pre>";
            // print_r(($HotelId));
            // echo "<pre>";
            // print_r(($HotelDetails->params));
            // die;
            $ResponseStatus = $apiResponse['status'];
            if ($ResponseStatus == 1) {
                $html = new Zend_View();
                $html->setScriptPath(APPLICATION_PATH . '/views/scripts/buyhotel/');
                $html->assign(array('apiResponse' => $apiResponse, 'post' => $post));
                $bodyText = $html->render('getapihotelinfo.phtml');
                echo json_encode(['status' => true, 'message' => 'SUCESS', 'bodyText' => $bodyText, 'apiResponse' => $apiResponse, 'post' => $post]);
                exit;
            } else {
                echo json_encode(['status' => false, 'message' => 'Not found']);
                exit;
            }
        }
    }


    public function booknowAction()
    {
        $this->_helper->viewRenderer->setNoRender(true);
        if ($this->_request->isXmlHttpRequest()) {
            $post = json_decode(file_get_contents('php://input'), true);
            if ($post['hotelData'] && $post['searchID'] && $post['RoomInfo']) {
                $searchIDSearch = $post['searchID'];
                $objTempFlight = new Travel_Model_TblFlight();
                $FlightTempData = $objTempFlight->GetFlightTempData($searchIDSearch);
                $arrUrlData = json_decode($FlightTempData['APIBookingData'], true);
                $TPSysId = $FlightTempData['TPSysId'];
                $SearchParams = $arrUrlData['SearchParams'];
                $SearchHotelTraceId = $post['hotelData']['SearchHotelTraceId'];
                $arrUrlData['hotelData'] = $post['hotelData'];
                $arrUrlData['RoomInfo'] = $post['RoomInfo'];

                $arrUrlData['searchids'] = $SearchHotelTraceId;
                $tempData = array(
                    'TraceId' => $SearchHotelTraceId,
                    'TPSysId' => ($TPSysId),
                    'APIBookingData' => json_encode($arrUrlData),
                );
                $objTempFlight->deleteFlightTempData($SearchHotelTraceId);
                $objTempFlight->insertFlightTempData($tempData);

                echo json_encode(['status' => true, 'message' => 'SUCESS', 'SearchTraceId' => $SearchHotelTraceId]);
                exit;
            } else {
                echo json_encode(['status' => false, 'message' => 'Oops somethings went wrong.', 'SearchTraceId' => '']);
                exit;
            }
        }
    }

    public function travellersAction()
    {

        // ini_set('display_errors', 1);
        // ini_set('display_startup_errors', 1);
        // error_reporting(E_ALL);
        $searchIDSearch = $SearchHotelTraceId = $this->view->searchIDSearch = $this->getRequest()->getParam('data');
        $objTempFlight = new Travel_Model_TblFlight();
        $FlightTempData = $objTempFlight->GetFlightTempData($searchIDSearch);
        if ($FlightTempData) {
            $TPSysId = $FlightTempData['TPSysId'];
            $arrUrlData = json_decode($FlightTempData['APIBookingData'], true);
            $hotelData = $arrUrlData['hotelData'];
            $RoomInfo = $arrUrlData['RoomInfo'];
            $SearchParams = $arrUrlData['SearchParams'];
            $B2BSearch = isset($arrUrlData['B2BSearch']) ? $arrUrlData['B2BSearch'] : [];
            $tboCountryCode = $SearchParams['tboCountryCode'];
            $leadId     = $SearchParams['TPSysId'];
            $objFlightProposal = new Travel_Model_TblFlightProposal();
            $crmcustomerObj = new Travel_Model_CRM_Customer();
            $arrAgencyDetails = $this->view->arrAgencyDetails = $objFlightProposal->getProposalAgencyDetails($leadId, 'query');
            $AgencySysId = $arrAgencyDetails['AgencySysId'];
            $AgentSysId = $arrAgencyDetails['AgentSysId'];
            $getAgencyDetail = $crmcustomerObj->GetAgencyDetailById($AgencySysId);
            $SecurityKey = isset($getAgencyDetail['SecurityKey']) ? $getAgencyDetail['SecurityKey'] : 0;


            if ($this->_request->isXmlHttpRequest()) {


                if ($hotelData && $RoomInfo && $searchIDSearch) {

                    $ExtraMarkupArray = [];
                    if ($RoomInfo['Rooms']) {
                        foreach ($RoomInfo['Rooms'] as $Rooms => $values) {
                            $ExtraMarkup = isset($values['ExtraMarkup']) ? ($values['ExtraMarkup']) : 0;
                            $discountVal = isset($values['Discounts']) ? ($values['Discounts']) : 0;
                            $ExtraMarkupArray[$Rooms]['ExtraMarkup'] = ($ExtraMarkup);
                            $ExtraMarkupArray[$Rooms]['Discounts'] = $discountVal;
                        }
                    }

                    $HotelID = $hotelData['HotelId'];
                    $ICSourceSysId = $hotelData['ICSourceSysId'];
                    $RoomId = $RoomInfo['RoomId'];
                    $CityName = $SearchParams['CityName'];
                    $hotelTotalRooms = $SearchParams['hotelTotalRooms'];
                    $tboCountryCode = $SearchParams['tboCountryCode'];
                    $memberDetailsRoom = $SearchParams['memberDetails'];
                    $hotelTotalNights = $SearchParams['hotelTotalNights'];
                    $AdultPax = (int) $SearchParams['totalMemberCount']['AdultPax'];
                    $ChildPax = (int) $SearchParams['totalMemberCount']['ChildPax'];
                    $MemberCount = ($AdultPax + $ChildPax);
                    if ($tboCountryCode != 'IN') {
                        $interNationalSearch = true;
                    } else {
                        $interNationalSearch = false;
                    }
                    if ($ICSourceSysId == 7) {
                        $request = [
                            "hotelId" => $HotelID,
                            "optionId" => $RoomId,
                        ];
                    } else {
                        $request = [
                            "BookingCode" => $RoomId,
                            "PaymentMode" => 'Limit',
                        ];
                    }

                    $DataS = array(
                        "request" => $request,
                        "searchID" => $searchIDSearch,
                        "MemberCount" => $MemberCount,
                        "destination" => $CityName,
                        "nights" => $hotelTotalNights,
                        "rooms" => $hotelTotalRooms,
                        "PlanType" => 2,
                        "ICSourceSysId" => $ICSourceSysId,
                        "B2B" => $B2BSearch,
                        "MPType" => 1,
                        "interNationalSearch" => $interNationalSearch,
                        "ExtraMarkup" => $ExtraMarkupArray,
                        'APIMode' => ($AgencySysId == 1) ? 1 : 0,

                    );


                    $getData['SecurityKey'] = $SecurityKey;
                    $URL = GTX_API_URL . '/hotel/v2/hotelreview';
                    $apiResponse = [];
                    $apiResponse = Zend_Controller_Action_HelperBroker::getStaticHelper("Hotel")->apiHttpRequest($DataS, $getData, $URL);

                    $status = isset($apiResponse['status']) ? $apiResponse['status'] : false;
                    $ErrorMessage = isset($apiResponse['message']) ? $apiResponse['message'] : '';
                    if ($apiResponse && $status) {
                        $arrUrlData['searchids'] = $SearchHotelTraceId;
                        $arrUrlData['hoteldetails'] = $apiResponse;
                        $HotelDetails = $apiResponse['HotelDetails'];
                        $RoomInfo = $apiResponse['RoomInfo'];

                        $IsPANMandatory = ($HotelDetails['IsPANMandatory']);
                        $IsPassportMandatory = ($HotelDetails['IsPassportMandatory']);

                        $TotalBaseFare = 0;
                        $OtherCharges = 0;
                        $TotalTaxesandFee = 0;
                        $TotalDiscount = 0;
                        $GrandTotal = 0;
                        $Currncy = '';
                        $TotalCommissionEarned = 0;
                        $TotalFixedMarkUp = 0;
                        $TotalGSTOnMarkUp = 0;
                        $TotalTDSEarn = 0;
                        $travellers = [];
                        $BaseFareArray = [];
                        if ($memberDetailsRoom) {
                            foreach ($memberDetailsRoom as $key => $values) {
                                $RoomInfoData = $RoomInfo[0]['Rooms'][$key];

                                $Currncy = $RoomInfoData['Currency'];
                                $ConvertionRate = $RoomInfoData['ConvertionRate'];
                                $BaseFare = ($RoomInfoData['TotalBaseFare'] * $ConvertionRate);
                                $TotalBaseFare += ($RoomInfoData['TotalBaseFare'] * $ConvertionRate);
                                $OtherCharges = isset($RoomInfoData['OtherCharges']) ? $RoomInfoData['OtherCharges'] : 0;
                                $TotalFixedMarkUp += ($RoomInfoData['FixedMarkUp'] * $ConvertionRate);
                                $TotalGSTOnMarkUp += ($RoomInfoData['GSTOnMarkUp'] * $ConvertionRate);
                                $TotalTaxesandFee += (($RoomInfoData['TotalTaxFare'] + $OtherCharges) * $ConvertionRate);
                                $adultCount = isset($values['AdultPax']) ? $values['AdultPax'] : 1;
                                $childCount = isset($values['ChildPax']) ? $values['ChildPax'] : 0;
                                $childAge = (isset($values['ChildsAge']) && !empty($values['ChildsAge'])) ? explode(',', $values['ChildsAge']) : [];
                                $memberDetails = [];
                                if ($adultCount > 0) {
                                    $intPaxCount = 1;
                                    for ($i = 0; $i < $adultCount; $i++) {
                                        $memberDetails[$i]['index'] = $i;
                                        $memberDetails[$i]['room'] = ($key + 1);
                                        $memberDetails[$i]['PaxCount'] = $intPaxCount;
                                        $memberDetails[$i]['PaxType'] = 1;
                                        $memberDetails[$i]['pax'] = 'ADULT';
                                        $memberDetails[$i]['AgeR'] = '12 yrs+';
                                        $memberDetails[$i]['cid'] = 0;
                                        $memberDetails[$i]['fname'] = '';
                                        $memberDetails[$i]['lname'] = '';
                                        $memberDetails[$i]['name'] = '';
                                        $memberDetails[$i]['title'] = '';
                                        $memberDetails[$i]['dob'] = '';
                                        $memberDetails[$i]['passno'] = '';
                                        $memberDetails[$i]['passisse'] = '';
                                        $memberDetails[$i]['passexp'] = '';
                                        $memberDetails[$i]['panno'] = '';
                                        $memberDetails[$i]['passnational'] = 'IN';
                                        $memberDetails[$i]['isdobr'] = false;
                                        $memberDetails[$i]['IsPassM'] = $IsPassportMandatory;
                                        $memberDetails[$i]['addonns'] = true;
                                        $memberDetails[$i]['checked'] = ($i == 1) ? true : false;
                                        $memberDetails[$i]['IsPAN'] = $IsPANMandatory;
                                        $intPaxCount++;
                                    }
                                }
                                if ($childCount > 0) {
                                    $intPaxCount = 1;
                                    $CH = 0;
                                    for ($kk = $i; $kk < ($childCount + $adultCount); $kk++) {
                                        $AGE = isset($childAge[$CH]) ? $childAge[$CH] : '';
                                        $memberDetails[$kk]['index'] = $kk;
                                        $memberDetails[$kk]['room'] = ($key + 1);
                                        $memberDetails[$kk]['PaxCount'] = $intPaxCount;
                                        $memberDetails[$kk]['PaxType'] = 2;
                                        $memberDetails[$kk]['pax'] = 'CHILD';
                                        $memberDetails[$kk]['AgeR'] = '2-12 Yrs';
                                        $memberDetails[$kk]['Age'] = $AGE;
                                        $memberDetails[$kk]['cid'] = 0;
                                        $memberDetails[$kk]['fname'] = '';
                                        $memberDetails[$kk]['lname'] = '';
                                        $memberDetails[$kk]['name'] = '';
                                        $memberDetails[$kk]['title'] = '';
                                        $memberDetails[$kk]['dob'] = '';
                                        $memberDetails[$kk]['passno'] = '';
                                        $memberDetails[$kk]['passisse'] = '';
                                        $memberDetails[$kk]['passexp'] = '';
                                        $memberDetails[$kk]['panno'] = '';
                                        $memberDetails[$kk]['passnational'] = 'IN';
                                        $memberDetails[$kk]['isdobr'] = false;
                                        $memberDetails[$kk]['IsPassM'] = $IsPassportMandatory;
                                        $memberDetails[$kk]['addonns'] = true;
                                        $memberDetails[$kk]['checked'] = false;
                                        $memberDetails[$kk]['IsPAN'] = false;
                                        $intPaxCount++;
                                        $CH++;
                                    }
                                }
                                $travellers[$key]['RoomType'] = ['name' => $RoomInfoData['RoomType'], 'MealBase' => $RoomInfoData['MealBase']];
                                $travellers[$key]['memberDetails'] = $memberDetails;
                                $BaseFareArray[$key] = ['BaseFare' => $BaseFare, 'name' => $RoomInfoData['RoomType'], 'MealBase' => $RoomInfoData['MealBase']];
                            }
                        }

                        $fare = array(
                            'Currncy' => $Currncy,
                            'BaseFare' => round($TotalBaseFare, 2),
                            'TaxesandFee' => round($TotalTaxesandFee, 2),
                            'GrandTotal' => round($TotalBaseFare + $TotalTaxesandFee + $TotalFixedMarkUp + $TotalGSTOnMarkUp, 2),
                            'CommissionEarned' => round($TotalCommissionEarned, 2),
                            'TDSEarn' => round($TotalTDSEarn, 2),
                            'Discount' => round($TotalDiscount, 2),
                            'FixedMarkUp' => round($TotalFixedMarkUp, 2),
                            'GSTOnMarkUp' => round($TotalGSTOnMarkUp, 2),
                            'roomCoun' => $hotelTotalRooms,
                            'nightCoun' => ($hotelTotalNights),
                            'BaseFareArray' => ($BaseFareArray),
                        );
                        $TotalPay = ceil($TotalBaseFare + $TotalTaxesandFee + $TotalFixedMarkUp + $TotalGSTOnMarkUp);
                        // echo "<pre>";
                        // print_r(($TotalPay));
                        // print_r(($fare));
                        // echo "</pre>";
                        $tempData = array(
                            'TraceId' => $SearchHotelTraceId,
                            'TPSysId' => ($TPSysId),
                            'APIBookingData' => json_encode($arrUrlData),
                        );
                        $objTempFlight->deleteFlightTempData($SearchHotelTraceId);
                        $objTempFlight->insertFlightTempData($tempData);
                        echo json_encode(['status' => true, 'message' => 'SUCESS', 'fare' => $fare, 'travellers' => $travellers, 'hoteldetails' => $HotelDetails, 'RoomInfo' => $RoomInfo, 'SearchParams' => $SearchParams]);
                        exit;
                    } else {
                        echo json_encode(['status' => false, 'message' => $ErrorMessage, 'SearchTraceId' => '']);
                        exit;
                    }

                    // echo "<pre>";
                    // print_r($getData);
                    // echo "</pre>";
                    // exit;
                } else {
                    echo json_encode(['status' => false, 'message' => 'Oops somethings went wrong.', 'SearchTraceId' => '']);
                    exit;
                }
            }
            // echo "<pre>";
            // print_r(($arrAgencyDetails));
            // die;
            $objMarkup = new Markup_Model_Markup();
            if (!empty(trim($tboCountryCode)) && trim($tboCountryCode) != "IN") {
                $intAirType = 2;
            } else {
                $intAirType = 1;
            }
            $arrAgencyUserDetail = $objMarkup->getAgencyUserDetail(array("AgencySysId" => $AgencySysId, "ItemSourceType" => (int) $intAirType, "PlanType" => 2));
            $this->view->arrAgencyUserDetail = $arrAgencyUserDetail;
            $crmcustomerObj = new Travel_Model_CRM_Customer();
            $customerDetails = isset($SearchParams['customerId']) ? $crmcustomerObj->GetAgencyCustomerById(trim($SearchParams['customerId'])) : '';
            $this->view->arrTrevllerDetails = $customerDetails;
            $this->view->searchID = $searchIDSearch;
            $this->view->hotelData = $hotelData;
            $this->view->RoomInfo = $RoomInfo;
            $this->view->SearchParams = $SearchParams;
            $this->view->arrTrevllerDetails = $customerDetails;
            $this->view->AgencySysId = $AgencySysId;
            // echo "<pre>";
            // print_r(($arrAgencyUserDetail));
            // die;
        } else {

            echo json_encode(['status' => false, 'message' => 'Invalid request', 'SearchTraceId' => '']);
            exit;
        }
    }

    public function savePassengerDetailsAction()
    {
        if ($this->getRequest()->isXmlHttpRequest()) {
            // ini_set('display_errors', 1);
            // ini_set('display_startup_errors', 1);
            // error_reporting(E_ALL);
            $objFlight = new Travel_Model_TblFlight();
            $this->_helper->layout->disableLayout();
            $post = json_decode(file_get_contents('php://input'), true);
            parse_str($post['data'], $data);

            $memberDetails = isset($post['travellers']) ? $post['travellers'] : [];
            $countryCodeISO = strtoupper($data['countryCodeISO']);
            $countrycode = $countryCode = $data['countrycode'];
            $mobileNumber = $leadMobile = $data['mobile_number'];
            $email_id = $leadEmail = $data['email_id'];
            $airline_number = $data['airline_number'];
            $airline_email = $data['airline_email'];
            $specialrequest = $data['specialrequest'];
            $isgstapply = $data['isgstapply'];
            $gstnnumber = $data['gstnnumber'];
            $companyname = $data['companyname'];
            $gstemail = $data['gstemail'];
            $gstphone = $data['gstphone'];
            $gstaddress = $data['gstaddress'];
            $gststate = $data['gststate'];
            $searchIDSearch = $BookingID = $post['searchids'];

            $objTempFlight = new Travel_Model_TblFlight();
            $FlightTempData = $objTempFlight->GetFlightTempData($searchIDSearch);
            $TPSysId = $FlightTempData['TPSysId'];
            $arrUrlData = json_decode($FlightTempData['APIBookingData'], true);
            $hoteldetails = $arrUrlData['hoteldetails'];
            $SearchParams = $arrUrlData['SearchParams'];
            $leadId     = $SearchParams['TPSysId'];
            $objFlightProposal = new Travel_Model_TblFlightProposal();
            $crmcustomerObj = new Travel_Model_CRM_Customer();
            $arrAgencyDetails = $this->view->arrAgencyDetails = $objFlightProposal->getProposalAgencyDetails($leadId, 'query');
            $AgencySysId = $arrAgencyDetails['AgencySysId'];
            $AgentSysId = $arrAgencyDetails['AgentSysId'];
            $getAgencyDetail = $crmcustomerObj->GetAgencyDetailById($AgencySysId);
            $SecurityKey = isset($getAgencyDetail['SecurityKey']) ? $getAgencyDetail['SecurityKey'] : 0;
            // echo "<pre>post";
            // print_r(($getAgencyDetail));
            // echo "<pre>post";
            // print_r(($AgencySysId));
            // die;

            if (empty($mobileNumber)) {
                $response = array('success' => false, 'message' => 'Please enter mobile number.', 'index' => 'airline_number');
                echo json_encode($response);
                exit;
            }

            if (strlen($mobileNumber) != 10 && strlen($mobileNumber) != 11) {
                $response = array('success' => false, 'message' => 'Please enter a valid mobile number.', 'index' => 'mobile_number');
                echo json_encode($response);
                exit;
            }
            if (empty($email_id)) {
                $response = array('success' => false, 'message' => 'Please enter Email ID.', 'index' => 'email_id');
                echo json_encode($response);
                exit;
            }

            if (!filter_var($email_id, FILTER_VALIDATE_EMAIL)) {
                $msg = "Email address is not valid.";
                $response = array('success' => false, 'message' => $msg, 'index' => 'email_id');
                echo json_encode($response);
                exit;
            }

            $memberData = [];
            if ($memberDetails) {
                foreach ($memberDetails as $k => $val) {
                    foreach ($val['memberDetails'] as $i => $value) {
                        $firstName = $fname = $data['fname-' . $k . '-' . $i];
                        $lastName = $data['lname-' . $k . '-' . $i];
                        $relation = 9; //$data['relation-' . $i];
                        $salutation = $data['title-' . $k . '-' . $i];
                        $panno = $data['panno-' . $k . '-' . $i];
                        //$passengerDob = isset($data['dob-' . $k . '-' . $i]) ? $data['dob-' . $k . '-' . $i] : '';
                        $nationality = ''; //isset($data['passenger-nationality-' . $k . '-' . $i]) ? $data['passenger-nationality-' . $k . '-' . $i] : '';
                        $passengerPassportNo = isset($data['passno-' . $k . '-' . $i]) ? $data['passno-' . $k . '-' . $i] : '';
                        $PassportExpiry = isset($data['passexp-' . $k . '-' . $i]) ? $data['passexp-' . $k . '-' . $i] : '';
                        $passporIssue = isset($data['passisse-' . $k . '-' . $i]) ? $data['passisse-' . $k . '-' . $i] : '';
                        //$passengerDob = Zend_Controller_Action_HelperBroker::getStaticHelper('DateFormat')->cal2Db($passengerDob, 'd/m/y');
                        $passporIssue = Zend_Controller_Action_HelperBroker::getStaticHelper('DateFormat')->cal2Db($passporIssue, 'd/m/y');
                        $PassportExpiry = Zend_Controller_Action_HelperBroker::getStaticHelper('DateFormat')->cal2Db($PassportExpiry, 'd/m/y');

                        $memberData[$k][$i] = $value;
                        $memberData[$k][$i]['relation'] = $relation;
                        $memberData[$k][$i]['title'] = $salutation;
                        $memberData[$k][$i]['panno'] = $panno;
                        $memberData[$k][$i]['passno'] = $passengerPassportNo;
                        $memberData[$k][$i]['passisse'] = $passporIssue;
                        $memberData[$k][$i]['passexp'] = $PassportExpiry;
                        $memberData[$k][$i]['passnational'] = $nationality;
                        $memberData[$k][$i]['fname'] = $firstName;
                        $memberData[$k][$i]['lname'] = $lastName;
                        $memberData[$k][$i]['name'] = $firstName . ' ' . $lastName;
                        //$memberData[$k][$i]['dob'] = $passengerDob;
                        $memberData[$k][$i]['countrycode'] = $countrycode;
                        $memberData[$k][$i]['countryCodeISO'] = $countryCodeISO;

                        if (empty($salutation)) {
                            $response = array('success' => false, 'message' => 'Please select title.', 'index' => 'title-' . $k . '-'  . $i);
                            echo json_encode($response);
                            exit;
                        }
                        if (empty($firstName)) {
                            $response = array('success' => false, 'message' => 'Please enter first name.', 'index' => 'fname-' . $k . '-'  . $i);
                            echo json_encode($response);
                            exit;
                        }

                        if (empty($lastName)) {
                            $response = array('success' => false, 'message' => 'Please enter last name.', 'index' => 'lname-' . $k . '-'  . $i);
                            echo json_encode($response);
                            exit;
                        }
                        $pattern = "/^[A-Z]{5}[0-9]{4}[A-Z]{1}$/";
                        if ($value['PaxType'] == 1 && $value['IsPAN'] == 1 && empty($panno)) {
                            $response = array('success' => false, 'message' => 'Please enter PAN number.', 'index' => 'panno-' . $k . '-'  . $i);
                            echo json_encode($response);
                            exit;
                        }
                        if (!preg_match($pattern, $panno) && $value['PaxType'] == 1 && $value['IsPAN'] == 1) {
                            $response = array('success' => false, 'message' => 'Enter valid PAN number.', 'index' => 'panno-' . $k . '-'  . $i);
                            echo json_encode($response);
                            exit;
                        }

                        if ($value['IsPassM'] == 1) {
                            if (empty($passengerPassportNo)) {
                                $response = array('success' => false, 'message' => 'Please enter Passpost number.', 'index' => 'passno-' . $k . '-'  . $i);
                                echo json_encode($response);
                                exit;
                            }
                            if (empty($passporIssue)) {
                                $response = array('success' => false, 'message' => 'Please enter Passpost Issue Date.', 'index' => 'passisse-' . $k . '-'  . $i);
                                echo json_encode($response);
                                exit;
                            }
                            if (empty($PassportExpiry)) {
                                $response = array('success' => false, 'message' => 'Please enter Passpost Expiry Date.', 'index' => 'passexp-' . $k . '-'  . $i);
                                echo json_encode($response);
                                exit;
                            }
                        }
                    }
                }
            }

            $ForCustomerSession = [];
            if ($memberData) {
                foreach ($memberData as $keyss => $value) {
                    foreach ($value as $key => $val) {
                        $ForCustomerSession[] = $val;
                    }
                }
            }

            $ICSourceSysId = $hoteldetails['HotelDetails']['ICSourceSysId'];
            $currencySysId = isset($hoteldetails['HotelDetails']['currencySysId']) ? $hoteldetails['HotelDetails']['currencySysId'] : 1;
            $Currency = isset($hoteldetails['HotelDetails']['Currency']) ? $hoteldetails['HotelDetails']['Currency'] : '';

            $SearchParams = $arrUrlData['SearchParams'];
            $tboCountryCode = $SearchParams['tboCountryCode'];
            $memberDetailsSearch = $SearchParams['memberDetails'];
            $hotelTotalNights = $SearchParams['hotelTotalNights'];
            $cityId = $SearchParams['tboCityId'];
            $hotelXrefCityId = $SearchParams['hotelXrefCityId'];
            $CityName = $SearchParams['CityName'];
            $countrySysId = $SearchParams['countrySysId'];
            $checkin = $SearchParams['hotelFromDateSession'];
            // echo "<pre>";
            // print_r(($SearchParams));
            // die;
            $intCustomerSysId = isset($SearchParams['customerId']) ? $SearchParams['customerId'] : 0;
            $crmcustomerObj = new Travel_Model_CRM_Customer();
            $customerDetails = $crmcustomerObj->GetAgencyCustomerById($intCustomerSysId);
            $AgencySysId__ = isset($customerDetails['AgencySysId']) ? $customerDetails['AgencySysId'] : 0;
            $IsB2BCustomer = isset($customerDetails['IsB2BAgent']) ? $customerDetails['IsB2BAgent'] : 0;
            $IsEnabledWallet = isset($customerDetails['IsEnabledWallet']) ? $customerDetails['IsEnabledWallet'] : 0;
            $CustomerSysId = isset($customerDetails['CustomerSysId']) ? $customerDetails['CustomerSysId'] : 0;

            $AgentUserDetail = $crmcustomerObj->getAgentDetailById($AgencySysId__);
            $UserSysId = isset($AgentUserDetail[0]['UserSysId']) ? $AgentUserDetail[0]['UserSysId'] : 0;

            $checkin = Zend_Controller_Action_HelperBroker::getStaticHelper('DateFormat')->cal2Db($checkin, 'd/m/y');
            $checkout = $SearchParams['hotelToDateSession'];
            $checkout = Zend_Controller_Action_HelperBroker::getStaticHelper('DateFormat')->cal2Db($checkout, 'd/m/y');
            $CancelArr = isset($hoteldetails['RoomInfo'][0]['CancelArr']) ? $hoteldetails['RoomInfo'][0]['CancelArr'] : [];
            $HotelFaciality = (isset($hoteldetails['HotelDetails']['HotelFaciality']) && !empty($hoteldetails['HotelDetails']['HotelFaciality'])) ? $hoteldetails['HotelDetails']['HotelFaciality'] : [];
            $Instruction = isset($hoteldetails['HotelDetails']['Instruction']) ? $hoteldetails['HotelDetails']['Instruction'] : [];
            $insts = isset($hoteldetails['HotelDetails']['inst'][0]) ? $hoteldetails['HotelDetails']['inst'][0] : [];
            $HotelDescription = isset($hoteldetails['HotelDetails']['HotelDescription']) ? $hoteldetails['HotelDetails']['HotelDescription'] : '';
            $HotelImages = isset($hoteldetails['HotelDetails']['HotelImages']) ? $hoteldetails['HotelDetails']['HotelImages'] : '';
            $IsPANMandatory = ($hoteldetails['HotelDetails']['IsPANMandatory']);
            $IsPassportMandatory = ($hoteldetails['HotelDetails']['IsPassportMandatory']);

            $f = 1;
            $roomjson = [];
            $bookingrequest = [];
            $adultcount = 0;
            $childcount = 0;
            $rooms = 0;
            if ($memberDetailsSearch) {
                foreach ($memberDetailsSearch as $key => $pax) {
                    $adultcount += $pax['AdultPax'];
                    $childcount += $pax['ChildPax'];
                    $TotAdultCount = isset($pax['AdultPax']) ? trim($pax['AdultPax']) : 0;
                    $TotChildCount = isset($pax['ChildPax']) ? $pax['ChildPax'] : 0;


                    $roomjson[$f]['Adult']  = $TotAdultCount;
                    $roomjson[$f]['Child']  = $TotChildCount;
                    $roomjson[$f]['Infant']  = 0;
                    $roomjson[$f]['bedtype'] = '';
                    $roomjson[$f]['departuredate'] = date('d/m/Y',  strtotime($checkin));
                    $roomjson[$f]['returndate'] = '';
                    $roomjson[$f]['fromaircode'] = '';
                    $roomjson[$f]['toaircode'] = '';
                    $roomjson[$f]['airclass'] = '';
                    $f++;
                }
            }

            $Instructionarray = [];
            if (!empty($insts)) {
                $Instruction = array_merge($insts, $Instruction);
            } else {
                $Instruction = $Instruction;
            }

            if ($Instruction) {
                foreach ($Instruction as $inst) {
                    if ($this->json_validate($inst['msg'])) {
                        $msg = (isset($inst['msg']) && !empty($inst['msg'])) ? json_decode($inst['msg'], 1) : [];
                    } else {
                        $msg = ['' => $inst['msg']];
                    }
                    foreach ($msg as $key => $value) {
                        $Instructionarray[] = array(
                            'types' => $inst['type'],
                            'name' => $key,
                            'description' => $value,
                        );
                    }
                }
            }
            $HotelFacialityArray = [];
            if ($HotelFaciality) {
                foreach ($HotelFaciality as $value) {
                    $HotelFacialityArray[] = array(
                        'name' => $value,
                    );
                }
            }
            if ($CancelArr) {
                foreach ($CancelArr as $value) {
                    $CancelArray[] = array(
                        'fromdate' => (isset($value['fromddate']) && !empty($value['fromddate'])) ? date('Y-m-d H:i:s', strtotime($value['fromddate'])) : '',
                        'todate' => (isset($value['todate'])  && !empty($value['todate'])) ? date('Y-m-d H:i:s', strtotime($value['todate'])) : '',
                        'amount' => $value['am'],
                        'servicefee' => isset($value['servicefee']) ? $value['servicefee'] : 0,
                        'Currency' => $value['Currency'],
                        'LastCancellationDate' => (isset($value['LastCancellationDate']) && !empty($value['LastCancellationDate'])) ? date('Y-m-d H:i:s', strtotime($value['LastCancellationDate'])) : '',
                        'Isfullrefundallowed' => isset($value['Isfullrefundallowed']) ? $value['Isfullrefundallowed'] : false,
                    );
                }
            }
            $ImageArray = [];
            if ($HotelImages) {
                foreach ($HotelImages as $img) {
                    $ImageArray[] = array(
                        'ImageURL' => isset($img['url']) ? $img['url'] : '',
                        'sizes' => isset($img['sz']) ? $img['sz'] : '',
                    );
                }
            }
            $AgencySysId = $AgencySysId;
            $arrayCancellation = '';
            $HotelAddress = $hoteldetails['HotelDetails']['HotelAddress'];
            // $HotelAddress = $hoteldetails['HotelDetails']['HotelAddress'] . ', ' . $hoteldetails['HotelDetails']['HotelCity'] . ', ' . $hoteldetails['HotelDetails']['HotelCountry'] . ' - ' . $hoteldetails['HotelDetails']['postalCode'];
            $HotelDetails = array(
                'cancellationPolicy' => $arrayCancellation,
                'AgencySysId' => $AgencySysId,
                'TraceId' => $BookingID,
                'ConfirmationNo' => '',
                'CheckInDate' => $checkin,
                'CheckOutDate' => $checkout,
                'BookingRefNo' => '',
                'BookingId' => $BookingID,
                'APIBookingId' => $hoteldetails['HotelDetails']['bookingId'],
                'HotelBookingStatus' => '',
                'ResultIndex' => $hoteldetails['HotelDetails']['HotelId'],
                'HotelName' => $hoteldetails['HotelDetails']['HotelName'],
                'HotelCode' => $hoteldetails['HotelDetails']['HotelId'],
                'HotelDescription' => $HotelDescription,
                'StarRating' => $hoteldetails['HotelDetails']['HotelStars'],
                'Currency' => $Currency,
                // 'HotelPicture' => isset($hoteldetails['HotelDetails']['HotelImages'][0]['tns']) ? $hoteldetails['HotelDetails']['HotelImages'][0]['tns'] : $hoteldetails['HotelDetails']['HotelImages'][0]['url'],
                'HotelPicture' => isset($hoteldetails['HotelDetails']['HotelImages'][0]['tns']) ? $hoteldetails['HotelDetails']['HotelImages'][0]['tns'] : ($hoteldetails['HotelDetails']['HotelImages'][0]['url'] ?? ''),
                'HotelAddress' => $HotelAddress,
                'HotelContactNo' => isset($hoteldetails['HotelDetails']['HotelContact']['ph']) ? $hoteldetails['HotelDetails']['HotelContact']['ph'] : '',
                'HotelMap' => $hoteldetails['HotelDetails']['HotelAddress'],
                'Latitude' => $hoteldetails['HotelDetails']['HotelGeioLocation']['ln'],
                'Longitude' => $hoteldetails['HotelDetails']['HotelGeioLocation']['lt'],
                'HotelLocation' => isset($hoteldetails['HotelDetails']['location']) ? $hoteldetails['HotelDetails']['location'] : '',
                'PinCode' => isset($hoteldetails['HotelDetails']['postalCode']) ? $hoteldetails['HotelDetails']['postalCode'] : '',
                'Remarks' => $specialrequest,
                'NoOfNights' => $hotelTotalNights,
                'NoOfRooms' => $rooms,
                'totaladult' => $adultcount,
                'totalchild' => $childcount,
                'memberdata' => json_encode($roomjson),
                'facility' => ($HotelFacialityArray),
                'cancellation' => ($CancelArray),
                'instruction' => ($Instructionarray),
                'images' => ($ImageArray),
                'TBBCityId' => $cityId,
                'cityid' => $cityId,
                'ContSysId' => $countrySysId,
                'cityName' => !empty($hoteldetails['HotelDetails']['HotelCity']) ? $hoteldetails['HotelDetails']['HotelCity'] : $CityName,
                'HotelCountry' => !empty($hoteldetails['HotelDetails']['HotelCountry']) ? $hoteldetails['HotelDetails']['HotelCountry'] : '',
                'gtxcity' => !empty($hotelXrefCityId) ? $hotelXrefCityId : 0,
                'IsMarkForDel' => '0',
                'created_at' => date('Y-m-d H:i:s'),
                'updated_at' => date('Y-m-d H:i:s'),
            );
            // echo "<pre>";
            // print_r(($HotelDetails));
            // echo "<pre>";
            // print_r(($hoteldetails['HotelDetails']));
            // die;

            $ARR_SALUTIONTBO = unserialize(ARR_SALUTIONTBO);

            $ARR_SALUTION = array_flip($ARR_SALUTIONTBO);
            $ARR_SALUTION_CHILD = array_flip($ARR_SALUTIONTBO);
            $ConvertionRate = 1;
            $index = 0;
            $booking_room_data = [];
            $TotalBaseFare = 0;
            $TotalTaxesandFee = 0;
            $OtherCharges = 0;
            $TotalDiscount = 0;
            $GrandTotal = 0;
            $Currncy = '';
            $TotalCommissionEarned = 0;
            $TotalFixedMarkUp = 0;
            $TotalGSTOnMarkUp = 0;
            $TotalTDSEarn = 0;
            $roomtravellerinfo = [];
            $hotelPassengerArr = [];
            $HotelRoomsDetails_TBO = [];
            if ($memberDetailsSearch) {
                foreach ($memberDetailsSearch as $key => $mem) {
                    $RoomInfo = $hoteldetails['RoomInfo'][0]['Rooms'][$key];
                    $OtherCharges = isset($RoomInfo['OtherCharges']) ? $RoomInfo['OtherCharges'] : 0;
                    $TotalPrice = ($RoomInfo['TotalBaseFare'] + $RoomInfo['FixedMarkUp'] + $RoomInfo['FixedMarkUp'] + $RoomInfo['GSTOnMarkUp'] + $RoomInfo['TotalTaxFare'] + $OtherCharges);
                    $RoomInfoData = [];

                    $RoomInfoData['numberOfAdults'] = $mem['AdultPax'];
                    $RoomInfoData['numberOfChild'] = $mem['ChildPax'];
                    $mem['numberOfAdults'] = $mem['AdultPax'];
                    $mem['numberOfChild'] = $mem['ChildPax'];

                    $IntmemberData = isset($memberData[$key]) ? $memberData[$key] : [];

                    $ConvertionRate = $RoomInfo['ConvertionRate'];
                    $HotelRoomsDetails = array(
                        'AgencySysId' => $AgencySysId,
                        'TraceId' => $BookingID,
                        'NoOfAdults' => $RoomInfoData['numberOfAdults'],
                        'NoOfChild' => $RoomInfoData['numberOfChild'],
                        'RoomIndex' => $key,
                        'RoomTypeCode' => $RoomInfo['id'],
                        'RoomTypeName' => $RoomInfo['RoomType'],
                        'RatePlanCode' => $RoomInfo['MealBase'],
                        'RatePlanName' => $RoomInfo['RoomCategory'],
                        'RatePlan' => isset($RoomInfo['RatePlan']) ? $RoomInfoData['RatePlan'] : '0',
                        'LastCancellationDate' => isset($RoomInfo['LastCancellationDate']) ? date('Y-m-d H:i:s', strtotime($RoomInfo['LastCancellationDate'])) : '',
                        'LastVoucherDate' => NULL,
                        'BedTypeCode' => null,
                        'SmokingPreference' => 0,
                        'CurrencyType' => $currencySysId,
                        'Currency' => $RoomInfo['Currency'],
                        'RoomPrice' => $RoomInfo['TotalBaseFare'] * $ConvertionRate,
                        'TotalPrice' => ($TotalPrice * $ConvertionRate),
                        'TaxesServiceFee' => (($RoomInfo['TotalTaxFare'] + $OtherCharges) * $ConvertionRate),
                        'intCostToCustomer' => ($TotalPrice * $ConvertionRate),
                        'AgencyMarkUp' => $RoomInfo['FixedMarkUp'] * $ConvertionRate,
                        'ServiceTaxOnAgencyMarkUp' => $RoomInfo['GSTOnMarkUp'] * $ConvertionRate,
                        'PublishedPrice' => $TotalPrice * $ConvertionRate,
                        'OfferedPrice' => $RoomInfo['TotalNetFare'] * $ConvertionRate,
                        // 'Discounts' => isset($RoomInfo['couponVal']) ? $RoomInfo['couponVal'] * $ConvertionRate : 0,
                        'Discounts' => isset($RoomInfo['couponVal']) ? $RoomInfo['couponVal']  : 0,
                        'IsMarkForDel' => '0',
                        'created_at' => date('Y-m-d H:i:s'),
                        'updated_at' => date('Y-m-d H:i:s'),
                    );

                    $TotalBaseFare += $RoomInfo['TotalBaseFare'] * $ConvertionRate;
                    $TotalFixedMarkUp += $RoomInfo['FixedMarkUp'] * $ConvertionRate;
                    $TotalGSTOnMarkUp += $RoomInfo['GSTOnMarkUp'] * $ConvertionRate;
                    $OtherCharges = isset($RoomInfo['OtherCharges']) ? $RoomInfo['OtherCharges'] : 0;
                    $TotalTaxesandFee += (($RoomInfo['TotalTaxFare'] + $OtherCharges) * $ConvertionRate);
                    // $TotalDiscount += isset($RoomInfo['couponVal']) ? $RoomInfo['couponVal'] * $ConvertionRate : 0;
                    $TotalDiscount += isset($RoomInfo['couponVal']) ? $RoomInfo['couponVal']  : 0;
                    ///$Currncy = 'INR';
                    $Currncy = $RoomInfo['Currency'];
                    $booking_room_data[$key] = $HotelRoomsDetails;
                    $HotelPassenger = [];
                    $travellerInfo = array();
                    if ($mem['numberOfAdults']) {
                        for ($a = 0; $a < $mem['numberOfAdults']; $a++) {
                            $index++;
                            $ind = ($index - 1);
                            if ($a == 0) {
                                $LeadPassenger = true;
                            } else {
                                $LeadPassenger = false;
                            }

                            $HotelPassenger[$a] = array(
                                'AgencySysId' => $AgencySysId,
                                'EmailId' => $leadEmail,
                                'Salutation' => $ARR_SALUTION[$IntmemberData[$a]['title']],
                                'Title' =>  isset($IntmemberData[$a]['title']) ? $IntmemberData[$a]['title'] : '',
                                'Contacts' => $leadMobile,
                                'Relation' => 9,
                                'FirstName' => $IntmemberData[$a]['fname'],
                                'LastName' => $IntmemberData[$a]['lname'],
                                'panno' => isset($IntmemberData[$a]['panno']) ? $IntmemberData[$a]['panno'] : '',
                                'Age' => 0,
                                'IsPswExpire' => 0,
                                'CreatedByUserSysId' => $AgencySysId,
                                'Address' => 'Not Required',
                                'CityTitle' => 'Not Required',
                                'CitySysId' => 0,
                                'paxType' => $IntmemberData[$a]['PaxType'],
                                'IsPassM' => $IntmemberData[$a]['IsPassM'],
                                'StateOrZoneSysId' => 0,
                                'CountrySysId' => 0,
                                'countryCode' => $countryCode,
                                'RegisterDate' => date('Y-m-d H:i:s'),
                                'IsApproved' => '0',
                                'IsActive' => '1',
                                'IsMarkForDel' => '0',
                                'created_at' => date('Y-m-d H:i:s'),
                                'updated_at' => date('Y-m-d H:i:s'),
                            );
                            if (!empty($IntmemberData[$a]['passno']) && $IntmemberData[$a]['IsPassM'] == 1) {
                                $HotelPassenger[$a]['passportnoexpiry'] = $IntmemberData[$a]['passexp'];
                                $HotelPassenger[$a]['passporIssue'] = $IntmemberData[$a]['passisse'];
                                $HotelPassenger[$a]['passportno'] = $IntmemberData[$a]['passno'];
                            }
                            if ($ind == 0) {
                                $HotelPassenger[$a]['GTX_customerSysId'] = isset($apiCustomer['Message']) ? $apiCustomer['Message'] : 0;
                            } else {
                                $HotelPassenger[$a]['GTX_customerSysId'] = isset($apiCustomer['memberId'][($ind - 1)]) ? $apiCustomer['memberId'][($ind - 1)] : 0;
                            }

                            $traveller['fN'] = $IntmemberData[$a]['fname'];
                            $traveller['lN'] =  $IntmemberData[$a]['lname'];
                            $traveller['ti'] = trim($IntmemberData[$a]['title']);
                            $traveller['pt'] = 'ADULT';

                            // echo '<pre>';
                            // print_r($IntmemberData[$a]);
                            // echo '</pre>';
                            if ($IntmemberData[$a]['IsPAN'] == 1) {
                                $traveller['pan'] = $IntmemberData[$a]['panno'];
                            }
                            if ($IntmemberData[$a]['IsPassM'] == 1) {
                                if (!empty($IntmemberData[$a]['passno'])) {
                                    $traveller['pNum'] = $IntmemberData[$a]['passno'];
                                }
                            }
                            $travellerInfo[] = $traveller;
                            $HotelPassenger[$a]['apiTraceId'] = $BookingID;
                            if ($ICSourceSysId == 3) {
                                $expDate = isset($memberData[$a]['passexp']) ? date('Y-m-d', strtotime($memberData[$a]['passexp'])) : '';
                                $issueDate = isset($memberData[$a]['passisse']) ? date('Y-m-d', strtotime($memberData[$a]['passisse'])) : '';
                                if ($a == 0) {
                                    $LeadPassenger = true;
                                } else {
                                    $LeadPassenger = false;
                                }
                                $hotelPassengerArr[$key]["paxes"][$a] = array(
                                    'Title' => trim($IntmemberData[$a]['title']),
                                    'FirstName' => $IntmemberData[$a]['fname'],
                                    'Middlename' => null,
                                    'LastName' => $IntmemberData[$a]['lname'],
                                    'Phoneno' => $leadMobile,
                                    'Email' => $leadEmail,
                                    'PaxType' => 1,
                                    'LeadPassenger' => $LeadPassenger,
                                    'PAN' => ($IsPANMandatory == 1) ? $IntmemberData[$a]['panno'] : null,
                                    'Age' => 0,

                                    "PaxId" => $a,
                                    // "GSTCompanyAddress" => null,
                                    // "GSTCompanyContactNumber" => null,
                                    // "GSTCompanyName" => null,
                                    // "GSTNumber" => null,
                                    // "GSTCompanyEmail" => null,

                                );
                                if ($IsPassportMandatory == 1) {
                                    $hotelPassengerArr[$key]["paxes"][$a]['PassportNo'] = isset($IntmemberData[$a]['passno']) ? $IntmemberData[$a]['passno'] : '';
                                    $hotelPassengerArr[$key]["paxes"][$a]['PassportIssueDate'] = isset($IntmemberData[$a]['passisse']) ? date('Y-m-d', strtotime($IntmemberData[$a]['passisse'])) . 'T00: 00: 00' : '';
                                    $hotelPassengerArr[$key]["paxes"][$a]['PassportExpDate'] = isset($IntmemberData[$a]['passexp']) ? date('Y-m-d', strtotime($IntmemberData[$a]['passexp'])) . 'T00: 00: 00' : '';
                                }
                            }
                        }
                    }


                    if ($mem['numberOfChild'] > 0) {
                        $ch = 0;
                        if ($ICSourceSysId == 3) {
                            $ChildAge = explode(',', $mem['ChildsAge']);
                        } else {
                            $ChildAge = explode(',', $mem['ChildsAge']);
                        }

                        for ($c = $a; $c < ($mem['numberOfChild'] + $mem['numberOfAdults']); $c++) {

                            $index++;
                            $ind = ($index - 1);

                            $HotelPassenger[$c] = array(
                                'AgencySysId' => $AgencySysId,
                                'EmailId' => $leadEmail,
                                'Salutation' => isset($IntmemberData[$c]['title']) ? $ARR_SALUTION_CHILD[$IntmemberData[$c]['title']] : '',
                                'Title' => isset($IntmemberData[$c]['title']) ? $IntmemberData[$c]['title'] : '',
                                'Relation' => 9,
                                'Contacts' => $leadMobile,
                                'FirstName' => isset($IntmemberData[$c]['fname']) ? $IntmemberData[$c]['fname'] : '',
                                'LastName' => isset($IntmemberData[$c]['lname']) ? $IntmemberData[$c]['lname'] : '',
                                'panno' => '',
                                'Age' => isset($ChildAge[$ch]) ? $ChildAge[$ch] : 0,
                                'IsPswExpire' => 0,
                                'CreatedByUserSysId' => $AgencySysId,
                                'Address' => 'Not Required',
                                'CityTitle' => 'Not Required',
                                'CitySysId' => 0,
                                'paxType' => $IntmemberData[$c]['PaxType'],
                                'IsPassM' => $IntmemberData[$c]['IsPassM'],
                                'StateOrZoneSysId' => 0,
                                'CountrySysId' => 0,
                                'countryCode' => $countryCode,
                                'RegisterDate' => date('Y-m-d H:i:s'),
                                'IsApproved' => '0',
                                'IsActive' => '1',
                                'IsMarkForDel' => '0',
                                'created_at' => date('Y-m-d H:i:s'),
                                'updated_at' => date('Y-m-d H:i:s'),
                            );
                            if (!empty($IntmemberData[$c]['passno']) && $IntmemberData[$c]['IsPassM'] == 1) {
                                $HotelPassenger[$c]['passportnoexpiry'] = $IntmemberData[$c]['passexp'];
                                $HotelPassenger[$c]['passporIssue'] = $IntmemberData[$c]['passisse'];
                                $HotelPassenger[$c]['passportno'] = $IntmemberData[$c]['passno'];
                            }
                            $HotelPassenger[$c]['GTX_customerSysId'] = isset($apiCustomer['memberId'][($ind - 1)]) ? $apiCustomer['memberId'][($ind - 1)] : 0;
                            $HotelPassenger[$c]['apiTraceId'] =  $BookingID;

                            if ($IntmemberData[$c]['title'] == 'Ms') {
                                $chtitle = 'Miss';
                            } elseif ($IntmemberData[$c]['title'] == 'Mstr') {
                                $chtitle = 'Master';
                            } else {
                                $chtitle = $IntmemberData[$c]['title'];
                            }
                            $traveller['fN'] = $IntmemberData[$c]['fname'];
                            $traveller['lN'] =  $IntmemberData[$c]['lname'];
                            $traveller['ti'] = $chtitle;
                            $traveller['pt'] = 'CHILD';
                            unset($traveller['pan']);

                            if ($IntmemberData[$c]['IsPassM'] == 1) {
                                if (!empty($IntmemberData[$c]['passno'])) {
                                    $traveller['pNum'] = $IntmemberData[$a]['passno'];
                                }
                            }
                            if ($ICSourceSysId == 3) {
                                $hotelPassengerArr[$key]["paxes"][$c] = array(
                                    'Title' => trim($IntmemberData[$c]['title']),
                                    'FirstName' => $IntmemberData[$c]['fname'],
                                    'Middlename' => null,
                                    'LastName' => $IntmemberData[$c]['lname'],
                                    'Phoneno' => $leadMobile,
                                    'Email' => $leadEmail,
                                    'PaxType' => 2,
                                    'LeadPassenger' => false,
                                    'Age' => isset($ChildAge[$ch]) ? $ChildAge[$ch] : 0,
                                    'PAN' => ($IsPANMandatory == 1) ? $IntmemberData[0]['panno'] : '',

                                    "PaxId" => $c,
                                    // "GSTCompanyAddress" => null,
                                    // "GSTCompanyContactNumber" => null,
                                    // "GSTCompanyName" => null,
                                    // "GSTNumber" => null,
                                    // "GSTCompanyEmail" => null,
                                );
                                if ($IsPassportMandatory == 1) {
                                    $hotelPassengerArr[$key]["paxes"][$c]['PassportNo'] = isset($IntmemberData[$c]['passno']) ? $IntmemberData[$c]['passno'] : '';

                                    $hotelPassengerArr[$key]["paxes"][$c]['PassportIssueDate'] = isset($IntmemberData[$c]['passisse']) ? date('Y-m-d', strtotime($IntmemberData[$c]['passisse'])) . 'T00: 00: 00' : '';
                                    $hotelPassengerArr[$key]["paxes"][$c]['PassportExpDate'] = isset($IntmemberData[$c]['passexp']) ? date('Y-m-d', strtotime($IntmemberData[$c]['passexp'])) . 'T00: 00: 00' : '';
                                }
                            }
                            $travellerInfo[] = $traveller;
                            $ch++;
                        }
                    }
                    $alltraveller['travellerInfo'] = $travellerInfo;
                    $roomtravellerinfo[] = $alltraveller;
                    $booking_room_data[$key]['customer'] = $HotelPassenger;
                    // pr($HotelPassenger);LastCancellationDate
                }
            }

            if ($ICSourceSysId == 3) {
                if ($memberDetailsSearch) {
                    foreach ($memberDetailsSearch as $key => $mem) {
                        $HotelPassenger__ = $hotelPassengerArr[$key]['paxes'];
                        $CancelDateskipped = false;
                        $RoomInfoData = isset($hoteldetails['RoomInfo'][0]['Rooms'][$key]) ? $hoteldetails['RoomInfo'][0]['Rooms'][$key] : [];

                        $HotelRoomsDetails_TBO[$key] = array(
                            'HotelPassenger' => $HotelPassenger__,
                        );
                    }
                }
                $bookingRequestTbo = array(
                    'BookingCode' => isset($hoteldetails['RoomInfo'][0]['Rooms'][0]['RoomIndex']) ? $hoteldetails['RoomInfo'][0]['Rooms'][0]['RoomIndex'] : false,
                    'IsVoucherBooking' => true, //isset($hoteldetails['RoomInfo'][0]['IsVoucherBooking']) ? $hoteldetails['RoomInfo'][0]['IsVoucherBooking'] : false,
                    'NetAmount' => isset($hoteldetails['RoomInfo'][0]['NetAmount']) ? $hoteldetails['RoomInfo'][0]['NetAmount'] : 0,
                    'RequestedBookingMode' => 5,
                    'GuestNationality' => 'IN',
                    'HotelRoomsDetails' => $HotelRoomsDetails_TBO,
                );
            }

            // echo "<pre>bookingRequestTbo";
            // print_r(($bookingRequestTbo));
            // die;
            $emails[] = $leadEmail;
            $contacts[] =  $leadMobile;
            $code[] =  '+' . $countryCode;
            $deliveri['emails'] =  $emails;
            $deliveri['contacts'] =  $contacts;
            $deliveri['code'] =   $code;
            $bookingId = $hoteldetails['HotelDetails']['bookingId'];
            $amount = isset($hoteldetails['RoomInfo'][0]['RoomTotalPrice']) ? $hoteldetails['RoomInfo'][0]['RoomTotalPrice'] : 0;
            $payments[] = array('amount' => (float)$amount);
            if ($ICSourceSysId == 3) {
                $bookingrequest = $bookingRequestTbo;
            } else {
                $bookingrequest['bookingId'] = $bookingId;
                $bookingrequest['roomTravellerInfo'] = $roomtravellerinfo;
                $bookingrequest['deliveryInfo'] = $deliveri;
                $bookingrequest['type'] = 'HOTEL';
                $bookingrequest['paymentInfos'] = $payments;
            }

            $Hotel_booking_data = array(
                'hotel_data' => $HotelDetails,
                'booking_room_data' => $booking_room_data,
            );
            $fare = array(
                'Currncy' => $Currncy,
                'BaseFare' => $TotalBaseFare,
                'TaxesandFee' => $TotalTaxesandFee,
                'GrandTotal' => (($TotalBaseFare + $TotalTaxesandFee + $TotalFixedMarkUp + $TotalGSTOnMarkUp) - $TotalDiscount),
                'CommissionEarned' => $TotalCommissionEarned,
                'TDSEarn' => $TotalTDSEarn,
                'Discount' => $TotalDiscount,
                'FixedMarkUp' => $TotalFixedMarkUp,
                'GSTOnMarkUp' => $TotalGSTOnMarkUp,
            );

            $BookingDetails = [
                'HotelBookingData' => $Hotel_booking_data,
                'Fare' => $fare,
            ];
            $TPSysId = $SearchParams['TPSysId'];
            $BookingDetails["AgencySysId"] = $AgencySysId;
            $BookingDetails["AgentSysId"] = $AgencySysId;
            $BookingDetails["email"] = isset($leadEmail) ? $leadEmail : '';
            $BookingDetails["mobile"] = isset($leadMobile) ? $leadMobile : '';
            $BookingDetails["FirstName"] = isset($ForCustomerSession[0]['fname']) ? $ForCustomerSession[0]['fname'] : '';
            $BookingDetails["LastName"] = isset($ForCustomerSession[0]['lname']) ? $ForCustomerSession[0]['lname'] : '';
            $BookingDetails["editLeadId"] = $TPSysId;
            $BookingDetails["IsB2BQuery"] = $IsB2BCustomer;
            $BookingDetails["B2BAgentSysId"] = $UserSysId;
            $BookingDetails["B2BAgencySysId"] = $AgencySysId__;
            $BookingDetails["leadsource"] = 'Agency';
            $BookingDetails["IsB2BProposal"] = $IsB2BCustomer;
            $BookingDetails["ICSourceSysId"] = $ICSourceSysId;
            $BookingDetails["ExchangeCurrencyRate"] = $ConvertionRate;
            $BookingDetails["TraceId"] = $BookingID;
            $BookingDetails["APIMode"] = 0;
            $BookingDetails["IsNewMigration"] = 3;

            $gstData = array(
                'GstNumber' => $gstnnumber,
                'GstCompany' => $companyname,
                'GstEmail' => $gstemail,
                'GstPhone' => $gstphone,
                'GstAddress' => $gstaddress,
                'GstState' => $gststate,
            );

            $ServiceTaxNo = $getAgencyDetail['ServiceTaxNo'];
            $gstvalidate = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->gstvalidate($gstnnumber, $ServiceTaxNo);

            $getData['SecurityKey'] = $SecurityKey;
            $URL = $this->baseUrl . '/gtxwebservices/hotel-api';

            $HotelQueryids = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->apiHttpRequest($BookingDetails, $getData, $URL);
            // echo "<pre>";
            // print_r(($HotelQueryids));
            // echo "<pre>";
            // print_r(($BookingDetails));
            // die;
            $misxItems_name = [];
            if ($BookingDetails['HotelBookingData']['booking_room_data']) {
                foreach ($BookingDetails['HotelBookingData']['booking_room_data'] as $key => $value) {

                    $TotalGST = $value['ServiceTaxOnAgencyMarkUp'];
                    $Discounts = isset($value['Discounts']) ? $value['Discounts'] : 0;
                    $misxItems_name[] = [
                        'AgencySysId' => $AgencySysId,
                        'AgentSysId' => 0,
                        'MisxItems_name' => 'Hotel',
                        'Description' => $value['RoomTypeName'],
                        'ItemQty' => 1,
                        'ItemRates' => ($value['RoomPrice'] + $value['TaxesServiceFee']),
                        'Total' => $value['RoomPrice'] + $value['TaxesServiceFee'],
                        'DiscountType' => 1,
                        'Discount' => $Discounts,
                        'TotalDiscount' => $Discounts,
                        'TotalAmount' => ($value['RoomPrice'] + $value['TaxesServiceFee'] + $value['AgencyMarkUp'] + $TotalGST - $Discounts),
                        'MarkupType' => '',
                        'Markup' =>  $value['AgencyMarkUp'],
                        'TotalMarkup' =>  $value['AgencyMarkUp'],
                        'SubTotal' => ($value['RoomPrice'] + $value['TaxesServiceFee'] + $value['AgencyMarkUp'] + $TotalGST - $Discounts),
                        'ServiceFeeTotal' => 0,
                        'GSTPercentage' => '18',
                        'TotalGST' => $TotalGST,
                        'SGST' => ($gstvalidate['SGST'] == 1) ? ($TotalGST / 2) : 0,
                        'CGST' => ($gstvalidate['CGST'] == 1) ? ($TotalGST / 2) : 0,
                        'IGST' => ($gstvalidate['IGST'] == 1) ? $TotalGST : 0,
                        'ItemsSACCode' => '',
                    ];
                }
            }

            $Invoicedata = [];
            if ($HotelQueryids['status'] == 1) {
                $arrIds = isset($HotelQueryids['arrIds']) ? $HotelQueryids['arrIds'] : [];
                $MasterTPSysId = isset($arrIds['MasterTPSysId']) ? $arrIds['MasterTPSysId'] : 0;
                $TPSysId = isset($arrIds['TPSysId']) ? $arrIds['TPSysId'] : 0;
                $VersionId = isset($arrIds['VersionId']) ? $arrIds['VersionId'] : 0;
                $CustomerSysIdGTX = isset($arrIds['CustomerSysId']) ? $arrIds['CustomerSysId'] : 0;
                $TrxId = isset($arrIds['TrxId']) ? $arrIds['TrxId'] : 0;

                $TotalInvoiceValue = $fare['GrandTotal'];
                $PublishedFare = $fare['GrandTotal'];
                $agencyMarkUpGST = $fare['GSTOnMarkUp'];
                $Discount = $fare['Discount'];
                $Invoicedata = [
                    'AgentSysId' => 0,
                    'CustomerSysId' => $CustomerSysIdGTX,
                    'TPSysId' => $TPSysId,
                    'MasterTPSysId' => $MasterTPSysId,
                    'ProposalID' => $TPSysId . '/V1',
                    'InvoiceDate' => date('Y-m-d'),
                    'isDisplayMarkup' => true,
                    'PaymentDueDate' => date('Y-m-d'),
                    'PaymentDate' => date('Y-m-d'),
                    'ClientGST' => 0,
                    'ClientGSTNumber' => '',
                    'Currency' => 1,
                    'TotalInvoiceValue' => $TotalInvoiceValue,
                    'InvoiceStatus' => true,
                    'TotalSGST' => ($gstvalidate['SGST'] == 1) ? ($agencyMarkUpGST / 2) : 0,
                    'TotalCGST' => ($gstvalidate['CGST'] == 1) ? ($agencyMarkUpGST / 2) : 0,
                    'TotalIGST' => ($gstvalidate['IGST'] == 1) ? $agencyMarkUpGST : 0,
                    'SumdiscountItem' => $Discount,
                    'OtherDiscount' => 0,
                    'otherDiscountVal' => 0,
                    'TotalAdvance' => $PublishedFare,
                    'TotalDueAmount' => 0,
                    'InvoiceValue' => $PublishedFare,
                    'notes' => 'Hotel Voucher',
                    'termsandcondition' => '',
                    'client_state' => '',
                    'Advance' => 0,
                    'PaymentType' => 4,
                    'paymentNote' => 'Online',
                    'misxItems_name' => $misxItems_name,

                ];
                $arrUrlData['Invoicedata'] = $Invoicedata;
                $arrUrlData['HotelQueryids'] = $HotelQueryids;
                $arrUrlData['BookingDetails'] = $BookingDetails;
                $arrUrlData['bookingrequest'] = $bookingrequest;
                $arrUrlData['gstData'] = $gstData;

                $tempData = array(
                    'TraceId' => $searchIDSearch,
                    'TPSysId' => ($TPSysId),
                    'APIBookingData' => json_encode($arrUrlData),
                );
                $objTempFlight->deleteFlightTempData($searchIDSearch);
                $objTempFlight->insertFlightTempData($tempData);
                echo json_encode(['success' => true, 'message' => 'SUCESS', 'fare' => $fare, 'SearchTraceId' => $searchIDSearch]);
                exit;
            } else {
                $response = array('success' => false, 'message' => 'Unable to create query. please contact administrator.');
                echo json_encode($response);
                exit;
            }
        }
    }

    public function reviewAction()
    {

        // ini_set('display_errors', 1);
        // ini_set('display_startup_errors', 1);
        // error_reporting(E_ALL);
        $searchIDSearch = $SearchHotelTraceId = $this->view->searchIDSearch = $this->getRequest()->getParam('data');
        $objTempFlight = new Travel_Model_TblFlight();
        $FlightTempData = $objTempFlight->GetFlightTempData($searchIDSearch);

        if ($FlightTempData) {
            $TPSysId = $FlightTempData['TPSysId'];
            $arrUrlData = json_decode($FlightTempData['APIBookingData'], true);
            $SearchParams = $arrUrlData['SearchParams'];
            $leadId     = $SearchParams['TPSysId'];
            $objFlightProposal = new Travel_Model_TblFlightProposal();
            $crmcustomerObj = new Travel_Model_CRM_Customer();
            $arrAgencyDetails = $this->view->arrAgencyDetails = $objFlightProposal->getProposalAgencyDetails($leadId, 'query');
            $this->intLoggedinUserAgencySysId = $AgencySysId = $arrAgencyDetails['AgencySysId'];
            $this->intLoggedinUserId = $AgentSysId = $arrAgencyDetails['AgentSysId'];
            $getAgencyDetail = $crmcustomerObj->GetAgencyDetailById($AgencySysId);
            $SecurityKey = isset($getAgencyDetail['SecurityKey']) ? $getAgencyDetail['SecurityKey'] : 0;
            // echo "<pre>";
            // print_r(($arrAgencyDetails));
            // die;

            // echo "<pre>";
            // print_r(($SearchParams));
            // die;
            if ($TPSysId && $searchIDSearch) {
                $TotalBaseFare = 0;
                $TotalTaxesandFee = 0;
                $TotalDiscount = 0;
                $Currncy = '';
                $TotalCommissionEarned = 0;
                $TotalFixedMarkUp = 0;
                $TotalGSTOnMarkUp = 0;
                $TotalTDSEarn = 0;
                $BaseFareArray = [];

                $PostData = ['TPSysId' => $TPSysId];
                $getData['SecurityKey'] = $SecurityKey;
                $URL = $this->baseUrl . '/gtxwebservices/hotel-api/hotel-voucher';

                $HOTEL_VOUCHER = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->apiHttpRequest($PostData, $getData, $URL);
                $HotelData = isset($HOTEL_VOUCHER['data']) ? $HOTEL_VOUCHER['data'] : [];
                $AdultPax = isset($HotelData['HotelData']['AdultPax']) ? (int)$HotelData['HotelData']['AdultPax'] : 0;
                $ChildPax = isset($HotelData['HotelData']['ChildPax']) ? (int)$HotelData['HotelData']['ChildPax'] : 0;
                $PaymentStatus = isset($HotelData['HotelData']['PaymentStatus']) ? $HotelData['HotelData']['PaymentStatus'] : '';
                $CurrentStatus = isset($HotelData['HotelData']['CurrentStatus']) ? $HotelData['HotelData']['CurrentStatus'] : '';
                $accom_room = isset($HotelData['accom_room']) ? $HotelData['accom_room'] : [];

                if ($this->_request->isXmlHttpRequest()) {
                    if (empty($HotelData) || ($CurrentStatus == 24)) {
                        $response = array('success' => true, 'TrackId' => base64_encode($TPSysId), 'msg' => 'This Trace id already expired', 'urlData' => $strUrlData, 'formAction' => "/flight-new/booking-confirmation/data/" . $TPSysId . "");
                        echo json_encode($response);
                        exit;
                    }
                }
                // echo "<pre>";
                // print_r(($HotelData));
                // die;
                if ($accom_room) {
                    foreach ($accom_room as $key => $values) {
                        $Currncy = $values['Currency'];
                        $BaseFare = ($values['RoomPrice']);
                        $TotalBaseFare += ($values['RoomPrice']);
                        $TotalFixedMarkUp += ($values['AgencyMarkUp']);
                        $TotalGSTOnMarkUp += ($values['GSTOnAgencyMarkUp']);
                        $TotalTaxesandFee += (($values['Taxes']));
                        $BaseFareArray[$key] = ['BaseFare' => $BaseFare, 'name' => $values['RoomTypeName'], 'MealBase' => $values['MealPlanType']];
                    }
                }

                $fare = array(
                    'Currncy' => $Currncy,
                    'BaseFare' => round($TotalBaseFare, 2),
                    'TaxesandFee' => round($TotalTaxesandFee, 2),
                    'GrandTotal' => round($TotalBaseFare + $TotalTaxesandFee + $TotalFixedMarkUp + $TotalGSTOnMarkUp, 2),
                    'CommissionEarned' => round($TotalCommissionEarned, 2),
                    'TDSEarn' => round($TotalTDSEarn, 2),
                    'Discount' => round($TotalDiscount, 2),
                    'FixedMarkUp' => round($TotalFixedMarkUp, 2),
                    'GSTOnMarkUp' => round($TotalGSTOnMarkUp, 2),
                    'roomCoun' => count($accom_room),
                    'nightCoun' => ($HotelData['HotelData']['TotalNights']),
                    'BaseFareArray' => ($BaseFareArray),
                );
                // echo "<pre>post";
                // print_r(($accom_room));
                // die;
                if ($this->_request->isXmlHttpRequest()) {
                    echo json_encode([
                        'status' => true,
                        'message' => 'SUCESS',
                        'fare' => $fare,
                        'HotelData' => $HotelData,
                    ]);
                    exit;
                }
            } else {
                $response = array('success' => false, 'msg' => 'Invalid URL or This Trace id already expired');
                echo json_encode($response);
                exit;
            }

            $crmcustomerObj = new Travel_Model_CRM_Customer();
            $getAgencyDetail = $crmcustomerObj->GetAgencyDetailById($this->intLoggedinUserAgencySysId);
            $getAgentDetailById = $crmcustomerObj->getAgentDetailById($this->intLoggedinUserId);
            $this->view->IsAllowFlightBooking = isset($getAgentDetailById[0]['IsAllowFlightBooking']) ? $getAgentDetailById[0]['IsAllowFlightBooking'] : 0;
            $this->view->IsCheckWallet = isset($getAgencyDetail['IsCheckWallet']) ? $getAgencyDetail['IsCheckWallet'] : 0;
            $intCustomerSysId = isset($SearchParams['customerId']) ? $SearchParams['customerId'] : 0;
            $customerDetails = $crmcustomerObj->GetAgencyCustomerById($intCustomerSysId);
            $AgencySysId = isset($customerDetails['AgencySysId']) ? $customerDetails['AgencySysId'] : 0;
            $IsB2BCustomer = isset($customerDetails['IsB2BAgent']) ? $customerDetails['IsB2BAgent'] : 0;
            $IsEnabledWallet = isset($customerDetails['IsEnabledWallet']) ? $customerDetails['IsEnabledWallet'] : 0;
            $CustomerSysId = isset($customerDetails['CustomerSysId']) ? $customerDetails['CustomerSysId'] : 0;
            $this->view->IsB2BCustomer = $IsB2BCustomer;
            $this->view->IsEnabledWallet = $IsEnabledWallet;
            $this->view->walletBalanceAmount = '0.00';

            $model = new Gtxwebservices_Model_Webservices();
            if ($IsB2BCustomer == 1) {
                $B2bAgencyDetailById = $crmcustomerObj->GetAgencyDetailById($AgencySysId);
                $B2BAgencySysIdKey = $getAgencyDetail['SecurityKey'];
                $B2CAgencySysIdKey = $B2bAgencyDetailById['SecurityKey'];
                $apiDataIV = array(
                    "B2BAgencySysIdKey" => $B2BAgencySysIdKey,
                    "B2CAgencySysIdKey" => $B2CAgencySysIdKey,
                );

                $result = json_decode($model->GetB2Bbalance($apiDataIV), true);
                $this->view->walletBalanceAmount = $result['creditBalance'];
            } elseif ($IsEnabledWallet == 1) {
                $apiDataIV = array(
                    "CustomerSysId" => $CustomerSysId,
                );

                $result = json_decode($model->GetB2Cbalance($apiDataIV, $SecurityKey), true);
                $this->view->walletBalanceAmount = (isset($result['WalletBalance'][0]['BalanceAmount']) && !empty($result['WalletBalance'][0]['BalanceAmount'])) ? $result['WalletBalance'][0]['BalanceAmount'] : 0;
            }

            $IsPaymentGateway = !empty($arrAgencyDetails['IsPaymentGateway']) ? $arrAgencyDetails['IsPaymentGateway'] : 0;
            $IsCheckWallet = !empty($arrAgencyDetails['IsCheckWallet']) ? $arrAgencyDetails['IsCheckWallet'] : 0;
            if ($IsPaymentGateway == true && $IsCheckWallet == true) {
                $this->view->strPayWithPaymentGatewayUrl = Catabatic_Helper::getSiteUrl() . "payment/payment-options/customer-pay-by-agency";
            } else {
                $this->view->strPayWithPaymentGatewayUrl = Catabatic_Helper::getSiteUrl() . "payment/payment-options/customer-pay-by-agency";
            }


            $FixedMarkUp = isset($fare['FixedMarkUp']) ? $fare['FixedMarkUp'] : 0;
            $GSTOnMarkUp = isset($fare['GSTOnMarkUp']) ? $fare['GSTOnMarkUp'] : 0;
            $intPublishFareNew = isset($fare['GrandTotal']) ? $fare['GrandTotal'] : 0;
            $arrPriceAndMarkups = array(
                "intAgencyMarkUpAmount" => ($FixedMarkUp - $GSTOnMarkUp),
                "intTotalAmount" => $intPublishFareNew,
                "AgentServiceTaxAmount" => $GSTOnMarkUp,
                "SupplierSourceStr" => "API",
                "MarketPlaceId" => "1",
                "TotalDiscount" => 0,
                "CurrencyType" => 1
            );
            $arrPriceAndMarkups = array(
                "intAgentMarkUpAmount" => 0,
                "intAgencyMarkUpAmount" => ($FixedMarkUp - $GSTOnMarkUp),
                "intGTXMarkUpAmount" => 0,
                "intTotalAmount" => $intPublishFareNew,
                "intTax" => 0,
                "GTXServiceTaxAmount" => 0,
                "AgentServiceTaxAmount" => $GSTOnMarkUp,
                "AgentsCustomServiceTaxAmount" => "0",
                "Pax" => ($AdultPax + $ChildPax),
                "SupplierSourceStr" => "API",
                "MarketPlaceId" => "1",
                "TotalDiscount" => 0,
                "CurrencyType" => 1
            );
            $strPriceAndMarkups = json_encode($arrPriceAndMarkups);
            $this->view->stringData = $strStringData = $this->getEnc($strPriceAndMarkups);
            // echo "<pre>HotelData";
            // print_r(($strStringData));
            // echo "<pre>HotelData";
            // print_r(($strPriceAndMarkups));
            // die;
            $secureCode = Zend_Controller_Action_HelperBroker::getStaticHelper('SecureCode')->secureCode(trim(base64_encode($searchIDSearch)), 1);

            $this->view->TPSysId = $TPSysId;
            $this->view->secureCode = $secureCode;
            $this->view->intCustomerSysId = $intCustomerSysId;
            $this->view->intPlanType = "1";
            $this->view->strTrxType = "A";
            $this->view->strReturnURL = "/hotel-proposal/book-hotel/data/" . $searchIDSearch . '/code/' . $secureCode;
            $this->view->strErrorURL = "/hotel-proposal/review/data/" . $searchIDSearch . '/code/' . $secureCode;
            $this->view->intLoggedinAgencySysId = $AgencySysId;
            $this->view->IsCardChrgToCustomer = 1;
            $this->view->intLoggedinUserAgencySysId = $this->intLoggedinUserAgencySysId;
            $this->view->intPublishFare = ceil($intPublishFareNew);
            $this->view->intPublishFareNew = $intPublishFareNew;
            $this->view->Symbol = $fare['Currency'];

            $this->view->guid = $this->GUID();
            $this->view->walletCode = $this->walletCode($this->intLoggedinUserAgencySysId, $this->view->guid, ceil($intPublishFareNew), $AgencySysId, $TPSysId, $intCustomerSysId, $strStringData);
            $this->view->securecode = $this->secureCode($AgencySysId, $this->view->guid);

            $objPaymentDetail = new Payment_Model_Payment();
            $getPaymentCompanyName = $objPaymentDetail->getPaymentCompanyNameAllDetail($this->intLoggedinUserAgencySysId);
            $PaymentMerchantId = $getPaymentCompanyName['PaymentMerchantId'];
            $PaymentOption = $getPaymentCompanyName['PaymentOption'];
            $this->view->getPaymentCompanyName = $PaymentOption;
            $this->view->PaymentMerchantId = $PaymentMerchantId;
            $this->view->Symbol = $fare['Currncy'];
            $this->view->HotelData = $HotelData['HotelData'];
            // echo "<pre>post";
            // print_r(($fare));
            // echo "<pre>post";
            // print_r(($HotelData));
            // die;
            $this->view->intLoggedinUserId = $this->intLoggedinUserId;
            $this->view->intLoggedinUserGroupSysId = $this->intLoggedinUserAgencySysId;
            $this->view->intLoggedinUserAgencySysId = $this->intLoggedinUserAgencySysId;
            $this->view->searchID = $searchIDSearch;
            $this->view->TPSysId = $TPSysId;
            $this->view->ActionName = 'review';

            $Customer = new Zend_Session_Namespace('Customer');
            $this->view->intTpSysId = $intTpSysId = $Customer->intTPSysId;
            $this->view->intCustomerSysId = $intCustomerSysId = $Customer->intCustomerSysId;
        }
    }

    public function verifyingbookingAction()
    {
        if ($this->getRequest()->isXmlHttpRequest() && $this->getRequest()->getPost()) {
            $post = $this->getRequest()->getPost();
            $code = $post['code'];
            $data = $strUrlData = $post['data'];
            $secureCode = Catabatic_ValidateCustomer::secureCode(base64_encode($data), 1);
            if ($secureCode != $code) {
                echo "Please check your request parameters";
                exit;
            }

            $objTempFlight = new Travel_Model_TblFlight();
            $FlightTempData = $objTempFlight->GetFlightTempData($strUrlData);
            $TPSysId = $intTPSysId = $FlightTempData['TPSysId'];
            $arrUrlData = json_decode($FlightTempData['APIBookingData'], true);
            $SearchParams = $arrUrlData['SearchParams'];
            $leadId     = $SearchParams['TPSysId'];
            $objFlightProposal = new Travel_Model_TblFlightProposal();
            $crmcustomerObj = new Travel_Model_CRM_Customer();

            $arrAgencyDetails = $this->view->arrAgencyDetails = $objFlightProposal->getProposalAgencyDetails($leadId, 'query');
            $this->intLoggedinUserAgencySysId = $AgencySysId = $arrAgencyDetails['AgencySysId'];
            $this->intLoggedinUserId = $AgentSysId = $arrAgencyDetails['AgentSysId'];
            $getAgencyDetail = $crmcustomerObj->GetAgencyDetailById($AgencySysId);
            $SecurityKey = isset($getAgencyDetail['SecurityKey']) ? $getAgencyDetail['SecurityKey'] : 0;
            $PrimaryEmail = isset($agencyDetails['PrimaryEmail']) ? $agencyDetails['PrimaryEmail'] : 0;

            $getAgentDetailById = $crmcustomerObj->getAgentDetailById($AgencySysId);
            $getData['SecurityKey'] = $SecurityKey;
            $PostData = ['TPSysId' => $TPSysId];
            $URL = $this->baseUrl . '/gtxwebservices/hotel-api/hotel-voucher';

            $HOTEL_VOUCHER = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->apiHttpRequest($PostData, $getData, $URL);
            $HotelData = isset($HOTEL_VOUCHER['data']) ? $HOTEL_VOUCHER['data'] : [];
            $PaymentStatus = isset($HotelData['HotelData']['PaymentStatus']) ? $HotelData['HotelData']['PaymentStatus'] : '';
            $CurrentStatus = isset($HotelData['HotelData']['CurrentStatus']) ? $HotelData['HotelData']['CurrentStatus'] : '';
            $MasterTPSysId = isset($HotelData['HotelData']['MasterTPSysId']) ? $HotelData['HotelData']['MasterTPSysId'] : '';
            $accom_room = isset($HotelData['accom_room']) ? $HotelData['accom_room'] : [];
            $CustomerDetails = isset($HotelData['CustomerDetails']) ? $HotelData['CustomerDetails'] : [];
            $intCustomerSysId = isset($SearchParams['customerId']) ? $SearchParams['customerId'] : 0;
            /// $customerDetails = $crmcustomerObj->GetAgencyCustomerById($intCustomerSysId);


            $EmailId_cus = isset($CustomerDetails['EmailId']) ? trim($CustomerDetails['EmailId']) : 0;
            $Contacts_cus = isset($CustomerDetails['Contacts']) ? trim($CustomerDetails['Contacts']) : 0;
            $countrycode = isset($CustomerDetails['countrycode']) ? trim($CustomerDetails['countrycode']) : 0;
            $smsemail = $EmailId_cus;
            $smsmobile = $Contacts_cus;
            $MobileNumber = $countrycode . $Contacts_cus;

            $generateNumericOTP = $this->generateNumericOTP(6);

            $customHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('Custom');
            $IsSMSApi = isset($getAgencyDetail['IsSMSApi']) ? trim($getAgencyDetail['IsSMSApi']) : 0;

            if (isset($post['verifying']) && $post['verifying'] == 'true' && !empty($post['verifying'])) {
                $getBooingOTP = $objTempFlight->getBooingOTP($intTPSysId);
                $OTPNumber = trim($post['OTPNumber']);

                if ($getBooingOTP == $OTPNumber) {
                    $objTempFlight->updateBookingStatusTravelPlan(array("CustomerRemark" => '1'), $intTPSysId, $MasterTPSysId);
                    $response = array('success' => true, 'checkOTP' => false, 'msg' => 'success', 'urlData' => '');
                    echo json_encode($response);
                    exit;
                } else {
                    $response = array('success' => false, 'checkOTP' => false, 'msg' => 'Invalid otp', 'urlData' => '');
                    echo json_encode($response);
                    exit;
                }
            }

            $objTempFlight->updateBookingStatusTravelPlan(array("CustomerRemark" => $generateNumericOTP), $intTPSysId, $MasterTPSysId);
            $currentDate = date('Y-m-d H:i:s');
            $dateTime = new DateTime($currentDate);
            $dateTime->modify('+2 minutes');
            $RandomCodeValidTo = $dateTime->format('Y-m-d H:i:s');

            $col = array('RandomCode' => $generateNumericOTP, 'RandomCodeValidFrom' => $currentDate, 'RandomCodeValidTo' => $RandomCodeValidTo);
            $message = "OTP for CRM access is $generateNumericOTP do not share it with anyone.\nTRVCRM";
            $postFields = "";
            $postFields .= "&method=$this->SMSMETHOD";
            $postFields .= "&api_key=$this->SMSAPIKEY";
            $postFields .= "&sender=$this->SMSSENDER";
            $postFields .= "&message=$message";
            $postFields .= "&format=$this->SMSFORMAT";
            $postURL = $this->SMSURL;
            $data = new Payment_Model_Checkotp();
            $html = new Zend_View();
            $html->setScriptPath(APPLICATION_PATH . '/views/scripts/flight/');
            $html->assign(array('getBooingOTP' => $generateNumericOTP, 'agencyDetails' => $agencyDetails));
            $bodyText = $html->render('OTPEmail.phtml');
            $fromName = (isset($agencyDetails['DisplayName']) && !empty($agencyDetails['DisplayName'])) ? trim($agencyDetails['DisplayName']) : trim(trim($agencyDetails['Title']));
            $emailData = array(
                'fromEmail' => $PrimaryEmail,
                'fromName' => $fromName,
                'subject' => 'OTP for booking ' . date('Y-m-d H:i:s'),
                'to' => array($smsemail),
                'bodyHtml' => $bodyText,
                'bodyText' => ''
            );

            $arrEmailStatisticsType = array_keys(unserialize(ARR_EMAIL_STATISTICS_TYPE));
            $arrEmailStatistics = array(
                "TPSysId" => 0,
                "TypeSysId" => 1, // 1 For Email 2 For SMS
                "AgencySysId" => $AgencySysId,
                "AgentSysId" => 0,
                "Title" => $bodyText,
                "Source" => $arrEmailStatisticsType[1], // 1 For Vouchers
                "Status" => 0,
                "RefSysId" => "",
                "RefSysStatus" => "",
                "CreateDate" => date('Y-m-d H:i:s')
            );
            $smsmobile = $smsmobile;
            $postFields .= "&to=" . substr($smsmobile, -10);
            $hidePhoneNumberDigit = $customHelper->hidePhoneNumberDigit($smsmobile, 1);
            $emailResponse = json_decode($this->mailSentByElastice($emailData, $arrEmailStatistics), true);
            $resultVal = $data->sendSmsDetails($postURL, $postFields, $arrEmailStatistics, $IsSMSApi);

            $response = array('success' => true, 'checkOTP' => true, 'msg' => '', 'urlData' => '',  'PhoneNumberDigit' => $hidePhoneNumberDigit);
            echo json_encode($response);
            exit;
            // echo "<pre>post";
            // print_r(($emailResponse));
            // die;
        }
    }

    public function validatePaymentAction()
    {
        if ($this->_request->isXmlHttpRequest()) {
            $this->_helper->layout->disableLayout();
            $this->paymentMdl = new Payment_Model_Payment();
            $AgencySysId = $this->getRequest()->getParam('AgencySysId');
            $intPublishFare = $this->getRequest()->getParam('intPublishFare');
            $wallet = $this->paymentMdl->getDetailsByUniqueId("TB_Agency_Wallet", "AgencySysId", $AgencySysId);
            $post = $this->getRequest()->getPost();
            $crmcustomerObj     = new Travel_Model_CRM_Customer();

            $response = array('success' => true, 'message' => '');
            echo json_encode($response);
            exit;
            if ($wallet['BalanceAmount'] >= $intPublishFare) {
                $response = array('success' => true, 'message' => '');
                echo json_encode($response);
                exit;
            } else {
                $response = array('success' => false, 'message' => 'Unable to  continue payment! please contact agency with this message');
                echo json_encode($response);
                exit;
            }
        }
    }

    public function bookHotelAction()
    {
        $post = $this->getRequest()->getParams();
        $objFlight = new Travel_Model_TblFlight();

        $strUrlData = $searchId = $bookingId = $this->view->strUrlData = !empty($this->getRequest()->getParam('strUrlData')) ? $this->getRequest()->getParam('strUrlData') : $this->getRequest()->getParam('data');
        $FlightTempData = $objFlight->GetFlightTempData($strUrlData);
        $this->view->TPSysId = $intTPSysId = $TPSysId = ($FlightTempData['TPSysId'] > 0) ? $FlightTempData['TPSysId'] : 0;
        $arrUrlData = json_decode($FlightTempData['APIBookingData'], true);

        $SearchParams = $arrUrlData['SearchParams'];
        $paymentModebyUser = (isset($arrUrlData['paymentModebyUser']) && !empty($arrUrlData['paymentModebyUser'])) ? $arrUrlData['paymentModebyUser'] : 1;
        $withprice = (isset($arrUrlData['withprice']) && !empty($arrUrlData['withprice'])) ? $arrUrlData['withprice'] : 0;
        $B2BSearch = (isset($arrUrlData['B2BSearch']) && !empty($arrUrlData['B2BSearch'])) ? $arrUrlData['B2BSearch'] : [];
        $IsB2Bproposal = (isset($arrUrlData['IsB2Bproposal']) && !empty($arrUrlData['IsB2Bproposal'])) ? $arrUrlData['IsB2Bproposal'] : 0;

        $SearchParams = $arrUrlData['SearchParams'];
        $leadId     = $SearchParams['TPSysId'];
        $objFlightProposal = new Travel_Model_TblFlightProposal();
        $crmcustomerObj = new Travel_Model_CRM_Customer();
        $arrAgencyDetails = $this->view->arrAgencyDetails = $objFlightProposal->getProposalAgencyDetails($leadId, 'query');
        $this->intLoggedinAgencyId = $AgencySysId = $arrAgencyDetails['AgencySysId'];
        $this->intLoggedinUserId = $AgentSysId = $arrAgencyDetails['AgentSysId'];
        $getAgencyDetail = $crmcustomerObj->GetAgencyDetailById($AgencySysId);
        $SecurityKey = isset($getAgencyDetail['SecurityKey']) ? $getAgencyDetail['SecurityKey'] : 0;
        $urlData = (json_encode(['TPSysId' => $TPSysId, 'SecurityKey' => $SecurityKey]));
        if ($this->getRequest()->isPost() && $this->_request->isXmlHttpRequest()) {
            /* Disable Layout */
            $paymentMdl = new Payment_Model_Payment();
            $crmcustomerObj = new Travel_Model_CRM_Customer();
            $strTrxStatus = !empty($this->getRequest()->getParam('trxstatus')) ? $this->getRequest()->getParam('trxstatus') : $post['status'];
            if ($strTrxStatus == "success") {
                $this->_helper->layout->disableLayout();
                $post = $this->getRequest()->getPost();
                $PostData = ['TPSysId' => $TPSysId];
                $getData['SecurityKey'] = $SecurityKey;
                $URL = $this->baseUrl . '/gtxwebservices/hotel-api/hotel-voucher';

                $HOTEL_VOUCHER = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->apiHttpRequest($PostData, $getData, $URL);
                $HotelData = isset($HOTEL_VOUCHER['data']) ? $HOTEL_VOUCHER['data'] : [];
                $PaymentStatus = isset($HotelData['HotelData']['PaymentStatus']) ? $HotelData['HotelData']['PaymentStatus'] : '';
                $CurrentStatus = isset($HotelData['HotelData']['CurrentStatus']) ? $HotelData['HotelData']['CurrentStatus'] : '';
                $accom_room = isset($HotelData['accom_room']) ? $HotelData['accom_room'] : [];
                $ICSourceSysId = isset($HotelData['HotelData']['ICSourceSysId']) ? $HotelData['HotelData']['ICSourceSysId'] : 0;

                $checkPaymentStatus = $paymentMdl->checkPaymentStatus($AgencySysId, $TPSysId);
                // if (empty($arrUrlData) || ($CurrentStatus == 24)) {
                //     $response = array('success' => true, 'TrackId' => base64_encode($TPSysId), 'msg' => 'This Trace id already expired', 'urlData' => $strUrlData, 'formAction' => "/flight-new/booking-confirmation/data/" . $TPSysId . "");
                //     echo json_encode($response);
                //     exit;
                // }

                if ($checkPaymentStatus == 1) {

                    $TotalBaseFare = 0;
                    $TotalTaxesandFee = 0;
                    $TotalDiscount = 0;
                    $Currncy = '';
                    $TotalCommissionEarned = 0;
                    $TotalFixedMarkUp = 0;
                    $TotalGSTOnMarkUp = 0;
                    $TotalTDSEarn = 0;
                    $BaseFareArray = [];
                    if ($accom_room) {
                        foreach ($accom_room as $key => $values) {
                            $Currncy = $values['Currency'];
                            $BaseFare = ($values['RoomPrice']);
                            $TotalBaseFare += ($values['RoomPrice']);
                            $TotalFixedMarkUp += ($values['AgencyMarkUp']);
                            $TotalGSTOnMarkUp += ($values['GSTOnAgencyMarkUp']);
                            $TotalTaxesandFee += (($values['Taxes']));
                            $BaseFareArray[$key] = ['BaseFare' => $BaseFare, 'name' => $values['RoomTypeName'], 'MealBase' => $values['MealPlanType']];
                        }
                    }

                    $fare = array(
                        'Currncy' => $Currncy,
                        'BaseFare' => round($TotalBaseFare, 2),
                        'TaxesandFee' => round($TotalTaxesandFee, 2),
                        'GrandTotal' => round($TotalBaseFare + $TotalTaxesandFee + $TotalFixedMarkUp + $TotalGSTOnMarkUp, 2),
                        'CommissionEarned' => round($TotalCommissionEarned, 2),
                        'TDSEarn' => round($TotalTDSEarn, 2),
                        'Discount' => round($TotalDiscount, 2),
                        'FixedMarkUp' => round($TotalFixedMarkUp, 2),
                        'GSTOnMarkUp' => round($TotalGSTOnMarkUp, 2),
                        'roomCoun' => count($accom_room),
                        'nightCoun' => ($HotelData['HotelData']['TotalNights']),
                        'BaseFareArray' => ($BaseFareArray),
                    );
                    $checkPaymentStatus = $paymentMdl->checkPaymentStatus($this->intLoggedinAgencyId, $intTPSysId);
                    $getAgencyDetail = $crmcustomerObj->GetAgencyDetailById($this->intLoggedinAgencyId);

                    $intCustomerSysId = isset($SearchParams['customerId']) ? $SearchParams['customerId'] : 0;
                    $customerDetails = $crmcustomerObj->GetAgencyCustomerById($intCustomerSysId);
                    $AgencySysId__ = isset($customerDetails['AgencySysId']) ? $customerDetails['AgencySysId'] : 0;
                    $IsB2BCustomer = isset($customerDetails['IsB2BAgent']) ? $customerDetails['IsB2BAgent'] : 0;
                    $IsEnabledWallet = isset($customerDetails['IsEnabledWallet']) ? $customerDetails['IsEnabledWallet'] : 0;
                    $CustomerSysId = isset($customerDetails['CustomerSysId']) ? $customerDetails['CustomerSysId'] : 0;
                    $PublishedFare = ($fare['GrandTotal']);
                    $B2BWalletbalance = $PublishedFare;

                    $B2bAgencyDetailById = $crmcustomerObj->GetAgencyDetailById($AgencySysId__);
                    $AgentUserDetail = $crmcustomerObj->getAgentDetailById($AgencySysId__);
                    $UserSysId = isset($AgentUserDetail[0]['UserSysId']) ? $AgentUserDetail[0]['UserSysId'] : 0;
                    $B2BAgencySysIdKey = $getAgencyDetail['SecurityKey'];
                    $B2CAgencySysIdKey = $B2bAgencyDetailById['SecurityKey'];

                    $HotelQueryids = $arrUrlData['HotelQueryids'];
                    $TPSysId = $HotelQueryids['arrIds']['TPSysId'];
                    $intCustSysId = $HotelQueryids['arrIds']['CustomerSysId'];
                    $MasterTPSysId = $HotelQueryids['arrIds']['MasterTPSysId'];
                    $VersionId = $HotelQueryids['arrIds']['VersionId'];
                    $TrxId = $HotelQueryids['arrIds']['TrxId'];


                    $model = new Gtxwebservices_Model_Webservices();
                    // // // if ($IsB2BCustomer == 1) {

                    // // //     $URL_ = $this->baseUrl . '/webservice/credit-balance/update-credit-balance-for-offline-request/';
                    // // //     $updateCreditBalance = array(
                    // // //         'B2BAgencySysIdKey' => $B2BAgencySysIdKey,
                    // // //         'B2CAgencySysIdKey' => $B2CAgencySysIdKey,
                    // // //         'Remark' => 'Hotel Booking ',
                    // // //         'Amount' => $B2BWalletbalance,
                    // // //         'PlanType' => 2, // for hote
                    // // //         'UserSysId' => $UserSysId,
                    // // //         'PaymentMode' => 'Online Wallet',
                    // // //         'RefrenceNo' => $bookingId,
                    // // //         'CurrencyType' => $this->CurrencyId,
                    // // //         'FlightTraceId' => $strUrlData,
                    // // //         'IsPayLater' => true
                    // // //     );

                    // // //     $updateBalance = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->DebitFromWallet($updateCreditBalance, $URL_, $AgencySysId__);
                    // // //     ///$updateBalance = json_decode('{"status":true,"TransactionId":"A8203FDFD54448B393549481D2B2EDB4","message":""}', 1);
                    // // //     $TransactionId = isset($updateBalance['TransactionId']) ? $updateBalance['TransactionId'] : 0;
                    // // //     $Paystatus = isset($updateBalance['status']) ? $updateBalance['status'] : 0;
                    // // //     $message = isset($updateBalance['message']) ? $updateBalance['message'] : '';
                    // // //     if ($Paystatus) {
                    // // //         $postFieldArray = array(
                    // // //             'MasterTPSysId' => $MasterTPSysId,
                    // // //             'TPSysId' => $TPSysId,
                    // // //             'TrxId' => $TrxId,
                    // // //             'VersionId' => $VersionId,
                    // // //             'ErrorCode' => 6,
                    // // //             'field' => 'PaymentStatus',
                    // // //             'StatusCode' => 22,
                    // // //             'XRefBookingId' => '',
                    // // //             'APIBookingRes' => '',
                    // // //         );
                    // // //         $URL = $this->baseUrl . "/gtxwebservices/flight/update-api-payment-failed";
                    // // //         $result = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->getHttpRequestArray($postFieldArray, $URL);
                    // // //     } else {
                    // // //         $response = array('success' => false, 'TrackId' => $strUrlData, 'IsTJFlightAPI' => 0, 'msg' => "Oop's unable to debit from agent wallet. " . $message, 'urlData' => $strUrlData, 'formAction' => "/flight/booking-confirmation/data/" . $strUrlData . "");
                    // // //         echo json_encode($response);
                    // // //         exit;
                    // // //     }
                    // // // } elseif ($IsEnabledWallet == 1 && $paymentModebyUser == 1) {
                    // // //     $apiDataIV = array(
                    // // //         "CustomerSysId" => $CustomerSysId,
                    // // //     );

                    // // //     $result = json_decode($model->GetB2Cbalance($apiDataIV, $SecurityKey), true);
                    // // //     $walletstatus = (isset($result['status']) && !empty($result['status'])) ? $result['status'] : 0;
                    // // //     $walletBalanceAmount = (isset($result['WalletBalance'][0]['BalanceAmount']) && !empty($result['WalletBalance'][0]['BalanceAmount'])) ? $result['WalletBalance'][0]['BalanceAmount'] : 0;
                    // // //     if ($walletstatus == 1) {
                    // // //         if ($walletBalanceAmount >= $PublishedFare) {
                    // // //             $DebitFromWallet = array(
                    // // //                 'Remark' => 'Hotel Booking ',
                    // // //                 'Amount' => $PublishedFare,
                    // // //                 'CustomerSysId' => $CustomerSysId,
                    // // //                 'PlanType' => 2,
                    // // //                 'PaymentMode' => 'Online Wallet',
                    // // //                 'ReferenceNo' => $bookingId,
                    // // //                 'CurrencyType' => $this->CurrencyId,
                    // // //                 'FlightTraceId' => $strUrlData,
                    // // //             );
                    // // //             $URL_ = $this->baseUrl . '/gtxwebservices/customer-wallet/update-b2c-wallet-balance/';
                    // // //             $updateBalance = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->B2CDebitFromWallet($DebitFromWallet, $URL_, $this->intLoggedinAgencyId, $SecurityKey);
                    // // //             $TransactionId = isset($updateBalance['TransactionId']) ? $updateBalance['TransactionId'] : 0;
                    // // //         } else {
                    // // //             $response = array('success' => false, 'TrackId' => $strUrlData, 'IsTJFlightAPI' => 0, 'msg' => 'Agent does not have sufficient Credit Balance. Use Pay Later or Ask customer to top up balance.', 'urlData' => $strUrlData, 'formAction' => "/flight/booking-confirmation/data/" . $TrackId . "");
                    // // //             echo json_encode($response);
                    // // //             exit;
                    // // //         }
                    // // //     }
                    // // // }

                    $bookingrequest = isset($arrUrlData['bookingrequest']) ? $arrUrlData['bookingrequest'] : [];
                    $Invoicedata = isset($arrUrlData['Invoicedata']) ? $arrUrlData['Invoicedata'] : [];
                    // echo "<pre>DataS";
                    // print_r(($paymentModebyUser));
                    // echo "<pre>DataS";
                    // print_r(($arrUrlData));
                    // die;
                    $nights = (int) $SearchParams['hotelTotalNights'];
                    $rooms = (int) $SearchParams['hotelTotalRooms'];
                    $AdultPax = (int) $SearchParams['totalMemberCount']['AdultPax'];
                    $ChildPax = (int) $SearchParams['totalMemberCount']['ChildPax'];
                    $MemberCount = ($AdultPax + $ChildPax);
                    $CityName = $SearchParams['CityName'];
                    $tboCountryCode = $SearchParams['tboCountryCode'];
                    if ($tboCountryCode != 'IN') {
                        $interNationalSearch = true;
                    } else {
                        $interNationalSearch = false;
                    }

                    $request = array(
                        "EndUserIp" => $_SERVER['REMOTE_ADDR'],
                        'TokenAgencyId' => '',
                        'TokenMemberId' => '',
                    );
                    $DataS = array(
                        'apidata' => $request,
                        'memberCount' => 0,
                        'JourneyType' => 0,
                        'interNationalSearch' => $interNationalSearch,
                        'searchID' => $strUrlData,
                        'ICSourceSysId' => $ICSourceSysId,
                        'APIMode' => ($this->intLoggedinAgencyId == 1) ? 1 : 0
                    );
                    $url = GTX_API_URL . '/flight/v3/getbalnace';
                    $getData['SecurityKey'] = $SecurityKey;

                    $apiResponse = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->apiHttpRequest($DataS, $getData, $url);
                    $CashBalance = (isset($apiResponse['results']) && !empty($apiResponse['results'])) ? (float)$apiResponse['results'] : 0;


                    if ($CashBalance >= (float) ceil($PublishedFare)) {
                    } else {
                        $response = array('success' => false, 'TrackId' => base64_encode($urlData), 'msg' => 'Sorry we could not process your booking. Please contact our customer support. (API Insufficient Balance)');
                        echo json_encode($response);
                        exit;
                    }
                    $APIBookingresponse = [];
                    $GTXUpdateresponse = [];
                    $DataS = array(
                        "request" => $bookingrequest,
                        "searchID" => $searchId,
                        "MemberCount" => $MemberCount,
                        "destination" => $CityName,
                        "nights" => $nights,
                        "rooms" => $rooms,
                        "PlanType" => 2,
                        "MPType" => 1,
                        "ICSourceSysId" => $ICSourceSysId,
                        "interNationalSearch" => $interNationalSearch,
                        "APIMode" => ($this->intLoggedinAgencyId == 1) ? 1 : 0
                    );

                    $url = GTX_API_URL . '/hotel/v2/hotelbook';
                    $getData['SecurityKey'] = $SecurityKey;
                    /////$hotelbook = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->apiHttpRequest($DataS, $getData, $url);
                    $hotelbook = json_decode('{"status":true,"message":"SUCCESS","data":{"bookingId":"TJS206601511157","status":{"success":true,"httpStatus":200}}}', 1);
                    $ResponseStatus = isset($hotelbook['status']) ? $hotelbook['status'] : false;
                    $ErrorMessage = isset($hotelbook['message']) ? $hotelbook['message'] : '';
                    // echo "hotelbook";
                    // print_r(json_encode($hotelbook));
                    // echo "DataS";
                    // print_r(($DataS));
                    // die;
                    if ($ResponseStatus == 1) {
                        if ($ICSourceSysId == 3) {
                            $BookingId = $hotelbook['data']['BookResult']['BookingId'];
                            $TraceId = $hotelbook['data']['BookResult']['TraceId'];
                            $BookingRefNo = $hotelbook['data']['BookResult']['BookingRefNo'];
                            $ConfirmationNo = $hotelbook['data']['BookResult']['ConfirmationNo'];
                            $request__['BookingId'] = $BookingId;
                        } else {
                            $BookingId = $hotelbook['data']['bookingId'];
                            $BookingRefNo = $hotelbook['data']['bookingId'];
                            $ConfirmationNo = $hotelbook['data']['bookingId'];
                            $request__['bookingId'] = $BookingId;
                        }

                        $DataSD = array(
                            "request" => $request__,
                            "searchID" => $searchId,
                            "MemberCount" => $MemberCount,
                            "destination" => $CityName,
                            "nights" => $nights,
                            "rooms" => $rooms,
                            "PlanType" => 2,
                            "MPType" => 1,
                            "ICSourceSysId" => $ICSourceSysId,
                            "interNationalSearch" => $interNationalSearch,
                            "APIMode" => ($this->intLoggedinAgencyId == 1) ? 1 : 0
                        );

                        $url = GTX_API_URL . '/hotel/v2/hotelbookdetails';
                        $getData['SecurityKey'] = $SecurityKey;
                        $apiResponse = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->apiHttpRequest($DataSD, $getData, $url);
                        $status = isset($apiResponse['status']) ? $apiResponse['status'] : false;
                        $message = isset($apiResponse['message']) ? $apiResponse['message'] : '';

                        if ($ICSourceSysId == 3) {
                            $VoucherStatus = isset($apiResponse['data']['GetBookingDetailResult']['VoucherStatus']) ? $apiResponse['data']['GetBookingDetailResult']['VoucherStatus'] : false;
                            $OrderStatus = isset($apiResponse['data']['GetBookingDetailResult']['HotelBookingStatus']) ? $apiResponse['data']['GetBookingDetailResult']['HotelBookingStatus'] : '';
                            $ErrorMessage = isset($apiResponse['GetBookingDetailResult']['Error']['ErrorMessage']) ? $apiResponse['GetBookingDetailResult']['Error']['ErrorMessage'] : '';
                        } else {
                            $VoucherStatus = false;
                            $OrderStatus = isset($apiResponse['data']['order']['status']) ? $apiResponse['data']['order']['status'] : 0;
                            $ErrorMessage = isset($apiResponse['errors'][0]['message']) ? $apiResponse['errors'][0]['message'] : '';
                        }

                        $postFieldArray = [
                            "MasterTPSysId" => $MasterTPSysId,
                            "TPSysId" => $TPSysId,
                            "VersionId" => $VersionId,
                            "XRefBookingId" => $searchId,
                            "APIBookingid" => $BookingId,
                            "TrxId" => $TrxId,
                            "ErrorCode" => 1,
                            "BookingRefNo" => $BookingRefNo,
                            "ConfirmationNo" => $ConfirmationNo,
                            "TrxOrdDocId" => ($paymentModebyUser == 1) ? 19 : 0,
                            "hotelsource" => "API",
                            "AgencySysId" => $this->intLoggedinAgencyId,
                            "APIMode" => ($this->intLoggedinAgencyId == 1) ? 1 : 0
                        ];


                        $InvoiceValue = isset($Invoicedata['InvoiceValue']) ? $Invoicedata['InvoiceValue'] : 0;
                        $Invoicedata['AgentSysId'] = $this->intLoggedinAgencyId;
                        $Invoicedata['InvoiceStatus'] = ($checkPaymentStatus == 1) ? 1 : 5;
                        $Invoicedata['TotalAdvance'] = ($checkPaymentStatus == 1) ? round(($InvoiceValue), 2) : 0;
                        $Invoicedata['TotalDueAmount'] = ($checkPaymentStatus == 1) ? 0 : round(($InvoiceValue), 2);
                        //$OrderStatus = 'PAYMENT_SUCCESS';

                        if ($status == 1 && ($OrderStatus != 'ABORTED' || $OrderStatus != 'Cancelled' || $OrderStatus != 'BookFailed' || $OrderStatus != 'VerifyPrice')) {

                            $InvoiceCreate = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->InvoiceCreate($Invoicedata, [], $SecurityKey, $this->intLoggedinAgencyId);
                            if ($OrderStatus == 'PENDING' || $OrderStatus == 'PAYMENT_SUCCESS') {
                                $postFieldArray['ErrorCode'] = 0;
                            } elseif ($VoucherStatus != 1 && $ICSourceSysId == 3) {
                                $postFieldArray['ErrorCode'] = 0;
                            }

                            $URL = $this->baseUrl . "/gtxwebservices/hotel-api/updatebooking";
                            $result = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->apiHttpRequest($postFieldArray, $getData, $URL);
                            $GTXUpdateresponse = $result;
                            // echo "<pre>DataS";
                            // print_r(($result));
                            // echo "<pre>DataS";
                            // print_r(($postFieldArray));
                            // echo "<pre>InvoiceCreate";
                            // print_r(($InvoiceCreate));
                            // die;
                        } else {
                            if ($IsB2BCustomer == 1) {
                                $dataArray = array(
                                    'B2BAgencySysIdKey' => $B2CAgencySysIdKey,
                                    'B2CAgencySysIdKey' => $B2BAgencySysIdKey,
                                    'PaymentMode' => 'Wallet Refund',
                                    'Amount' => $B2BWalletbalance,
                                    'RefrenceNo' => $bookingId,
                                    'CreditDate' => date('Y-m-d'),
                                    'Remark' => 'Refund',
                                    'PlanType' => 2,
                                    'CurrencyType' => $this->CurrencyId,
                                    'UserSysId' => $UserSysId,
                                    'FlightTraceId' => $strUrlData,
                                );
                                $URL_CREDIT = $this->baseUrl . '/webservice/credit-balance/save-online-request/';
                                $CreditIntoWallet = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->CreditIntoWallet($dataArray, $URL_CREDIT, $AgencySysId__);
                            } elseif ($IsEnabledWallet == 1 && $paymentModebyUser == 1) {
                                $DebitFromWallet = array(
                                    'Remark' => 'Refund',
                                    'Amount' => $PublishedFare,
                                    'CustomerSysId' => $CustomerSysId,
                                    'PlanType' => 1,
                                    'PaymentMode' => 'Wallet Refund',
                                    'ReferenceNo' => $bookingId,
                                    'CurrencyType' => $this->CurrencyId,
                                    'FlightTraceId' => $strUrlData,
                                );

                                $URL_ = $this->baseUrl . '/gtxwebservices/customer-wallet/add-b2c-wallet-balance/';
                                $CreditIntoWallet = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->B2CDebitFromWallet($DebitFromWallet, $URL_, $this->intLoggedinAgencyId, $SecurityKey);
                            }

                            $response = array(
                                'MasterTPSysId' => $MasterTPSysId,
                                'TPSysId' => $TPSysId,
                                'TrxId' => $TrxId,
                                'field' => 'BookingStatus',
                                'XRefBookingId' => '',
                                'ErrorCode' => 6,
                                'StatusCode' => 144,
                                'APIMode' => ($this->intLoggedinAgencyId == 1) ? 1 : 0,
                            );
                            $URL = $this->baseUrl . "/gtxwebservices/flight/update-api-payment-failed";
                            $result = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->getHttpRequestArray($response, $URL);
                            $GTXUpdateresponse = $result;
                        }
                    } else {

                        // // // if ($IsB2BCustomer == 1) {
                        // // //     $dataArray = array(
                        // // //         'B2BAgencySysIdKey' => $B2CAgencySysIdKey,
                        // // //         'B2CAgencySysIdKey' => $B2BAgencySysIdKey,
                        // // //         'PaymentMode' => 'Wallet Refund',
                        // // //         'Amount' => $B2BWalletbalance,
                        // // //         'RefrenceNo' => $bookingId,
                        // // //         'CreditDate' => date('Y-m-d'),
                        // // //         'Remark' => 'Refund',
                        // // //         'PlanType' => 2,
                        // // //         'CurrencyType' => $this->CurrencyId,
                        // // //         'UserSysId' => $UserSysId,
                        // // //         'FlightTraceId' => $strUrlData,
                        // // //     );
                        // // //     $URL_CREDIT = $this->baseUrl . '/webservice/credit-balance/save-online-request/';
                        // // //     $CreditIntoWallet = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->CreditIntoWallet($dataArray, $URL_CREDIT, $AgencySysId__);
                        // // // } elseif ($IsEnabledWallet == 1 && $paymentModebyUser == 1) {
                        // // //     $DebitFromWallet = array(
                        // // //         'Remark' => 'Refund',
                        // // //         'Amount' => $PublishedFare,
                        // // //         'CustomerSysId' => $CustomerSysId,
                        // // //         'PlanType' => 1,
                        // // //         'PaymentMode' => 'Wallet Refund',
                        // // //         'ReferenceNo' => $bookingId,
                        // // //         'CurrencyType' => $this->CurrencyId,
                        // // //         'FlightTraceId' => $strUrlData,
                        // // //     );

                        // // //     $URL_ = $this->baseUrl . '/gtxwebservices/customer-wallet/add-b2c-wallet-balance/';
                        // // //     $CreditIntoWallet = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->B2CDebitFromWallet($DebitFromWallet, $URL_, $this->intLoggedinAgencyId, $SecurityKey);
                        // // // }

                        $response = array(
                            'MasterTPSysId' => $MasterTPSysId,
                            'TPSysId' => $TPSysId,
                            'TrxId' => $TrxId,
                            'VersionId' => $VersionId,
                            'ErrorCode' => $ErrorMessage,
                            'StatusType' => 70, /// Query Confirmed
                            'BookingStatus' => 144, // Ticket Failed
                            'PaymentStatus' => ($checkPaymentStatus == 1) ? 22 : 147, // 147 - Pending Payment, 22 - Full Payment
                        );
                        $URL = $this->baseUrl . "/gtxwebservices/hotel-api/update-api-payment-failed";
                        $result = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->getHttpRequestArray($response, $URL);
                        $GTXUpdateresponse = $result;
                    }

                    $TransactionId = '';
                    $arrUrlData['Bookres'] = $hotelbook;
                    $arrUrlData['InvoiceCreate'] = $InvoiceCreate;
                    $arrUrlData['GTXUpdateresponse'] = $GTXUpdateresponse;
                    $arrUrlData['APIBookingresponse'] = $APIBookingresponse;
                    $arrUrlData['walletTransactionId'] = $TransactionId;
                    $arrUrlData['CreditIntoWallet'] = $CreditIntoWallet;
                    $arrUrlData['message'] = $message;
                    $tempData = array(
                        'TPSysId' => $intTPSysId,
                        'TraceId' => $searchId,
                        'APIBookingData' => json_encode($arrUrlData),
                    );

                    $objFlight->deleteFlightTempData($searchId);
                    $objFlight->insertFlightTempData($tempData);
                    $response = array('success' => true, 'TrackId' => base64_encode($urlData), 'msg' => $ErrorMessage, 'urlData' => $strUrlData, 'formAction' => "/hotel-proposal/booking-confirmation/data/" . $searchId . "?status=true");
                    echo json_encode($response);
                    exit;
                } else {
                    $response = array('success' => true, 'TrackId' => base64_encode($urlData), 'msg' => 'This Trace id already expired', 'urlData' => $strUrlData, 'formAction' => "/flight-new/booking-confirmation/data/" . $TPSysId . "");
                    echo json_encode($response);
                    exit;
                }
            } else {
                $response = array('success' => false, 'TrackId' => base64_encode($urlData), 'msg' => 'Session is already expired', 'urlData' => $strUrlData, 'formAction' => "/buyhotel/booking-confirmation/data/" . $searchId . "?status=true");
                echo json_encode($response);
                exit;
            }
        } else {
            $this->view->status = !empty($this->getRequest()->getParam('status')) ? $this->getRequest()->getParam('status') : '';
            $this->view->strUrlData = $this->view->strUrlData = $this->getRequest()->getParam('data');
            $this->view->TrxSysId = $this->getRequest()->getParam('TrxSysId');
            $this->view->TPSysId = $this->getRequest()->getParam('TPSysId');
            $this->view->guid = $this->getRequest()->getParam('guid');
        }
    }


    public function bookingConfirmationAction()
    {

        // ini_set('display_errors', 1);
        // ini_set('display_startup_errors', 1);
        // error_reporting(E_ALL);
        $param = $this->getRequest()->getParams();
        $this->view->SearchHotelTraceId = ($this->getRequest()->getParam('data'));
        $searchIDSearch = $this->view->searchIDSearch = base64_decode($this->getRequest()->getParam('data'));

        if ($searchIDSearch) {
            $json_decode = json_decode($searchIDSearch, 1);

            $PostData = ['TPSysId' => ($json_decode['TPSysId'])];
            $getData['SecurityKey'] = $json_decode['SecurityKey'];
            $URL = $this->baseUrl . '/gtxwebservices/hotel-api/hotel-voucher';

            // $objTempFlight = new Travel_Model_TblFlight();
            // $FlightTempData = $objTempFlight->GetFlightTempDataByTPSysId(base64_decode($param['data']));

            $HOTEL_VOUCHER = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->apiHttpRequest($PostData, $getData, $URL);
            $HotelData = isset($HOTEL_VOUCHER['data']) ? $HOTEL_VOUCHER['data'] : [];
            $PaymentStatus = isset($HotelData['HotelData']['PaymentStatus']) ? $HotelData['HotelData']['PaymentStatus'] : '';
            $CurrentStatus = isset($HotelData['HotelData']['CurrentStatus']) ? $HotelData['HotelData']['CurrentStatus'] : '';
            $BookingStatus = isset($HotelData['HotelData']['BookingStatus']) ? $HotelData['HotelData']['BookingStatus'] : '';
            $XrefBookingId = isset($HotelData['HotelData']['XrefBookingId']) ? $HotelData['HotelData']['XrefBookingId'] : '';
            $TPSysId = isset($HotelData['HotelData']['TPSysId']) ? $HotelData['HotelData']['TPSysId'] : '';
            $accom_room = isset($HotelData['accom_room']) ? $HotelData['accom_room'] : [];
            $ICSourceSysId = isset($HotelData['HotelData']['ICSourceSysId']) ? $HotelData['HotelData']['ICSourceSysId'] : 0;
            $MasterTPSysId = isset($HotelData['HotelData']['MasterTPSysId']) ? $HotelData['HotelData']['MasterTPSysId'] : 0;

            $objFlightProposal = new Travel_Model_TblFlightProposal();
            $crmcustomerObj = new Travel_Model_CRM_Customer();
            $arrAgencyDetails = $this->view->arrAgencyDetails = $objFlightProposal->getProposalAgencyDetails($MasterTPSysId, 'query');
            // echo "<pre>post";
            // print_r(($arrAgencyDetails));
            // echo "<pre>post";
            // print_r(($HotelData['HotelData']));
            // die;
            if ($this->_request->isXmlHttpRequest()) {

                if ($TPSysId && $searchIDSearch) {
                    $TotalBaseFare = 0;
                    $TotalTaxesandFee = 0;
                    $TotalDiscount = 0;
                    $Currncy = '';
                    $TotalCommissionEarned = 0;
                    $TotalFixedMarkUp = 0;
                    $TotalGSTOnMarkUp = 0;
                    $TotalTDSEarn = 0;
                    $BaseFareArray = [];
                    if ($accom_room) {
                        foreach ($accom_room as $key => $values) {
                            $Currncy = $values['Currency'];
                            $BaseFare = ($values['RoomPrice']);
                            $TotalBaseFare += ($values['RoomPrice']);
                            $TotalFixedMarkUp += ($values['AgencyMarkUp']);
                            $TotalGSTOnMarkUp += ($values['GSTOnAgencyMarkUp']);
                            $TotalTaxesandFee += (($values['Taxes']));
                            $BaseFareArray[$key] = ['BaseFare' => $BaseFare, 'name' => $values['RoomTypeName'], 'MealBase' => $values['MealPlanType']];
                        }
                    }

                    $fare = array(
                        'Currncy' => $Currncy,
                        'BaseFare' => round($TotalBaseFare, 2),
                        'TaxesandFee' => round($TotalTaxesandFee, 2),
                        'GrandTotal' => round($TotalBaseFare + $TotalTaxesandFee + $TotalFixedMarkUp + $TotalGSTOnMarkUp, 2),
                        'CommissionEarned' => round($TotalCommissionEarned, 2),
                        'TDSEarn' => round($TotalTDSEarn, 2),
                        'Discount' => round($TotalDiscount, 2),
                        'FixedMarkUp' => round($TotalFixedMarkUp, 2),
                        'GSTOnMarkUp' => round($TotalGSTOnMarkUp, 2),
                        'roomCoun' => count($accom_room),
                        'nightCoun' => ($HotelData['HotelData']['TotalNights']),
                        'BaseFareArray' => ($BaseFareArray),
                    );
                    echo json_encode([
                        'status' => true,
                        'message' => 'SUCESS',
                        'fare' => $fare,
                        'HotelData' => $HotelData,
                    ]);
                    exit;
                }
            }

            $this->view->intLoggedinUserId = $this->intLoggedinUserId;
            $this->view->intLoggedinUserGroupSysId = $this->intLoggedinUserGroupSysId;
            $this->view->intLoggedinUserAgencySysId = $this->intLoggedinUserAgencySysId;
            $this->view->searchID = $searchIDSearch;
            $this->view->TPSysId = $TPSysId;
            $this->view->PaymentStatus = $PaymentStatus;
            $this->view->CurrentStatus = $CurrentStatus;
            $this->view->BookingStatus = $BookingStatus;
            $this->view->XrefBookingId = $XrefBookingId;
            $this->view->ActionName = 'confirm';
        }
    }

    public function printvoucherAction()
    {
        $this->_helper->layout->disableLayout();
        // ini_set('display_errors', 1);
        // ini_set('display_startup_errors', 1);
        // error_reporting(E_ALL);
        $param = $this->getRequest()->getParams();
        $this->view->SearchHotelTraceId = ($this->getRequest()->getParam('data'));
        $searchIDSearch = $this->view->searchIDSearch = base64_decode($this->getRequest()->getParam('data'));


        if ($searchIDSearch) {
            $json_decode = json_decode($searchIDSearch, 1);
            $PostData = ['TPSysId' => ($json_decode['TPSysId'])];
            $getData['SecurityKey'] = $json_decode['SecurityKey'];

            $URL = $this->baseUrl . '/gtxwebservices/hotel-api/hotel-voucher';
            $HOTEL_VOUCHER = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->apiHttpRequest($PostData, $getData, $URL);

            $HotelData = isset($HOTEL_VOUCHER['data']) ? $HOTEL_VOUCHER['data'] : [];
            $XrefBookingId = isset($HotelData['HotelData']['XrefBookingId']) ? $HotelData['HotelData']['XrefBookingId'] : '';
            $HotelCountry = isset($HotelData['HotelData']['HotelCountry']) ? $HotelData['HotelData']['HotelCountry'] : '';
            $AgencySysId = isset($HotelData['HotelData']['AgencySysId']) ? $HotelData['HotelData']['AgencySysId'] : 0;
            $accom_room = isset($HotelData['accom_room']) ? $HotelData['accom_room'] : [];



            $url = GTX_API_URL . '/flight/v3/get-agency-term-and-condtions';
            $getData['SecurityKey'] = $json_decode['SecurityKey'];
            $DataTC = ['AgencySysId' => $AgencySysId];
            $TermsAndCondition = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->apiHttpRequest($DataTC, $getData, $url);
            $TCHotelVoucher = isset($TermsAndCondition['results']['TCHotelVoucher']) ? $TermsAndCondition['results']['TCHotelVoucher'] : '';


            // echo "<pre>post";
            // print_r(($TCHotelVoucher));
            // echo "<pre>post";
            // print_r(($HotelData['HotelData']));
            // die;
            $TotalBaseFare = 0;
            $TotalTaxesandFee = 0;
            $TotalDiscount = 0;
            $Currncy = '';
            $TotalCommissionEarned = 0;
            $TotalFixedMarkUp = 0;
            $TotalGSTOnMarkUp = 0;
            $TotalTDSEarn = 0;
            $BaseFareArray = [];
            if ($accom_room) {
                foreach ($accom_room as $key => $values) {
                    $Currncy = $values['Currency'];
                    $BaseFare = ($values['RoomPrice']);
                    $TotalBaseFare += ($values['RoomPrice']);
                    $TotalFixedMarkUp += ($values['AgencyMarkUp']);
                    $TotalGSTOnMarkUp += ($values['GSTOnAgencyMarkUp']);
                    $TotalTaxesandFee += (($values['Taxes']));
                    $BaseFareArray[$key] = ['BaseFare' => $BaseFare, 'name' => $values['RoomTypeName'], 'MealBase' => $values['MealPlanType']];
                }
            }

            $fare = array(
                'Currncy' => $Currncy,
                'BaseFare' => round($TotalBaseFare, 2),
                'TaxesandFee' => round($TotalTaxesandFee, 2),
                'GrandTotal' => round($TotalBaseFare + $TotalTaxesandFee + $TotalFixedMarkUp + $TotalGSTOnMarkUp, 2),
                'CommissionEarned' => round($TotalCommissionEarned, 2),
                'TDSEarn' => round($TotalTDSEarn, 2),
                'Discount' => round($TotalDiscount, 2),
                'FixedMarkUp' => round($TotalFixedMarkUp, 2),
                'GSTOnMarkUp' => round($TotalGSTOnMarkUp, 2),
                'roomCoun' => count($accom_room),
                'nightCoun' => ($HotelData['HotelData']['TotalNights']),
                'BaseFareArray' => ($BaseFareArray),
            );

            if (isset($param['email']) && $param['email'] == true) {
                $withprice = $param['withprice'];
                $withcancellation = $param['withcancellation'];
                $EticketEmail = $param['EticketEmail'];
                $objMarkup = new Markup_Model_Markup();
                $_crmcustomerObj = new Travel_Model_CRM_Customer();
                if (!empty(trim($HotelCountry)) && trim($HotelCountry) != "India") {
                    $intAirType = 2;
                } else {
                    $intAirType = 1;
                }
                $arrAgencyUserDetail = $objMarkup->getAgencyUserDetail(array("AgencySysId" => $AgencySysId, "ItemSourceType" => (int) $intAirType, "PlanType" => 2, 'MarketType' => 1));
                $this->view->arrAgencyUserDetail = $arrAgencyUserDetail;
                $getAgencyDetail = $_crmcustomerObj->GetAgencyDetailById($AgencySysId);
                $fromName = (isset($getAgencyDetail['DisplayName']) && !empty($getAgencyDetail['DisplayName'])) ? trim($getAgencyDetail['DisplayName']) : trim(trim($getAgencyDetail['Title']));
                $emailSendId = trim($getAgencyDetail['PrimaryEmail']);
                $IsBookingEmail = (isset($arrAgencyUserDetail) && !empty($arrAgencyUserDetail['IsBookingEmail'])) ? $arrAgencyUserDetail['IsBookingEmail'] : 0;
                if (isset($arrAgencyUserDetail) && !empty($arrAgencyUserDetail['EmailId']) && $IsBookingEmail == 1) {
                    $ToemailSendId = trim($arrAgencyUserDetail['EmailId']);
                } else {
                    $ToemailSendId = $emailSendId; //$this->intLoggedinUserEmailId; Email Delivered SuccessFully
                }

                $html = new Zend_View();
                $html->setScriptPath(APPLICATION_PATH . '/views/scripts/buyhotel/');
                $html->assign(array('apiResponse' => $HOTEL_VOUCHER, 'fare' => $fare, 'TCHotelVoucher' => $TCHotelVoucher, 'withcancellation' => $withcancellation, 'withprice' => $withprice));

                $bodyText = $html->render('printvoucher.phtml');

                $emailData = array(
                    'fromEmail' => $ToemailSendId,
                    'fromName' => $fromName,
                    'subject' => 'Hotel Booking Confirmation',
                    'to' => array($EticketEmail),
                    'bodyHtml' => $bodyText,
                    'bodyText' => ''
                );

                $arrEmailStatisticsType = array_keys(unserialize(ARR_EMAIL_STATISTICS_TYPE));
                $arrEmailStatistics = array(
                    "TPSysId" => 0,
                    "TypeSysId" => 1, // 1 For Email 2 For SMS
                    "AgencySysId" => $AgencySysId,
                    "AgentSysId" => $AgencySysId,
                    "Title" => $bodyText,
                    "Source" => $arrEmailStatisticsType[1], // 1 For Vouchers
                    "Status" => 0,
                    "RefSysId" => "",
                    "RefSysStatus" => "",
                    "CreateDate" => date('Y-m-d H:i:s')
                );
                $emailResponse = json_decode($this->mailSentByElastice($emailData, $arrEmailStatistics), true);
                if ($emailResponse['success']) {
                    $response = array('success' => true);
                    echo json_encode($response);
                    exit;
                } else {
                    $response = array('success' => false);
                    echo json_encode($response);
                    exit;
                }
                // echo "<pre>post";
                // print_r(($emailResponse));
                // echo "<pre>post";
                // print_r(($fare));
                // die;
            }


            $this->view->XrefBookingId = $XrefBookingId;
            $this->view->apiResponse = $HOTEL_VOUCHER;
            $this->view->fare = $fare;
            $this->view->TCHotelVoucher = $TCHotelVoucher;
            $this->view->ActionName = 'confirm';
        }
    }

    public function printinvoiceAction()
    {
        $this->_helper->layout->disableLayout();
        // ini_set('display_errors', 1);
        // ini_set('display_startup_errors', 1);
        // error_reporting(E_ALL);
        $param = $this->getRequest()->getParams();
        $this->view->SearchHotelTraceId = ($this->getRequest()->getParam('data'));
        $searchIDSearch = $this->view->searchIDSearch = base64_decode($this->getRequest()->getParam('data'));

        if ($searchIDSearch) {

            $json_decode = json_decode($searchIDSearch, 1);
            $PostData = ['TPSysId' => ($json_decode['TPSysId'])];
            $getData['SecurityKey'] = $json_decode['SecurityKey'];

            $URL = $this->baseUrl . '/gtxwebservices/hotel-api/hotel-voucher';
            $HOTEL_VOUCHER = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->apiHttpRequest($PostData, $getData, $URL);

            $HotelData = isset($HOTEL_VOUCHER['data']) ? $HOTEL_VOUCHER['data'] : [];
            $XrefBookingId = isset($HotelData['HotelData']['XrefBookingId']) ? $HotelData['HotelData']['XrefBookingId'] : '';
            $accom_room = isset($HotelData['accom_room']) ? $HotelData['accom_room'] : [];
            $AgencySysId = isset($HotelData['HotelData']['AgencySysId']) ? $HotelData['HotelData']['AgencySysId'] : 0;


            $url = GTX_API_URL . '/flight/v3/get-agency-term-and-condtions';
            $getData['SecurityKey'] =  $json_decode['SecurityKey'];
            $DataTC = ['AgencySysId' => $AgencySysId];
            $TermsAndCondition = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->apiHttpRequest($DataTC, $getData, $url);
            $FlightInvoice = isset($TermsAndCondition['results']['FlightInvoice']) ? $TermsAndCondition['results']['FlightInvoice'] : '';

            $TotalBaseFare = 0;
            $TotalTaxesandFee = 0;
            $TotalDiscount = 0;
            $Currncy = '';
            $TotalCommissionEarned = 0;
            $TotalFixedMarkUp = 0;
            $TotalGSTOnMarkUp = 0;
            $TotalTDSEarn = 0;
            $BaseFareArray = [];
            if ($accom_room) {
                foreach ($accom_room as $key => $values) {
                    $Currncy = $values['Currency'];
                    $BaseFare = ($values['RoomPrice']);
                    $TotalBaseFare += ($values['RoomPrice']);
                    $TotalFixedMarkUp += ($values['AgencyMarkUp']);
                    $TotalGSTOnMarkUp += ($values['GSTOnAgencyMarkUp']);
                    $TotalTaxesandFee += (($values['Taxes']));
                    $BaseFareArray[$key] = ['BaseFare' => $BaseFare, 'name' => $values['RoomTypeName'], 'MealBase' => $values['MealPlanType']];
                }
            }

            $fare = array(
                'Currncy' => $Currncy,
                'BaseFare' => round($TotalBaseFare, 2),
                'TaxesandFee' => round($TotalTaxesandFee, 2),
                'GrandTotal' => round($TotalBaseFare + $TotalTaxesandFee + $TotalFixedMarkUp + $TotalGSTOnMarkUp, 2),
                'CommissionEarned' => round($TotalCommissionEarned, 2),
                'TDSEarn' => round($TotalTDSEarn, 2),
                'Discount' => round($TotalDiscount, 2),
                'FixedMarkUp' => round($TotalFixedMarkUp, 2),
                'GSTOnMarkUp' => round($TotalGSTOnMarkUp, 2),
                'roomCoun' => count($accom_room),
                'nightCoun' => ($HotelData['HotelData']['TotalNights']),
                'BaseFareArray' => ($BaseFareArray),
            );
            // echo "<pre>post";
            // print_r(($TermsAndCondition));
            // die;

            $this->view->XrefBookingId = $XrefBookingId;
            $this->view->apiResponse = $HOTEL_VOUCHER;
            $this->view->fare = $fare;
            $this->view->FlightInvoice = $FlightInvoice;
            $this->view->ActionName = 'confirm';
        }
    }

    public function json_validate(string $json): bool
    {
        if (empty($json)) {
            return false; // Empty strings are not valid JSON
        }
        json_decode($json);
        return (json_last_error() == JSON_ERROR_NONE);
    }

    public function getRanges($intMin, $intMax, $intRanges = 1)
    {

        $intRange = $intMax - $intMin;
        $intIncrement = abs($intRange / $intRanges);
        $arrRanges = array();

        for ($i = 0; $i < $intRanges; $i++) {
            $arrRanges[] = $i == 0 || $i == ($intRanges - 1) ? $i == 0 ? $intMin : $intMax : $intMin + ($i * $intIncrement);
        }

        return $arrRanges;
    }
    public function renderRanges($arrRanges, $strSelected = '', $strName = 'ranges')
    {

        $DataArray = [];
        foreach ($arrRanges as $intIndex => $intRange) {
            $intMin = $intIndex == 0 ? $intRange : $arrRanges[($intIndex - 1)];
            $intMax = $intIndex == 0 ? $arrRanges[($intIndex + 1)] : $intRange;
            $DataArray[] = ceil($intMin) . '-' . ceil($intMax);
        }
        return array_unique($DataArray);
    }

    public function generateNumericOTP($n)
    {
        $generator = "1357902468";
        $result = "";
        for ($i = 1; $i <= $n; $i++) {
            $result .= substr($generator, (rand() % (strlen($generator))), 1);
        }
        // Return result
        return $result;
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit