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

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

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

class Travel_Model_TblSightseeing
{

    private $db = NULL;

    public $intId = NULL;

    public $strCondition = NULL;

    public $searchArr = NULL;

    public $searchSightseeingArr = NULL;

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

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


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

    public function getAllSightseeingList($intLoggedinUserAgencySysId)
    {
        $sql = " SELECT InvnItemSysId, XRef, TB_IC_Supplier.SupplierName AS SupplierType, TB_Master_Geo_Country.Title AS CountryName, TB_Master_Geo_City.Title AS CityName, TB_IC_SightSeeing.Title AS SightseeingName,TB_IC_SightSeeing.SSSysId, TB_IC_SightSeeing.DurationStr,TB_IC_SightSeeing.SSType,TB_IC_SightSeeing.ICSourceSysId,TB_IC_SightSeeing.IsActive as IsActiveSightseeing, "
            . "TB_Master_BookingType.Title AS BookingName, SightSeeingTypeName As SightseeingType, tmis.IsActive, tmis.IsSaleStart,tmis.DisplayOnB2C, CONVERT(VARCHAR(24),tmis.FromDate,103) as FromDate,CONVERT(VARCHAR(24),tmis.ToDate,103) as ToDate "
            . "FROM TB_MP_Inventory_SightSeeing as tmis "
            . "LEFT JOIN TB_IC_SightSeeing ON tmis.XRef=TB_IC_SightSeeing.SSSysId "
            . "LEFT JOIN TB_IC_Supplier ON tmis.SupplierSysId=TB_IC_Supplier.SupplierSysId "
            . "LEFT JOIN TB_Master_Geo_Country ON TB_IC_SightSeeing.ContSysId=TB_Master_Geo_Country.ContId "
            . "LEFT JOIN TB_Master_Geo_City ON TB_IC_SightSeeing.CitySysId=TB_Master_Geo_City.CityId "
            . "LEFT JOIN TB_Master_BookingType ON tmis.BookingType=TB_Master_BookingType.BookingType "
            //                . "LEFT JOIN TB_Master_SightSeeingType ON TB_IC_SightSeeing.SSType=TB_Master_SightSeeingType.SSType "
            //. "JOIN TB_Master_SightSeeingGroupType ON TB_IC_SightSeeing.SSGrType=TB_Master_SightSeeingGroupType.SSGroupType "
            . " WHERE 1=1 AND tmis.IsMarkForDelete='0' AND TB_IC_SightSeeing.SSSysId != '0'   ";

        if (!empty($intLoggedinUserAgencySysId)) {
            $sql .= " AND tmis.AgencySysId = '" . $intLoggedinUserAgencySysId . "' ";
        }

        if (!empty($this->strCondition)) {
            $sql .= $this->strCondition;
        }

        if (!empty($this->searchArr)) {
            //echo "<pre>"; print_r($searchArr); die;
            if (isset($this->searchArr['cityId']) && $this->searchArr['cityId'] > 0) {
                $sql .= " AND TB_IC_SightSeeing.CitySysId = '" . $this->searchArr['cityId'] . "' ";
            }

            if (isset($this->searchArr['SightseeingGroupType']) && !empty($this->searchArr['SightseeingGroupType'])) {
                $sql .= " AND TB_IC_SightSeeing.SSGrType = '" . $this->searchArr['SightseeingGroupType'] . "' ";
            }

            if (isset($this->searchArr['SightseeingType']) && !empty($this->searchArr['SightseeingType'])) {
                $sql .= " AND TB_IC_SightSeeing.SSType = '" . $this->searchArr['SightseeingType'] . "' ";
            }

            if (isset($this->searchArr['supplierId']) && !empty($this->searchArr['supplierId'])) {
                $sql .= " AND tmis.SupplierSysId = '" . $this->searchArr['supplierId'] . "'";
            }

            if (isset($this->searchArr['SightseeingName']) && !empty($this->searchArr['SightseeingName'])) {
                $SightseeingName = $this->searchArr['SightseeingName'];
                $sql .= " AND TB_IC_SightSeeing.Title LIKE '%$SightseeingName%'";
            }
        }

        $sql .= " ORDER BY tmis.UpdateDate DESC ";

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

    public function getAllManageSightseeingListAgencyWise($intLoggedinUserId, $searchData = array())
    {
        $select = $this->db->select();
        $ICArray = array("SSSysId", "Title AS SightseeingName", "DurationStr", "DurationInMin", "IsActive", "IsApproved", "SightSeeingTypeName", "SightSeeingGrTypeName", "IsRate");
        $select->from(array('tb1' => "TB_IC_SightSeeing"), $ICArray);
        //$select->joinLeft(array('tb2' => "TB_MP_Inventory_SightSeeing"), "tb2.XRef = tb1.SSSysId", array("DisplayOnB2C", "TotalCostNativeAdult", "InvnItemSysId"));
        $select->joinLeft(array('tb3' => "TB_Master_Geo_Country"), "tb1.ContSysId = tb3.ContId", array("Title AS CountryName"));
        $select->joinLeft(array('tb4' => "TB_Master_Geo_City"), "tb1.CitySysId = tb4.CityId", array("Title AS CityName"));
        $select->joinLeft(array('tb5' => "TB_Agency"), "tb1.ICSourceSysId = tb5.AgencySysId", array("Title as AgencyName"));
        $select->where("tb1.IsMarkForDel =?", 0);
        if (!empty($intLoggedinUserId)) {
            $select->where("tb1.ICSourceSysId = '" . $intLoggedinUserId . "'  AND IsAgentSpec = 1 ");
        }
        if (!empty($searchData)) {
            if (isset($searchData['cityId']) && (int) $searchData['cityId'] != 0) {
                $select->where("tb1.CitySysId = '" . $searchData['cityId'] . "' ");
            }
            if (isset($searchData['ContSysId']) && (int) $searchData['ContSysId'] != 0) {
                $select->where("tb1.ContSysId = '" . $searchData['ContSysId'] . "' ");
            }
            if (isset($searchData['SightseeingType']) && !empty($searchData['SightseeingType'])) {
                $select->where("tb1.SSType = '" . $searchData['SightseeingType'] . "' ");
            }
            if (isset($searchData['SightseeingName']) && ($searchData['SightseeingName'] != "")) {
                $SightseeingName = $searchData['SightseeingName'];
                $select->where("tb1.Title LIKE '%$SightseeingName%'");
            }
        }

        $select->order("tb1.SSSysId DESC ");
//      echo $select;
        return $select;
    }


    public function getAllManageSightseeingList($intLoggedinUserId)
    {
        $sql = " SELECT TB_MP_Inventory_SightSeeing.DisplayOnB2C,TB_IC_SightSeeing.SSSysId, TB_Master_Geo_Country.Title AS CountryName, TB_Master_Geo_City.Title AS CityName, TB_IC_SightSeeing.Title AS SightseeingName, TB_IC_SightSeeing.DurationStr, TB_IC_SightSeeing.DurationInMin, "
            . " TB_IC_SightSeeing.IsActive, TB_IC_SightSeeing.IsApproved, TB_IC_SightSeeing.SightSeeingTypeName, TB_IC_SightSeeing.SightSeeingGrTypeName, TB_Agency.Title as AgencyName "
            . "FROM TB_IC_SightSeeing "
            . "LEFT JOIN TB_MP_Inventory_SightSeeing ON TB_MP_Inventory_SightSeeing.XRef=TB_IC_SightSeeing.SSSysId "
            . "LEFT JOIN TB_Master_Geo_Country ON TB_IC_SightSeeing.ContSysId=TB_Master_Geo_Country.ContId "
            . "LEFT JOIN TB_Master_Geo_City ON TB_IC_SightSeeing.CitySysId=TB_Master_Geo_City.CityId "
            . "LEFT JOIN TB_Agency ON TB_IC_SightSeeing.ICSourceSysId=TB_Agency.AgencySysId "
            . " WHERE 1=1 AND TB_IC_SightSeeing.IsMarkForDel='0' ";

        if (!empty($intLoggedinUserId)) {
            $sql .= " AND TB_IC_SightSeeing.ICSourceSysId = '" . $intLoggedinUserId . "'  AND IsAgentSpec = 1 ";
        }

        if (!empty($this->searchSightseeingArr)) {
            //echo "<pre>"; print_r($searchArr); die;
            if ($this->searchSightseeingArr['cityId'] != 0) {
                $sql .= " AND TB_IC_SightSeeing.CitySysId = '" . $this->searchSightseeingArr['cityId'] . "' ";
            }

            if ($this->searchSightseeingArr['ContSysId'] != 0) {
                $sql .= " AND TB_IC_SightSeeing.ContSysId = '" . $this->searchSightseeingArr['ContSysId'] . "' ";
            }




            if ($this->searchSightseeingArr['SightseeingType'] != 0) {
                $sql .= " AND TB_IC_SightSeeing.SSType = '" . $this->searchSightseeingArr['SightseeingType'] . "' ";
            }

            if ($this->searchSightseeingArr['SightseeingName'] != "") {
                $SightseeingName = $this->searchSightseeingArr['SightseeingName'];
                $sql .= " AND TB_IC_SightSeeing.Title LIKE '%$SightseeingName%'";
            }
        }

        $sql .= " ORDER BY TB_IC_SightSeeing.SSSysId DESC ";

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

    public function getAllManageSightseeingListAdmin($intLoggedinUserId)
    {
        $sql = " SELECT SSSysId, TB_Master_Geo_Country.Title AS CountryName, TB_Master_Geo_City.Title AS CityName, TB_IC_SightSeeing.Title AS SightseeingName, TB_IC_SightSeeing.DurationStr, TB_IC_SightSeeing.DurationInMin, "
            . " TB_IC_SightSeeing.IsActive, TB_IC_SightSeeing.IsApproved, TB_IC_SightSeeing.IsUnique, TB_IC_SightSeeing.ContSysId,TB_IC_SightSeeing.CitySysId, TB_IC_SightSeeing.ICSourceSysId, TB_IC_SightSeeing.SightSeeingTypeName, TB_IC_SightSeeing.SightSeeingGrTypeName, TB_Agency.Title as AgencyName "
            . "FROM TB_IC_SightSeeing "
            . "LEFT JOIN TB_Master_Geo_Country ON TB_IC_SightSeeing.ContSysId=TB_Master_Geo_Country.ContId "
            . "LEFT JOIN TB_Master_Geo_City ON TB_IC_SightSeeing.CitySysId=TB_Master_Geo_City.CityId "
            . "LEFT JOIN TB_Agency ON TB_IC_SightSeeing.ICSourceSysId=TB_Agency.AgencySysId "
            . " WHERE 1=1 AND TB_IC_SightSeeing.IsMarkForDel='0' ";

        if (!empty($intLoggedinUserId)) {
            $sql .= " AND TB_IC_SightSeeing.ICSourceSysId = '" . $intLoggedinUserId . "'  AND IsAgentSpec = 1 ";
        }

        if (!empty($this->searchSightseeingArr)) {
            //echo "<pre>"; print_r($searchArr); die;
            if ($this->searchSightseeingArr['cityId'] != 0) {
                $sql .= " AND TB_IC_SightSeeing.CitySysId = '" . $this->searchSightseeingArr['cityId'] . "' ";
            }

            if ($this->searchSightseeingArr['SightseeingType'] != 0) {
                $sql .= " AND TB_IC_SightSeeing.SSType = '" . $this->searchSightseeingArr['SightseeingType'] . "' ";
            }

            if ($this->searchSightseeingArr['SightseeingName'] != "") {
                $SightseeingName = $this->searchSightseeingArr['SightseeingName'];
                $sql .= " AND TB_IC_SightSeeing.Title LIKE '%$SightseeingName%'";
            }
        }
        $sql .= " AND TB_IC_SightSeeing.IsApproved = '0' AND TB_IC_SightSeeing.IsMapped = '0' AND TB_IC_SightSeeing.IsMarkForDel = '0' ";
        $sql .= " ORDER BY TB_IC_SightSeeing.SSSysId DESC ";

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

    public function getAllManageSightseeingListMapMaster($country_id, $city_id)
    {
        $sql = " SELECT SSSysId, TB_Master_Geo_Country.Title AS CountryName, TB_Master_Geo_City.Title AS CityName, TB_IC_SightSeeing.Title AS SightseeingName, TB_IC_SightSeeing.DurationStr, TB_IC_SightSeeing.DurationInMin, "
            . " TB_IC_SightSeeing.IsActive, TB_IC_SightSeeing.IsApproved, TB_IC_SightSeeing.ContSysId,TB_IC_SightSeeing.CitySysId, TB_IC_SightSeeing.ICSourceSysId, TB_IC_SightSeeing.SightSeeingTypeName, TB_IC_SightSeeing.SightSeeingGrTypeName, TB_Agency.Title as AgencyName "
            . "FROM TB_IC_SightSeeing "
            . "LEFT JOIN TB_Master_Geo_Country ON TB_IC_SightSeeing.ContSysId=TB_Master_Geo_Country.ContId "
            . "LEFT JOIN TB_Master_Geo_City ON TB_IC_SightSeeing.CitySysId=TB_Master_Geo_City.CityId "
            . "LEFT JOIN TB_Agency ON TB_IC_SightSeeing.ICSourceSysId=TB_Agency.AgencySysId "
            . " WHERE 1=1 AND TB_IC_SightSeeing.IsMarkForDel='0' ";

        if (!empty($country_id)) {
            $sql .= " AND TB_IC_SightSeeing.ContSysId = '" . $country_id . "'  ";
        }
        if (!empty($city_id)) {
            $sql .= " AND TB_IC_SightSeeing.CitySysId = '" . $city_id . "' ";
        }


        $sql .= " AND TB_IC_SightSeeing.IsApproved = '1' AND TB_IC_SightSeeing.IsMarkForDel = '0' ";
        $sql .= " ORDER BY TB_IC_SightSeeing.Title ASC ";

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

    public function getAllManageSightseeingListAgency($agencyId, $country_id, $city_id)
    {
        $sql = " SELECT SSSysId, TB_Master_Geo_Country.Title AS CountryName, TB_Master_Geo_City.Title AS CityName, TB_IC_SightSeeing.Title AS SightseeingName, TB_IC_SightSeeing.DurationStr, TB_IC_SightSeeing.DurationInMin, "
            . " TB_IC_SightSeeing.IsActive, TB_IC_SightSeeing.IsApproved, TB_IC_SightSeeing.ContSysId,TB_IC_SightSeeing.CitySysId, TB_IC_SightSeeing.ICSourceSysId, TB_IC_SightSeeing.SightSeeingTypeName, TB_IC_SightSeeing.SightSeeingGrTypeName, TB_Agency.Title as AgencyName "
            . "FROM TB_IC_SightSeeing "
            . "LEFT JOIN TB_Master_Geo_Country ON TB_IC_SightSeeing.ContSysId=TB_Master_Geo_Country.ContId "
            . "LEFT JOIN TB_Master_Geo_City ON TB_IC_SightSeeing.CitySysId=TB_Master_Geo_City.CityId "
            . "LEFT JOIN TB_Agency ON TB_IC_SightSeeing.ICSourceSysId=TB_Agency.AgencySysId "
            . " WHERE 1=1 AND TB_IC_SightSeeing.IsMarkForDel='0' ";

        if (!empty($country_id)) {
            $sql .= " AND TB_IC_SightSeeing.ContSysId = '" . $country_id . "'  ";
        }
        if (!empty($city_id)) {
            $sql .= " AND TB_IC_SightSeeing.CitySysId = '" . $city_id . "' ";
        }
        //        if(!empty($agencyId)) {
        //            $sql .= " AND TB_IC_SightSeeing.ICSourceSysId = '".$agencyId."'  ";
        //        }

        $sql .= " AND TB_IC_SightSeeing.IsApproved = '0' AND TB_IC_SightSeeing.IsMapped = '0' AND TB_IC_SightSeeing.IsUnique = '0' AND TB_IC_SightSeeing.IsMarkForDel = '0' ";
        $sql .= " ORDER BY TB_IC_SightSeeing.Title ASC ";

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


    public function getManageSightSeeingDetailsMap($SSSysId)
    {

        //        $sql = " SELECT ActivitySysId, TB_IC_Activity.IsAgentSpec, TB_IC_Activity.AgentSysId, TB_IC_Activity.ContSysId, TB_IC_Activity.CitySysId, PeakMothMask, PickUpLocation, DaysWeekMask, TB_IC_Activity.Icon, TB_IC_Activity.ActivityGrType AS ActivityGrTypeId, TB_IC_Activity.ActivityType AS ActivityTypeId, DifficultyLevel, IsTransferInc, StartAgeYr, EndAgeYr, Popularity, ThingsToCarry,OtherInclusion,Advisory,RefundPolicy,CancellationPolicy,ConfirmationPolicy,TimeSlots, TB_Master_Geo_Country.Title AS CountryName, TB_Master_Geo_City.Title AS CityName, TB_IC_Activity.Title AS ActivityName, TB_IC_Activity.WriteUp AS details, TB_IC_Activity.DifficultyLevel, TB_IC_Activity.ThingsToCarry,TB_IC_Activity.OtherInclusion,TB_IC_Activity.Advisory,TB_IC_Activity.RefundPolicy,TB_IC_activity.CancellationPolicy,TB_IC_Activity.ConfirmationPolicy,TB_IC_Activity.DurationInMin, TB_IC_Activity.DurationStr, "
        //                . " TB_Master_ActivityType.Title As ActivityType,  TB_Master_DifficultyType.Title as DifficultyType,TB_IC_Activity.Address, TB_IC_Activity.IsApproved, TB_IC_Activity.IsTeenAllowed, TB_IC_Activity.IsKidAllowed, TB_IC_Activity.IsAdultAllowed, TB_IC_Activity.AwardRecognizations, TB_IC_Activity.IsPetAllowed, TB_IC_Activity.IsTrxAllowed, TB_IC_Activity.IsPickAllowed, TB_IC_Activity.BookingType, ";

        $sql = " SELECT TB_IC_SightSeeing.SSSysId, TB_IC_SightSeeing.synonyms,"
            . "TB_IC_SightSeeing.ContSysId, TB_IC_SightSeeing.CitySysId,"
            . " TB_IC_SightSeeing.Title AS SightSeeingName, "
            . "TB_IC_SightSeeing.IsMarkForDel "
            . "FROM TB_IC_SightSeeing "
            . " WHERE 1 = 1 ";

        if (!empty($SSSysId)) {
            $sql .= " AND SSSysId = '" . $SSSysId . "' ";
        }
        return $this->db->query($sql)->fetch();
    }


    public function getAllSightseeingGroupTypeList()
    {
        $sql = "Select SSGroupType, Title From TB_Master_SightSeeingGroupType where 1 = 1 AND IsActive='1'";
        $sql .= " ORDER BY Title ";

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

    public function getAllSightseeingTypeList()
    {
        $sql = "Select SSType, Title, Details From TB_Master_SightSeeingType where 1 = 1 AND IsActive='1'";
        $sql .= " ORDER BY Title ";

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

    public function getAllSightseeingInclypeList()
    {
        $sql = "Select SSInclType, Title From TB_Master_SightSeeInclType where 1 = 1 AND IsActive='1'";
        $sql .= " ORDER BY Title ";

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

    public function getAllBookingTypeList()
    {
        $sql = "Select BookingType, Title From TB_Master_BookingType where 1 = 1 AND IsActive='1'";
        $sql .= " ORDER BY Title ";

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

    public function getAllDifficultyTypeList()
    {
        $sql = "Select DifficultyType, Title From TB_Master_DifficultyType where 1 = 1 AND IsActive='1'";
        $sql .= " ORDER BY Title ";

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

    public function getInclusionList($inclusions_id)
    {
        $sql = "select dbo.GetSightseeingInclype('" . $inclusions_id . "') as InclusionName ";

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

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


    public function updateSightseeingDetails($SSSysId, $insert)
    {
        $where = array('SSSysId = ? ' => $SSSysId);
        return $this->db->update('TB_IC_SightSeeing', $insert, $where);
    }


    public function getCountryList($strCountryName)
    {
        $sql = "Select ContId, Title From TB_Master_Geo_Country where 1 = 1 AND IsActive='1' AND Code!='0' ";

        if (!empty($strCountryName)) {
            $sql .= " AND Title LIKE '$strCountryName%' ";
        }

        $sql .= " ORDER BY Title";
        //echo $sql; die;

        $rowset = $this->db->query($sql)->fetchAll();

        if (count($rowset) >  0) {
            foreach ($rowset as $row) {

                $response[] = array('ContId' => $row['ContId'], 'value' => $row['Title'], 'label' => $row['Title']);
            }
        } else {
            $response[] = array('ContId' => 0);
        }
        return $response;
    }

    public function getCityList($strCityName, $strcountryId)
    {
        $sql = "Select CityId, Title From TB_Master_Geo_City where 1 = 1 AND IsActive='1' ";

        if (!empty($strCityName)) {
            $sql .= " AND Title LIKE '$strCityName%' ";
        }
        if (!empty($strcountryId)) {
            $sql .= " AND ContSysId ='" . $strcountryId . "' ";
        }
        $sql .= " ORDER BY Title";
        //echo $sql; die;

        $rowset = $this->db->query($sql)->fetchAll();

        if (count($rowset) >  0) {
            foreach ($rowset as $row) {

                $response[] = array('CityId' => $row['CityId'], 'value' => $row['Title'], 'label' => $row['Title']);
            }
        } else {
            $response[] = array('CityId' => 0);
        }
        return $response;
    }

    public function getSightseeingList($AgentSysId, $strSightseeingName, $strcountryId, $strCitySysId)
    {
        $sql = "Select SSSysId, Title,IsAgentSpec,ICSourceSysId,CitySysId From TB_IC_SightSeeing where 1 = 1 AND IsActive='1' AND IsMarkForDel = 0 ";

        if (!empty($AgentSysId)) {
            $sql .= " AND (IsApproved = '1' OR (ICSourceSysId = '$AgentSysId' AND IsAgentSpec = 1))  ";
        }
        if (!empty($strSightseeingName)) {
            $sql .= " AND Title LIKE '%$strSightseeingName%' ";
        }
        if (!empty($strcountryId)) {
            $sql .= " AND ContSysId IN (" . $strcountryId . ") ";
        }
        if (!empty($strCitySysId)) {
            $sql .= " AND CitySysId IN (" . $strCitySysId . ") ";
        }
        $sql .= " ORDER BY Title";
        //        echo $sql; die;

        $rowset = $this->db->query($sql)->fetchAll();

        if (count($rowset) >  0) {
            foreach ($rowset as $row) {
                $internal = (($row['ICSourceSysId'] == $AgentSysId) && $row['IsAgentSpec'] == 1) ? ' (Internal)' : '';
                $title = $row['Title'] . $internal;
                $response[] = array('SSSysId' => $row['SSSysId'], 'value' => $row['Title'], 'label' => $title, 'CitySysId' => $row['CitySysId']);
            }
        } else {
            $response[] = array('SSSysId' => 0, 'value' => 'Add New Activity', 'label' => 'Add New Sightseeing', 'CitySysId' => 0);
        }
        return $response;
    }

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


    public function getAllSightseeingInventoryList($intLoggedinUserAgencySysId, $city = NULL, $country = NULL)
    {
        $sql = " SELECT TOP 50 AdultEntryFee,ChildEntryFee,InvnItemSysId, XRef, AgencySysId, inclusions, FromDate, ToDate, PurchasedQty, PublishQty,CostCurrency, TB_Master_Currency.Symbol AS Currency, TB_IC_Supplier.SupplierName AS SupplierType, "
            . "tcs.Title, TB_Master_BookingType.Title AS BookingName, tmis.IsTransferInc, TotalCostNativeAdult, TotalCostNativeChild, TotalCostForeignerChild, TotalCostForeignerAdult, tmis.IsActive, tmis.IsSaleStart, tmis.DisplayOnB2C "
            . "FROM TB_MP_Inventory_SightSeeing [tmis] "
            . "JOIN TB_IC_SightSeeing [tcs] ON tmis.XRef=tcs.SSSysId "
            . "JOIN TB_Master_Currency ON tmis.CostCurrency=TB_Master_Currency.CurrencyType "
            . "JOIN TB_IC_Supplier ON tmis.SupplierSysId=TB_IC_Supplier.SupplierSysId "
            . "JOIN TB_Master_BookingType ON tmis.BookingType=TB_Master_BookingType.BookingType "
            . " WHERE IsMarkForDelete='0' ";

        if (!empty($intLoggedinUserAgencySysId)) {
            $sql .= " AND AgencySysId = '" . $intLoggedinUserAgencySysId . "' ";
        }
        if ($city > 0) {
            $sql .= " AND  tcs.CitySysId  = '" . $city . "' ";
        }
        if ($country > 0) {
            $sql .= " AND  tcs.ContSysId  = '" . $country . "' ";
        }
        $sql .= " ORDER BY tmis.InvnItemSysId DESC ";

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

    public function getAllSightseeingInventoryListBySSSId($SSSysId, $intLoggedinUserAgencySysId)
    {
        $sql = " SELECT TOP 50 InvnItemSysId, XRef, AgencySysId, inclusions, FromDate, ToDate, PurchasedQty, PublishQty,CostCurrency, TB_Master_Currency.Symbol AS Currency, TB_IC_Supplier.SupplierName AS SupplierType, "
            . "tcs.Title, TB_Master_BookingType.Title AS BookingName, tmis.IsTransferInc, TotalCostNativeAdult, TotalCostNativeChild, TotalCostForeignerChild, TotalCostForeignerAdult, tmis.IsActive, tmis.IsSaleStart,tmis.AdultEntryFee,tmis.ChildEntryFee,tmis.DisplayOnB2C "
            . "FROM TB_MP_Inventory_SightSeeing [tmis] "
            . "JOIN TB_IC_SightSeeing [tcs] ON tmis.XRef=tcs.SSSysId "
            . "JOIN TB_Master_Currency ON tmis.CostCurrency=TB_Master_Currency.CurrencyType "
            . "JOIN TB_IC_Supplier ON tmis.SupplierSysId=TB_IC_Supplier.SupplierSysId "
            . "JOIN TB_Master_BookingType ON tmis.BookingType=TB_Master_BookingType.BookingType "
            . " WHERE IsMarkForDelete='0' ";

        if (!empty($intLoggedinUserAgencySysId)) {
            $sql .= " AND AgencySysId = '" . $intLoggedinUserAgencySysId . "' ";
        }
        if (!empty($SSSysId)) {
            $sql .= " AND XRef = '" . $SSSysId . "' ";
        }
        $sql .= " ORDER BY tmis.InvnItemSysId DESC ";

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


    public function getSightseeingInventoryList($InvnItemSysId, $intLoggedinUserAgencySysId)
    {

        $sql = " SELECT InvnItemSysId, XRef, AgencySysId, FromDate, ToDate, PurchasedQty, PublishQty,CostCurrency, TB_Master_Currency.Symbol AS Currency, TB_IC_Supplier.SupplierName AS SupplierType, "
            . "tcs.Title,tcs.CitySysId, TB_Master_BookingType.Title AS BookingName, tmis.IsTransferInc, TotalCostNativeAdult, TotalCostNativeChild, TotalCostForeignerChild, TotalCostForeignerAdult, TrxCurrency, tmis.IsActive,TB_Master_Geo_City.Title as CityTitle ,tmis.DisplayOnB2C "
            . "FROM TB_MP_Inventory_SightSeeing [tmis] "
            . "JOIN TB_IC_SightSeeing [tcs] ON tmis.XRef=tcs.SSSysId "
            . "JOIN TB_Master_Currency ON tmis.CostCurrency=TB_Master_Currency.CurrencyType "
            . "JOIN TB_IC_Supplier ON tmis.SupplierSysId=TB_IC_Supplier.SupplierSysId "
            . "JOIN TB_Master_BookingType ON tmis.BookingType=TB_Master_BookingType.BookingType "
            . "LEFT JOIN TB_Master_Geo_City ON tcs.CitySysId=TB_Master_Geo_City.CityId"
            . " WHERE 1 = 1 AND IsMarkForDelete='0'  ";

        if (!empty($InvnItemSysId)) {
            $sql .= " AND InvnItemSysId = " . $InvnItemSysId;
        }
        if (!empty($intLoggedinUserAgencySysId)) {
            $sql .= " AND AgencySysId = '" . $intLoggedinUserAgencySysId . "' ";
        }

        $sql .= " ORDER BY tmis.InvnItemSysId DESC ";
        //echo $sql;exit;
        return $this->db->query($sql)->fetchAll();
    }


    public function getStandardMarkupsSightseeing($intAgencySysId)
    {

        $sql = " SELECT TB_MP_StdMarkup_SightSeeing.MPType AS MPType_id, TB_Master_MPType.Title as MPType, 
                CustGrSysId, Currency, TaxPer, MarkUpType, IsSameForAll, MarkUp, PerPaxMarkUp, MarkUpNativeAdult, MarkUpNativeChild, MarkUpForeignerAdult, MarkUpForeignerChild
                ,DiscountType, DiscountMsg, DiscountNativeAdult, DiscountNativeChild, DiscountForeignerAdult , DiscountForeignerChild, IsPublish, PublishDate, TB_MP_StdMarkup_SightSeeing.Details, RateRuleSysId, TCDocSysId, ValidTill,
                 CreateDate, UpdateDate, IsMarkForDel, IsActive
                 FROM TB_MP_StdMarkup_SightSeeing INNER JOIN TB_Master_MPType 
                 ON TB_MP_StdMarkup_SightSeeing.MPType = TB_Master_MPType.MPType
                 WHERE 1 = 1 AND ItemSourceType = '0' ";

        if (!empty($intAgencySysId)) {
            $sql .= " AND AgencySysId = " . $intAgencySysId;
        }

        //        if(!empty($cost_markup)) {
        //            $sql .= " AND MarkUpType = " . $cost_markup;
        //        }

        $sql .= " ORDER BY UpdateDate DESC ";

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


    public function getCustomizedMarkups($InvnItemSysId, $MPType = '', $CustGrSysId = '', $cost_markup)
    {

        $sql = " SELECT InvnItemSysId, TB_MP_Inventory_SightSeeing_Alloc.MPType AS MPType_id, TB_Master_MPType.Title as MPType, 
                CustGrSysId, AgencySysId, MaxQntToSale, MarkUpType, TaxPer, MarkUpNativeAdult, MarkUpNativeChild, MarkUpForeignerAdult, MarkUpForeignerChild
                ,DiscountType, DiscountMsg, DiscountNativeAdult, DiscountNativeChild, DiscountForeignerAdult , DiscountForeignerChild, NetPriceNativeAdult, 
                 NetPriceNativeChild, NetPriceForeignerAdult, NetPriceForeignerChild, IsPublish, PublishDate, TB_MP_Inventory_SightSeeing_Alloc.Details, RateRuleSysId, TCDocSysId, ValidTill,
                 CreateDate, UpdateDate, IsMarkForDel, IsActive
                 FROM TB_MP_Inventory_SightSeeing_Alloc INNER JOIN TB_Master_MPType 
                 ON TB_MP_Inventory_SightSeeing_Alloc.MPType = TB_Master_MPType.MPType
                 WHERE 1 = 1  ";

        if (!empty($MPType)) {
            $sql .= " AND TB_MP_Inventory_SightSeeing_Alloc.MPType = " . $MPType;
        }

        if (!empty($InvnItemSysId)) {
            $sql .= " AND InvnItemSysId = " . $InvnItemSysId;
        }

        if (!empty($CustGrSysId)) {
            $sql .= " AND AgencySysId = " . $CustGrSysId;
        }

        if (!empty($cost_markup)) {
            $sql .= " AND MarkUpType = " . $cost_markup;
        }
        $sql .= " AND TB_MP_Inventory_SightSeeing_Alloc.IsMarkForDel = '0'";
        $sql .= " ORDER BY InvnItemSysId, UpdateDate DESC ";

        //echo $sql; die;

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

    public function getSightseeingMarketPlacesByAgencySysId($InvnItemSysId, $intAgencySysId, $cost_markup)
    {
        $sql = "Select MPType From TB_MP_Inventory_SightSeeing_Alloc where 1 = 1";

        if (!empty($InvnItemSysId)) {
            $sql .= " AND InvnItemSysId = " . $InvnItemSysId;
        }

        if (!empty($intAgencySysId)) {
            $sql .= " AND AgencySysId = '" . $intAgencySysId . "' ";
        }
        if (!empty($cost_markup)) {
            $sql .= " AND MarkUpType = '" . $cost_markup . "' ";
        }

        $sql .= " ORDER BY MPType";

        $rowset = $this->db->query($sql)->fetchAll();
        if (count($rowset) >  0) {
            foreach ($rowset as $row) {
                $response[] = $row['MPType'];
            }
        } else {
            $response = array();
        }
        return array_values($response);
    }


    public function getStandardMarkupsPolicies($InvnItemSysId)
    {

        $sql = " SELECT InvnItemSysId, TCInfo, TCDocPath FROM TB_MP_Inventory_SightSeeing WHERE 1 = 1  ";
        if (!empty($InvnItemSysId)) {
            $sql .= " AND InvnItemSysId = " . $InvnItemSysId;
        }
        $sql .= " ORDER BY InvnItemSysId";
        //echo $sql; die;
        return $this->db->query($sql)->fetch();
    }


    public function addGroupSettings($data)
    {
        $this->db->insert('TB_MP_Inventory_SightSeeing_GrCost', $data);
        return $this->db->lastInsertId();
    }

    public function addSIghtseeingExtraServices($data)
    {
        $this->db->insert('TB_MP_Inventory_SightSeeing_ExtraServices', $data);
        return $this->db->lastInsertId();
    }
    public function getSightseeingGroupList($InvnItemSysId, $PaxCount = '')
    {

        $sql = " SELECT * FROM TB_MP_Inventory_SightSeeing_GrCost WHERE 1 = 1  ";

        if (!empty($InvnItemSysId)) {
            $sql .= " AND InvnItemSysId = " . $InvnItemSysId;
        }

        if (!empty($PaxCount)) {
            $sql .= " AND PaxCount = " . $PaxCount;
        }

        $sql .= " ORDER BY InvnItemSysId, UpdateDate DESC ";

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

     
    public function checkSightseeingGroupCost($InvnItemSysId)
    {
        $SightSeeingGrCost = array('TotalCostNativeAdult');
        $select = $this->db->select();
        $select->from(array('tbl' => "TB_MP_Inventory_SightSeeing_GrCost"), $SightSeeingGrCost);
        $select->where("tbl.InvnItemSysId = ?", $InvnItemSysId); 
        //echo $select; die;
        $result = $this->db->fetchRow($select);
        return $result;
    }
    public function deleteCustomizedGroupSetting($InvnItemSysId, $PaxVal)
    {
        $where = array('InvnItemSysId = ? ' => $InvnItemSysId, 'PaxCount = ? ' => $PaxVal);
        $this->db->delete('TB_MP_Inventory_SightSeeing_GrCost', $where);
    }

    public function addMarkupSettings($data)
    {
        $this->db->insert('TB_MP_Inventory_SightSeeing_Alloc', $data);
        return $this->db->lastInsertId();
    }

    public function updateIsItParentFlight($intLastInsertInwardId, $lastInvnItemSysId)
    {
        $where = array('InvnItemSysId = ? ' => $lastInvnItemSysId);
        $update = array('PairItemSysId' => $intLastInsertInwardId);
        $this->db->update('TB_MP_Inventory_Air', $update, $where);
    }

    public function deleteCustomizedMarkupSetting($InvnItemSysId, $MPType, $intLoggedinUserAgencySysId, $MarkUpType)
    {
        $where = array('InvnItemSysId = ? ' => $InvnItemSysId, 'MPType = ? ' => $MPType, 'AgencySysId = ? ' => $intLoggedinUserAgencySysId, 'MarkUpType = ? ' => $MarkUpType);
        $this->db->delete('TB_MP_Inventory_SightSeeing_Alloc', $where);
    }


    public function getCustomizedMarkupsPolicies($InvnItemSysId)
    {

        $sql = " SELECT InvnItemSysId, TCInfo, TCDocPath FROM TB_MP_Inventory_SightSeeing WHERE 1 = 1 ";

        if (!empty($InvnItemSysId)) {
            $sql .= " AND InvnItemSysId = " . $InvnItemSysId;
        }

        //echo $sql; die;
        return $this->db->query($sql)->fetch();
    }

    public function addMarkupPoliciesSettings($data)
    {
        $this->db->insert('TB_MP_Inventory_Air_Artifect', $data);
        return $this->db->lastInsertId();
    }


    public function editMarkupPoliciesSettings($update, $InvnItemSysId)
    {
        $where = array('InvnItemSysId = ? ' => $InvnItemSysId);
        $this->db->update('TB_MP_Inventory_SightSeeing', $update, $where);
    }


    public function getSightseeingInventoryDetailsList($InvnItemSysId, $intLoggedinUserAgencySysId)
    {

        $sql = " SELECT ChildEntryFee,AdultEntryFee,InvnItemSysId, XRef, tmis.AgencySysId, FromDate, ToDate, PurchasedQty, inclusions, PublishQty,CostCurrency, TB_Master_Currency.Symbol AS Currency, TB_IC_Supplier.SupplierName AS SupplierType, "
            . "tcs.Title, TB_Master_BookingType.Title AS BookingName, tmis.IsTransferInc, TotalCostNativeAdult, TotalCostNativeChild, TotalCostForeignerChild, TotalCostForeignerAdult, tmis.IsActive,tmis.DisplayOnB2C "
            . "FROM TB_MP_Inventory_SightSeeing [tmis] "
            . "JOIN TB_IC_SightSeeing [tcs] ON tmis.XRef=tcs.SSSysId "
            . "JOIN TB_Master_Currency ON tmis.CostCurrency=TB_Master_Currency.CurrencyType "
            . "JOIN TB_IC_Supplier ON tmis.SupplierSysId=TB_IC_Supplier.SupplierSysId "
            . "JOIN TB_Master_BookingType ON tmis.BookingType=TB_Master_BookingType.BookingType "
            . " WHERE 1 = 1 ";

        if (!empty($InvnItemSysId)) {
            $sql .= " AND InvnItemSysId = " . $InvnItemSysId;
        }
        if (!empty($intLoggedinUserAgencySysId)) {
            $sql .= " AND AgencySysId = '" . $intLoggedinUserAgencySysId . "' ";
        }

        $sql .= " ORDER BY tmis.InvnItemSysId DESC ";
        //echo $sql;exit;
        return $this->db->query($sql)->fetch();
    }


    public function getAllSightseeingInventoryMarkupList($InvnItemSysId, $intLoggedinUserAgencySysId)
    {

        $sql = " SELECT * FROM TB_MP_Inventory_SightSeeing_Alloc WHERE 1 = 1 ";

        if (!empty($InvnItemSysId)) {
            $sql .= " AND InvnItemSysId = " . $InvnItemSysId;
        }
        if (!empty($intLoggedinUserAgencySysId)) {
            $sql .= " AND AgencySysId = '" . $intLoggedinUserAgencySysId . "' ";
        }
        $sql .= " AND IsMarkForDel = '0'";
        //echo $sql;exit;
        return $this->db->query($sql)->fetchAll();
    }


    public function updateSightseeingInventoryDetails($update, $InvnItemSysId, $intLoggedinUserId)
    {
        $where = array('InvnItemSysId = ? ' => $InvnItemSysId, 'AgencySysId = ? ' => $intLoggedinUserId);
        $this->db->update('TB_MP_Inventory_SightSeeing', $update, $where);
    }

    public function updateSightseeingSaleInventory($InvnItemSysId, $actionValue, $intLoggedinUserId)
    {
        $update = array('IsSaleStart' => $actionValue);
        $where = array('InvnItemSysId = ? ' => $InvnItemSysId, 'AgencySysId = ? ' => $intLoggedinUserId);
        $this->db->update('TB_MP_Inventory_SightSeeing', $update, $where);
    }

    public function getCurrencyConversionPrice($agentBaseCurrency, $inventoryCurrency)
    {
        $sql = " SELECT * FROM TB_IC_CurrencyConversion WHERE 1=1 AND IsActive='1' ";

        if (!empty($agentBaseCurrency)) {
            $sql .= " AND FCurrencyType = " . $agentBaseCurrency;
        }
        if (!empty($inventoryCurrency)) {
            $sql .= " AND TCurrencyType = " . $inventoryCurrency;
        }

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


    public function getCurrencyConversionPaddingPrice($agentBaseCurrency)
    {
        $sql = " SELECT * FROM TB_System_CurrencyExcPadding WHERE 1=1 AND IsActive='1' ";

        if (!empty($agentBaseCurrency)) {
            $sql .= " AND CurrencyType = " . $agentBaseCurrency;
        }

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


    public function cloneMPInventorySightseeing($update, $InvnItemSysId)
    {

        $currentDate = date('Y-m-d H:i:s');

        $sql = " INSERT INTO TB_MP_Inventory_SightSeeing ( InventoryType
                ,XRef, AgencySysId, SupplierSysId, FromDate, ToDate, BookingType, inclusions
                ,IsTransferInc, IsPickDropInc, PurchasedQty, PublishQty, BlockQty
                ,SoldQty, ReturnQty, NetInHandQty, CostCurrency, TotalCostNativeAdult,TotalCostNativeChild
                ,TotalCostForeignerChild,TotalCostForeignerAdult,TrxCurrency,SaleAmtNativeChild
                ,SaleAmtNativeAdult,SaleAmtForeignerChild,SaleAmtForeignerAdult,Brief,IfAnyOffer
                ,OfferMsg,OfferImage,TCInfo,TCDocPath,IxFixedDateInven,CreatorSysId
                ,ApproveDate
                ,CreateDate
                ,UpdateDate
                ,IsActive
                ,IsMarkForDelete
                ,IsApproved) 
                
                SELECT InventoryType
                ,XRef, AgencySysId, SupplierSysId, '" . $update['FromDate'] . "', '" . $update['ToDate'] . "', BookingType, inclusions
                ,IsTransferInc, IsPickDropInc, PurchasedQty, PublishQty, BlockQty
                ,SoldQty, ReturnQty, NetInHandQty, CostCurrency, '" . $update['TotalCostNativeAdult'] . "','" . $update['TotalCostNativeChild'] . "'
                ,'" . $update['TotalCostForeignerChild'] . "','" . $update['TotalCostForeignerAdult'] . "',TrxCurrency,SaleAmtNativeChild
                ,SaleAmtNativeAdult,SaleAmtForeignerChild,SaleAmtForeignerAdult,Brief,IfAnyOffer
                ,OfferMsg,OfferImage,TCInfo,TCDocPath,IxFixedDateInven,CreatorSysId
                ,'" . $currentDate . "'
                ,'" . $currentDate . "'
                ,'" . $currentDate . "'
                ,'0'
                ,'0'
                ,'0' FROM TB_MP_Inventory_SightSeeing WHERE InvnItemSysId = " . $InvnItemSysId;

        $this->db->query($sql);
        return $this->db->lastInsertId('TB_MP_Inventory_SightSeeing');
    }

    public function getInventoryDetails($InvnItemSysId, $intLoggedinUserAgencySysId)
    {

        $sql = " SELECT InvnItemSysId, XRef, TB_IC_Supplier.SupplierName AS SupplierType, TB_Master_Geo_Country.Title AS CountryName, TB_Master_Geo_City.Title AS CityName, TB_IC_SightSeeing.Title AS SightseeingName, TB_IC_SightSeeing.DurationInMin, TB_IC_SightSeeing.DurationStr, TB_IC_SightSeeing.TimeSlots, TB_IC_SightSeeing.WriteUp AS details, TB_IC_SightSeeing.ThingsToCarry, TotalCostNativeAdult, TotalCostNativeChild, TotalCostForeignerChild, TotalCostForeignerAdult, "
            . "TB_Master_BookingType.Title AS BookingName, TB_Master_SightSeeingType.Title As SightseeingType, TB_Master_SightSeeingGroupType.Title AS SightseeingGroupType, TB_Master_DifficultyType.Title as DifficultyType, tmis.IsActive "
            . "FROM TB_MP_Inventory_SightSeeing [tmis] "
            . "JOIN TB_IC_SightSeeing ON tmis.XRef=TB_IC_SightSeeing.SSSysId "
            . "JOIN TB_IC_Supplier ON tmis.SupplierSysId=TB_IC_Supplier.SupplierSysId "
            . "JOIN TB_Master_Geo_Country ON TB_IC_SightSeeing.ContSysId=TB_Master_Geo_Country.ContId "
            . "JOIN TB_Master_Geo_City ON TB_IC_SightSeeing.CitySysId=TB_Master_Geo_City.CityId "
            . "JOIN TB_Master_BookingType ON tmis.BookingType=TB_Master_BookingType.BookingType "
            . "LEFT JOIN TB_Master_DifficultyType ON TB_IC_SightSeeing.DifficultyLevel=TB_Master_DifficultyType.DifficultyType "
            . "JOIN TB_Master_SightSeeingType ON TB_IC_SightSeeing.SSType=TB_Master_SightSeeingType.SSType "
            . "JOIN TB_Master_SightSeeingGroupType ON TB_IC_SightSeeing.SSGrType=TB_Master_SightSeeingGroupType.SSGroupType "
            . " WHERE 1=1 ";

        if (!empty($InvnItemSysId)) {
            $sql .= " AND InvnItemSysId = '" . $InvnItemSysId . "' ";
        }

        if (!empty($intLoggedinUserAgencySysId)) {
            $sql .= " AND AgencySysId = '" . $intLoggedinUserAgencySysId . "' ";
        }
        $sql .= " ORDER BY tmis.UpdateDate DESC ";

        //echo $sql;exit;
        return $this->db->query($sql)->fetch();
    }


    public function getSightseeingDetails($SSSysId, $intLoggedinUserId = NULL)
    {

        $sql = " SELECT TB_IC_SightSeeing.OtherInclusion,TB_IC_SightSeeing.Advisory,TB_IC_SightSeeing.RefundPolicy,TB_IC_SightSeeing.CancellationPolicy,TB_IC_SightSeeing.ConfirmationPolicy, SSSysId, TB_IC_SightSeeing.IsAgentSpec, TB_IC_SightSeeing.AgentSysId,TB_IC_SightSeeing.IsUnique, TB_IC_SightSeeing.ContSysId,TB_IC_SightSeeing.YoutubeURL, TB_IC_SightSeeing.CitySysId, PeakMothMask, PickUpLocation, PickUpTime, DaysWeekMask, WriteUp, TB_IC_SightSeeing.Icon, TimeSlots, TB_IC_SightSeeing.SSGrType, TB_IC_SightSeeing.SSType, DifficultyLevel, IsTransferInc, StartAgeYr, EndAgeYr, Popularity, ThingsToCarry, TB_Master_Geo_Country.Title AS CountryName, TB_Master_Geo_City.Title AS CityName, TB_IC_SightSeeing.Title AS SightseeingName, TB_IC_SightSeeing.DurationInMin, TB_IC_SightSeeing.DurationStr, TB_IC_SightSeeing.WriteUp AS details, TB_IC_SightSeeing.ThingsToCarry, "
            . " TB_Master_DifficultyType.Title as DifficultyType, TB_IC_SightSeeing.Address, TB_IC_SightSeeing.MinPax,TB_IC_SightSeeing.MaxPax,TB_IC_SightSeeing.TermCondition, TB_IC_SightSeeing.IsApproved, TB_IC_SightSeeing.IsTeenAllowed, TB_IC_SightSeeing.IsKidAllowed, TB_IC_SightSeeing.AwardRecognizations, TB_IC_SightSeeing.IsPetAllowed, TB_IC_SightSeeing.IsTrxAllowed, TB_IC_SightSeeing.IsPickAllowed, TB_IC_SightSeeing.BookingType,  "
            . " TB_IC_SightSeeing.latitude,TB_IC_SightSeeing.SightSeeingTypeName,TB_IC_SightSeeing.SightSeeingGrTypeName, TB_IC_SightSeeing.longitude, TB_IC_SightSeeing.PrimaryContact, TB_IC_SightSeeing.SecondaryContact, TB_IC_SightSeeing.OtherContacts, TB_IC_SightSeeing.StartLocalTime, TB_IC_SightSeeing.EndLocalTime,  TB_IC_SightSeeing.synonyms, TB_IC_SightSeeing.IsAdultAllowed, TB_IC_SightSeeing.IsActive, TB_IC_SightSeeing.IsMarkForDel "
            . " FROM TB_IC_SightSeeing "
            . "LEFT JOIN TB_Master_Geo_Country ON TB_IC_SightSeeing.ContSysId=TB_Master_Geo_Country.ContId "
            . "LEFT JOIN TB_Master_Geo_City ON TB_IC_SightSeeing.CitySysId=TB_Master_Geo_City.CityId "
            . "LEFT JOIN TB_Master_DifficultyType ON TB_IC_SightSeeing.DifficultyLevel=TB_Master_DifficultyType.DifficultyType "
            . " WHERE 1=1 ";

        if (!empty($SSSysId)) {
            $sql .= " AND SSSysId = '" . $SSSysId . "' ";
        }

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

        //echo $sql;exit;
        return $this->db->query($sql)->fetch();
    }

    public function deleteSightseeingInventory($InvnItemSysId, $intLoggedinUserAgencySysId)
    {
        $where = array('InvnItemSysId = ? ' => $InvnItemSysId, 'AgencySysId = ? ' => $intLoggedinUserAgencySysId);
        $updateData = array('IsMarkForDelete' => '1');
        $this->db->update('TB_MP_Inventory_SightSeeing', $updateData, $where);
    }


    public function setActiveDeactive($SSSysId, $statusValue)
    {
        $where = array('SSSysId = ? ' => base64_decode($SSSysId));
        $updateData = array('IsActive' => $statusValue);
        return $this->db->update('TB_IC_SightSeeing', $updateData, $where);
    }

    public function setActiveDeactiveInventory($InvnItemSysId, $intLoggedinUserAgencySysId, $statusValue)
    {
        $where = array('InvnItemSysId = ? ' => base64_decode($InvnItemSysId), 'AgencySysId = ? ' => $intLoggedinUserAgencySysId);
        $updateData = array('IsActive' => $statusValue);
        return $this->db->update('TB_MP_Inventory_SightSeeing', $updateData, $where);
    }

    public function getSuppliersList($cityId, $intLoggedinUserId)
    {

        $sql = " SELECT distinct(TB_IC_Supplier.SupplierSysId), TB_IC_Supplier.SupplierName FROM TB_IC_Supplier "
            . " RIGHT JOIN TB_MP_Inventory_SightSeeing ON TB_MP_Inventory_SightSeeing.SupplierSysId=TB_IC_Supplier.SupplierSysId WHERE 1 =1 AND TB_IC_Supplier.IsDelete='0' ";

        if (!empty($cityId)) {
            $sql .= " AND TB_IC_Supplier.CitySysId = " . $cityId;
        }

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

        $sql .= " AND TB_IC_Supplier.Services LIKE '_____1%' ";
        $sql .= " ORDER BY TB_IC_Supplier.SupplierName ";

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


    public function getSightseeingTypeListBySightseeingGroupId($SightseeingGrTypeId)
    {
        $sql = " SELECT SSType, Title FROM TB_Master_SightSeeingType "
            . "WHERE 1 =1 AND IsActive='1' ";

        if (!empty($SightseeingGrTypeId)) {
            $sql .= " AND SSGroupType = " . $SightseeingGrTypeId;
        }

        $sql .= " ORDER BY Title ";

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


    /*
     * setMasking. To create masking (need master data, result data and primary key of master table).
     * Created by Pooja on 3aug2016
     * @param  array $maskingArr
     * @param  array $masterListingArr
     * @param  int $primaryKey
     * @return int.
     */

    public function setMasking($maskingArr, $masterListingArr)
    {
        $mask = '1';

        if (count($masterListingArr) > 0) {
            foreach ($masterListingArr as $Key => $Val) {
                $char = in_array($Key, $maskingArr) ? '1' : '0';
                $mask .= $char;
            }
        }

        return $mask;
    }


    /*
     * getMasking(). To create masking (need master data, result data and primary key of master table).
     * Created by Pooja on 4aug2016
     * @param  string $varfromDb
     * @param  array $masterListingArr
     * @param  int $primaryKey
     * @return int.
     */
    public function getMasking($varfromDb, $masterListingArr)
    {
        $varfromDbArr = str_split(trim($varfromDb));
        $resultMask = array();
        $counter = 1;
        foreach ($masterListingArr as  $Key => $Val) {
            if (@$varfromDbArr[$counter] == 1) {
                $skey = $Key - 1;
                $resultMask[$skey] = $Key;
            }
            $counter++;
        }
        return $resultMask;
    }
    public function getMaskingName($varfromDb, $masterListingArr)
    {
        $varfromDbArr = str_split(trim($varfromDb));
        $resultMask = array();
        $counter = 1;
        foreach ($masterListingArr as  $Key => $Val) {
            if (@$varfromDbArr[$counter] == 1) {
                $skey = $Key - 1;
                $resultMask[$skey] = $Val;
            }
            $counter++;
        }
        return $resultMask;
    }


    /**
     * setApproveDisapprove. To set IsActive/IsDeactive record.
     * 
     * @param  string $whereCondition
     * @param  string $tableName
     * @param  int    $isActive
     * @return int
     */
    public function setApproveDisapprove($whereCondition, $tableName, $updateArr)
    {
        try {
            $isChanged = $this->db->update($tableName, $updateArr, $whereCondition);
        } catch (Exception $e) {
            die('There has been an error. ' . $e->getMessage());
        }
        return @$isChanged ? $isChanged : 0;
    }

    /**
     * setSaleStartStop. To set IsSaleStart record.
     * 
     * @param  string $whereCondition
     * @param  string $tableName
     * @param  int    $IsSaleStart
     * @return int
     */
    public function setSaleStartStop($whereCondition, $tableName, $IsSaleStart = 0)
    {
        try {
            $isChanged = $this->db->update($tableName, array('IsSaleStart' => $IsSaleStart), $whereCondition);
        } catch (Exception $e) {
            die('There has been an error. ' . $e->getMessage());
        }
        return @$isChanged ? $isChanged : 0;
    }


    public function addStdMarkupSightseeing($data = array())
    {
        try {
            $select = $this->db->select()
                ->from("TB_MP_StdMarkup_SightSeeing", array('count(*) AS totalRecords'))
                ->where("ItemSourceType =?", 0)
                ->where("AgencySysId =?", $data['AgencySysId'])
                ->where("MpType =?", $data['MPType']);
            $resultData = $this->db->fetchOne($select);
            //            echo $resultData; die;
            if ($resultData == 1) {
                $where['AgencySysId = ?'] = $data['AgencySysId'];
                $where['MpType = ?'] = $data['MPType'];
                return $this->db->update('TB_MP_StdMarkup_SightSeeing', $data, $where);
            } else {
                $this->db->insert('TB_MP_StdMarkup_SightSeeing', $data);
                return $this->db->lastInsertId('TB_MP_StdMarkup_SightSeeing');
            }
        } catch (Exception $e) {
            die('There has been an error. ' . $e->getMessage());
        }
    }

    public function getInventoryCityList($intLoggedinUserAgencySysId)
    {
        $sql = " SELECT distinct(tb3.CityId) AS CityId, tb3.Title FROM TB_MP_Inventory_SightSeeing AS tb1 "
            . "LEFT JOIN TB_IC_SightSeeing AS tb2 ON tb1.XRef = tb2.SSSysId "
            . "LEFT JOIN TB_Master_Geo_City AS tb3 ON tb2.CitySysId = tb3.CityId  WHERE 1 = 1 ";
        if (!empty($intLoggedinUserAgencySysId)) {
            $sql .= " AND tb1.AgencySysId = " . $intLoggedinUserAgencySysId;
        }
        $sql .= " AND tb3.IsMarkForDel = '0' AND tb3.Title!='0' AND tb1.IsMarkForDelete = '0' ";

        $sql .= " ORDER BY tb3.Title";
        //echo $sql; die;

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


    public function getSightseeingCityList($intLoggedinUserId)
    {
        $sql = " SELECT distinct(tb3.CityId) AS CityId, tb3.Title FROM TB_IC_SightSeeing AS tb2 "
            . "LEFT JOIN TB_Master_Geo_City AS tb3 ON tb2.CitySysId = tb3.CityId  WHERE 1 = 1 ";
        if (!empty($intLoggedinUserId)) {
            $sql .= " AND tb2.ICSourceSysId = " . $intLoggedinUserId;
        }
        $sql .= " AND tb3.IsMarkForDel = '0' AND tb3.Title!='0' ";

        $sql .= " ORDER BY tb3.Title";
        //echo $sql; die;

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

    public function getSightseeingCountryList($intLoggedinUserId)
    {
        $sql = " SELECT distinct(tb3.ContId) AS ContId, tb3.Title FROM TB_IC_SightSeeing AS tb2 "
            . "LEFT JOIN TB_Master_Geo_Country AS tb3 ON tb2.ContSysId = tb3.ContId  WHERE 1 = 1 ";
        if (!empty($intLoggedinUserId)) {
            $sql .= " AND tb2.ICSourceSysId = " . $intLoggedinUserId;
        }
        $sql .= " AND tb3.IsMarkForDel = '0' AND tb3.Title!='0' ";

        $sql .= " ORDER BY tb3.Title";
        //echo $sql; die;

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


    public function getAgencyMarkupSettingDetails($intLoggedinUserAgencySysId, $maketPlaceId)
    {
        $agencyMarkup = array('AgencySysId', 'MPType', 'Currency', 'MarkUpType', 'IsSameForAll', 'MarkUp', 'MarkUpNativeAdult', 'MarkUpNativeChild', 'MarkUpForeignerAdult', 'MarkUpForeignerChild', 'TaxPer', 'IsActive');
        $select = $this->db->select();
        $select->from(array('tbl' => "TB_MP_StdMarkup_SightSeeing"), $agencyMarkup);
        $select->where("tbl.ItemSourceType = ?", 0);
        $select->where("tbl.AgencySysId = ?", $intLoggedinUserAgencySysId);
        $select->where("tbl.MPType = ?", $maketPlaceId);
        //echo $select; die;
        $result = $this->db->fetchRow($select);
        return $result;
    }



    // Added By Pardeep Panchal

    public function displayOnB2C($ActivitySysId, $statusValue)
    {
        $where = array('InvnItemSysId = ? ' => base64_decode($ActivitySysId));
        $updateData = array('DisplayOnB2C' => $statusValue);
        return $this->db->update('TB_MP_Inventory_SightSeeing', $updateData, $where);
    }

    public function GetRateExist($InvnItemSysId)
    {
        $select = $this->db->select();
        $selectarray = array('InvnItemSysId', 'XRef', 'DisplayOnB2C');
        $select->from(array('tb1' => "TB_MP_Inventory_SightSeeing"), $selectarray);
        $select->where("tb1.InvnItemSysId =?", $InvnItemSysId);
        $select->where("tb1.IsMarkForDelete =?", 0);
        $result = $this->db->fetchRow($select);
        return $result;
    }

    public function getSSTypeName($SSType)
    {
        $select = $this->db->select();
        $select->from(array('tbl' => "TB_Master_SightSeeingType"), array('Title'));
        $select->where("tbl.SSType = ?", $SSType);
        $result = $this->db->fetchRow($select);
        return $result['Title'];
    }
    public function getSSGroupTypeName($SSGroupType)
    {
        $select = $this->db->select();
        $select->from(array('tbl' => "TB_Master_SightSeeingGroupType"), array('Title'));
        $select->where("tbl.SSGroupType = ?", $SSGroupType);
        $result = $this->db->fetchRow($select);
        return $result['Title'];
    }
    public function getSightseeingListWithPrice($cityId, $agencySysId = null, $strSightseeingName, $desinationCovered = NULL, $fromDate = NULL, $DestinationWise = 0)
    {
        //$sql = "Select SSSysId, Title,IsAgentSpec,ICSourceSysId,CitySysId From TB_IC_SightSeeing where 1 = 1 AND IsActive='1' AND IsMarkForDel = 0 ";

        $cond = " ";
        $condName = !empty($strSightseeingName) ? "  AND a.Title LIKE '%$strSightseeingName%'  " : "";
        $condDate = ($fromDate) ? " AND  c.FromDate <= '$fromDate' AND c.ToDate >= '$fromDate'" : "";
        $condCity = !empty($desinationCovered) ? " OR CitySysId IN ($desinationCovered) " : '';
        $sqlPackage = "SELECT SSSysId,a.Title,ICSourceSysId,IsAgentSpec,CitySysId,b.Title as CityName,Country,c.TotalCostNativeAdult,c.FromDate,c.ToDate,c.InvnItemSysId FROM TB_IC_SightSeeing a 
            left JOIN TB_Master_Geo_City b ON a.CitySysId = b.CityId left JOIN TB_MP_Inventory_SightSeeing c ON a.SSSysId = c.XRef AND c.AgencySysId = $agencySysId
                 WHERE (a.CitySysId = '" . $cityId . "' $condCity) AND a.IsMarkForDel = '0' AND a.IsActive = '1' AND c.IsMarkForDelete = '0' AND c.IsActive = '1' AND c.IsSaleStart = '1' $condName $cond $condDate  
                     Order By CASE WHEN a.CitySysId = '" . $cityId . "' THEN 1 ELSE 2 END ASC,  a.Title ASC";
        //$sqlPackage = "SELECT a.Title,b.Title as CityName,Country FROM TB_IC_SightSeeing a left JOIN TB_Master_Geo_City b ON a.CitySysId = b.CityId WHERE a.IsMarkForDel = '0' AND a.IsActive = '1'";
        //    	echo $sqlPackage; die;
        $rowset = $this->db->query($sqlPackage)->fetchAll();
//        echo "<pre>";print_r($rowset);die;
        if (count($rowset) >  0) {
            foreach ($rowset as $row) {
                $title = $row['Title'];
                if($DestinationWise == 1){
                    $response[$row['CitySysId']][] = array('SSSysId' => $row['SSSysId'], 'value' => $row['Title'], 'label' => $title, 'CitySysId' => $row['CitySysId'], 'InvnItemSysId' => $row['InvnItemSysId'], 'toDate' => $row['ToDate'], 'fromDate' => $row['FromDate']);
                }else{
                    $response[] = array('SSSysId' => $row['SSSysId'], 'value' => $row['Title'], 'label' => $title, 'CitySysId' => $row['CitySysId'], 'InvnItemSysId' => $row['InvnItemSysId'], 'toDate' => $row['ToDate'], 'fromDate' => $row['FromDate']);
                }
                
            }
        } else {
            $response[] = array('SSSysId' => 0, 'value' => 'Add New Activity', 'label' => 'Add New Sightseeing', 'CitySysId' => 0);
        }
        return $response;
    }

    public function getAllSightseeingListWithPrice($cityId, $agencySysId = null, $strSightseeingName = null, $desinationCovered = NULL, $fromDate = NULL)
    {
        //$sql = "Select SSSysId, Title,IsAgentSpec,ICSourceSysId,CitySysId From TB_IC_SightSeeing where 1 = 1 AND IsActive='1' AND IsMarkForDel = 0 ";

        $cond = " AND a.ICSourceSysId = '$agencySysId' ";
        if (!empty($strSightseeingName) && $strSightseeingName != null) {
            $condName = "  AND a.Title LIKE '%$strSightseeingName%'  ";
        }

        $condDate = ($fromDate) ? " AND  c.FromDate <= '$fromDate' AND c.ToDate >= '$fromDate'" : "";
        $condCity = !empty($desinationCovered) ? " OR CitySysId IN ($desinationCovered) " : '';
        $sqlPackage = "SELECT SSSysId,a.Title,ICSourceSysId,IsAgentSpec,CitySysId,b.Title as CityName,Country,c.TotalCostNativeAdult,FromDate,ToDate FROM TB_IC_SightSeeing a 
            left JOIN TB_Master_Geo_City b ON a.CitySysId = b.CityId left JOIN TB_MP_Inventory_SightSeeing c ON a.SSSysId = c.XRef 
                 WHERE (a.CitySysId = '" . $cityId . "' $condCity) AND a.IsMarkForDel = '0' AND a.IsActive = '1' $condName $cond $condDate AND c.TotalCostNativeAdult > '0' 
                     Order By CASE WHEN a.CitySysId = '" . $cityId . "' THEN 1 ELSE 2 END ASC,  a.Title ASC";
        //$sqlPackage = "SELECT a.Title,b.Title as CityName,Country FROM TB_IC_SightSeeing a left JOIN TB_Master_Geo_City b ON a.CitySysId = b.CityId WHERE a.IsMarkForDel = '0' AND a.IsActive = '1'";
        //    	echo $sqlPackage; die;
        $rowset = $this->db->query($sqlPackage)->fetchAll();

        if (count($rowset) >  0) {
            foreach ($rowset as $row) {
                $title = $row['Title'];
                $response[] = array('SSSysId' => $row['SSSysId'], 'value' => $row['Title'], 'label' => $title, 'CitySysId' => $row['CitySysId']);
            }
        } else {
            $response[] = array('SSSysId' => 0, 'value' => 'Add New Activity', 'label' => 'Add New Sightseeing', 'CitySysId' => 0);
        }
        return $response;
    }
    public function updateSightseeingSICDetails($insert, $where)
    {
        return $this->db->update('TB_MP_Inventory_SightSeeing_Alloc', $insert, $where);
    }
    public function checkVarientName($variantName)
    {
        $select = $this->db->select();
        $select->from(array('tbl' => "TB_IC_SightSeeing_Variant"), array('VarSysId'));
        $select->where("tbl.VariantName = ?", trim($variantName));
        $select->where("tbl.IsActive = ?", 1);
        $select->where("tbl.IsMarkForDel = ?", 0);
        $result = $this->db->fetchRow($select);
        return $result['VarSysId'];
    }
	    public function getSightseeingVariant($SSSysId)
    {
        $select = $this->db->select();
        $select->from(array('tbl' => "TB_IC_SightSeeing_Variant_Mapping"), array('*'));
		$select->joinLeft(array('tb2' => "TB_IC_SightSeeing_Variant"), "tbl.VSysId = tb2.VarSysId", array("VarSysId","VariantName"));
        $select->where("tbl.SSysId = ?", trim($SSSysId));
        $select->where("tbl.IsActive = ?", 1);
        $select->where("tbl.IsMarkForDel = ?", 0);
		//echo $select;die;
        $result = $this->db->fetchAll($select);
        return $result;
    }
    public function getSightseeingVehiclesIncluded($id,$RouteVechSysId = 0){
        
        $arrRouteVehicles = array('RouteVechSysId','VehicleSysId','VehicleTypeSysId','Cost', 'ChildCost', 'ChildAge','Capacity','CurrencyType','vehicleCostType','vehicleKM','vehiclePerKMCost','vehicleDriverPerDayCost','vehicleDriverPerNightCost','vehicleTollTax','vehicleOtherCost','SupplierSysId','SSInvnItemSysId','MarkupType','Markup','TotalCost');
        
        $select = $this->db->select();
        $select->from(array('tb1' => "TB_Agency_Transport_Route_Vehicle") ,$arrRouteVehicles);
        $select->joinLeft(array('tb2' => "TB_IC_Supplier"),"tb2.SupplierSysId = tb1.SupplierSysId",array('SupplierName'));
        $select->joinLeft(array('tb3' => "TB_Master_Vehicle"),"tb3.VehSysId = tb1.VehicleSysId",array('VehName','IsAC'));
        $select->joinLeft(array('tb4' => "TB_Master_VehicleType"),"tb4.VehicleTypeSysId = tb1.VehicleTypeSysId",array('Title as VehicleTypeName'));
        $select->joinLeft(array('tb5' => "TB_Master_Currency"),"tb5.CurrencyType = tb1.CurrencyType",array('Symbol as CurrencySymbol'));
        $select->joinLeft(array('tb6' => "TB_Agency_Area_Master"),"tb6.AreaSysId = tb1.PickupAreaId",array('AreaSysId','Area','CityId','CityName'));
        $select->joinLeft(array('tb7' => "TB_MP_Inventory_SightSeeing"),"tb7.InvnItemSysId = tb1.SSInvnItemSysId",array('AdultEntryFee','ChildEntryFee'));
        $select->where("tb1.SSInvnItemSysId = ?", $id );
        if($RouteVechSysId>0){
            $select->where("tb1.RouteVechSysId = ?", $RouteVechSysId );
        }
        $select->where("tb1.IsActive = ?", 1 );
        $select->where("tb1.IsMarkForDel = ?", 0 );
        $select->order("tb1.RouteVechSysId ASC ");
        $result = $this->db->fetchAll($select);
        return $result;    
    }
    public function checkSightseeingVehiclesIncluded($id,$RouteVechSysId = 0){
        
        $arrRouteVehicles = array('RouteVechSysId');
        
        $select = $this->db->select();
        $select->from(array('tb1' => "TB_Agency_Transport_Route_Vehicle") ,$arrRouteVehicles);
        $select->where("tb1.SSInvnItemSysId = ?", $id );
        if($RouteVechSysId>0){
            $select->where("tb1.RouteVechSysId = ?", $RouteVechSysId );
        }
        $select->where("tb1.IsActive = ?", 1 );
        $select->where("tb1.IsMarkForDel = ?", 0 );
        $select->order("tb1.RouteVechSysId ASC ");
        $result = $this->db->fetchRow($select);
        return $result;    
    }
    public function checkSightseeingPriceType($SSId,$AgencySysId){
        $select = $this->db->select();
            $select->from(array('tb1' => "TB_MP_Inventory_SightSeeing") ,array('AdultEntryFee'));
        $select->joinLeft(array('tb2' => "TB_MP_Inventory_SightSeeing_Alloc"),"tb2.InvnItemSysId = tb1.InvnItemSysId AND tb2.IsMarkForDel = '0' AND tb2.IsActive = 1 AND IsSaleStart = 1",array('NetPriceNativeAdult'));
        $select->joinLeft(array('tb3' => "TB_MP_Inventory_SightSeeing_GrCost"),"tb3.InvnItemSysId = tb1.InvnItemSysId AND tb3.IsMarkForDelete = '0' AND tb3.IsActive = 1",array('TotalCostNativeAdult'));
        $select->joinLeft(array('tb4' => "TB_Agency_Transport_Route_Vehicle"),"tb4.SSInvnItemSysId = tb1.InvnItemSysId AND tb4.IsMarkForDel = '0' AND tb4.IsActive = 1",array('RouteVechSysId'));
        $select->where("tb1.XRef = ?", $SSId);
        $select->where("tb1.AgencySysId = ?", $AgencySysId);
        $select->where("tb1.IsMarkForDelete = ?", 0);
        $select->where("tb1.IsSaleStart = ?", 1);
        $select->where("tb1.IsActive = ?", 1);
//        echo $select;die;
        $result = $this->db->fetchRow($select);
        return $result; 
    }
    public function checkAndUpdateIsRateAvailable($AgencySysId,$SSSysId){
        $select = $this->db->select();
        $select->from(array('tb11' => "TB_IC_SightSeeing") ,array('Title'));
        $select->joinLeft(array('tb1' => "TB_MP_Inventory_SightSeeing"),"tb11.SSSysId = tb1.XRef AND tb1.IsMarkForDelete = '0' AND AgencySysId = $AgencySysId",array('AdultEntryFee','XRef'));
        $select->joinLeft(array('tb2' => "TB_MP_Inventory_SightSeeing_Alloc"),"tb2.InvnItemSysId = tb1.InvnItemSysId AND tb2.IsMarkForDel = '0' AND tb2.IsActive = 1",array('NetPriceNativeAdult'));
        $select->joinLeft(array('tb3' => "TB_MP_Inventory_SightSeeing_GrCost"),"tb3.InvnItemSysId = tb1.InvnItemSysId AND tb3.IsMarkForDelete = '0' AND tb3.IsActive = 1",array('TotalCostNativeAdult'));
        $select->joinLeft(array('tb4' => "TB_Agency_Transport_Route_Vehicle"),"tb4.SSInvnItemSysId = tb1.InvnItemSysId AND tb4.IsMarkForDel = '0' AND tb4.IsActive = 1",array('RouteVechSysId'));
        $select->where("tb11.SSSysId = ?", $SSSysId);
//        $select->where("tb11.ICSourceSysId = ?", $AgencySysId);
//        $select->where("tb1.AgencySysId = ?", $AgencySysId);
        $select->where("tb11.IsMarkForDel = ?", 0); 
        $select->where("tb11.IsActive = ?", 1);
//        echo $select;die;
        $result = $this->db->fetchRow($select);
        $IsRate = 0;
        if(!empty($result)){
            $AdultEntryFee =  isset($result['AdultEntryFee']) ? (float)$result['AdultEntryFee'] : 0;
            $NetPriceNativeAdult =  isset($result['NetPriceNativeAdult']) ? (float)$result['NetPriceNativeAdult'] : 0;
            $TotalCostNativeAdult =  isset($result['TotalCostNativeAdult']) ? (float)$result['TotalCostNativeAdult'] : 0;
            $RouteVechSysId =  isset($result['RouteVechSysId']) ? (int)$result['RouteVechSysId'] : 0;
            $IsRate = 0;
            if((int)($AdultEntryFee + $NetPriceNativeAdult + $TotalCostNativeAdult + $RouteVechSysId) > 0){
                $IsRate = 1; 
            }
            $update = array(
                'IsRate' => $IsRate
            );
            $this->updateSightseeingDetails($SSSysId, $update); 
        }
        
        return $IsRate;
    }
    public function GetSightseeingRateListExist($SSSysId)
    {
        $select = $this->db->select();
        $selectarray = array('InvnItemSysId', 'XRef', 'DisplayOnB2C');
        $select->from(array('tb1' => "TB_MP_Inventory_SightSeeing"), $selectarray);
        $select->where("tb1.XRef =?", $SSSysId);
        $select->where("tb1.IsMarkForDelete =?", 0);
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function getMiscItemListWithPrice($AgencySysId)
    {
        $select = $this->db->select();
        $select->from(array('tb1' => "Tb_Ic_Misc_Items"));
        $select->where("tb1.ICSourceSysId =?", $AgencySysId);
        $select->where("tb1.IsMarkForDel =?", 0);
        $select->where("tb1.IsActive =?", 1);
        $result = $this->db->fetchAll($select);
        return $result;
    }
    public function getSightseeingOtherServices($id){
        
        $select = $this->db->select();
        $select->from(array('tb1' => "TB_MP_Inventory_SightSeeing_ExtraServices") ,array('InvnItemSysId','ExtraServiceSysId','Title','PriceType','TotalCost'));
        $select->joinLeft(array('tb2' => "TB_IC_Supplier"),"tb2.SupplierSysId = tb1.SupplierSysId",array('SupplierName'));
        $select->joinLeft(array('tb3' => "TB_Master_Currency"),"tb3.CurrencyType = tb1.CostCurrency",array('Symbol as CurrencySymbol'));
        $select->where("tb1.InvnItemSysId = ?", $id );
        $select->where("tb1.IsActive = ?", 1 );
        $select->where("tb1.IsMarkForDel = ?", 0 );
        $select->order("tb1.ExtraServiceSysId ASC ");
        $result = $this->db->fetchAll($select);
        return $result;    
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit