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

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/b2bzend/application/admin/controllers/ProposalController.php
<?php
/**
 * Class City
 *
 * @name		City
 * @author		Er Amit Kumar Dubey 
 * @version 	1.0
 * @copyright 	GTX
 * Handle Without Session Data Related function for Front end only
 *
 */
class Admin_ProposalController extends Catabatic_ValidateAdmin{
    
    const CONST_SOURCE_ADMIN = 3;
    
    protected $intLoggedinUserId = '';
    protected $intLoggedinUserGroupSysId = '';
    protected $intLoggedinUserAgencySysId = '';
    protected $intLoggedinUserTrxCurrency = '';
    protected $InfoSourceSysId = '';
    
    
    public function init() {
        parent::init();
        $this->model = @$this->modelName ? new $this->modelName() : null;
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $this->baseUrl = $request->getScheme() . '://' . $request->getHttpHost();

        $sessionLogin_user = new Zend_Session_Namespace('sessionLogin_user');
        $this->intLoggedinUserId = $sessionLogin_user->intLoggedinUserId;
        $this->GRID_PER_PAGE_RECORD_COUNT = GRID_PER_PAGE_RECORD_COUNT;
        $this->InfoSourceSysId = self::CONST_SOURCE_ADMIN; // Source - Agent 
        
        
        
        $this->_crmcustomerObj = new Travel_Model_CRM_Customer();
		$this->_crmcusttravelplan = new Travel_Model_CRM_CustomerTravelPlan();
		$this->_crmcusttravelplanHotel = new Travel_Model_CRM_CustomerTravelPlanHotel();
		$this->_crmcusttravelplanAccom = new Travel_Model_CRM_CustomerTravelPlanAccom();
		$this->_crmcustomertravelItenary = new Travel_Model_CRM_CustomerTravelItenary();
		$this->_HtmlPurifier = new Zend_Filter_HtmlPurifier();
        
    }
	
	public function previewHotelResultAction(){
		$this->_helper->layout->disableLayout();
		$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$pid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('pid')));
		$uid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('uid')));
		$type = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('type')));
		$strdecode = @$this->getDec($uid);
		if(isset($mid) && !empty($mid)){
			if(isset($type) && !empty($type)){
				$typedecode = @$this->getDec($type);
				$proposalList=$this->_crmcusttravelplan->GetPublicProposalWithHotelListByPlanId($mid,$pid);
			}else{ 
				$proposalListAPI=$this->_crmcusttravelplan->GetPublicProposalWithHotelList($mid,$pid);
				$proposalInvetoryList = $this->_crmcusttravelplan->GetPublicProposalWithInventoryHotelList($mid);
                                $proposalList = array_merge($proposalListAPI,$proposalInvetoryList);
                                //$proposalList = array_unique($proposalList);
			}
			
		//echo "<pre>";print_r($proposalList);die;
		if($proposalList[0]['StatusType']==17){
			$this->_redirect('/proposal/booking-confirmation/mid/'.base64_encode($mid).'/pid/'.base64_encode($pid).'/uid/'.base64_encode($uid).'');
			exit;
		}
		$strdecode=explode(':',$strdecode);
		$CustomerSysId=@$proposalList[0]['CustomerSysId'];
		//echo $strdecode[0]."/".intval($CRMCustSysId).":".$strdecode[2]."/".intval($proposalId);
		if((@$strdecode[0]!=intval($CustomerSysId)) || (@$strdecode[2]!=intval($mid))){
			//$this->view->strmismatch="Already booked this proposal or Some thing went wrong.Please contact to administrator";
			//echo "Already booked this proposal or Some thing went wrong.Please contact to administrator";
			$this->_redirect("/proposal/preview-hotel-result-view/mid/".base64_encode($mid)."/pid/".base64_encode($pid)."/uid/".base64_encode($uid)."/type/".base64_encode($type));
			die;
		}
		
		$this->view->uid=$uid;
		$sessionLogin_user = new Zend_Session_Namespace('sessionLogin_user');
		//echo "<pre>";print_r($proposalList);die;
		//$sessionLogin_user->intLoggedinUserAgencySysId=$proposalList[0]['AgencySysId'];  please remove comment from this lime and comment next line to remove static data
		$sessionLogin_user->intLoggedinUserAgencySysId=$proposalList[0]['AgencySysId'];
		$objHotel = new Travel_Model_TblBuyHotel();            
      	$this->view->markupAgency=$objHotel->getAgencyMarkup();
		//$sessionLogin_user->intLoggedinUserAgencySysId='';
		//print_r($sessionLogin_user->intLoggedinUserAgencySysId);
		$this->view->proposalList=$proposalList;
		$this->view->proposalId=$mid;
		//$leadId=$proposalId;
		$leadId=$proposalList[0]['TPSysId'];
		//code for hotel modify search
				$getLeadlist = $this->_crmcusttravelplan->GetPublicPageLeadList($CustomerSysId, $proposalList[0]['AgencySysId'], $leadId);	
				//echo "<pre>"; print_r($getLeadlist);die;
						if (isset($getLeadlist[0]['hotelFromDate']) && !empty($getLeadlist[0]['hotelToDate'])) {
					$fromDate = $getLeadlist[0]['hotelFromDate']->format('Y-m-d');
					$toDate = $getLeadlist[0]['hotelToDate']->format('Y-m-d');
					// input format should be 206-03-25
					$totalDays = Zend_Controller_Action_HelperBroker::getStaticHelper('DateFormat')->calculateNoOfDays($fromDate, $toDate);
				}
				$roomjsonarray=json_decode($getLeadlist[0]['RoomMemInfoJson'],1);
				//echo "<pre>";print_r($roomjsonarray);die;
				for ($d = 1; $d <= count($roomjsonarray); $d++) {
					$getLeadlist[0]['hotelTotalRooms'] = count($roomjsonarray);
					$getLeadlist[0]['memberDetails'][] = array('AdultPax' => $roomjsonarray[$d]['adult'], 'ChildPax' => $roomjsonarray[$d]['child']['childcount'], 'ChildsAge' => @$roomjsonarray[$d]['child']['childage']);
				}
				$getLeadlist[0]['searchType'] = 'CRMHOTELSEARCH';
				$getLeadlist[0]['TPSysId'] = $leadId;
				$getLeadlist[0]['TPIntSysId'] = isset($getLeadlist[0]['TPIntSysId'])?$getLeadlist[0]['TPIntSysId']:'';
				$objCity = new Travel_Model_TblCity();
				$objCity->intCityId=isset($getLeadlist[0]['hotelXrefCityId'])?$getLeadlist[0]['hotelXrefCityId']:'';
				$cityList = $objCity->getCityList();
				$hoteltbbcityid='';
				//print_r($cityList);die;
					if(!empty($cityList)) { 
						$hoteltbbcityid=$cityList[0]['TBBCityId'];
					}
				$getLeadlist[0]['hidden_selected_hotel_id'] = $hoteltbbcityid;
				$getLeadlist[0]['hotelFromDateSession'] = isset($getLeadlist[0]['hotelFromDate']) ? $getLeadlist[0]['hotelFromDate']->format('d-M-y') : '';
				$getLeadlist[0]['customername'] = isset($getCustomerDetail['FullName'])?$getCustomerDetail['FullName']:'';
				$getLeadlist[0]['emailID'] = isset($getCustomerDetail['EmailId'])?$getCustomerDetail['EmailId']:'';
				$getLeadlist[0]['customerId'] = $CustomerSysId;
				$getLeadlist[0]['hotelToDateSession'] = isset($getLeadlist[0]['hotelToDate']) ? $getLeadlist[0]['hotelToDate']->format('d-M-y') : '';
				$getLeadlist[0]['hotelCountryCode'] = isset($getLeadlist[0]['Countries']) ? $getLeadlist[0]['Countries'] : '';
				$getLeadlist[0]['totalDays'] = isset($totalDays) ? $totalDays : 0;
				//echo "<pre>";print_r($getLeadlist);die;
				/*$hotelSearchSession = new Zend_Session_Namespace('hotelSearchSession');
				$hotelSearchSession->hotelSearchSession=$getLeadlist;*/
				$this->view->leadDetail=$getLeadlist;	
				//end of code for modify
				//create session for grn hotel search query

					$totalMemberCount = Zend_Controller_Action_HelperBroker::getStaticHelper('ArrayCalculation')->calculateArrayValues($getLeadlist[0]['memberDetails']);
				//end of grn hotel session
				
		//customer detail
				$tpID=$leadId;
				if (isset($CustomerSysId) && !empty($CustomerSysId)) {
			        $this->_crmcustomerObj = new Travel_Model_CRM_Customer();
					//$getCustomerDetail = $this->_crmcustomerObj->GetCustomerById($CRMCustSysId);
					$getCustomerDetail = $this->_crmcusttravelplan->GetTravelPlanCustomerDetails($tpID);
					
					//echo "<pre>";print_r($getCustomerDetail);die;
				$objAgencyUser = new Travel_Model_CRM_AgencyUserInbox();
				$checkCustomerChatExist = $getCustomerDetail[0]['CustomerSysId'] > 0? $objAgencyUser->CheckCustomerMsgCount($getCustomerDetail[0]['CustomerSysId'],$tpID,$proposalList[0]['AgentSysId']):array();
				$getversiondetails = $this->_crmcusttravelplan->GetVersionInfo($tpID);
				$getCustomerDetail['userChatExist']=count($checkCustomerChatExist);
				}
		//end of customer detail

		//query for get customer chat history
			$chatSenderDetails=array();
			if($getCustomerDetail['userChatExist'] > 0){
					if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
						$getChatHistoryDetail = $objAgencyUser->GetCustChatHistDetWithLead($tpID,$getCustomerDetail[0]['CustomerSysId'],'ASC');
						$this->view->chatHistoryDetail=$getChatHistoryDetail;
						$chatSenderDetails['TPSysId']=$tpID;
						$chatSenderDetails['AgencySysId']=$getLeadlist[0]['AgencySysId'];
						$chatSenderDetails['CustomerSysId']=$getCustomerDetail[0]['CustomerSysId'];
						$chatSenderDetails['AgentSysId']=$proposalList[0]['AgentSysId'];
						//$chatSenderDetails['EmailId']=$getcustomerDetail[0]['EmailId'];
						$objAgencyStaff   =	new Travel_Model_TblAgencyStaff();
						$agentDetail=$objAgencyStaff->getUserDetailsById($proposalList[0]['AgentSysId']);
						$chatSenderDetails['EmailId']=$agentDetail['EmailId'];
						//print_r($agentDetail);
						
						
					}
			}
			//end of customer chat history
			$agencyStaffObj = new Travel_Model_TblAgencyStaff();
			$agentDetail=$agencyStaffObj->getUserDetailsById($proposalList[0]['AgentSysId']);
			$AgencySysId = $getLeadlist[0]['AgencySysId'];
			$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1']);
			$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
			$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';

			//send email to agent when customer open proposal
				$isPlanViewed=$this->_crmcusttravelplan->GetTravelPlanType($mid);
				//echo "<pre>";print_r($getAgencyDetail);die;
				if($isPlanViewed['IsPlanViewed']==0){
						$emailSendId=trim($getAgencyDetail['PrimaryEmail']);
						$fromName=(isset($getAgencyDetail['DisplayName']) && !empty($getAgencyDetail['DisplayName']))?trim($getAgencyDetail['DisplayName']):trim(trim($getAgencyDetail['Title']));
						$emailId = trim($agentDetail['EmailId']);
						        $html = new Zend_View();
						        $html->setScriptPath(APPLICATION_PATH . '/views/scripts/proposal/');
								        $html->assign('type', 'proposalViewSendEmailToAgent');
										$html->assign('customerDetails', $getCustomerDetail);
										$html->assign('agentDetails', $agentDetail);
										$html->assign('agencyDetails', $getAgencyDetail);
										$link=$this->view->baseUrl("/proposal/preview-hotel-result/mid/".base64_encode($mid)."/pid/".base64_encode($pid)."/uid/".base64_encode($uid)."/type/".base64_encode($type));
										$html->assign('link',$link);
										$html->assign('data',$proposalList);
										//$html->assign('data', $hotelValues);
										$bodyText = $html->render('email-template.phtml');


						//$bodyText='Customer open your proposal' .$this->view->baseUrl("/proposal/preview-hotel-result/mid/".base64_encode($mid)."/pid/".base64_encode($pid)."/uid/".base64_encode($uid)."/type/".base64_encode($type));
						//$bodyText='Customer open your proposal' .$this->view->baseUrl("/proposal/preview-hotel-result/mid/".base64_encode($mid)."/pid/".base64_encode($pid)."/uid/".base64_encode($uid)."/type/".base64_encode($type));
						$emailData = array('fromEmail'=>trim($emailSendId),'fromName'=>trim($fromName),'subject'=>'HelloGTX - Proposal Open Alert !','to'=>array(trim($emailId)),'bodyHtml'=>$bodyText,'bodyText'=>'');
						$arrEmailStatisticsType = array_keys(unserialize(ARR_EMAIL_STATISTICS_TYPE));
						$arrSMSStatisticsType = array_keys(unserialize(ARR_SMS_STATISTICS_TYPE));
						$params['arrSMSStatisticsType'] = $arrSMSStatisticsType[0];
						$params['arrEmailStatisticsType'] = $arrEmailStatisticsType[2];
						$params['TPSysId']=$proposalList[0]['TPSysId'];
						$params['AgencySysId']=$proposalList[0]['AgencySysId'];
						$params['AgentSysId']=$proposalList[0]['AgentSysId'];
						   $arrEmailStatistics = array(
								"TPSysId" => $proposalList[0]['TPSysId'],
								"TypeSysId" => 1,  // 1 For Email 2 For SMS
								"AgencySysId" => $proposalList[0]['AgencySysId'],
								"AgentSysId" => $proposalList[0]['AgentSysId'],
								"Title" => $bodyText,
								"Source" => @$params['arrEmailStatisticsType'], // 3 For resend Proposals
								"Status" => 0,
								"RefSysId" => "",
								"RefSysStatus" => "",
								"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
						 );
						$this->mailSentByElastice($emailData,$arrEmailStatistics);

						//send sms
							$mobile_no = trim($agentDetail['ContactNo1']);
							$updateData = new Payment_Model_Checkotp();
							$bitly_response = Zend_Controller_Action_HelperBroker::getStaticHelper('Custom')->getSmallLinkFromBitlyAPI($link,$this->BITLYLOGIN,$this->BITLYAPIKEY);
							if($bitly_response['errorCode']==0){
								$link=$bitly_response['results'][$link]['shortUrl'];
							}
							$massage = "Your Customer(".trim($getCustomerDetail[0]['FirstName'])." ".trim($getCustomerDetail[0]['LastName'])."-".trim($getCustomerDetail[0]['Contacts']).") has just opened the proposal for ".trim(stripslashes($proposalList[0]['hotelCityTitle'])).",Click: ".$link." to view and assist for finalizing.";
							$this->postFields = "";
							$this->postFields .="&method=$this->SMSMETHOD";
							$this->postFields .="&api_key=$this->SMSAPIKEY";
							$this->postFields .="&to=$mobile_no";
							$this->postFields .="&sender=$this->SMSSENDER";
							$this->postFields .="&message=$massage";
							$this->postFields .="&format=$this->SMSFORMAT";
							$postURL = $this->SMSURL;
							// Added By Amit For SMS Count...
									$arrSMSStatistics = array(
															"TPSysId" => isset($params['TPSysId'])?$params['TPSysId']:0,
															"TypeSysId" => 2,  // 1 For Email 2 For SMS
															"AgencySysId" => isset($params['AgencySysId'])?$params['AgencySysId']:0,
															"AgentSysId" => isset($params['AgentSysId'])?$params['AgentSysId']:0,
															"Title" => $massage,
															"Source" => isset($params['arrSMSStatisticsType'])?$params['arrSMSStatisticsType']:1, // 2 Resend Proposals (Bulk)
															"Status" => '',
															"RefSysId" => '',
															"RefSysStatus" => "",
															"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
														);
														//print_r($arrSMSStatistics);
							// Added By AmitFor SMS Count Ends...
							//$resultVal = $updateData->sendSmsDetails($postURL, $this->postFields,$arrSMSStatistics);
							$resultVal['status'] = 'OK';
							 if (isset($resultVal['status']) && $resultVal['status'] == 'OK') {
								  $errorMessage = "";
							 }else{
								  $errorMessage = "Oops! Please try again";
							 }
							//echo $errorMessage."/".print_r($resultVal)."/".$massage."/".$mobile_no;
						//end of send sms

						$data = array(
							'isPlanViewed' => 1,
							'UpdateDate' => date('Y-m-d H:i:s'),
						);
						$where = "TPSysId = " . $mid;
						$updatetravelplanrecord = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($data, $where);
				}
			//#end

			
			$this->view->getAgentDetail=$getAgentDetail;
			$this->view->agencyDetails=$getAgencyDetail;
			$this->view->getcustomerDetail = $getCustomerDetail;
			$this->view->chatSenderDetails=$chatSenderDetails;
		}

	}
	public function customerChatPublicPageAction(){
        $this->view->layout()->disableLayout();
        //$this->_helper->viewRenderer->setNoRender(true);
		$CRMCustSysId = $this->getRequest()->getParam('cid') ? $this->_HtmlPurifier->filter($this->getRequest()->getParam('cid')) : '';
        $leadId = $this->getRequest()->getParam('id') ? $this->_HtmlPurifier->filter($this->getRequest()->getParam('id')) : '';
        $CRMCustSysId = base64_decode($CRMCustSysId);
        $leadId = base64_decode($leadId);
        if (isset($CRMCustSysId) && !empty($CRMCustSysId)) {
			$getChatHostoryDetail = $this->_crmcusttravelplan->GetCustomerChatHistoryDetails($leadId,'ASC');
			$this->view->type='viewCustomerChatPublicPage';
			$this->view->id=$leadId;
			$this->view->cid=$CRMCustSysId;
			$this->view->data=$getChatHostoryDetail;
			$this->render('ajax-html');
        }
		
	}
	//function for api
     public function getHotelDetailApiAction() {
        $this->_helper->viewRenderer->setNoRender(true);
        $this->_helper->layout->disableLayout();
        if($this->_request->isXmlHttpRequest()) {
            $resultIndex = $this->getRequest()->getParam('resultIndex');
            $hotelCode = $this->getRequest()->getParam("hotelCode");
            $userip = $this->getRequest()->getParam('userip');
            $tokenid = $this->getRequest()->getParam('tokenid');
            $traceid = $this->getRequest()->getParam('traceid');
            $tpid = $this->getRequest()->getParam('tpid');
            $curency = $this->getRequest()->getParam('curency');
            $markupty = $this->getRequest()->getParam('markupty');
            $markupAg = $this->getRequest()->getParam('markupAg');
            $objApi = new Travel_Model_ApiIntegration();
            $hotelInfo = $objApi->getHotelInfoWithoutDb($resultIndex, $hotelCode, $userip, $tokenid, $traceid);
			$hotelInfo['tpid']=$tpid;
			$hotelInfo['tpidEncode']=base64_encode($tpid);
			$session_hotelinfo = new Zend_Session_Namespace('HOTELINFO');
			$session_hotelinfo=$hotelInfo;
			//echo "<pre>";print_r($session_hotelinfo);die;
			
			//$selectedHotelResults = new Zend_Session_Namespace('selectedHotelResults');
			//$selectedHotelResults->selectedHotelResults=$hotelInfo;
			//print_r($hotelInfo);
			$travelPlanDetail=$this->_crmcusttravelplan->GetTravelPlanCustomerDetails($tpid);	
			$roomjsonarray=json_decode($travelPlanDetail[0]['RoomMemInfoJson'],1);	
			$hotelRoomD = $objApi->getHotelRoomDetail($userip, $tokenid, $traceid, $resultIndex, $hotelCode);
			//echo "<pre>";print_r($hotelRoomD);die;
			$session_hotel_room_detail = new Zend_Session_Namespace('HOTEL_ROOM_DETAIL');
            $session_hotel_room_detail = $session_hotel_room_detail;
			//get hotel aminities
				$objAminity = new Travel_Model_TblAmenities();
				$hotelAminity = $objAminity->getHotlAmenitiesforPopupApi($hotelCode);
				$hotelInfo['hotelAminity']=$hotelAminity;
			//end of hotel aminities

			//add markup for hotel in price
				if(isset($hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails']) && count($hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'])>0){
					$getCurrencyObj=new Travel_Model_TblCurrency();
					$getAccomRoomInfoObj=new Travel_Model_TblICAccomdationRoom();
					$updatedate=date('Y-m-d H:i:s');
					$J=1;
					for($i=0;$i<count($hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails']);$i++){
						$fetchRoomResult=$getAccomRoomInfoObj->GetAccomRoomDetail($travelPlanDetail[0]['hotelAccoSysId'],$hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['RoomTypeCode'],$J);
						//print_r($fetchRoomResult);
						if(count($fetchRoomResult)==0){
					$getCurrencyObj->strCurrencySymbol =$hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['Price']['CurrencyCode']; 
					$HelperCurrency = $getCurrencyObj->getCurrencyTypes();
					$CurrencyType=$HelperCurrency[0]['CurrencyType'];
					$AccomRoomInfoArray = array(
						'AccomSysId' => $travelPlanDetail[0]['hotelAccoSysId'],
						'SourceSysId' =>$travelPlanDetail[0]['ICSourceSysId'],
						'Title' => !empty($hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['RoomTypeName'])?$hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['RoomTypeName']:'',
						'TokenId' => $travelPlanDetail[0]['TokenId'],
						'TraceId' => $travelPlanDetail[0]['TraceId'],
						'RoomIndex' => $J,
						'Amenities'=>!empty($hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['Amenities'][0])?$hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['Amenities'][0]:'',
						'RoomNumber' => !empty($hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['RoomTypeCode'])?$hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['RoomTypeCode']:'',
						'Qty' => 1,
						'CurrencyType' => !empty($CurrencyType)?$CurrencyType:'',
						'PublishedFare' => !empty($hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['Price']['PublishedPrice'])?$hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['Price']['PublishedPrice']:'0',
						'Commission' => 0,
						'RoomType'=>0,
						'EconomyType'=>0,
						'BedType'=>0,
						'PaxCount'=>0,
						'IsPetAllow'=>0,
						'Location'=>'',
						'MaxPetAllow'=>0,
						'AllowChild'=>0,
						'AllowInfant'=>0,
						'MaxPaxCount'=>0,
						'MaxAllowChild'=>0,
						'MaxAllowInfant'=>0,
						'MealPlanType'=>0,
						'AminitiesMask'=>'',
						'InclustionOptionsMask'=>'',
						'OtherDetails' =>!empty($hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['Inclusions'][0])?$hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['Inclusions'][0]:'',
						'RoomTypeCode' => !empty($hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['RoomTypeCode'])?$hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['RoomTypeCode']:'',
						'RatePlanCode' => !empty($hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['RatePlanCode'])?$hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['RatePlanCode']:'',
						'RatePlanName' => !empty($hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['RatePlan'])?$hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['RatePlan']:'',
						'CancellationPolicy' => !empty($hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['CancellationPolicy'])?addslashes($hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['CancellationPolicy']):'',
						'UpdatedDate' => $updatedate,
						'CreateDate' => $updatedate,
						'IsApproved' => 1,
						'IsActive' => 1,
						'IsDelete' => 0
					);
					$getAccomRoomInfoObj->addAccomRoomInfo($AccomRoomInfoArray);
				} else{
					$AccomRoomInfoArrayUpdate = array(
						'Title' => !empty($hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['RoomTypeName'])?$hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['RoomTypeName']:'',
						'Amenities'=>!empty($hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['Inclusions'][0])?$hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['Inclusions'][0]:'',
						'TokenId' => $travelPlanDetail[0]['TokenId'],
						'TraceId' => $travelPlanDetail[0]['TraceId'],
						'Qty' => 1,
						'CurrencyType' => !empty($CurrencyType)?$CurrencyType:'',
						'PublishedFare' => !empty($hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['Price']['PublishedPrice'])?$hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['Price']['PublishedPrice']:'0',
						'OtherDetails' =>!empty($hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['Inclusions'][0])?$hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['Inclusions'][0]:'',
						'RoomNumber' => !empty($hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['RoomTypeCode'])?$hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['RoomTypeCode']:'',
						'RoomTypeCode' => !empty($hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['RoomTypeCode'])?$hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['RoomTypeCode']:'',
						'RatePlanCode' => !empty($hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['RatePlanCode'])?$hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['RatePlanCode']:'',
						'RatePlanName' => !empty($hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['RatePlan'])?$hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['RatePlan']:'',
						'UpdatedDate' => $updatedate,
					);
					//echo "<pre>";print_r($AccomRoomInfoArrayUpdate);
				$where = "AccomSysId = " . $travelPlanDetail[0]['hotelAccoSysId']." AND RoomIndex=".$J." AND RoomNumber='".$hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['RoomTypeCode']."'";
					$lastId=$getAccomRoomInfoObj->updateAccomRoomInfo($AccomRoomInfoArrayUpdate,$where);
				}
						
						
						
						
						$minprice=$hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['Price']['RoomPrice'];
						$minprice=$minprice*(count($roomjsonarray));
						if($curency > 0){
									//$priceMarAdd=Zend_Controller_Action_HelperBroker::getStaticHelper('CurrencyConversion')->InvToCurrency($curency,$markupty, $markupAg,$minprice);
									$priceMarAdd=$minprice;
								} else{
									$priceMarAdd=$markupAg+$minprice;
								}
						$hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['Price']['RoomPrice']=$minprice;
						$hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['Price']['RoomPriceWithMarkUp']=$priceMarAdd;
						$hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails'][$i]['Price']['RoomPriceDb']=$travelPlanDetail[0]['NetCost'];
						$J++;
					}
				}
			//end of markup
			//echo "<pre>";print_r($hotelRoomD['GetHotelRoomResult']['HotelRoomsDetails']);die;
		    $detail = array('hotelInfo' => $hotelInfo, 'hotelRoomD' => $hotelRoomD,'noOfRooms' => count($roomjsonarray));
            echo json_encode($detail);
			exit;
			
        }
    }
    public function bookSelectedRoomAction() {
	    $this->_helper->viewRenderer->setNoRender(true);
        $this->_helper->layout->disableLayout();
        if($this->_request->isXmlHttpRequest()) {
	        $objApi = new Travel_Model_ApiIntegration();
            $selectArr = $this->getRequest()->getParam('roomDetail');
            $tokenId = Zend_Controller_Action_HelperBroker::getStaticHelper('Flight')->authenticateAPI();
            //$_SESSION['authenticationtokenId'] = $tokenId;
            $resultIndex = $this->getRequest()->getParam('resultIndex');
            $tpid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('tpid')));
            //$noOfRooms = $this->getRequest()->getParam('noOfRooms');$selectArr['noOfRooms']
            $noOfRooms = $selectArr['noOfRooms'];
			 //echo "<pre>";print_r($selectArr);die;
            $roomindexID = $this->getRequest()->getParam('roomindexID');
            $noofRes = count($selectArr['hotelRoomD']['GetHotelRoomResult']['HotelRoomsDetails']);
            $cancellationPolicy = urldecode($this->getRequest()->getParam('cancellationPolicy'));
			   $cancellationPolicyObj = new Travel_Model_TblICAccomdationRoomCancellationPolicy();
			   $travelPlanDetail=$this->_crmcusttravelplan->GetTravelPlanCustomerDetails($tpid);
				//update room index in accom table
					$where = "TPIntSysId = " . $travelPlanDetail[0]['TPIntSysId'];
					$updatetravelplan = array(
						'RoomIndex' => $roomindexID,
						'UpdateDate' => date('Y-m-d H:i:s')
					);
					$updatetravelPlanAccom = $this->_crmcusttravelplanAccom->UpdateTravelPlanAccomData($updatetravelplan, $where);
				//end of update room index in accom table
		
					 $cancellationPolicyDecode=json_decode($cancellationPolicy,true);
					// print_r($cancellationPolicyDecode);
			  		 $valExistRT=$cancellationPolicyObj->ChkCancellationPolicyExist($travelPlanDetail[0]['hotelAccoSysId'],$roomindexID);
					  $chargeType=(isset($cancellationPolicyDecode[0]['ChargeType']) && !empty($cancellationPolicyDecode[0]['ChargeType']))?2:1;
					  $getCurrencyObj=new Travel_Model_TblCurrency();
					  $getCurrencyObj->strCurrencySymbol =@$cancellationPolicyDecode[0]['Currency']; 
					  $HelperCurrency = $getCurrencyObj->getCurrencyTypes();
					  $Charge=@$cancellationPolicyDecode[0]['Charge'];
					  $Fromdate=date('Y-m-d H:i:s',strtotime(@$cancellationPolicyDecode[0]['FromDate']));
					  $Todate=date('Y-m-d H:i:s',strtotime(@$cancellationPolicyDecode[0]['ToDate']));
					  //echo "<pre>";print_r($HelperCurrency);die;
					  $Currency=$HelperCurrency[0]['CurrencyType'];
					  $ItemSysId=0;
		            $j = $roomindexID - 1;
                if(count($valExistRT)==0){
                    if(!empty($cancellationPolicyDecode)){
						$arrayCancelPlo=array(
							'AccoSysid'=>$travelPlanDetail[0]['hotelAccoSysId'],
							'ItemSysId'=>$ItemSysId,
							'roomindex'=>$roomindexID,
							'RoomNumber'=>$selectArr['hotelRoomD']['GetHotelRoomResult']['HotelRoomsDetails'][$j]['RoomTypeCode'],
							'ChargeType'=>$chargeType,
							'Currency'=>$Currency,
							'Charge'=>$Charge,
							'Fromdate'=>$Fromdate,
							'Todate'=>$Todate,
							'createdOn'=>date('Y-m-d H:i:s'),
							'UpdatedOn'=>date('Y-m-d H:i:s'),
							'IsActive'=>'1',
							'IsMarkForDel'=>'0' 
							);
							//echo "";print_r($arrayCancelPlo);
						$cancellationPolicyObj->addRoomCancellationPolicy($arrayCancelPlo);
                    }
                }else{
                    if(!empty($cancellationPolicyDecode)){
							$arrayCancelPlo=array(
							'ItemSysId'=>$ItemSysId,
							'ChargeType'=>$chargeType,
							'RoomNumber'=>$selectArr['hotelRoomD']['GetHotelRoomResult']['HotelRoomsDetails'][$j]['RoomTypeCode'],
							'Currency'=>$Currency,
							'Charge'=>$Charge,
							'Fromdate'=>$Fromdate,
							'Todate'=>$Todate,
							'UpdatedOn'=>date('Y-m-d H:i:s')
							);
							$whereCn="AccoSysid='".$travelPlanDetail[0]['hotelAccoSysId']."' AND roomindex='".$roomindexID."'";
							$cancellationPolicyObj->UpdateRoomCancellationPolicy($arrayCancelPlo, $whereCn);
	                    }
                    } 
			$rommwisePrice=(trim($selectArr['hotelRoomD']['GetHotelRoomResult']['HotelRoomsDetails'][$j]['Price']['RoomPrice'], ".\r\n")/$noOfRooms);
            for ($i = 0; $i < $noOfRooms; $i++) {
                
                //if ($selectArr['hotelRoomD']['GetHotelRoomResult']['HotelRoomsDetails'][$j]['RoomIndex'] == $roomindexID) {
                    $rooms[] = array("RoomIndex" => trim($selectArr['hotelRoomD']['GetHotelRoomResult']['HotelRoomsDetails'][$j]['RoomIndex'], ".\r\n"),
                        "RoomTypeCode" => htmlspecialchars($selectArr['hotelRoomD']['GetHotelRoomResult']['HotelRoomsDetails'][$j]['RoomTypeCode']),
                        "RatePlanCode" => trim($selectArr['hotelRoomD']['GetHotelRoomResult']['HotelRoomsDetails'][$j]['RatePlanCode'], ".\r\n"),
                        "RoomTypeName" => trim($selectArr['hotelRoomD']['GetHotelRoomResult']['HotelRoomsDetails'][$j]['RoomTypeName'], ".\r\n"),
                        "BedTypeCode" => null,
                        "BedTypeDescription" => '',
                        "SmokingPreference" => "0",
                        "Supplements" => null,
                        'Price' => array("CurrencyCode" => "INR",
                            "RoomPrice" => (float) $rommwisePrice,
                            "Tax" => trim($selectArr['hotelRoomD']['GetHotelRoomResult']['HotelRoomsDetails'][$j]['Price']['Tax'], ".\r\n"),
                            "ExtraGuestCharge" => trim($selectArr['hotelRoomD']['GetHotelRoomResult']['HotelRoomsDetails'][$j]['Price']['ExtraGuestCharge'], ".\r\n"),
                            "ChildCharge" => trim($selectArr['hotelRoomD']['GetHotelRoomResult']['HotelRoomsDetails'][$j]['Price']['ChildCharge'], ".\r\n"),
                            "OtherCharges" => trim($selectArr['hotelRoomD']['GetHotelRoomResult']['HotelRoomsDetails'][$j]['Price']['OtherCharges'], ".\r\n"),
                            "Discount" => trim($selectArr['hotelRoomD']['GetHotelRoomResult']['HotelRoomsDetails'][$j]['Price']['Discount'], ".\r\n"),
                            "PublishedPrice" => (float) trim($selectArr['hotelRoomD']['GetHotelRoomResult']['HotelRoomsDetails'][$j]['Price']['PublishedPrice'], ".\r\n"),
                            "PublishedPriceRoundedOff" => (int) trim($selectArr['hotelRoomD']['GetHotelRoomResult']['HotelRoomsDetails'][$j]['Price']['PublishedPriceRoundedOff'], ".\r\n"),
                            "OfferedPrice" => (float) trim($selectArr['hotelRoomD']['GetHotelRoomResult']['HotelRoomsDetails'][$j]['Price']['OfferedPrice'], ".\r\n"),
                            "OfferedPriceRoundedOff" => (int) trim($selectArr['hotelRoomD']['GetHotelRoomResult']['HotelRoomsDetails'][$j]['Price']['OfferedPriceRoundedOff'], ".\r\n"),
                            "AgentCommission" => (float) trim($selectArr['hotelRoomD']['GetHotelRoomResult']['HotelRoomsDetails'][$j]['Price']['AgentCommission'], ".\r\n"),
                            "AgentMarkUp" => (float) trim($selectArr['hotelRoomD']['GetHotelRoomResult']['HotelRoomsDetails'][$j]['Price']['AgentMarkUp'], ".\r\n"),
                            "ServiceTax" => (float) trim($selectArr['hotelRoomD']['GetHotelRoomResult']['HotelRoomsDetails'][$j]['Price']['ServiceTax'], ".\r\n"),
                            "TDS" => (float) trim($selectArr['hotelRoomD']['GetHotelRoomResult']['HotelRoomsDetails'][$j]['Price']['TDS'], ".\r\n")
                        )
                    );
                //}
               // $j++;
            }
            $objGest = new Travel_Model_Tbltbbcuser();
           
            $datahRoom = array(
                "EndUserIp" => $_SERVER['REMOTE_ADDR'],
                "TokenId" => $tokenId,
                "TraceId" => trim($selectArr['hotelRoomD']['GetHotelRoomResult']['TraceId']),
                "ResultIndex" => $resultIndex,
                "HotelCode" => $selectArr['hotelInfo']['HotelInfoResult']['HotelDetails']['HotelCode'],
                "HotelName" => $selectArr['hotelInfo']['HotelInfoResult']['HotelDetails']['HotelName'],
                "GuestNationality" => 'IN',
                "NoOfRooms" => $noOfRooms,
                "ClientReferenceNo" => "0",
                "IsVoucherBooking" => "true",
                "HotelRoomsDetails" => $rooms
                
                
            );
			$blockRoom = new Zend_Session_Namespace('blockRoom');
            $blkRoom = $objApi->blockRoom($datahRoom);
			$blockRoom->blockRoom=$blkRoom;
            $intErrorCode = $blkRoom['BlockRoomResult']['Error']['ErrorCode'];
            $strErrorMessage = $blkRoom['BlockRoomResult']['Error']['ErrorMessage'];
            //echo "<pre>";print_r($datahRoom);print_r($blkRoom);
            if($intErrorCode == 0){
				//update in accom selected room table
					$HotelNorms=$blkRoom['BlockRoomResult']["HotelNorms"];
					if(isset($HotelNorms) && !empty($HotelNorms)){
						$getAccomRoomInfoObj=new Travel_Model_TblICAccomdationRoom();
						$AccomRoomInfoArrayUpdate = array(
							'HotelNorms'=>$HotelNorms,
							'UpdatedDate' => date('Y-m-d H:i:s'),
						);
						//echo "<pre>";print_r($AccomRoomInfoArrayUpdate);
						$where = "AccomSysId = " . $travelPlanDetail[0]['hotelAccoSysId']." AND RoomIndex=".$roomindexID." AND RoomNumber='".$selectArr['hotelRoomD']['GetHotelRoomResult']['HotelRoomsDetails'][$j]['RoomTypeCode']."'";
						$updateRoomInfo=$getAccomRoomInfoObj->updateAccomRoomInfo($AccomRoomInfoArrayUpdate,$where);
					}
				//end of update in accom selected room table

				$roomDetail->roomDetail['hotelRoomD']['GetHotelRoomResult']['HotelRoomsDetails']=$blkRoom['BlockRoomResult']['HotelRoomsDetails'];
				$roomDetail->roomDetail['hotelInfo']=$selectArr['hotelInfo'];
				$roomDetail->roomDetail['blkRoom']=$blkRoom;
                $response['ERROR']['CODE']      = $intErrorCode;
                $response['ERROR']['MESSAGE']   = $strErrorMessage;
                $response['HOTELINFO']['API_SOURCE_ID'] = 3;
                $sessionPreBookingHotelDetails = new Zend_Session_Namespace('sessionPreBookingHotelDetails');
                $sessionPreBookingHotelDetails->params =  $response;
                $msg = 'success';
                echo json_encode(array('status'=>'success'));
            }else{
                $response['ERROR']['CODE']      = $intErrorCode;
                $response['ERROR']['MESSAGE']   = $strErrorMessage;
                $response['HOTELINFO']['API_SOURCE_ID'] = 3;
                $sessionPreBookingHotelDetails = new Zend_Session_Namespace('sessionPreBookingHotelDetails');
                $sessionPreBookingHotelDetails->params =  $response;
                echo json_encode(array('status'=>'failed'));
            }
		} else {
			 echo json_encode(array('status'=>'failed'));
		}
		exit;
    }
	public function displaySelectedRoomAction(){
		$this->view->layout()->disableLayout();
			
		$selectedroomDetails = new Zend_Session_Namespace('selectedroom_hotelinfo');
		$roomDetail = new Zend_Session_Namespace('roomDetail');
		$hotelSearchSession = new Zend_Session_Namespace('hotelSearchSession');
		$tpid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('tpid')));
		$uid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('uid')));
		$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		
		//HOTELAPITYPE
		//echo "<pre>"; print_r($selectedroomDetails->selectedroom_hotelinfo);die;
		$planId=$tpid;
		if(isset($planId) && !empty($planId)){
			$travelPlanDetail=$this->_crmcusttravelplan->GetTravelPlanCustomerDetails($planId);
			if($travelPlanDetail[0]['StatusType']==17){
				$this->_redirect('/proposal/booking-confirmation/mid/'.base64_encode($mid).'/pid/'.base64_encode($tpid).'/uid/'.base64_encode($uid).'');
				exit;
			}
			$strdecode=$this->getDec($uid);
			$strdecode=explode(':',$strdecode);
			if( (@$strdecode[0] != intval($travelPlanDetail[0]['CustomerSysId'])) || (@$strdecode[2]!=intval($mid))){
				echo "Please try again";
				die;
			}
			$this->view->uid=$uid;
			$this->view->mid=$travelPlanDetail[0]['MasterTPSysId'];
			$this->view->tpid=$tpid;
		
			$travelPlanItenObj=new Travel_Model_CRM_CustomerTravelItenary();
			$travelPlanItenaryId=$travelPlanItenObj->GetItenaryId($planId);
			//$travelPlanAccomObj=new Travel_Model_TblCustomerTravelAccom();
			//$travelPlanAccomId=$travelPlanAccomObj->GetAccomId($travelPlanAccomObj[0]['TPIntSysId']);
			$this->view->travelPlanAccomId=$travelPlanItenaryId['TPIntSysId'];
			//echo "<pre>"; print_r($travelPlanDetail);
			$agencyStaffObj = new Travel_Model_TblAgencyStaff();
			$agentDetail=$agencyStaffObj->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
		$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
		$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1']);
		$crmcustomerObj = new Travel_Model_CRM_Customer();
		$getAgencyDetail=$crmcustomerObj->GetAgencyDetailById($AgencySysId);
		$guestDetails=$crmcustomerObj->GetCustomerWithDetails($travelPlanDetail[0]['CustomerSysId']);
		$hotelGuestDetails = new Zend_Session_Namespace('hotelGuestDetails');
		$hotelGuestDetails->hotelGuestDetails=$guestDetails;
		//echo "<pre>";print_r($guestDetails);die;
		//$guestDetails=$crmcustomerObj->GetCustomerWithDetails($travelPlanDetail[0]['CustomerSysId']);
		$agencyAddress='';	
		if(isset($getAgencyDetail['CountrySysId']) && !empty($getAgencyDetail['StateOrZoneSysId']) && !empty($getAgencyDetail['CitySysId'])){
			$agencyAddress=$crmcustomerObj->GetNameOfContStateCity($getAgencyDetail['CountrySysId'],$getAgencyDetail['StateOrZoneSysId'],$getAgencyDetail['CitySysId']);
		}
		$agencyState='';
		$agencyCountry='';
		if(isset($agencyAddress['StateName']) && !empty($agencyAddress['StateName'])){
			$agencyState=$agencyAddress['StateName']?" ,".$agencyAddress['StateName']:'';
		}
		if(isset($agencyAddress['countryName']) && !empty($agencyAddress['countryName'])){
			$agencyCountry=$agencyAddress['countryName']?"(".$agencyAddress['countryName'].")":'';
		}
		//customer detail
				$tpID=$planId;
				$CustomerSysId=$travelPlanDetail[0]['CustomerSysId'];
				if (isset($CustomerSysId) && !empty($CustomerSysId)) {
			        $this->_crmcustomerObj = new Travel_Model_CRM_Customer();
					//$getCustomerDetail = $this->_crmcustomerObj->GetCustomerById($CRMCustSysId);
					$getCustomerDetail = $travelPlanDetail;
					
					//echo "<pre>";print_r($getCustomerDetail);die;
				$objAgencyUser = new Travel_Model_CRM_AgencyUserInbox();
				$checkCustomerChatExist = $getCustomerDetail[0]['CustomerSysId'] > 0? $objAgencyUser->CheckCustomerMsgCount($getCustomerDetail[0]['CustomerSysId'],$tpID):array();
				$getCustomerDetail['userChatExist']=count($checkCustomerChatExist);
				}
		//end of customer detail

		//query for get customer chat history
			$chatSenderDetails=array();
			if($getCustomerDetail['userChatExist'] > 0){
					if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
						$getChatHistoryDetail = $objAgencyUser->GetCustChatHistDetWithLead($tpID,$getCustomerDetail[0]['CustomerSysId'],'DESC');
						$this->view->chatHistoryDetail=$getChatHistoryDetail;
						$chatSenderDetails['TPSysId']=$tpID;
						$chatSenderDetails['AgencySysId']=$travelPlanDetail[0]['AgencySysId'];
						$chatSenderDetails['CustomerSysId']=$getCustomerDetail[0]['CustomerSysId'];
						$chatSenderDetails['AgentSysId']=$travelPlanDetail[0]['AgentSysId'];
						//$chatSenderDetails['EmailId']=$getcustomerDetail[0]['EmailId'];
						$objAgencyStaff   =	new Travel_Model_TblAgencyStaff();
						$agentDetail=$objAgencyStaff->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
						$chatSenderDetails['EmailId']=$agentDetail['EmailId'];
						//print_r($agentDetail);
						
						
					}
			}
			//end of customer chat history


		$API_SOURCE_ID=$travelPlanDetail[0]['ICSourceSysId'];
		$roomjsonarray=json_decode($travelPlanDetail[0]['RoomMemInfoJson'],1);
				$adultPax =0;
				$childPax =0;
				if(!empty($roomjsonarray)){
					foreach($roomjsonarray as $res){
						$adultPax += $res['adult'];
						$childPax += $res['child']['childcount'];
					}
				}
		//echo "<pre>";print_r($roomjsonarray);die;
		if($API_SOURCE_ID == "3"){
							if(!empty($roomjsonarray)){
								$intRoomPrice = 0;
								$intTax = 0;
								//foreach ($arrHotelRoomsDetails as $roomsDetailsVal){
									$strCurrencyCode = 'INR';
									//$strCurrencyCode = $travelPlanDetail[0]['CurrencyCode'];
									$intRoomPrice = $travelPlanDetail[0]['NetCost'];
									$intTax += $travelPlanDetail[0]['XServiceTaxAmount'];
								//}
							}
							
							$this->view->intRoomPrice =  $intRoomPrice = round($intRoomPrice);
							$this->view->intTax =  $intTax = !empty($intTax)?round($intTax):0;
							//$this->view->intRoomCount =  $intRoomCount = count($roomjsonarray);
							$this->view->intRoomCount =  $intRoomCount = 1;
							$this->view->intNigthsCount =  $intNigthsCount = $travelPlanDetail[0]['hotelTotalNights'];
							$this->view->intTotalAmount =  $intTotalAmount = $intRoomPrice * $intRoomCount;

							$this->view->intAgentMarkUpAmount =  $intAgentMarkUpAmount = $travelPlanDetail[0]['hotelMarkUp'];//$markupAgency->markupAg;
							$this->view->intAgencyMarkUpAmount =  $intAgencyMarkUpAmount = $travelPlanDetail[0]['AgencyMarkUp'];//$markupAgency->markupAg;
							$this->view->intGTXMarkUpAmount =  $intGTXMarkUpAmount = $travelPlanDetail[0]['GTXMarkup'];//$markupAgency->markupAg;
							$this->view->intTotalGTXTaxAmount =  $intTotalGTXTaxAmount = $travelPlanDetail[0]['Taxes'];//gtx total tax included all markup taxes;
							//$this->view->intTotalAmountForApplicableNights =  $intTotalAmountForApplicableNights = $intTotalAmount * $intNigthsCount;
							$this->view->intTotalAmountForApplicableNights =  $intTotalAmountForApplicableNights = $intTotalAmount * 1;
							$this->view->intGrandPayableAmount =  $intGrandPayableAmount = $intTotalAmountForApplicableNights + $intTax + $intAgentMarkUpAmount + $intAgencyMarkUpAmount + $intGTXMarkUpAmount + $intTotalGTXTaxAmount;
							$markuparray['intAgentMarkUpAmount']=$intAgentMarkUpAmount;
							$markuparray['intAgencyMarkUpAmount']=$intAgencyMarkUpAmount;
							$markuparray['intGTXMarkUpAmount']=$intGTXMarkUpAmount;
							$markuparray['intTotalGTXTaxAmount']=$intTotalGTXTaxAmount;
							$markuparray['intTax']=$intTax;
							$serviceTaxhelper_GTX = Zend_Controller_Action_HelperBroker::getStaticHelper('Hotel')->getServiceTaxByAgencyId($intGTXMarkUpAmount,'H',$travelPlanDetail[0]['AgencySysId']);
							$serviceTaxhelper_AgentService = Zend_Controller_Action_HelperBroker::getStaticHelper('Hotel')->getServiceTaxByAgencyId($intAgentMarkUpAmount,'H',$travelPlanDetail[0]['AgencySysId']);
							$serviceTaxhelper_Agency = Zend_Controller_Action_HelperBroker::getStaticHelper('Hotel')->getServiceTaxByAgencyId($intAgencyMarkUpAmount,'H',$travelPlanDetail[0]['AgencySysId']);
							$markuparray['GTXServiceTaxAmount']=@$serviceTaxhelper_GTX['serviceTaxAmount'];
							$markuparray['AgentServiceTaxAmount']=@$serviceTaxhelper_AgentService['serviceTaxAmount'];
							$markuparray['AgentsCustomServiceTaxAmount']=@$serviceTaxhelper_Agency['serviceTaxAmount'];
							$markuparray['Pax']=$adultPax+$childPax;
							$markuparray['SupplierSourceStr']='API';
					}else if($API_SOURCE_ID == "4"){
						$sessionPreBookingHotelDetails = new Zend_Session_Namespace('sessionPreBookingHotelDetails');
						//echo "<pre>";print_r($sessionPreBookingHotelDetails->params);die;
							$NO_OF_ROOMS = count($roomjsonarray);
							$ARR_ROOMPRICE = $travelPlanDetail[0]['NetCost'];
			
							$NO_OF_CHILD = $childPax;
							$NO_OF_ADULTS = $adultPax;
								if(count($ARR_ROOMPRICE) > 0 && !empty($ARR_ROOMPRICE)){
									$intRoomPrice = 0;
									$intTax = 0;
									$intServiceFee = 0;
									//for ($i = 1; $i<=$NO_OF_ROOMS; $i++){
										$strCurrencyCode = 'INR';
										$intRoomPrice += $travelPlanDetail[0]['NetCost'];
										$intTax += $travelPlanDetail[0]['XServiceTaxAmount'];
										//$intServiceFee += $ARR_ROOMPRICE['SERVICE_FEE'];
									//}
								}
							
							$this->view->intRoomPrice =  $intRoomPrice = round($intRoomPrice);
							$this->view->intTax =  $intTax = !empty($intTax)?round($intTax):0;
							$this->view->intRoomCount =  $intRoomCount = 1;
							//$this->view->intRoomCount =  $intRoomCount = count($roomjsonarray);
							$this->view->intNigthsCount =  $intNigthsCount = $travelPlanDetail[0]['hotelTotalNights'];
							$this->view->intTotalAmount =  $intTotalAmount = $intRoomPrice * $intRoomCount;
							$this->view->intAgentMarkUpAmount =  $intAgentMarkUpAmount = $travelPlanDetail[0]['hotelMarkUp'];//$markupAgency->markupAg;
							$this->view->intAgencyMarkUpAmount =  $intAgencyMarkUpAmount = $travelPlanDetail[0]['AgencyMarkUp'];//$markupAgency->markupAg;
							$this->view->intGTXMarkUpAmount =  $intGTXMarkUpAmount = $travelPlanDetail[0]['GTXMarkup'];//$markupAgency->markupAg;
							$this->view->intTotalGTXTaxAmount =  $intTotalGTXTaxAmount = $travelPlanDetail[0]['Taxes'];//gtx total tax included all markup taxes;
							$this->view->intTotalAmountForApplicableNights =  $intTotalAmountForApplicableNights = $intTotalAmount * 1;
							//$this->view->intTotalAmountForApplicableNights =  $intTotalAmountForApplicableNights = $intTotalAmount * $intNigthsCount;
							$this->view->intGrandPayableAmount =  $intGrandPayableAmount = $intTotalAmountForApplicableNights + $intTax + $intAgentMarkUpAmount + $intAgencyMarkUpAmount + $intGTXMarkUpAmount + $intTotalGTXTaxAmount;
							$markuparray['intAgentMarkUpAmount']=$intAgentMarkUpAmount;
							$markuparray['intAgencyMarkUpAmount']=$intAgencyMarkUpAmount;
							$markuparray['intGTXMarkUpAmount']=$intGTXMarkUpAmount;
							$markuparray['intTotalGTXTaxAmount']=$intTotalGTXTaxAmount;
							$markuparray['intTax']=$intTax;
							$serviceTaxhelper_GTX = Zend_Controller_Action_HelperBroker::getStaticHelper('Hotel')->getServiceTaxByAgencyId($intGTXMarkUpAmount,'H',$travelPlanDetail[0]['AgencySysId']);
							$serviceTaxhelper_AgentService = Zend_Controller_Action_HelperBroker::getStaticHelper('Hotel')->getServiceTaxByAgencyId($intAgentMarkUpAmount,'H',$travelPlanDetail[0]['AgencySysId']);
							$serviceTaxhelper_Agency = Zend_Controller_Action_HelperBroker::getStaticHelper('Hotel')->getServiceTaxByAgencyId($intAgencyMarkUpAmount,'H',$travelPlanDetail[0]['AgencySysId']);
							$markuparray['GTXServiceTaxAmount']=isset($serviceTaxhelper_GTX['serviceTaxAmount'])?$serviceTaxhelper_GTX['serviceTaxAmount']:0;
							$markuparray['AgentServiceTaxAmount']=isset($serviceTaxhelper_AgentService['serviceTaxAmount'])?$serviceTaxhelper_AgentService['serviceTaxAmount']:0;
							$markuparray['AgentsCustomServiceTaxAmount']=isset($serviceTaxhelper_Agency['serviceTaxAmount'])?$serviceTaxhelper_Agency['serviceTaxAmount']:0;
							$markuparray['Pax']=$adultPax+$childPax;
							$markuparray['SupplierSourceStr']='API';
					}

			
		$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
		$this->view->getAgentDetail=$getAgentDetail;
		$this->view->agencyDetails=$getAgencyDetail;
		$this->view->hotelInfo=$roomDetail->roomDetail;
		$this->view->guestDetail=$guestDetails;
		$this->view->selectedroom_hotelinfo=$selectedroomDetails->selectedroom_hotelinfo;
		$this->view->getcustomerDetail = $getCustomerDetail;
		$this->view->chatSenderDetails = $chatSenderDetails;
		$this->view->markuparray=$markuparray;
		$this->view->travelPlanDetail=$travelPlanDetail;
		}
		$ARR_SALUTION=unserialize(ARR_SALUTION);
		$this->view->ARR_SALUTION=$ARR_SALUTION;
		$ARR_CUSTOMER_RELATION=unserialize(ARR_CUSTOMER_RELATION);
		$this->view->ARR_CUSTOMER_RELATION=$ARR_CUSTOMER_RELATION;
	}
    public function updatePublicPageCustomerAction() {
			$this->view->layout()->disableLayout();
			$this->_helper->viewRenderer->setNoRender(true);
			$customerId=$this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('cid')));	
			$AgencySysId=$this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('AgencySysId')));	
 			$data=$this->getRequest()->getParam('data');	
        if(isset($customerId) && !empty($customerId)) {
			parse_str($data,$res);
			$res=$this->_HtmlPurifier->filterArray($res);
			if(!empty($res) > 0){
				$fname = $res['firstName'];
				$lname = $res['lastName'];
				$customerEmail = $res['emailId'];
				$mobilenumber = $res['mobilNo'];
				$salution = $res['initial'];
				$checkboxVal=$res['update_customer'];
				$date = date('Y-m-d H:i:s');
				if($checkboxVal==1){
						if(isset($customerEmail) && !empty($customerEmail)){
						   $customerDetails = $this->_crmcustomerObj->ChkEmailWithResponse($customerEmail,$AgencySysId);
						}
						if(isset($mobilenumber) && !empty($mobilenumber)){
						   $customerDetails = $this->_crmcustomerObj->ChkMobileWithResponse($mobilenumber,$AgencySysId,'','');
						}
						if(!empty($customerDetails)){
						$where = "CustomerSysId = " . $customerId." AND AgencySysId = ".$AgencySysId;
						$agencyuserArray = array(
							'EmailId' => $customerEmail,
							'Title' => $salution,
							'Contacts' => $mobilenumber,
							'UserName' => $fname.''.$lname,
							'FirstName' => $fname,
							'LastName' => $lname,
							'UpdateDate' => $date
						);
						$this->_agencycustomerObj = new Travel_Model_CRM_AgencyCustomer();
						$agencyCustomerData = $this->_agencycustomerObj->UpdateAgencyCustomer($agencyuserArray,$where);
						echo json_encode(array('status'=>'success'));
					}
					exit;
				} else{
					echo json_encode(array('status'=>'failed'));
					exit;
				}
				echo json_encode(array('status'=>'success'));
				exit;
			} else {
				echo json_encode(array('status'=>'failed'));
				exit;
			}
		} else {
			echo json_encode(array('status'=>'failed'));
			exit;
		}
		exit;
    }
	public function bookingHotelReviewCustomerAction(){
		$this->view->layout()->disableLayout();
			
		$uid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('uid')));
		$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$tpid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('tpid')));
		$selectedroomDetails = new Zend_Session_Namespace('selectedroom_hotelinfo');
		$sessionPreBookingHotelDetails = new Zend_Session_Namespace('sessionPreBookingHotelDetails');
		$roomDetail = new Zend_Session_Namespace('roomDetail');
		$hotelSearchSession = new Zend_Session_Namespace('hotelSearchSession');
        $this->view->strPayWithWalletUrl = Catabatic_Helper::getSiteUrl()."payment/payment-options/customer-pay";
        $this->view->strRechargeNowUrl = Catabatic_Helper::getSiteUrl()."payment/payment-options";
        $this->view->strSearchPageUrl = "/buyhotel/search-results";
        $this->view->intPlanType = "2";
        $this->view->strTrxType = "H";
		//echo "<pre>"; print_r($hotelSearchSession->hotelSearchSession);die;
		$planId=$tpid;
		if(isset($planId) && !empty($planId)){
			$travelPlanItenObj=new Travel_Model_CRM_CustomerTravelItenary();
			$travelPlanItenaryId=$travelPlanItenObj->GetItenaryId($planId);
			$travelPlanAccomObj=new Travel_Model_CRM_CustomerTravelPlanAccom();
			$travelPlanAccomDetail=$travelPlanAccomObj->GetAccomDetailById($travelPlanItenaryId['TPIntSysId']);
			$this->view->travelPlanAccomDetail=$travelPlanAccomDetail['SpecialRequest'];
			//print_r($travelPlanAccomDetail);
			$travelplanObj = new Travel_Model_CRM_CustomerTravelPlan();
			//$travelPlanDetail=$travelplanObj->GetTravelPlanCustomerDetails($planId);
			$travelPlanDetail=$travelplanObj->GetTravelPlanCustomerDetailsPax($planId);
			//echo "<pre>"; print_r($travelPlanDetail);
			if(isset($travelPlanDetail[0]['StatusType']) && $travelPlanDetail[0]['StatusType']==17){
				$this->_redirect('/proposal/booking-confirmation/mid/'.base64_encode($mid).'/pid/'.base64_encode($tpid).'/uid/'.base64_encode($uid).'');
				exit;
			}

			$strdecode=$this->getDec($uid);
			$strdecode=explode(':',$strdecode);
			if( (@$strdecode[0] != intval(@$travelPlanDetail[0]['CustomerSysId'])) || (@$strdecode[2]!=intval($mid)) || (count($travelPlanDetail)==0)){
				echo "Please try again";
				die;
			}
			$this->view->uid=$uid;
			$this->view->tpid=$tpid;
			$this->view->mid=$travelPlanDetail[0]['MasterTPSysId'];


			$agencyStaffObj = new Travel_Model_TblAgencyStaff();
			$agentDetail=$agencyStaffObj->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
			$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
			$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1']);
			$crmcustomerObj = new Travel_Model_CRM_Customer();
			$getAgencyDetail=$crmcustomerObj->GetAgencyDetailById($AgencySysId);
			$guestDetails=$crmcustomerObj->GetCustomerWithDetails($travelPlanDetail[0]['CustomerSysId']);
		
		// for wallet use
        $this->view->strReturnURL = "http://".$_SERVER['SERVER_NAME']."/proposal/make-public-page-payment/cid/".base64_encode($travelPlanDetail[0]['CustomerSysId'])."/tid/".base64_encode($travelPlanItenaryId['TPIntSysId']);
        $this->view->strErrorURL = "http://".$_SERVER['HTTP_HOST']."/proposal/make-public-page-payment/cid/".base64_encode($travelPlanDetail[0]['CustomerSysId'])."/tid/".base64_encode($travelPlanItenaryId['TPIntSysId']);
		$this->view->intLoggedinAgencySysId = $AgencySysId;
		$this->view->IsCardChrgToCustomer = $travelPlanDetail[0]['IsCardChrgToCustomer'];
		$this->view->intLoggedinUserAgencySysId = $AgencyUserSysId=$travelPlanDetail[0]['AgentSysId'];
		$API_SOURCE_ID=$travelPlanDetail[0]['ICSourceSysId'];
		$roomjsonarray=json_decode($travelPlanDetail[0]['RoomMemInfoJson'],1);
				$adultPax =0;
				$childPax =0;
				if(!empty($roomjsonarray)){
					foreach($roomjsonarray as $res){
						$adultPax += $res['adult'];
						$childPax += $res['child']['childcount'];
					}
				}

			if($API_SOURCE_ID == "3"){
								$arrHotelRoomsDetails = $selectedroomDetails->selectedroom_hotelinfo;
								if(!empty($roomjsonarray)){
									$intRoomPrice = 0;
									$intTax = 0;
									//foreach ($arrHotelRoomsDetails as $roomsDetailsVal){
										$strCurrencyCode = 'INR';
										$intRoomPrice += $travelPlanDetail[0]['NetCost'];
										$intTax += $travelPlanDetail[0]['XServiceTaxAmount'];
									//}
								}
								
								$this->view->intRoomPrice =  $intRoomPrice = $intRoomPrice;
								//$this->view->intTax =  $intTax = !empty($intTax)?round($intTax):0;
								$this->view->intTax =  $intTax = !empty($intTax)?($intTax):0;
								$this->view->intRoomCount =  $intRoomCount = 1;
								//$this->view->intRoomCount =  $intRoomCount = count($roomjsonarray);
								$this->view->intNigthsCount =  $intNigthsCount = $travelPlanDetail[0]['hotelTotalNights'];
								$this->view->intTotalAmount =  $intTotalAmount = $intRoomPrice * $intRoomCount;
								$this->view->intAgentMarkUpAmount =  $intAgentMarkUpAmount = $travelPlanDetail[0]['hotelMarkUp'];//$markupAgency->markupAg;
								$this->view->intAgencyMarkUpAmount =  $intAgencyMarkUpAmount = $travelPlanDetail[0]['AgencyMarkUp'];//$markupAgency->markupAg;
								$this->view->intGTXMarkUpAmount =  $intGTXMarkUpAmount = $travelPlanDetail[0]['GTXMarkup'];//$markupAgency->markupAg;
								$this->view->intTotalAmountForApplicableNights =  $intTotalAmountForApplicableNights = $intTotalAmount * 1;
								//$this->view->intTotalAmountForApplicableNights =  $intTotalAmountForApplicableNights = $intTotalAmount * $intNigthsCount;
								$XServiceTaxAmount = $travelPlanDetail[0]['XServiceTaxAmount'];
								$GTXServiceTaxAmount = $travelPlanDetail[0]['GTXServiceTaxAmount'];
								$AgentServiceTaxAmount = $travelPlanDetail[0]['AgentServiceTaxAmount'];
								$AgentsCustomServiceTaxAmount = $travelPlanDetail[0]['AgentsCustomServiceTaxAmount'];
								//$this->view->intTotalAmountForApplicableNights =  $intTotalAmountForApplicableNights = $intTotalAmount * $intNigthsCount;
								$this->view->intGrandPayableAmount =  $intGrandPayableAmount = round($intTotalAmountForApplicableNights + $intAgentMarkUpAmount + $intAgencyMarkUpAmount + $intGTXMarkUpAmount + $XServiceTaxAmount + $GTXServiceTaxAmount + $AgentServiceTaxAmount + $AgentsCustomServiceTaxAmount);
								$markuparray['intAgentMarkUpAmount']=$intAgentMarkUpAmount;
								$markuparray['intAgencyMarkUpAmount']=$intAgencyMarkUpAmount;
								$markuparray['intGTXMarkUpAmount']=$intGTXMarkUpAmount;
								$markuparray['intTotalAmount']=$intTotalAmount;
								$markuparray['intTax']=$XServiceTaxAmount;
								$markuparray['GTXServiceTaxAmount']=$GTXServiceTaxAmount;
								$markuparray['AgentServiceTaxAmount']=$AgentServiceTaxAmount;
								$markuparray['AgentsCustomServiceTaxAmount']=$AgentsCustomServiceTaxAmount;
								$markuparray['Pax']=$adultPax+$childPax;
								$markuparray['SupplierSourceStr']='API';
								$markuparray['MarketPlaceId']=1; //b2b or b2c
								$markuparray['TotalDiscount']=$travelPlanDetail[0]['Discounts'];; //0
								$markuparray['CurrencyType']=$travelPlanDetail[0]['CurrencyType'];
						}else if($API_SOURCE_ID == "4"){
							$sessionPreBookingHotelDetails = new Zend_Session_Namespace('sessionPreBookingHotelDetails');
							$NO_OF_ROOMS = count($roomjsonarray);
							$ARR_ROOMPRICE = $travelPlanDetail[0]['NetPrice'];
			
							$NO_OF_CHILD = $childPax;
							$NO_OF_ADULTS = $adultPax;
			
								if(count($ARR_ROOMPRICE) > 0 && !empty($ARR_ROOMPRICE)){
									$intRoomPrice = 0;
									$intTax = 0;
									$intServiceFee = 0;
									//for ($i = 1; $i<=$NO_OF_ROOMS; $i++){
										$strCurrencyCode = 'INR';
										$intRoomPrice += $travelPlanDetail[0]['NetCost'];
										$intTax += $travelPlanDetail[0]['XServiceTaxAmount'];
										//$intServiceFee += $ARR_ROOMPRICE['SERVICE_FEE'];
									//}
								}
								
								$this->view->intRoomPrice =  $intRoomPrice = ($intRoomPrice);
								$this->view->intTax =  $intTax = !empty($intTax)?($intTax):0;
								$this->view->intRoomCount =  $intRoomCount = 1;
								//$this->view->intRoomCount =  $intRoomCount = count($roomjsonarray);
								$this->view->intNigthsCount =  $intNigthsCount = $travelPlanDetail[0]['hotelTotalNights'];
								$this->view->intTotalAmount =  $intTotalAmount = $intRoomPrice * $intRoomCount;
								$this->view->intAgentMarkUpAmount =  $intAgentMarkUpAmount = $travelPlanDetail[0]['hotelMarkUp'];//$markupAgency->markupAg;
								$this->view->intAgencyMarkUpAmount =  $intAgencyMarkUpAmount = $travelPlanDetail[0]['AgencyMarkUp'];//$markupAgency->markupAg;
								$this->view->intGTXMarkUpAmount =  $intGTXMarkUpAmount = $travelPlanDetail[0]['GTXMarkup'];//$markupAgency->markupAg;
								$this->view->intTotalAmountForApplicableNights =  $intTotalAmountForApplicableNights = $intTotalAmount * 1;
								
								$XServiceTaxAmount = $travelPlanDetail[0]['XServiceTaxAmount'];
								$GTXServiceTaxAmount = $travelPlanDetail[0]['GTXServiceTaxAmount'];
								$AgentServiceTaxAmount = $travelPlanDetail[0]['AgentServiceTaxAmount'];
								$AgentsCustomServiceTaxAmount = $travelPlanDetail[0]['AgentsCustomServiceTaxAmount'];
								//$this->view->intTotalAmountForApplicableNights =  $intTotalAmountForApplicableNights = $intTotalAmount * $intNigthsCount;
								$this->view->intGrandPayableAmount =  $intGrandPayableAmount = $intTotalAmountForApplicableNights + $intAgentMarkUpAmount + $intAgencyMarkUpAmount + $intGTXMarkUpAmount + $XServiceTaxAmount + $GTXServiceTaxAmount + $AgentServiceTaxAmount + $AgentsCustomServiceTaxAmount;
								//echo $intGrandPayableAmount;die;
								$markuparray['intAgentMarkUpAmount']=$intAgentMarkUpAmount;
								$markuparray['intAgencyMarkUpAmount']=$intAgencyMarkUpAmount;
								$markuparray['intGTXMarkUpAmount']=$intGTXMarkUpAmount;
								$markuparray['intTotalAmount']=$intTotalAmount;
								$markuparray['intTax']=$XServiceTaxAmount;
								$markuparray['GTXServiceTaxAmount']=$GTXServiceTaxAmount;
								$markuparray['AgentServiceTaxAmount']=$AgentServiceTaxAmount;
								$markuparray['AgentsCustomServiceTaxAmount']=$AgentsCustomServiceTaxAmount;
								$markuparray['Pax']=$adultPax+$childPax;
								$markuparray['SupplierSourceStr']='API';
								$markuparray['MarketPlaceId']=1; //b2b or b2c
								$markuparray['TotalDiscount']=$travelPlanDetail[0]['Discounts'];; //0
								$markuparray['CurrencyType']=$travelPlanDetail[0]['CurrencyType'];
						}
		$encryptMarkUpData=$this->getEnc(json_encode($markuparray));
        $this->view->guid = $this->GUID();    
		//echo "<pre>";print_r($markuparray);
		//echo $travelPlanDetail[0]['AgentSysId'].','. $this->view->guid.','. $intGrandPayableAmount.','. $AgencySysId.','. $travelPlanDetail[0]['TPSysId'].','.$travelPlanDetail[0]['CRMCustSysId'].','.$encryptMarkUpData;
        $this->view->walletCode = $this->walletCode($travelPlanDetail[0]['AgentSysId'], $this->view->guid, round($intGrandPayableAmount), $AgencySysId, $travelPlanDetail[0]['TPSysId'],$travelPlanDetail[0]['CustomerSysId'],$encryptMarkUpData);
        $this->view->securecode = $this->secureCode($this->intLoggedinUserAgencySysId, $this->view->guid);
		
		//end of wallet use
		//echo "<pre>";print_r($guestDetails);die;
		$agencyAddress='';	
		if(isset($getAgencyDetail['CountrySysId']) && !empty($getAgencyDetail['StateOrZoneSysId']) && !empty($getAgencyDetail['CitySysId'])){
			$agencyAddress=$crmcustomerObj->GetNameOfContStateCity($getAgencyDetail['CountrySysId'],$getAgencyDetail['StateOrZoneSysId'],$getAgencyDetail['CitySysId']);
		}
		$agencyState='';
		$agencyCountry='';
		if(isset($agencyAddress['StateName']) && !empty($agencyAddress['StateName'])){
			$agencyState=$agencyAddress['StateName']?" ,".$agencyAddress['StateName']:'';
		}
		if(isset($agencyAddress['countryName']) && !empty($agencyAddress['countryName'])){
			$agencyCountry=$agencyAddress['countryName']?"(".$agencyAddress['countryName'].")":'';
		}
		//customer detail
				$tpID=$planId;
				$CRMCustSysId=$travelPlanDetail[0]['CustomerSysId'];
				if (isset($CRMCustSysId) && !empty($CRMCustSysId)) {
			        $this->_crmcustomerObj = new Travel_Model_CRM_Customer();
					//$getCustomerDetail = $this->_crmcustomerObj->GetCustomerById($CRMCustSysId);
					$getCustomerDetail = $travelPlanDetail;
					
					//echo "<pre>";print_r($getCustomerDetail);die;
				$objAgencyUser = new Travel_Model_CRM_AgencyUserInbox();
				$checkCustomerChatExist = $getCustomerDetail[0]['CustomerSysId'] > 0? $objAgencyUser->CheckCustomerMsgCount($getCustomerDetail[0]['CustomerSysId'],$tpID):array();
				$getCustomerDetail['userChatExist']=count($checkCustomerChatExist);
				}
		//end of customer detail

		//query for get customer chat history
			$chatSenderDetails=array();
			if($getCustomerDetail['userChatExist'] > 0){
					if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
						$getChatHistoryDetail = $objAgencyUser->GetCustChatHistDetWithLead($tpID,$getCustomerDetail[0]['CustomerSysId'],'DESC');
						$this->view->chatHistoryDetail=$getChatHistoryDetail;
						$chatSenderDetails['TPSysId']=$tpID;
						$chatSenderDetails['AgencySysId']=$travelPlanDetail[0]['AgencySysId'];
						$chatSenderDetails['CRMCustSysId']=$getCustomerDetail[0]['CustomerSysId'];
						$chatSenderDetails['AgentSysId']=$travelPlanDetail[0]['AgentSysId'];
						//$chatSenderDetails['EmailId']=$getcustomerDetail[0]['EmailId'];
						$objAgencyStaff   =	new Travel_Model_TblAgencyStaff();
						$agentDetail=$objAgencyStaff->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
						$chatSenderDetails['EmailId']=$agentDetail['EmailId'];
						//print_r($agentDetail);
						
						
					}
			}
			//end of customer chat history
		$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
		$this->view->getAgentDetail=$getAgentDetail;
		$this->view->agencyDetails=$getAgencyDetail;
		$this->view->hotelInfo=$roomDetail->roomDetail;
		$this->view->hotelSearchInfo=$hotelSearchSession->hotelSearchSession;
		$this->view->guestDetail=$guestDetails;
		$this->view->selectedroom_hotelinfo=$selectedroomDetails->selectedroom_hotelinfo;
		$this->view->getcustomerDetail = $getCustomerDetail;
		$this->view->chatSenderDetails = $chatSenderDetails;
		$this->view->encryptMarkUpData=$encryptMarkUpData;
		$this->view->travelPlanDetail=$travelPlanDetail;
		$ARR_SALUTION=unserialize(ARR_SALUTION);
		$ARR_CUSTOMER_RELATION=unserialize(ARR_CUSTOMER_RELATION);
		$this->view->ARR_CUSTOMER_RELATION 	= $ARR_CUSTOMER_RELATION;
		$this->view->ARR_SALUTION 	= $ARR_SALUTION;
		} else {
			echo "Please try again";
			die;
		}
	}

	public function updateCustomerSpecialRequestAction() {
			$this->view->layout()->disableLayout();
			$this->_helper->viewRenderer->setNoRender(true);
			$leadId=$this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('leadId')));	
			$TPIntSysId=$this->_HtmlPurifier->filter($this->getRequest()->getParam('TPIntSysId'));	
 			$specialRequest=$this->_HtmlPurifier->filter($this->getRequest()->getParam('specialRequest'));	
 			$mobilNo=$this->_HtmlPurifier->filter($this->getRequest()->getParam('mobilNo'));	
 			$emailId=$this->_HtmlPurifier->filter($this->getRequest()->getParam('emailId'));	
 			$salutation=$this->_HtmlPurifier->filter($this->getRequest()->getParam('salutation'));	
			$custrelation=$this->_HtmlPurifier->filter($this->getRequest()->getParam('custrelation'));
			$isUpdateCustomer=$this->_HtmlPurifier->filter($this->getRequest()->getParam('isUpdateCustomer'));
 			$firstName=$this->_HtmlPurifier->filter($this->getRequest()->getParam('firstName'));	
 			$lastName=$this->_HtmlPurifier->filter($this->getRequest()->getParam('lastName'));	
 			$customerid=$this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('cid')));	
 			$AgencySysId=$this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('aid')));	
 			$CRMCustSysId=$this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('CRid')));	
	        if(isset($leadId) && !empty($leadId)) {
				$date = date('Y-m-d H:i:s');
				$accomArray = array(
							'SpecialRequest' => addslashes($specialRequest),
							'UpdateDate' => $date
						);
				$where = "TPIntSysId = " . $TPIntSysId;
				$accomObj=new Travel_Model_CRM_CustomerTravelPlanAccom();
				$customerRcord = $accomObj->UpdateTravelPlanAccom($accomArray, $where);
				
				if(isset($isUpdateCustomer) && $isUpdateCustomer==1){
					$agencyCustomerArray = array(
								'FirstName' => addslashes(trim($firstName)),
								'LastName' => addslashes(trim($lastName)),
								'Title' => trim($salutation),
								//'Relation'=>trim($custrelation),
								'UpdateDate' => $date
							);
					$whereAgencyCus = "CustomerSysId = " . $customerid;
					$agencyCustomeObj=new Travel_Model_CRM_AgencyCustomer();
					$customerRcordUpdate = $agencyCustomeObj->UpdateAgencyCustomer($agencyCustomerArray, $whereAgencyCus);
				}
				//add agency members for trvel plan
						
						$this->_travelPaxObj = new Travel_Model_CRM_CustomerTravelPlanPax();
						$paxMembers=$this->_travelPaxObj->GetTravelPlanRoomPaxInfo($leadId,$customerid);
						$objGest = new Travel_Model_Tbltbbcuser();
						
						$chkcustomerMember=$objGest->getCustomerAndMembersDetailsAll(trim($mobilNo),trim($emailId),trim($salutation),trim($custrelation),trim($firstName),trim($lastName),$AgencySysId);
						//echo "<pre>";print_r($chkcustomerMember);die;
						$this->_agencycustomermemberObj = new Travel_Model_CRM_CustomerMember();
						if(count($chkcustomerMember)==0){
							
							//$chkcustomerMemberSelf=$objGest->getMembersSelfDetails(0,trim($customerid),$AgencySysId);
							//print_r($chkcustomerMemberSelf);die;
							
										$arrCustMem = array(
											'AgencySysId' => $AgencySysId,
											'CustomerSysId' => $customerid,
											'EmailId' => trim($emailId),
											'Title' => trim($salutation), 
											'Relation'=>trim($custrelation),
											'Logo' => ' ','IsfromSM' => '0', 'SMTypeId' => '0', 'SMId' => '0','UserId' => '0', 'IsEmployee' => '0',
											'Contacts' => trim($mobilNo), 
											'JoinDate' =>trim($date), 'ExitDate' => EMPTY_DATE, 
											'UserName' => ' ','FirstName' =>trim($firstName),
											'LastName' =>trim($lastName), 
											'Designation' => ' ','Password' => ' ', 'RandStr' => ' ',
											'PasswordExpiryDate' => EMPTY_DATE, 
											'IsPswExpire' => '0','OtherEmail' => ' ','SecondaryEmail' => ' ', 
											'LastLoginTime' => EMPTY_DATE, 
											'IsLogInNow' => '0', 
											'CreatedByUserSysId' => $customerid,
											'RandomCode' => ' ', 
											'Gender' => '0',
											'UserNickName' => ' ', 
											'UserPicPath' => '', 
											'ContactNo1' => '0', 
											'ContactNo2' => '0', 
											'HomePhone' => '0',
											'SecondaryPhone' => '0', 
											'UserDetails' => ' ', 
											'Address' => ' ', 
											'CitySysId' => '0',
											'StateOrZoneSysId' => '0',
											'CountrySysId' => '0',
											'PinCode' => '0', 
											'SecondaryAddress' => ' ',
											'Fax' => '0', 
											'MacIp' => '0', 
											'SpeakingLangSysId' => '0',
											'Signature' => ' ', 
											'UpdateDate' => $date, 
											'RegisterDate' => $date,
											'IsApproved' => '1',
											'IsActive' => '1', 
											'IsMarkForDelete' => '0'
											);
				
										$MemberSysId=$this->_agencycustomermemberObj->addCustomerMember($arrCustMem);
								
								/*if(count($chkcustomerMemberSelf)==0){
								}else{
									$arrCustMemUpdate = array(
											'EmailId' => trim($emailId),
											'Title' => trim($salutation), 
											'Contacts' => trim($mobilNo), 
											'FirstName' =>trim($firstName),
											'LastName' =>trim($lastName), 
											'UpdateDate' => $date, 
										);
										$whereMember = "CustomerSysId = " . $customerid." AND Relation=".$custrelation;
										$MemberSysId=$this->_agencycustomermemberObj->updateCustomerMember($arrCustMemUpdate,$whereMember);
								}*/
							//echo "<pre>";print_r($memberRecod)."/".print_r($paxMembers);
							}else{
								$MemberSysId=$chkcustomerMember[0]['MemberSysId'];	
								$arrCustMemUpdate = array(
									'Relation'=>trim($custrelation),
									'UpdateDate' => $date, 
									);
									$whereMember = "MemberSysId = " . $MemberSysId;
								//echo "<pre>";print_r($arrCustMemUpdate);die;
								$MemberSysId=$this->_agencycustomermemberObj->updateCustomerMember($arrCustMemUpdate,$whereMember);
							}
							$MemberSysId=isset($MemberSysId)?$MemberSysId:$paxMembers['MemberSysId'];	
								$arrCustMemPax = array(
									'TPSysId' => $leadId,
									'CustomerSysId' => $customerid,
									'MemberSysId' => ($MemberSysId)?$MemberSysId:0,
									'UpdateDate' => $date, 
									'IsApproved' => '1',
									'IsActive' => '1', 
									'IsMarkForDelete' => '0'
									);
									//print_r($arrCustMemPax);die;
								$paxRecod=$this->_travelPaxObj->addCustomerTravelPlanPax($arrCustMemPax);
							/*if(count($paxMembers)==0){
								$MemberSysId=$chkcustomerMember[0]['MemberSysId'];	
								$arrCustMemPax = array(
									'TPSysId' => $leadId,
									'CustomerSysId' => $customerid,
									'MemberSysId' => $MemberSysId,
									'UpdateDate' => $date, 
									'IsApproved' => '1',
									'IsActive' => '1', 
									'IsMarkForDelete' => '0'
									);
								$paxRecod=$this->_travelPaxObj->addCustomerTravelPlanPax($arrCustMemPax);
							}else{
								$MemberSysId=$paxMembers['MemberSysId'];
								$arrCustMem = array(
									'MemberSysId' => $MemberSysId, 
									'UpdateDate' => $date, 
								);
								$whereMem = "TPSysId = " . $leadId;
								$paxRecod=$this->_travelPaxObj->UpdateCustomerTravelPlanPax($arrCustMem,$whereMem);
							}*/
				echo json_encode(array('status'=>'success'));
				exit;
		} else {
			echo json_encode(array('status'=>'failed'));
			exit;
		}
		exit;
    }
	public function updateHotelExpiredSessionApiAction(){
         $this->view->layout()->disableLayout();
		 $hotelCode = $this->getRequest()->getParam('hotelCode') ? $this->_HtmlPurifier->filter($this->getRequest()->getParam('hotelCode')) : '';
		 $traceid = $this->getRequest()->getParam('traceid') ? $this->_HtmlPurifier->filter($this->getRequest()->getParam('traceid')) : '';
		 $planId=$this->getRequest()->getParam('tpid') ? $this->_HtmlPurifier->filter($this->getRequest()->getParam('tpid')) : '';
		 $travelPlanDetail=$this->_crmcusttravelplan->GetTravelPlanCustomerDetails($planId);
		// echo "<pre>";print_r($travelPlanDetail);
		 $hotelSearchSession = new Zend_Session_Namespace('hotelSearchSession');
		// echo "<pre>";print_r($hotelSearchSession->hotelSearchSession);die;
		 $tokenId = Zend_Controller_Action_HelperBroker::getStaticHelper('Flight')->authenticateAPI();
		 $memberDetails=$hotelSearchSession->hotelSearchSession[0]['memberDetails'];
		 $RoomMemInfoJson=json_decode($travelPlanDetail[0]['RoomMemInfoJson'],true);
		$adultPax =0;
		$childPax =0;

		$arrMemberDetails = array();
		$i=0;
		if(!empty($RoomMemInfoJson)){
			foreach($RoomMemInfoJson as $res){
				$adultPax += $res['adult'];
				$childPax += $res['child']['childcount'];
				 $arrMemberDetails[$i]['NoOfAdults']=$res['adult'];
				 $arrMemberDetails[$i]['NoOfChild']=$res['child']['childcount'];
				if($res['child']['childcount'] > 0){
					$arrChildAge = explode(",",$res['child']['childage']);
					$arrMemberDetails[$i]['ChildAge'] = $arrChildAge;
				}else{
					$arrMemberDetails[$i]['ChildAge'] = NULL;
				}
			$i++;
			}
		}
                
                $customhelper = Zend_Controller_Action_HelperBroker::getStaticHelper('Custom');
                $currencySymbol=$customhelper->GetCurrencyByCurrencyType($travelPlanDetail[0]['CurrencyType']);
                
		 $datah = array(
                    "CheckInDate" => $travelPlanDetail[0]['StartDate']->format('d-M-y'),
                    "NoOfNights" => $travelPlanDetail[0]['hotelTotalNights'],
                    "CountryCode" => "IN",
                    "CityId" => $travelPlanDetail[0]['hotelXrefCityId'],
                    "ResultCount" => null,
                    "PreferredCurrency" => trim($currencySymbol['Symbol']),
                    "GuestNationality" => "IN",
                    "NoOfRooms" => count($RoomMemInfoJson),
                    "RoomGuests" => $arrMemberDetails,
                    'PreferredHotel' => $travelPlanDetail[0]['hotelName'],
                    'MaxRating' => $travelPlanDetail[0]['Stars'],
                    'MinRating' => $travelPlanDetail[0]['Stars'],
                    'ReviewScore' => null,
                    'IsNearBySearchAllowed' => 'false',
                    'EndUserIp' => $_SERVER['REMOTE_ADDR'],
                    'TokenId' => $tokenId
                );
				
			//echo "<pre>";print_r($datah);exit;	
                $apiRes1 = array();
                $urlHotel=TBO_HOTEL_API_SEARCH_URL;

                $data_stringh = json_encode($datah);
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $urlHotel);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $data_stringh);
                curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                    'Content-Type: application/json',
                    'Content-Length: ' . strlen($data_stringh)
                ));
                $outputH = curl_exec($ch);
                $response = json_decode($outputH, true);
                $intResponseStatus = $response['HotelSearchResult']['ResponseStatus'];
                $intErrorCode = $response['HotelSearchResult']['Error']['ErrorCode'];


			if ($intResponseStatus == 1 && $intErrorCode == 0) {
					$objHotel = new Travel_Model_TblBuyHotel();  
                    $strTraceId = $response['HotelSearchResult']['TraceId'];
                    $intAPICityId = $response['HotelSearchResult']['CityId'];
                    $arrHotelResultsAll = $response['HotelSearchResult']['HotelResults'];
					//echo "<pre>";	print_r($arrHotelResultsAll);
					$matchKey = array_search($hotelCode, array_column($arrHotelResultsAll, 'HotelCode'));
					$arrHotelResults=$arrHotelResultsAll[$matchKey];
					$selectedHotelResults = new Zend_Session_Namespace('selectedHotelResults');
					$selectedHotelResults->selectedHotelResults=$arrHotelResults;
					
					//echo "<pre>";print_r($arrHotelResults);die;
					//echo "<pre>";print_r($arrHotelResults);die;
                    $CreateDate = Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss');
					$intHotelCityId=$travelPlanDetail[0]['hotelXrefCityId'];
					if(trim($arrHotelResults["HotelCode"])==$hotelCode){
						$res=array('status'=>'success','resultIndex'=>trim($arrHotelResults['ResultIndex']),'hotelCode'=>trim($arrHotelResults["HotelCode"]),'tokenid'=>trim($tokenId),'traceid'=>trim($strTraceId));
					} else{
						$res=array('status'=>'failed','ErrorCode'=>@$ErrorCode,'ErrorMessage'=>'Hotel not found or already booked','strTraceId'=>$strTraceId,'noOfRooms'=>count($RoomMemInfoJson));
					}
					echo json_encode($res);
                exit;
                } else { 
                    $status = $response['HotelSearchResult']['ResponseStatus'];
                    $ErrorCode = $response['HotelSearchResult']['Error']['ErrorCode'];
                    $ErrorMessage = $response['HotelSearchResult']['Error']['ErrorMessage'];
                    $strTraceId = $response['HotelSearchResult']['TraceId'];
					$res=array('status'=>$status,'ErrorCode'=>@$ErrorCode,'ErrorMessage'=>$ErrorMessage,'strTraceId'=>$strTraceId,'noOfRooms'=>count($RoomMemInfoJson));
					echo json_encode($res);
                    exit;
                }
		
		
	}
    public function makePublicPagePaymentAction() {
       
	   //echo "<pre>";print_r($_REQUEST);die;
        $objTrx = new Travel_Model_TblAgencyCustomerTrx();
        $intXRefTrxNo = $this->getRequest()->getParam('txnid');
        $strTrxStatus = $this->getRequest()->getParam('status');
        $planId=$this->getRequest()->getParam('TpSysId');
		$hotelSearchSession = new Zend_Session_Namespace('hotelSearchSession');
		$hotelGuestDetails = new Zend_Session_Namespace('hotelGuestDetails');
		$selectedHotelResults = new Zend_Session_Namespace('selectedHotelResults');
		$sessionPreBookingHotelDetails = new Zend_Session_Namespace('sessionPreBookingHotelDetails');
		$roomDetail=new Zend_Session_Namespace('roomDetail');
		$blockRoom = new Zend_Session_Namespace('blockRoom');
		$travelplanObj = new Travel_Model_CRM_CustomerTravelPlan();
		$travelPlanDetail=$travelplanObj->GetTravelPlanCustomerDetailsPax($planId);
		$API_SOURCE_ID=$travelPlanDetail[0]['ICSourceSysId'];
		$MasterTPSysId=$travelPlanDetail[0]['MasterTPSysId'];
		$uid=$travelPlanDetail[0]['CustomerSysId'].':'.$planId.':'.$MasterTPSysId;
		$uid=base64_encode($this->getEnc($uid));
		$customHelper = Zend_Controller_Action_HelperBroker::getStaticHelper("Custom");
		//echo "<pre>"; print_r($blockRoom->blockRoom);
		/*echo "<pre>";
		print_r($hotelSearchSession->hotelSearchSession);
		print_r($hotelGuestDetails->hotelGuestDetails);
		print_r($selectedHotelResults->selectedHotelResults);
		print_r($roomDetail->roomDetail);
		die;*/
		$RoomMemInfoJson=json_decode($travelPlanDetail[0]['RoomMemInfoJson'],1);
		//print_r($RoomMemInfoJson);
		$adultPax =0;
		$childPax =0;
		if(!empty($RoomMemInfoJson)){
			for($g=1;$g<=count($RoomMemInfoJson);$g++){
				$adultPax += $RoomMemInfoJson[$g]['adult'];
				$childPax += $RoomMemInfoJson[$g]['child']['childcount'];
			}
		}
		$totalPax=$adultPax+$childPax;
		$ARR_SALUTION = unserialize(ARR_SALUTION);
		 $createDate = date('Y-m-d H:i:s');
		//print_r($ARR_SALUTION);
		if($travelPlanDetail[0]['Salutation'] > 0){
			$strTitle=$ARR_SALUTION[trim($travelPlanDetail[0]['MEMBERTitle'])];
		}else{
			$strTitle='Mr.';
		}
       // if ($strTrxStatus == "success" && !empty($intXRefTrxNo)) {
		   if($API_SOURCE_ID == "4"){ //echo "HI"; exit;
           
            if ($strTrxStatus == "success" ) {
				
                $sessionPreBookingHotelDetails->params['GRN_PRE_BOOKING_DATA']['PAXES']['DETAILS']['TITLE'] = $strTitle;
                $sessionPreBookingHotelDetails->params['GRN_PRE_BOOKING_DATA']['PAXES']['DETAILS']['NAME'] = $travelPlanDetail[0]['MEMBERFirstName'];
                $sessionPreBookingHotelDetails->params['GRN_PRE_BOOKING_DATA']['PAXES']['DETAILS']['LASTNAME'] = $travelPlanDetail[0]['MEMBERLastName'];
                $sessionPreBookingHotelDetails->params['GRN_PRE_BOOKING_DATA']['PAXES']['DETAILS']['TYPE'] = "AD";
                
                $sessionPreBookingHotelDetails->params['GRN_PRE_BOOKING_DATA']['HOLDER']['DETAILS']['TITLE'] = $strTitle;
                $sessionPreBookingHotelDetails->params['GRN_PRE_BOOKING_DATA']['HOLDER']['DETAILS']['NAME'] = $travelPlanDetail[0]['MEMBERFirstName'];
                $sessionPreBookingHotelDetails->params['GRN_PRE_BOOKING_DATA']['HOLDER']['DETAILS']['LASTNAME'] = $travelPlanDetail[0]['MEMBERLastName'];
                $sessionPreBookingHotelDetails->params['GRN_PRE_BOOKING_DATA']['HOLDER']['DETAILS']['EMAIL_ID'] = $travelPlanDetail[0]['EmailId'];
                $sessionPreBookingHotelDetails->params['GRN_PRE_BOOKING_DATA']['HOLDER']['DETAILS']['PHONE_NO'] = $travelPlanDetail[0]['Contacts'];
                $sessionPreBookingHotelDetails->params['GRN_PRE_BOOKING_DATA']['HOLDER']['DETAILS']['NATIONALITY'] = $travelPlanDetail[0]['Countries'];

				$roominfojson=isset($travelPlanDetail[0]['RoomMemInfoJson'])?json_decode($travelPlanDetail[0]['RoomMemInfoJson'],1):array();
				$memberDetails=array();
				if(!empty($roominfojson)){
					for ($d = 1; $d <= count($roominfojson); $d++) {
						$memberDetails[] = array('AdultPax' => $roominfojson[$d]['adult'], 'ChildPax' => $roominfojson[$d]['child']['childcount'], 'ChildsAge' => @$roominfojson[$d]['child']['childage']);
					}
				}


				$sessionPreBookingHotelDetails->params['memberDetails']=$memberDetails;
				//echo $strTrxStatus."<pre>";print_r($sessionPreBookingHotelDetails->params);
				
                $response = Zend_Controller_Action_HelperBroker::getStaticHelper("Hotel")->apiHotelBooking($sessionPreBookingHotelDetails->params);
				//echo "<pre>";print_r($travelPlanDetail);print_r($response);die;
              //echo "<pre>"; print_r($response); die;
                $ERROR_CODE = $response['ERROR']['CODE'];
                $ERROR_MESSAGE = $response['ERROR']['MESSAGE'];
                if(empty($ERROR_CODE) && empty($ERROR_MESSAGE)){
                    $arrHotelBookingResponse = $response['BOOKING_RESPONSE'];
					if(isset($arrHotelBookingResponse) && !empty($arrHotelBookingResponse)){
						$GRNBOOKING_DETAILS=new Zend_Session_Namespace('GRNBOOKING_DETAILS');
						$GRNBOOKING_DETAILS->GRNBOOKING_DETAILS=$response;
						//print_r($GRNBOOKING_DETAILS->GRNBOOKING_DETAILS);die;
						$objBuyHotel = new Travel_Model_TblBuyHotel();
						$dataBooking = array(
							"APIBookingRes" => json_encode($arrHotelBookingResponse)
						);
						
						if(!empty($planId)){
							if(isset($MasterTPSysId) && $MasterTPSysId > 0){	
								$whereMaste = "MasterTPSysId = " . $MasterTPSysId;
								$disableAlltravelplan = array(
									'StatusType' => 10,
									'UpdateDate' => $createDate
								);
								$disableAlltravelplan = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($disableAlltravelplan, $whereMaste);
							}
							$where = "TPSysId = " . $planId;
							$updatetravelplan = array(
								'StatusType' => 17,
								'UpdateDate' => $createDate
							);
							$updatetravelPlan = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($updatetravelplan, $where);
							
							// update main query status created by Er Amit Kumar Dubey on 8 may 2017 at 11:23 AM
								$statusArray=$customHelper->changeQueryStatusByProposal();
								$querystatus=$statusArray[17];
								if(isset($querystatus) && !empty($querystatus)){
									$whereQuery = "TPSysId = " . $MasterTPSysId;
									$updatetravelplanquery = array(
										'StatusType' => $querystatus,
										'UpdateDate' => $createDate
									);
									$updatetravelPlanQuery = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($updatetravelplanquery, $whereQuery);
								}
								
							//update accom table with bookingid
							$whereHotel = "TPIntSysId = " . $travelPlanDetail[0]['TPIntSysId'];
							$updatetravelplanHotel = array(
								'XRefBookingId' =>$response['BOOKING_RESPONSE']['booking_id'].'/'.$response['BOOKING_RESPONSE']['booking_reference'],
								'UpdateDate' => $createDate
							);
							$crmcusttravelplanAccomObj=new Travel_Model_CRM_CustomerTravelPlanAccom();
							$updatetravelPlanHotel = $crmcusttravelplanAccomObj->UpdateTravelPlanAccom($updatetravelplanHotel, $whereHotel);
						}
						$msgArray=array('status'=>$arrHotelBookingResponse['status'],"CODE"=>$CODE,'MESSAGE'=>'Your payment is success');
						$PAYMENT_MSG = new Zend_Session_Namespace('PAYMENT_MSG');
						$PAYMENT_MSG->PAYMENT_MSG=$msgArray;
						
							if($response['BOOKING_RESPONSE']['booking_id']!=''){
							//send email to customer
									$html = new Zend_View();
									$html->setScriptPath(APPLICATION_PATH . '/views/scripts/proposal/');
									//$URL='cid:'.$agencyCustomerDetails['CustomerSysId']."@@"."aid:".$agencysysID;
									//$encryptData=$this->getEnc($URL);
									$agencyStaffObj = new Travel_Model_TblAgencyStaff();
									$agentDetail=$agencyStaffObj->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
									$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
									$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1'],'AgentEmail'=>$agentDetail['EmailId']);
									$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
									$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';

									$html->assign('type', 'HotelBookingPaymentConfirmationEmail');
									$html->assign('data', $travelPlanDetail);
									$html->assign('getAgentDetail',$getAgentDetail);
									$html->assign('agencyDetails',$getAgencyDetail);
									$html->assign('ARR_SALUTION',$ARR_SALUTION);
									//$html->assign('URL', $encryptData);
									$paymentconfirmText = $html->render('email-template.phtml');
									$html->assign('type', 'HotelBookingConfirmationEmailText');
									$html->assign('data', $travelPlanDetail);
									$html->assign('getAgentDetail',$getAgentDetail);
									$html->assign('agencyDetails',$getAgencyDetail);
									$html->assign('ARR_SALUTION',$ARR_SALUTION);
				
									$bookingConfirmText = $html->render('email-template.phtml');
									
									$aConfig = $this->getInvokeArg('bootstrap')->getOptions();
									$this->smtpUserName = $aConfig['smtpUserName'];
									$this->smtpPassword = $aConfig['smtpPassword'];
									$this->smtpPort = $aConfig['smtpPort'];
									$this->smtpHost = $aConfig['smtpHost'];
									$this->fromEmail = $aConfig['fromEmail'];
									$this->fromName = $aConfig['fromName'];
									$emailId = '' . trim($travelPlanDetail[0]['ProposalEmailTo']) . '';
									$emailData1 = array('fromEmail'=>$this->fromEmail,'fromName'=>$this->fromName,'subject'=>stripslashes($travelPlanDetail[0]['hotelCityTitle']).' Trip Payment Receipt','to'=>array(trim($emailId)),'bodyHtml'=>$paymentconfirmText,'bodyText'=>'');
									$emailData2 = array('fromEmail'=>$this->fromEmail,'fromName'=>$this->fromName,'subject'=>stripslashes($travelPlanDetail[0]['hotelCityTitle']).' Trip Booking Details','to'=>array(trim($emailId)),'bodyHtml'=>$bookingConfirmText,'bodyText'=>'');
									try {
										//echo "success";
										$arrEmailStatisticsType = array_keys(unserialize(ARR_EMAIL_STATISTICS_TYPE));
										$arrEmailStatistics = array(
											"TPSysId" => $planId,
											"TypeSysId" => 1,  // 1 For Email 2 For SMS
											"AgencySysId" => $travelPlanDetail[0]['AgencySysId'],
											"AgentSysId" => $travelPlanDetail[0]['AgentSysId'],
											"Title" => $paymentconfirmText,
											"Source" => $arrEmailStatisticsType[1], // 2 For Vouchers
											"Status" => 0,
											"RefSysId" => "",
											"RefSysStatus" => "",
											"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
										);
										$arrEmailStatistics2 = array(
											"TPSysId" => $planId,
											"TypeSysId" => 1,  // 1 For Email 2 For SMS
											"AgencySysId" => $travelPlanDetail[0]['AgencySysId'],
											"AgentSysId" => $travelPlanDetail[0]['AgentSysId'],
											"Title" => $bookingConfirmText,
											"Source" => $arrEmailStatisticsType[1], // 2 For Vouchers
											"Status" => 0,
											"RefSysId" => "",
											"RefSysStatus" => "",
											"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
										);
										$this->mailSentByElastice($emailData1,$arrEmailStatistics);
										$this->mailSentByElastice($emailData2,$arrEmailStatistics2);
										$msg="success";
									} catch (Exception $err) {
										//print_r($err, true);
										$msg="failed";
									}
							//end of send email to customer
						
						}
						
					} else{
							/*if(isset($MasterTPSysId) && $MasterTPSysId > 0){	
								$whereMaste = "MasterTPSysId = " . $MasterTPSysId;
								$disableAlltravelplan = array(
									'StatusType' => 10,
									'UpdateDate' => $createDate
								);
								$disableAlltravelplan = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($disableAlltravelplan, $whereMaste);
							}*/
							$where = "TPSysId = " . $planId;
							$updatetravelplan = array(
								'StatusType' => 7,
								'UpdateDate' => $createDate
							);
							$updatetravelPlan = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($updatetravelplan, $where);


							// update main query status created by Er Amit Kumar Dubey on 8 may 2017 at 11:27 AM
								$statusArray=$customHelper->changeQueryStatusByProposal();
								$querystatus=$statusArray[7];
								if(isset($querystatus) && !empty($querystatus)){
									$whereQuery = "TPSysId = " . $MasterTPSysId;
									$updatetravelplanquery = array(
										'StatusType' => $querystatus,
										'UpdateDate' => $createDate
									);
									$updatetravelPlanQuery = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($updatetravelplanquery, $whereQuery);
								}


						$msgArray=array('status'=>'failed',"CODE"=>'','MESSAGE'=>'Your payment is success.Hotel Booking is pending.Please Wait');
						$PAYMENT_MSG = new Zend_Session_Namespace('PAYMENT_MSG');
						$PAYMENT_MSG->PAYMENT_MSG=$msgArray;
						
					}
                  $this->_redirect("/proposal/booking-confirmation/mid/".base64_encode($MasterTPSysId)."/pid/".base64_encode($planId)."/uid/".$uid);
                  exit;
                }else{
					$msgArray=array('status'=>"failed","CODE"=>$CODE,'MESSAGE'=>$ERROR_MESSAGE);
					$PAYMENT_MSG = new Zend_Session_Namespace('PAYMENT_MSG');
					$PAYMENT_MSG->PAYMENT_MSG=$msgArray;
                    $this->_redirect("/proposal/booking-confirmation/mid/".base64_encode($MasterTPSysId)."/pid/".base64_encode($planId)."/uid/".$uid);
                    exit;
                }
                
                
            }else{
				$PAYMENT_MSG = new Zend_Session_Namespace('PAYMENT_MSG');
				$msgArray=array('status'=>"Payment unsuccessful");
				$PAYMENT_MSG->PAYMENT_MSG=$msgArray;
                  $this->_redirect("/proposal/booking-confirmation/mid/".base64_encode($MasterTPSysId)."/pid/".base64_encode($planId)."/uid/".$uid);
                exit;
                    
            }
        } else {
        if ($strTrxStatus == "success") {

           /* for ($i = 0; $i < 2; $i++) {
            $hotelPassenger[] = array(
                                    "Title" => $strTitle,
                                    "FirstName" => trim($travelPlanDetail[0]['FirstName']),
                                    "Middlename" => "",
                                    "LastName" => trim($travelPlanDetail[0]['LastName']),
                                    "Phoneno" => trim($travelPlanDetail[0]['Contacts']),
                                    "Email" => trim($travelPlanDetail[0]['EmailId']),
                                    "PaxType" => 1,
                                    "LeadPassenger" => true,
                                    "Age" => 0,
                                    "PassportNo" => "J3578965",
                                    "PassportIssueDate" => "0001-01-01T00:00:00",
                                    "PassportExpDate" => "0001-01-01T00:00:00"
                                );
            }*/
           
            $noOfRooms = count($RoomMemInfoJson);
            $j = 0;
			$n=1;
			//$rommwisePrice=(trim($blockRoom->blockRoom['BlockRoomResult']['HotelRoomsDetails'][$j]['Price']['RoomPrice'], ".\r\n")/$noOfRooms);
            for ($i = 0; $i < $noOfRooms; $i++) {

				 $hotelPassenger=array();
				 $adultPaxTotal = $RoomMemInfoJson[$n]['adult'];
				 $childPaxTotal = $RoomMemInfoJson[$n]['child']['childcount'];
				 $totalAdCh=$adultPaxTotal+$childPaxTotal;
				for ($m = 0; $m < $adultPaxTotal; $m++) {
					$hotelPassenger[] = array(
							"Title" => $strTitle,
							"FirstName" => trim($travelPlanDetail[0]['MEMBERFirstName']),
							"Middlename" => "",
							"LastName" => trim($travelPlanDetail[0]['MEMBERLastName']),
							"Phoneno" => trim($travelPlanDetail[0]['Contacts']),
							"Email" => trim($travelPlanDetail[0]['EmailId']),
							"PaxType" => 1,
							"LeadPassenger" => true,
							"Age" => 0,
							"PassportNo" => "J3578965",
							"PassportIssueDate" => "0001-01-01T00:00:00",
							"PassportExpDate" => "0001-01-01T00:00:00"
						);
				}
				if($childPaxTotal > 0){
					for ($m = 0; $m < $childPaxTotal; $m++) {
						$hotelPassenger[] = array(
								"Title" => $strTitle,
								"FirstName" => trim($travelPlanDetail[0]['MEMBERFirstName']),
								"Middlename" => "",
								"LastName" => trim($travelPlanDetail[0]['MEMBERLastName']),
								"Phoneno" => trim($travelPlanDetail[0]['Contacts']),
								"Email" => trim($travelPlanDetail[0]['EmailId']),
								"PaxType" => 2,
								"LeadPassenger" => true,
								"Age" => 0,
								"PassportNo" => "J3578965",
								"PassportIssueDate" => "0001-01-01T00:00:00",
								"PassportExpDate" => "0001-01-01T00:00:00"
							);
					}
				}

               
                    $rooms[] = array("RoomIndex" => trim($blockRoom->blockRoom['BlockRoomResult']['HotelRoomsDetails'][$j]['RoomIndex'], ".\r\n"),
                    "RoomTypeCode" => htmlspecialchars($blockRoom->blockRoom['BlockRoomResult']['HotelRoomsDetails'][$j]['RoomTypeCode']),
                    "RoomTypeName" => trim($blockRoom->blockRoom['BlockRoomResult']['HotelRoomsDetails'][$j]['RoomTypeName'], ".\r\n"),
                    "RatePlanCode" => trim($blockRoom->blockRoom['BlockRoomResult']['HotelRoomsDetails'][$j]['RatePlanCode'], ".\r\n"),
                    "BedTypeCode" => null,
                    "SmokingPreference" => "0",
                    "Supplements" => null,
                    'Price' => array("CurrencyCode" => "INR",
                        "RoomPrice" => (float) trim($blockRoom->blockRoom['BlockRoomResult']['HotelRoomsDetails'][$j]['Price']['RoomPrice'], ".\r\n"),
                        "Tax" => trim($blockRoom->blockRoom['BlockRoomResult']['HotelRoomsDetails'][$j]['Price']['Tax'], ".\r\n"),
                        "ExtraGuestCharge" => trim($blockRoom->blockRoom['BlockRoomResult']['HotelRoomsDetails'][$j]['Price']['ExtraGuestCharge'], ".\r\n"),
                        "ChildCharge" => trim($blockRoom->blockRoom['BlockRoomResult']['HotelRoomsDetails'][$j]['Price']['ChildCharge'], ".\r\n"),
                        "OtherCharges" => trim($blockRoom->blockRoom['BlockRoomResult']['HotelRoomsDetails'][$j]['Price']['OtherCharges'], ".\r\n"),
                        "Discount" => trim($blockRoom->blockRoom['BlockRoomResult']['HotelRoomsDetails'][$j]['Price']['Discount'], ".\r\n"),
                        "PublishedPrice" => (float) trim($blockRoom->blockRoom['BlockRoomResult']['HotelRoomsDetails'][$j]['Price']['PublishedPrice'], ".\r\n"),

                        "PublishedPriceRoundedOff" => (int) trim($blockRoom->blockRoom['BlockRoomResult']['HotelRoomsDetails'][$j]['Price']['PublishedPriceRoundedOff'], ".\r\n"),
                        "OfferedPrice" => (float) trim($blockRoom->blockRoom['BlockRoomResult']['HotelRoomsDetails'][$j]['Price']['OfferedPrice'], ".\r\n"),
                        "OfferedPriceRoundedOff" => (int) trim($blockRoom->blockRoom['BlockRoomResult']['HotelRoomsDetails'][$j]['Price']['OfferedPriceRoundedOff'], ".\r\n"),

                        "AgentCommission" => trim($blockRoom->blockRoom['BlockRoomResult']['HotelRoomsDetails'][$j]['Price']['AgentCommission'], ".\r\n"),
                        "AgentMarkUp" => trim($blockRoom->blockRoom['BlockRoomResult']['HotelRoomsDetails'][$j]['Price']['AgentMarkUp'], ".\r\n"),
                        "ServiceTax" => trim($blockRoom->blockRoom['BlockRoomResult']['HotelRoomsDetails'][$j]['Price']['ServiceTax'], ".\r\n"),
                        "TDS" => trim($blockRoom->blockRoom['BlockRoomResult']['HotelRoomsDetails'][$j]['Price']['TDS'], ".\r\n")),
                        "HotelPassenger" => $hotelPassenger
                );
                $n++;
            }
			
			//echo "<pre>";print_r($rooms);
			//call api for hotel room booking details created by Er amit kumar dubey on 22 nov 2016
            $tokenId = Zend_Controller_Action_HelperBroker::getStaticHelper('Flight')->authenticateAPI();
            $datahRoom = array(
                "ResultIndex" => $selectedHotelResults->selectedHotelResults['ResultIndex'],
                "HotelCode" => $selectedHotelResults->selectedHotelResults['HotelCode'],
                "HotelName" => $selectedHotelResults->selectedHotelResults['HotelName'],
                "GuestNationality" => 'IN',
                "NoOfRooms" => count($RoomMemInfoJson),
                "ClientReferenceNo" => 0,
                "IsVoucherBooking" => true,
                "HotelRoomsDetails" => $rooms,
                "EndUserIp" => $_SERVER['REMOTE_ADDR'],
                "TokenId" => $tokenId,
                "TraceId" => $blockRoom->blockRoom['BlockRoomResult']['TraceId']
            );

            
            
            $objApi = new Travel_Model_ApiIntegration();
            $arrHotelBookingResponse = $objApi->bookRoom($datahRoom);
			//echo "<pre>";print_r($arrHotelBookingResponse);die;
			$objBuyHotel = new Travel_Model_TblBuyHotel();
			$dataBooking = array(
				"APIBookingRes" => json_encode($arrHotelBookingResponse)
			);
			//print_r($arrHotelBookingResponse);die;
			$strBookingStatus = $arrHotelBookingResponse['BookResult']['HotelBookingStatus'];
			$strBookingId = $arrHotelBookingResponse['BookResult']['BookingId'];
			$strBookingRef = $arrHotelBookingResponse['BookResult']['BookingRefNo']; 
				///if payment success then update travel plan
				$createDate = date('Y-m-d H:i:s');
				if(!empty($planId)){
				 	//$objBuyHotel->updateBookingDetails($dataBooking,$planId);
					if($strBookingStatus=='Confirmed'){
						if(isset($MasterTPSysId) && $MasterTPSysId > 0){	
							$whereMaster = "MasterTPSysId = " . $MasterTPSysId;
							$disableAlltravelplan = array(
								'StatusType' => 10,
								'UpdateDate' => $createDate
							);
							$disableAlltravelplan = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($disableAlltravelplan, $whereMaster);
						}
						
						$where = "TPSysId = " . $planId;
						$updatetravelplan = array(
							'StatusType' => 17,
							'UpdateDate' => $createDate
						);
						$updatetravelPlan = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($updatetravelplan, $where);



							// update main query status created by Er Amit Kumar Dubey on 8 may 2017 at 11:23 AM
								$statusArray=$customHelper->changeQueryStatusByProposal();
								$querystatus=$statusArray[17];
								if(isset($querystatus) && !empty($querystatus)){
									$whereQuery = "TPSysId = " . $MasterTPSysId;
									$updatetravelplanquery = array(
										'StatusType' => $querystatus,
										'UpdateDate' => $createDate
									);
									$updatetravelPlanQuery = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($updatetravelplanquery, $whereQuery);
								}

						//update accom table with bookingid
						$whereHotel = "TPIntSysId = " . $travelPlanDetail[0]['TPIntSysId'];
						$updatetravelplanHotel = array(
							'XRefBookingId' =>$strBookingId.'/'.$strBookingRef,
							'UpdateDate' => $createDate
						);
						$crmcusttravelplanAccomObj=new Travel_Model_CRM_CustomerTravelPlanAccom();
						$updatetravelPlanHotel = $crmcusttravelplanAccomObj->UpdateTravelPlanAccom($updatetravelplanHotel, $whereHotel);
						$PAYMENT_MSG = new Zend_Session_Namespace('PAYMENT_MSG');
						$msgArray=array('status'=>"success",'MESSAGE'=>'Payment successful');
						$PAYMENT_MSG->PAYMENT_MSG=$msgArray;
						
						if($strBookingId!=''){
							//send email to customer
									$html = new Zend_View();
									$html->setScriptPath(APPLICATION_PATH . '/views/scripts/proposal/');
									//$URL='cid:'.$agencyCustomerDetails['CustomerSysId']."@@"."aid:".$agencysysID;
									//$encryptData=$this->getEnc($URL);
									$agencyStaffObj = new Travel_Model_TblAgencyStaff();
									$agentDetail=$agencyStaffObj->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
									$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
									$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1'],'AgentEmail'=>$agentDetail['EmailId']);
									$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
									$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';

									$html->assign('type', 'HotelBookingPaymentConfirmationEmail');
									$html->assign('data', $travelPlanDetail);
									$html->assign('getAgentDetail',$getAgentDetail);
									$html->assign('agencyDetails',$getAgencyDetail);
									$html->assign('ARR_SALUTION',$ARR_SALUTION);
									//$html->assign('URL', $encryptData);
									$paymentconfirmText = $html->render('email-template.phtml');
									$html->assign('type', 'HotelBookingConfirmationEmailText');
									$html->assign('data', $travelPlanDetail);
									$html->assign('getAgentDetail',$getAgentDetail);
									$html->assign('agencyDetails',$getAgencyDetail);
									$html->assign('ARR_SALUTION',$ARR_SALUTION);
				
									$bookingConfirmText = $html->render('email-template.phtml');
									
									$aConfig = $this->getInvokeArg('bootstrap')->getOptions();
									$this->smtpUserName = $aConfig['smtpUserName'];
									$this->smtpPassword = $aConfig['smtpPassword'];
									$this->smtpPort = $aConfig['smtpPort'];
									$this->smtpHost = $aConfig['smtpHost'];
									$this->fromEmail = $aConfig['fromEmail'];
									$this->fromName = $aConfig['fromName'];
									$emailId = '' . trim($travelPlanDetail[0]['ProposalEmailTo']) . '';
									$emailData1 = array('fromEmail'=>$this->fromEmail,'fromName'=>$this->fromName,'subject'=>stripslashes($travelPlanDetail[0]['hotelCityTitle']).' Trip Payment Receipt','to'=>array(trim($emailId)),'bodyHtml'=>$paymentconfirmText,'bodyText'=>'');
									$emailData2 = array('fromEmail'=>$this->fromEmail,'fromName'=>$this->fromName,'subject'=>stripslashes($travelPlanDetail[0]['hotelCityTitle']).' Trip Booking Details','to'=>array(trim($emailId)),'bodyHtml'=>$bookingConfirmText,'bodyText'=>'');
									try {
										//echo "success";
										$arrEmailStatisticsType = array_keys(unserialize(ARR_EMAIL_STATISTICS_TYPE));
										$arrEmailStatistics = array(
											"TPSysId" => $planId,
											"TypeSysId" => 1,  // 1 For Email 2 For SMS
											"AgencySysId" => $travelPlanDetail[0]['AgencySysId'],
											"AgentSysId" => $travelPlanDetail[0]['AgentSysId'],
											"Title" => $paymentconfirmText,
											"Source" => $arrEmailStatisticsType[1], // 2 For Vouchers
											"Status" => 0,
											"RefSysId" => "",
											"RefSysStatus" => "",
											"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
										);
										$arrEmailStatistics2 = array(
											"TPSysId" => $planId,
											"TypeSysId" => 1,  // 1 For Email 2 For SMS
											"AgencySysId" => $travelPlanDetail[0]['AgencySysId'],
											"AgentSysId" => $travelPlanDetail[0]['AgentSysId'],
											"Title" => $bookingConfirmText,
											"Source" => $arrEmailStatisticsType[1], // 2 For Vouchers
											"Status" => 0,
											"RefSysId" => "",
											"RefSysStatus" => "",
											"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
										);
										$this->mailSentByElastice($emailData1,$arrEmailStatistics);
										$this->mailSentByElastice($emailData2,$arrEmailStatistics2);
										$msg="success";
									} catch (Exception $err) {
										//print_r($err, true);
										$msg="failed";
									}
							//end of send email to customer
						
						}
						
						
					} else{
						if(isset($arrHotelBookingResponse['BookResult']['Error']['ErrorMessage']) && !empty($arrHotelBookingResponse['BookResult']['Error']['ErrorMessage'])){
							$PAYMENT_MSG = new Zend_Session_Namespace('PAYMENT_MSG');
							$msgArray=array('status'=>"success",'MESSAGE'=>'Some thing went wrong . '.$arrHotelBookingResponse['BookResult']['Error']['ErrorMessage']);
							$PAYMENT_MSG->PAYMENT_MSG=$msgArray;
						}else{
							$where = "TPSysId = " . $planId;
							$updatetravelplan = array(
								'StatusType' => 7,
								'UpdateDate' => $createDate
							);
							$updatetravelPlan = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($updatetravelplan, $where);

							// update main query status created by Er Amit Kumar Dubey on 8 may 2017 at 11:23 AM
								$statusArray=$customHelper->changeQueryStatusByProposal();
								$querystatus=$statusArray[7];
								if(isset($querystatus) && !empty($querystatus)){
									$whereQuery = "TPSysId = " . $MasterTPSysId;
									$updatetravelplanquery = array(
										'StatusType' => $querystatus,
										'UpdateDate' => $createDate
									);
									$updatetravelPlanQuery = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($updatetravelplanquery, $whereQuery);
								}

							$PAYMENT_MSG = new Zend_Session_Namespace('PAYMENT_MSG');
							$msgArray=array('status'=>"success",'MESSAGE'=>'Payment successful . Booking Pending');
							$PAYMENT_MSG->PAYMENT_MSG=$msgArray;
						}
					}
				}

				//print_r($msgArray);
                  $this->_redirect("/proposal/booking-confirmation/mid/".base64_encode($MasterTPSysId)."/pid/".base64_encode($planId)."/uid/".$uid);
            //}
            
        }else{
				$PAYMENT_MSG = new Zend_Session_Namespace('PAYMENT_MSG');
				$msgArray=array('status'=>"failed",'MESSAGE'=>'Payment unsuccessful');
				$PAYMENT_MSG->PAYMENT_MSG=$msgArray;
                  $this->_redirect("/proposal/booking-confirmation/mid/".base64_encode($MasterTPSysId)."/pid/".base64_encode($planId)."/uid/".$uid);
				exit;
        }
		}
		
       
    }
	public function bookingConfirmationAction(){
		$this->view->layout()->disableLayout();
		$proposalId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$pid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('pid')));
		$uid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('uid')));
		$strdecode = @$this->getDec($uid);
		//if(isset($proposalId) && !empty($proposalId)){
		$travelPlanDetail=$this->_crmcusttravelplan->GetTravelPlanCustomerDetailsPax($pid);
		//echo "<pre>";print_r($travelPlanDetail);
		$strdecode=explode(':',$strdecode);
		$CRMCustSysId=$travelPlanDetail[0]['CustomerSysId'];
		if((@$strdecode[0]!=intval($CRMCustSysId)) || (@$strdecode[1]!=intval($pid)) || (@$strdecode[2]!=intval($proposalId))){
			echo "Please try again";
			die;
		}

		$PAYMENT_MSG = new Zend_Session_Namespace('PAYMENT_MSG');
		//customer detail
				$tpID=$pid;
				$CRMCustSysId=$travelPlanDetail[0]['CustomerSysId'];
				$getLeadlist = $this->_crmcusttravelplan->GetPurchasedPublicPageLeadList($CRMCustSysId, $travelPlanDetail[0]['AgencySysId'], $tpID);
				$API_SOURCE_ID=$travelPlanDetail[0]['ICSourceSysId'];
				$roomjsonarray=json_decode($travelPlanDetail[0]['RoomMemInfoJson'],1);				
				$adultPax =0;
				$childPax =0;
				if(!empty($roomjsonarray)){
					foreach($roomjsonarray as $res){
						$adultPax += $res['adult'];
						$childPax += $res['child']['childcount'];
					}
				}
				if($API_SOURCE_ID == "3"){
								if(count($roomjsonarray) > 0 && !empty($roomjsonarray)){
									$intRoomPrice = 0;
									$intTax = 0;
									//foreach ($arrHotelRoomsDetails as $roomsDetailsVal){
										$strCurrencyCode ='INR';
										//$strCurrencyCode = $travelPlanDetail['Price']['CurrencyCode'];
										$intRoomPrice += $travelPlanDetail[0]['NetCost'];
										$intTax += $travelPlanDetail[0]['XServiceTaxAmount'];
									//}
								}
								
								$this->view->intRoomPrice =  $intRoomPrice = round($intRoomPrice);
								$this->view->intTax =  $intTax = !empty($intTax)?round($intTax):0;
								$this->view->intRoomCount =  $intRoomCount = 1;
								//$this->view->intRoomCount =  $intRoomCount = count($roomjsonarray);
								$this->view->intNigthsCount =  $intNigthsCount = $travelPlanDetail[0]['hotelTotalNights'];
								$this->view->intTotalAmount =  $intTotalAmount = $intRoomPrice * $intRoomCount;
								$this->view->intAgentMarkUpAmount =  $intAgentMarkUpAmount = $travelPlanDetail[0]['hotelMarkUp'];//$markupAgency->markupAg;
								$this->view->intAgencyMarkUpAmount =  $intAgencyMarkUpAmount = $travelPlanDetail[0]['AgencyMarkUp'];//$markupAgency->markupAg;
								$this->view->intGTXMarkUpAmount =  $intGTXMarkUpAmount = $travelPlanDetail[0]['GTXMarkup'];//$markupAgency->markupAg;
								$this->view->intTotalGTXTaxAmount =  $intTotalGTXTaxAmount = $travelPlanDetail[0]['Taxes'];//gtx total tax included all markup taxes;
								$this->view->intTotalAmountForApplicableNights =  $intTotalAmountForApplicableNights = $intTotalAmount * 1;
								//$this->view->intTotalAmountForApplicableNights =  $intTotalAmountForApplicableNights = $intTotalAmount * $intNigthsCount;
								$this->view->intGrandPayableAmount =  $intGrandPayableAmount = $intTotalAmountForApplicableNights + $intTax + $intAgentMarkUpAmount + $intAgencyMarkUpAmount + $intGTXMarkUpAmount + $intTotalGTXTaxAmount;
						}else if($API_SOURCE_ID == "4"){
							$NO_OF_ROOMS = count($roomjsonarray);
							$ARR_ROOMPRICE = $travelPlanDetail[0]['NetCost'];
			
							$NO_OF_CHILD = $childPax;
							$NO_OF_ADULTS = $adultPax;
				
								if(count($ARR_ROOMPRICE) > 0 && !empty($ARR_ROOMPRICE)){
									$intRoomPrice = 0;
									$intTax = 0;
									$intServiceFee = 0;
									for ($i = 1; $i<=$NO_OF_ROOMS; $i++){
										$strCurrencyCode = $travelPlanDetail[0]['CurrencyType'];
										$intRoomPrice += $travelPlanDetail[0]['NetCost'];
										$intTax += $travelPlanDetail[0]['XServiceTaxAmount'];
									}
								}
								$this->view->intRoomPrice =  $intRoomPrice = round($intRoomPrice);
								$this->view->intTax =  $intTax = !empty($intTax)?round($intTax):0;
								//$this->view->intRoomCount =  $intRoomCount = count($roomjsonarray);
								$this->view->intRoomCount =  $intRoomCount = 1;
								$this->view->intNigthsCount =  $intNigthsCount = $travelPlanDetail[0]['hotelTotalNights'];
								$this->view->intTotalAmount =  $intTotalAmount = $intRoomPrice * $intRoomCount;
								$this->view->intAgentMarkUpAmount =  $intAgentMarkUpAmount = $travelPlanDetail[0]['hotelMarkUp'];//$markupAgency->markupAg;
								$this->view->intAgencyMarkUpAmount =  $intAgencyMarkUpAmount = $travelPlanDetail[0]['AgencyMarkUp'];//$markupAgency->markupAg;
								$this->view->intGTXMarkUpAmount =  $intGTXMarkUpAmount = $travelPlanDetail[0]['GTXMarkup'];//$markupAgency->markupAg;
								$this->view->intTotalGTXTaxAmount =  $intTotalGTXTaxAmount = $travelPlanDetail[0]['Taxes'];//gtx total tax included all markup taxes;
								//$this->view->intTotalAmountForApplicableNights =  $intTotalAmountForApplicableNights = $intTotalAmount * $intNigthsCount;
								$this->view->intTotalAmountForApplicableNights =  $intTotalAmountForApplicableNights = $intTotalAmount * 1;
								$this->view->intGrandPayableAmount =  $intGrandPayableAmount = $intTotalAmountForApplicableNights + $intTax + $intAgentMarkUpAmount + $intAgencyMarkUpAmount + $intGTXMarkUpAmount + $intTotalGTXTaxAmount;
						}
				
				
				
				if (isset($CRMCustSysId) && !empty($CRMCustSysId)) {
			        $this->_crmcustomerObj = new Travel_Model_CRM_Customer();
					$getCustomerDetail = $this->_crmcusttravelplan->GetTravelPlanCustomerDetails($tpID);
					$objAgencyUser = new Travel_Model_CRM_AgencyUserInbox();
					$checkCustomerChatExist = $getCustomerDetail[0]['CustomerSysId'] > 0? $objAgencyUser->CheckCustomerMsgCount($getCustomerDetail[0]['CustomerSysId'],$tpID):array();
					$getversiondetails = $this->_crmcusttravelplan->GetVersionInfo($tpID);
					$getCustomerDetail['userChatExist']=count($checkCustomerChatExist);
				}
		//end of customer detail
		//query for get customer chat history
			$chatSenderDetails=array();
			if($getCustomerDetail['userChatExist'] > 0){
					if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
						$getChatHistoryDetail = $objAgencyUser->GetCustChatHistDetWithLead($tpID,$getCustomerDetail[0]['CustomerSysId'],'DESC');
						$this->view->chatHistoryDetail=$getChatHistoryDetail;
						$chatSenderDetails['TPSysId']=$tpID;
						$chatSenderDetails['AgencySysId']=$getLeadlist[0]['AgencySysId'];
						$chatSenderDetails['CRMCustSysId']=$getCustomerDetail[0]['CustomerSysId'];
						$chatSenderDetails['AgentSysId']=$getLeadlist[0]['AgentSysId'];
						//$chatSenderDetails['EmailId']=$getcustomerDetail[0]['EmailId'];
						$objAgencyStaff   =	new Travel_Model_TblAgencyStaff();
						$agentDetail=$objAgencyStaff->getUserDetailsById($getLeadlist[0]['AgentSysId']);
						$chatSenderDetails['EmailId']=$agentDetail['EmailId'];
						//print_r($agentDetail);
						
						
					}
			}
			//end of customer chat history
			$agencyStaffObj = new Travel_Model_TblAgencyStaff();
			$agentDetail=$agencyStaffObj->getUserDetailsById($getLeadlist[0]['AgentSysId']);
			$AgencySysId = $getLeadlist[0]['AgencySysId'];
			$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1'],'AgentEmail'=>$agentDetail['EmailId']);
			$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
			$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
			$this->view->getAgentDetail=$getAgentDetail;
			$this->view->agencyDetails=$getAgencyDetail;
		//echo "<pre>";print_r($travelPlanDetail);die;
		$this->view->travelPlanDetail=$travelPlanDetail;
		$this->view->getcustomerDetail = $getCustomerDetail;
		$this->view->PAYMENT_MSG=$PAYMENT_MSG->PAYMENT_MSG;
		$ARR_SALUTION=unserialize(ARR_SALUTION);
		$this->view->ARR_SALUTION=$ARR_SALUTION;
		$this->view->uid=$uid;
		
		
   }
    public function hotelViewAction() {
       	$this->_helper->layout->disableLayout(); 
		$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$pid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('pid')));
		$uid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('uid')));
		$strdecode = @$this->getDec($uid);
		//if(isset($proposalId) && !empty($proposalId)){
		$travelPlanDetail=$this->_crmcusttravelplan->GetTravelPlanCustomerDetailsTrx($pid);
		//print_r($travelPlanDetail);die;
		$strdecode=explode(':',$strdecode);
		$CRMCustSysId=$travelPlanDetail[0]['CustomerSysId'];
		if((@$strdecode[0]!=intval($CRMCustSysId)) || (@$strdecode[1]!=intval($pid)) || (@$strdecode[2]!=intval($mid))){
			echo "Please try again";
			die;
		}

		//customer detail
		$CustomerSysId=$travelPlanDetail[0]['CustomerSysId'];

				if (isset($CustomerSysId) && !empty($CustomerSysId)) {
			        $this->_crmcustomerObj = new Travel_Model_CRM_Customer();
					$getCustomerDetail = $this->_crmcusttravelplan->GetTravelPlanCustomerDetails($pid);
					$objAgencyUser = new Travel_Model_CRM_AgencyUserInbox();
					$checkCustomerChatExist = $getCustomerDetail[0]['CustomerSysId'] > 0? $objAgencyUser->CheckCustomerMsgCount($getCustomerDetail[0]['CustomerSysId'],$pid):array();
					$getversiondetails = $this->_crmcusttravelplan->GetVersionInfo($pid);
					$getCustomerDetail['userChatExist']=count($checkCustomerChatExist);
				}
		//end of customer detail
		//query for get customer chat history
			$chatSenderDetails=array();
			if($getCustomerDetail['userChatExist'] > 0){
					if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
						$getChatHistoryDetail = $objAgencyUser->GetCustChatHistDetWithLead($pid,$getCustomerDetail[0]['CustomerSysId'],'DESC');
						$this->view->chatHistoryDetail=$getChatHistoryDetail;
						$chatSenderDetails['TPSysId']=$pid;
						$chatSenderDetails['AgencySysId']=$travelPlanDetail[0]['AgencySysId'];
						$chatSenderDetails['CustomerSysId']=$travelPlanDetail[0]['CustomerSysId'];
						$chatSenderDetails['AgentSysId']=$travelPlanDetail[0]['AgentSysId'];
						//$chatSenderDetails['EmailId']=$getcustomerDetail[0]['EmailId'];
						$objAgencyStaff   =	new Travel_Model_TblAgencyStaff();
						$agentDetail=$objAgencyStaff->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
						$chatSenderDetails['EmailId']=$agentDetail['EmailId'];
						//print_r($agentDetail);
						
						
					}
			}
			//end of customer chat history
			$agencyStaffObj = new Travel_Model_TblAgencyStaff();
			$agentDetail=$agencyStaffObj->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
			$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
			$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1']);
			$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
			$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
			$this->view->getAgentDetail=$getAgentDetail;
			$this->view->agencyDetails=$getAgencyDetail;
			$this->view->getcustomerDetail = $getCustomerDetail;
			$this->view->travelPlanDetail=$travelPlanDetail;
			$ARR_SALUTION=unserialize(ARR_SALUTION);
			$this->view->ARR_SALUTION=$ARR_SALUTION;
    }

    public function hotelVoucherAction() {
        $this->_helper->layout->disableLayout();
		$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$pid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('pid')));
		$uid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('uid')));
		$strdecode = @$this->getDec($uid);
		//if(isset($proposalId) && !empty($proposalId)){
		$travelPlanDetail=$this->_crmcusttravelplan->GetTravelPlanCustomerDetailsTrx($pid);
		//print_r($travelPlanDetail);die;
		$strdecode=explode(':',$strdecode);
		$CustomerSysId=$travelPlanDetail[0]['CustomerSysId'];
		if((@$strdecode[0]!=intval($CustomerSysId)) || (@$strdecode[1]!=intval($pid)) || (@$strdecode[2]!=intval($mid))){
			echo "Please try again";
			die;
		}
		$objAgencyStaff = new Travel_Model_TblAgencyStaff();
		$agentDetail=$objAgencyStaff->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
		$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
		$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1']);
		$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
		$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
		$this->view->getAgentDetail=$getAgentDetail;
		$this->view->agencyDetails=$getAgencyDetail;
		$this->view->travelPlanDetail=$travelPlanDetail;
		$ARR_SALUTION=unserialize(ARR_SALUTION);
		$this->view->ARR_SALUTION=$ARR_SALUTION;
   }
    public function hotelInvoiceAction() {
        $this->_helper->layout->disableLayout(); 

		$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$pid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('pid')));
		$uid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('uid')));
		$strdecode = @$this->getDec($uid);
		//if(isset($proposalId) && !empty($proposalId)){
		$travelPlanDetail=$this->_crmcusttravelplan->GetTravelPlanCustomerDetailsTrx($pid);
		$strdecode=explode(':',$strdecode);
		$CustomerSysId=$travelPlanDetail[0]['CustomerSysId'];
		if((@$strdecode[0]!=intval($CustomerSysId)) || (@$strdecode[1]!=intval($pid)) || (@$strdecode[2]!=intval($mid))){
			echo "Please try again";
			die;
		}
		$objAgencyStaff = new Travel_Model_TblAgencyStaff();
		$agentDetail=$objAgencyStaff->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
		$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
		$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1']);
		$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
		$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
		$this->view->getAgentDetail=$getAgentDetail;
		$this->view->agencyDetails=$getAgencyDetail;
		$this->view->travelPlanDetail=$travelPlanDetail;
                //echo "<pre>";print_r($getAgencyDetail);die;
		$ARR_SALUTION=unserialize(ARR_SALUTION);
		$this->view->ARR_SALUTION=$ARR_SALUTION;
		$customhelper = Zend_Controller_Action_HelperBroker::getStaticHelper('Custom');
		$this->view->getallstatustype=$customhelper->getAllStatusType();
    }
	public function getPackagePdfAction(){
		require_once 'library/tcpdf/tcpdf.php';
		// create new PDF document
		$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
		// set document information
		$pdf->SetCreator(PDF_CREATOR);
		$pdf->SetAuthor('TripsBank');
		$pdf->SetTitle('Package Report');
		$pdf->SetSubject('Package Report');
		$pdf->SetKeywords('TCPDF, PDF, package, tripsbank, proposal');
		// set default header data
		//$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
		// set header and footer fonts
		$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
		$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
		// set default monospaced font
		$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
		// set margins
		$pdf->SetMargins(10, 10, 10, true);
		//$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
		$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
		$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
		// set auto page breaks
		$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
		// set image scale factor
		$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
		// set some language-dependent strings (optional)
		if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
		require_once(dirname(__FILE__).'/lang/eng.php');
		$pdf->setLanguageArray($l);
		}
		// ---------------------------------------------------------
		// set font
		//$pdf->SetFont('helvetica', 'B', 10);
		// add a page
		$pdf->AddPage();
		//$pdf->Write(0, 'Total Purchase report', '', 0, 'L', true, 1, false, false, 0);
		//$pdf->SetFont('helvetica', '', 10);
		// -----------------------------------------------------------------------------
		// Table with rowspans and THEAD
/*		$tbl = <<<EOD
		EOD;
*/		$html = new Zend_View();
		$html->setScriptPath(APPLICATION_PATH . '/views/scripts/proposal/');
		//$html->assign('customerDetails', $getCustomerDetail);
		$bodyText = $html->render('pdf-package.phtml');
		$pdf_folder_path= 'public/pdf/package/'; // path to save the generated PDF
		$pdf->writeHTML($bodyText, true, false, false, false, '');
		// -----------------------------------------------------------------------------
		ob_end_clean();
		//Close and output PDF document
		$pdf->Output($pdf_folder_path.'package.pdf', 'F'); // for save direct in folder
		//$pdf->Output('test.pdf', 'I'); // for direct open
		//$pdf->Output('test.pdf', 'D'); // for select to save or open
		ob_end_flush();
		echo "Pdf Sent Successfully";
		exit;
		//============================================================+
		// END OF FILE
		//============================================================+
	}
	public function createPackagePdfAction(){
		$this->_helper->layout->disableLayout();
		$TPSysId = $this->_HtmlPurifier->filter($this->_request->getParam('pid'));
		$TPSysId = base64_decode($TPSysId);
        if ($TPSysId > 0) {
			$objPackage = new Travel_Model_TblPackage();
            $flexiPackageList = $objPackage->getFlexiPackageList($TPSysId);
			if(!empty($flexiPackageList)){
			$flexiPackageItenList = $objPackage->getFlexiPackageItenList($TPSysId);
           // $this->view->flexiPackageList = $flexiPackageList;
			$inclusionMastArray=$objPackage->getPackageInclusionListOrderById();
			//echo "<pre>";print_r($flexiPackageList);die;
		    $inclusionArr = $objPackage->getMasking($flexiPackageList['InclMask'], $inclusionMastArray, 'InclId');
			$flexiPackageList['inclusionDetails']=$inclusionArr;
		   // echo "<pre>";print_r($inclusionArr);die;
			
			//get hotel details
			$hotelarr = $objPackage->getFlexiPackageFinalHotels($TPSysId);
			
			//for tnc details
            $packageTncList = $objPackage->getPackageTncList($TPSysId);
			
			//for agency details
			$crmcustomerObj = new Travel_Model_CRM_Customer();
			$getAgencyDetail=$crmcustomerObj->GetAgencyDetailById($flexiPackageList['AgencySysId']);
			
			// for agent/supplier details 
			//$objAgencyStaff   =	new Travel_Model_TblAgencyStaff();
			//$agentDetail=$objAgencyStaff->getUserDetailsById($flexiPackageList['SupplierSysId']);
			$objSupplier = new Travel_Model_TblSupplier();
			$supplierDetails=$objSupplier->getSupplierById($flexiPackageList['SupplierSysId']);
			
			//echo "<pre>";print_r($supplierDetails);die;
			
			$flexiPackageList['agencyDetails']=$getAgencyDetail;
			$flexiPackageList['tncDetails']=$packageTncList;
			$flexiPackageList['supplierDetails']=$supplierDetails;
			//echo "<pre>";print_r($flexiPackageList);die;
			//echo "<pre>";print_r($hotelarr);die;
			$html = new Zend_View();
			$html->setScriptPath(APPLICATION_PATH . '/views/scripts/proposal/');
			$html->assign('flexiPackageList', $flexiPackageList);
			$html->assign('flexiPackageItenList', $flexiPackageItenList);
			$html->assign('hotelDetails', $hotelarr);
			$bodyText = $html->render('create-package-pdf.phtml');
			echo $bodyText;
			exit;
			} else {
			echo "Something went wrong"; die;	
			}
        }

	}
    public function getApiHotelRoomInfoAction() {

        $this->_helper->viewRenderer->setNoRender(true);
        $this->_helper->layout->disableLayout();

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

            $intAccomSysId = trim($this->getRequest()->getParam('intAccomSysId'));
			$price=$this->_HtmlPurifier->filter($this->getRequest()->getParam('price'));        
			$TPSysId=$this->_HtmlPurifier->filter($this->getRequest()->getParam('TPSysId')); 
			$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
			$uid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('uid')));
			$tabId=$this->getRequest()->getParam('tabId');
			$strdecode = @$this->getDec($uid);
			$travelplanObj = new Travel_Model_CRM_CustomerTravelPlan();
			$travelPlanDetail=$travelplanObj->GetTravelPlanCustomerDetails($TPSysId);       
			$strdecode=explode(':',$strdecode);
			$CRMCustSysId=$travelPlanDetail[0]['CustomerSysId'];
			if((@$strdecode[0]!=intval($CRMCustSysId)) || (@$strdecode[2]!=intval($travelPlanDetail[0]['MasterTPSysId']))){
				echo "Please try again";
				die;
			}
			$this->view->uid=$uid;
			$this->view->proposalId=$mid;
			
            $hotelSearchSession = new Zend_Session_Namespace('hotelSearchSession');
			//echo "<pre>";print_r($hotelSearchSession->hotelSearchSession[0]);
			//echo "<pre>";print_r($travelPlanDetail);
			 $travellerDetailArr=json_decode($travelPlanDetail[0]['RoomMemInfoJson'],1);
			//echo "<pre>";print_r($this->travelPlanDetail);die;
			$adultPax =0;
			$childPax =0;
			$arrMemberDetails=array();
			$getApiRooms=array();
			if(!empty($travellerDetailArr) ){
				$g=0;
				foreach($travellerDetailArr as $res){
					$adultPax += $res['adult'];
					$childPax += $res['child']['childcount'];
                    $arrMemberDetails[$g]['AdultPax'] = $res['adult'];
                    $arrMemberDetails[$g]['ChildPax'] = $res['child']['childcount'];
                    //$arrMemberDetails[$i]['NoOfChild'] = $memberDetails[$i]['ChildPax'];
                    if($res['child']['childcount'] > 0){
                        $arrChildAge = explode(",",$res['child']['childage']);
                       // $arrMemberDetails[$g]['ChildsAge'] = $arrChildAge;
                        $arrMemberDetails[$g]['ChildsAge'] = $res['child']['childage'];
                    }
					$g++;
				}
			}
			//echo "<pre>";print_r($arrMemberDetails);
            //$this->view->hotelCityTitle = $travelPlanDetail[0]['hotelCityTitle'];
			$getApiRooms['hotelTotalRooms']=count($travellerDetailArr);
			$getApiRooms['hotelTotalNights']=$travelPlanDetail[0]['hotelTotalNights'];
			$getApiRooms['hotelFromDateSession']=$travelPlanDetail[0]['hotelFromDate']->format('d-M-y');
			$getApiRooms['hotelToDateSession']=$travelPlanDetail[0]['hotelToDate']->format('d-M-y');
			$getApiRooms['selectNationality']=$travelPlanDetail[0]['Countries'];
			$getApiRooms['countryCode']=$travelPlanDetail[0]['Countries'];
			$getApiRooms['hotelXrefCityId']=$travelPlanDetail[0]['hotelXrefCityId'];
			$getApiRooms['hidden_selected_hotel_id']=$travelPlanDetail[0]['hotelXrefCityId'];
			$getApiRooms['totalMemberCount']['AdultPax']=$adultPax;
			$getApiRooms['totalMemberCount']['ChildPax']=$childPax;
			$getApiRooms['totalMemberCount']['ChildsAge']='';
			$getApiRooms['memberDetails']=$arrMemberDetails;
			$getApiRooms['hotelStarRating']=$travelPlanDetail[0]['hotelStarRating'];
			$getApiRooms['apiSourceSysId']=$travelPlanDetail[0]['ICSourceSysId'];
			$getApiRooms['strTraceId']= $strTraceId = $travelPlanDetail[0]['TraceId'];
			$getApiRooms['strHotelCode']= $strHotelCode = $travelPlanDetail[0]['ShortName'];
           
            
            //echo "<pre>"; print_r($hotelSearchSession->hotelSearchSession); exit;
            $arrResponseData = Zend_Controller_Action_HelperBroker::getStaticHelper('Hotel')->getApiHotelRoomInfo($getApiRooms);
           //echo "<pre>"; print_r($arrResponseData); die;
            
             if(!empty($arrResponseData) ){
                $this->view->strTraceId = isset($arrResponseData['search_id'])?$arrResponseData['search_id']:'';
                $this->view->strErrorMessage = !empty($arrResponseData['errors'][0]['messages'][0])?$arrResponseData['errors'][0]['messages'][0]:'';
                $this->view->arrResponseData = !empty($arrResponseData['hotels'][0]['rates'])?$arrResponseData['hotels'][0]['rates']:'';
            }else{
                $this->view->strTraceId = '';
                $this->view->strErrorMessage = 'No rooms available.';
                $this->view->arrResponseData = '';
            }


			if(isset($arrResponseData['hotels'][0]['rates']) && count($arrResponseData['hotels'][0]['rates']) > 0){
				$I=1;
				$v=0;
				$getCurrencyObj=new Travel_Model_TblCurrency();
				$getAccomRoomInfoObj=new Travel_Model_TblICAccomdationRoom();
				$updatedate=date('Y-m-d H:i:s');
			 // echo "<pre>";print_r($arrResponseData['hotels'][0]['rates']);
				foreach($arrResponseData['hotels'][0]['rates'] as $roomInfo){
			    $fetchRoomResult=$getAccomRoomInfoObj->GetAccomRoomDetail($travelPlanDetail[0]['hotelAccoSysId'],$roomInfo['rooms'][0]['room_type'],$I);
				//echo count($fetchRoomResult);die;
				if(count($fetchRoomResult)==0){
					$getCurrencyObj->strCurrencySymbol =$roomInfo['currency']; 
					$HelperCurrency = $getCurrencyObj->getCurrencyTypes();
					$CurrencyType=$HelperCurrency[0]['CurrencyType'];
					$AccomRoomInfoArray = array(
						'AccomSysId' => $travelPlanDetail[0]['hotelAccoSysId'],
						'SourceSysId' =>$travelPlanDetail[0]['ICSourceSysId'],
						'Title' => !empty($roomInfo['rooms'][0]['description'])?$roomInfo['rooms'][0]['description']:'',
						'TokenId' => $travelPlanDetail[0]['TokenId'],
						'TraceId' => $travelPlanDetail[0]['TraceId'],
						'RoomIndex' => $I,
						'Amenities'=>$arrResponseData['hotels'][0]['facilities'],
						'RoomNumber' => !empty($roomInfo['rooms'][0]['room_type'])?$roomInfo['rooms'][0]['room_type']:'',
						'Qty' => !empty($roomInfo['no_of_rooms'])?$roomInfo['no_of_rooms']:'0',
						'CurrencyType' => !empty($CurrencyType)?$CurrencyType:'',
						'PublishedFare' => !empty($roomInfo['price'])?$roomInfo['price']:'0',
						'Commission' => 0,
						'RoomType'=>0,
						'EconomyType'=>0,
						'BedType'=>0,
						'PaxCount'=>0,
						'IsPetAllow'=>0,
						'Location'=>'',
						'MaxPetAllow'=>0,
						'AllowChild'=>0,
						'AllowInfant'=>0,
						'MaxPaxCount'=>0,
						'MaxAllowChild'=>0,
						'MaxAllowInfant'=>0,
						'MealPlanType'=>0,
						'AminitiesMask'=>'',
						'InclustionOptionsMask'=>'',
						'OtherDetails' =>!empty($roomInfo['other_inclusions'])?json_encode($roomInfo['other_inclusions']):'',
						'RoomTypeCode' => !empty($roomInfo['room_code'])?$roomInfo['room_code']:'',
						'RatePlanCode' => !empty($roomInfo['rate_key'])?$roomInfo['rate_key']:'',
						'RatePlanName' => !empty($roomInfo['rate_type'])?$roomInfo['rate_type']:'',
						'CancellationPolicy' => '',
						'UpdatedDate' => $updatedate,
						'CreateDate' => $updatedate,
						'IsApproved' => 1,
						'IsActive' => 1,
						'IsDelete' => 0
					);
					//echo "<pre>";print_r($AccomRoomInfoArray);die;
					$getAccomRoomInfoObj->addAccomRoomInfo($AccomRoomInfoArray);
				} else{

					$customhelper = Zend_Controller_Action_HelperBroker::getStaticHelper('Custom');
					$currencySymbol=$customhelper->GetCurrencyTypeByCurrency($roomInfo['currency']);
					$CurrencyType=$currencySymbol['CurrencyType'];

					$AccomRoomInfoArrayUpdate = array(
						'Title' => !empty($roomInfo['rooms'][0]['description'])?$roomInfo['rooms'][0]['description']:'',
						'Amenities'=>$arrResponseData['hotels'][0]['facilities'],
						'TokenId' => $travelPlanDetail[0]['TokenId'],
						'TraceId' => $travelPlanDetail[0]['TraceId'],
						'Qty' => !empty($roomInfo['no_of_rooms'])?$roomInfo['no_of_rooms']:'0',
						'CurrencyType' => !empty($CurrencyType)?$CurrencyType:'',
						'PublishedFare' => !empty($roomInfo['price'])?trim($roomInfo['price']):'0',
						'OtherDetails' =>!empty($roomInfo['other_inclusions'][0])?$roomInfo['other_inclusions'][0]:'',
						'RoomTypeCode' => !empty($roomInfo['room_code'])?trim($roomInfo['room_code']):'',
						'RatePlanCode' => !empty($roomInfo['rate_key'])?trim($roomInfo['rate_key']):'',
						'RatePlanName' => !empty($roomInfo['rate_type'])?trim($roomInfo['rate_type']):'',
						'UpdatedDate' => $updatedate,
					);
				//echo "<pre>";print_r($AccomRoomInfoArrayUpdate);die;
					$where = "AccomSysId = " . $travelPlanDetail[0]['hotelAccoSysId']." AND RoomIndex=".$I." AND RoomNumber='".$roomInfo['rooms'][0]['room_type']."'";
					$lastId=$getAccomRoomInfoObj->updateAccomRoomInfo($AccomRoomInfoArrayUpdate,$where);
				}
					
				$I++;
				$v++;
				}
			}
            //echo $lastId.'/'.$travelPlanDetail[0]['hotelAccoSysId'];
			// For Hotel Basic Details From DB...
            $objHotel = new Travel_Model_TblBuyHotel();
            //$intAccomSysId = $objHotel->getHotelInfoByShortCode($strHotelCode,$strTraceId);exit;
            $intImagesCount = $objHotel->countApiHotelsImages(trim($strHotelCode));
            if($intImagesCount < 2){
                //Get Grn Hotel Images...
                $arrResponseData = Zend_Controller_Action_HelperBroker::getStaticHelper('Hotel')->getApiHotelRoomImages($strHotelCode);
                if($arrResponseData['errors'] == 0){
                    if(!empty($arrResponseData['images']) ){
                        $CreateDate = Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss');
                        $objHotel = new Travel_Model_TblBuyHotel();
                        $intAccomSysId = $objHotel->getHotelInfoByShortCode($strHotelCode,$strTraceId);
                        $intGTXCityId = $travelPlanDetail[0]['hotelXrefCityId'];
                        $Seq = 1;
                            foreach($arrResponseData['images'] as $imgValue){
                                $imgPath = GRN_HOTEL_IMAGES_CDN_URL."/".$imgValue['path'];

                                $imgData = array(
                                    'AccomSysId' => $intAccomSysId,
                                    'Seq' => $Seq,
                                    'ImgType' => 2,
                                    'HotelCode' => trim($strHotelCode),
                                    'CitySysId' => $intGTXCityId,
                                    'TagTitle' => 'FullImage',
                                    'Details' => $imgPath,
                                    'UpdateDate' => $CreateDate,
                                    'CreateDate' => $CreateDate,
                                    'IsActive' => 1,
                                    'IsMarkForDel' => 0,
                                );
                                $objHotel->insertApiHotelsImages($imgData);
                                $Seq++;
                            }
                        
                    }
                }
            }
            
            //Get Grn Hotel Images...
            // For Hotel Basic Details From DB...
            $this->view->AgentMarkUp= $hotelMarkUp=($travelPlanDetail[0]['hotelMarkUp']>0)?trim($travelPlanDetail[0]['hotelMarkUp']):0;
            $this->view->AgencyMarkUp=$AgencyMarkUp=($travelPlanDetail[0]['AgencyMarkUp']>0)?trim($travelPlanDetail[0]['AgencyMarkUp']):0;
            $this->view->GTXMarkUp=$GTXMarkup=($travelPlanDetail[0]['GTXMarkup']>0)?trim($travelPlanDetail[0]['GTXMarkup']):0;
            $this->view->NetCost=$NetCost=($travelPlanDetail[0]['NetCost']>0)?trim($travelPlanDetail[0]['NetCost']):0;
            $this->view->Taxes=$Taxes=($travelPlanDetail[0]['Taxes']>0)?trim($travelPlanDetail[0]['Taxes']):0;
            $this->view->XServiceTaxAmount=$XServiceTaxAmount=($travelPlanDetail[0]['XServiceTaxAmount']>0)?trim($travelPlanDetail[0]['XServiceTaxAmount']):0;
            $priceArray=array(
							  'hotelMarkUp'=>trim($travelPlanDetail[0]['hotelMarkUp']),
							  'AgencyMarkUp'=>trim($travelPlanDetail[0]['AgencyMarkUp']),
							  'GTXMarkup'=>trim($travelPlanDetail[0]['GTXMarkup']),
							  'NetCost'=>trim($travelPlanDetail[0]['NetCost']),
							  'TotalCost'=>trim($travelPlanDetail[0]['TotalCost']),
							  'XServiceTaxAmount'=>trim($travelPlanDetail[0]['XServiceTaxAmount']),
							  'GTXServiceTaxAmount'=>trim($travelPlanDetail[0]['GTXServiceTaxAmount']),
							  'AgentServiceTaxAmount'=>trim($travelPlanDetail[0]['AgentServiceTaxAmount']),
							  'AgentsCustomServiceTaxAmount'=>trim($travelPlanDetail[0]['AgentsCustomServiceTaxAmount']),
							  'Taxes'=>trim($travelPlanDetail[0]['Taxes']),
						);

            // For Hotel Basic Details From DB...
            $arrHotelDetails = $objHotel->getHotelInfoById($intAccomSysId);
            $this->view->arrHotelDetails = $arrHotelDetails;
           
            // For Hotel Basic Details From DB...
            
            
            // For Hotel Basic Details From DB...
            $arrHotelImages = $objHotel->getAccomdationImagesByAccomSysId($intAccomSysId);
            $this->view->arrHotelImages = $arrHotelImages;
            //echo "<pre>";print_r($arrHotelImages);exit;
            // For Hotel Basic Details From DB...



            //$arrHotelAminity = $objHotel->getHotelMappedAmenities($strHotelCode);
            $this->view->arrhotelAminity = [];//$arrHotelAminity;
            // For Hotel Basic Details From DB...
			$this->view->getApiRooms=$getApiRooms;
			$this->view->tabId=$tabId;
			$this->view->TPSysId=$TPSysId;
			$this->view->travelPlanDetail=$travelPlanDetail;
			$this->view->priceArray=$priceArray;
                        
            $this->render('api-room-detail-info');
            
            
        }
    }
	//for grn hotel details SourceSysID=4
    public function getApiHotelRateInfoAction() { // rechecking checking rates 
        ini_set("display_errors", 0);
        $this->_helper->viewRenderer->setNoRender(true);
        $this->_helper->layout->disableLayout();
		
        if ($this->_request->isXmlHttpRequest()) {
            
           $sessionhotelDirectSearchData = new Zend_Session_Namespace('sessionhotelDirectSearchData');
		    $sessionPreBookingHotelDetails = new Zend_Session_Namespace('sessionPreBookingHotelDetails');
           $hotelSearchSession = new Zend_Session_Namespace('hotelSearchSession');
		   $roomDetail = new Zend_Session_Namespace('roomDetail');
          // echo "<pre>";print_r($roomDetail->roomDetail);
           
           $intApiSource = trim($this->getRequest()->getParam('apiSource'));
           $cancellationPolicy = trim(base64_decode($this->getRequest()->getParam('cancellationPolicy')));
           $RoomIndex = trim($this->getRequest()->getParam('index'));
		   $TPSysId=$this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('tpid')));
		   
		   $travelPlanDetail=$this->_crmcusttravelplan->GetTravelPlanCustomerDetails($TPSysId); 
		   $getCurrencyObj=new Travel_Model_TblCurrency();
		   //echo "<pre>";print_r($HelperCurrency);
           $strTraceId = trim($this->getRequest()->getParam('strTraceId'));
           $strRoomRateKey = trim($this->getRequest()->getParam('strRoomRateKey'));
           $strRoomGroupCode = trim($this->getRequest()->getParam('strRoomGroupCode'));
           
           $data = array(
                        "apiSource"         => $intApiSource,
                        "strTraceId"        => $strTraceId,
                        "strRoomRateKey"    => $strRoomRateKey,
                        "strRoomGroupCode"  => $strRoomGroupCode,
						"strCheckInDate" => $travelPlanDetail[0]['hotelFromDate']->format('Y-m-d'),
						"strCheckOutDate" => $travelPlanDetail[0]['hotelToDate']->format('Y-m-d')
                    );
           
           $arrResponseData = Zend_Controller_Action_HelperBroker::getStaticHelper('Hotel')->getApiHotelRateInfo($data);
		   $sessionPreBookingHotelDetails->params =  $arrResponseData;
		   $arrResponseData['HOTELAPITYPE']='GRN';
      	   //echo "<pre>";print_r($arrResponseData);die;


           if(count($arrResponseData > 0) && empty($arrResponseData['ERROR']['MESSAGE'])){


		   $arrayHotel=array();
		   $arrayHotelRoomInfo=array();
		   $arrayHotel['hotelInfo']['HotelInfoResult']['ResponseStatus']=$arrResponseData['ERROR']['CODE'];
		   $arrayHotel['hotelInfo']['HotelInfoResult']['Error']['ErrorCode']=$arrResponseData['ERROR']['CODE'];
		   $arrayHotel['hotelInfo']['HotelInfoResult']['Error']['ErrorMessage']=$arrResponseData['ERROR']['MESSAGE'];
		   $arrayHotel['hotelInfo']['HotelInfoResult']['TraceId']='';
		  // $arrayHotel['hotelInfo']['HotelInfoResult']['HotelDetails']=$arrResponseData['ERROR']['MESSAGE'];
		   $arrayHotel['hotelInfo']['HotelInfoResult']['HotelDetails']['HotelCode']=$arrResponseData['HOTELINFO']['HOTEL_CODE'];
		   $arrayHotel['hotelInfo']['HotelInfoResult']['HotelDetails']['HotelName']=$arrResponseData['HOTELINFO']['HOTEL_NAME'];
		   $arrayHotel['hotelInfo']['HotelInfoResult']['HotelDetails']['StarRating']='';
		   $arrayHotel['hotelInfo']['HotelInfoResult']['HotelDetails']['HotelURL']=$arrResponseData['HOTELINFO']['HOTEL_IMAGE'];
		   $arrayHotel['hotelInfo']['HotelInfoResult']['HotelDetails']['Description']=$arrResponseData['HOTELINFO']['HOTEL_DESC'];
		   $arrayHotel['hotelInfo']['HotelInfoResult']['HotelDetails']['HotelPolicy']='';
		   $arrayHotel['hotelInfo']['HotelInfoResult']['HotelDetails']['SpecialInstructions']='';
		   $arrayHotel['hotelInfo']['HotelInfoResult']['HotelDetails']['Address']=$arrResponseData['HOTELINFO']['HOTEL_ADDRESS'];
		   $arrayHotel['hotelInfo']['tpid']=$hotelSearchSession->hotelSearchSession[0]['TPSysId'];
		   $arrayHotel['hotelInfo']['HotelInfoResult']['hotelRoomD']['GetHotelRoomResult']['ResponseStatus']=$arrResponseData['ERROR']['MESSAGE'];
		   
		   $arrayHotelRoomInfo['Price']['RoomPriceWithMarkUp']=$arrResponseData['ROOMPRICE']['PRICE'];;
		   $arrResponseData['Price']['RoomPriceDb']=$travelPlanDetail[0]['NetCost'];
		   $arrayHotelRoomInfo['ChildCount']=$arrResponseData['ROOMINFO']['NO_OF_CHILD'];
		   $arrayHotelRoomInfo['RoomTypeName']=$arrResponseData['ROOMINFO']['ROOM_DESC'];
		   $arrayHotelRoomInfo['Amenities'][0]=$arrResponseData['ROOMINFO']['ROOM_INCLUSIONS'];
		   $arrayHotelRoomInfo['CancellationPolicy']=$arrResponseData['ROOMCANCELATIONS']['TAX_INFO'];
		   $arrayHotelRoomInfo['CancellationPolicies']=$arrResponseData['ROOMCANCELATIONS']['POLICY'];
		   $arrayHotelRoomInfo['CancellationPolicies'][0]['FromDate']=$arrResponseData['ROOMCANCELATIONS']['POLICY']['details'][0]['from'];
		   $arrayHotelRoomInfo['CancellationPolicies'][0]['ToDate']=@$arrResponseData['ROOMCANCELATIONS']['POLICY']['details'][0]['to'];
		   $selectedroomDetails = new Zend_Session_Namespace('selectedroom_hotelinfo');
		   $selectedroomDetails->selectedroom_hotelinfo=$arrayHotelRoomInfo;
		   //echo "<pre>";print_r($arrResponseData['ROOMCANCELATIONS']);die;
           if($intApiSource == '4'){
			  $cancellationPolicyDecode=json_decode($cancellationPolicy,true);
			 // print_r($cancellationPolicyDecode);
			 // $chargeType=(isset($cancellationPolicyDecode[0]['percent']) && !empty($cancellationPolicyDecode[0]['percent']))?2:1;
			  $chargeType=(isset($arrResponseData['ROOMCANCELATIONS']['POLICY']['details'][0]['percent']) && ($arrResponseData['ROOMCANCELATIONS']['POLICY']['details'][0]['percent'] > 0))?2:1;
			  $getCurrencyObj->strCurrencySymbol =isset($arrResponseData['ROOMCANCELATIONS']['POLICY']['details'][0]['currency'])?$arrResponseData['ROOMCANCELATIONS']['POLICY']['details'][0]['currency']:''; 
			  $HelperCurrency = $getCurrencyObj->getCurrencyTypes();
			  //echo "<pre>";print_r($HelperCurrency);die;
			  $Currency=$HelperCurrency[0]['CurrencyType'];
			  $Charge=isset($arrResponseData['ROOMCANCELATIONS']['POLICY']['details'][0]['flat_fee'])?$arrResponseData['ROOMCANCELATIONS']['POLICY']['details'][0]['flat_fee']:0;
			  $Fromdate=(isset($arrResponseData['ROOMCANCELATIONS']['POLICY']['details'][0]['from']) && !empty($arrResponseData['ROOMCANCELATIONS']['POLICY']['details'][0]['from']))?date('Y-m-d H:i:s',strtotime($arrResponseData['ROOMCANCELATIONS']['POLICY']['details'][0]['from'])):'';
			  $Todate='';
			  $ItemSysId=0;
              $strApiSource = "GRN";
           }else{
			  $strApiSource = "TBO";
           }

 		   $roomDetail->roomDetail=$arrayHotel;
		   //print_r($arrResponseData['ROOMCANCELATIONS']['POLICY']);
			   //add/edit cancellation policy
			   $HotelNorms=$arrResponseData['ROOMINFO']['ROOM_INSTRUCTIONS_SPL'];
			   $RoomType=$arrResponseData['ROOMINFO']['ROOM_TYPE'];
			   $HotelInclusions=$arrResponseData['ROOMINFO']['ROOM_INCLUSIONS'];
			   $cancellationPolicyObj = new Travel_Model_TblICAccomdationRoomCancellationPolicy();
			   $valExistRT=$cancellationPolicyObj->ChkCancellationPolicyExist($travelPlanDetail[0]['hotelAccoSysId'],$RoomIndex);
				//update in accom selected room table
					$getAccomRoomInfoObj=new Travel_Model_TblICAccomdationRoom();
					$AccomRoomInfoArrayUpdate = array(
						'HotelNorms'=>(isset($HotelNorms) && !empty($HotelNorms))?trim($HotelNorms):'',
						'UpdatedDate' => date('Y-m-d H:i:s'),
					);
					//echo "<pre>";print_r($AccomRoomInfoArrayUpdate);
					$where = "AccomSysId = " . $travelPlanDetail[0]['hotelAccoSysId']." AND RoomIndex=".$RoomIndex." AND RoomNumber='".$RoomType."'";
					$lastId=$getAccomRoomInfoObj->updateAccomRoomInfo($AccomRoomInfoArrayUpdate,$where);
				
				//end of update in accom selected room table

				//update room index in accom table
					$where = "TPIntSysId = " . $travelPlanDetail[0]['TPIntSysId'];
					$updatetravelplan = array(
						'RoomIndex' => $RoomIndex,
						'UpdateDate' => date('Y-m-d H:i:s')
					);
					$updatetravelPlanAccom = $this->_crmcusttravelplanAccom->UpdateTravelPlanAccomData($updatetravelplan, $where);
				//end of update room index in accom table
		
			   
                if(count($valExistRT)==0){
                    if(!empty($chargeType)){
						$arrayCancelPlo=array(
							'AccoSysid'=>$travelPlanDetail[0]['hotelAccoSysId'],
							'ItemSysId'=>$ItemSysId,
							'roomindex'=>$RoomIndex,
							'ChargeType'=>$chargeType,
							'Currency'=>$Currency,
							'RoomNumber'=>$RoomType,
							'Charge'=>$Charge,
							'Fromdate'=>$Fromdate,
							'Todate'=>$Todate,
							'createdOn'=>date('Y-m-d H:i:s'),
							'UpdatedOn'=>date('Y-m-d H:i:s'),
							'IsActive'=>'1',
							'IsMarkForDel'=>'0' 
							);
							//echo "";print_r($arrayCancelPlo);
						$cancellationPolicyObj->addRoomCancellationPolicy($arrayCancelPlo);
                    }
                }else{
                    if(!empty($chargeType)){
							$arrayCancelPlo=array(
							'ItemSysId'=>$ItemSysId,
							'ChargeType'=>$chargeType,
							'Currency'=>$Currency,
							'RoomNumber'=>$RoomType,
							'Charge'=>$Charge,
							'Fromdate'=>$Fromdate,
							'Todate'=>$Todate,
							'UpdatedOn'=>date('Y-m-d H:i:s')
							);
							$whereCn="AccoSysid='".$travelPlanDetail[0]['hotelAccoSysId']."' AND roomindex='".$RoomIndex."'";
							$cancellationPolicyObj->UpdateRoomCancellationPolicy($arrayCancelPlo, $whereCn);
	                    }
                    } 
                $sessionhotelDirectSearchData->params =  $arrResponseData;
                $response = array('success' => true,'msg' => '');
                echo json_encode($response);
                exit;
               
           }else{
               $response = array('success' => false,'msg' => 'there might be some technical error:'.$arrResponseData['ERROR']['MESSAGE']);
               echo json_encode($response);
               exit;
              
           }
       
            
            
        }
    }
	//hotel detail for grn api
	public function displaySelectedRoomDetailsAction(){
		$this->view->layout()->disableLayout();
			
		$selectedroomDetails = new Zend_Session_Namespace('selectedroom_hotelinfo');
		$sessionhotelDirectSearchData = new Zend_Session_Namespace('sessionhotelDirectSearchData');
		$roomDetail = new Zend_Session_Namespace('roomDetail');
		$hotelSearchSession = new Zend_Session_Namespace('hotelSearchSession');
		//HOTELAPITYPE
		
		$planId=$hotelSearchSession->hotelSearchSession[0]['TPSysId'];
		if(isset($planId) && !empty($planId)){
			$travelplanObj = new Travel_Model_CRM_CustomerTravelPlan();
			$travelPlanDetail=$travelplanObj->GetTravelPlanCustomerDetails($planId);
			$travelPlanItenObj=new Travel_Model_CRM_CustomerTravelItenary();
			$travelPlanItenaryId=$travelPlanItenObj->GetItenaryId($planId);
			//$travelPlanAccomObj=new Travel_Model_TblCustomerTravelAccom();
			//$travelPlanAccomId=$travelPlanAccomObj->GetAccomId($travelPlanAccomObj[0]['TPIntSysId']);
			$this->view->travelPlanAccomId=$travelPlanItenaryId['TPIntSysId'];
			//echo "<pre>"; print_r($travelPlanDetail);
			$agencyStaffObj = new Travel_Model_TblAgencyStaff();
			$agentDetail=$agencyStaffObj->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
		$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
		$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1']);
		$crmcustomerObj = new Travel_Model_CRM_Customer();
		$getAgencyDetail=$crmcustomerObj->GetAgencyDetailById($AgencySysId);
		$guestDetails=$crmcustomerObj->GetCustomerWithDetails($travelPlanDetail[0]['CustomerSysId']);
		$hotelGuestDetails = new Zend_Session_Namespace('hotelGuestDetails');
		$hotelGuestDetails->hotelGuestDetails=$guestDetails;
		//echo "<pre>";print_r($guestDetails);die;
		//$guestDetails=$crmcustomerObj->GetCustomerWithDetails($travelPlanDetail[0]['CustomerSysId']);
		$agencyAddress='';	
		if(isset($getAgencyDetail['CountrySysId']) && !empty($getAgencyDetail['StateOrZoneSysId']) && !empty($getAgencyDetail['CitySysId'])){
			$agencyAddress=$crmcustomerObj->GetNameOfContStateCity($getAgencyDetail['CountrySysId'],$getAgencyDetail['StateOrZoneSysId'],$getAgencyDetail['CitySysId']);
		}
		$agencyState='';
		$agencyCountry='';
		if(isset($agencyAddress['StateName']) && !empty($agencyAddress['StateName'])){
			$agencyState=$agencyAddress['StateName']?" ,".$agencyAddress['StateName']:'';
		}
		if(isset($agencyAddress['countryName']) && !empty($agencyAddress['countryName'])){
			$agencyCountry=$agencyAddress['countryName']?"(".$agencyAddress['countryName'].")":'';
		}
		//customer detail
				$tpID=$planId;
				$CRMCustSysId=$travelPlanDetail[0]['CustomerSysId'];
				if (isset($CRMCustSysId) && !empty($CRMCustSysId)) {
			        $this->_crmcustomerObj = new Travel_Model_CRM_Customer();
					//$getCustomerDetail = $this->_crmcustomerObj->GetCustomerById($CRMCustSysId);
					$getCustomerDetail = $this->_crmcusttravelplan->GetTravelPlanCustomerDetails($tpID);
					
					//echo "<pre>";print_r($getCustomerDetail);die;
				$objAgencyUser = new Travel_Model_CRM_AgencyUserInbox();
				$checkCustomerChatExist = $getCustomerDetail[0]['CustomerSysId'] > 0? $objAgencyUser->CheckCustomerMsgCount($getCustomerDetail[0]['CustomerSysId'],$tpID):array();
				$getCustomerDetail['userChatExist']=count($checkCustomerChatExist);
				}
		//end of customer detail

		//query for get customer chat history
			$chatSenderDetails=array();
			if($getCustomerDetail['userChatExist'] > 0){
					if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
						$getChatHistoryDetail = $objAgencyUser->GetCustChatHistDetWithLead($tpID,$getCustomerDetail[0]['CustomerSysId'],'DESC');
						$this->view->chatHistoryDetail=$getChatHistoryDetail;
						$chatSenderDetails['TPSysId']=$tpID;
						$chatSenderDetails['AgencySysId']=$travelPlanDetail[0]['AgencySysId'];
						$chatSenderDetails['CRMCustSysId']=$getCustomerDetail[0]['CustomerSysId'];
						$chatSenderDetails['AgentSysId']=$travelPlanDetail[0]['AgentSysId'];
						//$chatSenderDetails['EmailId']=$getcustomerDetail[0]['EmailId'];
						$objAgencyStaff   =	new Travel_Model_TblAgencyStaff();
						$agentDetail=$objAgencyStaff->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
						$chatSenderDetails['EmailId']=$agentDetail['EmailId'];
						//print_r($agentDetail);
						
						
					}
			}
			//end of customer chat history
		$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
		$this->view->getAgentDetail=$getAgentDetail;
		$this->view->agencyDetails=$getAgencyDetail;
		$this->view->hotelInfo=$sessionhotelDirectSearchData->params;
		$this->view->hotelSearchInfo=$hotelSearchSession->hotelSearchSession;
		$this->view->guestDetail=$guestDetails;
		$this->view->selectedroom_hotelinfo=$selectedroomDetails->selectedroom_hotelinfo;
		$this->view->getcustomerDetail = $getCustomerDetail;
		$this->view->chatSenderDetails = $chatSenderDetails;
		}
	}
	//function for encryptdata created by Er amit kumar dubey on 2 february 2017 at 6:17 PM
	/*public static function getDecUser($input){
            $filter = new Zend_Filter_Decrypt(array('adapter' => 'mcrypt', 'key' => self::ENC_KEY));
            $filter->setVector(self::VECTOR);
            $decoded = pack('H*', $input);
            $decrypted = $filter->filter($decoded);
            return $decrypted;
	}	
	public static function getEncUser($input){
		$filter = new Zend_Filter_Encrypt(array('adapter' => 'mcrypt', 'key' => self::ENC_KEY));
        $filter->setVector(self::VECTOR);
        $encrypted = $filter->filter($input);
        return bin2hex($encrypted); //hints: rawurlencode(..) works
        return $encrypted;
	}*/
	public function previewHotelResultViewAction(){
		$this->_helper->layout->disableLayout();
		$proposalId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$pid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('pid')));
		$uid = $this->_HtmlPurifier->filter(base64_decode(trim($this->getRequest()->getParam('uid'))));
		$type = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('type')));
		$strdecode = $this->getDec($uid);
		if(isset($proposalId) && !empty($proposalId)){
			if(isset($type) && !empty($type)){
				$typedecode = @$this->getDec($type);
				$proposalList=$this->_crmcusttravelplan->GetPublicProposalWithHotListByStaus($proposalId,$pid);
			}else{
				$proposalList=$this->_crmcusttravelplan->GetPublicProposalWithHotListByStaus($proposalId,'');
			}
		$strdecode=explode(':',$strdecode);
		$CRMCustSysId=@$proposalList[0]['CustomerSysId'];
		if($proposalList[0]['StatusType']==17){
			$this->_redirect('/proposal/booking-confirmation/mid/'.base64_encode($proposalId).'/pid/'.base64_encode($pid).'/uid/'.base64_encode($uid).'');
			exit;
		}
		//echo $strdecode[0]."/".intval($CRMCustSysId).":".$strdecode[2]."/".intval($proposalId);
		$this->view->uid=$uid;
		
		$sessionLogin_user = new Zend_Session_Namespace('sessionLogin_user');
		//echo "<pre>";print_r($proposalList);die;
		//$sessionLogin_user->intLoggedinUserAgencySysId=$proposalList[0]['AgencySysId'];  please remove comment from this lime and comment next line to remove static data
		$sessionLogin_user->intLoggedinUserAgencySysId=$proposalList[0]['AgencySysId'];
		$objHotel = new Travel_Model_TblBuyHotel();            
      	$this->view->markupAgency=$objHotel->getAgencyMarkup($proposalList[0]['AgencySysId']);
		//$sessionLogin_user->intLoggedinUserAgencySysId='';
		//print_r($sessionLogin_user->intLoggedinUserAgencySysId);
		$this->view->proposalList=$proposalList;
		$this->view->proposalId=$proposalId;
		//$leadId=$proposalId;
		
		$leadId=$proposalList[0]['TPSysId'];
		//code for hotel modify search
				$getLeadlist = $this->_crmcusttravelplan->GetPublicPageLeadListForView($CRMCustSysId, $proposalList[0]['AgencySysId'], $leadId);	
				//echo "<pre>"; print_r($getLeadlist);die;
						if (isset($getLeadlist[0]['hotelFromDate']) && !empty($getLeadlist[0]['hotelToDate'])) {
					$fromDate = $getLeadlist[0]['hotelFromDate']->format('Y-m-d');
					$toDate = $getLeadlist[0]['hotelToDate']->format('Y-m-d');
					// input format should be 206-03-25
					$totalDays = Zend_Controller_Action_HelperBroker::getStaticHelper('DateFormat')->calculateNoOfDays($fromDate, $toDate);
				}
				
				$roomjsonarray=json_decode($getLeadlist[0]['RoomMemInfoJson'],1);
				//echo "<pre>";print_r($roomjsonarray);die;
				for ($d = 1; $d <= count($roomjsonarray); $d++) {
					$getLeadlist[0]['hotelTotalRooms'] = count($roomjsonarray);
					$getLeadlist[0]['memberDetails'][] = array('AdultPax' => $roomjsonarray[$d]['adult'], 'ChildPax' => $roomjsonarray[$d]['child']['childcount'], 'ChildsAge' => @$roomjsonarray[$d]['child']['childage']);
				}
				$getLeadlist[0]['searchType'] = 'CRMHOTELSEARCH';
				$getLeadlist[0]['TPSysId'] = $leadId;
				$getLeadlist[0]['TPIntSysId'] = isset($getLeadlist[0]['TPIntSysId'])?$getLeadlist[0]['TPIntSysId']:'';
				
				$objCity = new Travel_Model_TblCity();
				$objCity->intCityId=isset($getLeadlist[0]['hotelXrefCityId'])?$getLeadlist[0]['hotelXrefCityId']:'';
				$cityList=array();
				if($objCity->intCityId){
					$cityList = $objCity->getCityList();
				}
				$hoteltbbcityid='';
				//print_r($cityList);die;
					if(!empty($cityList) ) { 
						$hoteltbbcityid=$cityList[0]['TBBCityId'];
					}

				$getLeadlist[0]['hidden_selected_hotel_id'] = $hoteltbbcityid;
				$getLeadlist[0]['hotelFromDateSession'] = isset($getLeadlist[0]['hotelFromDate']) ? $getLeadlist[0]['hotelFromDate']->format('d-M-y') : '';
				$getLeadlist[0]['customername'] = isset($getCustomerDetail['FullName'])?$getCustomerDetail['FullName']:'';
				$getLeadlist[0]['emailID'] = isset($getCustomerDetail['EmailId'])?$getCustomerDetail['EmailId']:'';
				$getLeadlist[0]['customerId'] = $CRMCustSysId;
				$getLeadlist[0]['hotelToDateSession'] = isset($getLeadlist[0]['hotelToDate']) ? $getLeadlist[0]['hotelToDate']->format('d-M-y') : '';
				$getLeadlist[0]['hotelCountryCode'] = isset($getLeadlist[0]['Countries']) ? $getLeadlist[0]['Countries'] : '';
				$getLeadlist[0]['totalDays'] = isset($totalDays) ? $totalDays : 0;
				//echo "<pre>";print_r($getLeadlist);die;
				/*$hotelSearchSession = new Zend_Session_Namespace('hotelSearchSession');
				$hotelSearchSession->hotelSearchSession=$getLeadlist;*/
				$this->view->leadDetail=$getLeadlist;	
				//end of code for modify
				//create session for grn hotel search query

					$totalMemberCount = Zend_Controller_Action_HelperBroker::getStaticHelper('ArrayCalculation')->calculateArrayValues($getLeadlist[0]['memberDetails']);
					/*$searchData = array('hotelCityTitle' => $getLeadlist[0]['hotelCityTitle'],
						'hotelFromDateSession' => isset($getLeadlist[0]['hotelFromDate']) ? $getLeadlist[0]['hotelFromDate']->format('d-M-y') : '',
						'hotelToDateSession' => isset($getLeadlist[0]['hotelToDate']) ? $getLeadlist[0]['hotelToDate']->format('d-M-y') : '',
						'hotelTotalNights' => $getLeadlist[0]['hotelTotalNights'],
						'selectNationality' => (trim($getLeadlist[0]['hotelCountryCode'])!='')?$getLeadlist[0]['hotelCountryCode']:'IN',
						'countryCode' => (trim($getLeadlist[0]['hotelCountryCode'])!='')?$getLeadlist[0]['hotelCountryCode']:'IN',
						'leadRemark' => '',
						'customername' => isset($getCustomerDetail['FullName'])?$getCustomerDetail['FullName']:'',
						'emailID' => isset($getCustomerDetail['EmailId'])?$getCustomerDetail['EmailId']:'',
						'searchType' => $getLeadlist[0]['searchType'],
						'customerId' => $getLeadlist[0]['CustomerSysId'],
						'TPSysId' => isset($getLeadlist[0]['TPSysId'])?$getLeadlist[0]['TPSysId']:'',
						'TPIntSysId' => isset($getLeadlist[0]['TPIntSysId'])?$getLeadlist[0]['TPIntSysId']:'',
						'hotelTotalRooms' => $getLeadlist[0]['hotelTotalRooms'],
						'hotelStarRating' => $this->_HtmlPurifier->filter($this->getRequest()->getPost('selectStarRating')),
						'hotelXrefCityId' => isset($getLeadlist[0]['hotelXrefCityId'])?$getLeadlist[0]['hotelXrefCityId']:'',
						'hidden_selected_hotel_id' => isset($getLeadlist[0]['hotelXrefCityId'])?$getLeadlist[0]['hotelXrefCityId']:'',
						'totalMemberCount' => $totalMemberCount,
						'memberDetails' => $getLeadlist[0]['memberDetails']);
					//print_r($searchData);die;
					$sessionhotelDirectSearchData = new Zend_Session_Namespace('sessionHotelDirectSearchData');
					$sessionhotelDirectSearchData->params = $searchData;*/
				
				//end of grn hotel session
				
		//customer detail
				$tpID=$leadId;
				if (isset($CRMCustSysId) && !empty($CRMCustSysId)) {
			        $this->_crmcustomerObj = new Travel_Model_CRM_Customer();
					//$getCustomerDetail = $this->_crmcustomerObj->GetCustomerById($CRMCustSysId);
					$getCustomerDetail = $this->_crmcusttravelplan->GetTravelPlanCustomerDetails($tpID);
					
					//echo "<pre>";print_r($getCustomerDetail);die;
				$objAgencyUser = new Travel_Model_CRM_AgencyUserInbox();
				$checkCustomerChatExist = $getCustomerDetail[0]['CustomerSysId'] > 0? $objAgencyUser->CheckCustomerMsgCount($getCustomerDetail[0]['CustomerSysId'],$tpID):array();
				$getversiondetails = $this->_crmcusttravelplan->GetVersionInfo($tpID);
				$getCustomerDetail['userChatExist']=count($checkCustomerChatExist);
				}
		//end of customer detail

		//query for get customer chat history
			$chatSenderDetails=array();
			if($getCustomerDetail['userChatExist'] > 0){
					if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
						$getChatHistoryDetail = $objAgencyUser->GetCustChatHistDetWithLead($tpID,$getCustomerDetail[0]['CustomerSysId'],'DESC');
						$this->view->chatHistoryDetail=$getChatHistoryDetail;
						$chatSenderDetails['TPSysId']=$tpID;
						$chatSenderDetails['AgencySysId']=$getLeadlist[0]['AgencySysId'];
						$chatSenderDetails['CustomerSysId']=$getCustomerDetail[0]['CustomerSysId'];
						$chatSenderDetails['AgentSysId']=$proposalList[0]['AgentSysId'];
						//$chatSenderDetails['EmailId']=$getcustomerDetail[0]['EmailId'];
						$objAgencyStaff   =	new Travel_Model_TblAgencyStaff();
						$agentDetail=$objAgencyStaff->getUserDetailsById($proposalList[0]['AgentSysId']);
						$chatSenderDetails['EmailId']=$agentDetail['EmailId'];
						//print_r($agentDetail);
						
						
					}
			}
			//end of customer chat history
			$agencyStaffObj = new Travel_Model_TblAgencyStaff();
			$agentDetail=$agencyStaffObj->getUserDetailsById($proposalList[0]['AgentSysId']);
			$AgencySysId = $getLeadlist[0]['AgencySysId'];
			$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1']);
			$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
			$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
			$this->view->getAgentDetail=$getAgentDetail;
			$this->view->agencyDetails=$getAgencyDetail;
			$this->view->getcustomerDetail = $getCustomerDetail;
			$this->view->chatSenderDetails=$chatSenderDetails;
		}

	}
	//create new version of proposal in travelplan table created by Er Amit Kumar Dubey on 13 february 2017 at 4:00 PM
    public function saveHotelProposalAction() {

        $this->_helper->viewRenderer->setNoRender(true);
        $this->_helper->layout->disableLayout();

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

            $intAccomSysId = trim($this->getRequest()->getParam('intAccomSysId'));
			$price=$this->_HtmlPurifier->filter($this->getRequest()->getParam('price'));        
			$TPSysId=$this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('tpid'))); 
			$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('pid')));
			$uid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('uid')));
			$netChangeBasePrice = $this->_HtmlPurifier->filter(($this->getRequest()->getParam('netChangeBasePrice')));
			$netChangeBasePriceTax = $this->_HtmlPurifier->filter(($this->getRequest()->getParam('netChangeBasePriceTax')));
			$strdecode = @$this->getDec($uid);
			$travelPlanDetail=$this->_crmcusttravelplan->GetTravelPlanCustomerDetails($TPSysId);  
			//echo "<pre>";print_r($travelPlanDetail);die;
			$strdecode=explode(':',$strdecode);
			$CRMCustSysId=$travelPlanDetail[0]['CustomerSysId'];
			if((@$strdecode[0]!=intval($CRMCustSysId)) || (@$strdecode[2]!=intval($travelPlanDetail[0]['MasterTPSysId']))){
				echo "Please try again";
				die;
			}
			$this->view->uid=$uid;
			$this->view->proposalId=$mid;
			$XServiceTaxAmount=$netChangeBasePriceTax;
			$basePrice=$netChangeBasePrice;




		 //add service tax amount
			if($travelPlanDetail[0]['SupplierSysId']==3){
				$serviceTaxApiType=8;
			}else if($travelPlanDetail[0]['SupplierSysId']==4){
				$serviceTaxApiType=9;
			}else{
                            $serviceTaxApiType=9;
                        }
			//service tax for base fare
			$arrServiceTaxOnNetPayable = Zend_Controller_Action_HelperBroker::getStaticHelper('Hotel')->getApiServiceTax($basePrice,"H",$serviceTaxApiType);
			$netPriceArrayServiceTax = !empty($arrServiceTaxOnNetPayable['serviceTaxAmount'])?$arrServiceTaxOnNetPayable['serviceTaxAmount']:0;
			//service tax for GTX MarkUp
			$arrServiceTaxOnNetPayable = Zend_Controller_Action_HelperBroker::getStaticHelper('Hotel')->getApiServiceTax($travelPlanDetail[0]['GTXMarkup'],"H",$serviceTaxApiType);
			$GTXMarkupArrayServiceTax = !empty($arrServiceTaxOnNetPayable['serviceTaxAmount'])?$arrServiceTaxOnNetPayable['serviceTaxAmount']:0;
			//service tax for Agency MarkUp
			$arrServiceTaxOnNetPayable = Zend_Controller_Action_HelperBroker::getStaticHelper('Hotel')->getApiServiceTax($travelPlanDetail[0]['AgencyMarkUp'],"H",$serviceTaxApiType);
			$AgencyMarkupArrayServiceTax = !empty($arrServiceTaxOnNetPayable['serviceTaxAmount'])?$arrServiceTaxOnNetPayable['serviceTaxAmount']:0;
			//service tax for Agent MarkUp
			$arrServiceTaxOnNetPayable = Zend_Controller_Action_HelperBroker::getStaticHelper('Hotel')->getApiServiceTax($travelPlanDetail[0]['hotelMarkUp'],"H",$serviceTaxApiType);
			$MarkupArrayServiceTax = !empty($arrServiceTaxOnNetPayable['serviceTaxAmount'])?$arrServiceTaxOnNetPayable['serviceTaxAmount']:0;
		//end of service tax 
			//echo $netPriceArrayServiceTax."/".$GTXMarkupArrayServiceTax."/".$AgencyMarkupArrayServiceTax."/".$MarkupArrayServiceTax;


				//if click on confirm then changed all other proposal status to on-hold BY neeraj sir on 17 april 2017 at 6:37 PM
					$wheremaster = "MasterTPSysId = " . $mid;
					$updatetravelplan = array(
						'StatusType' => 12,
						'UpdateDate' => date('Y-m-d H:i:s')
					);
					$updatetravelPlan = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($updatetravelplan, $wheremaster);
				//end of update


			$Taxes=0;
			$totalamount=$basePrice+$travelPlanDetail[0]['hotelMarkUp']+$travelPlanDetail[0]['GTXMarkup']+$travelPlanDetail[0]['AgencyMarkUp']+$Taxes+$netPriceArrayServiceTax+$GTXMarkupArrayServiceTax+$AgencyMarkupArrayServiceTax+$MarkupArrayServiceTax;
			$createDate = date('Y-m-d H:i:s');
			$existLeadDetail = $this->_crmcusttravelplan->CheckCustomerWithLeadId($TPSysId);
			$nextVersionId=$existLeadDetail[0]['VersionId']+1;
            $data = array(
                'PlanBookingId' => $this->_HtmlPurifier->filter($travelPlanDetail[0]['PlanBookingId']),
                'MasterTPSysId' => $mid,
				'VersionId'		=> $nextVersionId,
				'SupplierSysId' => trim($travelPlanDetail[0]['SupplierSysId'])>0?trim($travelPlanDetail[0]['SupplierSysId']):4,
				'CurrencyType' => trim($travelPlanDetail[0]['CurrencyType']),
				'InventoryType' => 2,
				'CreatorSysId' => 0,
				'IsHotelFromAPI' =>$travelPlanDetail[0]['IsHotelFromAPI'],
                'AgencySysId' => $travelPlanDetail[0]['AgencySysId'],
                'AgentSysId' => $travelPlanDetail[0]['AgentSysId'],
                'IsCardChrgToCustomer' => $travelPlanDetail[0]['IsCardChrgToCustomer'],
                'StatusType' => 5,
                'PlanType' => 2,
                'CustomerSysId' => $travelPlanDetail[0]['CustomerSysId'],
				'RoomInfoJson'=>$travelPlanDetail[0]['RoomInfoJson'],
                'AdditionalReq' => $travelPlanDetail[0]['AdditionalReq'],
                'StartDate' => $travelPlanDetail[0]['StartDate']->format('Y-m-d'),
                'ValidTill' => $travelPlanDetail[0]['ValidTill']->format('Y-m-d'),
                'Cities' => $travelPlanDetail[0]['Cities'],
                'Countries' => $travelPlanDetail[0]['Countries'],
				'CreateDate' => $createDate,
				'Price' => $basePrice,
				'NetPrice' =>$totalamount,
				//'MarkUp' => $MarkupArray[$i],
				'UpdateDate' => $createDate,
                'IsActive' => 1,
                'IsAprooved' => 1,
            );
            $lastID = $this->_crmcusttravelplan->addCustomerTravelPlan($data);
            if ($lastID) {
                $travelitenary = array(
                    'TPSysId' => $lastID,
                    'AgencySysId' => $travelPlanDetail[0]['AgencySysId'],
                    'StartDate' => $createDate,
                    'IsActive' => 1,
					'Sequence' => 1,
                    'CreateDate' => $createDate,
                );

                $lasttravelitenaryID = $this->_crmcustomertravelItenary->addCustomerTravelItenary($travelitenary);
            }

            ########### End Add Data in Travel Hotel Table ###################
                $hotelData = array(
                    'TPIntSysId' => $lasttravelitenaryID,
                    'SeqId' => 1,
                    'AccoBookingId' => 0,
                    'XRefBookingId' => 0,
                    'AccoSysId' => $travelPlanDetail[0]['AccoSysId'],
					'SourceSysId' => $travelPlanDetail[0]['ICSourceSysId'],
					'SupplierSysId' => trim($travelPlanDetail[0]['SupplierSysId'])>0?trim($travelPlanDetail[0]['SupplierSysId']):4,
					'IsfromAPI' => $travelPlanDetail[0]['IsfromAPI'],
                    'Title' => $travelPlanDetail[0]['hotelCityTitle'],
                    'AgencySysId' => $travelPlanDetail[0]['AgencySysId'],
					'RoomMemInfoJson' => $travelPlanDetail[0]['RoomMemInfoJson'],
                    'CreateDate' => $createDate,
                    'UpdateDate' => $createDate,
                    'FromDate' => $travelPlanDetail[0]['hotelFromDate'],
                    'ToDate' => $travelPlanDetail[0]['hotelToDate'],
                    'TotalNights' => $travelPlanDetail[0]['hotelTotalNights'],
                    'StarRating' => $travelPlanDetail[0]['hotelStarRating'],
                    'AdultPax' => $travelPlanDetail[0]['adultsinHotel'],
                    'ChildPax' => $travelPlanDetail[0]['childsinHotel'],
                    'ChildsAge' => $travelPlanDetail[0]['hotelChildsAge'],
                    'InfantPax' => $travelPlanDetail[0]['infentinHotel'],
                    'CurrencyType' => $travelPlanDetail[0]['CurrencyType'],
                    'Discounts' => $travelPlanDetail[0]['Discounts'],
                    'Taxes' => $travelPlanDetail[0]['Taxes'],
                    'XServiceTaxAmount' => $netPriceArrayServiceTax,
                    'GTXServiceTaxAmount' => $GTXMarkupArrayServiceTax,
                    'AgentServiceTaxAmount' => $AgencyMarkupArrayServiceTax,
                    'AgentsCustomServiceTaxAmount' => $MarkupArrayServiceTax,
                    'NetCost' => $basePrice,
                    'TotalCost' => $totalamount,
					'MarkUp' => $travelPlanDetail[0]['hotelMarkUp'],
					'GTXMarkup' => $travelPlanDetail[0]['GTXMarkup'],
					'AgencyMarkUp' => $travelPlanDetail[0]['AgencyMarkUp'],
                    'PetPax' => 0,
                    'TotalPax' => $travelPlanDetail[0]['TotalPax'],
                    'XrefCityId' => $travelPlanDetail[0]['hotelXrefCityId'],
                    'IsMarkForDel' => 0,
                    'IsSelectedOnPkg' => 1,
					'IsActive' => 1,
                );

                $lastairID = $this->_crmcusttravelplanHotel->addCustomerTravelPlanHotel($hotelData);
				$uid=$travelPlanDetail[0]['CustomerSysId'].':'.$lastID.':'.$mid;
				$uid=$this->getEnc($uid);
				if(isset($lastairID) && $lastairID > 0){
					$response=array('status'=>'success','tpid'=>base64_encode($lastID),'pid'=>base64_encode($mid),'uid'=>base64_encode($uid),'redirectionURL'=>true);
				}else{
					$response=array('status'=>'failed','TPSysId'=>'');
				}
				echo json_encode($response);
            
        }
    }
    public function getCustomerDetailAction() {
        $this->view->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
        $email = $this->_HtmlPurifier->filter($this->_request->getParam('emailID'));
        $mobilenum = $this->_HtmlPurifier->filter($this->_request->getParam('mobilenum'));
        $CRMCustSysId = $this->_HtmlPurifier->filter(base64_decode($this->_request->getParam('CRMCustSysId')));
        $AgencySysId = $this->_HtmlPurifier->filter(base64_decode($this->_request->getParam('AgencySysId')));
        //echo $mobilenum;
		if(isset($email) && !empty($email)){
	       $customerDetails = $this->_crmcustomerObj->ChkEmailWithResponse($email,$AgencySysId);
		}
		if(isset($mobilenum) && !empty($mobilenum)){
	       $customerDetails = $this->_crmcustomerObj->ChkMobileWithResponse($mobilenum,$AgencySysId,'',$CRMCustSysId);
		}
        if ($customerDetails) {
            $status = 'success';
        } else {
            $status = 'failure';
        }
        $detail['status'] = $status;
        //$detail['customerDetails']=$customerDetails;
        $detail['CustomerSysId'] = (isset($customerDetails['CustomerSysId']) && !empty($customerDetails['CustomerSysId'])) ? base64_encode($customerDetails['CustomerSysId']) : '';
        $detail['CRMCustSysId'] = (isset($customerDetails['CRMCustSysId']) && !empty($customerDetails['CRMCustSysId'])) ? base64_encode($customerDetails['CRMCustSysId']) : '';
        echo json_encode($detail);
    }
	//function used when message sent to customer chat
    public function sendEmailToAgentAction() {
        $this->_helper->layout->disableLayout();
        $result = '';
        if ($this->getRequest()->isPost()) {
            $this->_agencyuserObj = new Travel_Model_CRM_AgencyUserInbox();
            $TPSysId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('planId')));
            $SenderSysId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('senderId')));
            $RcvSysId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('recieverId')));
            $AgencySysId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('agencyId')));
            $emailid = $this->_HtmlPurifier->filter($this->getRequest()->getParam('emailid'));
            $isAgent = $this->_HtmlPurifier->filter($this->getRequest()->getParam('isAgent'));
            $message = $this->getRequest()->getParam('message');
            $message = $this->_HtmlPurifier->filter($message);
            if (isset($isAgent) && !empty($isAgent)) {
                $isAgent = 1;
            } else {
                $isAgent = 0;
            }
            // query for insert data in db created by amit kumar dubey on 16 august 2016 at 12:40 PM
            $date = date('Y-m-d H:i:s');
            $messageArray = array(
                'ModuleType' => 1,
                'RefSysId' => $TPSysId,
                'SenderSysId' => $SenderSysId,
                'UserSysId' => $RcvSysId,
                'AgencySysId' => $AgencySysId,
                'Message' => addslashes($message),
                'MsgType' => 1,
                'isAgent' => $isAgent,
                'Accepted' => 0,
                'Rejected' => 0,
                'RejectReason' => 0,
                'OtherInfo' => 0,
                'UpdateDate' => $date,
                'CreatedDate' => $date,
                'IsActive' => 1,
                'IsMarkForDel' => '0'
            );
            $customerRcord = $this->_agencyuserObj->addNotification($messageArray);
            //return $customerRcord; 
            $result = "success";
            // update notification in travel plan is viewd
            $where = "TPSysId = " . $TPSysId;
            $this->_crmcusttravelplan = new Travel_Model_CRM_CustomerTravelPlan();
            $data = array(
                'UpdateDate' => date('Y-m-d H:i:s'),
                'isPlanViewed' => 0
            );
            $updateViewdInCustomerTravelPlan = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($data, $where);
            //end of notification
            //send email to agent for notify
			$travelPlanDetail=$this->_crmcusttravelplan->GetTravelPlanCustomerDetails($TPSysId); 
			//echo "<pre>";print_r($travelPlanDetail); die;
			$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
			$AgentSysId = $travelPlanDetail[0]['AgentSysId'];
			$getAgentDetail = $this->_crmcusttravelplan->getAgentDetails($AgentSysId);
			$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
			$link='';
			$title='';
			$startDate='';
			$validTill='';
			$type='preview';
			$uid=$travelPlanDetail[0]['CustomerSysId'].':'.$travelPlanDetail[0]['TPSysId'].':'.$travelPlanDetail[0]['MasterTPSysId'];
			$uid=base64_encode($this->getEnc($uid));
			
			$returndate='';
			$departuredate='';
			$paxTOtalArr = json_decode($travelPlanDetail[0]['RoomInfoJson']);
			if(count($paxTOtalArr) > 0){
					foreach ($paxTOtalArr as $PaxTotal) {
							$departuredate=@$PaxTotal->departuredate;
							$returndate=trim(@$PaxTotal->returndate);
					}
			}
			
			if($travelPlanDetail[0]['PlanType']==1){
				$link=$this->view->baseUrl("/proposal-flight-booking/flight-booking-view/mid/".base64_encode($travelPlanDetail[0]['MasterTPSysId'])."/pid/".base64_encode($travelPlanDetail[0]['TPSysId'])."/uid/".base64_encode($uid)."/type/".base64_encode($type));
				$title=trim(stripslashes($travelPlanDetail[0]['hotelCityTitle']));
				$startDate=$travelPlanDetail[0]['hotelFromDate'];
				$validTill=$travelPlanDetail[0]['hotelToDate'];
			}
			if($travelPlanDetail[0]['PlanType']==2){
				$link=$this->view->baseUrl("/proposal/preview-hotel-result/mid/".base64_encode($travelPlanDetail[0]['MasterTPSysId'])."/pid/".base64_encode($travelPlanDetail[0]['TPSysId'])."/uid/".base64_encode($uid)."/type/".base64_encode($type));
				$title=trim(stripslashes($travelPlanDetail[0]['hotelCityTitle']));
				$startDate=$travelPlanDetail[0]['hotelFromDate'];
				$validTill=$travelPlanDetail[0]['hotelToDate'];
			}
			if($travelPlanDetail[0]['PlanType']==5){
                                $secureCode = Catabatic_ValidateCustomer::secureCode(base64_encode($travelPlanDetail[0]['TPSysId']),1);
				$link=$this->view->baseUrl("/publicpackage/view-customer-final-package/id/".base64_encode($travelPlanDetail[0]['TPSysId']).'/code/'.$secureCode);
				$title=trim(stripslashes($travelPlanDetail[0]['Title']));
				$startDate=$travelPlanDetail[0]['StartDate'];
				$validTill=$travelPlanDetail[0]['ValidTill'];
			}
			if($travelPlanDetail[0]['PlanType']==6){//for visa
				$link=$this->view->baseUrl("/proposal/booking-visa-review-customer/mid/".base64_encode($travelPlanDetail[0]['MasterTPSysId'])."/tpid/".base64_encode($travelPlanDetail[0]['TPSysId']));
				$title=trim(stripslashes($travelPlanDetail[0]['Title']));
				$departuredate=explode("/",$departuredate);
				$departuredate_res=$departuredate[2]."-".$departuredate[1]."-".$departuredate[0];
				$startDate = new DateTime($departuredate_res);
				$validTill='';
			}
			if($travelPlanDetail[0]['PlanType']==7){ // for forex
				$link=$this->view->baseUrl("/proposal/booking-forex-review-customer/mid/".base64_encode($travelPlanDetail[0]['MasterTPSysId'])."/tpid/".base64_encode($travelPlanDetail[0]['TPSysId']));
				$title=trim(stripslashes($travelPlanDetail[0]['Title']));
				$departuredate=explode("/",$departuredate);
				$departuredate_res=$departuredate[2]."-".$departuredate[1]."-".$departuredate[0];
				$startDate = new DateTime($departuredate_res);
				$validTill='';
			}
			if($travelPlanDetail[0]['PlanType']==8){ // for activity
				$link=$this->view->baseUrl("/proposal/booking-activity-review-customer/mid/".base64_encode($travelPlanDetail[0]['MasterTPSysId'])."/tpid/".base64_encode($travelPlanDetail[0]['TPSysId']));
				$title=trim(stripslashes($travelPlanDetail[0]['Title']));
				$departuredate=explode("/",$departuredate);
				$departuredate_res=$departuredate[2]."-".$departuredate[1]."-".$departuredate[0];
				$startDate = new DateTime($departuredate_res);
				$validTill='';
			}
			if($travelPlanDetail[0]['PlanType']==9){ // for sigtseeing
				$link=$this->view->baseUrl("/proposal/booking-sightseeing-review-customer/mid/".base64_encode($travelPlanDetail[0]['MasterTPSysId'])."/tpid/".base64_encode($travelPlanDetail[0]['TPSysId']));
				$title=trim(stripslashes($travelPlanDetail[0]['Title']));
				$departuredate=explode("/",$departuredate);
				$departuredate_res=$departuredate[2]."-".$departuredate[1]."-".$departuredate[0];
				$startDate = new DateTime($departuredate_res);
				$validTill='';
			}
			$emailSendId=trim($getAgentDetail['EmailId']);
			$fromName=(isset($getAgencyDetail['DisplayName']) && !empty($getAgencyDetail['DisplayName']))?trim($getAgencyDetail['DisplayName']):trim(trim($getAgencyDetail['Title']));
            if ($isAgent==1) {
	   			$emailId = trim($travelPlanDetail[0]['EmailId']);
				$html = new Zend_View();
				$html->setScriptPath(APPLICATION_PATH . '/views/scripts/customer/');
				//$URL='cid:'.$agencyCustomerDetails['CustomerSysId']."@@"."aid:".$agencysysID;
				//$encryptData=$this->getEnc($URL);
				$html->assign('type', 'SendEmailToCustomer');
				$html->assign('data', $travelPlanDetail);
				$html->assign('agentDetails',$getAgentDetail);
				$html->assign('link',$link);
				$html->assign('StartDate',$startDate);
				$html->assign('ValidTill',$validTill);
				$html->assign('Title',$title);
				$html->assign('message',trim($message));
				$html->assign('agencyDetails',$getAgencyDetail);
				$bodyText = $html->render('email-template.phtml');
         } else {
				$emailId = trim($getAgentDetail['EmailId']);
				$html = new Zend_View();
				$html->setScriptPath(APPLICATION_PATH . '/views/scripts/customer/');
				//$URL='cid:'.$agencyCustomerDetails['CustomerSysId']."@@"."aid:".$agencysysID;
				//$encryptData=$this->getEnc($URL);
				$html->assign('type', 'SendEmailToAgent');
				$html->assign('data', $travelPlanDetail);
				$html->assign('Title',$title);
				$html->assign('agentDetails',$getAgentDetail);
				$html->assign('link',$link);
				$html->assign('StartDate',$startDate);
				$html->assign('ValidTill',$validTill);
				$html->assign('message',trim($message));
				$html->assign('agencyDetails',$getAgencyDetail);
				$bodyText = $html->render('email-template.phtml');

				//$bodyText = "New message recieved from Customer(".trim($travelPlanDetail[0]['EmailId']).") : " ;
	        }
			//$emailId = 'amit.k@catpl.co.in';
			$bodyText = $bodyText;
			$emailData = array('fromEmail'=>$emailSendId,'fromName'=>$fromName,'subject'=>'Proposal Message Recieved','to'=>array(trim($emailId)),'bodyHtml'=>$bodyText,'bodyText'=>'');
            try {
                //echo "success";
				$arrEmailStatisticsType = array_keys(unserialize(ARR_EMAIL_STATISTICS_TYPE));
				$arrEmailStatistics = array(
					"TPSysId" => $travelPlanDetail[0]['TPSysId'],
					"TypeSysId" => 1,  // 1 For Email 2 For SMS
					"AgencySysId" => $travelPlanDetail[0]['AgencySysId'],
					"AgentSysId" => $travelPlanDetail[0]['AgentSysId'],
					"Title" => $bodyText,
					"Source" => $arrEmailStatisticsType[2], // 7 For Misc
					"Status" => 0,
					"RefSysId" => "",
					"RefSysStatus" => "",
					"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
				);
                $this->mailSentByElastice($emailData,$arrEmailStatistics);
                "success";
            } catch (Exception $err) {
                print_r($err, true);
                "failed";
            }
            //end of send email to agent
        }
        $status = array('response' => $result);
        return $this->_helper->json($status);
    }
	
	public function getSentSmsDetailsApiAction(){
		 $this->view->layout()->disableLayout();
         $this->_helper->viewRenderer->setNoRender(true);
		$TPSysId=$this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('tpid')));	
		$this->_crmsentsmsObj=new Travel_Model_CRM_SentSms();
		$smsDetails = $this->_crmsentsmsObj->GetSentSmsDetail($TPSysId);
		if(!empty($smsDetails)){
			$smsDetails['status']='success';
			$response =  json_encode($smsDetails);
		}else{
			$smsDetails['status']='failed';
			$response =  json_encode($smsDetails);
		}
		echo $response;
		exit;
	}
	//for visa preview
	public function previewVisaResultAction(){
		$this->_helper->layout->disableLayout();
		$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		if(isset($mid) && !empty($mid)){
			$proposalList=$this->_crmcusttravelplan->GetCustomerVisaProposal($mid);
			$getCustomerDetail = $this->_crmcusttravelplan->GetTravelPlanCustomerDetails($mid);
		//print_r($proposalList);die;
		if($proposalList[0]['StatusType']==17){
			$this->_redirect('/proposal/booking-visa-confirmation/mid/'.base64_encode($mid).'/tpid/'.base64_encode($proposalList[0]['TPSysId']));
			exit;
		}
		$CustomerSysId=$getCustomerDetail[0]['CustomerSysId'];
		//query for get customer chat history
            $objAgencyUser = new Travel_Model_CRM_AgencyUserInbox();
			$getChatHistoryDetail=array();
            $checkCustomerChatExist = (@$getCustomerDetail[0]['CustomerSysId'] > 0) ? $objAgencyUser->CheckCustomerMsgCount(@$getCustomerDetail[0]['CustomerSysId'], $mid,trim($proposalList[0]['AgentSysId'])) : array();
                if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
                    $getChatHistoryDetail = $objAgencyUser->GetCustChatHistDetWithLead($mid, $getCustomerDetail[0]['CustomerSysId'], 'ASC');
				}
			$getCustomerDetail['userChatExist'] = (count($checkCustomerChatExist)>0)?count($checkCustomerChatExist):count($getChatHistoryDetail);

            //query for get customer chat history
            $chatSenderDetails = array();
			$AgentSysId = $proposalList[0]['AgentSysId'];
			$AgencySysId = $proposalList[0]['AgencySysId'];
			$getAgentDetail=$this->_crmcusttravelplan->GetAgentDetails($AgentSysId);
			$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
			$getCustomerDetail[0]['TPSysId'] = $proposalList[0]['TPSysId'];
			$getCustomerDetail[0]['AgencySysId'] = $AgencySysId;
			$getCustomerDetail[0]['AgentSysId'] = $AgentSysId;
            if($getCustomerDetail['userChatExist'] > 0) {
                if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
                    $this->view->chatHistoryDetail = $getChatHistoryDetail;
                    $chatSenderDetails['TPSysId'] = $mid;
                    $chatSenderDetails['AgencySysId'] = $intLoggedinUserAgencySysId;
                    $chatSenderDetails['CustomerSysId'] = $getCustomerDetail[0]['CustomerSysId'];
                    $chatSenderDetails['AgentSysId'] = $proposalList[0]['AgentSysId'];
                    $chatSenderDetails['EmailId'] = $getAgentDetail['EmailId'];
                    //print_r($agentDetail);
                }
            }
			//end of customer chat history
			//end of customer chat history
			$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';

			//send email to agent when customer open proposal
				$isPlanViewed=$this->_crmcusttravelplan->GetTravelPlanType($mid);
				//echo "<pre>";print_r($isPlanViewed);die;
				if($isPlanViewed['IsPlanViewed']==0){
						$emailSendId=trim($getAgencyDetail['PrimaryEmail']);
						$fromName=(isset($getAgencyDetail['DisplayName']) && !empty($getAgencyDetail['DisplayName']))?trim($getAgencyDetail['DisplayName']):trim(trim($getAgencyDetail['Title']));
						$emailId = trim($getAgentDetail['EmailId']);
							$html = new Zend_View();
							$html->setScriptPath(APPLICATION_PATH . '/views/scripts/proposal/');
							$html->assign('type', 'OtherServicesViewSendEmailToAgent');
							$html->assign('customerDetails', $getCustomerDetail);
							$html->assign('agentDetails', $getAgentDetail);
							$html->assign('agencyDetails', $getAgencyDetail);
							$link=$this->view->baseUrl("/proposal/preview-visa-result/mid/".base64_encode($mid));
							$html->assign('link',$link);
							$html->assign('data',$proposalList);
							//$html->assign('data', $hotelValues);
							$bodyText = $html->render('email-template.phtml');
							$emailData = array('fromEmail'=>trim($emailSendId),'fromName'=>trim($fromName),'subject'=>'HelloGTX - Proposal Open Alert !','to'=>array(trim($emailId)),'bodyHtml'=>$bodyText,'bodyText'=>'');
							$arrEmailStatisticsType = array_keys(unserialize(ARR_EMAIL_STATISTICS_TYPE));
							$arrEmailStatistics = array(
								"TPSysId" => $proposalList[0]['TPSysId'],
								"TypeSysId" => 1,  // 1 For Email 2 For SMS
								"AgencySysId" => $proposalList[0]['AgencySysId'],
								"AgentSysId" => $proposalList[0]['AgentSysId'],
								"Title" => $bodyText,
								"Source" => $arrEmailStatisticsType[2], // 3 For Resend proposal
								"Status" => 0,
								"RefSysId" => "",
								"RefSysStatus" => "",
								"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
							);
							$this->mailSentByElastice($emailData,$arrEmailStatistics);

						//send sms
							$mobile_no = trim($getAgentDetail['ContactNo1']);
							$updateData = new Payment_Model_Checkotp();
							//$massage = "Your Customer(".trim($getcustomerDetail[0]['Contacts']).") has just opened the proposal. Team HelloGTX";
							$params['TPSysId']=$mid;
							$params['shared_url']=$link;
							$params['AgencySysId']=$AgencySysId;
							$params['AgentSysId']=$AgentSysId;
							$shorturl_response = Zend_Controller_Action_HelperBroker::getStaticHelper('ShortUrl')->url_get($params);
							if (isset($shorturl_response['status_code']) && $shorturl_response['status_code'] == 200) {
								$link = $shorturl_response['data']['short_url'];
							}                
							$massage = "Your Customer(" . trim($getCustomerDetail[0]['FirstName']) . " " . trim($getCustomerDetail[0]['LastName']) . "-" . trim($getCustomerDetail[0]['Contacts']) . ") has just opened the proposal for " . trim(stripslashes($proposalList[0]['DestinationPlaces'])) . ",Click: " . $link . " to view and assist for finalizing.";
							$this->postFields = "";
							$this->postFields .="&method=$this->SMSMETHOD";
							$this->postFields .="&api_key=$this->SMSAPIKEY";
							$this->postFields .="&to=$mobile_no";
							$this->postFields .="&sender=$this->SMSSENDER";
							$this->postFields .="&message=$massage";
							$this->postFields .="&format=$this->SMSFORMAT";
							$postURL = $this->SMSURL;
							$arrSMSStatisticsType = array_keys(unserialize(ARR_SMS_STATISTICS_TYPE));
							$arrSMSStatistics = array(
								"TPSysId" => $mid,
								"TypeSysId" => 1,  // 1 For Email 2 For SMS
								"AgencySysId" => $proposalList[0]['AgencySysId'],
								"AgentSysId" => $proposalList[0]['AgentSysId'],
								"Title" => $massage,
								"Source" => $arrSMSStatisticsType[0], // 2 For Resend
								"Status" => 0,
								"RefSysId" => "",
								"RefSysStatus" => "",
								"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
							);

							//$resultVal = $updateData->sendSmsDetails($postURL, $this->postFields,$arrSMSStatistics);
							$resultVal['status'] = 'OK';
							if (isset($resultVal['status']) && $resultVal['status'] == 'OK') {
								$errorMessage = "";
							} else {
								$errorMessage = "Oops! Please try again";
							}
						//end of send sms

						$data = array(
							'isPlanViewed' => 1,
							'UpdateDate' => date('Y-m-d H:i:s'),
						);
						$where = "TPSysId = " . $mid;
						$updatetravelplanrecord = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($data, $where);
				}
			//#end

			
			$this->view->getAgentDetail=$getAgentDetail;
			$this->view->agencyDetails=$getAgencyDetail;
			$this->view->getcustomerDetail = $getCustomerDetail;
			$this->view->chatSenderDetails=$chatSenderDetails;
			$this->view->leadDetail=$proposalList;
			$this->view->proposalList=$proposalList;
			$this->view->mid=$mid;
			$encydataForTnc=$this->getEnc($proposalList[0]['TPSysId'].":".$proposalList[0]['AgencySysId'].":".$proposalList[0]['CustomerSysId']);
			$this->view->encid=$encydataForTnc;
		}

	}
	public function bookingVisaReviewCustomerAction(){
		$this->view->layout()->disableLayout();
		$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$TPSysId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('tpid')));
        $this->view->strRechargeNowUrl = Catabatic_Helper::getSiteUrl()."payment/payment-options";
        $this->view->strSearchPageUrl = "/buyhotel/search-results";
        $this->view->intPlanType = "6";
        $this->view->strTrxType = "V";
		if(isset($TPSysId) && !empty($TPSysId)){
			$travelPlanDetail=$this->_crmcusttravelplan->GetCustomerVisaleadDetail($TPSysId);
			
			if(@$travelPlanDetail[0]['PlanType']!= 6){
				echo "Something went wrong.";
				exit;
			}
			if($travelPlanDetail[0]['StatusType']==17 || $travelPlanDetail[0]['StatusType']==16){
				$this->_redirect('/proposal/booking-visa-confirmation/mid/'.base64_encode($mid).'/tpid/'.base64_encode($TPSysId));
				exit;
			}
			$getCustomerDetail = $this->_crmcusttravelplan->GetTravelPlanCustomerDetails($TPSysId);

			$this->view->mid=$travelPlanDetail[0]['MasterTPSysId'];
			$agencyStaffObj = new Travel_Model_TblAgencyStaff();
			$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
			$AgentSysId = $travelPlanDetail[0]['AgentSysId'];
			$getCustomerDetail[0]['TPSysId'] = $travelPlanDetail[0]['TPSysId'];
			$getCustomerDetail[0]['AgencySysId'] = $travelPlanDetail[0]['AgencySysId'];
			$getCustomerDetail[0]['AgentSysId'] = $travelPlanDetail[0]['AgentSysId'];
			$crmcustomerObj = new Travel_Model_CRM_Customer();
			$getAgencyDetail= $crmcustomerObj->GetAgencyDetailById($AgencySysId);
			$getAgentDetail = $this->_crmcusttravelplan->getAgentDetails($AgentSysId);
			$guestDetails=$crmcustomerObj->GetCustomerWithDetails($travelPlanDetail[0]['CustomerSysId']);
		
		// for wallet use
        $this->view->strReturnURL = Catabatic_Helper::getSiteUrl()."proposal/make-visa-payment/cid/".base64_encode($travelPlanDetail[0]['CustomerSysId'])."/tid/".base64_encode($travelPlanDetail[0]['TPIntSysId']);
        $this->view->strErrorURL = Catabatic_Helper::getSiteUrl()."proposal/make-visa-payment/cid/".base64_encode($travelPlanDetail[0]['CustomerSysId'])."/tid/".base64_encode($travelPlanDetail[0]['TPIntSysId']);
		$this->view->intLoggedinAgencySysId = $AgencySysId;
		$this->view->IsCardChrgToCustomer = $travelPlanDetail[0]['IsCardChrgToCustomer'];
		$this->view->intLoggedinUserAgencySysId = $AgencyUserSysId=$travelPlanDetail[0]['AgentSysId'];
		$API_SOURCE_ID=$travelPlanDetail[0]['PlanType'];
		$roomjsonarray=json_decode($travelPlanDetail[0]['RoomInfoJson'],1);
			if($API_SOURCE_ID == 6){ // 
								$strCurrencyCode = 'INR';
								$Price = $travelPlanDetail[0]['Price'];
								$intTax = $travelPlanDetail[0]['XServiceTaxAmount'];
								$this->view->intTax =  $intTax = !empty($intTax)?($intTax):0;
								$this->view->intTotalAmount =  $intTotalAmount=$Price;
								$this->view->intAgentMarkUpAmount =  $intAgentMarkUpAmount = $travelPlanDetail[0]['MarkUp'];//$markupAgency->markupAg;
								$this->view->intAgencyMarkUpAmount =  $intAgencyMarkUpAmount = $travelPlanDetail[0]['AgencyMarkUp'];//$markupAgency->markupAg;
								$this->view->intGTXMarkUpAmount =  $intGTXMarkUpAmount = 0;//$markupAgency->markupAg;
								$XServiceTaxAmount = $travelPlanDetail[0]['XServiceTaxAmount'];
								$GTXServiceTaxAmount = $travelPlanDetail[0]['GTXServiceTaxAmount'];
								$AgentServiceTaxAmount = $travelPlanDetail[0]['AgentServiceTaxAmount'];
								$AgentsCustomServiceTaxAmount = $travelPlanDetail[0]['AgentsCustomServiceTaxAmount'];
								$customDiscount = $travelPlanDetail[0]['CustomDiscount'];
								$serviceTaxOnCustomDiscount = $travelPlanDetail[0]['ServiceTaxOnCustomDiscount'];
								$DiscountVal = $travelPlanDetail[0]['DiscountVal'];
								$this->view->intGrandPayableAmount =  $intGrandPayableAmount = round(($Price+$intAgentMarkUpAmount + $intAgencyMarkUpAmount + $intGTXMarkUpAmount + $XServiceTaxAmount + $GTXServiceTaxAmount + $AgentServiceTaxAmount + $AgentsCustomServiceTaxAmount)-($DiscountVal+$customDiscount+$serviceTaxOnCustomDiscount));
								$markuparray['intAgentMarkUpAmount']=$intAgentMarkUpAmount;
								$markuparray['intAgencyMarkUpAmount']=$intAgencyMarkUpAmount;
								$markuparray['intGTXMarkUpAmount']=$intGTXMarkUpAmount;
								$markuparray['intTotalAmount']=$intTotalAmount;
								$markuparray['intTax']=$XServiceTaxAmount;
								$markuparray['GTXServiceTaxAmount']=$GTXServiceTaxAmount;
								$markuparray['AgentServiceTaxAmount']=$AgentServiceTaxAmount;
								$markuparray['AgentsCustomServiceTaxAmount']=$AgentsCustomServiceTaxAmount;
								$markuparray['Pax']=count($roomjsonarray);
								$markuparray['SupplierSourceStr']='VISA';
								$markuparray['TotalDiscount']=$travelPlanDetail[0]['DiscountVal']; //0
								$markuparray['CurrencyType']=$travelPlanDetail[0]['CurrencyType'];
								$markuparray['MarketPlaceId']=($travelPlanDetail[0]['IsB2BProposal']==1)?2:1;
						}
						//echo "<pre>";print_r($markuparray);echo "</pre>";
						$this->view->guid = $this->GUID();    
						$encryptMarkUpData=$this->getEnc(json_encode($markuparray));
						$this->view->walletCode = $this->walletCode($travelPlanDetail[0]['AgentSysId'], $this->view->guid, round($intGrandPayableAmount), $AgencySysId, $travelPlanDetail[0]['TPSysId'],$travelPlanDetail[0]['CustomerSysId'],$encryptMarkUpData);
						$this->view->securecode = $this->secureCode($AgencySysId, $this->view->guid);
						$agencyAddress='';	
						if(isset($getAgencyDetail['CountrySysId']) && !empty($getAgencyDetail['StateOrZoneSysId']) && !empty($getAgencyDetail['CitySysId'])){
							$agencyAddress=$crmcustomerObj->GetNameOfContStateCity($getAgencyDetail['CountrySysId'],$getAgencyDetail['StateOrZoneSysId'],$getAgencyDetail['CitySysId']);
						}
						$agencyState='';
						$agencyCountry='';
						if(isset($agencyAddress['StateName']) && !empty($agencyAddress['StateName'])){
							$agencyState=$agencyAddress['StateName']?" ,".$agencyAddress['StateName']:'';
						}
						if(isset($agencyAddress['countryName']) && !empty($agencyAddress['countryName'])){
							$agencyCountry=$agencyAddress['countryName']?"(".$agencyAddress['countryName'].")":'';
						}
						//end of customer detail

		//query for get customer chat history
            $objAgencyUser = new Travel_Model_CRM_AgencyUserInbox();
			$getChatHistoryDetail=array();
            $checkCustomerChatExist = (@$getCustomerDetail[0]['CustomerSysId'] > 0) ? $objAgencyUser->CheckCustomerMsgCount(@$getCustomerDetail[0]['CustomerSysId'], $TPSysId,trim($travelPlanDetail[0]['AgentSysId'])) : array();
           // $checkCustomerChatExist = (count($checkCustomerChatExist)==0)?$objAgencyUser->CheckCustomerMsgCount(@$getcustomerDetail[0]['CustomerSysId'], $tpID):$checkCustomerChatExist;
                if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
                    $getChatHistoryDetail = $objAgencyUser->GetCustChatHistDetWithLead($TPSysId, $getCustomerDetail[0]['CustomerSysId'], 'ASC');
				}
			$getCustomerDetail['userChatExist'] = (count($checkCustomerChatExist)>0)?count($checkCustomerChatExist):count($getChatHistoryDetail);
            //  $this-view->getCustomerDetails = $getcustomerDetail;
            //query for get customer chat history
            $chatSenderDetails = array();
            if($getCustomerDetail['userChatExist'] > 0) {
                if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
                    $this->view->chatHistoryDetail = $getChatHistoryDetail;
                    $chatSenderDetails['TPSysId'] = $TPSysId;
                    $chatSenderDetails['AgencySysId'] = $travelPlanDetail[0]['AgencySysId'];
                    $chatSenderDetails['CustomerSysId'] = $getCustomerDetail[0]['CustomerSysId'];
                    $chatSenderDetails['AgentSysId'] = $travelPlanDetail[0]['AgentSysId'];
                    $chatSenderDetails['EmailId'] = $getAgentDetail['EmailId'];
                    //print_r($agentDetail);
                }
            }
			//end of customer chat history
			$IsB2CSite=$getAgentDetail['IsB2CSite'];
			$IsPaymentGateway=$getAgentDetail['IsPaymentGateway'];
			//print_r($getAgentDetail);
			if(!empty($IsB2CSite) && !empty($IsPaymentGateway)){
				$this->view->strPayWithWalletUrl = Catabatic_Helper::getSiteUrl()."payment/atom-payment/customer-payment";
			}else{
				if(!empty($IsPaymentGateway)){
					$this->view->strPayWithWalletUrl = Catabatic_Helper::getSiteUrl()."payment/payment-options/customer-pay-by-agency";
				} else {
					$this->view->strPayWithWalletUrl = Catabatic_Helper::getSiteUrl()."payment/payment-options/customer-pay";
				}
			}
			//send email to agent when customer open proposal
				$isPlanViewed=$this->_crmcusttravelplan->GetTravelPlanType($mid);
				//echo "<pre>";print_r($isPlanViewed);die;
				if($isPlanViewed['IsPlanViewed']==0){
						$proposalList=$this->_crmcusttravelplan->GetCustomerVisaProposal($mid);
						//echo "<pre>";print_r($proposalList);die;
						$emailSendId=trim($getAgencyDetail['PrimaryEmail']);
						$fromName=(isset($getAgencyDetail['DisplayName']) && !empty($getAgencyDetail['DisplayName']))?trim($getAgencyDetail['DisplayName']):trim(trim($getAgencyDetail['Title']));
							//$emailId = 'amit.k@catpl.co.in';
							$emailId = trim($getAgentDetail['EmailId']);
							$html = new Zend_View();
							$html->setScriptPath(APPLICATION_PATH . '/views/scripts/proposal/');
							$html->assign('type', 'OtherServicesViewSendEmailToAgent');
							$html->assign('customerDetails', $getCustomerDetail);
							$html->assign('agentDetails', $getAgentDetail);
							$html->assign('agencyDetails', $getAgencyDetail);
							$link=$this->view->baseUrl("/proposal/booking-visa-review-customer/mid/".base64_encode($mid)."/tpid/".base64_encode($TPSysId));
							$html->assign('link',$link);
							$html->assign('data',$proposalList);
							//$html->assign('data', $hotelValues);
							$bodyText = $html->render('email-template.phtml');
							$emailData = array('fromEmail'=>trim($emailSendId),'fromName'=>trim($fromName),'subject'=>'HelloGTX - Proposal Open Alert !','to'=>array(trim($emailId)),'bodyHtml'=>$bodyText,'bodyText'=>'');
							$arrEmailStatisticsType = array_keys(unserialize(ARR_EMAIL_STATISTICS_TYPE));
							$arrEmailStatistics = array(
								"TPSysId" => $proposalList[0]['TPSysId'],
								"TypeSysId" => 1,  // 1 For Email 2 For SMS
								"AgencySysId" => $proposalList[0]['AgencySysId'],
								"AgentSysId" => $proposalList[0]['AgentSysId'],
								"Title" => $bodyText,
								"Source" => $arrEmailStatisticsType[2], // 3 For Resend proposal
								"Status" => 0,
								"RefSysId" => "",
								"RefSysStatus" => "",
								"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
							);
							$this->mailSentByElastice($emailData,$arrEmailStatistics);

						//send sms
							$mobile_no = trim($getAgentDetail['ContactNo1']);
							$updateData = new Payment_Model_Checkotp();
							//$massage = "Your Customer(".trim($getcustomerDetail[0]['Contacts']).") has just opened the proposal. Team HelloGTX";
							$params['TPSysId']=$TPSysId;
							$params['shared_url']=$link;
							$params['AgencySysId']=$proposalList[0]['AgencySysId'];
							$params['AgentSysId']=$proposalList[0]['AgentSysId'];
							$shorturl_response = Zend_Controller_Action_HelperBroker::getStaticHelper('ShortUrl')->url_get($params);
							if (isset($shorturl_response['status_code']) && $shorturl_response['status_code'] == 200) {
								$link = $shorturl_response['data']['short_url'];
							}                
							$massage = "Your Customer(" . trim($getCustomerDetail[0]['FirstName']) . " " . trim($getCustomerDetail[0]['LastName']) . "-" . trim($getCustomerDetail[0]['Contacts']) . ") has just opened the proposal for " . trim(stripslashes($proposalList[0]['DestinationPlaces'])) . ",Click: " . $link . " to view and assist for finalizing.";
							$this->postFields = "";
							$this->postFields .="&method=$this->SMSMETHOD";
							$this->postFields .="&api_key=$this->SMSAPIKEY";
							$this->postFields .="&to=$mobile_no";
							$this->postFields .="&sender=$this->SMSSENDER";
							$this->postFields .="&message=$massage";
							$this->postFields .="&format=$this->SMSFORMAT";
							$postURL = $this->SMSURL;

							$arrSMSStatisticsType = array_keys(unserialize(ARR_SMS_STATISTICS_TYPE));
							$arrSMSStatistics = array(
								"TPSysId" => $TPSysId,
								"TypeSysId" => 2,  // 1 For Email 2 For SMS
								"AgencySysId" => $proposalList[0]['AgencySysId'],
								"AgentSysId" => $proposalList[0]['AgentSysId'],
								"Title" => $massage,
								"Source" => $arrSMSStatisticsType[0], // 2 For Resend
								"Status" => 0,
								"RefSysId" => "",
								"RefSysStatus" => "",
								"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
							);

							//$resultVal = $updateData->sendSmsDetails($postURL, $this->postFields,$arrSMSStatistics);
							$resultVal['status'] = 'OK';
							if (isset($resultVal['status']) && $resultVal['status'] == 'OK') {
								$errorMessage = "";
							} else {
								$errorMessage = "Oops! Please try again";
							}
						//end of send sms

						$data = array(
							'isPlanViewed' => 1,
							'UpdateDate' => date('Y-m-d H:i:s'),
						);
						$where = "TPSysId = " . $mid;
						$updatetravelplanrecord = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($data, $where);
				}
			//#end
		$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
		$this->view->getAgentDetail=$getAgentDetail;
		$this->view->agencyDetails=$getAgencyDetail;
		$this->view->guestDetail=$guestDetails;
		$this->view->getcustomerDetail = $getCustomerDetail;
		$this->view->chatSenderDetails = $chatSenderDetails;
		$this->view->encryptMarkUpData=$encryptMarkUpData;
		$this->view->travelPlanDetail=$travelPlanDetail;


		$this->view->tpid=$TPSysId;
		$encydataForTnc=$this->getEnc($travelPlanDetail[0]['TPSysId'].":".$travelPlanDetail[0]['AgencySysId'].":".$travelPlanDetail[0]['CustomerSysId']);
		$this->view->encid=$encydataForTnc;
		} else {
			echo "Please try again";
			die;
		}
	}
    public function makeVisaPaymentAction() {
       
	   //echo "<pre>";print_r($_REQUEST);die;
        $objTrx = new Travel_Model_TblAgencyCustomerTrx();
        $intXRefTrxNo = $this->getRequest()->getParam('TrxId');
        $strTrxStatus = $this->getRequest()->getParam('status');
		$GUID=$this->getRequest()->getParam('GUID');
        $planId=$this->getRequest()->getParam('TpSysId');
		$MasterTPSysId='';
		$arrVisaPaxType = Zend_Controller_Action_HelperBroker::getStaticHelper('General')->getVisaPaxType();
		$createDate = date('Y-m-d H:i:s');
		   if($planId != ''){ //echo "HI"; exit;
            if($strTrxStatus == "success") {
			$travelplanObj = new Travel_Model_CRM_CustomerTravelPlan();
			$travelPlanDetail=$travelplanObj->GetVisaCustomerDetailsPax($planId);
			$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
			$AgentSysId = $travelPlanDetail[0]['AgentSysId'];
			//echo "<pre>";print_r($travelPlanDetail);die;
			$API_SOURCE_ID=$travelPlanDetail[0]['PlanType'];
			$MasterTPSysId=$travelPlanDetail[0]['MasterTPSysId'];
			$uid=$travelPlanDetail[0]['CustomerSysId'].':'.$planId.':'.$MasterTPSysId;
			$uid=base64_encode($this->getEnc($uid));
			$customHelper = Zend_Controller_Action_HelperBroker::getStaticHelper("Custom");
			$RoomMemInfoJson=json_decode($travelPlanDetail[0]['RoomInfoJson'],1);
			$totalPax=count($RoomMemInfoJson);
				$roominfojson=isset($travelPlanDetail[0]['RoomMemInfoJson'])?json_decode($travelPlanDetail[0]['RoomMemInfoJson'],1):array();
				$memberDetails=array();
				if(!empty($roominfojson)){
					for ($d = 1; $d <= count($roominfojson); $d++) {
						$paxType=$arrVisaPaxType[$roominfojson[$d]['PaxType']];
						$memberDetails[] = array('FirstName' => $roominfojson[$d]['FirstName'], 'LastName' => $roominfojson[$d]['LastName'], 'PaxType' => $paxType);
					}
				}
						
							if(isset($MasterTPSysId) && $MasterTPSysId > 0){	
								$whereMaste = "MasterTPSysId = " . $MasterTPSysId;
								$disableAlltravelplan = array(
									'StatusType' => 10,
									'UpdateDate' => $createDate
								);
								$disableAlltravelplan = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($disableAlltravelplan, $whereMaste);
							}
							$where = "TPSysId = " . $planId;
							$updatetravelplan = array(
								'StatusType' => 17,
								'UpdateDate' => $createDate
							);
							//echo "<pre>";print_r($updatetravelplan);die;
							$updatetravelPlan = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($updatetravelplan, $where);
							
							// update main query status created by Er Amit Kumar Dubey on 8 may 2017 at 11:23 AM
								$statusArray=$customHelper->changeQueryStatusByProposal();
								$querystatus=$statusArray[17];
								if(isset($querystatus) && !empty($querystatus)){
									$whereQuery = "TPSysId = " . $MasterTPSysId;
									$updatetravelplanquery = array(
										'StatusType' => $querystatus,
										'UpdateDate' => $createDate
									);
									$updatetravelPlanQuery = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($updatetravelplanquery, $whereQuery);
								}
								
							//update accom table with bookingid
							$where = "TPIntSysId = " . $travelPlanDetail[0]['TPIntSysId'];
							$updateQuery = array(
								'XRefVoucherNo' =>$intXRefTrxNo."/".$GUID,
								'XRefBookingId' =>$GUID,
								'UpdateDate' => $createDate
							);
							$objCurd = new Visa_Model_Visa();
							$visaQueryPrposalTravelPlanId = $objCurd->updateTable("TB_Agency_Customer_TravelPlan_Visa",$updateQuery,$where);
							$msgArray=array('status'=>'success','msg'=>'Your payment is success');
							$PAYMENT_MSG = new Zend_Session_Namespace('PAYMENT_MSG');
							$PAYMENT_MSG->PAYMENT_MSG=$msgArray;

							//send email to customer
									$html = new Zend_View();
									$html->setScriptPath(APPLICATION_PATH . '/views/scripts/proposal/');
									$agencyStaffObj = new Travel_Model_TblAgencyStaff();
									$getAgentDetail = $this->_crmcusttravelplan->getAgentDetails($AgentSysId);
									$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
									//echo "<pre>";print_r($getAgencyDetail);die;
									$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';

									$html->assign('type', 'VisaBookingPaymentConfirmationEmail');
									$html->assign('data', $travelPlanDetail);
									$html->assign('getAgentDetail',$getAgentDetail);
									$html->assign('getAgencyDetail',$getAgencyDetail);
									//$html->assign('URL', $encryptData);
									$paymentconfirmText = $html->render('email-template.phtml');
									$html->assign('type', 'VisaBookingConfirmationEmailText');
									$html->assign('data', $travelPlanDetail);
									$html->assign('getAgentDetail',$getAgentDetail);
									$html->assign('getAgencyDetail',$getAgencyDetail);
									$bookingConfirmText = $html->render('email-template.phtml');
									//$emailId ='amit.k@catpl.co.in';
									$emailId = trim($travelPlanDetail[0]['ProposalEmailTo']);
									$emailSendId = trim($getAgentDetail['EmailId']);
									$fromName = (isset($getAgencyDetail['DisplayName']) && !empty($getAgencyDetail['DisplayName'])) ? trim($getAgencyDetail['DisplayName']) : trim(trim($getAgencyDetail['Title']));
									if($emailId!=''){
										$emailData1 = array('fromEmail'=>$emailSendId,'fromName'=>$fromName,'subject'=>stripslashes($travelPlanDetail[0]['Title']).' Payment Receipt','to'=>array(trim($emailId)),'bodyHtml'=>$paymentconfirmText,'bodyText'=>'');
										$emailData2 = array('fromEmail'=>$emailSendId,'fromName'=>$fromName,'subject'=>stripslashes($travelPlanDetail[0]['Title']).' Booking Details','to'=>array(trim($emailId)),'bodyHtml'=>$bookingConfirmText,'bodyText'=>'');
										try {
											//echo "success";
											$arrEmailStatisticsType = array_keys(unserialize(ARR_EMAIL_STATISTICS_TYPE));
											$arrEmailStatistics = array(
												"TPSysId" => $planId,
												"TypeSysId" => 1,  // 1 For Email 2 For SMS
												"AgencySysId" => $travelPlanDetail[0]['AgencySysId'],
												"AgentSysId" => $travelPlanDetail[0]['AgentSysId'],
												"Title" => $paymentconfirmText,
												"Source" => $arrEmailStatisticsType[1], // 2 For Vouchers
												"Status" => 0,
												"RefSysId" => "",
												"RefSysStatus" => "",
												"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
											);
											$arrEmailStatistics2 = array(
												"TPSysId" => $planId,
												"TypeSysId" => 1,  // 1 For Email 2 For SMS
												"AgencySysId" => $travelPlanDetail[0]['AgencySysId'],
												"AgentSysId" => $travelPlanDetail[0]['AgentSysId'],
												"Title" => $bookingConfirmText,
												"Source" => $arrEmailStatisticsType[1], // 2 For Vouchers
												"Status" => 0,
												"RefSysId" => "",
												"RefSysStatus" => "",
												"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
											);
											$this->mailSentByElastice($emailData1,$arrEmailStatistics);
											$this->mailSentByElastice($emailData2,$arrEmailStatistics2);
											$msg="success";
										} catch (Exception $err) {
											//print_r($err, true);
											$msg="failed";
										}
									}
							//end of send email to customer
			} if($strTrxStatus == "failure" ){
					$where = "TPSysId = " . $planId;
					$updatetravelplan = array(
						'StatusType' => 7,
						'UpdateDate' => $createDate
					);
					$updatetravelPlan = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($updatetravelplan, $where);


					// update main query status created by Er Amit Kumar Dubey on 8 may 2017 at 11:27 AM
						$statusArray=$customHelper->changeQueryStatusByProposal();
						$querystatus=$statusArray[7];
						if(isset($querystatus) && !empty($querystatus)){
							$whereQuery = "TPSysId = " . $MasterTPSysId;
							$updatetravelplanquery = array(
								'StatusType' => $querystatus,
								'UpdateDate' => $createDate
							);
							$updatetravelPlanQuery = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($updatetravelplanquery, $whereQuery);
						}
						$msgArray=array('status'=>'failed','msg'=>'Your payment is unsuccessful'.$$this->getRequest()->getParam('error_Message'));
						$PAYMENT_MSG = new Zend_Session_Namespace('PAYMENT_MSG');
						$PAYMENT_MSG->PAYMENT_MSG=$msgArray;
						exit;
			}
		  }else{
				$msgArray=array('status'=>'failed','msg'=>'Your payment is unsuccessful Id Mismatch');
				$PAYMENT_MSG = new Zend_Session_Namespace('PAYMENT_MSG');
				$PAYMENT_MSG->PAYMENT_MSG=$msgArray;
		}
		$this->_redirect("/proposal/booking-visa-confirmation/mid/".base64_encode($MasterTPSysId)."/tpid/".base64_encode($planId));
		exit;
    }
	public function bookingVisaConfirmationAction(){
		$this->view->layout()->disableLayout();
		$proposalId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$TPSysId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('tpid')));
		$PAYMENT_MSG = new Zend_Session_Namespace('PAYMENT_MSG');
		if($TPSysId==''){
			$this->view->error=1;
			//echo "Please try again";
			//die;
		} else{
			$this->view->error=0;
		$travelPlanDetail=$this->_crmcusttravelplan->GetVisaCustomerDetailsPax($TPSysId);
		//echo "<pre>";print_r($travelPlanDetail);die;
		$CustomerSysId=$travelPlanDetail[0]['CustomerSysId'];
		$getCustomerDetail = $this->_crmcustomerObj->ChkAgencyUser($CustomerSysId);
		$AgencySysId=$travelPlanDetail[0]['AgencySysId'];
		$AgentSysId=$travelPlanDetail[0]['AgentSysId'];
		$getAgencyDetail= $this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
		$getAgentDetail = $this->_crmcusttravelplan->getAgentDetails($AgentSysId);
//echo "<pre>";print_r($getCustomerDetail);
		//customer detail
				$CustomerSysId=$travelPlanDetail[0]['CustomerSysId'];
				$getLeadlist = $this->_crmcusttravelplan->GetPurchasedPublicPageLeadList($CustomerSysId, $AgencySysId, $TPSysId);
				$API_SOURCE_ID=$travelPlanDetail[0]['PlanType'];
				$roomjsonarray=json_decode($travelPlanDetail[0]['RoomInfoJson'],1);				
				if($API_SOURCE_ID == "6"){
					$strCurrencyCode = $travelPlanDetail[0]['CurrencyType'];
					$Price = $travelPlanDetail[0]['Price'];
					$intTax = $travelPlanDetail[0]['XServiceTaxAmount'];
					$this->view->intTax =  $intTax = !empty($intTax)?($intTax):0;
					$this->view->intTotalAmount =  $intTotalAmount=$Price;
					$this->view->intAgentMarkUpAmount =  $intAgentMarkUpAmount = $travelPlanDetail[0]['MarkUp'];//$markupAgency->markupAg;
					$this->view->intAgencyMarkUpAmount =  $intAgencyMarkUpAmount = $travelPlanDetail[0]['AgencyMarkUp'];//$markupAgency->markupAg;
					$this->view->intGTXMarkUpAmount =  $intGTXMarkUpAmount = $travelPlanDetail[0]['GTXMarkup'];//$markupAgency->markupAg;
					$XServiceTaxAmount = $travelPlanDetail[0]['XServiceTaxAmount'];
					$GTXServiceTaxAmount = $travelPlanDetail[0]['GTXServiceTaxAmount'];
					$AgentServiceTaxAmount = $travelPlanDetail[0]['AgentServiceTaxAmount'];
					$AgentsCustomServiceTaxAmount = $travelPlanDetail[0]['AgentsCustomServiceTaxAmount'];
					$customDiscount = $travelPlanDetail[0]['CustomDiscount'];
					$serviceTaxOnCustomDiscount = $travelPlanDetail[0]['ServiceTaxOnCustomDiscount'];
					$this->view->intGrandPayableAmount =  $intGrandPayableAmount = round(($Price+$intAgentMarkUpAmount + $intAgencyMarkUpAmount + $intGTXMarkUpAmount + $XServiceTaxAmount + $GTXServiceTaxAmount + $AgentServiceTaxAmount + $AgentsCustomServiceTaxAmount)-($customDiscount+$serviceTaxOnCustomDiscount));
				}

		//query for get customer chat history
            $objAgencyUser = new Travel_Model_CRM_AgencyUserInbox();
			$getChatHistoryDetail=array();
            $checkCustomerChatExist = (@$getCustomerDetail[0]['CustomerSysId'] > 0) ? $objAgencyUser->CheckCustomerMsgCount(@$getCustomerDetail[0]['CustomerSysId'], $TPSysId,trim($travelPlanDetail[0]['AgentSysId'])) : array();
           // $checkCustomerChatExist = (count($checkCustomerChatExist)==0)?$objAgencyUser->CheckCustomerMsgCount(@$getcustomerDetail[0]['CustomerSysId'], $tpID):$checkCustomerChatExist;
                if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
                    $getChatHistoryDetail = $objAgencyUser->GetCustChatHistDetWithLead($TPSysId, $getCustomerDetail[0]['CustomerSysId'], 'ASC');
				}
			$getCustomerDetail['userChatExist'] = (count($checkCustomerChatExist)>0)?count($checkCustomerChatExist):count($getChatHistoryDetail);
            //query for get customer chat history
            $chatSenderDetails = array();
            if($getCustomerDetail['userChatExist'] > 0) {
                if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
                    $this->view->chatHistoryDetail = $getChatHistoryDetail;
					
                    $chatSenderDetails['TPSysId'] = $TPSysId;
                    $chatSenderDetails['AgencySysId'] = $travelPlanDetail[0]['AgencySysId'];
                    $chatSenderDetails['CustomerSysId'] = $getCustomerDetail[0]['CustomerSysId'];
                    $chatSenderDetails['AgentSysId'] = $travelPlanDetail[0]['AgentSysId'];
                    $chatSenderDetails['EmailId'] = $getAgentDetail['EmailId'];
                    //print_r($agentDetail);
                }
            }
			            //echo "<pre>";print_r($chatSenderDetails);

			//end of customer chat history
			$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
			$getCustomerDetail[0]['TPSysId'] = $travelPlanDetail[0]['TPSysId'];
			$getCustomerDetail[0]['AgencySysId'] = $travelPlanDetail[0]['AgencySysId'];
			$getCustomerDetail[0]['AgentSysId'] = $travelPlanDetail[0]['AgentSysId'];
			$this->view->getAgentDetail=$getAgentDetail;
			$this->view->agencyDetails=$getAgencyDetail;
			$this->view->travelPlanDetail=$travelPlanDetail;
			$this->view->getcustomerDetail = $getCustomerDetail;
			$this->view->chatSenderDetails = $chatSenderDetails;
			$encydataForTnc=$this->getEnc($travelPlanDetail[0]['TPSysId'].":".$travelPlanDetail[0]['AgencySysId'].":".$travelPlanDetail[0]['CustomerSysId']);
			$this->view->encid=$encydataForTnc;
		}
		//echo "<pre>";print_r($travelPlanDetail);die;
		$this->view->PAYMENT_MSG=$PAYMENT_MSG->PAYMENT_MSG;
   }
    public function visaVoucherAction() {
        $this->_helper->layout->disableLayout();
		$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$TPSysId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('pid')));
		if($TPSysId==''){
			echo "Please try again";
			die;
		}
		$travelPlanDetail=$this->_crmcusttravelplan->GetVisaCustomerDetailsTrx($TPSysId);
		$CustomerSysId=$travelPlanDetail[0]['CustomerSysId'];
		$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
		$AgentSysId = $travelPlanDetail[0]['AgentSysId'];
		$getAgencyDetail= $this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
		$getAgentDetail = $this->_crmcusttravelplan->getAgentDetails($AgentSysId);
		$this->view->getAgentDetail=$getAgentDetail;
		$this->view->getAgencyDetail=$getAgencyDetail;
		$this->view->travelPlanDetail=$travelPlanDetail;
   }
    public function visaInvoiceAction() {
        $this->_helper->layout->disableLayout(); 
		$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$TPSysId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('pid')));
		if($TPSysId==''){
			echo "Please try again";
			die;
		}
		$travelPlanDetail=$this->_crmcusttravelplan->GetVisaCustomerDetailsTrx($TPSysId);
		$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
		$AgentSysId = $travelPlanDetail[0]['AgentSysId'];
		$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
		$getAgentDetail = $this->_crmcusttravelplan->getAgentDetails($AgentSysId);
		//$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
		$this->view->getAgentDetail=$getAgentDetail;
		$this->view->getAgencyDetail=$getAgencyDetail;
		$this->view->travelPlanDetail=$travelPlanDetail;
    }
    public function visaViewAction() {
       	$this->_helper->layout->disableLayout(); 
		$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$TPSysId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('pid')));
		if($TPSysId==''){
			echo "Please try again";
			die;
		}

		$travelPlanDetail=$this->_crmcusttravelplan->GetVisaCustomerDetailsTrx($TPSysId);
		//customer detail
		$AgencySysId=$travelPlanDetail[0]['AgencySysId'];
		$AgentSysId=$travelPlanDetail[0]['AgentSysId'];
		$getAgencyDetail= $this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
		$getAgentDetail = $this->_crmcusttravelplan->getAgentDetails($AgentSysId);
		$CustomerSysId=$travelPlanDetail[0]['CustomerSysId'];

				if (isset($CustomerSysId) && !empty($CustomerSysId)) {
			        $this->_crmcustomerObj = new Travel_Model_CRM_Customer();
					$getCustomerDetail = $this->_crmcusttravelplan->GetTravelPlanCustomerDetails($TPSysId);
					$objAgencyUser = new Travel_Model_CRM_AgencyUserInbox();
					$checkCustomerChatExist = $getCustomerDetail[0]['CustomerSysId'] > 0? $objAgencyUser->CheckCustomerMsgCount($getCustomerDetail[0]['CustomerSysId'],$TPSysId):array();
					$getversiondetails = $this->_crmcusttravelplan->GetVersionInfo($TPSysId);
					$getCustomerDetail['userChatExist']=count($checkCustomerChatExist);
				}
		//end of customer detail
		//query for get customer chat history
			$chatSenderDetails=array();
			if($getCustomerDetail['userChatExist'] > 0){
					if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
						$getChatHistoryDetail = $objAgencyUser->GetCustChatHistDetWithLead($TPSysId,$getCustomerDetail[0]['CustomerSysId'],'ASC');
						$this->view->chatHistoryDetail=$getChatHistoryDetail;
						$chatSenderDetails['TPSysId']=$TPSysId;
						$chatSenderDetails['AgencySysId']=$AgencySysId;
						$chatSenderDetails['CustomerSysId']=$travelPlanDetail[0]['CustomerSysId'];
						$chatSenderDetails['AgentSysId']=$AgentSysId;
						//$chatSenderDetails['EmailId']=$getcustomerDetail[0]['EmailId'];
						$chatSenderDetails['EmailId']=$getAgentDetail['EmailId'];
						//print_r($agentDetail);
						
						
					}
			}
			//end of customer chat history
			$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
			$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
			$this->view->getAgentDetail=$getAgentDetail;
			$this->view->agencyDetails=$getAgencyDetail;
			$this->view->getcustomerDetail = $getCustomerDetail;
			$this->view->travelPlanDetail=$travelPlanDetail;
			$ARR_SALUTION=unserialize(ARR_SALUTION);
			$this->view->ARR_SALUTION=$ARR_SALUTION;
			$encydataForTnc=$this->getEnc($travelPlanDetail[0]['TPSysId'].":".$travelPlanDetail[0]['AgencySysId'].":".$travelPlanDetail[0]['CustomerSysId']);
			$this->view->encid=$encydataForTnc;
    }

	//for other services preview
	public function previewSightseeingResultAction(){
		$this->_helper->layout->disableLayout();
		$TPSysId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		if(isset($TPSysId) && !empty($TPSysId)){
			$proposalList=$this->_crmcusttravelplan->GetCustomerSightSeeingProposal($TPSysId);
			$leadDetail=$this->_crmcusttravelplan->GetTravelPlanByCustomer($TPSysId);

		if($proposalList[0]['StatusType']==17){
			$this->_redirect('/proposal/booking-confirmation/mid/'.base64_encode($TPSysId));
			exit;
		}
			$crmcustomerObj = new Travel_Model_CRM_Customer();
			$getCustomerDetail[]=$crmcustomerObj->GetAgencyCustomerById($leadDetail[0]['CustomerSysId']);
			//print_r($getCustomerDetail);
			$CustomerSysId=$getCustomerDetail[0]['CustomerSysId'];
		//query for get customer chat history
            $objAgencyUser = new Travel_Model_CRM_AgencyUserInbox();
			$getChatHistoryDetail=array();
            $checkCustomerChatExist = (@$getCustomerDetail[0]['CustomerSysId'] > 0) ? $objAgencyUser->CheckCustomerMsgCount(@$getCustomerDetail[0]['CustomerSysId'], $TPSysId,trim($proposalList[0]['AgentSysId'])) : array();
                if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
                    $getChatHistoryDetail = $objAgencyUser->GetCustChatHistDetWithLead($TPSysId, $getCustomerDetail[0]['CustomerSysId'], 'ASC');
				}
			$getCustomerDetail['userChatExist'] = (count($checkCustomerChatExist)>0)?count($checkCustomerChatExist):count($getChatHistoryDetail);

            //query for get customer chat history
            $chatSenderDetails = array();
            $objAgencyStaff = new Travel_Model_TblAgencyStaff();
            $agentDetail = $objAgencyStaff->getUserDetailsById($proposalList[0]['AgentSysId']);
            if($getCustomerDetail['userChatExist'] > 0) {
                if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
                    $this->view->chatHistoryDetail = $getChatHistoryDetail;
                    $chatSenderDetails['TPSysId'] = $TPSysId;
                    $chatSenderDetails['AgencySysId'] = $intLoggedinUserAgencySysId;
                    $chatSenderDetails['CustomerSysId'] = $getCustomerDetail[0]['CustomerSysId'];
                    $chatSenderDetails['AgentSysId'] = $proposalList[0]['AgentSysId'];
                    $chatSenderDetails['EmailId'] = $agentDetail['EmailId'];
                    //print_r($agentDetail);
                }
            }
			//end of customer chat history
			//end of customer chat history
			$agencyStaffObj = new Travel_Model_TblAgencyStaff();
			$agentDetail=$agencyStaffObj->getUserDetailsById($proposalList[0]['AgentSysId']);
			$AgencySysId = $proposalList[0]['AgencySysId'];
			$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1']);
			$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
			$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';

			//send email to agent when customer open proposal
				$isPlanViewed=$this->_crmcusttravelplan->GetTravelPlanType($TPSysId);
				//echo "<pre>";print_r($proposalList);die;
				if($isPlanViewed['IsPlanViewed']==0){
						$emailSendId=trim($getAgencyDetail['PrimaryEmail']);
						$fromName=(isset($getAgencyDetail['DisplayName']) && !empty($getAgencyDetail['DisplayName']))?trim($getAgencyDetail['DisplayName']):trim(trim($getAgencyDetail['Title']));
						//$emailId = 'amit.k@catpl.co.in';
						$emailId = trim($agentDetail['EmailId']);
							$html = new Zend_View();
							$html->setScriptPath(APPLICATION_PATH . '/views/scripts/proposal/');
							$html->assign('type', 'OtherServicesViewSendEmailToAgent');
							$html->assign('customerDetails', $getCustomerDetail);
							$html->assign('agentDetails', $agentDetail);
							$html->assign('agencyDetails', $getAgencyDetail);
							$link=$this->view->baseUrl("/proposal/preview-sightseeing-result/mid/".base64_encode($TPSysId)."/type/");
							$html->assign('link',$link);
							$html->assign('data',$proposalList);
							//$html->assign('data', $hotelValues);
							$bodyText = $html->render('email-template.phtml');
							$emailData = array('fromEmail'=>trim($emailSendId),'fromName'=>trim($fromName),'subject'=>'HelloGTX - Proposal Open Alert !','to'=>array(trim($emailId)),'bodyHtml'=>$bodyText,'bodyText'=>'');
							$arrEmailStatisticsType = array_keys(unserialize(ARR_EMAIL_STATISTICS_TYPE));
							$arrEmailStatistics = array(
								"TPSysId" => $leadDetail[0]['TPSysId'],
								"TypeSysId" => 1,  // 1 For Email 2 For SMS
								"AgencySysId" => $leadDetail[0]['AgencySysId'],
								"AgentSysId" => $leadDetail[0]['AgentSysId'],
								"Title" => $bodyText,
								"Source" => $arrEmailStatisticsType[2], // 3 For Resend proposal
								"Status" => 0,
								"RefSysId" => "",
								"RefSysStatus" => "",
								"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
							);
							$this->mailSentByElastice($emailData,$arrEmailStatistics);

						//send sms
							$mobile_no = trim($agentDetail['ContactNo1']);
							$updateData = new Payment_Model_Checkotp();
							//$massage = "Your Customer(".trim($getcustomerDetail[0]['Contacts']).") has just opened the proposal. Team HelloGTX";
							$params['TPSysId']=$TPSysId;
							$params['shared_url']=$link;
							$params['AgencySysId']=$proposalList[0]['AgencySysId'];
							$params['AgentSysId']=$proposalList[0]['AgentSysId'];
							$shorturl_response = Zend_Controller_Action_HelperBroker::getStaticHelper('ShortUrl')->url_get($params);
							if (isset($shorturl_response['status_code']) && $shorturl_response['status_code'] == 200) {
								$link = $shorturl_response['data']['short_url'];
							}                
							$massage = "Your Customer(" . trim($getCustomerDetail[0]['FirstName']) . " " . trim($getCustomerDetail[0]['LastName']) . "-" . trim($getCustomerDetail[0]['Contacts']) . ") has just opened the proposal for " . trim(stripslashes($proposalList[0]['DestinationPlaces'])) . ",Click: " . $link . " to view and assist for finalizing.";
							$this->postFields = "";
							$this->postFields .="&method=$this->SMSMETHOD";
							$this->postFields .="&api_key=$this->SMSAPIKEY";
							$this->postFields .="&to=$mobile_no";
							$this->postFields .="&sender=$this->SMSSENDER";
							$this->postFields .="&message=$massage";
							$this->postFields .="&format=$this->SMSFORMAT";
							$postURL = $this->SMSURL;

							$arrSMSStatisticsType = array_keys(unserialize(ARR_SMS_STATISTICS_TYPE));
							$arrSMSStatistics = array(
								"TPSysId" => $TPSysId,
								"TypeSysId" => 2,  // 1 For Email 2 For SMS
								"AgencySysId" => $leadDetail[0]['AgencySysId'],
								"AgentSysId" => $leadDetail[0]['AgentSysId'],
								"Title" => $massage,
								"Source" =>  $arrEmailStatisticsType[2], // 3 For Resend proposal
								"Status" => 0,
								"RefSysId" => "",
								"RefSysStatus" => "",
								"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
							);
							// $resultVal = $updateData->sendSmsDetails($postURL, $this->postFields,$arrSMSStatistics);
							$resultVal['status'] = 'OK';
							if (isset($resultVal['status']) && $resultVal['status'] == 'OK') {
								$errorMessage = "";
							} else {
								$errorMessage = "Oops! Please try again";
							}
						//end of send sms

						$data = array(
							'isPlanViewed' => 1,
							'UpdateDate' => date('Y-m-d H:i:s'),
						);
						$where = "TPSysId = " . $TPSysId;
						$updatetravelplanrecord = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($data, $where);
				}
			//#end
			$this->view->getAgentDetail=$getAgentDetail;
			$this->view->agencyDetails=$getAgencyDetail;
			$this->view->getcustomerDetail = $getCustomerDetail;
			$this->view->chatSenderDetails=$chatSenderDetails;
			$this->view->leadDetail=$leadDetail;
			$this->view->proposalList=$proposalList;
			$this->view->mid=$TPSysId;
		}

	}
	public function bookingSightseeingReviewCustomerAction(){
		$this->view->layout()->disableLayout();
		$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$TPSysId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('tpid')));
        $this->view->strPayWithWalletUrl = Catabatic_Helper::getSiteUrl()."payment/payment-options/customer-pay";
        $this->view->strRechargeNowUrl = Catabatic_Helper::getSiteUrl()."payment/payment-options";
        $this->view->strSearchPageUrl = "/buyhotel/search-results";
        $this->view->intPlanType = "2";
        $this->view->strTrxType = "H";
		if(isset($TPSysId) && !empty($TPSysId)){
			$travelPlanDetail=$this->_crmcusttravelplan->GetCustomerSightSeeingleadDetail($TPSysId);
			$crmcustomerObj = new Travel_Model_CRM_Customer();
			$getCustomerDetail[]=$crmcustomerObj->GetAgencyCustomerById($travelPlanDetail[0]['CustomerSysId']);

			$this->view->mid=$travelPlanDetail[0]['MasterTPSysId'];
			$agencyStaffObj = new Travel_Model_TblAgencyStaff();
			$agentDetail=$agencyStaffObj->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
			$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
			$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1']);
			$crmcustomerObj = new Travel_Model_CRM_Customer();
			$getAgencyDetail=$crmcustomerObj->GetAgencyDetailById($AgencySysId);
			$guestDetails=$crmcustomerObj->GetCustomerWithDetails($travelPlanDetail[0]['CustomerSysId']);
		
		// for wallet use
        $this->view->strReturnURL = Catabatic_Helper::getSiteUrl()."proposal/make-sightseeing-payment/cid/".base64_encode($travelPlanDetail[0]['CustomerSysId'])."/tid/".base64_encode($travelPlanDetail[0]['TPIntSysId']);
        $this->view->strErrorURL = Catabatic_Helper::getSiteUrl()."proposal/make-sightseeing-payment/cid/".base64_encode($travelPlanDetail[0]['CustomerSysId'])."/tid/".base64_encode($travelPlanDetail[0]['TPIntSysId']);
		$this->view->intLoggedinAgencySysId = $AgencySysId;
		$this->view->IsCardChrgToCustomer = $travelPlanDetail[0]['IsCardChrgToCustomer'];
		$this->view->intLoggedinUserAgencySysId = $AgencyUserSysId=$travelPlanDetail[0]['AgentSysId'];
		$API_SOURCE_ID=$travelPlanDetail[0]['PlanType'];
		$roomjsonarray=json_decode($travelPlanDetail[0]['RoomInfoJson'],1);
			if($API_SOURCE_ID == 9){ // 
								$strCurrencyCode = 'INR';
								$Price = $travelPlanDetail[0]['Price'];
								$intTax = $travelPlanDetail[0]['XServiceTaxAmount'];
								$this->view->intTax =  $intTax = !empty($intTax)?($intTax):0;
								$this->view->intTotalAmount =  $intTotalAmount=$Price;
								$this->view->intAgentMarkUpAmount =  $intAgentMarkUpAmount = $travelPlanDetail[0]['MarkUp'];//$markupAgency->markupAg;
								$this->view->intAgencyMarkUpAmount =  $intAgencyMarkUpAmount = $travelPlanDetail[0]['AgencyMarkUp'];//$markupAgency->markupAg;
								$this->view->intGTXMarkUpAmount =  $intGTXMarkUpAmount = $travelPlanDetail[0]['GTXMarkup'];//$markupAgency->markupAg;
								$XServiceTaxAmount = $travelPlanDetail[0]['XServiceTaxAmount'];
								$GTXServiceTaxAmount = $travelPlanDetail[0]['GTXServiceTaxAmount'];
								$AgentServiceTaxAmount = $travelPlanDetail[0]['AgentServiceTaxAmount'];
								$AgentsCustomServiceTaxAmount = $travelPlanDetail[0]['AgentsCustomServiceTaxAmount'];
								$customDiscount = $travelPlanDetail[0]['CustomDiscount'];
								$serviceTaxOnCustomDiscount = $travelPlanDetail[0]['ServiceTaxOnCustomDiscount'];
								$this->view->intGrandPayableAmount =  $intGrandPayableAmount = round(($Price+$intAgentMarkUpAmount + $intAgencyMarkUpAmount + $intGTXMarkUpAmount + $XServiceTaxAmount + $GTXServiceTaxAmount + $AgentServiceTaxAmount + $AgentsCustomServiceTaxAmount)-($customDiscount+$serviceTaxOnCustomDiscount));
								$markuparray['intAgentMarkUpAmount']=$intAgentMarkUpAmount;
								$markuparray['intAgencyMarkUpAmount']=$intAgencyMarkUpAmount;
								$markuparray['intGTXMarkUpAmount']=$intGTXMarkUpAmount;
								$markuparray['intTotalAmount']=$intTotalAmount;
								$markuparray['intTax']=$XServiceTaxAmount;
								$markuparray['GTXServiceTaxAmount']=$GTXServiceTaxAmount;
								$markuparray['AgentServiceTaxAmount']=$AgentServiceTaxAmount;
								$markuparray['AgentsCustomServiceTaxAmount']=$AgentsCustomServiceTaxAmount;
								$markuparray['Pax']=count($roomjsonarray);
								$markuparray['SupplierSourceStr']='VISA';
								$markuparray['TotalDiscount']=$travelPlanDetail[0]['DiscountVal']; //0
								$markuparray['CurrencyType']=$travelPlanDetail[0]['CurrencyType'];
						}
        $this->view->guid = $this->GUID();    
		$encryptMarkUpData=$this->getEnc(json_encode($markuparray));
        $this->view->walletCode = $this->walletCode($travelPlanDetail[0]['AgentSysId'], $this->view->guid, round($intGrandPayableAmount), $AgencySysId, $travelPlanDetail[0]['TPSysId'],$travelPlanDetail[0]['CustomerSysId'],$encryptMarkUpData);
        $this->view->securecode = $this->secureCode($this->intLoggedinUserAgencySysId, $this->view->guid);
		$agencyAddress='';	
		if(isset($getAgencyDetail['CountrySysId']) && !empty($getAgencyDetail['StateOrZoneSysId']) && !empty($getAgencyDetail['CitySysId'])){
			$agencyAddress=$crmcustomerObj->GetNameOfContStateCity($getAgencyDetail['CountrySysId'],$getAgencyDetail['StateOrZoneSysId'],$getAgencyDetail['CitySysId']);
		}
		$agencyState='';
		$agencyCountry='';
		if(isset($agencyAddress['StateName']) && !empty($agencyAddress['StateName'])){
			$agencyState=$agencyAddress['StateName']?" ,".$agencyAddress['StateName']:'';
		}
		if(isset($agencyAddress['countryName']) && !empty($agencyAddress['countryName'])){
			$agencyCountry=$agencyAddress['countryName']?"(".$agencyAddress['countryName'].")":'';
		}
		//end of customer detail

		//query for get customer chat history
            $objAgencyUser = new Travel_Model_CRM_AgencyUserInbox();
			$getChatHistoryDetail=array();
            $checkCustomerChatExist = (@$getCustomerDetail[0]['CustomerSysId'] > 0) ? $objAgencyUser->CheckCustomerMsgCount(@$getCustomerDetail[0]['CustomerSysId'], $TPSysId,trim($travelPlanDetail[0]['AgentSysId'])) : array();
           // $checkCustomerChatExist = (count($checkCustomerChatExist)==0)?$objAgencyUser->CheckCustomerMsgCount(@$getcustomerDetail[0]['CustomerSysId'], $tpID):$checkCustomerChatExist;
                if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
                    $getChatHistoryDetail = $objAgencyUser->GetCustChatHistDetWithLead($TPSysId, $getCustomerDetail[0]['CustomerSysId'], 'ASC');
				}
			$getCustomerDetail['userChatExist'] = (count($checkCustomerChatExist)>0)?count($checkCustomerChatExist):count($getChatHistoryDetail);
            //  $this-view->getCustomerDetails = $getcustomerDetail;
            //query for get customer chat history
            $chatSenderDetails = array();
            $objAgencyStaff = new Travel_Model_TblAgencyStaff();
            $agentDetail = $objAgencyStaff->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
            if($getCustomerDetail['userChatExist'] > 0) {
                if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
                    $this->view->chatHistoryDetail = $getChatHistoryDetail;
                    $chatSenderDetails['TPSysId'] = $TPSysId;
                    $chatSenderDetails['AgencySysId'] = $travelPlanDetail[0]['AgencySysId'];
                    $chatSenderDetails['CustomerSysId'] = $getCustomerDetail[0]['CustomerSysId'];
                    $chatSenderDetails['AgentSysId'] = $travelPlanDetail[0]['AgentSysId'];
                    $chatSenderDetails['EmailId'] = $agentDetail['EmailId'];
                    //print_r($agentDetail);
                }
            }
			//end of customer chat history
		$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
		$this->view->getAgentDetail=$getAgentDetail;
		$this->view->agencyDetails=$getAgencyDetail;
		$this->view->guestDetail=$guestDetails;
		$this->view->getcustomerDetail = $getCustomerDetail;
		$this->view->chatSenderDetails = $chatSenderDetails;
		$this->view->encryptMarkUpData=$encryptMarkUpData;
		$this->view->travelPlanDetail=$travelPlanDetail;


		$this->view->tpid=$TPSysId;
		} else {
			echo "Please try again";
			die;
		}
	}
    public function makeSightseeingPaymentAction() {
       
	  // echo "<pre>";print_r($_REQUEST);die;
        $objTrx = new Travel_Model_TblAgencyCustomerTrx();
        $intXRefTrxNo = $this->getRequest()->getParam('txnid');
        $strTrxStatus = $this->getRequest()->getParam('status');
        $planId=$this->getRequest()->getParam('TpSysId');
		$MasterTPSysId='';
		$createDate = date('Y-m-d H:i:s');
		   if($planId != ''){ //echo "HI"; exit;
            if($strTrxStatus == "success") {
			$travelplanObj = new Travel_Model_CRM_CustomerTravelPlan();
			$travelPlanDetail=$travelplanObj->GetSightSeeingCustomerDetailsPax($planId);
			//echo "<pre>";print_r($travelPlanDetail);die;
			$API_SOURCE_ID=$travelPlanDetail[0]['PlanType'];
			$MasterTPSysId=$travelPlanDetail[0]['MasterTPSysId'];
			$uid=$travelPlanDetail[0]['CustomerSysId'].':'.$planId.':'.$MasterTPSysId;
			$uid=base64_encode($this->getEnc($uid));
			$customHelper = Zend_Controller_Action_HelperBroker::getStaticHelper("Custom");
			$RoomMemInfoJson=json_decode($travelPlanDetail[0]['RoomInfoJson'],1);
			$totalPax=count($RoomMemInfoJson);
				$roominfojson=isset($travelPlanDetail[0]['RoomMemInfoJson'])?json_decode($travelPlanDetail[0]['RoomMemInfoJson'],1):array();
				$memberDetails=array();
				if(!empty($roominfojson) ){
					for ($d = 1; $d <= count($roominfojson); $d++) {
						$memberDetails[] = array('FirstName' => $roominfojson[$d]['FirstName'], 'LastName' => $roominfojson[$d]['LastName'], 'DOB' => @$roominfojson[$d]['DOB']);
					}
				}
						
							if(isset($MasterTPSysId) && $MasterTPSysId > 0){	
								$whereMaste = "MasterTPSysId = " . $MasterTPSysId;
								$disableAlltravelplan = array(
									'StatusType' => 10,
									'UpdateDate' => $createDate
								);
								$disableAlltravelplan = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($disableAlltravelplan, $whereMaste);
							}
							$where = "TPSysId = " . $planId;
							$updatetravelplan = array(
								'StatusType' => 17,
								'UpdateDate' => $createDate
							);
							$updatetravelPlan = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($updatetravelplan, $where);
							
							// update main query status created by Er Amit Kumar Dubey on 8 may 2017 at 11:23 AM
								$statusArray=$customHelper->changeQueryStatusByProposal();
								$querystatus=$statusArray[17];
								if(isset($querystatus) && !empty($querystatus)){
									$whereQuery = "TPSysId = " . $MasterTPSysId;
									$updatetravelplanquery = array(
										'StatusType' => $querystatus,
										'UpdateDate' => $createDate
									);
									$updatetravelPlanQuery = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($updatetravelplanquery, $whereQuery);
								}
								
							//update accom table with bookingid
							$where = "TPIntSysId = " . $travelPlanDetail[0]['TPIntSysId'];
							$updateQuery = array(
								'XRefVoucherNo' =>$planId,
								'UpdateDate' => $createDate
							);
							$objCurd = new Visa_Model_Visa();
							$visaQueryPrposalTravelPlanId = $objCurd->updateTable("TB_Agency_Customer_TravelPlan_SightSeeing",$updateQuery,$where);
							$msgArray=array('status'=>'success','msg'=>'Your payment is success');
							$PAYMENT_MSG = new Zend_Session_Namespace('PAYMENT_MSG');
							$PAYMENT_MSG->PAYMENT_MSG=$msgArray;

							//send email to customer
									$html = new Zend_View();
									$html->setScriptPath(APPLICATION_PATH . '/views/scripts/proposal/');
									$agencyStaffObj = new Travel_Model_TblAgencyStaff();
									$agentDetail=$agencyStaffObj->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
									$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
									$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1'],'AgentEmail'=>$agentDetail['EmailId']);
									$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
									//echo "<pre>";print_r($getAgencyDetail);die;
									$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';

									$html->assign('type', 'SightSeeingBookingPaymentConfirmationEmail');
									$html->assign('data', $travelPlanDetail);
									$html->assign('getAgentDetail',$getAgentDetail);
									$html->assign('agencyDetails',$getAgencyDetail);
									//$html->assign('URL', $encryptData);
									$paymentconfirmText = $html->render('email-template.phtml');
									$html->assign('type', 'SightSeeingBookingConfirmationEmailText');
									$html->assign('data', $travelPlanDetail);
									$html->assign('getAgentDetail',$getAgentDetail);
									$html->assign('agencyDetails',$getAgencyDetail);
									$bookingConfirmText = $html->render('email-template.phtml');
									$aConfig = $this->getInvokeArg('bootstrap')->getOptions();
									$this->smtpUserName = $aConfig['smtpUserName'];
									$this->smtpPassword = $aConfig['smtpPassword'];
									$this->smtpPort = $aConfig['smtpPort'];
									$this->smtpHost = $aConfig['smtpHost'];
									$this->fromEmail = $aConfig['fromEmail'];
									$this->fromName = $aConfig['fromName'];
									//$emailId ='amit.k@catpl.co.in';
									$emailId = trim($travelPlanDetail[0]['ProposalEmailTo']);
									if($emailId!=''){
										$emailData1 = array('fromEmail'=>$this->fromEmail,'fromName'=>$this->fromName,'subject'=>stripslashes($travelPlanDetail[0]['VisaName']).' Trip Payment Receipt','to'=>array(trim($emailId)),'bodyHtml'=>$paymentconfirmText,'bodyText'=>'');
										$emailData2 = array('fromEmail'=>$this->fromEmail,'fromName'=>$this->fromName,'subject'=>stripslashes($travelPlanDetail[0]['VisaName']).' Trip Booking Details','to'=>array(trim($emailId)),'bodyHtml'=>$bookingConfirmText,'bodyText'=>'');
										try {
											//echo "success";
											$arrEmailStatisticsType = array_keys(unserialize(ARR_EMAIL_STATISTICS_TYPE));
											$arrEmailStatistics = array(
												"TPSysId" => $planId,
												"TypeSysId" => 1,  // 1 For Email 2 For SMS
												"AgencySysId" => $travelPlanDetail[0]['AgencySysId'],
												"AgentSysId" => $travelPlanDetail[0]['AgentSysId'],
												"Title" => $paymentconfirmText,
												"Source" => $arrEmailStatisticsType[1], // 2 For Vouchers
												"Status" => 0,
												"RefSysId" => "",
												"RefSysStatus" => "",
												"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
											);
											$arrEmailStatistics2 = array(
												"TPSysId" => $planId,
												"TypeSysId" => 1,  // 1 For Email 2 For SMS
												"AgencySysId" => $travelPlanDetail[0]['AgencySysId'],
												"AgentSysId" => $travelPlanDetail[0]['AgentSysId'],
												"Title" => $bookingConfirmText,
												"Source" => $arrEmailStatisticsType[1], // 2 For Vouchers
												"Status" => 0,
												"RefSysId" => "",
												"RefSysStatus" => "",
												"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
											);
											$this->mailSentByElastice($emailData1,$arrEmailStatistics);
											$this->mailSentByElastice($emailData2,$arrEmailStatistics2);
											$msg="success";
										} catch (Exception $err) {
											//print_r($err, true);
											$msg="failed";
										}
									}
							//end of send email to customer
			} if($strTrxStatus == "failure" ){
					$where = "TPSysId = " . $planId;
					$updatetravelplan = array(
						'StatusType' => 7,
						'UpdateDate' => $createDate
					);
					$updatetravelPlan = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($updatetravelplan, $where);


					// update main query status created by Er Amit Kumar Dubey on 8 may 2017 at 11:27 AM
						$statusArray=$customHelper->changeQueryStatusByProposal();
						$querystatus=$statusArray[7];
						if(isset($querystatus) && !empty($querystatus)){
							$whereQuery = "TPSysId = " . $MasterTPSysId;
							$updatetravelplanquery = array(
								'StatusType' => $querystatus,
								'UpdateDate' => $createDate
							);
							$updatetravelPlanQuery = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($updatetravelplanquery, $whereQuery);
						}
						$msgArray=array('status'=>'failed','msg'=>'Your payment is unsuccessful'.$$this->getRequest()->getParam('error_Message'));
						$PAYMENT_MSG = new Zend_Session_Namespace('PAYMENT_MSG');
						$PAYMENT_MSG->PAYMENT_MSG=$msgArray;
						exit;
			}
		  }else{
				$msgArray=array('status'=>'failed','msg'=>'Your payment is unsuccessful Id Mismatch');
				$PAYMENT_MSG = new Zend_Session_Namespace('PAYMENT_MSG');
				$PAYMENT_MSG->PAYMENT_MSG=$msgArray;
		}
		$this->_redirect("/proposal/booking-sightseeing-confirmation/mid/".base64_encode($MasterTPSysId)."/pid/".base64_encode($planId));
		exit;
    }
	public function bookingSightseeingConfirmationAction(){
		$this->view->layout()->disableLayout();
		$proposalId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$TPSysId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('pid')));
		$PAYMENT_MSG = new Zend_Session_Namespace('PAYMENT_MSG');
		if($TPSysId==''){
			$this->view->error=1;
			//echo "Please try again";
			//die;
		} else{
			$this->view->error=0;
		$travelPlanDetail=$this->_crmcusttravelplan->GetSightseeingCustomerDetailsPax($TPSysId);
		//echo "<pre>";print_r($travelPlanDetail);die;
		$CustomerSysId=$travelPlanDetail[0]['CustomerSysId'];
		$getCustomerDetail = $this->_crmcustomerObj->ChkAgencyUser($CustomerSysId);
//echo "<pre>";print_r($getCustomerDetail);
		//customer detail
				$CustomerSysId=$travelPlanDetail[0]['CustomerSysId'];
				$getLeadlist = $this->_crmcusttravelplan->GetPurchasedPublicPageLeadList($CustomerSysId, $travelPlanDetail[0]['AgencySysId'], $TPSysId);
				$API_SOURCE_ID=$travelPlanDetail[0]['PlanType'];
				$roomjsonarray=json_decode($travelPlanDetail[0]['RoomInfoJson'],1);				
				if($API_SOURCE_ID == "9"){
					$strCurrencyCode = $travelPlanDetail[0]['CurrencyType'];
					$Price = $travelPlanDetail[0]['Price'];
					$intTax = $travelPlanDetail[0]['XServiceTaxAmount'];
					$this->view->intTax =  $intTax = !empty($intTax)?($intTax):0;
					$this->view->intTotalAmount =  $intTotalAmount=$Price;
					$this->view->intAgentMarkUpAmount =  $intAgentMarkUpAmount = $travelPlanDetail[0]['MarkUp'];//$markupAgency->markupAg;
					$this->view->intAgencyMarkUpAmount =  $intAgencyMarkUpAmount = $travelPlanDetail[0]['AgencyMarkUp'];//$markupAgency->markupAg;
					$this->view->intGTXMarkUpAmount =  $intGTXMarkUpAmount = $travelPlanDetail[0]['GTXMarkup'];//$markupAgency->markupAg;
					$XServiceTaxAmount = $travelPlanDetail[0]['XServiceTaxAmount'];
					$GTXServiceTaxAmount = $travelPlanDetail[0]['GTXServiceTaxAmount'];
					$AgentServiceTaxAmount = $travelPlanDetail[0]['AgentServiceTaxAmount'];
					$AgentsCustomServiceTaxAmount = $travelPlanDetail[0]['AgentsCustomServiceTaxAmount'];
					$customDiscount = $travelPlanDetail[0]['CustomDiscount'];
					$serviceTaxOnCustomDiscount = $travelPlanDetail[0]['ServiceTaxOnCustomDiscount'];
					$this->view->intGrandPayableAmount =  $intGrandPayableAmount = round(($Price+$intAgentMarkUpAmount + $intAgencyMarkUpAmount + $intGTXMarkUpAmount + $XServiceTaxAmount + $GTXServiceTaxAmount + $AgentServiceTaxAmount + $AgentsCustomServiceTaxAmount)-($customDiscount+$serviceTaxOnCustomDiscount));
				}

		//query for get customer chat history
            $objAgencyUser = new Travel_Model_CRM_AgencyUserInbox();
			$getChatHistoryDetail=array();
            $checkCustomerChatExist = (@$getCustomerDetail[0]['CustomerSysId'] > 0) ? $objAgencyUser->CheckCustomerMsgCount(@$getCustomerDetail[0]['CustomerSysId'], $TPSysId,trim($travelPlanDetail[0]['AgentSysId'])) : array();
           // $checkCustomerChatExist = (count($checkCustomerChatExist)==0)?$objAgencyUser->CheckCustomerMsgCount(@$getcustomerDetail[0]['CustomerSysId'], $tpID):$checkCustomerChatExist;
                if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
                    $getChatHistoryDetail = $objAgencyUser->GetCustChatHistDetWithLead($TPSysId, $getCustomerDetail[0]['CustomerSysId'], 'ASC');
				}
			$getCustomerDetail['userChatExist'] = (count($checkCustomerChatExist)>0)?count($checkCustomerChatExist):count($getChatHistoryDetail);
            //query for get customer chat history
            $chatSenderDetails = array();
            $objAgencyStaff = new Travel_Model_TblAgencyStaff();
            $agentDetail = $objAgencyStaff->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
            if($getCustomerDetail['userChatExist'] > 0) {
                if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
                    $this->view->chatHistoryDetail = $getChatHistoryDetail;
					
                    $chatSenderDetails['TPSysId'] = $TPSysId;
                    $chatSenderDetails['AgencySysId'] = $travelPlanDetail[0]['AgencySysId'];
                    $chatSenderDetails['CustomerSysId'] = $getCustomerDetail[0]['CustomerSysId'];
                    $chatSenderDetails['AgentSysId'] = $travelPlanDetail[0]['AgentSysId'];
                    $chatSenderDetails['EmailId'] = $agentDetail['EmailId'];
                    //print_r($agentDetail);
                }
            }
			            //echo "<pre>";print_r($chatSenderDetails);

			//end of customer chat history
			$agencyStaffObj = new Travel_Model_TblAgencyStaff();
			$agentDetail=$agencyStaffObj->getUserDetailsById($getLeadlist[0]['AgentSysId']);
			$AgencySysId = $getLeadlist[0]['AgencySysId'];
			$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1'],'AgentEmail'=>$agentDetail['EmailId']);
			$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
			$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
			$this->view->getAgentDetail=$getAgentDetail;
			$this->view->agencyDetails=$getAgencyDetail;
			$this->view->travelPlanDetail=$travelPlanDetail;
			$this->view->getcustomerDetail = $getCustomerDetail;
			$this->view->chatSenderDetails = $chatSenderDetails;
		}
		//echo "<pre>";print_r($travelPlanDetail);die;
		$this->view->PAYMENT_MSG=$PAYMENT_MSG->PAYMENT_MSG;
   }
    public function sightseeingVoucherAction() {
        $this->_helper->layout->disableLayout();
		$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$TPSysId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('pid')));
		if($TPSysId==''){
			echo "Please try again";
			die;
		}
		$travelPlanDetail=$this->_crmcusttravelplan->GetSightSeeingCustomerDetailsTrx($TPSysId);
		$CustomerSysId=$travelPlanDetail[0]['CustomerSysId'];
		$objAgencyStaff = new Travel_Model_TblAgencyStaff();
		$agentDetail=$objAgencyStaff->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
		$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
		$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1']);
		$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
		$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
		$this->view->getAgentDetail=$getAgentDetail;
		$this->view->agencyDetails=$getAgencyDetail;
		$this->view->travelPlanDetail=$travelPlanDetail;
   }
    public function sightseeingInvoiceAction() {
        $this->_helper->layout->disableLayout(); 
		$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$TPSysId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('pid')));
		if($TPSysId==''){
			echo "Please try again";
			die;
		}
		$travelPlanDetail=$this->_crmcusttravelplan->GetSightSeeingCustomerDetailsTrx($TPSysId);
		$objAgencyStaff = new Travel_Model_TblAgencyStaff();
		$agentDetail=$objAgencyStaff->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
		$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
		$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1']);
		$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
		$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
		$this->view->getAgentDetail=$getAgentDetail;
		$this->view->agencyDetails=$getAgencyDetail;
		$this->view->travelPlanDetail=$travelPlanDetail;
		//echo "<pre>";print_r($getAgencyDetail);die;
		$customhelper = Zend_Controller_Action_HelperBroker::getStaticHelper('Custom');
		$this->view->getallstatustype=$customhelper->getAllStatusType();
    }
    public function sightseeingViewAction() {
       	$this->_helper->layout->disableLayout(); 
		$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$TPSysId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('pid')));
		if($TPSysId==''){
			echo "Please try again";
			die;
		}

		$travelPlanDetail=$this->_crmcusttravelplan->GetSightseeingCustomerDetailsTrx($TPSysId);
		//customer detail
			$travelplanObj = new Travel_Model_CRM_CustomerTravelPlan();
			$travelPlanDetail=$travelplanObj->GetSightSeeingCustomerDetailsPax($TPSysId);
		$CustomerSysId=$travelPlanDetail[0]['CustomerSysId'];

				if (isset($CustomerSysId) && !empty($CustomerSysId)) {
			        $this->_crmcustomerObj = new Travel_Model_CRM_Customer();
					$getCustomerDetail = $this->_crmcusttravelplan->GetTravelPlanCustomerDetails($TPSysId);
					$objAgencyUser = new Travel_Model_CRM_AgencyUserInbox();
					$checkCustomerChatExist = $getCustomerDetail[0]['CustomerSysId'] > 0? $objAgencyUser->CheckCustomerMsgCount($getCustomerDetail[0]['CustomerSysId'],$TPSysId):array();
					$getversiondetails = $this->_crmcusttravelplan->GetVersionInfo($TPSysId);
					$getCustomerDetail['userChatExist']=count($checkCustomerChatExist);
				}
		//end of customer detail
		//query for get customer chat history
			$chatSenderDetails=array();
			if($getCustomerDetail['userChatExist'] > 0){
					if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
						$getChatHistoryDetail = $objAgencyUser->GetCustChatHistDetWithLead($TPSysId,$getCustomerDetail[0]['CustomerSysId'],'ASC');
						$this->view->chatHistoryDetail=$getChatHistoryDetail;
						$chatSenderDetails['TPSysId']=$TPSysId;
						$chatSenderDetails['AgencySysId']=$travelPlanDetail[0]['AgencySysId'];
						$chatSenderDetails['CustomerSysId']=$travelPlanDetail[0]['CustomerSysId'];
						$chatSenderDetails['AgentSysId']=$travelPlanDetail[0]['AgentSysId'];
						//$chatSenderDetails['EmailId']=$getcustomerDetail[0]['EmailId'];
						$objAgencyStaff   =	new Travel_Model_TblAgencyStaff();
						$agentDetail=$objAgencyStaff->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
						$chatSenderDetails['EmailId']=$agentDetail['EmailId'];
						//print_r($agentDetail);
						
						
					}
			}
			//end of customer chat history
			$agencyStaffObj = new Travel_Model_TblAgencyStaff();
			$agentDetail=$agencyStaffObj->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
			$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
			$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1']);
			$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
			$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
			$this->view->getAgentDetail=$getAgentDetail;
			$this->view->agencyDetails=$getAgencyDetail;
			$this->view->getcustomerDetail = $getCustomerDetail;
			$this->view->travelPlanDetail=$travelPlanDetail;
			$ARR_SALUTION=unserialize(ARR_SALUTION);
			$this->view->ARR_SALUTION=$ARR_SALUTION;
    }
	//for other services preview activity
	public function previewActivityResultAction(){
		$this->_helper->layout->disableLayout();
		$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		if(isset($mid) && !empty($mid)){
			$proposalList=$this->_crmcusttravelplan->GetCustomerActivityProposal($mid);
		//echo "<pre>";print_r($proposalList);die;
		if($proposalList[0]['StatusType']==17){
			$this->_redirect('/proposal/booking-activity-confirmation/mid/'.base64_encode($TPSysId).'/tpid/'.base64_encode($proposalList[0]['TPSysId']));
			exit;
		}
			$crmcustomerObj = new Travel_Model_CRM_Customer();
			$getCustomerDetail[]=$crmcustomerObj->GetAgencyCustomerById($proposalList[0]['CustomerSysId']);
			//print_r($getCustomerDetail);
			$CustomerSysId=$getCustomerDetail[0]['CustomerSysId'];
		//query for get customer chat history
            $objAgencyUser = new Travel_Model_CRM_AgencyUserInbox();
			$getChatHistoryDetail=array();
            $checkCustomerChatExist = (@$getCustomerDetail[0]['CustomerSysId'] > 0) ? $objAgencyUser->CheckCustomerMsgCount(@$getCustomerDetail[0]['CustomerSysId'], $mid,trim($proposalList[0]['AgentSysId'])) : array();
                if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
                    $getChatHistoryDetail = $objAgencyUser->GetCustChatHistDetWithLead($mid, $getCustomerDetail[0]['CustomerSysId'], 'ASC');
				}
			$getCustomerDetail['userChatExist'] = (count($checkCustomerChatExist)>0)?count($checkCustomerChatExist):count($getChatHistoryDetail);

            //query for get customer chat history
            $chatSenderDetails = array();
			$AgentSysId = $proposalList[0]['AgentSysId'];
			$AgencySysId = $proposalList[0]['AgencySysId'];
			$getAgentDetail=$this->_crmcusttravelplan->GetAgentDetails($AgentSysId);
			$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
			$getCustomerDetail[0]['TPSysId'] = $proposalList[0]['TPSysId'];
			$getCustomerDetail[0]['AgencySysId'] = $AgencySysId;
			$getCustomerDetail[0]['AgentSysId'] = $AgentSysId;
            if($getCustomerDetail['userChatExist'] > 0) {
                if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
                    $this->view->chatHistoryDetail = $getChatHistoryDetail;
                    $chatSenderDetails['TPSysId'] = $mid;
                    $chatSenderDetails['AgencySysId'] = $AgencySysId;
                    $chatSenderDetails['CustomerSysId'] = $getCustomerDetail[0]['CustomerSysId'];
                    $chatSenderDetails['AgentSysId'] = $proposalList[0]['AgentSysId'];
                    $chatSenderDetails['EmailId'] = $getAgentDetail['EmailId'];
                    //print_r($agentDetail);
                }
            }
			//end of customer chat history
			//end of customer chat history
			$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';

			//send email to agent when customer open proposal
				$isPlanViewed=$this->_crmcusttravelplan->GetTravelPlanType($mid);
				//echo "<pre>";print_r($proposalList);die;
				if($isPlanViewed['IsPlanViewed']==0){
						$emailSendId=trim($getAgencyDetail['PrimaryEmail']);
						$fromName=(isset($getAgencyDetail['DisplayName']) && !empty($getAgencyDetail['DisplayName']))?trim($getAgencyDetail['DisplayName']):trim(trim($getAgencyDetail['Title']));
						//$emailId = 'amit.k@catpl.co.in';
						$emailId = trim($getAgentDetail['EmailId']);
							$html = new Zend_View();
							$html->setScriptPath(APPLICATION_PATH . '/views/scripts/proposal/');
							$html->assign('type', 'OtherServicesViewSendEmailToAgent');
							$html->assign('customerDetails', $getCustomerDetail);
							$html->assign('agentDetails', $getAgentDetail);
							$html->assign('agencyDetails', $getAgencyDetail);
							$link=$this->view->baseUrl("/proposal/preview-activity-result/mid/".base64_encode($mid));
							$html->assign('link',$link);
							$html->assign('data',$proposalList);
							//$html->assign('data', $hotelValues);
							$bodyText = $html->render('email-template.phtml');
							$emailData = array('fromEmail'=>trim($emailSendId),'fromName'=>trim($fromName),'subject'=>'HelloGTX - Proposal Open Alert !','to'=>array(trim($emailId)),'bodyHtml'=>$bodyText,'bodyText'=>'');
							$arrEmailStatisticsType = array_keys(unserialize(ARR_EMAIL_STATISTICS_TYPE));
							$arrEmailStatistics = array(
								"TPSysId" => $proposalList[0]['TPSysId'],
								"TypeSysId" => 1,  // 1 For Email 2 For SMS
								"AgencySysId" => $proposalList[0]['AgencySysId'],
								"AgentSysId" => $proposalList[0]['AgentSysId'],
								"Title" => $bodyText,
								"Source" => $arrEmailStatisticsType[2], // 3 For Resend proposal
								"Status" => 0,
								"RefSysId" => "",
								"RefSysStatus" => "",
								"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
							);
							$this->mailSentByElastice($emailData,$arrEmailStatistics);

						//send sms
							$mobile_no = trim($getAgentDetail['ContactNo1']);
							$updateData = new Payment_Model_Checkotp();
							//$massage = "Your Customer(".trim($getcustomerDetail[0]['Contacts']).") has just opened the proposal. Team HelloGTX";
							$params['TPSysId']=$mid;
							$params['shared_url']=$link;
							$params['AgencySysId']=$proposalList[0]['AgencySysId'];
							$params['AgentSysId']=$proposalList[0]['AgentSysId'];
							$shorturl_response = Zend_Controller_Action_HelperBroker::getStaticHelper('ShortUrl')->url_get($params);
							if (isset($shorturl_response['status_code']) && $shorturl_response['status_code'] == 200) {
								$link = $shorturl_response['data']['short_url'];
							}                
							$massage = "Your Customer(" . trim($getCustomerDetail[0]['FirstName']) . " " . trim($getCustomerDetail[0]['LastName']) . "-" . trim($getCustomerDetail[0]['Contacts']) . ") has just opened the proposal for " . trim(stripslashes($proposalList[0]['DestinationPlaces'])) . ",Click: " . $link . " to view and assist for finalizing.";
							$this->postFields = "";
							$this->postFields .="&method=$this->SMSMETHOD";
							$this->postFields .="&api_key=$this->SMSAPIKEY";
							$this->postFields .="&to=$mobile_no";
							$this->postFields .="&sender=$this->SMSSENDER";
							$this->postFields .="&message=$massage";
							$this->postFields .="&format=$this->SMSFORMAT";
							$postURL = $this->SMSURL;

							$arrSMSStatisticsType = array_keys(unserialize(ARR_SMS_STATISTICS_TYPE));
							$arrSMSStatistics = array(
								"TPSysId" => $mid,
								"TypeSysId" => 2,  // 1 For Email 2 For SMS
								"AgencySysId" => $proposalList[0]['AgencySysId'],
								"AgentSysId" => $proposalList[0]['AgentSysId'],
								"Title" => $massage,
								"Source" => $arrSMSStatisticsType[0], // 2 For Resend
								"Status" => 0,
								"RefSysId" => "",
								"RefSysStatus" => "",
								"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
							);

							//$resultVal = $updateData->sendSmsDetails($postURL, $this->postFields,$arrSMSStatistics);
							$resultVal['status'] = 'OK';
							if (isset($resultVal['status']) && $resultVal['status'] == 'OK') {
								$errorMessage = "";
							} else {
								$errorMessage = "Oops! Please try again";
							}
						//end of send sms

						$data = array(
							'isPlanViewed' => 1,
							'UpdateDate' => date('Y-m-d H:i:s'),
						);
						$where = "TPSysId = " . $mid;
						$updatetravelplanrecord = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($data, $where);
				}
			//#end
			$this->view->getAgentDetail=$getAgentDetail;
			$this->view->agencyDetails=$getAgencyDetail;
			$this->view->getcustomerDetail = $getCustomerDetail;
			$this->view->chatSenderDetails=$chatSenderDetails;
			$this->view->leadDetail=$proposalList;
			$this->view->proposalList=$proposalList;
			$this->view->mid=$mid;
			$encydataForTnc=$this->getEnc($proposalList[0]['TPSysId'].":".$proposalList[0]['AgencySysId'].":".$proposalList[0]['CustomerSysId']);
			$this->view->encid=$encydataForTnc;		
		}

	}
	public function bookingActivityReviewCustomerAction(){
		$this->view->layout()->disableLayout();
		$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$TPSysId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('tpid')));
		
        $this->view->strRechargeNowUrl = Catabatic_Helper::getSiteUrl()."payment/payment-options";
        $this->view->strSearchPageUrl = "/buyhotel/search-results";
        $this->view->intPlanType = "8";
        $this->view->strTrxType = "A";
		if(isset($TPSysId) && !empty($TPSysId)){
			$travelPlanDetail=$this->_crmcusttravelplan->GetCustomerActivityleadDetail($TPSysId);
			//echo "<pre>";print_r($travelPlanDetail);die;
			if($travelPlanDetail[0]['StatusType']==17){
				$this->_redirect('/proposal/booking-activity-confirmation/mid/'.base64_encode($mid).'/tpid/'.base64_encode($TPSysId));
				exit;
			}
			$crmcustomerObj = new Travel_Model_CRM_Customer();
			$getCustomerDetail[]=$crmcustomerObj->GetAgencyCustomerById($travelPlanDetail[0]['CustomerSysId']);
			//echo "<pre>";print_r($getCustomerDetail);die;

			//get detail for activity overview
				$objActivity = new Activity_Model_Activity();
				$arrActivityDetails = $objActivity->activityDetailById($travelPlanDetail[0]['InvnItemSysId']);
				//echo "<pre>";print_r($travelPlanDetail);die;
			//#end of get detail for activity overview
			$this->view->mid=$travelPlanDetail[0]['MasterTPSysId'];
			$agencyStaffObj = new Travel_Model_TblAgencyStaff();
			$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
			$AgentSysId = $travelPlanDetail[0]['AgentSysId'];
			$getCustomerDetail[0]['TPSysId'] = $travelPlanDetail[0]['TPSysId'];
			$getCustomerDetail[0]['AgencySysId'] = $travelPlanDetail[0]['AgencySysId'];
			$getCustomerDetail[0]['AgentSysId'] = $travelPlanDetail[0]['AgentSysId'];
			$getAgentDetail=$this->_crmcusttravelplan->GetAgentDetails($AgentSysId);
			//$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1']);
			$crmcustomerObj = new Travel_Model_CRM_Customer();
			$getAgencyDetail=$crmcustomerObj->GetAgencyDetailById($AgencySysId);
			$guestDetails=$crmcustomerObj->GetCustomerWithDetails($travelPlanDetail[0]['CustomerSysId']);
		//print_r($guestDetails);die;
		// for wallet use
        $this->view->strReturnURL = Catabatic_Helper::getSiteUrl()."proposal/make-activity-payment/cid/".base64_encode($travelPlanDetail[0]['CustomerSysId'])."/tid/".base64_encode($travelPlanDetail[0]['TPIntSysId']);
        $this->view->strErrorURL = Catabatic_Helper::getSiteUrl()."proposal/make-activity-payment/cid/".base64_encode($travelPlanDetail[0]['CustomerSysId'])."/tid/".base64_encode($travelPlanDetail[0]['TPIntSysId']);
		$this->view->intLoggedinAgencySysId = $AgencySysId;
		$this->view->IsCardChrgToCustomer = $travelPlanDetail[0]['IsCardChrgToCustomer'];
		$this->view->intLoggedinUserAgencySysId = $AgencyUserSysId=$AgentSysId;
		$API_SOURCE_ID=$travelPlanDetail[0]['PlanType'];
		$roomjsonarray=json_decode($travelPlanDetail[0]['RoomInfoJson'],1);
			if($API_SOURCE_ID ==8){ // 
					$strCurrencyCode = 'INR';
					$Price = $travelPlanDetail[0]['Price'];
					$intTax = $travelPlanDetail[0]['XServiceTaxAmount'];
					$this->view->intTax =  $intTax = !empty($intTax)?($intTax):0;
					$this->view->intTotalAmount =  $intTotalAmount=$Price;
					$this->view->intAgentMarkUpAmount =  $intAgentMarkUpAmount = $travelPlanDetail[0]['MarkUp'];//$markupAgency->markupAg;
					$this->view->intAgencyMarkUpAmount =  $intAgencyMarkUpAmount = $travelPlanDetail[0]['AgencyMarkUp'];//$markupAgency->markupAg;
					$this->view->intGTXMarkUpAmount =  $intGTXMarkUpAmount = $travelPlanDetail[0]['GTXMarkup'];//$markupAgency->markupAg;
					$XServiceTaxAmount = $travelPlanDetail[0]['XServiceTaxAmount'];
					$GTXServiceTaxAmount = $travelPlanDetail[0]['GTXServiceTaxAmount'];
					$AgentServiceTaxAmount = $travelPlanDetail[0]['AgentServiceTaxAmount'];
					$AgentsCustomServiceTaxAmount = $travelPlanDetail[0]['AgentsCustomServiceTaxAmount'];
					$customDiscount = $travelPlanDetail[0]['CustomDiscount'];
					$serviceTaxOnCustomDiscount = $travelPlanDetail[0]['ServiceTaxOnCustomDiscount'];
					$DiscountVal = $travelPlanDetail[0]['DiscountVal'];
					$serviceTaxOnCustomDiscount = $travelPlanDetail[0]['ServiceTaxOnCustomDiscount'];
					$this->view->intGrandPayableAmount =  $intGrandPayableAmount = round(($Price+$intAgentMarkUpAmount + $intAgencyMarkUpAmount + $intGTXMarkUpAmount + $XServiceTaxAmount + $GTXServiceTaxAmount + $AgentServiceTaxAmount + $AgentsCustomServiceTaxAmount)-($DiscountVal+$customDiscount+$serviceTaxOnCustomDiscount));
					$markuparray['intAgentMarkUpAmount']=$intAgentMarkUpAmount;
					$markuparray['intAgencyMarkUpAmount']=$intAgencyMarkUpAmount;
					$markuparray['intGTXMarkUpAmount']=$intGTXMarkUpAmount;
					$markuparray['intTotalAmount']=$intTotalAmount;
					$markuparray['intTax']=$XServiceTaxAmount;
					$markuparray['GTXServiceTaxAmount']=$GTXServiceTaxAmount;
					$markuparray['AgentServiceTaxAmount']=$AgentServiceTaxAmount;
					$markuparray['AgentsCustomServiceTaxAmount']=$AgentsCustomServiceTaxAmount;
					$markuparray['Pax']=count($roomjsonarray);
					$markuparray['SupplierSourceStr']='ACTIVITY';
					$markuparray['TotalDiscount']=$travelPlanDetail[0]['DiscountVal']; //0
					$markuparray['CurrencyType']=$travelPlanDetail[0]['CurrencyType'];
					$markuparray['MarketPlaceId']=($travelPlanDetail[0]['IsB2BProposal']==1)?2:1;
			}
						//echo "<pre>";print_r($markuparray);
        $this->view->guid = $this->GUID();    
		$encryptMarkUpData=$this->getEnc(json_encode($markuparray));
        $this->view->walletCode = $this->walletCode($travelPlanDetail[0]['AgentSysId'], $this->view->guid, round($intGrandPayableAmount), $AgencySysId, $travelPlanDetail[0]['TPSysId'],$travelPlanDetail[0]['CustomerSysId'],$encryptMarkUpData);
        $this->view->securecode = $this->secureCode($AgencySysId, $this->view->guid);
		$agencyAddress='';	
		if(isset($getAgencyDetail['CountrySysId']) && !empty($getAgencyDetail['StateOrZoneSysId']) && !empty($getAgencyDetail['CitySysId'])){
			$agencyAddress=$crmcustomerObj->GetNameOfContStateCity($getAgencyDetail['CountrySysId'],$getAgencyDetail['StateOrZoneSysId'],$getAgencyDetail['CitySysId']);
		}
		$agencyState='';
		$agencyCountry='';
		if(isset($agencyAddress['StateName']) && !empty($agencyAddress['StateName'])){
			$agencyState=$agencyAddress['StateName']?" ,".$agencyAddress['StateName']:'';
		}
		if(isset($agencyAddress['countryName']) && !empty($agencyAddress['countryName'])){
			$agencyCountry=$agencyAddress['countryName']?"(".$agencyAddress['countryName'].")":'';
		}
		//end of customer detail

		//query for get customer chat history
            $objAgencyUser = new Travel_Model_CRM_AgencyUserInbox();
			$getChatHistoryDetail=array();
            $checkCustomerChatExist = (@$getCustomerDetail[0]['CustomerSysId'] > 0) ? $objAgencyUser->CheckCustomerMsgCount(@$getCustomerDetail[0]['CustomerSysId'], $TPSysId,trim($travelPlanDetail[0]['AgentSysId'])) : array();
           // $checkCustomerChatExist = (count($checkCustomerChatExist)==0)?$objAgencyUser->CheckCustomerMsgCount(@$getcustomerDetail[0]['CustomerSysId'], $tpID):$checkCustomerChatExist;
                if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
                    $getChatHistoryDetail = $objAgencyUser->GetCustChatHistDetWithLead($TPSysId, $getCustomerDetail[0]['CustomerSysId'], 'ASC');
				}
			$getCustomerDetail['userChatExist'] = (count($checkCustomerChatExist)>0)?count($checkCustomerChatExist):count($getChatHistoryDetail);
            //  $this-view->getCustomerDetails = $getcustomerDetail;
            //query for get customer chat history
            $chatSenderDetails = array();
            if($getCustomerDetail['userChatExist'] > 0) {
                if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
                    $this->view->chatHistoryDetail = $getChatHistoryDetail;
                    $chatSenderDetails['TPSysId'] = $TPSysId;
                    $chatSenderDetails['AgencySysId'] = $travelPlanDetail[0]['AgencySysId'];
                    $chatSenderDetails['CustomerSysId'] = $getCustomerDetail[0]['CustomerSysId'];
                    $chatSenderDetails['AgentSysId'] = $travelPlanDetail[0]['AgentSysId'];
                    $chatSenderDetails['EmailId'] = $getAgentDetail['EmailId'];
                    //print_r($agentDetail);
                }
            }
			//end of customer chat history


			//send email to agent when customer open proposal
				$isPlanViewed=$this->_crmcusttravelplan->GetTravelPlanType($mid);
				//echo "<pre>";print_r($getAgentDetail);die;
				if($isPlanViewed['IsPlanViewed']==0){
						$proposalList=$this->_crmcusttravelplan->GetCustomerActivityProposal($mid);
						//echo "<pre>";print_r($proposalList);die;
						$emailSendId=trim($getAgencyDetail['PrimaryEmail']);
						$fromName=(isset($getAgencyDetail['DisplayName']) && !empty($getAgencyDetail['DisplayName']))?trim($getAgencyDetail['DisplayName']):trim(trim($getAgencyDetail['Title']));
						//$emailId = 'amit.k@catpl.co.in';
							$emailId = trim($getAgentDetail['EmailId']);
							$html = new Zend_View();
							$html->setScriptPath(APPLICATION_PATH . '/views/scripts/proposal/');
							$html->assign('type', 'OtherServicesViewSendEmailToAgent');
							$html->assign('customerDetails', $getCustomerDetail);
							$html->assign('agentDetails', $getAgentDetail);
							$html->assign('agencyDetails', $getAgencyDetail);
							$link=$this->view->baseUrl("/proposal/booking-activity-review-customer/mid/".base64_encode($mid)."/tpid/".base64_encode($TPSysId));
							$html->assign('link',$link);
							$html->assign('data',$proposalList);
							//$html->assign('data', $hotelValues);
							$bodyText = $html->render('email-template.phtml');
							$emailData = array('fromEmail'=>trim($emailSendId),'fromName'=>trim($fromName),'subject'=>'HelloGTX - Proposal Open Alert !','to'=>array(trim($emailId)),'bodyHtml'=>$bodyText,'bodyText'=>'');
							$arrEmailStatisticsType = array_keys(unserialize(ARR_EMAIL_STATISTICS_TYPE));
							$arrEmailStatistics = array(
								"TPSysId" => $proposalList[0]['TPSysId'],
								"TypeSysId" => 1,  // 1 For Email 2 For SMS
								"AgencySysId" => $proposalList[0]['AgencySysId'],
								"AgentSysId" => $proposalList[0]['AgentSysId'],
								"Title" => $bodyText,
								"Source" => $arrEmailStatisticsType[2], // 3 For Resend proposal
								"Status" => 0,
								"RefSysId" => "",
								"RefSysStatus" => "",
								"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
							);
							$this->mailSentByElastice($emailData,$arrEmailStatistics);

						//send sms
							$mobile_no = trim($getAgentDetail['ContactNo1']);
							$updateData = new Payment_Model_Checkotp();
							//$massage = "Your Customer(".trim($getcustomerDetail[0]['Contacts']).") has just opened the proposal. Team HelloGTX";
							$params['TPSysId']=$TPSysId;
							$params['shared_url']=$link;
							$params['AgencySysId']=$proposalList[0]['AgencySysId'];
							$params['AgentSysId']=$proposalList[0]['AgentSysId'];
							$shorturl_response = Zend_Controller_Action_HelperBroker::getStaticHelper('ShortUrl')->url_get($params);
							if (isset($shorturl_response['status_code']) && $shorturl_response['status_code'] == 200) {
								$link = $shorturl_response['data']['short_url'];
							}                
							$massage = "Your Customer(" . trim($getCustomerDetail[0]['FirstName']) . " " . trim($getCustomerDetail[0]['LastName']) . "-" . trim($getCustomerDetail[0]['Contacts']) . ") has just opened the proposal for " . trim(stripslashes($proposalList[0]['DestinationPlaces'])) . ",Click: " . $link . " to view and assist for finalizing.";
							$this->postFields = "";
							$this->postFields .="&method=$this->SMSMETHOD";
							$this->postFields .="&api_key=$this->SMSAPIKEY";
							$this->postFields .="&to=$mobile_no";
							$this->postFields .="&sender=$this->SMSSENDER";
							$this->postFields .="&message=$massage";
							$this->postFields .="&format=$this->SMSFORMAT";
							$postURL = $this->SMSURL;

							$arrSMSStatisticsType = array_keys(unserialize(ARR_SMS_STATISTICS_TYPE));
							$arrSMSStatistics = array(
								"TPSysId" => $TPSysId,
								"TypeSysId" => 2,  // 1 For Email 2 For SMS
								"AgencySysId" => $proposalList[0]['AgencySysId'],
								"AgentSysId" => $proposalList[0]['AgentSysId'],
								"Title" => $massage,
								"Source" => $arrSMSStatisticsType[0], // 2 For Resend
								"Status" => 0,
								"RefSysId" => "",
								"RefSysStatus" => "",
								"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
							);

							//$resultVal = $updateData->sendSmsDetails($postURL, $this->postFields,$arrSMSStatistics);
							$resultVal['status'] = 'OK';
							if (isset($resultVal['status']) && $resultVal['status'] == 'OK') {
								$errorMessage = "";
							} else {
								$errorMessage = "Oops! Please try again";
							}
						//end of send sms

						$data = array(
							'isPlanViewed' => 1,
							'UpdateDate' => date('Y-m-d H:i:s'),
						);
						$where = "TPSysId = " . $mid;
						$updatetravelplanrecord = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($data, $where);
				}
			//#end


			$IsB2CSite=$getAgentDetail['IsB2CSite'];
			$IsPaymentGateway=$getAgentDetail['IsPaymentGateway'];
			//print_r($getAgentDetail);
			if(!empty($IsB2CSite) && !empty($IsPaymentGateway)){
				$this->view->strPayWithWalletUrl = Catabatic_Helper::getSiteUrl()."payment/atom-payment/customer-payment";
			}else{
				if(!empty($IsPaymentGateway)){
					$this->view->strPayWithWalletUrl = Catabatic_Helper::getSiteUrl()."payment/payment-options/customer-pay-by-agency";
				} else {
					$this->view->strPayWithWalletUrl = Catabatic_Helper::getSiteUrl()."payment/payment-options/customer-pay";
				}
			}
		$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
		$this->view->getAgentDetail=$getAgentDetail;
		$this->view->agencyDetails=$getAgencyDetail;
		$this->view->guestDetail=$guestDetails;
		$this->view->getcustomerDetail = $getCustomerDetail;
		$this->view->chatSenderDetails = $chatSenderDetails;
		$this->view->encryptMarkUpData=$encryptMarkUpData;
		$this->view->travelPlanDetail=$travelPlanDetail;
		$this->view->arrActivityDetails=$arrActivityDetails;
		$objThings = new Cityprofiling_Model_TblCityprofiling();
		$this->view->arrThingsToCarryList=$objThings->getThingsToCarryList();
        //Get Activities Group Type List 
		$objActivities = new Travel_Model_TblActivities();
		$this->view->arrActivitiesGroupTypeList = $objActivities->getAllActivityGroupTypeList();

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

		$this->view->tpid=$TPSysId;

		$encydataForTnc=$this->getEnc($travelPlanDetail[0]['TPSysId'].":".$travelPlanDetail[0]['AgencySysId'].":".$travelPlanDetail[0]['CustomerSysId']);
		$this->view->encid=$encydataForTnc;

		} else {
			echo "Please try again";
			die;
		}
	}
    public function makeActivityPaymentAction() {
       
	   //echo "<pre>";print_r($_REQUEST);die;
        $objTrx = new Travel_Model_TblAgencyCustomerTrx();
        $intXRefTrxNo = $this->getRequest()->getParam('TrxId');
        $strTrxStatus = $this->getRequest()->getParam('status');
		$GUID=$this->getRequest()->getParam('GUID');
        $planId=$this->getRequest()->getParam('TpSysId');
		$MasterTPSysId='';
		$createDate = date('Y-m-d H:i:s');
		$customHelper = Zend_Controller_Action_HelperBroker::getStaticHelper("Custom");
			$travelplanObj = new Travel_Model_CRM_CustomerTravelPlan();
			$travelPlanDetail=$travelplanObj->GetActivityCustomerDetailsPax($planId);
			$MasterTPSysId=$travelPlanDetail[0]['MasterTPSysId'];
		   if($planId != ''){ //echo "HI"; exit;
            if($strTrxStatus == "success") {
			//echo "<pre>";print_r($travelPlanDetail);die;
			$API_SOURCE_ID=$travelPlanDetail[0]['PlanType'];
			$uid=$travelPlanDetail[0]['CustomerSysId'].':'.$planId.':'.$MasterTPSysId;
			$uid=base64_encode($this->getEnc($uid));
			$RoomMemInfoJson=json_decode($travelPlanDetail[0]['RoomInfoJson'],1);
			$totalPax=count($RoomMemInfoJson);
				$roominfojson=isset($travelPlanDetail[0]['RoomMemInfoJson'])?json_decode($travelPlanDetail[0]['RoomMemInfoJson'],1):array();
				$memberDetails=array();
				if(!empty($roominfojson) ){
					for ($d = 1; $d <= count($roominfojson); $d++) {
						$memberDetails[] = array('FirstName' => $roominfojson[$d]['FirstName'], 'LastName' => $roominfojson[$d]['LastName'], 'DOB' => @$roominfojson[$d]['DOB']);
					}
				}
						
							if(isset($MasterTPSysId) && $MasterTPSysId > 0){	
								$whereMaste = "MasterTPSysId = " . $MasterTPSysId;
								$disableAlltravelplan = array(
									'StatusType' => 10,
									'UpdateDate' => $createDate
								);
								$disableAlltravelplan = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($disableAlltravelplan, $whereMaste);
							}
							$where = "TPSysId = " . $planId;
							$updatetravelplan = array(
								'StatusType' => 17,
								'UpdateDate' => $createDate
							);
							$updatetravelPlan = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($updatetravelplan, $where);
							
							// update main query status created by Er Amit Kumar Dubey on 8 may 2017 at 11:23 AM
								$statusArray=$customHelper->changeQueryStatusByProposal();
								$querystatus=$statusArray[17];
								if(isset($querystatus) && !empty($querystatus)){
									$whereQuery = "TPSysId = " . $MasterTPSysId;
									$updatetravelplanquery = array(
										'StatusType' => $querystatus,
										'UpdateDate' => $createDate
									);
									$updatetravelPlanQuery = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($updatetravelplanquery, $whereQuery);
								}
								
							//update accom table with bookingid
							$where = "TPIntSysId = " . $travelPlanDetail[0]['TPIntSysId'];
							//$XRefVoucherNo=$planId."/".$intXRefTrxNo;
							$updateQuery = array(
								'XRefVoucherNo' =>$intXRefTrxNo."/".$GUID,
								'XRefBookingId' =>$GUID,
								'UpdateDate' => $createDate
							);
							$objCurd = new Activity_Model_Activity();
							$visaQueryPrposalTravelPlanId = $objCurd->updateTable("TB_Agency_Customer_TravelPlan_Itenary_Events",$updateQuery,$where);
							$msgArray=array('status'=>'success','msg'=>'Your payment is success');
							$PAYMENT_MSG = new Zend_Session_Namespace('PAYMENT_MSG');
							$PAYMENT_MSG->PAYMENT_MSG=$msgArray;

							//send email to customer
									$html = new Zend_View();
									$html->setScriptPath(APPLICATION_PATH . '/views/scripts/proposal/');
									$agencyStaffObj = new Travel_Model_TblAgencyStaff();
									$agentDetail=$agencyStaffObj->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
									$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
									$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1'],'AgentEmail'=>$agentDetail['EmailId'],'Signature'=>trim($agentDetail['Signature']));
									$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
									$objActivity = new Activity_Model_Activity();
									$arrActivityDetails = $objActivity->activityDetailById($travelPlanDetail[0]['InvnItemSysId']);
									//echo "<pre>";print_r($getAgencyDetail);die;
									$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';

									$html->assign('type', 'ActivityBookingPaymentConfirmationEmail');
									$html->assign('data', $travelPlanDetail);
									$html->assign('getAgentDetail',$getAgentDetail);
									$html->assign('agencyDetails',$getAgencyDetail);
									$html->assign('arrActivityDetails',$arrActivityDetails);
									
									//$html->assign('URL', $encryptData);
									$paymentconfirmText = $html->render('email-template.phtml');
									$html->assign('type', 'ActivityBookingConfirmationEmailText');
									$html->assign('data', $travelPlanDetail);
									$html->assign('getAgentDetail',$getAgentDetail);
									$html->assign('agencyDetails',$getAgencyDetail);
									$html->assign('arrActivityDetails',$arrActivityDetails);
									$bookingConfirmText = $html->render('email-template.phtml');
									//$emailId ='amit.k@catpl.co.in';
									$emailId = trim($travelPlanDetail[0]['ProposalEmailTo']);
									$emailSendId = trim($getAgentDetail['AgentEmail']);
									$fromName = (isset($getAgencyDetail['DisplayName']) && !empty($getAgencyDetail['DisplayName'])) ? trim($getAgencyDetail['DisplayName']) : trim(trim($getAgencyDetail['Title']));
									if($emailId!=''){
										$emailData1 = array('fromEmail'=>$emailSendId,'fromName'=>$fromName,'subject'=>stripslashes($travelPlanDetail[0]['Title']).' Payment Receipt','to'=>array(trim($emailId)),'bodyHtml'=>$paymentconfirmText,'bodyText'=>'');
										$emailData2 = array('fromEmail'=>$emailSendId,'fromName'=>$fromName,'subject'=>stripslashes($travelPlanDetail[0]['Title']).' Booking Details','to'=>array(trim($emailId)),'bodyHtml'=>$bookingConfirmText,'bodyText'=>'');
										try {
											$arrEmailStatisticsType = array_keys(unserialize(ARR_EMAIL_STATISTICS_TYPE));
											$arrEmailStatistics = array(
												"TPSysId" => $planId,
												"TypeSysId" => 1,  // 1 For Email 2 For SMS
												"AgencySysId" => $travelPlanDetail[0]['AgencySysId'],
												"AgentSysId" => $travelPlanDetail[0]['AgentSysId'],
												"Title" => $paymentconfirmText,
												"Source" => $arrEmailStatisticsType[1], // 2 For Vouchers
												"Status" => 0,
												"RefSysId" => "",
												"RefSysStatus" => "",
												"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
											);
											$arrEmailStatistics2 = array(
												"TPSysId" => $planId,
												"TypeSysId" => 1,  // 1 For Email 2 For SMS
												"AgencySysId" => $travelPlanDetail[0]['AgencySysId'],
												"AgentSysId" => $travelPlanDetail[0]['AgentSysId'],
												"Title" => $bookingConfirmText,
												"Source" => $arrEmailStatisticsType[1], // 2 For Vouchers
												"Status" => 0,
												"RefSysId" => "",
												"RefSysStatus" => "",
												"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
											);
											//echo "success";
											$this->mailSentByElastice($emailData1,$arrEmailStatistics);
											$this->mailSentByElastice($emailData2,$arrEmailStatistics2);
											$msg="success";
										} catch (Exception $err) {
											//print_r($err, true);
											$msg="failed";
										}
									}
							//end of send email to customer
			} if($strTrxStatus == "failure" ){
					$where = "TPSysId = " . $planId;
					$updatetravelplan = array(
						'StatusType' => 7,
						'UpdateDate' => $createDate
					);
					$updatetravelPlan = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($updatetravelplan, $where);


					// update main query status created by Er Amit Kumar Dubey on 8 may 2017 at 11:27 AM
						$statusArray=$customHelper->changeQueryStatusByProposal();
						$querystatus=$statusArray[7];
						if(isset($querystatus) && !empty($querystatus)){
							$whereQuery = "TPSysId = " . $MasterTPSysId;
							$updatetravelplanquery = array(
								'StatusType' => $querystatus,
								'UpdateDate' => $createDate
							);
							$updatetravelPlanQuery = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($updatetravelplanquery, $whereQuery);
						}
						$msgArray=array('status'=>'failed','msg'=>'Your payment is unsuccessful'.$this->getRequest()->getParam('error_Message'));
						$PAYMENT_MSG = new Zend_Session_Namespace('PAYMENT_MSG');
						$PAYMENT_MSG->PAYMENT_MSG=$msgArray;
						//exit;
			}
		  }else{
				$msgArray=array('status'=>'failed','msg'=>'Your payment is unsuccessful Id Mismatch');
				$PAYMENT_MSG = new Zend_Session_Namespace('PAYMENT_MSG');
				$PAYMENT_MSG->PAYMENT_MSG=$msgArray;
		}
		$this->_redirect("/proposal/booking-activity-confirmation/mid/".base64_encode($MasterTPSysId)."/tpid/".base64_encode($planId));
		exit;
    }
	public function bookingActivityConfirmationAction(){
		$this->view->layout()->disableLayout();
		$proposalId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$TPSysId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('tpid')));
		$PAYMENT_MSG = new Zend_Session_Namespace('PAYMENT_MSG');
		if($TPSysId==''){
			$this->view->error=1;
			//echo "Please try again";
			//die;
		} else{
			$this->view->error=0;
		$travelPlanDetail=$this->_crmcusttravelplan->GetActivityCustomerDetailsPax($TPSysId);
		//echo "dddddddddd"."<pre>";print_r($travelPlanDetail);die;
		$CustomerSysId=$travelPlanDetail[0]['CustomerSysId'];
		$getCustomerDetail = $this->_crmcustomerObj->ChkAgencyUser($CustomerSysId);
//echo "<pre>";print_r($getCustomerDetail);
		//customer detail
				$CustomerSysId=$travelPlanDetail[0]['CustomerSysId'];
				$getLeadlist = $this->_crmcusttravelplan->GetPurchasedPublicPageLeadList($CustomerSysId, $travelPlanDetail[0]['AgencySysId'], $TPSysId);
				$API_SOURCE_ID=$travelPlanDetail[0]['PlanType'];
				$roomjsonarray=json_decode($travelPlanDetail[0]['RoomInfoJson'],1);				
				if($API_SOURCE_ID == "8"){
					$strCurrencyCode = $travelPlanDetail[0]['CurrencyType'];
					$Price = $travelPlanDetail[0]['Price'];
					$intTax = $travelPlanDetail[0]['XServiceTaxAmount'];
					$this->view->intTax =  $intTax = !empty($intTax)?($intTax):0;
					$this->view->intTotalAmount =  $intTotalAmount=$Price;
					$this->view->intAgentMarkUpAmount =  $intAgentMarkUpAmount = $travelPlanDetail[0]['MarkUp'];//$markupAgency->markupAg;
					$this->view->intAgencyMarkUpAmount =  $intAgencyMarkUpAmount = $travelPlanDetail[0]['AgencyMarkUp'];//$markupAgency->markupAg;
					$this->view->intGTXMarkUpAmount =  $intGTXMarkUpAmount = $travelPlanDetail[0]['GTXMarkup'];//$markupAgency->markupAg;
					$XServiceTaxAmount = $travelPlanDetail[0]['XServiceTaxAmount'];
					$GTXServiceTaxAmount = $travelPlanDetail[0]['GTXServiceTaxAmount'];
					$AgentServiceTaxAmount = $travelPlanDetail[0]['AgentServiceTaxAmount'];
					$AgentsCustomServiceTaxAmount = $travelPlanDetail[0]['AgentsCustomServiceTaxAmount'];
					$customDiscount = $travelPlanDetail[0]['CustomDiscount'];
					$serviceTaxOnCustomDiscount = $travelPlanDetail[0]['ServiceTaxOnCustomDiscount'];
					$this->view->intGrandPayableAmount =  $intGrandPayableAmount = round(($Price+$intAgentMarkUpAmount + $intAgencyMarkUpAmount + $intGTXMarkUpAmount + $XServiceTaxAmount + $GTXServiceTaxAmount + $AgentServiceTaxAmount + $AgentsCustomServiceTaxAmount)-($customDiscount+$serviceTaxOnCustomDiscount));
				}

		//query for get customer chat history
            $objAgencyUser = new Travel_Model_CRM_AgencyUserInbox();
			$getChatHistoryDetail=array();
            $checkCustomerChatExist = (@$getCustomerDetail[0]['CustomerSysId'] > 0) ? $objAgencyUser->CheckCustomerMsgCount(@$getCustomerDetail[0]['CustomerSysId'], $TPSysId,trim($travelPlanDetail[0]['AgentSysId'])) : array();
           // $checkCustomerChatExist = (count($checkCustomerChatExist)==0)?$objAgencyUser->CheckCustomerMsgCount(@$getcustomerDetail[0]['CustomerSysId'], $tpID):$checkCustomerChatExist;
                if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
                    $getChatHistoryDetail = $objAgencyUser->GetCustChatHistDetWithLead($TPSysId, $getCustomerDetail[0]['CustomerSysId'], 'ASC');
				}
			$getCustomerDetail['userChatExist'] = (count($checkCustomerChatExist)>0)?count($checkCustomerChatExist):count($getChatHistoryDetail);
            //query for get customer chat history
            $chatSenderDetails = array();
            $objAgencyStaff = new Travel_Model_TblAgencyStaff();
           $getAgentDetail=$this->_crmcusttravelplan->GetAgentDetails($travelPlanDetail[0]['AgentSysId']);
            if($getCustomerDetail['userChatExist'] > 0) {
                if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
                    $this->view->chatHistoryDetail = $getChatHistoryDetail;
					
                    $chatSenderDetails['TPSysId'] = $TPSysId;
                    $chatSenderDetails['AgencySysId'] = $travelPlanDetail[0]['AgencySysId'];
                    $chatSenderDetails['CustomerSysId'] = $getCustomerDetail[0]['CustomerSysId'];
                    $chatSenderDetails['AgentSysId'] = $travelPlanDetail[0]['AgentSysId'];
                    $chatSenderDetails['EmailId'] = $getAgentDetail['EmailId'];
                    //print_r($agentDetail);
                }
            }
			            //echo "<pre>";print_r($chatSenderDetails);

			//end of customer chat history
			$agencyStaffObj = new Travel_Model_TblAgencyStaff();
			$agentDetail=$agencyStaffObj->getUserDetailsById($getLeadlist[0]['AgentSysId']);
			$AgencySysId = $getLeadlist[0]['AgencySysId'];
			$getCustomerDetail[0]['TPSysId'] = $getLeadlist[0]['TPSysId'];
			$getCustomerDetail[0]['AgencySysId'] = $getLeadlist[0]['AgencySysId'];
			$getCustomerDetail[0]['AgentSysId'] = $getLeadlist[0]['AgentSysId'];
			//$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1'],'AgentEmail'=>$agentDetail['EmailId']);
			$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
			$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
			$this->view->getAgentDetail=$getAgentDetail;
			$this->view->agencyDetails=$getAgencyDetail;
			$this->view->travelPlanDetail=$travelPlanDetail;
			$this->view->getcustomerDetail = $getCustomerDetail;
			$this->view->chatSenderDetails = $chatSenderDetails;
			$encydataForTnc=$this->getEnc($travelPlanDetail[0]['TPSysId'].":".$travelPlanDetail[0]['AgencySysId'].":".$travelPlanDetail[0]['CustomerSysId']);
			$this->view->encid=$encydataForTnc;
		}
		//echo "<pre>";print_r($travelPlanDetail);die;
		$this->view->PAYMENT_MSG=$PAYMENT_MSG->PAYMENT_MSG;
   }
    public function activityVoucherAction() {
        $this->_helper->layout->disableLayout();
		$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$TPSysId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('pid')));
		if($TPSysId==''){
			echo "Please try again";
			die;
		}
		$travelPlanDetail=$this->_crmcusttravelplan->GetActivityCustomerDetailsTrx($TPSysId);
		$CustomerSysId=$travelPlanDetail[0]['CustomerSysId'];
		$getAgentDetail=$this->_crmcusttravelplan->getAgentDetails($travelPlanDetail[0]['AgentSysId']);
		$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
		$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
		$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
		$objActivity = new Activity_Model_Activity();
		$arrActivityDetails = $objActivity->activityDetailById($travelPlanDetail[0]['InvnItemSysId']);
		//echo "<pre>";print_r($travelPlanDetail);die;
		$this->view->getAgentDetail=$getAgentDetail;
		$this->view->getAgencyDetail=$getAgencyDetail;
		$this->view->travelPlanDetail=$travelPlanDetail;
		$this->view->arrActivityDetails=$arrActivityDetails;
   }
    public function activityInvoiceAction() {
        $this->_helper->layout->disableLayout(); 
		$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$TPSysId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('pid')));
		if($TPSysId==''){
			echo "Please try again";
			die;
		}
		$travelPlanDetail=$this->_crmcusttravelplan->GetActivityCustomerDetailsTrx($TPSysId);
		//echo "<pre>";print_r($travelPlanDetail);die;
		$objAgencyStaff = new Travel_Model_TblAgencyStaff();
		$agentDetail=$objAgencyStaff->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
		$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
		$getAgentDetail=$this->_crmcusttravelplan->GetAgentDetails($travelPlanDetail[0]['AgentSysId']);
		$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
		$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
		$objActivity = new Activity_Model_Activity();
		$arrActivityDetails = $objActivity->activityDetailById($travelPlanDetail[0]['InvnItemSysId']);
		$this->view->getAgentDetail=$getAgentDetail;
		$this->view->agencyDetails=$getAgencyDetail;
		$this->view->travelPlanDetail=$travelPlanDetail;
		$this->view->arrActivityDetails=$arrActivityDetails;
		//echo "<pre>";print_r($getAgencyDetail);die;
		$customhelper = Zend_Controller_Action_HelperBroker::getStaticHelper('Custom');
		$this->view->getallstatustype=$customhelper->getAllStatusType();
    }
    public function activityViewAction() {
       	$this->_helper->layout->disableLayout(); 
		$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$TPSysId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('pid')));
		if($TPSysId==''){
			echo "Please try again";
			die;
		}

		$travelPlanDetail=$this->_crmcusttravelplan->GetActivityCustomerDetailsTrx($TPSysId);
		
		//customer detail
			$travelplanObj = new Travel_Model_CRM_CustomerTravelPlan();
			//$travelPlanDetail=$travelplanObj->GetActivityCustomerDetailsPax($TPSysId);
			$CustomerSysId=$travelPlanDetail[0]['CustomerSysId'];

				if (isset($CustomerSysId) && !empty($CustomerSysId)) {
					$crmcustomerObj = new Travel_Model_CRM_Customer();
					$getCustomerDetail[]=$crmcustomerObj->GetAgencyCustomerById($travelPlanDetail[0]['CustomerSysId']);
					$objAgencyUser = new Travel_Model_CRM_AgencyUserInbox();
					$checkCustomerChatExist = $getCustomerDetail[0]['CustomerSysId'] > 0? $objAgencyUser->CheckCustomerMsgCount($getCustomerDetail[0]['CustomerSysId'],$TPSysId):array();
					$getversiondetails = $this->_crmcusttravelplan->GetVersionInfo($TPSysId);
					$getCustomerDetail['userChatExist']=count($checkCustomerChatExist);
				}
		//end of customer detail
		//query for get customer chat history
			$chatSenderDetails=array();
			if($getCustomerDetail['userChatExist'] > 0){
					if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
						$getChatHistoryDetail = $objAgencyUser->GetCustChatHistDetWithLead($TPSysId,$getCustomerDetail[0]['CustomerSysId'],'ASC');
						$this->view->chatHistoryDetail=$getChatHistoryDetail;
						$chatSenderDetails['TPSysId']=$TPSysId;
						$chatSenderDetails['AgencySysId']=$travelPlanDetail[0]['AgencySysId'];
						$chatSenderDetails['CustomerSysId']=$travelPlanDetail[0]['CustomerSysId'];
						$chatSenderDetails['AgentSysId']=$travelPlanDetail[0]['AgentSysId'];
						//$chatSenderDetails['EmailId']=$getcustomerDetail[0]['EmailId'];
						$objAgencyStaff   =	new Travel_Model_TblAgencyStaff();
						$agentDetail=$objAgencyStaff->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
						$chatSenderDetails['EmailId']=$agentDetail['EmailId'];
						//print_r($agentDetail);
						
						
					}
			}
			//end of customer chat history
			$getAgentDetail=$this->_crmcusttravelplan->GetAgentDetails($travelPlanDetail[0]['AgentSysId']);
			$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
			//$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1']);
			$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
			$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
			$this->view->getAgentDetail=$getAgentDetail;
			$this->view->agencyDetails=$getAgencyDetail;
			$this->view->getcustomerDetail = $getCustomerDetail;
			$this->view->travelPlanDetail=$travelPlanDetail;
			$ARR_SALUTION=unserialize(ARR_SALUTION);
			$this->view->ARR_SALUTION=$ARR_SALUTION;
			$encydataForTnc=$this->getEnc($travelPlanDetail[0]['TPSysId'].":".$travelPlanDetail[0]['AgencySysId'].":".$travelPlanDetail[0]['CustomerSysId']);
			$this->view->encid=$encydataForTnc;
    }
	//for other services preview insurance
	public function previewInsuranceResultAction(){
		$this->_helper->layout->disableLayout();
		$TPSysId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		if(isset($TPSysId) && !empty($TPSysId)){
			$proposalList=$this->_crmcusttravelplan->GetCustomerInsuranceProposal($TPSysId);
			$leadDetail=$this->_crmcusttravelplan->GetTravelPlanByCustomer($TPSysId);
		//echo "<pre>";print_r($proposalList);die;
		if($proposalList[0]['StatusType']==17){
			$this->_redirect('/proposal/booking-confirmation/mid/'.base64_encode($TPSysId));
			exit;
		}
			$crmcustomerObj = new Travel_Model_CRM_Customer();
			$getCustomerDetail[]=$crmcustomerObj->GetAgencyCustomerById($leadDetail[0]['CustomerSysId']);
			//print_r($getCustomerDetail);
			$CustomerSysId=$getCustomerDetail[0]['CustomerSysId'];
		//query for get customer chat history
            $objAgencyUser = new Travel_Model_CRM_AgencyUserInbox();
			$getChatHistoryDetail=array();
            $checkCustomerChatExist = (@$getCustomerDetail[0]['CustomerSysId'] > 0) ? $objAgencyUser->CheckCustomerMsgCount(@$getCustomerDetail[0]['CustomerSysId'], $TPSysId,trim($proposalList[0]['AgentSysId'])) : array();
                if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
                    $getChatHistoryDetail = $objAgencyUser->GetCustChatHistDetWithLead($TPSysId, $getCustomerDetail[0]['CustomerSysId'], 'ASC');
				}
			$getCustomerDetail['userChatExist'] = (count($checkCustomerChatExist)>0)?count($checkCustomerChatExist):count($getChatHistoryDetail);

            //query for get customer chat history
            $chatSenderDetails = array();
            $objAgencyStaff = new Travel_Model_TblAgencyStaff();
            $agentDetail = $objAgencyStaff->getUserDetailsById($proposalList[0]['AgentSysId']);
            if($getCustomerDetail['userChatExist'] > 0) {
                if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
                    $this->view->chatHistoryDetail = $getChatHistoryDetail;
                    $chatSenderDetails['TPSysId'] = $TPSysId;
                    $chatSenderDetails['AgencySysId'] = $intLoggedinUserAgencySysId;
                    $chatSenderDetails['CustomerSysId'] = $getCustomerDetail[0]['CustomerSysId'];
                    $chatSenderDetails['AgentSysId'] = $proposalList[0]['AgentSysId'];
                    $chatSenderDetails['EmailId'] = $agentDetail['EmailId'];
                    //print_r($agentDetail);
                }
            }
			//end of customer chat history
			//end of customer chat history
			$agencyStaffObj = new Travel_Model_TblAgencyStaff();
			$agentDetail=$agencyStaffObj->getUserDetailsById($proposalList[0]['AgentSysId']);
			$AgencySysId = $proposalList[0]['AgencySysId'];
			$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1']);
			$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
			$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';

			//send email to agent when customer open proposal
				$isPlanViewed=$this->_crmcusttravelplan->GetTravelPlanType($TPSysId);
				//echo "<pre>";print_r($proposalList);die;
				if($isPlanViewed['IsPlanViewed']==0){
						$emailSendId=trim($getAgencyDetail['PrimaryEmail']);
						$fromName=(isset($getAgencyDetail['DisplayName']) && !empty($getAgencyDetail['DisplayName']))?trim($getAgencyDetail['DisplayName']):trim(trim($getAgencyDetail['Title']));
						//$emailId = 'amit.k@catpl.co.in';
						$emailId = trim($agentDetail['EmailId']);
							$html = new Zend_View();
							$html->setScriptPath(APPLICATION_PATH . '/views/scripts/proposal/');
							$html->assign('type', 'OtherServicesViewSendEmailToAgent');
							$html->assign('customerDetails', $getCustomerDetail);
							$html->assign('agentDetails', $agentDetail);
							$html->assign('agencyDetails', $getAgencyDetail);
							$link=$this->view->baseUrl("/proposal/preview-sightseeing-result/mid/".base64_encode($TPSysId)."/type/");
							$html->assign('link',$link);
							$html->assign('data',$proposalList);
							//$html->assign('data', $hotelValues);
							$bodyText = $html->render('email-template.phtml');
							$emailData = array('fromEmail'=>trim($emailSendId),'fromName'=>trim($fromName),'subject'=>'HelloGTX - Proposal Open Alert !','to'=>array(trim($emailId)),'bodyHtml'=>$bodyText,'bodyText'=>'');
							$arrEmailStatisticsType = array_keys(unserialize(ARR_EMAIL_STATISTICS_TYPE));
							$arrEmailStatistics = array(
								"TPSysId" => $proposalList[0]['TPSysId'],
								"TypeSysId" => 1,  // 1 For Email 2 For SMS
								"AgencySysId" => $proposalList[0]['AgencySysId'],
								"AgentSysId" => $proposalList[0]['AgentSysId'],
								"Title" => $bodyText,
								"Source" => $arrEmailStatisticsType[2], // 3 For Resend proposal
								"Status" => 0,
								"RefSysId" => "",
								"RefSysStatus" => "",
								"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
							);
							$this->mailSentByElastice($emailData,$arrEmailStatistics);

						//send sms
							$mobile_no = trim($agentDetail['ContactNo1']);
							$updateData = new Payment_Model_Checkotp();
							//$massage = "Your Customer(".trim($getcustomerDetail[0]['Contacts']).") has just opened the proposal. Team HelloGTX";
							$params['TPSysId']=$TPSysId;
							$params['shared_url']=$link;
							$params['AgencySysId']=$proposalList[0]['AgencySysId'];
							$params['AgentSysId']=$proposalList[0]['AgentSysId'];
							$shorturl_response = Zend_Controller_Action_HelperBroker::getStaticHelper('ShortUrl')->url_get($params);
							if (isset($shorturl_response['status_code']) && $shorturl_response['status_code'] == 200) {
								$link = $shorturl_response['data']['short_url'];
							}                
							$massage = "Your Customer(" . trim($getCustomerDetail[0]['FirstName']) . " " . trim($getCustomerDetail[0]['LastName']) . "-" . trim($getCustomerDetail[0]['Contacts']) . ") has just opened the proposal for " . trim(stripslashes($proposalList[0]['DestinationPlaces'])) . ",Click: " . $link . " to view and assist for finalizing.";
							$this->postFields = "";
							$this->postFields .="&method=$this->SMSMETHOD";
							$this->postFields .="&api_key=$this->SMSAPIKEY";
							$this->postFields .="&to=$mobile_no";
							$this->postFields .="&sender=$this->SMSSENDER";
							$this->postFields .="&message=$massage";
							$this->postFields .="&format=$this->SMSFORMAT";
							$postURL = $this->SMSURL;

							$arrSMSStatisticsType = array_keys(unserialize(ARR_SMS_STATISTICS_TYPE));
							$arrSMSStatistics = array(
								"TPSysId" => $TPSysId,
								"TypeSysId" => 2,  // 1 For Email 2 For SMS
								"AgencySysId" => $proposalList[0]['AgencySysId'],
								"AgentSysId" => $proposalList[0]['AgentSysId'],
								"Title" => $massage,
								"Source" => $arrSMSStatisticsType[0], // 2 For Resend
								"Status" => 0,
								"RefSysId" => "",
								"RefSysStatus" => "",
								"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
							);

							//$resultVal = $updateData->sendSmsDetails($postURL, $this->postFields,$arrSMSStatistics);
							$resultVal['status'] = 'OK';
							if (isset($resultVal['status']) && $resultVal['status'] == 'OK') {
								$errorMessage = "";
							} else {
								$errorMessage = "Oops! Please try again";
							}
						//end of send sms

						$data = array(
							'isPlanViewed' => 1,
							'UpdateDate' => date('Y-m-d H:i:s'),
						);
						$where = "TPSysId = " . $TPSysId;
						$updatetravelplanrecord = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($data, $where);
				}
			//#end
			$this->view->getAgentDetail=$getAgentDetail;
			$this->view->agencyDetails=$getAgencyDetail;
			$this->view->getcustomerDetail = $getCustomerDetail;
			$this->view->chatSenderDetails=$chatSenderDetails;
			$this->view->leadDetail=$leadDetail;
			$this->view->proposalList=$proposalList;
			$this->view->mid=$TPSysId;
		}

	}
	public function bookingInsuranceReviewCustomerAction(){
		$this->view->layout()->disableLayout();
		$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$TPSysId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('tpid')));
        $this->view->strPayWithWalletUrl = Catabatic_Helper::getSiteUrl()."payment/payment-options/customer-pay";
        $this->view->strRechargeNowUrl = Catabatic_Helper::getSiteUrl()."payment/payment-options";
        $this->view->strSearchPageUrl = "/buyhotel/search-results";
        $this->view->intPlanType = "2";
        $this->view->strTrxType = "H";
		if(isset($TPSysId) && !empty($TPSysId)){
			$travelPlanDetail=$this->_crmcusttravelplan->GetCustomerInsuranceleadDetail($TPSysId);
			$crmcustomerObj = new Travel_Model_CRM_Customer();
			$getCustomerDetail[]=$crmcustomerObj->GetAgencyCustomerById($travelPlanDetail[0]['CustomerSysId']);

			$this->view->mid=$travelPlanDetail[0]['MasterTPSysId'];
			$agencyStaffObj = new Travel_Model_TblAgencyStaff();
			$agentDetail=$agencyStaffObj->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
			$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
			$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1']);
			$crmcustomerObj = new Travel_Model_CRM_Customer();
			$getAgencyDetail=$crmcustomerObj->GetAgencyDetailById($AgencySysId);
			$guestDetails=$crmcustomerObj->GetCustomerWithDetails($travelPlanDetail[0]['CustomerSysId']);
		
		// for wallet use
        $this->view->strReturnURL = Catabatic_Helper::getSiteUrl()."proposal/make-insurance-payment/cid/".base64_encode($travelPlanDetail[0]['CustomerSysId'])."/tid/".base64_encode($travelPlanDetail[0]['TPIntSysId']);
        $this->view->strErrorURL = Catabatic_Helper::getSiteUrl()."proposal/make-insurance-payment/cid/".base64_encode($travelPlanDetail[0]['CustomerSysId'])."/tid/".base64_encode($travelPlanDetail[0]['TPIntSysId']);
		$this->view->intLoggedinAgencySysId = $AgencySysId;
		$this->view->IsCardChrgToCustomer = $travelPlanDetail[0]['IsCardChrgToCustomer'];
		$this->view->intLoggedinUserAgencySysId = $AgencyUserSysId=$travelPlanDetail[0]['AgentSysId'];
		$API_SOURCE_ID=$travelPlanDetail[0]['PlanType'];
		$roomjsonarray=json_decode($travelPlanDetail[0]['RoomInfoJson'],1);
			if($API_SOURCE_ID ==4){ // 
								$strCurrencyCode = 'INR';
								$Price = $travelPlanDetail[0]['Price'];
								$intTax = $travelPlanDetail[0]['XServiceTaxAmount'];
								$this->view->intTax =  $intTax = !empty($intTax)?($intTax):0;
								$this->view->intTotalAmount =  $intTotalAmount=$Price;
								$this->view->intAgentMarkUpAmount =  $intAgentMarkUpAmount = $travelPlanDetail[0]['MarkUp'];//$markupAgency->markupAg;
								$this->view->intAgencyMarkUpAmount =  $intAgencyMarkUpAmount = $travelPlanDetail[0]['AgencyMarkUp'];//$markupAgency->markupAg;
								$this->view->intGTXMarkUpAmount =  $intGTXMarkUpAmount = $travelPlanDetail[0]['GTXMarkup'];//$markupAgency->markupAg;
								$XServiceTaxAmount = $travelPlanDetail[0]['XServiceTaxAmount'];
								$GTXServiceTaxAmount = $travelPlanDetail[0]['GTXServiceTaxAmount'];
								$AgentServiceTaxAmount = $travelPlanDetail[0]['AgentServiceTaxAmount'];
								$AgentsCustomServiceTaxAmount = $travelPlanDetail[0]['AgentsCustomServiceTaxAmount'];
								$customDiscount = $travelPlanDetail[0]['CustomDiscount'];
								$serviceTaxOnCustomDiscount = $travelPlanDetail[0]['ServiceTaxOnCustomDiscount'];
								$this->view->intGrandPayableAmount =  $intGrandPayableAmount = round(($Price+$intAgentMarkUpAmount + $intAgencyMarkUpAmount + $intGTXMarkUpAmount + $XServiceTaxAmount + $GTXServiceTaxAmount + $AgentServiceTaxAmount + $AgentsCustomServiceTaxAmount)-($customDiscount+$serviceTaxOnCustomDiscount));
								$markuparray['intAgentMarkUpAmount']=$intAgentMarkUpAmount;
								$markuparray['intAgencyMarkUpAmount']=$intAgencyMarkUpAmount;
								$markuparray['intGTXMarkUpAmount']=$intGTXMarkUpAmount;
								$markuparray['intTotalAmount']=$intTotalAmount;
								$markuparray['intTax']=$XServiceTaxAmount;
								$markuparray['GTXServiceTaxAmount']=$GTXServiceTaxAmount;
								$markuparray['AgentServiceTaxAmount']=$AgentServiceTaxAmount;
								$markuparray['AgentsCustomServiceTaxAmount']=$AgentsCustomServiceTaxAmount;
								$markuparray['Pax']=count($roomjsonarray);
								$markuparray['SupplierSourceStr']='VISA';
								$markuparray['TotalDiscount']=$travelPlanDetail[0]['DiscountVal']; //0
								$markuparray['CurrencyType']=$travelPlanDetail[0]['CurrencyType'];
						}
        $this->view->guid = $this->GUID();    
		$encryptMarkUpData=$this->getEnc(json_encode($markuparray));
        $this->view->walletCode = $this->walletCode($travelPlanDetail[0]['AgentSysId'], $this->view->guid, round($intGrandPayableAmount), $AgencySysId, $travelPlanDetail[0]['TPSysId'],$travelPlanDetail[0]['CustomerSysId'],$encryptMarkUpData);
        $this->view->securecode = $this->secureCode($this->intLoggedinUserAgencySysId, $this->view->guid);
		$agencyAddress='';	
		if(isset($getAgencyDetail['CountrySysId']) && !empty($getAgencyDetail['StateOrZoneSysId']) && !empty($getAgencyDetail['CitySysId'])){
			$agencyAddress=$crmcustomerObj->GetNameOfContStateCity($getAgencyDetail['CountrySysId'],$getAgencyDetail['StateOrZoneSysId'],$getAgencyDetail['CitySysId']);
		}
		$agencyState='';
		$agencyCountry='';
		if(isset($agencyAddress['StateName']) && !empty($agencyAddress['StateName'])){
			$agencyState=$agencyAddress['StateName']?" ,".$agencyAddress['StateName']:'';
		}
		if(isset($agencyAddress['countryName']) && !empty($agencyAddress['countryName'])){
			$agencyCountry=$agencyAddress['countryName']?"(".$agencyAddress['countryName'].")":'';
		}
		//end of customer detail

		//query for get customer chat history
            $objAgencyUser = new Travel_Model_CRM_AgencyUserInbox();
			$getChatHistoryDetail=array();
            $checkCustomerChatExist = (@$getCustomerDetail[0]['CustomerSysId'] > 0) ? $objAgencyUser->CheckCustomerMsgCount(@$getCustomerDetail[0]['CustomerSysId'], $TPSysId,trim($travelPlanDetail[0]['AgentSysId'])) : array();
           // $checkCustomerChatExist = (count($checkCustomerChatExist)==0)?$objAgencyUser->CheckCustomerMsgCount(@$getcustomerDetail[0]['CustomerSysId'], $tpID):$checkCustomerChatExist;
                if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
                    $getChatHistoryDetail = $objAgencyUser->GetCustChatHistDetWithLead($TPSysId, $getCustomerDetail[0]['CustomerSysId'], 'ASC');
				}
			$getCustomerDetail['userChatExist'] = (count($checkCustomerChatExist)>0)?count($checkCustomerChatExist):count($getChatHistoryDetail);
            //  $this-view->getCustomerDetails = $getcustomerDetail;
            //query for get customer chat history
            $chatSenderDetails = array();
            $objAgencyStaff = new Travel_Model_TblAgencyStaff();
            $agentDetail = $objAgencyStaff->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
            if($getCustomerDetail['userChatExist'] > 0) {
                if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
                    $this->view->chatHistoryDetail = $getChatHistoryDetail;
                    $chatSenderDetails['TPSysId'] = $TPSysId;
                    $chatSenderDetails['AgencySysId'] = $travelPlanDetail[0]['AgencySysId'];
                    $chatSenderDetails['CustomerSysId'] = $getCustomerDetail[0]['CustomerSysId'];
                    $chatSenderDetails['AgentSysId'] = $travelPlanDetail[0]['AgentSysId'];
                    $chatSenderDetails['EmailId'] = $agentDetail['EmailId'];
                    //print_r($agentDetail);
                }
            }
			//end of customer chat history
		$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
		$this->view->getAgentDetail=$getAgentDetail;
		$this->view->agencyDetails=$getAgencyDetail;
		$this->view->guestDetail=$guestDetails;
		$this->view->getcustomerDetail = $getCustomerDetail;
		$this->view->chatSenderDetails = $chatSenderDetails;
		$this->view->encryptMarkUpData=$encryptMarkUpData;
		$this->view->travelPlanDetail=$travelPlanDetail;


		$this->view->tpid=$TPSysId;
		} else {
			echo "Please try again";
			die;
		}
	}
    public function makeInsurancePaymentAction() {
       
	  // echo "<pre>";print_r($_REQUEST);die;
        $objTrx = new Travel_Model_TblAgencyCustomerTrx();
        $intXRefTrxNo = $this->getRequest()->getParam('txnid');
        $strTrxStatus = $this->getRequest()->getParam('status');
        $planId=$this->getRequest()->getParam('TpSysId');
		$MasterTPSysId='';
		$createDate = date('Y-m-d H:i:s');
		   if($planId != ''){ //echo "HI"; exit;
            if($strTrxStatus == "success") {
			$travelplanObj = new Travel_Model_CRM_CustomerTravelPlan();
			$travelPlanDetail=$travelplanObj->GetInsuranceCustomerDetailsPax($planId);
			//echo "<pre>";print_r($travelPlanDetail);die;
			$API_SOURCE_ID=$travelPlanDetail[0]['PlanType'];
			$MasterTPSysId=$travelPlanDetail[0]['MasterTPSysId'];
			$uid=$travelPlanDetail[0]['CustomerSysId'].':'.$planId.':'.$MasterTPSysId;
			$uid=base64_encode($this->getEnc($uid));
			$customHelper = Zend_Controller_Action_HelperBroker::getStaticHelper("Custom");
			$RoomMemInfoJson=json_decode($travelPlanDetail[0]['RoomInfoJson'],1);
			$totalPax=count($RoomMemInfoJson);
				$roominfojson=isset($travelPlanDetail[0]['RoomMemInfoJson'])?json_decode($travelPlanDetail[0]['RoomMemInfoJson'],1):array();
				$memberDetails=array();
				if(!empty($roominfojson) ){
					for ($d = 1; $d <= count($roominfojson); $d++) {
						$memberDetails[] = array('FirstName' => $roominfojson[$d]['FirstName'], 'LastName' => $roominfojson[$d]['LastName'], 'DOB' => @$roominfojson[$d]['DOB']);
					}
				}
						
							if(isset($MasterTPSysId) && $MasterTPSysId > 0){	
								$whereMaste = "MasterTPSysId = " . $MasterTPSysId;
								$disableAlltravelplan = array(
									'StatusType' => 10,
									'UpdateDate' => $createDate
								);
								$disableAlltravelplan = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($disableAlltravelplan, $whereMaste);
							}
							$where = "TPSysId = " . $planId;
							$updatetravelplan = array(
								'StatusType' => 17,
								'UpdateDate' => $createDate
							);
							$updatetravelPlan = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($updatetravelplan, $where);
							
							// update main query status created by Er Amit Kumar Dubey on 8 may 2017 at 11:23 AM
								$statusArray=$customHelper->changeQueryStatusByProposal();
								$querystatus=$statusArray[17];
								if(isset($querystatus) && !empty($querystatus)){
									$whereQuery = "TPSysId = " . $MasterTPSysId;
									$updatetravelplanquery = array(
										'StatusType' => $querystatus,
										'UpdateDate' => $createDate
									);
									$updatetravelPlanQuery = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($updatetravelplanquery, $whereQuery);
								}
								
							//update accom table with bookingid
							$where = "TPIntSysId = " . $travelPlanDetail[0]['TPIntSysId'];
							$updateQuery = array(
								'XRefVoucherNo' =>$planId,
								'UpdateDate' => $createDate
							);
							$objCurd = new Visa_Model_Visa();
							$visaQueryPrposalTravelPlanId = $objCurd->updateTable("TB_Agency_Customer_TravelPlan_Insurance",$updateQuery,$where);
							$msgArray=array('status'=>'success','msg'=>'Your payment is success');
							$PAYMENT_MSG = new Zend_Session_Namespace('PAYMENT_MSG');
							$PAYMENT_MSG->PAYMENT_MSG=$msgArray;

							//send email to customer
									$html = new Zend_View();
									$html->setScriptPath(APPLICATION_PATH . '/views/scripts/proposal/');
									$agencyStaffObj = new Travel_Model_TblAgencyStaff();
									$agentDetail=$agencyStaffObj->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
									$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
									$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1'],'AgentEmail'=>$agentDetail['EmailId']);
									$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
									//echo "<pre>";print_r($getAgencyDetail);die;
									$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';

									$html->assign('type', 'InsuranceBookingPaymentConfirmationEmail');
									$html->assign('data', $travelPlanDetail);
									$html->assign('getAgentDetail',$getAgentDetail);
									$html->assign('agencyDetails',$getAgencyDetail);
									//$html->assign('URL', $encryptData);
									$paymentconfirmText = $html->render('email-template.phtml');
									$html->assign('type', 'InsuranceBookingConfirmationEmailText');
									$html->assign('data', $travelPlanDetail);
									$html->assign('getAgentDetail',$getAgentDetail);
									$html->assign('agencyDetails',$getAgencyDetail);
									$bookingConfirmText = $html->render('email-template.phtml');
									$aConfig = $this->getInvokeArg('bootstrap')->getOptions();
									$this->smtpUserName = $aConfig['smtpUserName'];
									$this->smtpPassword = $aConfig['smtpPassword'];
									$this->smtpPort = $aConfig['smtpPort'];
									$this->smtpHost = $aConfig['smtpHost'];
									$this->fromEmail = $aConfig['fromEmail'];
									$this->fromName = $aConfig['fromName'];
									//$emailId ='amit.k@catpl.co.in';
									$emailId = trim($travelPlanDetail[0]['ProposalEmailTo']);
									if($emailId!=''){
										$emailData1 = array('fromEmail'=>$this->fromEmail,'fromName'=>$this->fromName,'subject'=>stripslashes($travelPlanDetail[0]['VisaName']).' Trip Payment Receipt','to'=>array(trim($emailId)),'bodyHtml'=>$paymentconfirmText,'bodyText'=>'');
										$emailData2 = array('fromEmail'=>$this->fromEmail,'fromName'=>$this->fromName,'subject'=>stripslashes($travelPlanDetail[0]['VisaName']).' Trip Booking Details','to'=>array(trim($emailId)),'bodyHtml'=>$bookingConfirmText,'bodyText'=>'');
										try {
											$arrEmailStatisticsType = array_keys(unserialize(ARR_EMAIL_STATISTICS_TYPE));
											$arrEmailStatistics = array(
												"TPSysId" => $planId,
												"TypeSysId" => 1,  // 1 For Email 2 For SMS
												"AgencySysId" => $travelPlanDetail[0]['AgencySysId'],
												"AgentSysId" => $travelPlanDetail[0]['AgentSysId'],
												"Title" => $paymentconfirmText,
												"Source" => $arrEmailStatisticsType[1], // 2 For Vouchers
												"Status" => 0,
												"RefSysId" => "",
												"RefSysStatus" => "",
												"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
											);
											$arrEmailStatistics2 = array(
												"TPSysId" => $planId,
												"TypeSysId" => 1,  // 1 For Email 2 For SMS
												"AgencySysId" => $travelPlanDetail[0]['AgencySysId'],
												"AgentSysId" => $travelPlanDetail[0]['AgentSysId'],
												"Title" => $bookingConfirmText,
												"Source" => $arrEmailStatisticsType[1], // 2 For Vouchers
												"Status" => 0,
												"RefSysId" => "",
												"RefSysStatus" => "",
												"CreateDate" => Zend_Date::now()->toString('yyyy-MM-dd HH:mm:ss')
											);
											//echo "success";
											$this->mailSentByElastice($emailData1,$arrEmailStatistics);
											$this->mailSentByElastice($emailData2,$arrEmailStatistics2);
											$msg="success";
										} catch (Exception $err) {
											//print_r($err, true);
											$msg="failed";
										}
									}
							//end of send email to customer
			} if($strTrxStatus == "failure" ){
					$where = "TPSysId = " . $planId;
					$updatetravelplan = array(
						'StatusType' => 7,
						'UpdateDate' => $createDate
					);
					$updatetravelPlan = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($updatetravelplan, $where);


					// update main query status created by Er Amit Kumar Dubey on 8 may 2017 at 11:27 AM
						$statusArray=$customHelper->changeQueryStatusByProposal();
						$querystatus=$statusArray[7];
						if(isset($querystatus) && !empty($querystatus)){
							$whereQuery = "TPSysId = " . $MasterTPSysId;
							$updatetravelplanquery = array(
								'StatusType' => $querystatus,
								'UpdateDate' => $createDate
							);
							$updatetravelPlanQuery = $this->_crmcusttravelplan->UpdateCustomerTravelPlan($updatetravelplanquery, $whereQuery);
						}
						$msgArray=array('status'=>'failed','msg'=>'Your payment is unsuccessful'.$$this->getRequest()->getParam('error_Message'));
						$PAYMENT_MSG = new Zend_Session_Namespace('PAYMENT_MSG');
						$PAYMENT_MSG->PAYMENT_MSG=$msgArray;
						exit;
			}
		  }else{
				$msgArray=array('status'=>'failed','msg'=>'Your payment is unsuccessful Id Mismatch');
				$PAYMENT_MSG = new Zend_Session_Namespace('PAYMENT_MSG');
				$PAYMENT_MSG->PAYMENT_MSG=$msgArray;
		}
		$this->_redirect("/proposal/booking-insurance-confirmation/mid/".base64_encode($MasterTPSysId)."/pid/".base64_encode($planId));
		exit;
    }
	public function bookingInsuranceConfirmationAction(){
		$this->view->layout()->disableLayout();
		$proposalId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$TPSysId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('pid')));
		$PAYMENT_MSG = new Zend_Session_Namespace('PAYMENT_MSG');
		if($TPSysId==''){
			$this->view->error=1;
			//echo "Please try again";
			//die;
		} else{
			$this->view->error=0;
		$travelPlanDetail=$this->_crmcusttravelplan->GetInsuranceCustomerDetailsPax($TPSysId);
		//echo "<pre>";print_r($travelPlanDetail);die;
		$CustomerSysId=$travelPlanDetail[0]['CustomerSysId'];
		$getCustomerDetail = $this->_crmcustomerObj->ChkAgencyUser($CustomerSysId);
//echo "<pre>";print_r($getCustomerDetail);
		//customer detail
				$CustomerSysId=$travelPlanDetail[0]['CustomerSysId'];
				$getLeadlist = $this->_crmcusttravelplan->GetPurchasedPublicPageLeadList($CustomerSysId, $travelPlanDetail[0]['AgencySysId'], $TPSysId);
				$API_SOURCE_ID=$travelPlanDetail[0]['PlanType'];
				$roomjsonarray=json_decode($travelPlanDetail[0]['RoomInfoJson'],1);				
				if($API_SOURCE_ID == "8"){
					$strCurrencyCode = $travelPlanDetail[0]['CurrencyType'];
					$Price = $travelPlanDetail[0]['Price'];
					$intTax = $travelPlanDetail[0]['XServiceTaxAmount'];
					$this->view->intTax =  $intTax = !empty($intTax)?($intTax):0;
					$this->view->intTotalAmount =  $intTotalAmount=$Price;
					$this->view->intAgentMarkUpAmount =  $intAgentMarkUpAmount = $travelPlanDetail[0]['MarkUp'];//$markupAgency->markupAg;
					$this->view->intAgencyMarkUpAmount =  $intAgencyMarkUpAmount = $travelPlanDetail[0]['AgencyMarkUp'];//$markupAgency->markupAg;
					$this->view->intGTXMarkUpAmount =  $intGTXMarkUpAmount = $travelPlanDetail[0]['GTXMarkup'];//$markupAgency->markupAg;
					$XServiceTaxAmount = $travelPlanDetail[0]['XServiceTaxAmount'];
					$GTXServiceTaxAmount = $travelPlanDetail[0]['GTXServiceTaxAmount'];
					$AgentServiceTaxAmount = $travelPlanDetail[0]['AgentServiceTaxAmount'];
					$AgentsCustomServiceTaxAmount = $travelPlanDetail[0]['AgentsCustomServiceTaxAmount'];
					$customDiscount = $travelPlanDetail[0]['CustomDiscount'];
					$serviceTaxOnCustomDiscount = $travelPlanDetail[0]['ServiceTaxOnCustomDiscount'];
					$this->view->intGrandPayableAmount =  $intGrandPayableAmount = round(($Price+$intAgentMarkUpAmount + $intAgencyMarkUpAmount + $intGTXMarkUpAmount + $XServiceTaxAmount + $GTXServiceTaxAmount + $AgentServiceTaxAmount + $AgentsCustomServiceTaxAmount)-($customDiscount+$serviceTaxOnCustomDiscount));
				}

		//query for get customer chat history
            $objAgencyUser = new Travel_Model_CRM_AgencyUserInbox();
			$getChatHistoryDetail=array();
            $checkCustomerChatExist = (@$getCustomerDetail[0]['CustomerSysId'] > 0) ? $objAgencyUser->CheckCustomerMsgCount(@$getCustomerDetail[0]['CustomerSysId'], $TPSysId,trim($travelPlanDetail[0]['AgentSysId'])) : array();
           // $checkCustomerChatExist = (count($checkCustomerChatExist)==0)?$objAgencyUser->CheckCustomerMsgCount(@$getcustomerDetail[0]['CustomerSysId'], $tpID):$checkCustomerChatExist;
                if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
                    $getChatHistoryDetail = $objAgencyUser->GetCustChatHistDetWithLead($TPSysId, $getCustomerDetail[0]['CustomerSysId'], 'ASC');
				}
			$getCustomerDetail['userChatExist'] = (count($checkCustomerChatExist)>0)?count($checkCustomerChatExist):count($getChatHistoryDetail);
            //query for get customer chat history
            $chatSenderDetails = array();
            $objAgencyStaff = new Travel_Model_TblAgencyStaff();
            $agentDetail = $objAgencyStaff->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
            if($getCustomerDetail['userChatExist'] > 0) {
                if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
                    $this->view->chatHistoryDetail = $getChatHistoryDetail;
					
                    $chatSenderDetails['TPSysId'] = $TPSysId;
                    $chatSenderDetails['AgencySysId'] = $travelPlanDetail[0]['AgencySysId'];
                    $chatSenderDetails['CustomerSysId'] = $getCustomerDetail[0]['CustomerSysId'];
                    $chatSenderDetails['AgentSysId'] = $travelPlanDetail[0]['AgentSysId'];
                    $chatSenderDetails['EmailId'] = $agentDetail['EmailId'];
                    //print_r($agentDetail);
                }
            }
			            //echo "<pre>";print_r($chatSenderDetails);

			//end of customer chat history
			$agencyStaffObj = new Travel_Model_TblAgencyStaff();
			$agentDetail=$agencyStaffObj->getUserDetailsById($getLeadlist[0]['AgentSysId']);
			$AgencySysId = $getLeadlist[0]['AgencySysId'];
			$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1'],'AgentEmail'=>$agentDetail['EmailId']);
			$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
			$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
			$this->view->getAgentDetail=$getAgentDetail;
			$this->view->agencyDetails=$getAgencyDetail;
			$this->view->travelPlanDetail=$travelPlanDetail;
			$this->view->getcustomerDetail = $getCustomerDetail;
			$this->view->chatSenderDetails = $chatSenderDetails;
		}
		//echo "<pre>";print_r($travelPlanDetail);die;
		$this->view->PAYMENT_MSG=$PAYMENT_MSG->PAYMENT_MSG;
   }
    public function insuranceViewAction() {
       	$this->_helper->layout->disableLayout(); 
		$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$TPSysId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('pid')));
		if($TPSysId==''){
			echo "Please try again";
			die;
		}

		$travelPlanDetail=$this->_crmcusttravelplan->GetInsuranceCustomerDetailsTrx($TPSysId);
		//customer detail
			$travelplanObj = new Travel_Model_CRM_CustomerTravelPlan();
			$travelPlanDetail=$travelplanObj->GetInsuranceCustomerDetailsPax($TPSysId);
			$CustomerSysId=$travelPlanDetail[0]['CustomerSysId'];

				if (isset($CustomerSysId) && !empty($CustomerSysId)) {
					$crmcustomerObj = new Travel_Model_CRM_Customer();
					$getCustomerDetail[]=$crmcustomerObj->GetAgencyCustomerById($travelPlanDetail[0]['CustomerSysId']);
					$objAgencyUser = new Travel_Model_CRM_AgencyUserInbox();
					$checkCustomerChatExist = $getCustomerDetail[0]['CustomerSysId'] > 0? $objAgencyUser->CheckCustomerMsgCount($getCustomerDetail[0]['CustomerSysId'],$TPSysId):array();
					$getversiondetails = $this->_crmcusttravelplan->GetVersionInfo($TPSysId);
					$getCustomerDetail['userChatExist']=count($checkCustomerChatExist);
				}
		//end of customer detail
		//query for get customer chat history
			$chatSenderDetails=array();
			if($getCustomerDetail['userChatExist'] > 0){
					if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
						$getChatHistoryDetail = $objAgencyUser->GetCustChatHistDetWithLead($TPSysId,$getCustomerDetail[0]['CustomerSysId'],'ASC');
						$this->view->chatHistoryDetail=$getChatHistoryDetail;
						$chatSenderDetails['TPSysId']=$TPSysId;
						$chatSenderDetails['AgencySysId']=$travelPlanDetail[0]['AgencySysId'];
						$chatSenderDetails['CustomerSysId']=$travelPlanDetail[0]['CustomerSysId'];
						$chatSenderDetails['AgentSysId']=$travelPlanDetail[0]['AgentSysId'];
						//$chatSenderDetails['EmailId']=$getcustomerDetail[0]['EmailId'];
						$objAgencyStaff   =	new Travel_Model_TblAgencyStaff();
						$agentDetail=$objAgencyStaff->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
						$chatSenderDetails['EmailId']=$agentDetail['EmailId'];
						//print_r($agentDetail);
						
						
					}
			}
			//end of customer chat history
			$agencyStaffObj = new Travel_Model_TblAgencyStaff();
			$agentDetail=$agencyStaffObj->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
			$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
			$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1']);
			$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
			$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
			$this->view->getAgentDetail=$getAgentDetail;
			$this->view->agencyDetails=$getAgencyDetail;
			$this->view->getcustomerDetail = $getCustomerDetail;
			$this->view->travelPlanDetail=$travelPlanDetail;
			$ARR_SALUTION=unserialize(ARR_SALUTION);
			$this->view->ARR_SALUTION=$ARR_SALUTION;
    }
    public function insuranceVoucherAction() {
        $this->_helper->layout->disableLayout();
		$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$TPSysId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('pid')));
		if($TPSysId==''){
			echo "Please try again";
			die;
		}
		$travelPlanDetail=$this->_crmcusttravelplan->GetInsuranceCustomerDetailsTrx($TPSysId);
		$CustomerSysId=$travelPlanDetail[0]['CustomerSysId'];
		$objAgencyStaff = new Travel_Model_TblAgencyStaff();
		$agentDetail=$objAgencyStaff->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
		$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
		$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1']);
		$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
		$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
		$this->view->getAgentDetail=$getAgentDetail;
		$this->view->agencyDetails=$getAgencyDetail;
		$this->view->travelPlanDetail=$travelPlanDetail;
   }
    public function insuranceInvoiceAction() {
        $this->_helper->layout->disableLayout(); 
		$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		$TPSysId = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('pid')));
		if($TPSysId==''){
			echo "Please try again";
			die;
		}
		$travelPlanDetail=$this->_crmcusttravelplan->GetInsuranceCustomerDetailsTrx($TPSysId);
		$objAgencyStaff = new Travel_Model_TblAgencyStaff();
		$agentDetail=$objAgencyStaff->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
		$AgencySysId = $travelPlanDetail[0]['AgencySysId'];
		$getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1']);
		$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
		$getAgencyDetail['fullAddress']=isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
		$this->view->getAgentDetail=$getAgentDetail;
		$this->view->agencyDetails=$getAgencyDetail;
		$this->view->travelPlanDetail=$travelPlanDetail;
		//echo "<pre>";print_r($getAgencyDetail);die;
		$customhelper = Zend_Controller_Action_HelperBroker::getStaticHelper('Custom');
		$this->view->getallstatustype=$customhelper->getAllStatusType();
    }
    public function agencyTncDataAction() {
        $this->_helper->layout->disableLayout();
		$encid = $this->getRequest()->getParam("encid") ? $this->getRequest()->getParam("encid") : '';
		$error=1;
		$getRecord=array();
		if($encid!=''){
			$data=@$this->getDec($encid); //data in current format ==> planid:agencysysid:customersysid
			$data_Exp=explode(":",$data);
			if(count($data_Exp)==3){
				$TPSysId=trim($data_Exp[0]);
				$AgencySysId=trim($data_Exp[1]);
				$CustomerSysId=trim($data_Exp[2]);
				$checkRecordExist=$this->_crmcusttravelplan->CheckCustomerWithLeadId($TPSysId);
				//echo "<pre>";print_r($checkRecordExist);
				if(count($checkRecordExist)>0 && $checkRecordExist[0]['CustomerSysId']==$CustomerSysId){
					$objAgency=new Travel_Model_TblAgency();
					
					$getRecord=$objAgency->getAgencyTnCDetails($AgencySysId);
					
					$error=0;
					$getAgencyDetail=$this->_crmcustomerObj->GetAgencyDetailById($AgencySysId);
					//echo "<pre>";print_r($getRecord);
					$this->view->agencyDetails=$getAgencyDetail;
					$this->view->agencyTncData=$getRecord;
					
				}
			}else{
				$error=1;
			}
		}else{
			$error=1;
		}
		//echo $error;
		if($error==1){
			echo "Something went wrong";
			exit;
		}
		$this->view->encid=$encid;
    }
	
	public function downloadVisaCoveringLetterAction(){
		$InvnVisaAllSysId = $this->getRequest()->getParam("id") ? base64_decode($this->getRequest()->getParam("id")) : '';
		$type = $this->getRequest()->getParam("type") ? $this->getRequest()->getParam("type") : '';
		$ICSourceSysId = $this->getRequest()->getParam("icId") ? base64_decode($this->getRequest()->getParam("icId")) : '';
		if($InvnVisaAllSysId>0){
			$objVisa = new Travel_Model_TblVisa();
			$VisaDetailList = $objVisa->VisaInventoryDeList($InvnVisaAllSysId,$ICSourceSysId);
			//echo "<pre>";print_r($VisaDetailList);
			if(!empty($VisaDetailList)){
				$filename=$VisaDetailList['DocFileName'.$type];
						if($filename !=''){
							$file = USER_FILE_UPLOAD_PATH . 'agency/' . $ICSourceSysId . "/".$filename;
							header("Pragma: public");
							header("Expires: 0");
							header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
							header("Content-Type: application/force-download");
							header( "Content-Disposition: attachment; filename=\"".basename($file)."\"");
							header( "Content-Description: File Transfer");
							@readfile($file); 
							die;
						}else{
							echo "some error . please try after some time.";
						}

			}
			 
		}else{
			echo "something went wrong";
		}
		exit;
	}
        
        
        
        public function viewHotelDetailsAction() {
        /* Disable Layout */
        $this->_helper->layout->disableLayout();
        if (!$this->_request->isXmlHttpRequest()) {
            $this->view->layoutType = 'browser';
            $AccomSysId = base64_decode($this->getRequest()->getParam('hotelid'));
        } else {
            $AccomSysId = $this->getRequest()->getParam('hotelid');
        }
        
        $this->view->price = $this->getRequest()->getParam('price');
        $this->view->AllowBooking = $this->getRequest()->getParam('AllowBooking');
        $this->view->TPSysId = $this->getRequest()->getParam('TPSysId');
        $this->view->MasterTPSysId = $this->getRequest()->getParam('MasterTPSysId');
        $this->view->intAccomSysId = $this->getRequest()->getParam('intAccomSysId');
        $this->view->InvnItemSysId = $this->getRequest()->getParam('InvnItemSysId');

        $objAccom = new Travel_Model_TblICAccomdation();
        $objAccImg = new Travel_Model_TblAccomoImg();
        $accomoDetailArr = $objAccom->getAccomodation($AccomSysId);
        $this->view->accomoDetailsArr = $accomoDetailArr;
//        echo '<pre>'; print_r($accomoDetails);
        $accImgArr = $objAccImg->getAccomoImage($AccomSysId);
        $this->view->accImgArr = $accImgArr;
    }
    
    
    public function getInventoryHotelDetailsAction() {
        /* Disable Layout */
        $this->_helper->layout->disableLayout();
        if ($this->_request->isXmlHttpRequest()) {
            $price = $this->getRequest()->getParam('price');
            $AllowBooking = $this->getRequest()->getParam('AllowBooking');
            $TPSysId = $this->getRequest()->getParam('TPSysId');
            $MasterTPSysId = $this->getRequest()->getParam('MasterTPSysId');
            $intAccomSysId = $this->getRequest()->getParam('AccomSysId');
            $InvnItemSysId = $this->getRequest()->getParam('InvnItemSysId');
            
            if($AllowBooking){
                
                $redirectUrl = "/proposal/display-selected-room-inv/tpid/".  base64_encode($TPSysId) ."/mid/".  base64_encode($MasterTPSysId);
                echo json_encode(['success' => true, 'msg' => 'success','url' => $redirectUrl,'redirect'=> true]);
                exit;
            }
            
        } 
        

       
    }
    
    
    
    public function displaySelectedRoomInvAction(){
        
        
		$this->view->layout()->disableLayout();
		
		$tpid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('tpid')));
		$uid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('uid')));
		$mid = $this->_HtmlPurifier->filter(base64_decode($this->getRequest()->getParam('mid')));
		
		//HOTELAPITYPE
		//echo "<pre>"; print_r($selectedroomDetails->selectedroom_hotelinfo);die;
		$planId = $tpid;
                
		if(isset($planId) && !empty($planId)){
                    
			$travelPlanDetail=$this->_crmcusttravelplan->GetTravelPlanCustomerInvHotelDetails($planId);
			if($travelPlanDetail[0]['StatusType']==17){
				$this->_redirect('/proposal/booking-confirmation/mid/'.base64_encode($mid).'/pid/'.base64_encode($tpid).'/htype/inv');
				exit;
			}
			
                        $this->view->uid=$uid;
                        $this->view->mid=$travelPlanDetail[0]['MasterTPSysId'];
                        $this->view->tpid=$tpid;
		
			$travelPlanItenObj = new Travel_Model_CRM_CustomerTravelItenary();
			$travelPlanItenaryId = $travelPlanItenObj->GetItenaryId($planId);
			$this->view->travelPlanAccomId=$travelPlanItenaryId['TPIntSysId'];
			//echo "<pre>"; print_r($travelPlanDetail);
			$agencyStaffObj = new Travel_Model_TblAgencyStaff();
			$agentDetail=$agencyStaffObj->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
                        $AgencySysId = $travelPlanDetail[0]['AgencySysId'];
                        $getAgentDetail = array('AgentName' => $agentDetail['FirstName'] . " " . $agentDetail['LastName'],'AgentContact'=>$agentDetail['ContactNo1']);
                        $crmcustomerObj = new Travel_Model_CRM_Customer();
                        $getAgencyDetail=$crmcustomerObj->GetAgencyDetailById($AgencySysId);
                        $guestDetails=$crmcustomerObj->GetCustomerWithDetails($travelPlanDetail[0]['CustomerSysId']);
                        $hotelGuestDetails = new Zend_Session_Namespace('hotelGuestDetails');
                        $hotelGuestDetails->hotelGuestDetails=$guestDetails;
                        //echo "<pre>";print_r($guestDetails);die;
                        //$guestDetails=$crmcustomerObj->GetCustomerWithDetails($travelPlanDetail[0]['CustomerSysId']);
                        $agencyAddress='';	
		if(isset($getAgencyDetail['CountrySysId']) && !empty($getAgencyDetail['StateOrZoneSysId']) && !empty($getAgencyDetail['CitySysId'])){
			$agencyAddress=$crmcustomerObj->GetNameOfContStateCity($getAgencyDetail['CountrySysId'],$getAgencyDetail['StateOrZoneSysId'],$getAgencyDetail['CitySysId']);
		}
		$agencyState='';
		$agencyCountry='';
		if(isset($agencyAddress['StateName']) && !empty($agencyAddress['StateName'])){
			$agencyState=$agencyAddress['StateName']?" ,".$agencyAddress['StateName']:'';
		}
		if(isset($agencyAddress['countryName']) && !empty($agencyAddress['countryName'])){
			$agencyCountry=$agencyAddress['countryName']?"(".$agencyAddress['countryName'].")":'';
		}
                
		//customer detail
                $tpID=$planId;
                $CustomerSysId=$travelPlanDetail[0]['CustomerSysId'];
                if (isset($CustomerSysId) && !empty($CustomerSysId)) {
                    $this->_crmcustomerObj = new Travel_Model_CRM_Customer();
                    $getCustomerDetail = $travelPlanDetail;
                    $objAgencyUser = new Travel_Model_CRM_AgencyUserInbox();
                    $checkCustomerChatExist = $getCustomerDetail[0]['CustomerSysId'] > 0? $objAgencyUser->CheckCustomerMsgCount($getCustomerDetail[0]['CustomerSysId'],$tpID):array();
                    $getCustomerDetail['userChatExist']=count($checkCustomerChatExist);
                }
		//end of customer detail

                         

                /*Travel Plan Pax Details*/
		$roomjsonarray = json_decode($travelPlanDetail[0]['RoomMemInfoJson'],1);
                //echo "<pre>";print_r($roomjsonarray);exit;
                $adultPax =0;
                $childPax =0;
                if(!empty($roomjsonarray) ){
                        foreach($roomjsonarray as $res){
                                $adultPax += $res['adult'];
                                $childPax += $res['child']['childcount'];
                        }
                }
		/*Travel Plan Pax Details Ends*/
                
                
                
                //query for get customer chat history
                $chatSenderDetails=array();
                if($getCustomerDetail['userChatExist'] > 0){
                    if (isset($getCustomerDetail[0]['CustomerSysId']) && !empty($getCustomerDetail[0]['CustomerSysId'])) {
                            $getChatHistoryDetail = $objAgencyUser->GetCustChatHistDetWithLead($tpID,$getCustomerDetail[0]['CustomerSysId'],'DESC');
                            $this->view->chatHistoryDetail=$getChatHistoryDetail;
                            $chatSenderDetails['TPSysId']=$tpID;
                            $chatSenderDetails['AgencySysId']=$travelPlanDetail[0]['AgencySysId'];
                            $chatSenderDetails['CustomerSysId']=$getCustomerDetail[0]['CustomerSysId'];
                            $chatSenderDetails['AgentSysId']=$travelPlanDetail[0]['AgentSysId'];
                            //$chatSenderDetails['EmailId']=$getcustomerDetail[0]['EmailId'];
                            $objAgencyStaff   =	new Travel_Model_TblAgencyStaff();
                            $agentDetail=$objAgencyStaff->getUserDetailsById($travelPlanDetail[0]['AgentSysId']);
                            $chatSenderDetails['EmailId']=$agentDetail['EmailId'];
                            //print_r($agentDetail);


                    }
                }
                //end of customer chat history
                

			
		$getAgencyDetail['fullAddress'] = isset($agencyAddress['CityName'])?$agencyAddress['CityName'].$agencyState.$agencyCountry:'';
		$this->view->getAgentDetail = $getAgentDetail;
		$this->view->agencyDetails = $getAgencyDetail;
		$this->view->hotelInfo = @$roomDetail->roomDetail;
		$this->view->guestDetail = $guestDetails;
		$this->view->selectedroom_hotelinfo = @$selectedroomDetails->selectedroom_hotelinfo;
		$this->view->getcustomerDetail = $getCustomerDetail;
		$this->view->chatSenderDetails = $chatSenderDetails;
		$this->view->markuparray = @$markuparray;
		$this->view->travelPlanDetail=$travelPlanDetail;
		}
		$ARR_SALUTION=unserialize(ARR_SALUTION);
		$this->view->ARR_SALUTION=$ARR_SALUTION;
		$ARR_CUSTOMER_RELATION=unserialize(ARR_CUSTOMER_RELATION);
		$this->view->ARR_CUSTOMER_RELATION=$ARR_CUSTOMER_RELATION;
                
                
                
                
                
                
                
                
                
                
                
	}
        
        
        
}

Youez - 2016 - github.com/yon3zu
LinuXploit