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/b2bsite.hellogtx.com/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/b2bsite.hellogtx.com/Readymadepackagexml.php
<?php

/* Zend Framework
 * @category   Zend
 * @package    Zend_Controller_Action
 * @copyright  Copyright (c) 2008-2014 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    1.0
 * @author     Ranvir singh <ranvir@catpl.co.in>
 * Create Date 06-09-2016
 * Update Date 06-09-2016
 * ************************************************************* */

class Gtxwebservices_Model_Readymadepackagexml extends Zend_Db_Table_Abstract {

    function __construct() {
        $this->db = Zend_Db_Table::getDefaultAdapter();
    }

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

    public function getTC($SecurityKey) {
        $select = $this->db->select()->from(array("T1" => "TB_Agency"), array(""))
                ->joinLeft(array('T2' => "TB_Agency_Terms_Conditions"), "T1.AgencySysId = T2.AgencySysId")
                ->where("T1.SecurityKey =?", $SecurityKey);
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function createxml($packageId, $PackageCostCalType, $sCode) {
        $catTypeMaster = Catabatic_Helper::getPackCatType();
        $statusArray = array(1 => TRUE, 0 => FALSE);
        $OstatusArray = array(1 => FALSE, 0 => TRUE);
        $currentDate = date("Y-m-d");
        $finalResultSet = array();
        $querySet = "GET_READYMADEPACKAGE_ITENARYWISE_FULLINFO $packageId";
        $statement = $this->db->query($querySet);
        // Result set 1
        $resultSet1 = $statement->fetchAll();
        $finalResultSet['Result1'] = array();
        foreach ($resultSet1 as $row) {
            $finalResultSet['Result1'][] = $row;
        }
        // Result set 2
        $statement->nextRowSet(); // Advance to the second result set
        $resultSet2 = $statement->fetchAll();
        $finalResultSet['Result2'] = array();
        foreach ($resultSet2 as $row) {
            $finalResultSet['Result2'][] = $row;
        }
        // Result set 3
        $statement->nextRowSet(); // Advance to the third result set
        $resultSet3 = $statement->fetchAll();
        $finalResultSet['Result3'] = array();
        foreach ($resultSet3 as $row) {
            $finalResultSet['Result3'][] = $row;
        }
        // Result set 4
        $statement->nextRowSet(); // Advance to the third result set
        $resultSet4 = $statement->fetchAll();
        $finalResultSet['Result4'] = array();
        foreach ($resultSet4 as $row) {
            $finalResultSet['Result4'][] = $row;
        }
        // Result set 5
        $statement->nextRowSet(); // Advance to the third result set
        $resultSet5 = $statement->fetchAll();
        $finalResultSet['Result5'] = array();
        foreach ($resultSet5 as $row) {
            $finalResultSet['Result5'][] = $row;
        }
        // Result set 6
        $statement->nextRowSet(); // Advance to the third result set
        $resultSet6 = $statement->fetchAll();
        $finalResultSet['Result6'] = array();
        foreach ($resultSet6 as $row) {
            $finalResultSet['Result6'][] = $row;
        }
        // Result set 7
        $statement->nextRowSet(); // Advance to the third result set
        $resultSet7 = $statement->fetchAll();
        $finalResultSet['Result7'] = array();
        foreach ($resultSet7 as $row) {
            $finalResultSet['Result7'][] = $row;
        }
        // Result set 8
        $statement->nextRowSet(); // Advance to the third result set
        $resultSet8 = $statement->fetchAll();
        $finalResultSet['Result8'] = array();
        foreach ($resultSet8 as $row) {
            $finalResultSet['Result8'][] = $row;
        }
        // Result set 9
        $statement->nextRowSet(); // Advance to the third result set
        $resultSet9 = $statement->fetchAll();
        $finalResultSet['Result9'] = array();
        foreach ($resultSet9 as $row) {
            $finalResultSet['Result9'][] = $row;
        }
        // Result set 10
        $statement->nextRowSet(); // Advance to the third result set
        $resultSet10 = $statement->fetchAll();
        $finalResultSet['Result10'] = array();
        foreach ($resultSet10 as $row) {
            $finalResultSet['Result10'][] = $row;
        }
        // Result set 11
        $statement->nextRowSet(); // Advance to the third result set
        $resultSet11 = $statement->fetchAll();
        $finalResultSet['Result11'] = array();
        foreach ($resultSet11 as $row) {
            $finalResultSet['Result11'][] = $row;
        }
        // Result set 12
        $statement->nextRowSet(); // Advance to the third result set
        $resultSet12 = $statement->fetchAll();
        $finalResultSet['Result12'] = array();
        foreach ($resultSet12 as $row) {
            $finalResultSet['Result12'][] = $row;
        }
        $statement->nextRowSet(); // Advance to the third result set
        $resultSet13 = $statement->fetchAll();
        $finalResultSet['Result13'] = array();
        foreach ($resultSet13 as $row) {
            $finalResultSet['Result13'][] = $row;
        }
        $statement->nextRowSet(); // Advance to the third result set
        $resultSet14 = $statement->fetchAll();
        $finalResultSet['Result14'] = array();
        foreach ($resultSet14 as $row) {
            $finalResultSet['Result14'][] = $row;
        }

        $statement->nextRowSet(); // Advance to the third result set
        $resultSet15 = $statement->fetchAll();
        $finalResultSet['Result15'] = array();
        foreach ($resultSet15 as $row) {
            $finalResultSet['Result15'][] = $row;
        }
        $statement->nextRowSet(); // Advance to the third result set
        $resultSet16 = $statement->fetchAll();
        $finalResultSet['Result16'] = array();
        foreach ($resultSet16 as $row) {
            $finalResultSet['Result16'][] = $row;
        }


        $statement->nextRowSet(); // Advance to the third result set
        $resultSet17 = $statement->fetchAll();
        $finalResultSet['Result17'] = array();
        foreach ($resultSet17 as $row) {
            $finalResultSet['Result17'][] = $row;
        }

        $statement->nextRowSet(); // Advance to the third result set
        $resultSet18 = $statement->fetchAll();
        $finalResultSet['Result18'] = array();
        foreach ($resultSet18 as $row) {
            $finalResultSet['Result18'][] = $row;
        }

        $statement->nextRowSet(); // Advance to the third result set
        $resultSet19 = $statement->fetchAll();
        $finalResultSet['Result19'] = array();
        foreach ($resultSet19 as $row) {
            $finalResultSet['Result19'][] = $row;
        }

        $statement->nextRowSet(); // Advance to the third result set
        $resultSet20 = $statement->fetchAll();
        $finalResultSet['Result20'] = array();
        foreach ($resultSet20 as $row) {
            $finalResultSet['Result20'][] = $row;
        }
        $statement->nextRowSet(); // Advance to the third result set
        $resultSet21 = $statement->fetchAll();
        $finalResultSet['Result21'] = array();
        foreach ($resultSet21 as $row) {
            $finalResultSet['Result21'][] = $row;
        }
        /*  start Itineraries code */
        $subItem = array(0 => "CITY", 1 => "HOTEL", 2 => "ACTIVITY", 3 => "SIGHTSEEING");
        // $ItinerarieItem = array();
        $catagoryArray = array();
        $dataCatId = array();
        foreach ($finalResultSet['Result1'] as $ItinerariesF) {
            $dataCatId[$ItinerariesF['PACKCATEGORYID']][] = $ItinerariesF['TPINTSYSID'];
            $catagoryArray[$ItinerariesF['PACKCATEGORYID']] = $ItinerariesF['PACKCATEGORYTITLE'];
        }
        $ItinerarieItem = array();
        $i = 0;
        $totalDay = 0;
        $checkQuadPrice = false;
        $AgencyId = (int) $finalResultSet['Result1'][0]['AGENCYSYSID'];
        //echo "<pre>";print_r($finalResultSet['Result7']);exit;
//        if($AgencyId == 43249) {
//            $finalResultSet['Result7'] = $finalResultSet['Result19'];
//        } 
        //echo "<pre>";print_r($finalResultSet['Result7']);exit;
        $IsTG = (int) $finalResultSet['Result1'][0]['IsTG'];
        $IsGTXNetworkWeb = (int) $finalResultSet['Result1'][0]['IsGTXNetworkWeb'];
        if ($IsTG == 1 && $sCode == "ewr53bg") {
            $TGAgencySysId = "1903";
        } else if ($IsGTXNetworkWeb == 1 && $sCode != '') {
            $termsandCondition = $this->getTC($sCode);
            if (!empty($termsandCondition)) {
                $TGAgencySysId = $termsandCondition[0]['AgencySysId'];
                $finalResultSet['Result8'][0]['RefundPolicy'] = $termsandCondition[0]['REFUNDPOLICY'];
                $finalResultSet['Result8'][0]['BOOKINGTERMS'] = $termsandCondition[0]['BookingTerms'];
                $finalResultSet['Result8'][0]['CANCELLATIONPOLICY'] = $termsandCondition[0]['CancellationPolicy'];
                $finalResultSet['Result8'][0]['TERMSANDCONDITIONS'] = $termsandCondition[0]['TermsAndConditions'];
                $finalResultSet['Result8'][0]['TRAVELBASICS'] = $termsandCondition[0]['TravelBasics'];
                $finalResultSet['Result8'][0]['WHYUSEUS'] = $termsandCondition[0]['WhyUseUs'];

                $finalResultSet['Result8'][0]['IsREFUNDPOLICY'] = $termsandCondition[0]['IsREFUNDPOLICY'];
                $finalResultSet['Result8'][0]['IsBookingTerms'] = $termsandCondition[0]['IsBookingTerms'];
                $finalResultSet['Result8'][0]['IsCancellationPolicy'] = $termsandCondition[0]['IsCancellationPolicy'];
                $finalResultSet['Result8'][0]['IsTermsAndConditions'] = $termsandCondition[0]['IsTermsAndConditions'];
                $finalResultSet['Result8'][0]['IsTravelBasics'] = $termsandCondition[0]['IsTravelBasics'];
                $finalResultSet['Result8'][0]['IsWhyUseUs'] = $termsandCondition[0]['IsWhyUseUs'];
            }
        } else {
            $TGAgencySysId = $AgencyId;
        }

        $catagoryArrayResult7 = array();
        if (!empty($finalResultSet['Result7'])) {
            foreach ($finalResultSet['Result7'] as $ItinerariesF) {
                if ($AgencyId == 48 || $AgencyId == 4995) {
                    if ($ItinerariesF['PAX'] == 2) {
                        $catagoryArrayResult7[$ItinerariesF['MARKETPLACEID']][$ItinerariesF['TOURTYPE']][$ItinerariesF['PACKCATEGORYID']][1][] = $ItinerariesF;
                    }
                } else {
                    $catagoryArrayResult7[$ItinerariesF['MARKETPLACEID']][$ItinerariesF['TOURTYPE']][$ItinerariesF['PACKCATEGORYID']][1][] = $ItinerariesF;
                }
            }
        }
        foreach ($finalResultSet['Result1'] as $Itineraries) {
            if ($Itineraries['MASTERREFID'] == 0) {
                $totalDay = $Itineraries['INTSEQUENCE'];
                $ItinerarieItem[$i]['ItineraryId'] = $Itineraries['TPINTSYSID'];
                $ItinerarieItem[$i]['Title'] = htmlentities($Itineraries['INTTITLE'], ENT_QUOTES);
                $ItinerarieItem[$i]['MealPlanInclude'] = $Itineraries['MealPlanInclude'];
                $ItinerarieItem[$i]['Day'] = $Itineraries['INTSEQUENCE'];
                $ItinerarieItem[$i]['Program'] = htmlentities($Itineraries['INTDETAILS'], ENT_QUOTES);
                $arrayINCLMASK = str_split($Itineraries['INCLMASK']);
                $arrayPACKTYPEMASK = str_split($Itineraries['PACKTYPEMASK']);
                $subItinerariesItem = array();
                $subItems = array();
                foreach ($subItem as $key => $val) {
                    $subItemId = 0;
                    if ($val == "CITY") {
                        foreach ($finalResultSet['Result2'] as $ItinerariesCity) {
                            if ($ItinerariesCity["TPINTSYSID"] == $Itineraries['TPINTSYSID']) {
                                $subItemId = (int) $ItinerariesCity["PLACESYSID"];
                            }
                        }
                    } else if ($val == "HOTEL") {
                        $hotelArray = array();
                        $r = 0;
                        foreach ($catagoryArray as $catKey => $catVal) {
                            $h = 0;
                            foreach ($finalResultSet['Result3'] as $ItinerariesHOTEL) {
                                if ($ItinerariesHOTEL["TPINTSYSID"] == $dataCatId[$catKey][$i]) {
                                    $hotelArray[$r]['Item'][$h]['IsIncluded'] = $statusArray[$ItinerariesHOTEL["ISSELECTEDONPKG"]];
                                    $hotelArray[$r]['Item'][$h]['Id'] = (int) $ItinerariesHOTEL["ACCOMSYSID"];
                                    $hotelArray[$r]['Item'][$h]['MasterIntSysId'] = (int) $ItinerariesHOTEL["MASTERINTSYSID"];
                                    $hotelArray[$r]['Item'][$h]['MEALTYPENAME'] = trim($ItinerariesHOTEL["MEALTYPENAME"]);
                                    $hotelArray[$r]['Item'][$h]['ROOMTYPENAME'] = trim($ItinerariesHOTEL["ROOMTYPENAME"]);
                                    $h++;
                                }
                            }

                            $hotelArray[$r]['Type'] = $catVal;
                            $hotelArray[$r]['Id'] = $catKey;
                            $r++;
                        }
                        $subItems = $hotelArray;
                    } else if ($val == "ACTIVITY") {
                        $activityArray = array();
                        $a = 0;
                        $activityArray[0]['Item'] = array();
                        foreach ($finalResultSet['Result5'] as $ItinerariesACTIVITY) {
                            if ($ItinerariesACTIVITY["TPIntSysId"] == $Itineraries['TPINTSYSID']) {
                                $activityArray[0]['Item'][$a]['IsIncluded'] = $OstatusArray[$ItinerariesACTIVITY["ISOPTIONALACTIVITY"]];
                                $activityArray[0]['Item'][$a]['Id'] = (int) $ItinerariesACTIVITY["ACTIVITYSYSID"];
                                $activityArray[0]['Item'][$a]['MasterIntSysId'] = 0;
                                $a++;
                            }
                        }
                        $activityArray[0]['Type'] = NULL;
                        $activityArray[0]['Id'] = 0;
                        $subItems = $activityArray;
                    } else if ($val == "SIGHTSEEING") {
                        $sightseeingArray = array();
                        $s = 0;
                        $sightseeingArray[0]['Item'] = array();
                        foreach ($finalResultSet['Result6'] as $ItinerariesSIGHTSEEING) {
                            if ($ItinerariesSIGHTSEEING["TPIntSysId"] == $Itineraries['TPINTSYSID']) {
                                $sightseeingArray[0]['Item'][$s]['IsIncluded'] = $OstatusArray[$ItinerariesSIGHTSEEING["ISOPTIONALSIGHTSEEING"]];
                                $sightseeingArray[0]['Item'][$s]['Id'] = (int) $ItinerariesSIGHTSEEING["SSSYSID"];
                                $sightseeingArray[0]['Item'][$s]['MasterIntSysId'] = 0;
                                $s++;
                            }
                        }
                        $sightseeingArray[0]['Type'] = NULL;
                        $sightseeingArray[0]['Id'] = 0;
                        $subItems = $sightseeingArray;
                    }
                    $subItinerariesItem[$key]["Type"] = $val;
                    $subItinerariesItem[$key]["Id"] = $subItemId; //static
                    $subItinerariesItem[$key]["Items"] = $subItems;
                }
                $ItinerarieItem[$i]['ItineraryItem'] = $subItinerariesItem;
                $i++;
            }
        }
        $Itineraries = array("Itinerary" => $ItinerarieItem);
        //echo "<pre>";print_r($Itineraries);
        $Cities = array();
        $Cities["desc"] = NULL;
        $c = 0;
        $checkCity = array();
        $getCityName = array();
        $cityBaseInt = $getCountryName = array();
        foreach ($finalResultSet['Result2'] as $ItinerariesCity) {
            $cityBaseInt[$ItinerariesCity['SEQUENCE']][$ItinerariesCity['PLACESYSID']][] = $ItinerariesCity['TPINTSYSID'];
        }
        foreach ($finalResultSet['Result2'] as $ItinerariesCity) {
            if (!in_array($ItinerariesCity['PLACESYSID'], $checkCity)) {
                $checkCity[] = $ItinerariesCity['PLACESYSID'];
                $Cities["City"][$c]["CityId"] = (int) $ItinerariesCity['PLACESYSID'];
                $Cities["City"][$c]["Title"] = $ItinerariesCity['CITYNAME'];
                $getCityName[$ItinerariesCity['PLACESYSID']] = $ItinerariesCity['CITYNAME'];
                $getCountryName[$ItinerariesCity['COUNTRYID']] = $ItinerariesCity['COUNTRYNAME'];
                $Cities["City"][$c]["Hotels"] = array();
                $cH = 0;
                $checkHotelId = array();
                //echo "<pre>";print_r($finalResultSet['Result3']);exit;
                foreach ($finalResultSet['Result3'] as $ItinerariesCityHOTEL) {
                    if ($ItinerariesCity['PLACESYSID'] == $ItinerariesCityHOTEL['CITYID']) {
                        if (!in_array($ItinerariesCityHOTEL['ACCOMSYSID'], $checkHotelId)) {
                            $checkHotelId[] = (int) $ItinerariesCityHOTEL['ACCOMSYSID'];
                            $Cities["City"][$c]["Hotels"]["Hotel"][$cH]["RefHotelId"] = (int) $ItinerariesCityHOTEL['ACCOMSYSID'];
                            $Cities["City"][$c]["Hotels"]["Hotel"][$cH]["Name"] = $ItinerariesCityHOTEL['HOTELNAME'];
                            $Cities["City"][$c]["Hotels"]["Hotel"][$cH]["Star"] = $ItinerariesCityHOTEL['STARRATING'];
                            $Cities["City"][$c]["Hotels"]["Hotel"][$cH]["Rating"] = $ItinerariesCityHOTEL['REVIEWRATING'];
                            $Cities["City"][$c]["Hotels"]["Hotel"][$cH]["IsIncluded"] = $statusArray[$ItinerariesCityHOTEL['ISSELECTEDONPKG']];
                            $Cities["City"][$c]["Hotels"]["Hotel"][$cH]["Location"] = array("Lat" => trim($ItinerariesCityHOTEL['GEOLAT']), "Long" => trim($ItinerariesCityHOTEL['GEOLONG']), "Address" => htmlentities($ItinerariesCityHOTEL['ADDRESS'], ENT_QUOTES));
                            $Cities["City"][$c]["Hotels"]["Hotel"][$cH]["Images"] = array();
                            $aI = 0;
                            if (!empty($finalResultSet['Result4'])) {
                                foreach ($finalResultSet['Result4'] as $imagesData) {
                                    if ($ItinerariesCityHOTEL['ACCOMSYSID'] == $imagesData['ACCOMSYSID']) {
                                        $Cities["City"][$c]["Hotels"]["Hotel"][$cH]["Images"]["Image"][$aI]['ImagId'] = (int) $imagesData['IMAGEID'];
                                        $Cities["City"][$c]["Hotels"]["Hotel"][$cH]["Images"]["Image"][$aI]['Type'] = $imagesData['IMAGETYPE'];
                                        $Cities["City"][$c]["Hotels"]["Hotel"][$cH]["Images"]["Image"][$aI]['Order'] = $imagesData['SEQ'];
                                        $Cities["City"][$c]["Hotels"]["Hotel"][$cH]["Images"]["Image"][$aI]['ShortDesc'] = NULL;
                                        $Cities["City"][$c]["Hotels"]["Hotel"][$cH]["Images"]["Image"][$aI]['URL'] = trim($imagesData['URL']);
                                        $aI++;
                                    }
                                }
                            }
                            $Cities["City"][$c]["Hotels"]["Hotel"][$cH]["CityId"] = (int) $ItinerariesCityHOTEL['CITYID'];
                            $Cities["City"][$c]["Hotels"]["Hotel"][$cH]["Brief"] = htmlentities($ItinerariesCityHOTEL['BRIEF'], ENT_QUOTES);
                            $Cities["City"][$c]["Hotels"]["Hotel"][$cH]["MainImg"] = $ItinerariesCityHOTEL['DETAILIMG'];
                            $Cities["City"][$c]["Hotels"]["Hotel"][$cH]["AccoAminitiesMask"] = $ItinerariesCityHOTEL['ACCOAMINITIESMASK'];
                            $Cities["City"][$c]["Hotels"]["Hotel"][$cH]["AccoAminities"] = array();
                            $ACCOAMINITIES = $this->maskArray(str_split($ItinerariesCityHOTEL['ACCOAMINITIESMASK']), $finalResultSet['Result10']);
                            if (!empty($ACCOAMINITIES)) {
                                $am = 0;
                                foreach ($ACCOAMINITIES as $valACCOAMINITIES) {
                                    $Cities["City"][$c]["Hotels"]["Hotel"][$cH]["AccoAminities"][$am]["AminityId"] = $valACCOAMINITIES['AminityId'];
                                    $Cities["City"][$c]["Hotels"]["Hotel"][$cH]["AccoAminities"][$am]["Title"] = $valACCOAMINITIES['Title'];
                                    $am++;
                                }
                            }
                            $Cities["City"][$c]["Hotels"]["Hotel"][$cH]["IsfromAPI"] = false; //Need Help
                            $Cities["City"][$c]["Hotels"]["Hotel"][$cH]["SupplierSysId"] = (int) $ItinerariesCityHOTEL['SUPPLIERSYSID'];
                            $Cities["City"][$c]["Hotels"]["Hotel"][$cH]["SupplierName"] = $ItinerariesCityHOTEL['SUPPLIERNAME'];
                            $Cities["City"][$c]["Hotels"]["Hotel"][$cH]["priceaditionals"] = NULL; //Need Discuusion
                            $Cities["City"][$c]["Hotels"]["Hotel"][$cH]["RoomTypeName"] = isset($ItinerariesCityHOTEL['ROOMTYPENAME']) ? $ItinerariesCityHOTEL['ROOMTYPENAME'] : '';
                            $Cities["City"][$c]["Hotels"]["Hotel"][$cH]["MealTypeName"] = isset($ItinerariesCityHOTEL['MEALTYPENAME']) ? $ItinerariesCityHOTEL['MEALTYPENAME'] : '';
                            $cH++;
                        }
                    }
                }
                $Cities["City"][$c]["Activities"] = array();
                $cA = 0;
                $checkActivityId = array();
                foreach ($finalResultSet['Result5'] as $ItinerariesCityActivity) {
                    if ($ItinerariesCity['PLACESYSID'] == $ItinerariesCityActivity['CITYID']) {
                        if (!in_array($ItinerariesCityActivity['ACTIVITYSYSID'], $checkActivityId)) {
                            $checkActivityId[] = (int) $ItinerariesCityActivity['ACTIVITYSYSID'];
                            $Cities["City"][$c]["Activities"]["Activity"][$cA]["RefActivityId"] = (int) $ItinerariesCityActivity['ACTIVITYSYSID'];
                            $Cities["City"][$c]["Activities"]["Activity"][$cA]["Title"] = $ItinerariesCityActivity['TITLE'];
                            $Cities["City"][$c]["Activities"]["Activity"][$cA]["Description"] = htmlentities($ItinerariesCityActivity['WRITEUP'], ENT_QUOTES);
                            $Cities["City"][$c]["Activities"]["Activity"][$cA]["CurrencyType"] = "0"; //Need Help
                            $Cities["City"][$c]["Activities"]["Activity"][$cA]["CityId"] = (int) $ItinerariesCityActivity['CITYID'];
                            $Cities["City"][$c]["Activities"]["Activity"][$cA]["CityName"] = $ItinerariesCityActivity['CITYNAME'];
                            $Cities["City"][$c]["Activities"]["Activity"][$cA]["Lat"] = trim($ItinerariesCityActivity['LATITUDE']);
                            $Cities["City"][$c]["Activities"]["Activity"][$cA]["Long"] = trim($ItinerariesCityActivity['LONGITUDE']);
                            $Cities["City"][$c]["Activities"]["Activity"][$cA]["Image"] = $ItinerariesCityActivity['THUMNAILIMG'];
                            $Cities["City"][$c]["Activities"]["Activity"][$cA]["SupplierSysId"] = (int) $ItinerariesCityActivity['SUPPLIERSYSID'];
                            $Cities["City"][$c]["Activities"]["Activity"][$cA]["SupplierName"] = $ItinerariesCityActivity['SUPPLIERNAME'];
                            $Cities["City"][$c]["Activities"]["Activity"][$cA]["priceaditionals"] = NULL;
                            $cA++;
                        }
                    }
                }
                $Cities["City"][$c]["SightSeeings"] = array();
                $cS = 0;
                $checkSightSeeingId = array();
                foreach ($finalResultSet['Result6'] as $ItinerariesCitySightSeeing) {
                    if (!in_array($ItinerariesCitySightSeeing['SSSYSID'], $checkSightSeeingId)) {
                        $checkSightSeeingId[] = (int) $ItinerariesCitySightSeeing['SSSYSID'];
                        $Cities["City"][$c]["SightSeeings"]["SightSeeing"][$cS]["RefSSId"] = (int) $ItinerariesCitySightSeeing['SSSYSID'];
                        $Cities["City"][$c]["SightSeeings"]["SightSeeing"][$cS]["Title"] = $ItinerariesCitySightSeeing['SSTITLE'];
                        $Cities["City"][$c]["SightSeeings"]["SightSeeing"][$cS]["Description"] = htmlentities($ItinerariesCitySightSeeing['WRITEUP'], ENT_QUOTES);
                        $Cities["City"][$c]["SightSeeings"]["SightSeeing"][$cS]["CurrencyType"] = 0; //Need Help
                        $Cities["City"][$c]["SightSeeings"]["SightSeeing"][$cS]["CityId"] = (int) $ItinerariesCitySightSeeing['CITYID'];
                        $Cities["City"][$c]["SightSeeings"]["SightSeeing"][$cS]["CityName"] = $ItinerariesCitySightSeeing['CITYNAME'];
                        $Cities["City"][$c]["SightSeeings"]["SightSeeing"][$cS]["Lat"] = $ItinerariesCitySightSeeing['LATITUDE'];
                        $Cities["City"][$c]["SightSeeings"]["SightSeeing"][$cS]["Long"] = $ItinerariesCitySightSeeing['LONGITUDE'];
                        $Cities["City"][$c]["SightSeeings"]["SightSeeing"][$cS]["Image"] = htmlentities($ItinerariesCitySightSeeing['THUMNAILIMG'], ENT_QUOTES);
                        $Cities["City"][$c]["SightSeeings"]["SightSeeing"][$cS]["SupplierSysId"] = (int) $ItinerariesCitySightSeeing['SUPPLIERSYSID'];
                        $Cities["City"][$c]["SightSeeings"]["SightSeeing"][$cS]["SupplierName"] = $ItinerariesCitySightSeeing['SUPPLIERNAME'];
                        $Cities["City"][$c]["SightSeeings"]["SightSeeing"][$cS]["priceaditionals"] = NULL;
                        $cS++;
                    }
                }
                $c++;
            }
        }
        $tourTypesC = array();
        $minPrice = array();
        foreach ($finalResultSet['Result7'] as $tourTypesVal) {
            if ($AgencyId == 48 || $AgencyId == 4995) {
                if ($ItinerariesF['PAX'] == 2) {
                    $minPrice[] = $tourTypesVal['PRICEPERPERSON'];
                    $tourTypesC['TOURTYPE'][$tourTypesVal['TOURTYPE']]['TOURTYPE'] = $tourTypesVal['TOURTYPE'];
                    $tourTypesC['TOURTYPE'][$tourTypesVal['TOURTYPE']]['TOURTYPETITLE'] = $tourTypesVal['TOURTYPETITLE'];
                    $tourTypesC['TOURTYPE'][$tourTypesVal['TOURTYPE']]['Category'][$tourTypesVal['PACKCATEGORYID']]['CategoryId'] = (int) $tourTypesVal['PACKCATEGORYID'];
                    $tourTypesC['TOURTYPE'][$tourTypesVal['TOURTYPE']]['Category'][$tourTypesVal['PACKCATEGORYID']]['Type'] = $tourTypesVal['PACKCATEGORYTITLE'];
                    $tourTypesC['TOURTYPE'][$tourTypesVal['TOURTYPE']]['Category'][$tourTypesVal['PACKCATEGORYID']]['TPSysId'] = (int) $tourTypesVal['TPSYSID'];
                    $tourTypesC['TOURTYPE'][$tourTypesVal['TOURTYPE']]['Category'][$tourTypesVal['PACKCATEGORYID']]['MasterTPId'] = $tourTypesVal['MASTERREFID'];
                    $tourTypesC['TOURTYPE'][$tourTypesVal['TOURTYPE']]['Category'][$tourTypesVal['PACKCATEGORYID']]['SeletedForPackage'] = TRUE; //Need Help
                    $tourTypesC['TOURTYPE'][$tourTypesVal['TOURTYPE']]['Category'][$tourTypesVal['PACKCATEGORYID']]['Price'] = NULL; //Need Help
                    $tourTypesC['TOURTYPE'][$tourTypesVal['TOURTYPE']]['Category'][$tourTypesVal['PACKCATEGORYID']]['PriceAdditional'][] = $tourTypesVal;
                }
            } else {
                $minPrice[] = $tourTypesVal['PRICEPERPERSON'];
                $tourTypesC['TOURTYPE'][$tourTypesVal['TOURTYPE']]['TOURTYPE'] = $tourTypesVal['TOURTYPE'];
                $tourTypesC['TOURTYPE'][$tourTypesVal['TOURTYPE']]['TOURTYPETITLE'] = $tourTypesVal['TOURTYPETITLE'];
                $tourTypesC['TOURTYPE'][$tourTypesVal['TOURTYPE']]['Category'][$tourTypesVal['PACKCATEGORYID']]['CategoryId'] = (int) $tourTypesVal['PACKCATEGORYID'];
                $tourTypesC['TOURTYPE'][$tourTypesVal['TOURTYPE']]['Category'][$tourTypesVal['PACKCATEGORYID']]['Type'] = $tourTypesVal['PACKCATEGORYTITLE'];
                $tourTypesC['TOURTYPE'][$tourTypesVal['TOURTYPE']]['Category'][$tourTypesVal['PACKCATEGORYID']]['TPSysId'] = (int) $tourTypesVal['TPSYSID'];
                $tourTypesC['TOURTYPE'][$tourTypesVal['TOURTYPE']]['Category'][$tourTypesVal['PACKCATEGORYID']]['MasterTPId'] = $tourTypesVal['MASTERREFID'];
                $tourTypesC['TOURTYPE'][$tourTypesVal['TOURTYPE']]['Category'][$tourTypesVal['PACKCATEGORYID']]['SeletedForPackage'] = TRUE; //Need Help
                $tourTypesC['TOURTYPE'][$tourTypesVal['TOURTYPE']]['Category'][$tourTypesVal['PACKCATEGORYID']]['Price'] = NULL; //Need Help
                $tourTypesC['TOURTYPE'][$tourTypesVal['TOURTYPE']]['Category'][$tourTypesVal['PACKCATEGORYID']]['PriceAdditional'][] = $tourTypesVal;
            }
        }
        $tourTypes = array();
        $tp = 0;
        $p = 0;
        $checkB2CPrice = false;
        foreach ($catagoryArrayResult7 as $keyValP => $tourTypeP) {
            if ($keyValP == 1) {
                $checkB2CPrice = true;
            }
            $tourTypes['MarketType'][$p]['MarketTypeId'] = (int) $keyValP;
            $tourTypes['MarketType'][$p]['MarketTypeTitle'] = ($keyValP == 2) ? 'B2B' : 'B2C';
            $tourTypes['MarketType'][$p]['TourType'] = array();
            $tp = 0;
            foreach ($tourTypeP as $keyValP => $keyVal) {
                $tourTypes['MarketType'][$p]['TourType'][$tp]['TourType'] = $keyValP;
                $tourTypes['MarketType'][$p]['TourType'][$tp]['TourTypeTitle'] = ($keyValP == 1) ? 'Private' : 'Group';
                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories'] = array();
                $pt = 0;
                foreach ($keyVal as $key => $valP) {
                    $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["CategoryId"] = $key;
                    $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["Type"] = $catTypeMaster[$key];
                    $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["TPSysId"] = $valP[1][0]['TPSYSID'];
                    $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MasterTPId"] = $$valP[1][0]['MASTERREFID'];
                    $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["SeletedForPackage"] = TRUE;
                    $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["GroupSize"] = $valP[1][0]['PAX'];
                    $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["Price"] = $valP[1][0]['PRICEPERPERSON'];
                    $pJ = 0;
                    foreach ($valP as $keyM => $valM) {
                        $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]['MPTypeId'] = 1;
                        $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]['MPTypeText'] = "ITENARYWISE";
                        $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"] = array();
                        $pA = 0;
                        foreach ($valM as $val) {
                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['From'] = $val['FROMDATE']->format('Y-m-d');
                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['To'] = $val['TODATE']->format('Y-m-d');
                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['Currency'] = $val['CURRENCYTYPE'];
                            if ($val['AdultCostExtraBed']) {
                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceTripleOcc'] = $val['AdultCostExtraBed'];
                            } else {
                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceTripleOcc'] = $val['COSTPPDO'];
                            }
                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceDoubleOcc'] = $val['COSTPPDO'];
                            if ($val['COSTPPSO']) {
                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceSingleOcc'] = $val['COSTPPSO'] + $val['COSTPPDO'];
                            } else {
                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceSingleOcc'] = $val['COSTPPSO'];
                            }

                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceExtraBed'] = $val['COSTEXTRABED'];
                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceWithoutBed'] = $val['COSTCHILDWITHOUTBED'];
                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['Tax'] = $val['TAX'];
                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['PAX'] = $val['PAX'];
                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['MarkType'] = $val['MARKTYPE'];
                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['MarkValue'] = (float) $val['MARKVALUE'];
                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['ExcludedPercent'] = $val['EXCLUDEDPERCENT'];
                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['PricePerPerson'] = (float) $val['PRICEPERPERSON'];
                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['TourType'] = (int) $val['TOURTYPE'];
                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['TourTypeTitle'] = $val['TOURTYPETITLE'];
                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['DiscountType'] = 0; //Need Help
                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['DiscountVal'] = 0; //Need Help

                            $FROMDATECheck = $val['FROMDATE']->format('Y-m-d');
                            $TODATECheck = $val['TODATE']->format('Y-m-d');
                            foreach ($finalResultSet['Result19'] as $val19M) {
                                if (($valP[1][0]['TPSYSID'] == $val19M['TPSYSID']) && ($val['PAX'] == $val19M['PAX']) && ($FROMDATECheck == $val19M['FROMDATE']->format('Y-m-d')) && ($TODATECheck == $val19M['TODATE']->format('Y-m-d'))) {
                                    $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['PC'] = $val19M['CURRENCYTYPE'];
                                    if ($AgencyId == 43249) {

                                        $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['Currency'] = $val19M['CURRENCYTYPE'];
                                        if (trim($val['MARKTYPE']) == 'FixedAmount') {
                                            if ($val19M['CostInfent']) {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostInfent'] = (float) $val19M['CostInfent'] + (float) $val['MARKVALUE'];
                                            } else {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostInfent'] = $val19M['CostInfent'];
                                            }
                                            if ($val19M['COSTCHILDWITHOUTBED']) {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceWithoutBed'] = (float) $val19M['COSTCHILDWITHOUTBED'] + (float) $val['MARKVALUE'];
                                            } else {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceWithoutBed'] = $val19M['COSTCHILDWITHOUTBED'];
                                            }
                                            if ($val19M['COSTEXTRABED']) {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceExtraBed'] = (float) $val19M['COSTEXTRABED'] + (float) $val['MARKVALUE'];
                                            } else {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceExtraBed'] = $val19M['COSTEXTRABED'];
                                            }
                                            if ($val19M['COSTPPDO']) {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['PricePerPerson'] = (float) $val19M['COSTPPDO'] + (float) $val['MARKVALUE'];
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["Price"] = (float) $val19M['COSTPPDO'] + (float) $val['MARKVALUE'];
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceDoubleOcc'] = (float) $val19M['COSTPPDO'] + (float) $val['MARKVALUE'];
                                            } else {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['PricePerPerson'] = $val19M['COSTPPDO'];
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["Price"] = $val19M['COSTPPDO'];
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceDoubleOcc'] = $val19M['COSTPPDO'];
                                            }
                                            if ($val19M['COSTSO']) {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceSingleOcc'] = (float) ($val19M['COSTPPSO'] + $val19M['COSTPPDO']) + (float) $val['MARKVALUE'];
                                            } else {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceSingleOcc'] = $val19M['COSTPPSO'];
                                            }
                                            if ($val19M['AdultCostExtraBed']) {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceTripleOcc'] = (float) $val19M['AdultCostExtraBed'] + (float) $val['MARKVALUE'];
                                            } else {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceTripleOcc'] = $val19M['AdultCostExtraBed'];
                                            }
                                            if ($val19M['CostQuad']) {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostQuad'] = (float) $val19M['CostQuad'] + (float) $val['MARKVALUE'];
                                            } else {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostQuad'] = $val19M['CostQuad'];
                                            }
                                            if ($val19M['CostQuint']) {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostQuint'] = (float) $val19M['CostQuint'] + (float) $val['MARKVALUE'];
                                            } else {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostQuint'] = $val19M['CostQuint'];
                                            }
                                            if ($val19M['CostHexa']) {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostHexa'] = (float) $val19M['CostHexa'] + (float) $val['MARKVALUE'];
                                            } else {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostHexa'] = $val19M['CostHexa'];
                                            }
                                        } else {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["Price"] = $valP[1][0]['PRICEPERPERSON'];
                                            if ($val19M['CostInfent']) {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostInfent'] = (float) $val19M['CostInfent'] + ((float) $val19M['CostInfent'] * (float) $val['MARKVALUE']) / 100;
                                            } else {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostInfent'] = $val19M['CostInfent'];
                                            }

                                            if ($val19M['COSTCHILDWITHOUTBED']) {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceWithoutBed'] = (float) $val19M['COSTCHILDWITHOUTBED'] + ((float) $val19M['COSTCHILDWITHOUTBED'] * (float) $val['MARKVALUE']) / 100;
                                            } else {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceWithoutBed'] = $val19M['COSTCHILDWITHOUTBED'];
                                            }
                                            if ($val19M['COSTEXTRABED']) {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceExtraBed'] = (float) $val19M['COSTEXTRABED'] + ((float) $val19M['COSTEXTRABED'] * (float) $val['MARKVALUE']) / 100;
                                            } else {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceExtraBed'] = $val19M['COSTEXTRABED'];
                                            }
                                            if ($val19M['COSTPPDO']) {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['PricePerPerson'] = (float) $val19M['COSTPPDO'] + ((float) $val19M['COSTPPDO'] * (float) $val['MARKVALUE']) / 100;
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["Price"] = (float) $val19M['COSTPPDO'] + ((float) $val19M['COSTPPDO'] * (float) $val['MARKVALUE']) / 100;
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceDoubleOcc'] = (float) $val19M['COSTPPDO'] + ((float) $val19M['COSTPPDO'] * (float) $val['MARKVALUE']) / 100;
                                            } else {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['PricePerPerson'] = $val19M['COSTPPDO'];
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["Price"] = $val19M['COSTPPDO'];
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceDoubleOcc'] = $val19M['COSTPPDO'];
                                            }
                                            if ($val19M['COSTSO']) {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceSingleOcc'] = (float) ($val19M['COSTPPSO'] + $val19M['COSTPPDO']) + ( (float) ($val19M['COSTSO'] + $val19M['COSTPPDO']) * (float) $val['MARKVALUE']) / 100;
                                            } else {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceSingleOcc'] = $val19M['COSTPPSO'];
                                            }
                                            if ($val19M['CostQuad']) {
                                                if ($checkQuadPrice == False && $val19M['CostQuad'] > 0) {
                                                    $checkQuadPrice = True;
                                                }
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostQuad'] = (float) ($val19M['CostQuad']) + ( (float) ($val19M['CostQuad']) * (float) $val['MARKVALUE']) / 100;
                                            } else {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostQuad'] = $val19M['CostQuad'];
                                            }

                                            if ($val19M['CostQuint']) {
                                                if ($checkQuadPrice == False && $val19M['CostQuint'] > 0) {
                                                    $checkQuadPrice = True;
                                                }
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostQuint'] = (float) ($val19M['CostQuint']) + ( (float) ($val19M['CostQuint']) * (float) $val['MARKVALUE']) / 100;
                                            } else {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostQuint'] = $val19M['CostQuint'];
                                            }
                                            if ($val19M['CostHexa']) {
                                                if ($checkQuadPrice == False && $val19M['CostHexa'] > 0) {
                                                    $checkQuadPrice = True;
                                                }
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostHexa'] = (float) ($val19M['CostHexa']) + ( (float) ($val19M['CostHexa']) * (float) $val['MARKVALUE']) / 100;
                                            } else {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostHexa'] = $val19M['CostHexa'];
                                            }


                                            if ($val19M['AdultCostExtraBed']) {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceTripleOcc'] = (float) $val19M['AdultCostExtraBed'] + ((float) $val19M['AdultCostExtraBed'] * (float) $val['MARKVALUE']) / 100;
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['COSTTO'] = (float) $val19M['AdultCostExtraBed'] + ((float) $val19M['AdultCostExtraBed'] * (float) $val['MARKVALUE']) / 100;
                                            } else {
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceTripleOcc'] = $val19M['AdultCostExtraBed'];
                                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['COSTTO'] = $val19M['AdultCostExtraBed'];
                                            }
                                        }
                                    }
                                    if (trim($val['MARKTYPE']) == 'FixedAmount') {
                                        if ($val19M['CostInfent']) {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostInfent'] = (float) $val19M['CostInfent'] + (float) $val['MARKVALUE'];
                                        } else {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostInfent'] = $val19M['CostInfent'];
                                        }
                                        if ($val19M['COSTCHILDWITHOUTBED']) {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CWOB'] = (float) $val19M['COSTCHILDWITHOUTBED'] + (float) $val['MARKVALUE'];
                                        } else {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CWOB'] = $val19M['COSTCHILDWITHOUTBED'];
                                        }
                                        if ($val19M['COSTEXTRABED']) {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CEB'] = (float) $val19M['COSTEXTRABED'] + (float) $val['MARKVALUE'];
                                        } else {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CEB'] = $val19M['COSTEXTRABED'];
                                        }
                                        if ($val19M['COSTPPDO']) {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['COSTDO'] = (float) $val19M['COSTPPDO'] + (float) $val['MARKVALUE'];
                                        } else {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['COSTDO'] = $val19M['COSTPPDO'];
                                        }
                                        if ($val19M['COSTSO']) {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['COSTSO'] = (float) ($val19M['COSTPPSO'] + $val19M['COSTPPDO']) + (float) $val['MARKVALUE'];
                                        } else {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['COSTSO'] = $val19M['COSTPPSO'];
                                        }
                                        if ($val19M['AdultCostExtraBed']) {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['ACEB'] = (float) $val19M['AdultCostExtraBed'] + (float) $val['MARKVALUE'];
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['COSTTO'] = (float) $val19M['AdultCostExtraBed'] + (float) $val['MARKVALUE'];
                                        } else {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['ACEB'] = $val19M['AdultCostExtraBed'];
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['COSTTO'] = $val19M['AdultCostExtraBed'];
                                        }
                                        if ($val19M['CostQuad']) {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostQuad'] = (float) $val19M['CostQuad'] + (float) $val['MARKVALUE'];
                                        } else {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostQuad'] = $val19M['CostQuad'];
                                        }
                                        if ($val19M['CostQuint']) {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostQuint'] = (float) $val19M['CostQuint'] + (float) $val['MARKVALUE'];
                                        } else {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostQuint'] = $val19M['CostQuint'];
                                        }
                                        if ($val19M['CostHexa']) {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostHexa'] = (float) $val19M['CostHexa'] + (float) $val['MARKVALUE'];
                                        } else {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostHexa'] = $val19M['CostHexa'];
                                        }
                                    } else {
                                        if ($val19M['CostInfent']) {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostInfent'] = (float) $val19M['CostInfent'] + ((float) $val19M['CostInfent'] * (float) $val['MARKVALUE']) / 100;
                                        } else {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostInfent'] = $val19M['CostInfent'];
                                        }
                                        if ($val19M['COSTCHILDWITHOUTBED']) {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CWOB'] = (float) $val19M['COSTCHILDWITHOUTBED'] + ((float) $val19M['COSTCHILDWITHOUTBED'] * (float) $val['MARKVALUE']) / 100;
                                        } else {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CWOB'] = $val19M['COSTCHILDWITHOUTBED'];
                                        }
                                        if ($val19M['COSTEXTRABED']) {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CEB'] = (float) $val19M['COSTEXTRABED'] + ((float) $val19M['COSTEXTRABED'] * (float) $val['MARKVALUE']) / 100;
                                        } else {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CEB'] = $val19M['COSTEXTRABED'];
                                        }
                                        if ($val19M['COSTPPDO']) {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['COSTDO'] = (float) $val19M['COSTPPDO'] + ((float) $val19M['COSTPPDO'] * (float) $val['MARKVALUE']) / 100;
                                        } else {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['COSTDO'] = $val19M['COSTPPDO'];
                                        }
                                        if ($val19M['COSTPPSO']) {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['COSTSO'] = (float) ($val19M['COSTPPSO'] + $val19M['COSTPPDO']) + ( (float) ($val19M['COSTPPSO'] + $val19M['COSTPPDO']) * (float) $val['MARKVALUE']) / 100;
                                        } else {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['COSTSO'] = $val19M['COSTPPSO'];
                                        }
                                        if ($val19M['CostQuad']) {
                                            if ($checkQuadPrice == False && $val19M['CostQuad'] > 0) {
                                                $checkQuadPrice = True;
                                            }
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostQuad'] = (float) ($val19M['CostQuad']) + ( (float) ($val19M['CostQuad']) * (float) $val['MARKVALUE']) / 100;
                                        } else {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostQuad'] = $val19M['CostQuad'];
                                        }

                                        if ($val19M['CostQuint']) {
                                            if ($checkQuadPrice == False && $val19M['CostQuint'] > 0) {
                                                $checkQuadPrice = True;
                                            }
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostQuint'] = (float) ($val19M['CostQuint']) + ( (float) ($val19M['CostQuint']) * (float) $val['MARKVALUE']) / 100;
                                        } else {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostQuint'] = $val19M['CostQuint'];
                                        }
                                        if ($val19M['CostHexa']) {
                                            if ($checkQuadPrice == False && $val19M['CostHexa'] > 0) {
                                                $checkQuadPrice = True;
                                            }
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostHexa'] = (float) ($val19M['CostHexa']) + ( (float) ($val19M['CostHexa']) * (float) $val['MARKVALUE']) / 100;
                                        } else {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['CostHexa'] = $val19M['CostHexa'];
                                        }


                                        if ($val19M['AdultCostExtraBed']) {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['ACEB'] = (float) $val19M['AdultCostExtraBed'] + ((float) $val19M['AdultCostExtraBed'] * (float) $val['MARKVALUE']) / 100;
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['COSTTO'] = (float) $val19M['AdultCostExtraBed'] + ((float) $val19M['AdultCostExtraBed'] * (float) $val['MARKVALUE']) / 100;
                                        } else {
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['ACEB'] = $val19M['AdultCostExtraBed'];
                                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['COSTTO'] = $val19M['AdultCostExtraBed'];
                                        }
                                    }
                                }
                            }
                            $pA++;
                        }
                        $pJ++;
                    }
                    $pt++;
                }
                $tp++;
            }
            $p++;
        }
        if ($checkB2CPrice == false) {
            foreach ($catagoryArrayResult7 as $keyValP => $tourTypeP) {
                $keyValP = 1;
                $tourTypes['MarketType'][$p]['MarketTypeId'] = (int) $keyValP;
                $tourTypes['MarketType'][$p]['MarketTypeTitle'] = ($keyValP == 2) ? 'B2B' : 'B2C';
                $tourTypes['MarketType'][$p]['TourType'] = array();
                $tp = 0;
                foreach ($tourTypeP as $keyValP => $keyVal) {
                    $tourTypes['MarketType'][$p]['TourType'][$tp]['TourType'] = $keyValP;
                    $tourTypes['MarketType'][$p]['TourType'][$tp]['TourTypeTitle'] = 'Private';
                    $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories'] = array();
                    $pt = 0;
                    foreach ($keyVal as $key => $valP) {
                        $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["CategoryId"] = $key;
                        $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["Type"] = $catTypeMaster[$key];
                        $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["TPSysId"] = $valP[1][0]['TPSYSID'];
                        $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MasterTPId"] = $$valP[1][0]['MASTERREFID'];
                        $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["SeletedForPackage"] = TRUE;
                        $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["GroupSize"] = $valP[1][0]['PAX'];
                        $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["Price"] = $valP[1][0]['PRICEPERPERSON'];
                        $pJ = 0;
                        foreach ($valP as $keyM => $valM) {
                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]['MPTypeId'] = 1;
                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]['MPTypeText'] = "ITENARYWISE";
                            $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"] = array();
                            $pA = 0;
                            foreach ($valM as $val) {
                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['From'] = $val['FROMDATE']->format('Y-m-d');
                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['To'] = $val['TODATE']->format('Y-m-d');
                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['Currency'] = $val['CURRENCYTYPE'];
                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceTripleOcc'] = $val['AdultCostExtraBed'];
                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceDoubleOcc'] = $val['COSTPPDO'];
                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceSingleOcc'] = $val['COSTPPSO'] + $val['COSTPPDO'];
                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceExtraBed'] = $val['COSTEXTRABED'];
                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['priceWithoutBed'] = $val['COSTCHILDWITHOUTBED'];
                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['costInfent'] = $val['CostInfent'];
                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['Tax'] = $val['TAX'];
                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['PAX'] = $val['PAX'];
                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['MarkType'] = $val['MARKTYPE'];
                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['MarkValue'] = $val['MARKVALUE'];
                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['ExcludedPercent'] = $val['EXCLUDEDPERCENT'];
                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['PricePerPerson'] = $val['PRICEPERPERSON'];
                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['TourType'] = (int) $val['TOURTYPE'];
                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['TourTypeTitle'] = $val['TOURTYPETITLE'];
                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['DiscountType'] = 0; //Need Help
                                $tourTypes['MarketType'][$p]['TourType'][$tp]['Categories']["Category"][$pt]["MPType"][$pJ]["PriceAdditional"][$pA]['DiscountVal'] = 0; //Need Help
                                $pA++;
                            }
                            $pJ++;
                        }
                        $pt++;
                    }
                    $tp++;
                }
                $p++;
            }
        }
        $Inclusions = $this->maskString($finalResultSet['Result12'], $arrayINCLMASK);
        $PackageType = $this->maskString($finalResultSet['Result11'], $arrayPACKTYPEMASK);
        $CancellationRules = array();
        $cl = 0;
        if (!empty($finalResultSet['Result14'])) {
            foreach ($finalResultSet['Result14'] as $CancellationRulesData) {
                $CancellationRules[$cl]["DaysBefore"] = $CancellationRulesData['DAYSBEFORE'];
                $CancellationRules[$cl]["ExtraValue"] = $CancellationRulesData['EXTRAVALUE'];
                $CancellationRules[$cl]["IsPercentage"] = $statusArray[$CancellationRulesData['ISPERCENTAGE']];
                $CancellationRules[$cl]["Title"] = $CancellationRulesData['TITLE'];
                $CancellationRules[$cl]["TPRulesSysId"] = $CancellationRulesData['TPRULESSYSID'];
                $CancellationRules[$cl]["Value"] = $CancellationRulesData['VALUE'];
                $cl++;
            }
        }
        $bl = 0;
        $BuspickupLocationArray = array();
        if (!empty($finalResultSet['Result15'])) {
            foreach ($finalResultSet['Result15'] as $BuspickupLocation) {
                $BuspickupLocationArray[$BuspickupLocation['BusRouteSysId']][$BuspickupLocation['Sequence']]["PickupLocationSysId"] = (int) $BuspickupLocation['PickupLocationSysId'];
                $BuspickupLocationArray[$BuspickupLocation['BusRouteSysId']][$BuspickupLocation['Sequence']]["PickupLocationSysId"] = (int) $BuspickupLocation['PickupLocationSysId'];
                $BuspickupLocationArray[$BuspickupLocation['BusRouteSysId']][$BuspickupLocation['Sequence']]["StartCityId"] = (int) $BuspickupLocation['StartCityId'];
                $BuspickupLocationArray[$BuspickupLocation['BusRouteSysId']][$BuspickupLocation['Sequence']]["EndCityId"] = (int) $BuspickupLocation['EndCityId'];
                $BuspickupLocationArray[$BuspickupLocation['BusRouteSysId']][$BuspickupLocation['Sequence']]["pickupLocation"] = $BuspickupLocation['pickupLocation'];
                $BuspickupLocationArray[$BuspickupLocation['BusRouteSysId']][$BuspickupLocation['Sequence']]["PickupTime"][$BuspickupLocation['PickupLocationSysId']][] = $BuspickupLocation['PickupTime'];
                $bl++;
            }
        }
        //echo "<pre>";print_r();exit;
        $blc = 0;
        $TransferArray = array();
        if (!empty($finalResultSet['Result16'])) {
            foreach ($finalResultSet['Result16'] as $transferValArray) {
                $TransferArray[$transferValArray['TPInvnSysId']][$transferValArray['Sequence']]["Sequence"][] = (int) $transferValArray['Sequence'];
                $TransferArray[$transferValArray['TPInvnSysId']][$transferValArray['Sequence']]["TPInvnSysId"][] = (int) $transferValArray['TPInvnSysId'];
                $TransferArray[$transferValArray['TPInvnSysId']][$transferValArray['Sequence']]["Remark"][] = htmlentities($transferValArray['Remark'], ENT_QUOTES);
                $TransferArray[$transferValArray['TPInvnSysId']][$transferValArray['Sequence']]["NetCost"][] = (float) $transferValArray['NetCost'];
                $TransferArray[$transferValArray['TPInvnSysId']][$transferValArray['Sequence']]["AirportTransport"][] = trim($transferValArray['AirportTransport']);
                $TransferArray[$transferValArray['TPInvnSysId']][$transferValArray['Sequence']]["HotelTransport"][] = trim($transferValArray['HotelTransport']);
                $TransferArray[$transferValArray['TPInvnSysId']][$transferValArray['Sequence']]["RoadType"][] = trim($transferValArray['RoadType']);
                $blc++;
            }
        }

        $cc = 0;
        $couponCode = array();
        if (!empty($finalResultSet['Result20'])) {
            foreach ($finalResultSet['Result20'] as $CouponCodeArray) {
                $couponCode[$cc]['Description'] = htmlentities($CouponCodeArray['Description'], ENT_QUOTES);
                $couponCode[$cc]['CouponCode'] = trim($CouponCodeArray['CouponCode']);
                $cc++;
            }
        }
        $k = 1;
        $fixedInventoryArrayList = array();
        if (!empty($finalResultSet['Result17'])) {
            foreach ($finalResultSet['Result17'] as $fixedInventoryArray) {
                $fixedInventoryArrayList[$fixedInventoryArray['DestinationSysId']]["CityName"] = $fixedInventoryArray['Title'];
                //$fixedInventoryArrayList[$fixedInventoryArray['DestinationSysId']]["FlightDetail"] = array();

                if (!empty($finalResultSet['Result18'])) {
                    foreach ($finalResultSet['Result18'] as $fixedInventoryFlightDetailArray) {
                        if ($fixedInventoryFlightDetailArray['DestinationSysId'] == $fixedInventoryArray['DestinationSysId']) {
                            if ($fixedInventoryFlightDetailArray['InvnAirlineSysId'] != null) {
                                $fixedInventoryArrayList[$fixedInventoryFlightDetailArray['DestinationSysId']]['FlightInv'][$fixedInventoryFlightDetailArray['FlightType']][$fixedInventoryFlightDetailArray['InvnAirlineSysId']]["FlightType"] = $fixedInventoryFlightDetailArray['FlightType'];
                                $fixedInventoryArrayList[$fixedInventoryFlightDetailArray['DestinationSysId']]['FlightInv'][$fixedInventoryFlightDetailArray['FlightType']][$fixedInventoryFlightDetailArray['InvnAirlineSysId']]["AirlineName"] = $fixedInventoryFlightDetailArray['AirlineName'];
                                $fixedInventoryArrayList[$fixedInventoryFlightDetailArray['DestinationSysId']]['FlightInv'][$fixedInventoryFlightDetailArray['FlightType']][$fixedInventoryFlightDetailArray['InvnAirlineSysId']]["AirlineCode"] = $fixedInventoryFlightDetailArray['AirlineCode'];
                                $fixedInventoryArrayList[$fixedInventoryFlightDetailArray['DestinationSysId']]['FlightInv'][$fixedInventoryFlightDetailArray['FlightType']][$fixedInventoryFlightDetailArray['InvnAirlineSysId']]["DepartureAirportCode"] = $fixedInventoryFlightDetailArray['DepartureAirportCode'];
                                $fixedInventoryArrayList[$fixedInventoryFlightDetailArray['DestinationSysId']]['FlightInv'][$fixedInventoryFlightDetailArray['FlightType']][$fixedInventoryFlightDetailArray['InvnAirlineSysId']]["DepartureAirportName"] = $fixedInventoryFlightDetailArray['DepartureAirportName'];
                                $fixedInventoryArrayList[$fixedInventoryFlightDetailArray['DestinationSysId']]['FlightInv'][$fixedInventoryFlightDetailArray['FlightType']][$fixedInventoryFlightDetailArray['InvnAirlineSysId']]["DepartureTime"] = $fixedInventoryFlightDetailArray['DepartureTime']->format("H:i:s");
                                $fixedInventoryArrayList[$fixedInventoryFlightDetailArray['DestinationSysId']]['FlightInv'][$fixedInventoryFlightDetailArray['FlightType']][$fixedInventoryFlightDetailArray['InvnAirlineSysId']]["FromTerminal"] = $fixedInventoryFlightDetailArray['FromTerminal'];
                                $fixedInventoryArrayList[$fixedInventoryFlightDetailArray['DestinationSysId']]['FlightInv'][$fixedInventoryFlightDetailArray['FlightType']][$fixedInventoryFlightDetailArray['InvnAirlineSysId']]["ArrivalAirportCode"] = $fixedInventoryFlightDetailArray['ArrivalAirportCode'];
                                $fixedInventoryArrayList[$fixedInventoryFlightDetailArray['DestinationSysId']]['FlightInv'][$fixedInventoryFlightDetailArray['FlightType']][$fixedInventoryFlightDetailArray['InvnAirlineSysId']]["ArrivalAirportName"] = $fixedInventoryFlightDetailArray['ArrivalAirportName'];
                                $fixedInventoryArrayList[$fixedInventoryFlightDetailArray['DestinationSysId']]['FlightInv'][$fixedInventoryFlightDetailArray['FlightType']][$fixedInventoryFlightDetailArray['InvnAirlineSysId']]["ArrivalTime"] = $fixedInventoryFlightDetailArray['ArrivalTime']->format("H:i:s");
                                $fixedInventoryArrayList[$fixedInventoryFlightDetailArray['DestinationSysId']]['FlightInv'][$fixedInventoryFlightDetailArray['FlightType']][$fixedInventoryFlightDetailArray['InvnAirlineSysId']]["ToTerminal"] = $fixedInventoryFlightDetailArray['ToTerminal'];
                                $fixedInventoryArrayList[$fixedInventoryFlightDetailArray['DestinationSysId']]['FlightInv'][$fixedInventoryFlightDetailArray['FlightType']][$fixedInventoryFlightDetailArray['InvnAirlineSysId']]["EstimateHours"] = $fixedInventoryFlightDetailArray['EstimateHours'];
                            }
                        }
                    }
                }


                $fromDate = $fixedInventoryArray['FromDate']->format('Ymd');
                $fixedInventoryArrayList[$fixedInventoryArray['DestinationSysId']]["FromDate"][$fromDate]["FromDate"] = $fixedInventoryArray['FromDate']->format('Y-m-d');
                $fixedInventoryArrayList[$fixedInventoryArray['DestinationSysId']]["FromDate"][$fromDate]["FromDateDMY"] = $fixedInventoryArray['FromDate']->format('d/m/Y');
                $fixedInventoryArrayList[$fixedInventoryArray['DestinationSysId']]["FromDate"][$fromDate]["AdultCost"] = (float) $fixedInventoryArray['AdultCost'];
                $fixedInventoryArrayList[$fixedInventoryArray['DestinationSysId']]["FromDate"][$fromDate]["InfantCost"] = (float) $fixedInventoryArray['InfantCost'];
                // $fixedInventoryArrayList[$fixedInventoryArray['DestinationSysId']]["FromDate"][$fromDate]["MarkupType"] = (int) $fixedInventoryArray['MarkupType'];
                if ($fixedInventoryArray['MarkupType'] == 2) {
                    $fixedInventoryArrayList[$fixedInventoryArray['DestinationSysId']]["FromDate"][$fromDate]["B2BAdultMarkup"] = ((float) $fixedInventoryArray['AdultCost'] * (float) $fixedInventoryArray['B2BAdultMarkup'] / 100);
                    $fixedInventoryArrayList[$fixedInventoryArray['DestinationSysId']]["FromDate"][$fromDate]["B2BInfantMarkup"] = ((float) $fixedInventoryArray['B2BInfantMarkup'] * (float) $fixedInventoryArray['InfantCost'] / 100);
                    $fixedInventoryArrayList[$fixedInventoryArray['DestinationSysId']]["FromDate"][$fromDate]["B2CAdultMarkup"] = ((float) $fixedInventoryArray['AdultCost'] * (float) $fixedInventoryArray['B2CAdultMarkup'] / 100);
                    $fixedInventoryArrayList[$fixedInventoryArray['DestinationSysId']]["FromDate"][$fromDate]["B2CInfantMarkup"] = ((float) $fixedInventoryArray['B2CInfantMarkup'] * (float) $fixedInventoryArray['InfantCost'] / 100);
                } else {
                    $fixedInventoryArrayList[$fixedInventoryArray['DestinationSysId']]["FromDate"][$fromDate]["B2BAdultMarkup"] = (float) $fixedInventoryArray['B2BAdultMarkup'];
                    $fixedInventoryArrayList[$fixedInventoryArray['DestinationSysId']]["FromDate"][$fromDate]["B2BInfantMarkup"] = (float) $fixedInventoryArray['B2BInfantMarkup'];
                    $fixedInventoryArrayList[$fixedInventoryArray['DestinationSysId']]["FromDate"][$fromDate]["B2CAdultMarkup"] = (float) $fixedInventoryArray['B2CAdultMarkup'];
                    $fixedInventoryArrayList[$fixedInventoryArray['DestinationSysId']]["FromDate"][$fromDate]["B2CInfantMarkup"] = (float) $fixedInventoryArray['B2CInfantMarkup'];
                }
                $fixedInventoryArrayList[$fixedInventoryArray['DestinationSysId']]["FromDate"][$fromDate]["CurrencySysId"] = (int) $fixedInventoryArray['CurrencySysId'];
                $fixedInventoryArrayList[$fixedInventoryArray['DestinationSysId']]["FromDate"][$fromDate]["Symbol"] = trim($fixedInventoryArray['Symbol']);
            }
        }

        //echo "<pre>";print_r($finalResultSet['Result21']);exit;

        $ei = 0;
        $eventarray = array();
        if (!empty($finalResultSet['Result21'])) {
            foreach ($finalResultSet['Result21'] as $EventCodeArray) {
                $eventarray[$ei]['EventSysId'] = (int) trim($EventCodeArray['EventSysId']);
                $eventarray[$ei]['Title'] = trim($EventCodeArray['Title']);
                $eventarray[$ei]['Description'] = htmlentities($EventCodeArray['Description'], ENT_QUOTES);
                $eventarray[$ei]['image'] = trim($EventCodeArray['image']);
                $eventarray[$ei]['FromDate'] = trim($EventCodeArray['FromDate']->format('Y-m-d'));
                $eventarray[$ei]['ToDate'] = trim($EventCodeArray['ToDate']->format('Y-m-d'));
                $eventarray[$ei]['Time'] = trim($EventCodeArray['Time']);
                $eventarray[$ei]['IndustryTitle'] = trim($EventCodeArray['EventTitle']);
                $eventarray[$ei]['CategoryTitle'] = trim($EventCodeArray['CategoryTitle']);
                $eventarray[$ei]['Address'] = trim($EventCodeArray['Address']);
                $eventarray[$ei]['CityName'] = trim($EventCodeArray['CityName']);
                $eventarray[$ei]['StateName'] = trim($EventCodeArray['StateName']);
                $eventarray[$ei]['CountryName'] = trim($EventCodeArray['CountryName']);
                $eventarray[$ei]['CountrySysId'] = (int) trim($EventCodeArray['CountrySysId']);
                $eventarray[$ei]['CitySysId'] = (int) trim($EventCodeArray['CitySysId']);
                $ei++;
            }
        }
        $PKGSELLVALIDTILL = $finalResultSet['Result1'][0]['PKGSELLVALIDTILL']->format('Y-m-d');
        $gtxPkgSourceId = (int) $finalResultSet['Result1'][0]['PACKSOURCEID'];
        //$TPSYSID = (int) $finalResultSet['Result1'][0]['TPSYSID'];
        $TPSYSID = (int) $packageId;
        $AllowMinPax = $finalResultSet['Result1'][0]['MINPAX'];
        $QuadPrice = false;
        if ((int) $finalResultSet['Result1'][0]['IsquadPrice'] == 1) {
            $QuadPrice = true;
        }
        $Terms = array(
            "RefundPolicy" => ($finalResultSet['Result8'][0]['IsREFUNDPOLICY'] == 1) ? htmlentities($finalResultSet['Result8'][0]['RefundPolicy'], ENT_QUOTES) : '',
            "BookingTerms" => ($finalResultSet['Result8'][0]['IsBookingTerms'] == 1) ? htmlentities($finalResultSet['Result8'][0]['BOOKINGTERMS'], ENT_QUOTES) : '',
            "CancellationPolicy" => ($finalResultSet['Result8'][0]['IsCancellationPolicy'] == 1) ? htmlentities($finalResultSet['Result8'][0]['CANCELLATIONPOLICY'], ENT_QUOTES) : '',
            "Conditions" => ($finalResultSet['Result8'][0]['IsTermsAndConditions'] == 1) ? htmlentities($finalResultSet['Result8'][0]['TERMSANDCONDITIONS'], ENT_QUOTES) : '',
            "Exclusions" => ($finalResultSet['Result8'][0]['IsExclusions'] == 1) ? htmlentities($finalResultSet['Result8'][0]['EXCLUSIONS'], ENT_QUOTES) : '',
            "Inclusion" => ($finalResultSet['Result8'][0]['IsInclusions'] == 1) ? htmlentities($finalResultSet['Result8'][0]['INCLUSIONS'], ENT_QUOTES) : '',
            "TravelBasics" => ($finalResultSet['Result8'][0]['IsTravelBasics'] == 1) ? htmlentities($finalResultSet['Result8'][0]['TRAVELBASICS'], ENT_QUOTES) : '',
            "WhyUseUs" => ($finalResultSet['Result8'][0]['IsWhyUseUs'] == 1) ? htmlentities($finalResultSet['Result8'][0]['WHYUSEUS'], ENT_QUOTES) : '',
        );
        $dataArray = array("package" => array(
                "TPId" => $TPSYSID,
                "IsCF" => (int) $finalResultSet['Result1'][0]['IsCommonFlightPackage'],
                "ImgHeader" => $finalResultSet['Result1'][0]['IMGHEADER'],
                "IsFixedDeparturePackage" => (int) $finalResultSet['Result1'][0]['IsFixedDeparturePackage'],
                "IsBusRoutePackage" => (int) $finalResultSet['Result1'][0]['IsBusRoutePackage'],
                "ImgThumbnail" => trim($finalResultSet['Result1'][0]['IMGTHUMBNAIL']), //need discussion
                "BookingValidUntill" => $PKGSELLVALIDTILL,
                "AdvBookingDays" => (int) $finalResultSet['Result1'][0]['ADVBOOKINGDAYS'],
                "DETAILS" => htmlentities($finalResultSet['Result1'][0]['Details'], ENT_QUOTES),
                "AdvBookingPercent" => (int) $finalResultSet['Result1'][0]['ADVBOOKINGPERCENT'],
                "PriceRange" => $finalResultSet['Result1'][0]['PriceRange'],
                "MarkUpOnGTXNetworkPackage" => (float) $finalResultSet['Result1'][0]['MarkUpOnGTXNetworkPackage'],
                "AgencyId" => (int) $AgencyId,
                "AgencyIdB2C" => (int) $TGAgencySysId,
                "AgencyIdB2B" => (int) $AgencyId,
                "DestinationPlaces" => trim($finalResultSet['Result1'][0]['DestinationPlaces']),
                "DestinationPlacesSysId" => (int) trim($finalResultSet['Result1'][0]['DestinationPlacesSysId']),
                "SourcePlaces" => trim($finalResultSet['Result1'][0]['SourcePlaces']),
                "SourcePlaceSysId" => (int) trim($finalResultSet['Result1'][0]['SourcePlaceSysId']),
                "AgencyName" => $finalResultSet['Result1'][0]['AGENCYDISPLAYNAME'],
                "Name" => $finalResultSet['Result1'][0]['TITLE'],
                "TagLine1" => NULL, //need discussion
                "TagLine2" => NULL, //need discussion
                "AllowMinPax" => $AllowMinPax,
                "GroupSize" => $finalResultSet['Result1'][0]['GROUPSIZE'],
                "Source" => array("SourceId" => $gtxPkgSourceId, "Value" => $finalResultSet['Result1'][0]['PACKSOURCETITLE']),
                "Type" => array("TypeId" => $finalResultSet['Result1'][0]['PackRangeTypeID'], "Value" => $finalResultSet['Result1'][0]['PACKRANGETYPETITLE']),
                "Supplier" => array("SupplierId" => $finalResultSet['Result1'][0]['SUPPLIERSYSID'], "SupplierName" => $finalResultSet['Result1'][0]['SUPPLIERNAME']),
                "PackageSpec" => array("Specification" => $finalResultSet['Result1'][0]['PACKAGESPECTITLE'], "SpecificationId" => $finalResultSet['Result1'][0]['PackSpecTypeID']),
                "Inclusions" => $Inclusions,
                "PackageType" => $PackageType,
                "Validity" => array("From" => $currentDate, "To" => $PKGSELLVALIDTILL), //need help
                "Cities" => $Cities,
                "DiscountCode" => $couponCode,
                "Transfers" => NULL, //need discussion
                "OtherServices" => NULL, //need discussion
                "Itineraries" => $Itineraries,
                "TourTypes" => $tourTypes,
                "Terms" => $Terms,
                "PackTypeMask" => 0, //need discussion
                "InclMask" => NULL, //need discussion
                "DiscountType" => 0, //need discussion
                "DiscountVal" => 0, //need discussion
                "CancellationRules" => $CancellationRules,
                "BuspickupLocation" => $BuspickupLocationArray,
                "TransferData" => $TransferArray,
                "AllowBookingType" => (int) $finalResultSet['Result1'][0]['BookingType'],
                "QuadPrice" => $QuadPrice,
                "fixedInventory" => $fixedInventoryArrayList,
                "bookingvalidityDay" => (int) $finalResultSet['Result1'][0]['bookingvalidityDay'],
                "eventarray" => $eventarray
        ));
        $Fcountries = "";
        $KcountryIds = "";
        $countries = array_values($getCountryName);
        if (!empty($countries)) {
            $Fcountries = implode(",", $countries);
            $KcountryIds = implode(",", array_keys($getCountryName));
        }
        $Fdestinations = "";
        $Kdestinations = "";
        $destinations = array_values($getCityName);
        if (!empty($destinations)) {
            $Fdestinations = implode(",", $destinations);
            $Kdestinations = implode(",", array_keys($getCityName));
        }
        $nights = (int) $totalDay - 1;
        $PackageSearchString = $finalResultSet['Result1'][0]['SearchString'];
        if ($PackageSearchString != "") {
            $PackageSearchString = $finalResultSet['Result1'][0]['SearchString'];
        } else {
            $PackageSearchString = $Fdestinations;
        }

        $finalDataArray = array(
            "gtxPkgId" => $TPSYSID,
            "gtxPkgSourceId" => $gtxPkgSourceId,
            "QuadPrice" => $QuadPrice,
            "agencyId" => $AgencyId,
            "isFeatured" => TRUE,
            "displayIndex" => 0,
            "shortJsonInfo" => NULL,
            "longJsonInfo" => $dataArray,
            "PackageSearchSting" => $PackageSearchString,
            "destinations" => $Fdestinations,
            "destinationIds" => $Kdestinations,
            "countries" => $Fcountries,
            "countryIds" => $KcountryIds,
            "minPrice" => min($minPrice),
            "maxPrice" => max($minPrice),
            "nights" => $nights,
            "minPax" => $AllowMinPax,
            "pkgValidFrom" => $currentDate,
            "pkgValidTo" => $PKGSELLVALIDTILL,
            "bookingValidUntil" => $PKGSELLVALIDTILL,
            "isPublished" => FALSE,
            "isActive" => TRUE,
            "isMarkForDel" => FALSE
        );
        $ItemType = 1;
        $insertData = array(
            "GTXPkgId" => $TPSYSID,
            "GTXPkgSourceId" => $gtxPkgSourceId,
            "AgencySysId" => $TGAgencySysId,
            "IsFeatured" => True,
            "DisplayIndex" => False,
            "ItemType" => $ItemType,
            "PackageType" => $gtxPkgSourceId,
            "PackageSearchString" => $PackageSearchString,
            "PackageSubType" => $PackageCostCalType,
            "ShortJsonInfo" => $PackageType,
            "LongJsonInfo" => json_encode($dataArray),
            "Destinations" => $Fdestinations,
            "DestinationsId" => $Kdestinations,
            "Countries" => $Fcountries,
            "CountryIds" => $KcountryIds,
            "MinPrice" => (float) min($minPrice),
            "MaxPrice" => (float) max($minPrice),
            "Nights" => $nights,
            "MinPax" => $AllowMinPax,
            "PackTypeMask" => "",
            "PackRangeType" => "",
            "PkgValidFrom" => $currentDate,
            "PkgValidUntil" => $PKGSELLVALIDTILL,
            "BookingValidUntil" => $PKGSELLVALIDTILL,
            "StarRating" => 3,
            "UpdateDate" => date("Y-m-d H:i:s"),
            "CreateDate" => date("Y-m-d H:i:s"),
            "PublishedOn" => date("Y-m-d H:i:s"),
            "CreatedBy" => isset(Travel_Model_AgencyAuth::getIdentity()->UserSysId) ? Travel_Model_AgencyAuth::getIdentity()->UserSysId : '1',
            "UpdatedBy" => isset(Travel_Model_AgencyAuth::getIdentity()->UserSysId) ? Travel_Model_AgencyAuth::getIdentity()->UserSysId : '1',
            "IsPublish" => false,
            "IsActive" => true,
            "IsMarkForDel" => false,
        );
        //echo "<pre>";print_r($insertData);exit;
        try {
            $dbtable = new Zend_Db_Table("TB_TBB2C_Packages_Master");
            $updateData = array(
                "UpdateDate" => date("Y-m-d H:i:s"),
                "UpdatedBy" => isset(Travel_Model_AgencyAuth::getIdentity()->UserSysId) ? Travel_Model_AgencyAuth::getIdentity()->UserSysId : '1',
                "IsMarkForDel" => true
            );
            $where = array("GTXPkgId=?" => $TPSYSID, "AgencySysId=?" => $TGAgencySysId);
            $dbtable->delete($where);
            $returnVal = $dbtable->insert($insertData);
        } catch (Zend_Exception $e) {
            echo $returnVal = $e->getMessage();
            exit;
        }
        header('Content-type: text/javascript');
        echo $ResultSet = $this->prettyPrint(Zend_Json::Encode($finalDataArray));
        exit;
        return $returnVal;
    }

    function prettyPrint($json) {
        $result = '';
        $level = 0;
        $in_quotes = false;
        $in_escape = false;
        $ends_line_level = NULL;
        $json_length = strlen($json);

        for ($i = 0; $i < $json_length; $i++) {
            $char = $json[$i];
            $new_line_level = NULL;
            $post = "";
            if ($ends_line_level !== NULL) {
                $new_line_level = $ends_line_level;
                $ends_line_level = NULL;
            }
            if ($in_escape) {
                $in_escape = false;
            } else if ($char === '"') {
                $in_quotes = !$in_quotes;
            } else if (!$in_quotes) {
                switch ($char) {
                    case '}':
                    case ']':
                        $level--;
                        $ends_line_level = NULL;
                        $new_line_level = $level;
                        break;

                    case '{':
                    case '[':
                        $level++;
                    case ',':
                        $ends_line_level = $level;
                        break;

                    case ':':
                        $post = " ";
                        break;

                    case " ":
                    case "\t":
                    case "\n":
                    case "\r":
                        $char = "";
                        $ends_line_level = $new_line_level;
                        $new_line_level = NULL;
                        break;
                }
            } else if ($char === '\\') {
                $in_escape = true;
            }
            if ($new_line_level !== NULL) {
                $result .= "\n" . str_repeat("\t", $new_line_level);
            }
            $result .= $char . $post;
        }
        return $result;
    }

    public function maskStringWithId($dataArray, $maskArray) {
        //  echo "<pre>";print_r($dataArray);exit;
        $string = array();
        $h = 0;
        for ($i = 1; $i < count($maskArray); $i++) {
            if ($maskArray[$i] == 1) {
                $string[$dataArray[$h]['INCLID']] = @$dataArray[$h]['TITLE'];
            }
            $h++;
        }

        return $string;
    }

    public function maskString($dataArray, $maskArray) {
        $string = array();
        $h = 0;
        for ($i = 1; $i < count($maskArray); $i++) {
            if ($maskArray[$i] == 1) {
                $string[] = @$dataArray[$h]['TITLE'];
            }
            $h++;
        }
        $stringSET = "";
        $string = array_values($string);
        if (!empty($string)) {
            $stringSET = implode(',', $string);
        }
        return $stringSET;
    }

    public function maskArray($maskArray, $dataArray) {
        $string = array();
        $h = 0;
        for ($i = 1; $i < count($maskArray); $i++) {
            if ($maskArray[$i] == 1) {
                $string[$h]['AminityId'] = @$dataArray[$h]['AMINITYID'];
                $string[$h]['Title'] = @$dataArray[$h]['TITLE'];
            }
            $h++;
        }
        return $string;
    }

}

Youez - 2016 - github.com/yon3zu
LinuXploit