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/tajmahaltoursonline.com/library/Helper/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/tajmahaltoursonline.com/library/Helper/Car.php
<?php

/* * *************************************************************
 * Catabatic Technology Pvt. Ltd.
 * File Name     : Hotel.php
 * File Desc.    : Hotel helper to including supporting functions/methods for Hotels
 * Created By    : Pardeep Panchal <pardeep@catpl.co.in>
 * Created Date  : 24 Nov 2017
 * Updated Date  : 24 Nov 2017
 * ************************************************************* */

class Zend_Controller_Action_Helper_Car extends Zend_Controller_Action_Helper_Abstract
{

    public $baseUrl;

    public function __construct()
    {

        $this->pluginLoader = new Zend_Loader_PluginLoader();
        $this->db = Zend_Db_Table::getDefaultAdapter();
        $BootStrap = $this->config();
        $this->siteName = $BootStrap['siteName'];
        $this->baseUrl = $BootStrap['siteUrl'];
    }

    public function config()
    {
        $front = $this->getFrontController();
        $bootstrap = $front->getParam('bootstrap');
        if (null === $bootstrap) {
            throw new Exception('Unable to find bootstrap');
        }
        return $bootstrap->getOptions()['bootstrap'];
    }
    public function calculateNoOfDays($date1, $date2)
    {
        $diff = abs(strtotime($date2) - strtotime($date1));
        $years = floor($diff / (365 * 60 * 60 * 24));
        $months = floor(($diff - $years * 365 * 60 * 60 * 24) / (30 * 60 * 60 * 24));
        $days = ceil(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24) / (60 * 60 * 24)) + 1;
        return $days;
    }
    public function CreateCarSessionSearch($data, $TraceId)
    {
        Zend_Session::namespaceUnset('SearchCarTraceId');
        Zend_Session::namespaceUnset('SearchCarData');
        //echo"<pre>";print_r($data);die();
        $SearchHotelTraceId = new Zend_Session_Namespace('SearchCarTraceId');
        $SearchHotelTraceId->params = $TraceId;

        $SearchCarData = new Zend_Session_Namespace('SearchCarData');

        $SearchCarData->params = $data;

        $arrTravelDate = explode(" ", $data['travelDate']);

        if (count($arrTravelDate) > 0) {
            $startDate = $arrTravelDate[2] . "-" . $arrTravelDate[0] . "-" . $arrTravelDate[1];
        }

        $travelDate = date('d-M-Y', strtotime($startDate));

        $arrTravelendDate = explode("/", $data['endDate']);
        if (count($arrTravelendDate) > 0) {
            $endDate = $arrTravelendDate[2] . "-" . $arrTravelendDate[0] . "-" . $arrTravelendDate[1];
        }
        $travelendDate = date('d-M-Y', strtotime($endDate));
        $travelDate = $data['travelDate'];
        $travelendDate = $data['endDate'];

        // die($travelendDate);
        $days = Zend_Controller_Action_HelperBroker::getStaticHelper("Car")->calculateNoOfDays($travelDate, $travelendDate);

        $time = explode(':', $data['pTime']);
        if ($time[0] > 12) {
            $ampm = 'PM';
        } else {
            $ampm = 'AM';
        }
        $ptime = $data['pTime'] . $ampm;

        $searchdata = array(
            'tripTypeOption' => $data['tripTypeOption'],
            'travelTypeOption' => $data['travelTypeOption'],
            'sourceCity' => $data['sourceCity'],
            'destinationCity' => $data['destinationCity'],
            'travelDate' => $data['travelDate'],
            'days' => trim($days),
            'pTime' => $ptime,
            'pickUpLocation' => 'xyz',
            'dropLocation' => '',
            'UserID' => '123',
        );

        $SearchCarData->params['carsearchdata'] = $searchdata;
        return $SearchCarData->params;
    }

    public function getCarSearchResult($data)
    {
        //echo"<pre>";print_r($data);die;
        $data_stringh = json_encode($data);
        // print_r($data_stringh) ; die;
        $url = CAR_URL . 'api/v1/car/search/';
        $SearchCarTraceId = new Zend_Session_Namespace('SearchCarTraceId');
        $CarTraceId = $SearchCarTraceId->params;

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_ENCODING, "gzip");
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_stringh);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array());
        $response = curl_exec($ch);
        //echo"<pre>";print_r($response);die;

        if (CAR_API_LOGS) {
            //Write Request Logs starts...
            $strFilePath = "cars/Search/" . date('Y-m-d-H-i-s') . "_request.json";
            Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $data_stringh);

            $strFilePath = "cars/Search/" . date('Y-m-d-H-i-s') . "_response.json";
            Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $response);
        }
        curl_close();
        //echo"<pre>";print_r($response);die;
        return $response;
    }





    public function getFlightClasses()
    {
        //return array('1' => 'Economy', '2' => 'Premium Economy', '3' => 'Business');
        return array('1' => 'All', '2' => 'Economy', '3' => 'Premium Economy', '4' => 'Business', '5' => 'PremiumBusiness', '6' => 'First');
    }
    public function getFlightClassesTripJack()
    {
        //return array('1' => 'Economy', '2' => 'Premium Economy', '3' => 'Business');
        return array('2' => 'ECONOMY', '3' => 'PREMIUM_ECONOMY', '4' => 'BUSINESS', '5' => 'PremiumBusiness', '6' => 'FIRST');
    }
    public function getCustomerDetails($tablename, $CustomerSysId)
    {
        $select = $this->db->select()->from("$tablename", "*");
        $select->where("GTX_customerSysId=?", "$CustomerSysId");
        $select->where("IsMarkForDel", 0);
        $select->where("IsActive", 1);
        $select->order("paxType", 'ASC');
        $result = $this->db->fetchRow($select);
        return $result;
    }

    public function sortArrayByColumn(&$arr = [], $col, $order = SORT_ASC)
    {
        $sort_col = array();

        if (count($arr) > 0) {
            foreach ($arr as $key => $row) {
                @$sort_col[$key] = $row[$col];
            }
        }

        @array_multisort($sort_col, $order, $arr);
    }

    public function getDateTimeFormatString($string, $type = 1)
    {  // supplied 2017-12-20T21:10:00 format
        if (empty($string))
            return '';

        if ($type == 1) {
            $arr = explode("T", $string);
            $date = new DateTime($arr[0]);
            return $date->format('D, d M') . ' ' . substr(@$arr[1], 0, 5);
        } elseif ($type == 2) {  // supplied  2017/12/20 format
            $date = new DateTime($string);
            return $date->format('D, d M');
        } elseif ($type == 3) {  // supplied  2017/12/20 format
            $arr = explode("T", $string);
            return substr(@$arr[1], 0, 5);
        }
    }

    public function convertMinutesToHoursFormat($minutes)
    {
        if ($minutes < 1) {
            //return;
        }
        $hours = floor($minutes / 60);
        $minutes = ($minutes % 60);
        return $hours . 'h ' . $minutes . 'm';
    }

    public function CalculateTotalTime($time1, $time2)
    {
        $diff = abs(strtotime($time1) - strtotime($time2));

        $tmins = $diff / 60;
        $hours = floor($tmins / 60);
        $mins = $tmins % 60;
        return $hours . 'h ' . $mins . 'm';
    }

    public function agencyMarkUpAndCommisions($data = [])
    {

        $intCommissionEarned = !empty($data['CommissionEarned']) ? $data['CommissionEarned'] : 0;
        $intIncentiveEarned = !empty($data['IncentiveEarned']) ? $data['IncentiveEarned'] : 0;
        $intPLBEarned = !empty($data['PLBEarned']) ? $data['PLBEarned'] : 0;

        $IsInternational = !empty($data['IsInternational']) ? $data['IsInternational'] : 0;
        if ($IsInternational == 1) {
            $intAirType = 2;
        } else {
            $intAirType = 1;
        }

        $AgencySysId = !empty($data['AgencySysId']) ? $data['AgencySysId'] : 0;

        $objTblMPAirMarkup = new Flights_Model_TblMPAirMarkup();
        $arrAgencyMarkups = $objTblMPAirMarkup->getAgencyMarkupsAir($intAirType, $AgencySysId);

        if (count($arrAgencyMarkups) > 0) {

            $intAgencyCurrencySysId = $arrAgencyMarkups[0]['Currency'];
            $intAgencyMarkUpType = $arrAgencyMarkups[0]['MarkUpType'];
            $intAgencyMarkUp = $arrAgencyMarkups[0]['StdMarkUpPer']; // Agency Fix Mark UP...
            $percentAgencySTax = $arrAgencyMarkups[0]['TaxPer'];

            $intCommssionType = $arrAgencyMarkups[0]['CommssionType']; // 2 For percentage
            $intCommssionVal = $arrAgencyMarkups[0]['CommssionVal']; // Percntage Value For Agency Commision From Actual Commision Retuned From API...

            if ($intCommssionType == 2) { // For Agency Commision In Percentage Only...
                $intAgencyCommisionEarnedFromAcutalCommision = ($intCommissionEarned * $intCommssionVal) / 100;
                $intAgencyPLBEarnedFromAcutalPLB = ($intPLBEarned * $intCommssionVal) / 100;
                $intAgencyIncentiveEarnedFromAcutalIncentive = ($intIncentiveEarned * $intCommssionVal) / 100;

                $TotalCommisions = $intAgencyCommisionEarnedFromAcutalCommision + $intAgencyPLBEarnedFromAcutalPLB + $intAgencyIncentiveEarnedFromAcutalIncentive;
            }


            $arrMarkUps = [
                'CommissionEarned' => $intAgencyCommisionEarnedFromAcutalCommision,
                'IncentiveEarned' => $intAgencyIncentiveEarnedFromAcutalIncentive,
                'PLBEarned' => $intAgencyPLBEarnedFromAcutalPLB,
                'TotalCommisions' => $TotalCommisions,
                'MarkUp' => $intAgencyMarkUp
            ];
        } else {
            $arrMarkUps = [
                'CommissionEarned' => 0,
                'IncentiveEarned' => 0,
                'PLBEarned' => 0,
                'TotalCommisions' => 0,
                'MarkUp' => 0
            ];
        }

        return $arrMarkUps;
    }

    public function GetCancelResponse($datastring)
    {

      //  $url = CAR_CANCEL_URL;
        //'api/v1/car/booking-cancel/'
        //$datastring = http_build_query($requestdata);
        $canelrequest = json_encode($datastring);
       // $datastring = $url.'?tripId=RT2BI257922-32FC1972-B574-B132-55A2-E9534D5EAB02&UserID=ganesh@catpl.co.in&mobileNumber=8585960381&ApiKey=H5HZ5C-I5V6DZ-SSL0VN-1JR4G5-JJLNRB-JGHWKZ&UserIPAddress=127.0.0.1&UserAgent=Mozilla&responsetype=2&';
        //return $url;
        //return $datastring;
       // echo"<pre>"; print_r($datastring);die;

        $url = CAR_URL.'api/v1/car/booking-cancel/';
       // echo"<pre>"; print_r($URL);die;
        try{

        
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_ENCODING, "gzip");
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $canelrequest);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array());
        $response = curl_exec($ch);
        curl_close();

    } catch (Exception $err) {
            print_r($err);
        $err->getMessage();
        $issend = FALSE;
    }
  // echo"<pre>"; print_r($response);die;
   // die($response);   
    if (CAR_API_LOGS) {
            //Write Request Logs starts...
            $strFilePath = "cars/BookingConfirm/" . date('Y-m-d-H-i-s') . "_request.json";
            Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $datastring);

            $strFilePath = "cars/BookingConfirm/" . date('Y-m-d-H-i-s') . "_response.json";
            Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $response);
        }
        return $response;
    }


    public function CreateSessionSearchParams($getData)
    {

        Zend_Session::namespaceUnset('sessionFlightSearchParams');
        //        Zend_Session::namespaceUnset('recentSearch');die;
        if (!empty($getData)) {
            $uri = Zend_Controller_Front::getInstance()->getRequest()->getRequestUri();
            $uriExp = explode('?', $uri);
            $recentSearch->params = [];
            $sessionFlightSearchParams = new Zend_Session_Namespace('sessionFlightSearchParams');
            $recentSearch = new Zend_Session_Namespace('recentSearch');
            $sessionFlightSearchParams->params = $getData;  // Putting all form data to Session

            $departure_dates = $getData['departure_date'];
            $return_dates = $getData['return_date'];
            if (!empty($departure_dates)) {
                $arrDepatureDate = explode("/", $departure_dates);
                if (count($arrDepatureDate) > 0) {
                    $strDepatureDate = $arrDepatureDate[2] . "-" . $arrDepatureDate[1] . "-" . $arrDepatureDate[0];
                }
            }
            if (!empty($return_dates)) {
                $arrReturnDepatureDate = explode("/", $return_dates);
                if (count($arrReturnDepatureDate) > 0) {
                    $strReturnDate = $arrReturnDepatureDate[2] . "-" . $arrReturnDepatureDate[1] . "-" . $arrReturnDepatureDate[0];
                }
            }
            $url = $this->baseUrl . "public/data/dynamic/flight_destinations.json";
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $str = curl_exec($ch);
            //            $str = file_get_contents($this->baseUrl . 'public/data/dynamic/flight_destinations.json',FILE_USE_INCLUDE_PATH);
            $Destinationjson = json_decode($str, true);
            $filterByFrom = $getData['source_city']; // or DEL,BLR etc.
            $filterByTo = $getData['destination_city']; // or DEL,BLR etc.
            //            die('Due to some techincal server problem unable to search flight. we are working on it.');

            $arrSourceCityId_ = array_filter($Destinationjson, function ($var) use ($filterByFrom) {
                return ($var['AirportCode'] == $filterByFrom);
            });

            $arrdestinationCityId_ = array_filter($Destinationjson, function ($var) use ($filterByTo) {
                return ($var['AirportCode'] == $filterByTo);
            });
            //echo '<pre>';print_r($Destinationjson);die;
            $arrSourceCityId = array_values($arrSourceCityId_);
            $arrdestinationCityId = array_values($arrdestinationCityId_);
            if (count($arrSourceCityId) > 0) {
                $intSourceCityId = $arrSourceCityId[0]['CityID'];
                $intCountryCode = trim($arrSourceCityId[0]['CountryCode']);
                $intOriginCountryCode = trim($arrSourceCityId[0]['CountryCode']);
            } else {
                $intSourceCityId = "";
                $intCountryCode = "";
            }

            if (count($arrdestinationCityId) > 0) {
                $intdestinationCityId = $arrdestinationCityId[0]['CityID'];
                $intdestinationCountryCode = trim($arrdestinationCityId[0]['CountryCode']);
                $intDestinaionCountryCode = trim($arrdestinationCityId[0]['CountryCode']);
            } else {
                $intdestinationCityId = "";
                $intdestinationCountryCode = "";
            }

            if ($intCountryCode == $intdestinationCountryCode) {
                $intCountryCode = 'IN';
            } else {
                $intCountryCode = 'INT';
            }

            if ($intOriginCountryCode != "IN" || empty($intOriginCountryCode)) {
                $sessionFlightSearchParams->params['interNationalSearch'] = true;
            } else if ($intdestinationCountryCode != "IN" || empty($intdestinationCountryCode)) {
                $sessionFlightSearchParams->params['interNationalSearch'] = true;
            } else {
                $sessionFlightSearchParams->params['interNationalSearch'] = false;
            }

            $sessionFlightSearchParams->params['sourceCityAirportCode'] = $getData['source_city'];
            $sessionFlightSearchParams->params['destinationCityAirportCode'] = $getData['destination_city'];

            $sessionFlightSearchParams->params['from'] = $getData['source_city'];
            $sessionFlightSearchParams->params['to'] = $getData['destination_city'];

            $sessionFlightSearchParams->params['sourceCityText'] = $getData['source'];
            $sessionFlightSearchParams->params['destinationCityText'] = $getData['destination'];

            $sessionFlightSearchParams->params['sourceCityId'] = $intSourceCityId;
            $sessionFlightSearchParams->params['destinationCityId'] = $intdestinationCityId;
            $sessionFlightSearchParams->params['intCountryCode'] = $intCountryCode;
            $sessionFlightSearchParams->params['route'] = $getData['route'];
            $sessionFlightSearchParams->params['flight_class'] = $getData['class'];

            $sessionFlightSearchParams->params['adults'] = $getData['adults'];
            $sessionFlightSearchParams->params['child'] = $getData['childs'];
            $sessionFlightSearchParams->params['infant'] = $getData['infants'];
            $sessionFlightSearchParams->params['departure_dates'] = $getData['departure_date'];
            $sessionFlightSearchParams->params['return_dates'] = !empty($getData['return_date']) ? $getData['return_date'] : '';

            $sessionFlightSearchParams->params['ContSysId_1'] = $getData['ContSysId_1'];
            $sessionFlightSearchParams->params['ContSysId'] = $getData['ContSysId'];
            $sessionFlightSearchParams->params['strDepatureDate'] = $strDepatureDate;
            $sessionFlightSearchParams->params['strReturnDate'] = $strReturnDate;
            $source_cityC = $sessionFlightSearchParams->params['source_city'];
            $destination_cityC = $sessionFlightSearchParams->params['destination_city'];
            $strDepatureDate = $sessionFlightSearchParams->params['strDepatureDate'];
            $departure_dates = $sessionFlightSearchParams->params['departure_dates'];
            $strReturnDate = $sessionFlightSearchParams->params['strReturnDate'];
            $return_dates = $sessionFlightSearchParams->params['return_dates'];
            //            echo '<pre>';print_r($recentSearch->params);
            //            echo '<pre>';print_r($sessionFlightSearchParams->params);
            $NewArray = false;
            if (!empty($recentSearch->params)) {
                foreach ($recentSearch->params as $k => $val) {
                    $source_city = $val['source_city'];
                    $destination_city = $val['destination_city'];
                    if ($source_cityC == $source_city && $destination_cityC == $destination_city) {
                        $NewArray = false;
                        $recentSearch->params[$k] = $val;
                        $recentSearch->params[$k]['departure_dates'] = $departure_dates;
                        $recentSearch->params[$k]['return_dates'] = $return_dates;
                        $recentSearch->params[$k]['strDepatureDate'] = $strDepatureDate;
                        $recentSearch->params[$k]['strReturnDate'] = $strReturnDate;
                        $recentSearch->params[$k]['searchUrl'] = $uriExp[1];
                    } else {
                        $NewArray = true;
                        $recentSearch->params[$k] = $val;
                        $recentSearch->params[$k]['searchUrl'] = $uriExp[1];
                    }
                    //
                }
            } else {
                $recentSearch->params[0] = $sessionFlightSearchParams->params;
                $recentSearch->params[0]['searchUrl'] = $uriExp[1];
            }
            if ($NewArray) {
                $recentSearch->params[] = $sessionFlightSearchParams->params;
                $recentSearch->params[]['searchUrl'] = $uriExp[1];
            }
            //            echo '<pre>';print_r($uriExp[1]);
            // echo '<pre>';print_r($sessionFlightSearchParams->params);
            //die('d');
            return true;
        } else {
            die('Oops something went wrong');
        }
    }

    public function searchApiFlights($arrSessionData = array())
    {
        $arrFlightClass = Zend_Controller_Action_HelperBroker::getStaticHelper('Flight')->getFlightClassesTripJack();
        $cabinClass = $arrFlightClass[$arrSessionData['flight_class']];
        $interNationalSearch = isset($arrSessionData['interNationalSearch']) ? trim($arrSessionData['interNationalSearch']) : 0;
        //echo '<pre>';print_r($arrSessionData);
        $arrFlightSearchResponse = array();

        $strFlightRoute = trim($arrSessionData['route']);
        $fromCityOrAirport = $arrSessionData['from'];
        $toCityOrAirport = $arrSessionData['to'];
        $strDepatureDate = $arrSessionData['strDepatureDate'];
        $strReturnDate = $arrSessionData['strReturnDate'];
        $adultCount = $arrSessionData['adults'];
        $childCount = $arrSessionData['child'];
        $infantCount = $arrSessionData['infant'];
        $intMemberCount = $adultCount + $childCount + $infantCount;
        if (isset($arrSessionData['DirectFlight']) && $arrSessionData['DirectFlight'] == 1) {
            $DirectFlight = true;
        } else {
            $DirectFlight = false;
        }
        if (isset($arrSessionData['isConnectingFlight']) && $arrSessionData['isConnectingFlight'] == 1) {
            $isConnectingFlight = true;
        } else {
            $isConnectingFlight = false;
        }
        $routeInfo = [];
        if ($strFlightRoute) {
            for ($i = 0; $i < $strFlightRoute; $i++) {
                if ($i == 0) {
                    $fromCity = $fromCityOrAirport;
                    $toCity = $toCityOrAirport;
                    $travelDate = $strDepatureDate;
                } else {
                    $fromCity = $toCityOrAirport;
                    $toCity = $fromCityOrAirport;
                    $travelDate = $strReturnDate;
                }
                $routeInfo[] = array(
                    'fromCityOrAirport' => array('code' => $fromCity),
                    'toCityOrAirport' => array('code' => $toCity),
                    'travelDate' => $travelDate,
                );
            }
        }
        if ($strFlightRoute == 1 && $interNationalSearch == '') {
            $SearchType = 'Oneway';
        } elseif ($strFlightRoute == 2 && $interNationalSearch == '') {
            $SearchType = 'DomReturn';
        } elseif ($strFlightRoute == 1 && $interNationalSearch == 1) {
            $SearchType = 'IntOneway';
        } elseif ($strFlightRoute == 2 && $interNationalSearch == 1) {
            $SearchType = 'IntReturn';
        }

        $data = array(
            'searchQuery' => array(
                'cabinClass' => ($cabinClass == 'All') ? 'ECONOMY' : strtoupper($cabinClass),
                'paxInfo' =>  array(
                    'ADULT' => $adultCount,
                    'CHILD' => $childCount,
                    'INFANT' => $infantCount,
                ),
                'routeInfos' => $routeInfo,
                'searchModifiers' => array('isDirectFlight' => $DirectFlight, 'isConnectingFlight' => $isConnectingFlight),
            ),
        );
        $logFile = $SearchType . '_' . $fromCityOrAirport . '_' . $toCityOrAirport . '_' . $adultCount . 'A_' . $childCount . 'C_' . $infantCount . 'I_isDirect_' . $DirectFlight . '_isConnecting_' . $isConnectingFlight;
        $data_stringh = json_encode($data);


        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, TRIPJACK_FL_SEARCHALL_URL);
        curl_setopt($ch, CURLOPT_ENCODING, "gzip");
        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(
            'Accept: application/json',
            'Content-Type: application/json',
            'Accept-Encoding: gzip',
            'apikey:' . APIKEY,
            'Content-Length: ' . strlen($data_stringh)
        ));

        $outputH = curl_exec($ch);
        $response = json_decode($outputH, true);
        if (FLIGHT_API_LOGS) {
            $strFilePath = "flight/FlightSearch/" . date('Y-m-d-H-i-s') . '_' . $logFile . "_request.json";
            Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $data_stringh);

            $strFilePath = "flight/FlightSearch/" . date('Y-m-d-H-i-s') . '_' . $logFile . "_response.json";
            Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $outputH);
        }

        if ($interNationalSearch && $strFlightRoute == 2) {
            $searchResult = $response['searchResult'];
            $COMBO = $searchResult['tripInfos']['COMBO'];
            $intResponseStatus = $response['status']['success'];
            $arrFlightSearchResponse['ResponseStatus'] = $intResponseStatus;
            $arrFlightSearchResponse['ErrorCode'] = '';
            $arrFlightSearchResponse['ErrorMessage'] = '';
            $arrFlightSearchResponse['OutBoundFlightResults'] = isset($COMBO) ? $COMBO : array();
            $arrFlightSearchResponse['InBoundFlightResults'] = array();
        } else {
            $searchResult = $response['searchResult'];
            $ONWARD = $searchResult['tripInfos']['ONWARD'];
            $RETURN = isset($searchResult['tripInfos']['RETURN']) ? $searchResult['tripInfos']['RETURN'] : [];
            $intResponseStatus = $response['status']['success'];
            $arrFlightSearchResponse['ResponseStatus'] = $intResponseStatus;
            $arrFlightSearchResponse['TraceId'] = '';
            $arrFlightSearchResponse['ErrorCode'] = '';
            $arrFlightSearchResponse['ErrorMessage'] = '';
            $arrFlightSearchResponse['OutBoundFlightResults'] = isset($ONWARD) ? $ONWARD : array();
            $arrFlightSearchResponse['InBoundFlightResults'] = isset($RETURN) ? $RETURN : array();
        }
        Zend_Session::namespaceUnset('FlightSearchResults');
        $FlightSearchResults = new Zend_Session_Namespace('FlightSearchResults');
        $FlightSearchResults->params = $arrFlightSearchResponse;  // store all serch result data to Session

        Zend_Session::namespaceUnset('FlightSearchLogFile');
        $FlightSearchLogFile = new Zend_Session_Namespace('FlightSearchLogFile');
        $FlightSearchLogFile->params = $logFile;  // store serch data to Session
        return $arrFlightSearchResponse;
    }

    public function GetApiFlightsFareRulesTripJack($arrData = array())
    {
        if ($arrData) {
            $FlightSearchLogFile = new Zend_Session_Namespace('FlightSearchLogFile');
            $logFile = $FlightSearchLogFile->params;
            $datah = array(
                'id' => $arrData['TraceId'],
                'flowType' => 'REVIEW',
            );

            $data_stringh = json_encode($datah);
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, TRIPJACK_FL_API_FARE_RULE_URL);
            curl_setopt($ch, CURLOPT_ENCODING, "gzip");
            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(
                'Accept: application/json',
                'Content-Type: application/json',
                'Accept-Encoding: gzip',
                'apikey:' . APIKEY,
                'Content-Length: ' . strlen($data_stringh)
            ));

            $outputH = curl_exec($ch);
            $response = json_decode($outputH, true);
            if (FLIGHT_API_LOGS) {

                //Write Request Logs starts...
                $strFilePath = "flight/FlightFareRules/" . date('Y-m-d-H-i-s') . '_' . $logFile . "_FareRules_request.json";
                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $data_stringh);
                //Write Request Logs starts...
                //Write Request Logs starts...
                $strFilePath = "flight/FlightFareRules/" . date('Y-m-d-H-i-s') . '_' . $logFile . "_FareRules_response.json";
                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $outputH);
                //Write Request Logs starts...
            }
            Zend_Session::namespaceUnset('FlightFareRulesSession');
            $FlightFareRulesSession = new Zend_Session_Namespace('FlightFareRulesSession');
            $FlightFareRulesSession->params = $response;  // store all serch result data to Session
            return $response;
        }
    }

    public function GetApiFlightsFareRules($arrData = array())
    {
        $tokenId = $this->authenticateAPI();
        if ($arrData) {
            $datah = array(
                'EndUserIp' => $_SERVER['REMOTE_ADDR'],
                'TokenId' => $tokenId,
                'TraceId' => $arrData['TraceId'],
                'ResultIndex' => $arrData['ApiResultIndex'],
            );


            //echo "<pre>";print_r($datah);exit;
            $data_stringh = json_encode($datah);
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, FLIGHT_API_FARE_RULE_URL);
            curl_setopt($ch, CURLOPT_ENCODING, "gzip");
            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(
                'Accept: application/json',
                'Content-Type: application/json',
                'Accept-Encoding: gzip',
                'Content-Length: ' . strlen($data_stringh)
            ));

            $outputH = curl_exec($ch);
            $response = json_decode($outputH, true);
            //            echo "<pre>";print_r($response);exit;
            if (FLIGHT_API_LOGS) {

                //Write Request Logs starts...
                $strFilePath = "flight/FlightFareRules/" . time() . "_FareRules_request.json";
                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $data_stringh);
                //Write Request Logs starts...
                //Write Request Logs starts...
                $strFilePath = "flight/FlightFareRules/" . time() . "_FareRules_response.json";
                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $outputH);
                //Write Request Logs starts...
            }
        }
        Zend_Session::namespaceUnset('FlightFareRulesSession');
        $FlightFareRulesSession = new Zend_Session_Namespace('FlightFareRulesSession');
        $FlightFareRulesSession->params = $response;  // store all serch result data to Session
        return $response;
    }

    public function GetApiFlightsFareQuoteTripJack($arrData = array())
    {
        if ($arrData) {
            $FlightSearchLogFile = new Zend_Session_Namespace('FlightSearchLogFile');
            $logFile = $FlightSearchLogFile->params;
            $priceIdArr = explode(',', $arrData['TraceId']);
            $datah = array(
                'priceIds' => $priceIdArr,
            );

            $data_stringh = json_encode($datah);
            // echo "<pre>";print_r($logFile);die;
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, TRIPJACK_FL_API_REVIEW_URL);
            curl_setopt($ch, CURLOPT_ENCODING, "gzip");
            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(
                'Accept: application/json',
                'Content-Type: application/json',
                'Accept-Encoding: gzip',
                'apikey:' . APIKEY,
                'Content-Length: ' . strlen($data_stringh)
            ));

            $outputH = curl_exec($ch);
            $response = json_decode($outputH, true);
            //echo "<pre>";print_r($response);exit;
            if (FLIGHT_API_LOGS) {

                //Write Request Logs starts...
                $strFilePath = "flight/FlightFareReview/" . date('Y-m-d-H-i-s') . '_' . $logFile . "_Review_request.json";
                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $data_stringh);
                //Write Request Logs starts...
                //Write Request Logs starts...
                $strFilePath = "flight/FlightFareReview/" . date('Y-m-d-H-i-s') . '_' . $logFile . "_Review_response.json";
                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $outputH);
                //Write Request Logs starts...
            }
        }
        if ($arrData['Inbound'] == 1) {
            Zend_Session::namespaceUnset('FlightFareQuoteSessionInb');
            $FlightFareQuoteSessionInb = new Zend_Session_Namespace('FlightFareQuoteSessionInb');
            $FlightFareQuoteSessionInb->params = $response;  // store all serch result data to Session
        } else {
            Zend_Session::namespaceUnset('FlightFareQuoteSession');
            $FlightFareQuoteSession = new Zend_Session_Namespace('FlightFareQuoteSession');
            $FlightFareQuoteSession->params = $response;  // store all serch result data to Session
        }

        return $response;
    }


    public function apiFlightTicketTripJack($data)
    {
        //    echo '<pre>';print_r($data);die('T');
        $SelectedMealSessionNew = new Zend_Session_Namespace('SelectedMealSessionNew');
        $SelectedBaggSessionNew = new Zend_Session_Namespace('SelectedBaggSessionNew');

        $SelectedMealSessionNewInb = new Zend_Session_Namespace('SelectedMealSessionNewInb');
        $SelectedBaggSessionNewInb = new Zend_Session_Namespace('SelectedBaggSessionNewInb');

        $flightSSRDetails = new Zend_Session_Namespace('flightSSRDetails');
        $sessionFlightSearchParams = new Zend_Session_Namespace('sessionFlightSearchParams');
        $interNationalSearch = $sessionFlightSearchParams->params['interNationalSearch'];

        $FlightSearchLogFile = new Zend_Session_Namespace('FlightSearchLogFile');
        $logFile = $FlightSearchLogFile->params;

        $MealSelected = $SelectedMealSessionNew->params;
        $BaggSelected = $SelectedBaggSessionNew->params;
        $arrSSR = $flightSSRDetails->params;
        $bookingId = $data['FlightBookingData'][0]['bookingId'];
        $isgstapply = isset($data['CustomerSession'][0]['isgstapply']) ? $data['CustomerSession'][0]['isgstapply'] : 0;
        // echo '<pre>';print_r($isgstapply);
        //echo '<pre>';print_r($data['FlightBookingData']);
        //die;
        $arrPassengers = [];
        $deliveryInfo = [];
        $ARR_SALUTION = unserialize(ARR_SALUTION);
        $ARR_SALUTION_CHILD = unserialize(ARR_SALUTION_CHILD);
        if ($bookingId && $data) {

            if ($data['CustomerSession']) {
                foreach ($data['CustomerSession'] as $key => $value) {
                    if ($key == 0) {
                        $CustomerSysId = $value['CustomerSysId'];
                    } else {
                        $CustomerSysId = $value['CustomerMemberSysId'];
                    }

                    if ($key == 0) {
                        $intMemberSysId = 1;
                    } else {
                        $intMemberSysId = 0;
                    }
                    if ($value['paxType'] == 1) {
                        $paxTitle = trim($ARR_SALUTION[$value['Salutation']], ".");
                        if ($key == 0) {
                            $deliveryInfo['emails'][$key] = $value['EmailId'];
                            $deliveryInfo['contacts'][$key] = '+' . $value['countryCode'] . '' . $value['Contacts'];
                        }
                        $paxType = 'ADULT';
                    } elseif ($value['paxType'] == 2) {
                        $paxTitle = trim($ARR_SALUTION_CHILD[$value['Salutation']], ".");
                        $paxType = 'CHILD';
                    } else {
                        $paxTitle = trim($ARR_SALUTION_CHILD[$value['Salutation']], ".");
                        $paxType = 'INFANT';
                    }
                    $arrPassengers[$key] = [
                        'ti' => $paxTitle,
                        'fN' => $value['FirstName'],
                        'lN' => $value['LastName'],
                        'dob' => $value['DOB'],
                        'pt' => $paxType,
                    ];
                    $MealArr = [];
                    if (!empty($SelectedMealSessionNew->params)) {
                        if (isset($SelectedMealSessionNew->params[$CustomerSysId]) && !empty($SelectedMealSessionNew->params[$CustomerSysId])) {
                            $meal = $SelectedMealSessionNew->params[$CustomerSysId];
                            $MealArr[] = array('key' => $meal['key'], 'code' => $meal['Code']);
                            //$arrPassengers[$key]['ssrMealInfos'] = [$MealArr];
                        }
                    }
                    if (!empty($SelectedMealSessionNewInb->params)) {
                        if (isset($SelectedMealSessionNewInb->params[$CustomerSysId]) && !empty($SelectedMealSessionNewInb->params[$CustomerSysId])) {
                            $meal2 = $SelectedMealSessionNewInb->params[$CustomerSysId];
                            $MealArr[] = array('key' => $meal2['key'], 'code' => $meal2['Code']);
                            //$arrPassengers[$key]['ssrMealInfos'] = [$MealArr];
                        }
                    }
                    $BaggArr = [];
                    if (!empty($SelectedBaggSessionNew->params)) {
                        if (isset($SelectedBaggSessionNew->params[$CustomerSysId]) && !empty($SelectedBaggSessionNew->params[$CustomerSysId])) {
                            $bagg = $SelectedBaggSessionNew->params[$CustomerSysId];
                            $BaggArr[] = array('key' => $bagg['key'], 'code' => $bagg['Code']);
                        }
                    }
                    if (!empty($SelectedBaggSessionNewInb->params)) {
                        if (isset($SelectedBaggSessionNewInb->params[$CustomerSysId]) && !empty($SelectedBaggSessionNewInb->params[$CustomerSysId])) {
                            $bagg2 = $SelectedBaggSessionNewInb->params[$CustomerSysId];
                            $BaggArr[] = array('key' => $bagg2['key'], 'code' => $bagg2['Code']);
                        }
                    }
                    if (!empty($MealArr)) {
                        $arrPassengers[$key]['ssrMealInfos'] = $MealArr;
                    }
                    if (!empty($BaggArr)) {
                        $arrPassengers[$key]['ssrBaggageInfos'] = $BaggArr;
                    }

                    // if($value['paxType'] == 3){
                    //     $arrPassengers[$key]['dob'] = $value['DOB'];
                    // }
                    if ($interNationalSearch == 1) {
                        $arrPassengers[$key]['pNum'] = $value['PassportNo'];
                        $arrPassengers[$key]['eD'] = $value['PassportExpiry'];
                        $arrPassengers[$key]['pid'] = $value['passporIssue'];
                    }
                }
            }
            if ($isgstapply == 1) {
                $gstInfo = array(
                    'gstNumber' =>   $data['CustomerSession'][0]['gstnnumber'],
                    'email' =>   $data['CustomerSession'][0]['EmailId'],
                    'registeredName' =>  $data['CustomerSession'][0]['companyname'],
                    'mobile' =>  $data['CustomerSession'][0]['Contacts'],
                    'address' => $data['CustomerSession'][0]['gstaddress'],
                );
            }
            $PublishedFare = 0;
            $baggageAmount = 0;
            $mealAmount = 0;
            $baggageAmount2 = 0;
            $mealAmount2 = 0;
            if ($data['FlightBookingData']) {
                foreach ($data['FlightBookingData'] as $amount) {
                    $PublishedFare += $amount['FairRules']['intPublishedFare'];
                }
            }
            if ($SelectedBaggSessionNew->params && !empty($SelectedBaggSessionNew->params)) {
                foreach ($SelectedBaggSessionNew->params as $baggage) {
                    $baggageAmount += $baggage['Price'];
                }
            }
            if ($SelectedMealSessionNew->params && !empty($SelectedMealSessionNew->params)) {
                foreach ($SelectedMealSessionNew->params as $meals) {
                    $mealAmount += $meals['Price'];
                }
            }
            if ($SelectedBaggSessionNewInb->params && !empty($SelectedBaggSessionNewInb->params)) {
                foreach ($SelectedBaggSessionNewInb->params as $baggage2) {
                    $baggageAmount2 += $baggage2['Price'];
                }
            }
            if ($SelectedMealSessionNewInb->params && !empty($SelectedMealSessionNewInb->params)) {
                foreach ($SelectedMealSessionNewInb->params as $meals2) {
                    $mealAmount2 += $meals2['Price'];
                }
            }
            $amount =  ($PublishedFare + $baggageAmount + $mealAmount + $baggageAmount2 + $mealAmount2);
            $paymentInfos[] = array('amount' => number_format($amount, 2, '.', ''));

            $data = array(
                'bookingId' => $bookingId,
                'paymentInfos' => $paymentInfos,
                'travellerInfo' => $arrPassengers,
                'deliveryInfo' => $deliveryInfo,
            );
            if ($isgstapply == 1) {
                $data['gstInfo'] = $gstInfo;
            }
            // echo '<pre>';
            // print_r(($data));
            // die('T');
            $data_stringh = json_encode($data);
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, TRIPJACK_FL_API_INSTANT_BOOK_URL);
            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(
                'Accept: application/json',
                'Content-Type: application/json',
                'Accept-Encoding: gzip',
                'apikey:' . APIKEY,
                'Content-Length: ' . strlen($data_stringh)
            ));


            $outputH = curl_exec($ch);
            $response = json_decode($outputH, true);

            if (FLIGHT_API_LOGS) {
                //Write Request Logs starts...
                $strFilePath = "flight/FlightTicket/" . date('Y-m-d-H-i-s') . '_' . $logFile . "_FlightTicket_request.json";
                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $data_stringh);
                //Write Request Logs starts...

                //Write Request Logs starts...
                $strFilePath = "flight/FlightTicket/" . date('Y-m-d-H-i-s') . '_' . $logFile . "_FlightTicket_response.json";
                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $outputH);
                //Write Request Logs starts...

            }
            Zend_Session::namespaceUnset('FlightBookingTicket');
            $FlightBookingTicket = new Zend_Session_Namespace('FlightBookingTicket');
            $FlightBookingTicket->params = $response;
            return $response;
        } else {
            return $response = [];
        }
        exit;
    }
    public function bookingDetailsTripJack($response)
    {
        $ResponseStatus = isset($response['status']['success']) ? $response['status']['success'] : '0';

        if ($ResponseStatus == 1) {
            $FlightSearchLogFile = new Zend_Session_Namespace('FlightSearchLogFile');
            $logFile = $FlightSearchLogFile->params;
            $bookingId = isset($response['bookingId']) ? $response['bookingId'] : '0';
            $data = array(
                'bookingId' => $bookingId
            );
            $data_stringh = json_encode($data);
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, TRIPJACK_FL_API_BOOKINGDETAILS_URL);
            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(
                'Accept: application/json',
                'Content-Type: application/json',
                //'Accept-Encoding: gzip',
                'apikey:' . APIKEY,
                'Content-Length: ' . strlen($data_stringh)
            ));
            $outputH = curl_exec($ch);
            //$res = json_decode($outputH, true);
            //echo "<pre>";print_r($outputH);die('lcc');
            if (FLIGHT_API_LOGS) {
                $strFilePath = "flight/BookingDetails/" . date('Y-m-d-H-i-s') . '_' . $logFile . "_BookingDetails_request.json";
                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $data_stringh);

                $strFilePath = "flight/BookingDetails/" . date('Y-m-d-H-i-s') . '_' . $logFile . "_BookingDetails_response.json";
                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $outputH);
            }

            //echo "<pre>";print_r($outputH);die('lcc');
            return json_decode($outputH, true);
        } else {
            return $response;
        }
    }
    public function apiFlightTicket($data)
    {
        //        echo '<pre>';print_r($data);die('T');
        $SelectedMealSessionNew = new Zend_Session_Namespace('SelectedMealSessionNew');
        $SelectedBaggSessionNew = new Zend_Session_Namespace('SelectedBaggSessionNew');
        $flightSSRDetails = new Zend_Session_Namespace('flightSSRDetails');
        $MealSelected = $SelectedMealSessionNew->params;
        $BaggSelected = $SelectedBaggSessionNew->params;
        $arrSSR = $flightSSRDetails->params;
        //echo "<pre>";print_r($BaggSelected);exit;
        $TraceId = $data['FlightBookingData']['apiTraceId'];
        $ResultIndex = $data['FlightBookingData']['ApiResultIndex'];
        $arrPassengers = [];
        $ARR_SALUTION = unserialize(ARR_SALUTION);
        if ($TraceId && $ResultIndex && $data) {
            $arrFairDetails = $data['FlightBookingData']['FairRules']['FareBreakdown'];
            $paxCountryTitle = $data['FlightBookingData']['Segments'][0]['originCountryName'];
            $paxCountryCode = $data['sessionFlightSearchParams']['intCountryCode'];
            $IsInternational = $data['sessionFlightSearchParams']['interNationalSearch'];
            $GSTCompanyAddress = '';
            $GSTCompanyContactNumber = '';
            $GSTCompanyName = '';
            $GSTNumber = '';
            $GSTCompanyEmail = '';
            $agencyEmailId = '';
            if ($data['CustomerSession']) {
                //$dataSSR = array('TraceId' => $TraceId, 'ResultIndex' => $ResultIndex);
                //$arrSSR = $this->flightSSRDetails($dataSSR);
                //                $arrSSR = [];
                foreach ($data['CustomerSession'] as $key => $value) {
                    if ($key == 0) {
                        $CustomerSysId = $value['CustomerSysId'];
                    } else {
                        $CustomerSysId = $value['CustomerMemberSysId'];
                    }
                    if (isset($MealSelected[$CustomerSysId]) && !empty($MealSelected[$CustomerSysId])) {
                        $WayType            = $MealSelected[$CustomerSysId]['WayType'];
                        $Code               = $MealSelected[$CustomerSysId]['Code'];
                        $Description        = $MealSelected[$CustomerSysId]['Description'];
                        $AirlineDescription = $MealSelected[$CustomerSysId]['AirlineDescription'];
                        $Quantity           = $MealSelected[$CustomerSysId]['Quantity'];
                        $Currency           = $MealSelected[$CustomerSysId]['Currency'];
                        $Price              = $MealSelected[$CustomerSysId]['Price'];
                        $Origin             = $MealSelected[$CustomerSysId]['Origin'];
                        $Destination        = $MealSelected[$CustomerSysId]['Destination'];
                    } else {
                        $WayType            = isset($arrSSR['MealDynamic'][0][0]['WayType']) ? trim($arrSSR['MealDynamic'][0][0]['WayType']) : '2';
                        $Code               = isset($arrSSR['MealDynamic'][0][0]['Code']) ? trim($arrSSR['MealDynamic'][0][0]['Code']) : 'No Meal';
                        $Description        = isset($arrSSR['MealDynamic'][0][0]['Description']) ? trim($arrSSR['MealDynamic'][0][0]['Description']) : '2';
                        $AirlineDescription = isset($arrSSR['MealDynamic'][0][0]['AirlineDescription']) ? trim($arrSSR['MealDynamic'][0][0]['AirlineDescription']) : '';
                        $Quantity           = isset($arrSSR['MealDynamic'][0][0]['Quantity']) ? trim($arrSSR['MealDynamic'][0][0]['Quantity']) : '0';
                        $Currency           = isset($arrSSR['MealDynamic'][0][0]['Currency']) ? trim($arrSSR['MealDynamic'][0][0]['Currency']) : 'INR';
                        $Price              = isset($arrSSR['MealDynamic'][0][0]['Price']) ? trim($arrSSR['MealDynamic'][0][0]['Price']) : '0';
                        $Origin             = isset($arrSSR['MealDynamic'][0][0]['Origin']) ? trim($arrSSR['MealDynamic'][0][0]['Origin']) : trim($data['Origin']);
                        $Destination        = isset($arrSSR['MealDynamic'][0][0]['Destination']) ? trim($arrSSR['MealDynamic'][0][0]['Destination']) : ($data['Destination']);
                    }
                    if (isset($BaggSelected[$CustomerSysId]) && !empty($BaggSelected[$CustomerSysId])) {
                        $WayTypeBaggage            = $BaggSelected[$CustomerSysId]['WayType'];
                        $CodeBaggage               = $BaggSelected[$CustomerSysId]['Code'];
                        $DescriptionBaggage        = $BaggSelected[$CustomerSysId]['Description'];
                        $WeightBaggage             = $BaggSelected[$CustomerSysId]['Weight'];
                        $CurrencyBaggage           = $BaggSelected[$CustomerSysId]['Currency'];
                        $PriceBaggage              = $BaggSelected[$CustomerSysId]['Price'];
                    } else {
                        $WayTypeBaggage            = isset($arrSSR['Baggage'][0][0]['WayType']) ? trim($arrSSR['Baggage'][0][0]['WayType']) : '2';
                        $CodeBaggage               = isset($arrSSR['Baggage'][0][0]['Code']) ? trim($arrSSR['Baggage'][0][0]['Code']) : 'No Baggage';
                        $DescriptionBaggage        = isset($arrSSR['Baggage'][0][0]['Description']) ? trim($arrSSR['Baggage'][0][0]['Description']) : '2';
                        $WeightBaggage             = isset($arrSSR['Baggage'][0][0]['Weight']) ? trim($arrSSR['Baggage'][0][0]['Weight']) : '0';
                        $CurrencyBaggage           = isset($arrSSR['Baggage'][0][0]['Currency']) ? trim($arrSSR['Baggage'][0][0]['Currency']) : 'INR';
                        $PriceBaggage              = isset($arrSSR['Baggage'][0][0]['Price']) ? trim($arrSSR['Baggage'][0][0]['Price']) : '0';
                    }
                    $paxTitle = trim($ARR_SALUTION[$value['Salutation']], ".");
                    if ($value['Salutation'] <= 2) {
                        $intGender = $value['Salutation'];
                    } else {
                        $intGender = 2;
                    }
                    $PassportNo = $value['PassportNo'];
                    $PassportExpiry = $value['PassportExpiry'];
                    $paxAddress = $value['Address'];
                    $paxCityTitle = $value['CityTitle'];
                    $paxContactNo = $value['Contacts'];
                    if ($key == 0) {
                        $intMemberSysId = 1;
                    } else {
                        $intMemberSysId = 0;
                    }
                    if ($arrFairDetails) {
                        foreach ($arrFairDetails as $fare) {
                            $PassengerType = $fare['PassengerType'];
                            if ($PassengerType == 1) {
                                $arrFairDetails2 = $arrFairDetails[0];
                            }
                            if ($PassengerType == 2) {
                                $arrFairDetails2 = $arrFairDetails[1];
                            }
                            if ($PassengerType == 3) {
                                $arrFairDetails2 = $arrFairDetails[2];
                            }
                        }
                    }
                    $intBaseFare = $arrFairDetails2['BaseFare'];
                    $intTax = $arrFairDetails2['Tax'];
                    $intYQTax = $arrFairDetails2['YQTax'];
                    $intAdditionalTxnFeeOfrd = $arrFairDetails2['AdditionalTxnFeeOfrd'];
                    $intAdditionalTxnFeePub = $arrFairDetails2['AdditionalTxnFeePub'];
                    $intAirTransFee = "00.00";
                    $intTransactionFee = "00.00";
                    $arrPassengers[] = [
                        'Title' => $paxTitle,
                        'FirstName' => $value['FirstName'],
                        'LastName' => $value['LastName'],
                        'PaxType' => $value['paxType'],
                        'DateOfBirth' => $value['DOB'],
                        'Gender' => $intGender,
                        'PassportNo' => ($IsInternational == 1) ? $PassportNo : '',
                        'PassportExpiry' => ($IsInternational == 1) ? $PassportExpiry : '',
                        'AddressLine1' => $paxAddress,
                        'AddressLine2' => '',
                        'City' => $paxCityTitle,
                        'CountryCode' => $paxCountryCode,
                        'CountryName' => $paxCountryTitle,
                        'ContactNo' => $paxContactNo,
                        'Email' => !empty($agencyEmailId) ? $agencyEmailId : "gaurav@hellogtx.com",
                        'IsLeadPax' => $intMemberSysId,
                        'FFAirline' => '',
                        'FFNumber' => '',
                        'GSTCompanyAddress' => $GSTCompanyAddress,
                        'GSTCompanyContactNumber' => $GSTCompanyContactNumber,
                        'GSTCompanyName' => $GSTCompanyName,
                        'GSTNumber' => $GSTNumber,
                        'GSTCompanyEmail' => $GSTCompanyEmail,
                        'Fare' =>
                        [
                            'BaseFare' => $intBaseFare,
                            'Tax' => $intTax,
                            'TransactionFee' => $intTransactionFee,
                            'YQTax' => $intYQTax,
                            'AdditionalTxnFeeOfrd' => $intAdditionalTxnFeeOfrd,
                            'AdditionalTxnFeePub' => $intAdditionalTxnFeePub,
                            'AirTransFee' => $intAirTransFee
                        ],
                        'MealDynamic' =>
                        [
                            'WayType' => $WayType,
                            'Code' => $Code,
                            'Description' => $Description,
                            'AirlineDescription' => $AirlineDescription,
                            'Quantity' => $Quantity,
                            'Price' => $Price,
                            'Currency' => $Currency,
                            'Origin' => $Origin,
                            'Destination' => $Destination
                        ],
                        'Baggage' =>
                        [
                            'WayType' => $WayTypeBaggage,
                            'Code' => $CodeBaggage,
                            'Description' => $DescriptionBaggage,
                            'Weight' => $WeightBaggage,
                            'Currency' => $CurrencyBaggage,
                            'Price' => $PriceBaggage,
                            'Origin' => $Origin,
                            'Destination' => $Destination
                        ]
                    ];
                }
            }
            //echo "<pre>";print_r($arrPassengers);exit;
            $tokenId = $this->authenticateAPI();
            $data = array(
                'PreferredCurrency' => 'INR',
                'IsBaseCurrencyRequired' => 'true',
                'EndUserIp' => $_SERVER['REMOTE_ADDR'],
                'TokenId' => $tokenId,
                'TraceId' => $TraceId,
                'ResultIndex' => $ResultIndex,
                'Passengers' => $arrPassengers

            );
            //            echo "<pre>";print_r($data);die('TTT');
            $data_stringh = json_encode($data);

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, FLIGHT_API_TICKET_URL);
            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);
            //echo "<pre>";print_r($outputH);die('lcc');
            $response = json_decode($outputH, true);

            if (FLIGHT_API_LOGS) {
                //Write Request Logs starts...
                $strFilePath = "flight/FlightTicket/" . time() . "_FlightTicket_request.json";
                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $data_stringh);
                //Write Request Logs starts...

                //Write Request Logs starts...
                $strFilePath = "flight/FlightTicket/" . time() . "_FlightTicket_response.json";
                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $outputH);
                //Write Request Logs starts...

            }
            //echo "<pre>";print_r($response);exit;
            //            Zend_Session::namespaceUnset('FlightBookingTicketSession');
            //            $FlightBookingTicketSession = new Zend_Session_Namespace('FlightBookingTicketSession');
            //            $FlightBookingTicketSession->params = $response;
            return $response;
        } else {
            return $response = [];
        }
        exit;
    }

    public function apiFlightBooking($data)
    {
        $SelectedMealSessionNew = new Zend_Session_Namespace('SelectedMealSessionNew');
        $arrSSRSelected = $SelectedMealSessionNew->params;
        $flightSSRDetails = new Zend_Session_Namespace('flightSSRDetails');

        $TraceId = $data['FlightBookingData']['apiTraceId'];
        $ResultIndex = $data['FlightBookingData']['ApiResultIndex'];
        $arrPassengers = [];
        $ARR_SALUTION = unserialize(ARR_SALUTION);
        if ($TraceId && $ResultIndex && $data) {
            $arrFairDetails = $data['FlightBookingData']['FairRules']['FareBreakdown'];
            //            $IsInternational = $data['FlightBookingData']['IsInternational'];
            $paxCountryTitle = $data['FlightBookingData']['Segments'][0]['originCountryName'];
            $paxCountryCode = $data['sessionFlightSearchParams']['intCountryCode'];
            $IsInternational = $data['sessionFlightSearchParams']['interNationalSearch'];
            $GSTCompanyAddress = '';
            $GSTCompanyContactNumber = '';
            $GSTCompanyName = '';
            $GSTNumber = '';
            $GSTCompanyEmail = '';
            $agencyEmailId = '';
            if ($data['CustomerSession']) {
                //$dataSSR = array('TraceId' => $TraceId, 'ResultIndex' => $ResultIndex);
                //$arrSSR = $this->flightSSRDetails($dataSSR);
                //                $arrSSR = [];
                $MealCode            = isset($flightSSRDetails->params['Meal'][0]['Code']) ? trim($flightSSRDetails->params['Meal'][0]['Code']) : 'VGML';
                $MealDesc            = isset($flightSSRDetails->params['Meal'][0]['Description']) ? trim($flightSSRDetails->params['Meal'][0]['Description']) : 'Veg/Non Dairy';

                $SeatCode            = isset($flightSSRDetails->params['SeatPreference'][0]['Code']) ? trim($flightSSRDetails->params['SeatPreference'][0]['Code']) : 'A';
                $SeatDesc            = isset($flightSSRDetails->params['SeatPreference'][0]['Description']) ? trim($flightSSRDetails->params['SeatPreference'][0]['Description']) : 'Window';
                foreach ($data['CustomerSession'] as $key => $value) {
                    if ($key == 0) {
                        $CustomerSysId = $value['CustomerSysId'];
                    } else {
                        $CustomerSysId = $value['CustomerMemberSysId'];
                    }
                    if (isset($arrSSRSelected[$CustomerSysId]) && !empty($arrSSRSelected[$CustomerSysId])) {
                        $MealCode = $arrSSRSelected[$CustomerSysId]['Code'];
                        $MealDesc = $arrSSRSelected[$CustomerSysId]['Description'];
                    } else {
                        $MealCode = isset($flightSSRDetails->params['Meal'][0]['Code']) ? trim($flightSSRDetails->params['Meal'][0]['Code']) : 'VGML';
                        $MealDesc = isset($flightSSRDetails->params['Meal'][0]['Description']) ? trim($flightSSRDetails->params['Meal'][0]['Description']) : 'Veg/Non Dairy';
                    }
                    $paxTitle = trim($ARR_SALUTION[$value['Salutation']], ".");
                    if ($value['Salutation'] <= 2) {
                        $intGender = $value['Salutation'];
                    } else {
                        $intGender = 2;
                    }
                    $PassportNo = $value['PassportNo'];
                    $PassportExpiry = $value['PassportExpiry'];
                    $paxAddress = $value['Address'];
                    $paxCityTitle = $value['CityTitle'];
                    $paxContactNo = $value['Contacts'];
                    if ($key == 0) {
                        $intMemberSysId = 1;
                    } else {
                        $intMemberSysId = 0;
                    }
                    if ($arrFairDetails) {
                        foreach ($arrFairDetails as $fare) {
                            $PassengerType = $fare['PassengerType'];
                            if ($PassengerType == 1) {
                                $arrFairDetails2 = $arrFairDetails[0];
                            }
                            if ($PassengerType == 2) {
                                $arrFairDetails2 = $arrFairDetails[1];
                            }
                            if ($PassengerType == 3) {
                                $arrFairDetails2 = $arrFairDetails[2];
                            }
                        }
                    }
                    $intBaseFare = $arrFairDetails2['BaseFare'];
                    $intTax = $arrFairDetails2['Tax'];
                    $intYQTax = $arrFairDetails2['YQTax'];
                    $intAdditionalTxnFeeOfrd = $arrFairDetails2['AdditionalTxnFeeOfrd'];
                    $intAdditionalTxnFeePub = $arrFairDetails2['AdditionalTxnFeePub'];
                    $intAirTransFee = "00.00";
                    $intTransactionFee = "00.00";
                    $arrPassengers[] = [
                        'Title' => $paxTitle,
                        'FirstName' => $value['FirstName'],
                        'LastName' => $value['LastName'],
                        'PaxType' => $value['paxType'],
                        'DateOfBirth' => $value['DOB'],
                        'Gender' => $intGender,
                        'PassportNo' => ($IsInternational == 1) ? $PassportNo : '',
                        'PassportExpiry' => ($IsInternational == 1) ? $PassportExpiry : '',
                        'AddressLine1' => $paxAddress,
                        'AddressLine2' => '',
                        'City' => $paxCityTitle,
                        'CountryCode' => $paxCountryCode,
                        'CountryName' => $paxCountryTitle,
                        'ContactNo' => $paxContactNo,
                        'Email' => !empty($agencyEmailId) ? $agencyEmailId : "gaurav@hellogtx.com",
                        'IsLeadPax' => $intMemberSysId,
                        'FFAirline' => '',
                        'FFNumber' => '',
                        'GSTCompanyAddress' => $GSTCompanyAddress,
                        'GSTCompanyContactNumber' => $GSTCompanyContactNumber,
                        'GSTCompanyName' => $GSTCompanyName,
                        'GSTNumber' => $GSTNumber,
                        'GSTCompanyEmail' => $GSTCompanyEmail,
                        'Fare' =>
                        [
                            'BaseFare' => $intBaseFare,
                            'Tax' => $intTax,
                            'TransactionFee' => $intTransactionFee,
                            'YQTax' => $intYQTax,
                            'AdditionalTxnFeeOfrd' => $intAdditionalTxnFeeOfrd,
                            'AdditionalTxnFeePub' => $intAdditionalTxnFeePub,
                            'AirTransFee' => $intAirTransFee
                        ],
                        'Meal' =>
                        [
                            'Code' => $MealCode,
                            'Description' => $MealDesc
                        ],
                        'Seat' =>
                        [
                            'Code' => $SeatCode,
                            'Description' => $SeatDesc
                        ]
                    ];
                }
            }
            //           echo "<pre>";print_r($arrPassengers);exit;
            $tokenId = $this->authenticateAPI();
            $dataArr = array(
                'EndUserIp' => $_SERVER['REMOTE_ADDR'],
                'TokenId' => $tokenId,
                'TraceId' => $TraceId,
                'ResultIndex' => $ResultIndex,
                'Passengers' => $arrPassengers
            );
            $data_stringh = json_encode($dataArr);
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, FLIGHT_API_BOOKING_URL);
            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);

            if (FLIGHT_API_LOGS) {
                //Write Request Logs starts...
                $strFilePath = "flight/FlightBooking/" . time() . "_FlightBooking_request.json";
                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $data_stringh);
                //Write Request Logs starts...

                //Write Request Logs starts...
                $strFilePath = "flight/FlightBooking/" . time() . "_FlightBooking_response.json";
                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $outputH);
                //Write Request Logs starts...
            }
            //            Zend_Session::namespaceUnset('FlightBookingTicketSession');
            //            $FlightBookingTicketSession = new Zend_Session_Namespace('FlightBookingTicketSession');
            //            $FlightBookingTicketSession->params = $response;
            return $response;
        } else {
            return $response = [];
        }
    }




    public function generateRoundTripRequest($data, $IsLCC)
    {
        //echo '<pre>';print_r($data['FlightBookingData']['JourneyType']);die;
        if ($IsLCC) {
            if ($data['FlightBookingData']['JourneyType'] == 1) {
                $SelectedMealSessionNew = new Zend_Session_Namespace('SelectedMealSessionNew');
                $SelectedBaggSessionNew = new Zend_Session_Namespace('SelectedBaggSessionNew');
                $flightSSRDetails = new Zend_Session_Namespace('flightSSRDetails');
                $MealSelected = $SelectedMealSessionNew->params;
                $BaggSelected = $SelectedBaggSessionNew->params;
                $arrSSR = $flightSSRDetails->params;
            } else {
                $SelectedMealSessionNewInb = new Zend_Session_Namespace('SelectedMealSessionNewInb');
                $SelectedBaggSessionNewInb = new Zend_Session_Namespace('SelectedBaggSessionNewInb');
                $flightSSRDetailsInb = new Zend_Session_Namespace('flightSSRDetailsInb');
                $MealSelected = $SelectedMealSessionNewInb->params;
                $BaggSelected = $SelectedBaggSessionNewInb->params;
                $arrSSR = $flightSSRDetailsInb->params;
            }
            //$SelectedMealSessionNew = new Zend_Session_Namespace('SelectedMealSessionNew');
            //$SelectedBaggSessionNew = new Zend_Session_Namespace('SelectedBaggSessionNew');
            //$flightSSRDetails = new Zend_Session_Namespace('flightSSRDetails');

            $TraceId = $data['FlightBookingData']['apiTraceId'];
            $ResultIndex = $data['FlightBookingData']['ApiResultIndex'];
            $arrPassengers = [];
            $ARR_SALUTION = unserialize(ARR_SALUTION);
            if ($TraceId && $ResultIndex && $data) {
                $arrFairDetails = $data['FlightBookingData']['FairRules']['FareBreakdown'];
                $IsInternational = $data['FlightBookingData']['IsInternational'];
                $paxCountryTitle = $data['FlightBookingData']['Segments'][0]['originCountryName'];
                $paxCountryCode = $data['sessionFlightSearchParams']['intCountryCode'];
                $GSTCompanyAddress = '';
                $GSTCompanyContactNumber = '';
                $GSTCompanyName = '';
                $GSTNumber = '';
                $GSTCompanyEmail = '';
                $agencyEmailId = '';
                if ($data['CustomerSession']) {
                    //$dataSSR = array('TraceId' => $TraceId, 'ResultIndex' => $ResultIndex);
                    //$arrSSR = $this->flightSSRDetails($dataSSR);
                    //                $arrSSR = [];
                    foreach ($data['CustomerSession'] as $key => $value) {
                        if ($key == 0) {
                            $CustomerSysId = $value['CustomerSysId'];
                        } else {
                            $CustomerSysId = $value['CustomerMemberSysId'];
                        }
                        if (isset($MealSelected[$CustomerSysId]) && !empty($MealSelected[$CustomerSysId])) {
                            $WayType            = $MealSelected[$CustomerSysId]['WayType'];
                            $Code               = $MealSelected[$CustomerSysId]['Code'];
                            $Description        = $MealSelected[$CustomerSysId]['Description'];
                            $AirlineDescription = $MealSelected[$CustomerSysId]['AirlineDescription'];
                            $Quantity           = $MealSelected[$CustomerSysId]['Quantity'];
                            $Currency           = $MealSelected[$CustomerSysId]['Currency'];
                            $Price              = $MealSelected[$CustomerSysId]['Price'];
                            $Origin             = $MealSelected[$CustomerSysId]['Origin'];
                            $Destination        = $MealSelected[$CustomerSysId]['Destination'];
                        } else {
                            $WayType            = isset($arrSSR['MealDynamic'][0][0]['WayType']) ? trim($arrSSR['MealDynamic'][0][0]['WayType']) : '2';
                            $Code               = isset($arrSSR['MealDynamic'][0][0]['Code']) ? trim($arrSSR['MealDynamic'][0][0]['Code']) : 'No Meal';
                            $Description        = isset($arrSSR['MealDynamic'][0][0]['Description']) ? trim($arrSSR['MealDynamic'][0][0]['Description']) : '2';
                            $AirlineDescription = isset($arrSSR['MealDynamic'][0][0]['AirlineDescription']) ? trim($arrSSR['MealDynamic'][0][0]['AirlineDescription']) : '';
                            $Quantity           = isset($arrSSR['MealDynamic'][0][0]['Quantity']) ? trim($arrSSR['MealDynamic'][0][0]['Quantity']) : '0';
                            $Currency           = isset($arrSSR['MealDynamic'][0][0]['Currency']) ? trim($arrSSR['MealDynamic'][0][0]['Currency']) : 'INR';
                            $Price              = isset($arrSSR['MealDynamic'][0][0]['Price']) ? trim($arrSSR['MealDynamic'][0][0]['Price']) : '0';
                            $Origin             = isset($arrSSR['MealDynamic'][0][0]['Origin']) ? trim($arrSSR['MealDynamic'][0][0]['Origin']) : trim($data['Origin']);
                            $Destination        = isset($arrSSR['MealDynamic'][0][0]['Destination']) ? trim($arrSSR['MealDynamic'][0][0]['Destination']) : ($data['Destination']);
                        }
                        if (isset($BaggSelected[$CustomerSysId]) && !empty($BaggSelected[$CustomerSysId])) {
                            $WayTypeBaggage            = $BaggSelected[$CustomerSysId]['WayType'];
                            $CodeBaggage               = $BaggSelected[$CustomerSysId]['Code'];
                            $DescriptionBaggage        = $BaggSelected[$CustomerSysId]['Description'];
                            $WeightBaggage             = $BaggSelected[$CustomerSysId]['Weight'];
                            $CurrencyBaggage           = $BaggSelected[$CustomerSysId]['Currency'];
                            $PriceBaggage              = $BaggSelected[$CustomerSysId]['Price'];
                        } else {
                            $WayTypeBaggage            = isset($arrSSR['Baggage'][0][0]['WayType']) ? trim($arrSSR['Baggage'][0][0]['WayType']) : '2';
                            $CodeBaggage               = isset($arrSSR['Baggage'][0][0]['Code']) ? trim($arrSSR['Baggage'][0][0]['Code']) : 'No Baggage';
                            $DescriptionBaggage        = isset($arrSSR['Baggage'][0][0]['Description']) ? trim($arrSSR['Baggage'][0][0]['Description']) : '2';
                            $WeightBaggage             = isset($arrSSR['Baggage'][0][0]['Weight']) ? trim($arrSSR['Baggage'][0][0]['Weight']) : '0';
                            $CurrencyBaggage           = isset($arrSSR['Baggage'][0][0]['Currency']) ? trim($arrSSR['Baggage'][0][0]['Currency']) : 'INR';
                            $PriceBaggage              = isset($arrSSR['Baggage'][0][0]['Price']) ? trim($arrSSR['Baggage'][0][0]['Price']) : '0';
                        }
                        $paxTitle = trim($ARR_SALUTION[$value['Salutation']], ".");
                        if ($value['Salutation'] <= 2) {
                            $intGender = $value['Salutation'];
                        } else {
                            $intGender = 2;
                        }
                        $PassportNo = $value['PassportNo'];
                        $PassportExpiry = $value['PassportExpiry'];
                        $paxAddress = $value['Address'];
                        $paxCityTitle = $value['CityTitle'];
                        $paxContactNo = $value['Contacts'];
                        if ($key == 0) {
                            $intMemberSysId = 1;
                        } else {
                            $intMemberSysId = 0;
                        }
                        if ($arrFairDetails) {
                            foreach ($arrFairDetails as $fare) {
                                $PassengerType = $fare['PassengerType'];
                                if ($PassengerType == 1) {
                                    $arrFairDetails2 = $arrFairDetails[0];
                                }
                                if ($PassengerType == 2) {
                                    $arrFairDetails2 = $arrFairDetails[1];
                                }
                                if ($PassengerType == 3) {
                                    $arrFairDetails2 = $arrFairDetails[2];
                                }
                            }
                        }
                        $intBaseFare = $arrFairDetails2['BaseFare'];
                        $intTax = $arrFairDetails2['Tax'];
                        $intYQTax = $arrFairDetails2['YQTax'];
                        $intAdditionalTxnFeeOfrd = $arrFairDetails2['AdditionalTxnFeeOfrd'];
                        $intAdditionalTxnFeePub = $arrFairDetails2['AdditionalTxnFeePub'];
                        $intAirTransFee = "00.00";
                        $intTransactionFee = "00.00";
                        $arrPassengers[] = [
                            'Title' => $paxTitle,
                            'FirstName' => $value['FirstName'],
                            'LastName' => $value['LastName'],
                            'PaxType' => $value['paxType'],
                            'DateOfBirth' => $value['DOB'],
                            'Gender' => $intGender,
                            'PassportNo' => ($IsInternational == 1) ? $PassportNo : '',
                            'PassportExpiry' => ($IsInternational == 1) ? $PassportExpiry : '',
                            'AddressLine1' => $paxAddress,
                            'AddressLine2' => '',
                            'City' => $paxCityTitle,
                            'CountryCode' => $paxCountryCode,
                            'CountryName' => $paxCountryTitle,
                            'ContactNo' => $paxContactNo,
                            'Email' => !empty($agencyEmailId) ? $agencyEmailId : "gaurav@hellogtx.com",
                            'IsLeadPax' => $intMemberSysId,
                            'FFAirline' => '',
                            'FFNumber' => '',
                            'GSTCompanyAddress' => $GSTCompanyAddress,
                            'GSTCompanyContactNumber' => $GSTCompanyContactNumber,
                            'GSTCompanyName' => $GSTCompanyName,
                            'GSTNumber' => $GSTNumber,
                            'GSTCompanyEmail' => $GSTCompanyEmail,
                            'Fare' =>
                            [
                                'BaseFare' => $intBaseFare,
                                'Tax' => $intTax,
                                'TransactionFee' => $intTransactionFee,
                                'YQTax' => $intYQTax,
                                'AdditionalTxnFeeOfrd' => $intAdditionalTxnFeeOfrd,
                                'AdditionalTxnFeePub' => $intAdditionalTxnFeePub,
                                'AirTransFee' => $intAirTransFee
                            ],
                            'MealDynamic' =>
                            [
                                'WayType' => $WayType,
                                'Code' => $Code,
                                'Description' => $Description,
                                'AirlineDescription' => $AirlineDescription,
                                'Quantity' => $Quantity,
                                'Price' => $Price,
                                'Currency' => $Currency,
                                'Origin' => $Origin,
                                'Destination' => $Destination
                            ],
                            'Baggage' =>
                            [
                                'WayType' => $WayTypeBaggage,
                                'Code' => $CodeBaggage,
                                'Description' => $DescriptionBaggage,
                                'Weight' => $WeightBaggage,
                                'Currency' => $CurrencyBaggage,
                                'Price' => $PriceBaggage,
                                'Origin' => $Origin,
                                'Destination' => $Destination
                            ]
                        ];
                    }
                }
                //            echo "<pre>";print_r($arrPassengers);exit;
                $tokenId = $this->authenticateAPI();
                $request = array(
                    'PreferredCurrency' => 'INR',
                    'IsBaseCurrencyRequired' => 'true',
                    'EndUserIp' => $_SERVER['REMOTE_ADDR'],
                    'TokenId' => $tokenId,
                    'TraceId' => $TraceId,
                    'ResultIndex' => $ResultIndex,
                    'Passengers' => $arrPassengers

                );
            }
        } else {
            if ($data['FlightBookingData']['JourneyType'] == 1) {
                $SelectedMealSessionNew = new Zend_Session_Namespace('SelectedMealSessionNew');
                $arrSSRSelected = $SelectedMealSessionNew->params;
                $flightSSRDetails = new Zend_Session_Namespace('flightSSRDetails');
                $arrSSR = $flightSSRDetails->params;
            } else {
                $SelectedMealSessionNewInb = new Zend_Session_Namespace('SelectedMealSessionNewInb');
                $arrSSRSelected = $SelectedMealSessionNewInb->params;
                $flightSSRDetailsInb = new Zend_Session_Namespace('flightSSRDetailsInb');
                $arrSSR = $flightSSRDetailsInb->params;
            }
            $TraceId = $data['FlightBookingData']['apiTraceId'];
            $ResultIndex = $data['FlightBookingData']['ApiResultIndex'];
            $arrPassengers = [];
            $ARR_SALUTION = unserialize(ARR_SALUTION);
            if ($TraceId && $ResultIndex && $data) {
                $arrFairDetails = $data['FlightBookingData']['FairRules']['FareBreakdown'];
                $IsInternational = $data['FlightBookingData']['IsInternational'];
                $paxCountryTitle = $data['FlightBookingData']['Segments'][0]['originCountryName'];
                $paxCountryCode = $data['sessionFlightSearchParams']['intCountryCode'];
                $GSTCompanyAddress = '';
                $GSTCompanyContactNumber = '';
                $GSTCompanyName = '';
                $GSTNumber = '';
                $GSTCompanyEmail = '';
                $agencyEmailId = '';
                if ($data['CustomerSession']) {
                    //$dataSSR = array('TraceId' => $TraceId, 'ResultIndex' => $ResultIndex);
                    //$arrSSR = $this->flightSSRDetails($dataSSR);

                    $SeatCode            = isset($arrSSR['SeatPreference'][0]['Code']) ? trim($arrSSR['SeatPreference'][0]['Code']) : 'A';
                    $SeatDesc            = isset($arrSSR['SeatPreference'][0]['Description']) ? trim($arrSSR['SeatPreference'][0]['Description']) : 'Window';
                    foreach ($data['CustomerSession'] as $key => $value) {
                        if ($key == 0) {
                            $CustomerSysId = $value['CustomerSysId'];
                        } else {
                            $CustomerSysId = $value['CustomerMemberSysId'];
                        }
                        if (isset($arrSSRSelected[$CustomerSysId]) && !empty($arrSSRSelected[$CustomerSysId])) {
                            $MealCode = $arrSSRSelected[$CustomerSysId]['Code'];
                            $MealDesc = $arrSSRSelected[$CustomerSysId]['Description'];
                        } else {
                            $MealCode = isset($arrSSR['Meal'][0]['Code']) ? trim($arrSSR['Meal'][0]['Code']) : 'VGML';
                            $MealDesc = isset($arrSSR['Meal'][0]['Description']) ? trim($arrSSR['Meal'][0]['Description']) : 'Veg/Non Dairy';
                        }
                        $paxTitle = trim($ARR_SALUTION[$value['Salutation']], ".");
                        if ($value['Salutation'] <= 2) {
                            $intGender = $value['Salutation'];
                        } else {
                            $intGender = 2;
                        }
                        $PassportNo = $value['PassportNo'];
                        $PassportExpiry = $value['PassportExpiry'];
                        $paxAddress = $value['Address'];
                        $paxCityTitle = $value['CityTitle'];
                        $paxContactNo = $value['Contacts'];
                        if ($key == 0) {
                            $intMemberSysId = 1;
                        } else {
                            $intMemberSysId = 0;
                        }
                        if ($arrFairDetails) {
                            foreach ($arrFairDetails as $fare) {
                                $PassengerType = $fare['PassengerType'];
                                if ($PassengerType == 1) {
                                    $arrFairDetails2 = $arrFairDetails[0];
                                }
                                if ($PassengerType == 2) {
                                    $arrFairDetails2 = $arrFairDetails[1];
                                }
                                if ($PassengerType == 3) {
                                    $arrFairDetails2 = $arrFairDetails[2];
                                }
                            }
                        }
                        $intBaseFare = $arrFairDetails2['BaseFare'];
                        $intTax = $arrFairDetails2['Tax'];
                        $intYQTax = $arrFairDetails2['YQTax'];
                        $intAdditionalTxnFeeOfrd = $arrFairDetails2['AdditionalTxnFeeOfrd'];
                        $intAdditionalTxnFeePub = $arrFairDetails2['AdditionalTxnFeePub'];
                        $intAirTransFee = "00.00";
                        $intTransactionFee = "00.00";
                        $arrPassengers[] = [
                            'Title' => $paxTitle,
                            'FirstName' => $value['FirstName'],
                            'LastName' => $value['LastName'],
                            'PaxType' => $value['paxType'],
                            'DateOfBirth' => $value['DOB'],
                            'Gender' => $intGender,
                            'PassportNo' => ($IsInternational == 1) ? $PassportNo : '',
                            'PassportExpiry' => ($IsInternational == 1) ? $PassportExpiry : '',
                            'AddressLine1' => $paxAddress,
                            'AddressLine2' => '',
                            'City' => $paxCityTitle,
                            'CountryCode' => $paxCountryCode,
                            'CountryName' => $paxCountryTitle,
                            'ContactNo' => $paxContactNo,
                            'Email' => !empty($agencyEmailId) ? $agencyEmailId : "gaurav@hellogtx.com",
                            'IsLeadPax' => $intMemberSysId,
                            'FFAirline' => '',
                            'FFNumber' => '',
                            'GSTCompanyAddress' => $GSTCompanyAddress,
                            'GSTCompanyContactNumber' => $GSTCompanyContactNumber,
                            'GSTCompanyName' => $GSTCompanyName,
                            'GSTNumber' => $GSTNumber,
                            'GSTCompanyEmail' => $GSTCompanyEmail,
                            'Fare' =>
                            [
                                'BaseFare' => $intBaseFare,
                                'Tax' => $intTax,
                                'TransactionFee' => $intTransactionFee,
                                'YQTax' => $intYQTax,
                                'AdditionalTxnFeeOfrd' => $intAdditionalTxnFeeOfrd,
                                'AdditionalTxnFeePub' => $intAdditionalTxnFeePub,
                                'AirTransFee' => $intAirTransFee
                            ],
                            'Meal' =>
                            [
                                'Code' => $MealCode,
                                'Description' => $MealDesc
                            ],
                            'Seat' =>
                            [
                                'Code' => $SeatCode,
                                'Description' => $SeatDesc
                            ]
                        ];
                    }
                }
                //           echo "<pre>";print_r($arrPassengers);exit;
                $tokenId = $this->authenticateAPI();
                $request = array(
                    'EndUserIp' => $_SERVER['REMOTE_ADDR'],
                    'TokenId' => $tokenId,
                    'TraceId' => $TraceId,
                    'ResultIndex' => $ResultIndex,
                    'Passengers' => $arrPassengers
                );
            }
        }
        return $request;
    }

    public function cancelFlightBooking($data)
    {
        $intCancellationType = $data['CancellationType'];
        $RequestType = $data['requestType'];
        $TOKEN_ID  = $this->authenticateAPI();
        //echo "<pre>"; print_r($data);die('dd');
        //if($intIsLCC == 1){

        if ($RequestType == 2) {
            $datah = array(
                "BookingId" => $data['BookingId'],
                "RequestType" => $RequestType,
                "CancellationType" => $intCancellationType,
                "Sectors" => $data['sectorsSelectors'],
                "TicketId" => $data['TicketId'],
                "Remarks" => $data['remarks'],
                "EndUserIp" => $_SERVER['REMOTE_ADDR'],
                "TokenId" => $TOKEN_ID,
            );
        } else {
            $datah = array(
                "BookingId" => $data['BookingId'],
                "Source" => $data['source'],
                "EndUserIp" => $_SERVER['REMOTE_ADDR'],
                "TokenId" => $TOKEN_ID,
            );
        }
        echo "<pre>";
        print_r(json_encode($datah));
        die('dd');
        $cURL = FLIGHT_API_BOOKING_CHANGE_REQUEST;
        //echo "<pre>"; print_r($datah); exit;
        $data_stringh = json_encode($datah);

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $cURL);
        curl_setopt($ch, CURLOPT_ENCODING, "gzip");
        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);
        $responseTBO = json_decode($outputH, true);
        //echo $outputH;

        //echo "<pre>"; print_r($responseTBO); exit;
        if (FLIGHT_API_LOGS) {

            //Write Request Logs starts...
            $strFilePath = "flight/FlightCancel/" . time() . "_FlightCancel_request.json";
            Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $data_stringh);
            //Write Request Logs starts...

            //Write Request Logs starts...
            $strFilePath = "flight/FlightCancel/" . time() . "_FlightCancel_response.json";
            Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $outputH);
            //Write Request Logs starts...

        }
        //return $responseTBO;
        //echo "<pre>"; print_r($responseTBO);
        $FlightCancelSession = new Zend_Session_Namespace('FlightCancelSession');
        $FlightCancelSession->params = $responseTBO;
        $intChangeRequestId = isset($responseTBO['Response']['TicketCRInfo'][0]['ChangeRequestId']) ? $responseTBO['Response']['TicketCRInfo'][0]['ChangeRequestId'] : '';
        $ResponseStatus = isset($responseTBO['Response']['ResponseStatus']) ? $responseTBO['Response']['ResponseStatus'] : '';
        $TicketCRInfo = isset($responseTBO['Response']['TicketCRInfo']) ? $responseTBO['Response']['TicketCRInfo'] : array();
        // $objFlight = new Travel_Model_TblFlight();
        // if (!empty($ResponseStatus) && $ResponseStatus == 1) {
        //     if (isset($data['TicketId']) && !empty($data['TicketId'])) {
        //         foreach ($data['TicketId'] as $key => $value) {
        //             $TicketId = $TicketCRInfo[$key]['TicketId'];
        //             $ChangeRequestId = $TicketCRInfo[$key]['ChangeRequestId'];
        //             $ChangeRequestStatus = $TicketCRInfo[$key]['ChangeRequestStatus'];
        //             $datah = array(
        //                 "ChangeRequestId" => $ChangeRequestId,
        //                 "EndUserIp" => $_SERVER['REMOTE_ADDR'],
        //                 "TokenId" => $TOKEN_ID
        //             );
        //             $data_stringh = json_encode($datah);
        //             $ch = curl_init();
        //             curl_setopt($ch, CURLOPT_URL, FLIGHT_API_BOOKING_CHANGE_REQUEST_STATUS);
        //             curl_setopt($ch, CURLOPT_ENCODING, "gzip");
        //             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);
        //             $responseCan = json_decode($outputH, true);

        //             $data = array(
        //                 "ChangeRequestId" => $ChangeRequestId,
        //                 "ChangeRequestRes" => json_encode($responseCan),
        //                 "ChangeRequestStatus" => $ChangeRequestStatus
        //             );
        //             $objFlight->updateTravelPlanPaxByTicketId($data, '' . $TicketId . '');
        //         }
        //     }

        //     if (FLIGHT_API_LOGS) {

        //         //Write Request Logs starts...
        //         $strFilePath = "flight/FlightCancelStatus/" . time() . "_FlightCancelStatus_request.json";
        //         Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $data_stringh);
        //         //Write Request Logs starts...

        //         //Write Request Logs starts...
        //         $strFilePath = "flight/FlightCancelStatus/" . time() . "_FlightCancelStatus_response.json";
        //         Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $outputH);
        //         //Write Request Logs starts...

        //     }

        //     return $responseTBO;
        //     //echo "<pre>"; print_r($responseTBO); exit;
        // }

        return $responseTBO;
    }

    public function GetAmendmentCharges($arrData = array())
    {
        if ($arrData) {

            $data_stringh = json_encode($arrData);
            //echo "<pre>"; print_r($data_stringh); exit;
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, TRIPJACK_FL_API_GETAMENDMENTCHARGES_URL);
            curl_setopt($ch, CURLOPT_ENCODING, "gzip");
            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(
                'Accept: application/json',
                'Content-Type: application/json',
                'Accept-Encoding: gzip',
                'apikey:' . APIKEY,
                'Content-Length: ' . strlen($data_stringh)
            ));

            $outputH = curl_exec($ch);
            $response = json_decode($outputH, true);
            if (FLIGHT_API_LOGS) {

                //Write Request Logs starts...
                $strFilePath = "flight/Amendment/" . date('Y-m-d-H-i-s') . "_AmendmentCharges_request.json";
                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $data_stringh);
                //Write Request Logs starts...
                //Write Request Logs starts...
                $strFilePath = "flight/Amendment/" . date('Y-m-d-H-i-s') . "_AmendmentCharges_response.json";
                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $outputH);
                //Write Request Logs starts...
            }
            Zend_Session::namespaceUnset('AmendmentChargesSession');
            $AmendmentChargesSession = new Zend_Session_Namespace('AmendmentChargesSession');
            $AmendmentChargesSession->params = $response;  // store all serch result data to Session
            return $response;
        }
    }
    public function GetSubmitAmendment($arrData = array())
    {
        if ($arrData) {

            $data_stringh = json_encode($arrData);
            //echo "<pre>"; print_r($data_stringh); exit;
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, TRIPJACK_FL_API_SUBMITAMENDMENT_URL);
            curl_setopt($ch, CURLOPT_ENCODING, "gzip");
            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(
                'Accept: application/json',
                'Content-Type: application/json',
                'Accept-Encoding: gzip',
                'apikey:' . APIKEY,
                'Content-Length: ' . strlen($data_stringh)
            ));

            $outputH = curl_exec($ch);
            $response = json_decode($outputH, true);
            if (FLIGHT_API_LOGS) {

                //Write Request Logs starts...
                $strFilePath = "flight/Amendment/" . date('Y-m-d-H-i-s') . "_SubmitAmendment_request.json";
                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $data_stringh);
                //Write Request Logs starts...
                //Write Request Logs starts...
                $strFilePath = "flight/Amendment/" . date('Y-m-d-H-i-s') . "_SubmitAmendment_response.json";
                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $outputH);
                //Write Request Logs starts...
            }
            Zend_Session::namespaceUnset('SubmitAmendment');
            $SubmitAmendment = new Zend_Session_Namespace('SubmitAmendment');
            $SubmitAmendment->params = $response;  // store all serch result data to Session
            return $response;
        }
    }

    public function GetAmendmentDetails($arrData = array())
    {
        if ($arrData) {

            $data_stringh = json_encode($arrData);
            //echo "<pre>"; print_r($data_stringh); exit;
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, TRIPJACK_FL_API_AMENDMENTDETAILS_URL);
            curl_setopt($ch, CURLOPT_ENCODING, "gzip");
            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(
                'Accept: application/json',
                'Content-Type: application/json',
                'Accept-Encoding: gzip',
                'apikey:' . APIKEY,
                'Content-Length: ' . strlen($data_stringh)
            ));

            $outputH = curl_exec($ch);
            $response = json_decode($outputH, true);
            if (FLIGHT_API_LOGS) {

                //Write Request Logs starts...
                $strFilePath = "flight/Amendment/" . date('Y-m-d-H-i-s') . "_AmendmentDetails_request.json";
                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $data_stringh);
                //Write Request Logs starts...
                //Write Request Logs starts...
                $strFilePath = "flight/Amendment/" . date('Y-m-d-H-i-s') . "_AmendmentDetails_response.json";
                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath, $outputH);
                //Write Request Logs starts...
            }

            return $response;
        }
    }

    function calculateServiceTax($intAmount, $percentAgencySTax)
    {
        $intAmount = (float) $intAmount;
        $intNetSTax = (($intAmount * $percentAgencySTax) / 100);
        $BasePriceWithSTax = $intNetSTax + $intAmount;
        $arrSerciceTax = array(
            "BasePrice" => $intAmount,
            "serviceTaxAmount" => $intNetSTax,
            "BasePriceWithSTax" => $BasePriceWithSTax,
            "ServiceTaxPercentage" => $percentAgencySTax,
        );
        return $arrSerciceTax;
    }
    function calculateMarkupTripJack($data)
    {
        $arrGTXMarkups = isset($data['getMarkup']['arrGTXMarkups']) ? $data['getMarkup']['arrGTXMarkups'] : [];
        $arrAgencyMarkups = isset($data['getMarkup']['arrAgencyMarkups']) ? $data['getMarkup']['arrAgencyMarkups'] : [];
        $arrApiServiceTax = isset($data['getMarkup']['arrApiServiceTax'][0]) ? $data['getMarkup']['arrApiServiceTax'][0]['Percentage'] : [];
        $intPublishedFare = isset($data['PublishedFare']) ? $data['PublishedFare'] : 0;
        $intOfferedFare = isset($data['OfferedFare']) ? $data['OfferedFare'] : 0;
        $intCommissionEarned = isset($data['intCommissionEarned']) ? $data['intCommissionEarned'] : 0;
        $intPLBEarned = isset($data['intPLBEarned']) ? $data['intPLBEarned'] : 0;
        $intIncentiveEarned = isset($data['intIncentiveEarned']) ? $data['intIncentiveEarned'] : 0;
        $intMemberCount = isset($data['intMemberCount']) ? $data['intMemberCount'] : 1;
        $intFlightRoute = isset($data['intFlightRoute']) ? $data['intFlightRoute'] : 1;
        $interNationalSearch = isset($data['interNationalSearch']) ? $data['interNationalSearch'] : 0;
        $commission = ($intPublishedFare - $intOfferedFare);
        // For GTX MarkUps...
        $intOfferedFareWithGTXCommision = 0;
        $totalGTXMarkUp = 0;
        if (count($arrGTXMarkups) > 0) {
            foreach ($arrGTXMarkups as $GTXMarkups) {
                $intGTXCurrencySysId = $GTXMarkups['Currency'];
                $intGTXMarkUpType = $GTXMarkups['MarkUpType'];
                $intGTXMarkUp = 0; //$GTXMarkups['MarkUp'];
                $totalGTXMarkUp += $intGTXMarkUp;
                if ($intGTXMarkUpType == 1) { // For Flat
                    $intGTXMarkUp = $intGTXMarkUp;
                    $intOfferedFareWithGTXCommision += $intOfferedFare + $intGTXMarkUp;
                } else { // For Percentage
                    $intGTXMarkUp = ($intOfferedFare * $intGTXMarkUp) / 100;
                    $intOfferedFareWithGTXCommision += $intOfferedFare + $intGTXMarkUp;
                }
            }
        } else {
            $intGTXMarkUp = 0;
            $intOfferedFareWithGTXCommision = $intOfferedFare + $intGTXMarkUp;
        }
        // For Agency MarkUps...
        $intCommission = 0;
        $totalAgencyMarkUp = 0;
        $intFareWithAgencyFixMarkUp = 0;
        $intAgencyCommisionEarnedFromAcutalCommision = 0;
        $intAgencyPLBEarnedFromAcutalPLB = 0;
        $intAgencyIncentiveEarnedFromAcutalIncentive = 0;
        if (count($arrAgencyMarkups) > 0) {
            foreach ($arrAgencyMarkups as $AgencyMarkups) {
                $intAgencyCurrencySysId = $AgencyMarkups['Currency'];
                $intAgencyMarkUp = $AgencyMarkups['StdMarkUpPer']; // Agency Fix Mark UP...
                $totalAgencyMarkUp += $intAgencyMarkUp;
                $intCommssionType = $AgencyMarkups['CommssionType']; // 2 For percentage
                $intCommssionVal = $AgencyMarkups['CommssionVal']; // Percntage Value For Agency Commision From Actual Commision Retuned From API...
                $intFareWithAgencyFixMarkUp += $intOfferedFareWithGTXCommision + $intAgencyMarkUp;
                if ($intCommssionType == 2) { // For Agency Commision In Percentage Only...
                    $intAgencyCommisionEarnedFromAcutalCommision    += (($intCommissionEarned * $intCommssionVal) / 100);
                    $intAgencyPLBEarnedFromAcutalPLB                += (($intPLBEarned * $intCommssionVal) / 100);
                    $intAgencyIncentiveEarnedFromAcutalIncentive    += (($intIncentiveEarned * $intCommssionVal) / 100);

                    $intCommission    += (($commission * $intCommssionVal) / 100);
                }
            }
        } else {
            $intFareWithAgencyFixMarkUp = $intOfferedFareWithGTXCommision;
            $intAgencyCommisionEarnedFromAcutalCommision = 0;
            $intAgencyPLBEarnedFromAcutalPLB = 0;
            $intAgencyIncentiveEarnedFromAcutalIncentive = 0;
        }
        //echo $intAgencyCommisionEarnedFromAcutalCommision.'=='.$intAgencyPLBEarnedFromAcutalPLB.'=='.$intAgencyIncentiveEarnedFromAcutalIncentive;
        $arrGSTOnGTXMarkUp = $this->calculateServiceTax($totalGTXMarkUp, $arrApiServiceTax);
        $intGSTOnGTXMarkUp = $arrGSTOnGTXMarkUp['serviceTaxAmount'];

        $arrGSTOnAgencyFixMarkUp = $this->calculateServiceTax($totalAgencyMarkUp, $arrApiServiceTax);
        $intGSTOnAgencyFixMarkUp = $arrGSTOnAgencyFixMarkUp['serviceTaxAmount'];

        $arrGSTOnAgencyCommisionEarned = $this->calculateServiceTax($intAgencyCommisionEarnedFromAcutalCommision, $arrApiServiceTax);
        $intGSTOnAgencyCommisionEarned = $arrGSTOnAgencyCommisionEarned['serviceTaxAmount'];

        $arrGSTOnAgencyPLBEarned = $this->calculateServiceTax($intAgencyPLBEarnedFromAcutalPLB, $arrApiServiceTax);
        $intGSTOnAgencyPLBEarned = $arrGSTOnAgencyPLBEarned['serviceTaxAmount'];

        $arrGSTOnAgencyIncentiveEarned = $this->calculateServiceTax($intAgencyIncentiveEarnedFromAcutalIncentive, $arrApiServiceTax);
        $intGSTOnAgencyIncentiveEarned = $arrGSTOnAgencyIncentiveEarned['serviceTaxAmount'];

        $intTotalEarningsForAgency = $intAgencyCommisionEarnedFromAcutalCommision + $intAgencyPLBEarnedFromAcutalPLB + $intAgencyIncentiveEarnedFromAcutalIncentive;

        $arrPriceAndMarkUps = array(
            "intOfferedFare" => $intOfferedFare,
            "intFareWithGTXMarkUp" => $intOfferedFareWithGTXCommision,
            "intFareWithAgencyFixMarkUp" => $intFareWithAgencyFixMarkUp,
            "intPublishFare" => ($intFareWithAgencyFixMarkUp + $intTotalEarningsForAgency + $intGSTOnGTXMarkUp + $intGSTOnAgencyFixMarkUp),
            "intCommissionEarned" => $intCommissionEarned,
            "intCommisionEarnedForAgency" => $intAgencyCommisionEarnedFromAcutalCommision,
            "intPLBEarned" => $intPLBEarned,
            "intPLBEarnedForAgency" => $intAgencyPLBEarnedFromAcutalPLB,
            "intIncentiveEarned" => $intIncentiveEarned,
            "intIncentiveEarnedForAgency" => $intAgencyIncentiveEarnedFromAcutalIncentive,
            "intTotalEarningsForAgency" => $intTotalEarningsForAgency,
            "intGTXMarkUp" => $intGTXMarkUp,
            "intAgencyFixMarkUp" => $intAgencyMarkUp,
            "intSTaxOnGTXMarkUp" => $intGSTOnGTXMarkUp,
            "intSTaxOnAgencyFixMarkUp" => $intGSTOnAgencyFixMarkUp,

            "intGSTOnAgencyCommisionEarned" => $intGSTOnAgencyCommisionEarned,
            "intGSTOnAgencyPLBEarned" => $intGSTOnAgencyPLBEarned,
            "intGSTOnAgencyIncentiveEarned" => $intGSTOnAgencyIncentiveEarned

        );
        return $arrPriceAndMarkUps;
        // echo '<pre>';print_r($commission + $intCommission);
        // echo '<pre>';print_r($intCommission);
        // echo '<pre>';print_r($intFareWithAgencyFixMarkUp);
        // echo '<pre>';print_r($intTotalEarningsForAgency);
        // echo '<pre>';print_r($data);

        // die;
    }
    public function getArrivalDepartureIndianFormat($string)
    {
        if (empty($string))
            return '';

        $arr = explode(" ", $string);

        $date = new DateTime($arr[0]);

        return $date->format('d M Y') . ' ' . substr(@$arr[1], 0, 5);
    }

    public function getTimeFromApiString($string)
    {
        if (empty($string))
            return '';

        $arr = explode("T", $string);

        $date = new DateTime($arr[0]);

        return substr(@$arr[1], 0, 5);
    }

    public function CalculateHoursMinutes($DepTime, $ArrTime)
    {
        if (empty($DepTime))
            return '';
        if (empty($ArrTime))
            return '';

        $date1 = new DateTime($DepTime . ':00');
        $date2 = new DateTime($ArrTime . ':00');

        $diff = $date2->diff($date1);

        $hours = $diff->h;
        $minutes = $diff->i;
        $hours = $hours + ($diff->days * 24);
        $travelTime = $hours . 'h ' . $minutes . 'm';
        return $travelTime;
        // $Darr = explode("T", $DepTime);
        // $Ddate = new DateTime($Darr[0]);

        // $Aarr = explode("T", $ArrTime);
        // $Adate = new DateTime($Aarr[0]);

        // $dep = $Ddate->format('Y-m-d') . ' ' . substr(@$Darr[1], 0, 5);
        // $arr = $Adate->format('Y-m-d') . ' ' . substr(@$Aarr[1], 0, 5);

        // $t1 = strtotime($dep);
        // $t2 = strtotime($arr);
        // $delta_T = ($t2 - $t1);
        // $day = round(($delta_T % 604800) / 86400);
        // $hours = round((($delta_T % 604800) % 86400) / 3600);
        // $minutes = round(((($delta_T % 604800) % 86400) % 3600) / 60);
        // $sec = round((((($delta_T % 604800) % 86400) % 3600) % 60));
        // $hours = ($hours > 9) ? $hours : '0' . $hours;
        // $minutes = ($minutes > 9) ? $minutes : '0' . $minutes;
        // $travelTime = $hours . 'h ' . $minutes . 'm';

        // return $travelTime;
    }
    public function MinutesToHours($minutes)
    {
        if ($minutes) {
            $hours = floor($minutes / 60);
            $min = $minutes - ($hours * 60);
            $LAYOVERTime = $hours . "h " . $min . 'm';
            return $LAYOVERTime;
        }
    }
    public function getDynamicPriceSlots($minPrice = NULL, $maxPrice = NULL)
    {

        if (!empty($minPrice) && !empty($maxPrice)) {
            $intMinPrice = round($minPrice);
            $intMaxPrice = round($maxPrice);
        } else {
            $intMinPrice = round(min($arrAirFare));
            $intMaxPrice = round(max($arrAirFare));
        }


        $intStartRage = floor($intMinPrice / 100) * 100;
        $intEndRage = floor($intMaxPrice / 100) * 100;

        $rangeDifference = $intEndRage - $intStartRage;

        $intTotalSlots = 4;
        $intDifference = $rangeDifference / $intTotalSlots;
        $intDifference = floor($intDifference / 100) * 100;


        $base = $rangeDifference / $intTotalSlots;

        $arr = array();
        $minStartRange = $intStartRage;
        $arr[] = "0-" . $intStartRage;
        for ($i = 1; $i <= $intTotalSlots; $i++) {

            $baseAmount = round($i * $base);
            $baseAmount = floor($baseAmount / 100) * 100;
            //if($i > 1){
            $intNewUpRange = $baseAmount + $intDifference;
            $arr[] = $minStartRange . "-" . ($intNewUpRange - 1);

            $minStartRange = $intNewUpRange;
            //}
        }
        $arr[] = $minStartRange . "-" . ($intNewUpRange);
        return $arr;
    }

    function encrypt($sData, $secretKey)
    {
        $sResult = '';
        for ($i = 0; $i < strlen($sData); $i++) {
            $sChar = substr($sData, $i, 1);
            $sKeyChar = substr($secretKey, ($i % strlen($secretKey)) - 1, 1);
            $sChar = chr(ord($sChar) + ord($sKeyChar));
            $sResult .= $sChar;
        }
        return $this->encode_base64($sResult);
    }

    function decrypt($sData, $secretKey)
    {
        $sResult = '';
        $sData = $this->decode_base64($sData);
        for ($i = 0; $i < strlen($sData); $i++) {
            $sChar = substr($sData, $i, 1);
            $sKeyChar = substr($secretKey, ($i % strlen($secretKey)) - 1, 1);
            $sChar = chr(ord($sChar) - ord($sKeyChar));
            $sResult .= $sChar;
        }
        return $sResult;
    }

    function encode_base64($sData)
    {
        $sBase64 = base64_encode($sData);
        return str_replace('=', '', strtr($sBase64, '+/', '-_'));
    }

    function decode_base64($sData)
    {
        $sBase64 = strtr($sData, '-_', '+/');
        return base64_decode($sBase64 . '==');
    }
    function GetAgencyCurrency($gtxagencysysid)
    {
        try {
            $apiDataIV = array(
                "AgencySysId" => $gtxagencysysid,
                "SecurityKey" => SECURITYKEY
            );
            $curl_IV = curl_init(API_GET_IV_KEY);
            curl_setopt($curl_IV, CURLOPT_POST, true);
            //curl_setopt($curl, CURLOPT_HEADER, true);
            curl_setopt($curl_IV, CURLOPT_POSTFIELDS, http_build_query($apiDataIV));
            curl_setopt($curl_IV, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl_IV, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl_IV, CURLOPT_TIMEOUT, 300);
            $responseIV = curl_exec($curl_IV);
            curl_close($curl_IV);
            //
            $IVData   = Zend_Json::decode($responseIV, true);
            $apiData = array(
                "AgencySysId" => $gtxagencysysid,
            );
            $curl_p = curl_init(API_AGENCY_CURRENCY_RATE);
            curl_setopt($curl_p, CURLOPT_POST, true);
            //curl_setopt($curl, CURLOPT_HEADER, true);
            curl_setopt($curl_p, CURLOPT_POSTFIELDS, http_build_query($apiData));
            curl_setopt($curl_p, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl_p, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl_p, CURLOPT_TIMEOUT, 300);
            $response_pro = curl_exec($curl_p);
            curl_close($curl_p);
            $data   = Zend_Json::decode($response_pro, true);
            //$agencyData = new Travel_Model_Encrytion($data['Message'], $apiDataIV['SecurityKey'], $IVData['Message']);

            echo '<pre>';
            print_r($data);
            //echo '<pre>';print_r($data);
            //echo '<pre>';print_r(Zend_Json::decode($agencyData->decrypt(),true));
            die('wait');
        } catch (Exception $error) {
            $this->view->error_msg = $error->getMessage();
            die;
        }
    }

    function is_valid_gstin($gstin)
    {
        $regex = "/^([0][1-9]|[1-2][0-9]|[3][0-5])([a-zA-Z]{5}[0-9]{4}[a-zA-Z]{1}[1-9a-zA-Z]{1}[zZ]{1}[0-9a-zA-Z]{1})+$/";
        return preg_match($regex, $gstin);
    }

    function getAgencyData($gtxagencysysid)
    {
        if ($gtxagencysysid) {
            $apiDataIV = array(
                "AgencySysId" => $gtxagencysysid,
                "SecurityKey" => SECURITYKEY //'AE54AF70-3DC8-431B-BED1-FB8A92CC2FAE'
            );

            $curl_IV = curl_init(API_GET_IV_KEY);
            curl_setopt($curl_IV, CURLOPT_POST, true);
            //curl_setopt($curl, CURLOPT_HEADER, true);
            curl_setopt($curl_IV, CURLOPT_POSTFIELDS, http_build_query($apiDataIV));
            curl_setopt($curl_IV, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl_IV, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl_IV, CURLOPT_TIMEOUT, 300);
            $responseIV = curl_exec($curl_IV);
            curl_close($curl_IV);
            //echo '<pre>';print_r($responseIV);
            //echo '<pre>';print_r(API_GET_IV_KEY);die;
            $apiData = array(
                "AgencySysId" => $gtxagencysysid,
            );
            $curl_p = curl_init(API_GET_AGENCY_DATA);
            curl_setopt($curl_p, CURLOPT_POST, true);
            //curl_setopt($curl, CURLOPT_HEADER, true);
            curl_setopt($curl_p, CURLOPT_POSTFIELDS, http_build_query($apiData));
            curl_setopt($curl_p, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl_p, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl_p, CURLOPT_TIMEOUT, 300);
            $response_pro = curl_exec($curl_p);
            curl_close($curl_p);
            $IVData   = Zend_Json::decode($responseIV, true);
            $data   = Zend_Json::decode($response_pro, true);
            $agencyData = new Travel_Model_Encrytion($data['Message'], $apiDataIV['SecurityKey'], $IVData['Message']);
            return Zend_Json::decode($agencyData->decrypt(), true);
            //echo '<pre>';print_r(Zend_Json::decode($agencyData->decrypt(),true));
            //die('wait');
        } else {
            return 'Bad request';
        }
    }

    function createGUID()
    {
        // Create a token
        $token      = $_SERVER['HTTP_HOST'];
        $token     .= $_SERVER['REQUEST_URI'];
        $token     .= uniqid(rand(), true);
        // GUID is 128-bit hex
        $hash        = strtoupper(md5($token));
        // Create formatted GUID
        $guid        = '';
        // GUID format is XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX for readability    
        $guid .= substr($hash,  0,  8) .
            '-' .
            substr($hash,  8,  4) .
            '-' .
            substr($hash, 12,  4) .
            '-' .
            substr($hash, 16,  4) .
            '-' .
            substr($hash, 20, 12);

        return $guid;
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit