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

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/b2bzend/application/modules/webservice/controllers/AgencyController.php
<?php

class Webservice_AgencyController extends Catabatic_ValidateCustomer
{

    public function init()
    {
        $this->_agencycustomerObj = new Travel_Model_CRM_AgencyCustomer();
        $this->_crmcustomerObj = new Travel_Model_CRM_Customer();
        $this->_crmagencyleadaccountObj = new Travel_Model_CRM_AgencyLeadAccount();
        $this->_customermemberObj = new Travel_Model_CRM_CustomerMember();
        $this->_leadstageObj = new Travel_Model_TblLeadStage();
        $this->getEncrytInputKey = Catabatic_Helper::getEncrytInputKey();
        $this->getEncrytBlockKey = Catabatic_Helper::getEncrytBlockKey();
        $this->getEncrytIV = Catabatic_Helper::getEncrytIV();
        $this->_HtmlPurifier = new Zend_Filter_HtmlPurifier();
        $this->_crmcusttravelplan = new Travel_Model_CRM_CustomerTravelPlan();
        $this->SMSURL = Catabatic_Helper::getSMSURL();
        $this->SMSMETHOD = Catabatic_Helper::getSMSMETHOD();
        $this->SMSAPIKEY = Catabatic_Helper::getSMSAPIKEY();
        $this->SMSSENDER = Catabatic_Helper::getSMSSENDER();
        $this->SMSFORMAT = Catabatic_Helper::getSMSFORMAT();
    }

    public function getIvKeyAction()
    {
        if ($this->getRequest()->isPost()) {
            $AgencySysId = (int) $this->getRequest()->getPost("AgencySysId");
            $SecurityKey = $this->getRequest()->getPost("SecurityKey");
            $model = new Webservice_Model_Master();
            $getIVkey = $model->getIVKey($AgencySysId, $SecurityKey);
            if (!empty($getIVkey)) {
                $getIVkeyVal = isset($getIVkey[0]['IVKEY']) ? $getIVkey[0]['IVKEY'] : '';
                if ($getIVkeyVal != '') {
                    $resultSet["status"] = true;
                    $resultSet["Message"] = $getIVkeyVal;
                } else {
                    $resultSet["status"] = false;
                    $resultSet["Message"] = "Please contact to IT Team";
                }
            } else {
                $resultSet["status"] = false;
                $resultSet["Message"] = "Please contact to IT Team";
            }
        } else {
            $resultSet["status"] = false;
            $resultSet["Message"] = "Please use post Method";
        }
        $jsonData = json_encode($resultSet);
        echo $jsonData;
        exit;
    }

    public function getAgencyTermAndCondtionsAction()
    {
        if ($this->getRequest()->isPost()) {
            $AgencySysId = (int) $this->getRequest()->getParam("AgencySysId");
            $model = new Webservice_Model_Master();
            $getIVkey = $model->getSecurityKeyAndIVKey($AgencySysId);
            if (!empty($getIVkey)) {
                $getTermAndCondtion = $model->getTermAndCondition($AgencySysId);
                $getIVkeyVal = isset($getIVkey[0]['IVKEY']) ? $getIVkey[0]['IVKEY'] : '';
                $getSecurityKey = isset($getIVkey[0]['SecurityKey']) ? $getIVkey[0]['SecurityKey'] : '';
                $aes = new Travel_Model_Encrytion(json_encode($getTermAndCondtion[0]), $getSecurityKey, $getIVkeyVal);
                $resultSet["status"] = true;
                $resultSet["Message"] = $aes->encrypt();
            } else {
                $resultSet["status"] = false;
                $resultSet["Message"] = "Please contact to IT Team";
            }
        } else {
            $resultSet["status"] = false;
            $resultSet["Message"] = "Please use post Method";
        }
        $jsonData = json_encode($resultSet);
        echo $jsonData;
        exit;
    }

    public function getAgencyDataAction()
    {
        if ($this->getRequest()->isPost()) {
            $AgencySysId = (int) $this->getRequest()->getParam("AgencySysId");
            $model = new Webservice_Model_Master();
            $getIVkey = $model->getSecurityKeyAndIVKey($AgencySysId);
            if (!empty($getIVkey)) {
                $getTermAndCondtion = $model->getAgencyData($AgencySysId);
                $getIVkeyVal = isset($getIVkey[0]['IVKEY']) ? $getIVkey[0]['IVKEY'] : '';
                $getSecurityKey = isset($getIVkey[0]['SecurityKey']) ? $getIVkey[0]['SecurityKey'] : '';
                $aes = new Travel_Model_Encrytion(json_encode($getTermAndCondtion[0]), $getSecurityKey, $getIVkeyVal);
                $resultSet["status"] = true;
                $resultSet["Message"] = $aes->encrypt();
            } else {
                $resultSet["status"] = false;
                $resultSet["Message"] = "Please contact to IT Team";
            }
        } else {
            $resultSet["status"] = false;
            $resultSet["Message"] = "Please use post Method";
        }
        $jsonData = json_encode($resultSet);
        echo $jsonData;
        exit;
    }

    public function createCustomerAction()
    {
    }

    public function addCustomerAction()
    {
        if ($this->getRequest()->isPost()) {
            $AgencySysId = (int) $this->getRequest()->getParam("AgencySysId");
            $Salutation = (int) $this->getRequest()->getParam("Salutation");
            $EmailId = $this->getRequest()->getParam("EmailId");
            $FirstName = $this->getRequest()->getParam("FirstName");
            $LastName = $this->getRequest()->getParam("LastName");
            $CountryCode = $this->getRequest()->getParam("CountryCode");
            $MobileNo = $this->getRequest()->getParam("MobileNo");
            $memberDetailArray = $this->getRequest()->getParam("memberDetailArray") ? json_decode($this->getRequest()->getParam("memberDetailArray"), 1) : array();

            $updatedate = date("Y-m-d H:i:s");
            if (isset($EmailId) && !empty($EmailId)) {
                try {
                    $customerDetailsEmail = $this->_crmcustomerObj->ChkEmailWithResponseUpdate($EmailId, $AgencySysId);
                    $CustomerSysId = $customerDetailsEmail['CustomerSysId'] ? $customerDetailsEmail['CustomerSysId'] : '';
                    if (empty($customerDetailsEmail)) {
                        $userArray = array(
                            'EmailId' => $EmailId,
                            'Salutation' => $Salutation,
                            'PrimaryContactNumber' => '',
                            'FullName' => $FirstName . ' ' . $LastName,
                            'FirstName' => $FirstName,
                            'LastName' => $LastName ? $LastName : '',
                            'ActiveDate' => $updatedate,
                            'UpdatedDate' => $updatedate,
                            'CreatedDate' => $updatedate,
                            'IsApproved' => '1',
                            'IsActive' => '1',
                            'IsMarkForDelete' => '0'
                        );
                        $CRMCustSysId = $this->_crmcustomerObj->addCustomer($userArray);
                        $userLeadArray = array(
                            'AgencySysId' => $AgencySysId,
                            'EmailId' => $EmailId,
                            'Salutation' => (isset($Salutation) && !empty($Salutation)) ? $Salutation : 0,
                            'PrimaryContactNumber' => $MobileNo,
                            'countrycode' => ($CountryCode) ? trim($CountryCode) : '91',
                            'FullName' => $FirstName . ' ' . $LastName,
                            'FirstName' => trim($FirstName),
                            'LastName' => trim($LastName),
                            'ActiveDate' => $updatedate,
                            'UpdatedDate' => $updatedate,
                            'CreatedDate' => $updatedate,
                            'IsApproved' => '1',
                            'IsActive' => '1',
                            'IsMarkForDelete' => '0',
                            'CampaignSysId' => 0
                        );
                        //for create new customer
                        //echo '<pre>';print_r($userLeadArray);die('www');
                        $AgencyCRMLeadSysId = $this->_crmagencyleadaccountObj->addCustomer($userLeadArray);
                        $agencyuserArray = array(
                            'AgencySysId' => $AgencySysId,
                            'AgencyCRMLeadSysId' => $AgencyCRMLeadSysId,
                            'CRMCustSysId' => $CRMCustSysId,
                            'EmailId' => $EmailId,
                            'Title' => $Salutation ? $Salutation : 0,
                            'Logo' => '',
                            'IsfromSM' => '0',
                            'UserId' => '0',
                            'CitySysId' => '',
                            'StateOrZoneSysId' => 0,
                            'CountrySysId' => '',
                            'IsEmployee' => '0',
                            'Contacts' => $MobileNo ? $MobileNo : '',
                            'JoinDate' => $updatedate,
                            'UserName' => $FirstName . '' . $LastName,
                            'FirstName' => $FirstName ? $FirstName : '',
                            'LastName' => $LastName ? $LastName : '',
                            'Relation' => '',
                            'PassportNo' => '',
                            'PassportExpiry' => '',
                            'DOB' => '',
                            'MarriageAnniversary' => '',
                            'CreatedByUserSysId' => '',
                            'RegisterDate' => $updatedate,
                            'UpdateDate' => $updatedate,
                            'countrycode' => $CountryCode,
                            'IsApproved' => '0',
                            'IsActive' => '1',
                            'IsMarkForDelete' => '0'
                        );
                        $CustomerSysId = $this->_agencycustomerObj->addAgencyCustomer($agencyuserArray);

                        $resultSet["status"] = true;
                        $resultSet["Message"] = $CustomerSysId;
                    } else {
                        if ($CustomerSysId > 0) {
                            $updateArray = array(
                                'FirstName' => $FirstName ? $FirstName : '',
                                'LastName' => $LastName ? $LastName : '',
                                'Title' => $Salutation ? $Salutation : 0,
                                'Contacts' => $MobileNo ? $MobileNo : '',
                                'countrycode' => $CountryCode,

                            );
                            $whare = array("CustomerSysId = ?" => $CustomerSysId, "AgencySysId = ?" => $AgencySysId);
                            $this->_agencycustomerObj->UpdateAgencyCustomer($updateArray, $whare);
                        }
                        $resultSet["status"] = true;
                        $resultSet["Message"] = $CustomerSysId;
                    }
                    //                      echo "<pre>";print_r($memberDetailArray);die;
                    if ($CustomerSysId) {
                        $ipadd = $_SERVER['REMOTE_ADDR'];
                        $curr_date = date('Y-m-d');
                        if (!empty($memberDetailArray)) {
                            foreach ($memberDetailArray as $mKey => $mVal) {

                                $FirstName = isset($mVal['FirstName']) ? trim($mVal['FirstName']) : '';
                                $LastName = isset($mVal['LastName']) ? trim($mVal['LastName']) : '';
                                $Relation = isset($mVal['Relation']) ? trim($mVal['Relation']) : 9;
                                $UserName = trim($FirstName . ' ' . $LastName);
                                $data = array(
                                    'AgencySysId' => $AgencySysId,
                                    'CustomerSysId' => $CustomerSysId,
                                    'EmailId' => isset($mVal['EmailId']) ? trim($mVal['EmailId']) : '',
                                    'Contacts' => isset($mVal['MobileNo']) ? trim($mVal['MobileNo']) : '',
                                    'UserName' => $UserName,
                                    'FirstName' => $FirstName,
                                    'LastName' => $LastName,
                                    'Relation' => isset($mVal['Relation']) ? trim($mVal['Relation']) : 9,
                                    'IsMarkForDelete' => 0,
                                    'Title' => isset($mVal['Salutation']) ? trim($mVal['Salutation']) : '',
                                    'Logo' => '',
                                    'IsfromSM' => 0,
                                    'SMTypeId' => 0,
                                    'SMId' => '',
                                    'UserId' => '',
                                    'IsEmployee' => 0,
                                    'JoinDate' => $curr_date,
                                    'ExitDate' => '1900-01-01',
                                    'Designation' => '',
                                    'Password' => '',
                                    'RandStr' => '',
                                    'PasswordExpiryDate' => $curr_date,
                                    'IsPswExpire' => 0,
                                    'OtherEmail' => '',
                                    'SecondaryEmail' => '',
                                    'LastLoginTime' => '1900-01-01',
                                    'IsLogInNow' => 0,
                                    'CreatedByUserSysId' => $AgencySysId,
                                    'RandomCode' => '',
                                    'Gender' => '',
                                    'UserNickName' => $FirstName,
                                    'UserPicPath' => '',
                                    'ContactNo1' => isset($mVal['MobileNo']) ? trim($mVal['MobileNo']) : '',
                                    'countrycode' => isset($mVal['CountryCode']) ? trim($mVal['CountryCode']) : '',
                                    'ContactNo2' => '',
                                    'PassportNo' => '',
                                    'PassportExpiry' => '',
                                    'HomePhone' => '',
                                    'SecondaryPhone' => '',
                                    'UserDetails' => '',
                                    'Address' => '',
                                    'PinCode' => '',
                                    'CitySysId' => '',
                                    'StateOrZoneSysId' => '',
                                    'CountrySysId' => '',
                                    'SecondaryAddress' => '',
                                    'Fax' => '',
                                    'MacIp' => $ipadd,
                                    'SpeakingLangSysId' => '',
                                    'Signature' => '',
                                    'UpdateDate' => $curr_date,
                                    'RegisterDate' => $curr_date,
                                    'IsApproved' => 1,
                                    'IsActive' => 1,
                                    'IsMarried' => '',
                                    'Noofkids' => '',
                                    'FoodPreference' => '',
                                    'CustomerCompanyName' => '',
                                    'Remarks' => '',
                                    'CustomerCategory' => '',
                                    'SeatPreference' => ''
                                );
                                if ($FirstName != '' && $Relation != '') {
                                    $objGest = new Travel_Model_Tbltbbcuser();
                                    $chkcustomerMember = $objGest->getCustomerAndMembersDetailsAll('', '', '', trim($Relation), trim($FirstName), '', $AgencySysId);
                                    if (!empty($chkcustomerMember)) {
                                        $whereMember = "CustomerSysId = " . $CustomerSysId . " AND MemberSysId=" . $chkcustomerMember[0]['MemberSysId'];
                                        //echo $whereMember;die;
                                        $this->_customermemberObj->updateCustomerMember($data, $whereMember);
                                        $record[] = $chkcustomerMember[0]['MemberSysId'];
                                    } else {
                                        $record[] = $this->_customermemberObj->addCustomerMember($data);
                                    }
                                }
                            }
                        }
                        $resultSet["memberId"] = $record;
                    }
                } catch (Zend_Exception $e) {
                    $resultSet["status"] = false;
                    $resultSet["Message"] = $e->getMessage();
                }
            }
        } else {
            $resultSet["status"] = false;
            $resultSet["Message"] = "Please use post Method";
        }
        $jsonData = json_encode($resultSet);
        echo $jsonData;
        exit;
    }

    public function addCustomerApiAction()
    {
        if ($this->getRequest()->isPost()) {
            $param = $this->getRequest()->getParams();
            $AgencySysId = (int) $this->getRequest()->getParam("AgencySysId");
            $UserSysId = (int) $this->getRequest()->getParam("UserSysId");
            $CustomerSysId = (int) $this->getRequest()->getParam("CustomerSysId");
            $Salutation = (int) $this->getRequest()->getParam("Salutation");
            $EmailId = $this->getRequest()->getParam("EmailId");
            $FirstName = $this->getRequest()->getParam("FirstName");
            $LastName = $this->getRequest()->getParam("LastName");
            $CountryCode = $this->getRequest()->getParam("CountryCode");
            $MobileNo = $this->getRequest()->getParam("MobileNo");
            $Relation = $this->getRequest()->getParam("Relation", NULL);
            $IsB2BAgent = $this->getRequest()->getParam("IsB2BAgent", NULL);
            $IsB2BAgent = !empty($IsB2BAgent) ? $IsB2BAgent : 0;
            $B2B = $this->getRequest()->getParam("B2B", 0);
            $B2B = !empty($B2B) ? $B2B : 0;

            $memberDetailArray = $this->getRequest()->getParam("memberDetailArray") ? json_decode($this->getRequest()->getParam("memberDetailArray"), 1) : array();

            $updatedate = date("Y-m-d H:i:s");
            if (isset($EmailId) && !empty($EmailId)) {
                try {
                    if (!isset($CustomerSysId) || empty($CustomerSysId)) {
                        $customerDetailsEmail = $this->_crmcustomerObj->ChkEmailWithResponseUpdate($EmailId, $AgencySysId);
                        $CustomerSysId = $customerDetailsEmail['CustomerSysId'] ? $customerDetailsEmail['CustomerSysId'] : '';
                    }

                    // print_r($CustomerSysId);
                    // die('api');
                    if ($B2B == 0) {
                        if (empty($customerDetailsEmail)) {
                            $userArray = array(
                                'EmailId' => $EmailId,
                                'Salutation' => $Salutation,
                                'PrimaryContactNumber' => '',
                                'FullName' => $FirstName . ' ' . $LastName,
                                'FirstName' => $FirstName,
                                'LastName' => $LastName ? $LastName : '',
                                'ActiveDate' => $updatedate,
                                'UpdatedDate' => $updatedate,
                                'CreatedDate' => $updatedate,
                                'IsApproved' => '1',
                                'IsActive' => '1',
                                'IsMarkForDelete' => '0'
                            );
                            $CRMCustSysId = $this->_crmcustomerObj->addCustomer($userArray);
                            $userLeadArray = array(
                                'AgencySysId' => $AgencySysId,
                                'EmailId' => $EmailId,
                                'Salutation' => (isset($Salutation) && !empty($Salutation)) ? $Salutation : 0,
                                'PrimaryContactNumber' => $MobileNo,
                                'countrycode' => ($CountryCode) ? trim($CountryCode) : '91',
                                'FullName' => $FirstName . ' ' . $LastName,
                                'FirstName' => trim($FirstName),
                                'LastName' => trim($LastName),
                                'ActiveDate' => $updatedate,
                                'UpdatedDate' => $updatedate,
                                'CreatedDate' => $updatedate,
                                'IsApproved' => '1',
                                'IsActive' => '1',
                                'IsMarkForDelete' => '0',
                                'CampaignSysId' => 0
                            );
                            //for create new customer
                            //echo '<pre>';print_r($userLeadArray);die('www');
                            $AgencyCRMLeadSysId = $this->_crmagencyleadaccountObj->addCustomer($userLeadArray);
                            $agencyuserArray = array(
                                'AgencySysId' => $AgencySysId,
                                'AgencyCRMLeadSysId' => $AgencyCRMLeadSysId,
                                'CRMCustSysId' => $CRMCustSysId,
                                'EmailId' => $EmailId,
                                'Title' => $Salutation ? $Salutation : 0,
                                'Logo' => '',
                                'IsfromSM' => '0',
                                'UserId' => '0',
                                'CitySysId' => '',
                                'StateOrZoneSysId' => 0,
                                'CountrySysId' => '',
                                'IsEmployee' => '0',
                                'Contacts' => $MobileNo ? $MobileNo : '',
                                'JoinDate' => $updatedate,
                                'UserName' => $FirstName . '' . $LastName,
                                'FirstName' => $FirstName ? $FirstName : '',
                                'LastName' => $LastName ? $LastName : '',
                                'Relation' => '',
                                'PassportNo' => '',
                                'PassportExpiry' => '',
                                'DOB' => '',
                                'MarriageAnniversary' => '',
                                'CreatedByUserSysId' => (int)$UserSysId,
                                'RegisterDate' => $updatedate,
                                'UpdateDate' => $updatedate,
                                'countrycode' => $CountryCode,
                                'IsApproved' => '0',
                                'IsActive' => '1',
                                'IsMarkForDelete' => '0',
                                'IsB2BAgent' => $IsB2BAgent
                            );
                            $CustomerSysId = $this->_agencycustomerObj->addAgencyCustomer($agencyuserArray);

                            $resultSet["status"] = true;
                            $resultSet["Message"] = $CustomerSysId;
                        } else {
                            // if ($CustomerSysId > 0) {
                            //     $updateArray = array(
                            //         'FirstName' => $FirstName ? $FirstName : '',
                            //         'LastName' => $LastName ? $LastName : '',
                            //         'Title' => $Salutation ? $Salutation : 1,
                            //         'Contacts' => $MobileNo ? $MobileNo : '',
                            //         'countrycode' => $CountryCode,

                            //     );
                            //     $whare = array("CustomerSysId = ?" => $CustomerSysId, "AgencySysId = ?" => $AgencySysId);
                            //     $this->_agencycustomerObj->UpdateAgencyCustomer($updateArray, $whare);
                            // }
                            $resultSet["status"] = true;
                            $resultSet["Message"] = $CustomerSysId;
                        }
                    }

                    if ($CustomerSysId) {
                        $ipadd = $_SERVER['REMOTE_ADDR'];
                        $curr_date = date('Y-m-d');
                        if (!empty($memberDetailArray)) {
                            foreach ($memberDetailArray as $mKey => $mVal) {

                                $FirstName = isset($mVal['FirstName']) ? trim($mVal['FirstName']) : '';
                                $LastName = isset($mVal['LastName']) ? trim($mVal['LastName']) : '';
                                $Relation = isset($mVal['Relation']) ? trim($mVal['Relation']) : 9;
                                $UserName = trim($FirstName . ' ' . $LastName);
                                $data = array(
                                    'AgencySysId' => $AgencySysId,
                                    'CustomerSysId' => $CustomerSysId,
                                    'EmailId' => isset($mVal['EmailId']) ? trim($mVal['EmailId']) : '',
                                    'Contacts' => isset($mVal['MobileNo']) ? trim($mVal['MobileNo']) : '',
                                    'UserName' => $UserName,
                                    'FirstName' => $FirstName,
                                    'LastName' => $LastName,
                                    'Relation' => isset($mVal['Relation']) ? trim($mVal['Relation']) : 9,
                                    'IsMarkForDelete' => 0,
                                    'Title' => isset($mVal['Salutation']) ? trim($mVal['Salutation']) : '',
                                    'Logo' => '',
                                    'IsfromSM' => 0,
                                    'SMTypeId' => 0,
                                    'SMId' => '',
                                    'UserId' => '',
                                    'IsEmployee' => 0,
                                    'JoinDate' => $curr_date,
                                    'ExitDate' => '1900-01-01',
                                    'Designation' => '',
                                    'Password' => '',
                                    'RandStr' => '',
                                    'PasswordExpiryDate' => $curr_date,
                                    'IsPswExpire' => 0,
                                    'OtherEmail' => '',
                                    'SecondaryEmail' => '',
                                    'LastLoginTime' => '1900-01-01',
                                    'IsLogInNow' => 0,
                                    'CreatedByUserSysId' => (int)$UserSysId,
                                    'RandomCode' => '',
                                    'Gender' => '',
                                    'UserNickName' => $FirstName,
                                    'UserPicPath' => '',
                                    'ContactNo1' => isset($mVal['MobileNo']) ? trim($mVal['MobileNo']) : '',
                                    'countrycode' => isset($mVal['CountryCode']) ? trim($mVal['CountryCode']) : '',
                                    'ContactNo2' => '',
                                    'PassportNo' => '',
                                    'PassportExpiry' => '',
                                    'HomePhone' => '',
                                    'SecondaryPhone' => '',
                                    'UserDetails' => '',
                                    'Address' => '',
                                    'PinCode' => '',
                                    'CitySysId' => '',
                                    'StateOrZoneSysId' => '',
                                    'CountrySysId' => '',
                                    'SecondaryAddress' => '',
                                    'Fax' => '',
                                    'MacIp' => $ipadd,
                                    'SpeakingLangSysId' => '',
                                    'Signature' => '',
                                    'UpdateDate' => $curr_date,
                                    'RegisterDate' => $curr_date,
                                    'IsApproved' => 1,
                                    'IsActive' => 1,
                                    'IsMarried' => '',
                                    'Noofkids' => '',
                                    'FoodPreference' => '',
                                    'CustomerCompanyName' => '',
                                    'Remarks' => '',
                                    'CustomerCategory' => '',
                                    'SeatPreference' => ''
                                );

                                if ($FirstName != '' && $Relation != '') {
                                    $objGest = new Travel_Model_Tbltbbcuser();
                                    $chkcustomerMember = $objGest->getCustomerAndMembersDetailsAll('', '', '', '', trim($FirstName), trim($LastName), $AgencySysId, $CustomerSysId);

                                    if (!empty($chkcustomerMember)) {
                                        $whereMember = "CustomerSysId = " . $CustomerSysId . " AND MemberSysId=" . $chkcustomerMember[0]['MemberSysId'];
                                        //echo $whereMember;die;
                                        $this->_customermemberObj->updateCustomerMember($data, $whereMember);
                                        $record[] = $chkcustomerMember[0]['MemberSysId'];
                                    } else {
                                        $record[] = $this->_customermemberObj->addCustomerMember($data);
                                    }
                                }
                            }
                        }
                        $resultSet["memberId"] = $record;
                        $resultSet["Message"] = $CustomerSysId;
                    }
                } catch (Zend_Exception $e) {
                    $resultSet["status"] = false;
                    $resultSet["Message"] = $e->getMessage();
                }
            }
        } else {
            $resultSet["status"] = false;
            $resultSet["Message"] = "Please use post Method";
        }
        $jsonData = json_encode($resultSet);
        echo $jsonData;
        exit;
    }

    public function updateCustomerAction()
    {
        if ($this->getRequest()->isPost()) {
            // echo "<pre>";print_r($_POST);exit;
            try {
                $AgencySysId = (int) $this->getRequest()->getParam("AgencySysId");
                $Salutation = (int) $this->getRequest()->getParam("Salutation");
                $EmailId = $this->getRequest()->getParam("EmailId");
                $FirstName = $this->getRequest()->getParam("FirstName");
                $LastName = $this->getRequest()->getParam("LastName");
                $CountryCode = $this->getRequest()->getParam("CountryCode");
                $MobileNo = $this->getRequest()->getParam("MobileNo");
                $CityId = $this->getRequest()->getParam("CityId");
                $customeraddress = $this->_request->getParam('customeraddress');
                $PassportNo = $this->getRequest()->getParam("PassportNo");
                $PassportIssue = $PassportExpiry = $custdob = '';
                $custdobVal = $this->getRequest()->getParam('custdob');
                $PassportExpiryVal = $this->getRequest()->getParam("PassportExpiry");
                $PassportIssueVal = $this->getRequest()->getParam("PassportIssue");
                if ($custdobVal != '') {
                    $custdob = explode('/', $custdobVal);
                    $custdob = $custdob[2] . "-" . $custdob[1] . "-" . $custdob[0];
                }
                if ($PassportExpiryVal != '') {
                    $PassportExpiry = explode('/', $PassportExpiryVal);
                    $PassportExpiry = $PassportExpiry[2] . "-" . $PassportExpiry[1] . "-" . $PassportExpiry[0];
                }
                if ($PassportIssueVal != '') {
                    $PassportIssue = explode('/', $PassportIssueVal);
                    $PassportIssue = $PassportIssue[2] . "-" . $PassportIssue[1] . "-" . $PassportIssue[0];
                }
                $updateArray = array(
                    'FirstName' => trim($FirstName),
                    'Title' => $Salutation ? $Salutation : 0,
                    'countrycode' => $CountryCode,
                    'LastName' => $LastName ? $LastName : '',
                    'Contacts' => $MobileNo ? $MobileNo : '',
                    'CitySysId' => $CityId,
                    'Address' => (isset($customeraddress) && !empty($customeraddress) ? $customeraddress : ''),
                );
                if ($PassportNo != '') {
                    $updateArray['PassportNo'] = $PassportNo;
                }
                if ($custdob != '') {
                    $updateArray['DOB'] = $custdob;
                }
                if ($PassportExpiry != '') {
                    $updateArray['PassportExpiry'] = $PassportExpiry;
                }
                if ($PassportIssue != '') {
                    $updateArray['PassportIssue'] = $PassportIssue;
                }
                $customerDetailsEmail = $this->_crmcustomerObj->ChkEmailWithResponseUpdate($EmailId, $AgencySysId);
                $CustomerSysId = $customerDetailsEmail['CustomerSysId'] ? $customerDetailsEmail['CustomerSysId'] : '0';
                if ($CustomerSysId > 0) {
                    $whare = array("CustomerSysId = ?" => $CustomerSysId, "AgencySysId = ?" => $AgencySysId);
                    $this->_agencycustomerObj->UpdateAgencyCustomer($updateArray, $whare);
                    $resultSet["status"] = true;
                    $resultSet["Message"] = $CustomerSysId;
                } else {
                    $resultSet["status"] = false;
                    $resultSet["Message"] = "Not updated";
                }
            } catch (Zend_Exception $e) {
                $resultSet["status"] = false;
                $resultSet["Message"] = $e->getMessage();
            }
        } else {
            $resultSet["status"] = false;
            $resultSet["Message"] = "Please use post Method";
        }
        $jsonData = json_encode($resultSet);
        echo $jsonData;
        exit;
    }

    public function addtodoAction()
    {
        if ($this->getRequest()->isPost()) {
            $details = $this->_request->getParam('details') ? $this->_HtmlPurifier->filter($this->_request->getParam('details')) : '';
            $customerSysId = $this->_request->getParam('customerSysId') ? (int) $this->_HtmlPurifier->filter($this->_request->getParam('customerSysId')) : '';
            $todoreminder = $this->_request->getParam('todoreminder') ? $this->_HtmlPurifier->filter($this->_request->getParam('todoreminder')) : '';
            $todosubject = $this->_request->getParam('todosubject') ? $this->_HtmlPurifier->filter($this->_request->getParam('todosubject')) : '';
            $todostartdate = $this->_request->getParam('todostartdate') ? $this->_request->getParam('todostartdate') : '';
            // $todoenddate = $this->_request->getParam('todoenddate') ? $this->_request->getParam('todoenddate') : '';
            $CustomerAuth = new Travel_Model_AgencyCustomerAuth();
            //echo "<pre>";print_r($_REQUEST);exit;
            $userName = $this->getRequest()->getParam('userName');
            $userPassword = $this->getRequest()->getParam('userPassword');
            $userName = $this->getDecryptData($userName);
            $userPassword = $this->getDecryptData($userPassword);
            $result = $CustomerAuth->agentLogin($userName, $userPassword);
            if (!$result) {
                $result_submit = array('IsLogin' => false, 'IsMobile' => false, 'error' => 'Please check UserName or Password');
                echo Zend_Json::encode($result_submit);
                exit;
            } else {
                $AgencySysId = $result['AgencySysId'];
                $AgentSysId = $result['UserSysId'];
                $explodetodostartdateAll = explode(' ', $todostartdate);
                $explodetodostartdate = explode('/', $explodetodostartdateAll[0]);
                $startdate = $explodetodostartdate[2] . '-' . $explodetodostartdate[1] . '-' . $explodetodostartdate[0] . " " . $explodetodostartdateAll[1];
                //                $explodetodoenddateAll = explode(' ', $todoenddate);
                //                $explodetodoenddate = explode('/', $explodetodoenddateAll[0]);
                //                $enddate = $explodetodoenddate[2] . '-' . $explodetodoenddate[1] . '-' . $explodetodoenddate[0] . " " . $explodetodoenddateAll[1];
                $data = array(
                    'Subject' => $todosubject,
                    'StartDateTime' => $startdate,
                    'EndDateTime' => $startdate,
                    'RelatedTo' => '',
                    'IsCompleted' => 0,
                    'Location' => 0,
                    'Type' => 0,
                    'Description' => addslashes($details),
                    'CustSysId' => $customerSysId,
                    'CreatedBySysId' => $AgentSysId,
                    'AssignToSysId' => $AgentSysId,
                    'AgencySysId' => $AgencySysId,
                    'CreateDate' => date('Y-m-d H:i:s'),
                    'UpdateDate' => date('Y-m-d H:i:s'),
                    'RemindDuration' => $todoreminder,
                    'IsActive' => 1,
                    'IsMarkForDel' => 0,
                );
                try {
                    // echo "<pre>";print_r($data);exit;
                    $modelNew = new Travel_Model_CRM_AgencyCustomerTodo();
                    $lastID = $modelNew->addAgencyCustomerTodo($data);
                    $response = array('success' => true, 'msg' => 'Sucess');
                } catch (Zend_Exception $e) {
                    $response = array('success' => false, 'msg' => $e->getMessage());
                }
                echo json_encode($response);
                exit;
            }
        } else {
            $response = array('success' => false, 'msg' => 'Please use Post Method');
            echo json_encode($response);
            exit;
        }
    }

    public function getMemberListAction()
    {
        if ($this->getRequest()->isPost()) {
            $AgencySysId = $this->_request->getParam('AgencySysId') ? $this->_HtmlPurifier->filter($this->_request->getParam('AgencySysId')) : '';
            $AgencyKey = $this->_request->getParam('AgencyKey') ? $this->_HtmlPurifier->filter($this->_request->getParam('AgencyKey')) : '';
            $EmailId = $this->_request->getParam('EmailId') ? $this->_HtmlPurifier->filter($this->_request->getParam('EmailId')) : '';
            $Contacts = $this->_request->getParam('Contacts') ? $this->_HtmlPurifier->filter($this->_request->getParam('Contacts')) : '';
            $model = new Webservice_Model_Master();
            $getIVkey = $model->getIVKey($AgencySysId, $AgencyKey);
            if (!empty($getIVkey)) {
                $getIVkeyVal = isset($getIVkey[0]['IVKEY']) ? $getIVkey[0]['IVKEY'] : '';
                if ($getIVkeyVal != '') {
                    $returnData = $this->_crmcustomerObj->getMemberList($EmailId, $Contacts, $getIVkeyVal);

                    $response = array('success' => true, 'data' => $returnData, 'msg' => '');
                } else {
                    $response["status"] = false;
                    $response["Message"] = "Please contact to IT Team";
                }
            } else {
                $response["status"] = false;
                $response["Message"] = "Please contact to IT Team";
            }
        } else {
            $response = array('success' => false, 'data' => '', 'msg' => 'Please use Post Method');
        }
        echo json_encode($response);
        exit;
    }
    public function updateMemberDocumentDetailAction()
    {   
         
        if ($this->getRequest()->isPost()) {
            $requestPerameter = $this->getRequest()->getPost();
            $ARR_SALUTION = unserialize(ARR_SALUTION);
            $objFlight = new Travel_Model_TblFlight();
            $param = isset($requestPerameter['param']) ? json_decode($requestPerameter['param'], 1) : array(); 
//            echo "<pre>";print_r($param); 
            $documentImagePathArr = array();
            $TblAgency = new Travel_Model_TblAgency();
            $objVisa = new Travel_Model_TblVisa();
            $TPSysId = isset($param['TPSysId']) ? $param['TPSysId'] : 0;
            $TPPaxSysId = isset($param['TPPaxSysId']) ? $param['TPPaxSysId'] : 0;
            $AgencySysId = isset($param['AgencySysId']) ? $param['AgencySysId'] : 0; 
            $paramArray = array();
            if ($TPSysId > 0 && $TPPaxSysId > 0) {
//                $paramArray = $this->_crmcusttravelplan->GetTravelPlanType($TPSysId);
                $paramArray = $this->_crmcusttravelplan->GetTravelPlanVisaLeadpaxDeail($TPSysId);
//                echo "<pre>";print_r($paramArray);die;
                $IsB2BProposal = (isset($paramArray['IsB2BProposal'])) ? (int) $paramArray['IsB2BProposal'] : 0;
                $MasterAgencySysId = (isset($paramArray['AgencySysId'])) ? (int) $paramArray['AgencySysId'] : 0;
                $CustomerAgencySysId = (isset($paramArray['CustomerAgencySysId'])) ? (int) $paramArray['CustomerAgencySysId'] : 0;
                $AgentSysId = (isset($paramArray['AgentSysId'])) ? (int) $paramArray['AgentSysId'] : 0;
                $OpsAgentSysId = (isset($paramArray['OpsAgentSysId'])) ? (int) $paramArray['OpsAgentSysId'] : 0;
                 
                if($IsB2BProposal == 1){
                    $AgencySysId = $CustomerAgencySysId;  
                } 
                $intCustomerSysId = (isset($paramArray['CustomerSysId'])) ? (int) $paramArray['CustomerSysId'] : 0;
                $memberData = (isset($param['memberData']) && !empty($param['memberData'])) ? $param['memberData'] : array();
                $CustomerSysId = $PaxCustomerSysId = (isset($memberData['CustomerSysId']) && (int)$memberData['CustomerSysId'] > 0) ? (int)$memberData['CustomerSysId'] : 0;
                $MemberSysId = $PaxMemberSysId = (isset($memberData['MemberSysId']) && (int)$memberData['MemberSysId'] > 0) ? (int)$memberData['MemberSysId'] : 0;
             
                // echo "<pre>";print_r($IsSendMail);die;
//                if (!empty($memberData)) {
//                    if($CustomerSysId == 0 && $MemberSysId == 0 && $IsB2BProposal == 1){
//                        $arrCustomerMembers[] = array(
//                            'AgencySysId' => $AgencySysId,
//                            'Title' => (int)($memberData['Salutation']),
//                            'FirstName' => trim($memberData['FirstName']),
//                            'LastName' => trim($memberData['LastName']),
//                            'Relation' => 9,
//                            'PassportNo' => trim($memberData['PassportNumber']),
//                            'PassportExpiry' => $memberData['PassportExpiry'],
//                            'PassportIssue' => $memberData['PassportIssue'],
//                            'UpdateDate' => date('Y-m-d'),
//                            'IsActive' => 1,
//                            'IsMarkForDelete' => 0,
//                        ); 
//                        $arrCustomerMembersIds = $objFlight->createAgencyCustomerMembers($arrCustomerMembers, $AgencySysId, $intCustomerSysId);    
//                        $PaxMemberSysId = (isset($arrCustomerMembersIds[0])) ? (int)$arrCustomerMembersIds[0] : 0;
//                        $PaxCustomerSysId = $intCustomerSysId;
//                    }
//                    $paxData = [
//                        'CustomerSysId' => $PaxCustomerSysId,
//                        'MemberSysId' => $PaxMemberSysId,
//                        'Salutation' => (int)($memberData['Salutation']),
//                        'FirstName' => trim($memberData['FirstName']),
//                        'LastName' => trim($memberData['LastName']),
//                        'passportno' => trim($memberData['PassportNumber']),
//                        'passportnoexpiry' => $memberData['PassportExpiry'],
//                        'passporIssue' => $memberData['PassportIssue'],
//                        'UpdateDate' => date('Y-m-d'),
//                    ];
//                    $wherepax = array('TPPaxSysId = ? ' => $TPPaxSysId);
//                    $updateId = $TblAgency->updateData('TB_Agency_Customer_TravelPlan_Pax', $paxData, $wherepax);
//                    
//                    if ($MemberSysId > 0) { 
//                        $memberSaveData = [
//                            'Title' => (int)($memberData['Salutation']),
//                            'FirstName' => trim($memberData['FirstName']),
//                            'LastName' => trim($memberData['LastName']),
//                            'PassportNo' => trim($memberData['PassportNumber']),
//                            'PassportExpiry' => $memberData['PassportExpiry'],
//                            'PassportIssue' => $memberData['PassportIssue'],
//                            'UpdateDate' => date('Y-m-d'),
//                        ]; 
//                        $whereMember = array('MemberSysId = ? ' => $MemberSysId);
//                        $TblAgency->updateData('TB_Agency_Customer_Members', $memberSaveData, $whereMember);
//                    } else if ($CustomerSysId > 0 && $MemberSysId == 0) { 
//                        $customerSaveData = [
//                            'Title' => (int)($memberData['Salutation']),
//                            'FirstName' => trim($memberData['FirstName']),
//                            'LastName' => trim($memberData['LastName']),
//                            'PassportNo' => trim($memberData['PassportNumber']),
//                            'PassportExpiry' => $memberData['PassportExpiry'],
//                            'PassportIssue' => $memberData['PassportIssue'],
//                            'UpdateDate' => date('Y-m-d'),
//                        ];
//                        $whereCustomer = array('CustomerSysId = ? ' => $CustomerSysId);
//                        $TblAgency->updateData('TB_Agency_Customer', $customerSaveData, $whereCustomer);
//                    }
//                }
                $GetTravelPlanUploadedDocumentsPre = $this->_crmcusttravelplan->GetTravelPlanUploadedDocuments($TPSysId,$TPPaxSysId);
//                echo "<PRE>";print_r($GetTravelPlanUploadedDocumentsPre); 
                $GetTravelPlanUploadedDocumentsPreArray = array();
                foreach($GetTravelPlanUploadedDocumentsPre as $tpKey => $tpValue){
                    $GetTravelPlanUploadedDocumentsPreArray[$tpValue['DocId']] = $tpValue;
                }
                $TotalRejectedUploadedDoc = 0;
                $IsDocUpdate = 0;
                if (isset($param['VisaDocument']) && !empty($param['VisaDocument'])) {
                    foreach ($param['VisaDocument'] as $key => $val) { 
                        $IsUpdate = (isset($GetTravelPlanUploadedDocumentsPreArray[$key]['DocImagePath']) && trim($GetTravelPlanUploadedDocumentsPreArray[$key]['DocImagePath']) == trim($val)) ? 0 : 1;
                        $StatusD = (isset($GetTravelPlanUploadedDocumentsPreArray[$key]['Status'])) ? (int)$GetTravelPlanUploadedDocumentsPreArray[$key]['Status'] : 0;
                         
                        if($IsUpdate == 1){
                            
                            $DocImagePath = is_array($val) ? implode(',',$val) : $val;
                            $documentImagePathArr = [
                                'DocImagePath' => $DocImagePath,
                                'Status' => 1,
                                'UpdateDate' => date('Y-m-d H:i'),
                            ];
                            $where = array('TPSysId = ? ' => $TPSysId, 'TPPaxSysId = ? ' => $TPPaxSysId, 'DocId = ? ' => $key);
                            $updateId = $TblAgency->updateData('TB_Agency_Customer_TravelPlan_Visa_Document', $documentImagePathArr, $where);
                             
                            $Remark = 'Update By Customer';
                            $travelplanHistory = array(
                                'AgencySysId' => $MasterAgencySysId,
                                'CustomerSysId' => $CustomerSysId,
                                'TPSysId' => $TPSysId,
                                'PlanType' => 6,
                                'TPPaxSysId' => $TPPaxSysId,
                                'DocId' => $key,
                                'UserSysId' => 0,
                                'Remark' => $Remark,
                                'CreateDate' => date('Y-m-d H:i'),
                                'IsManualAdded' => 0,
                                'Status' => 1,
                                'IsActive' => 1,
                                'IsMarkForDelete' => 0
                            );
                            $TblAgency->insertData('TB_Agency_Customer_TravelPlan_History', $travelplanHistory); 
                            if($StatusD == 3){
                                $TotalRejectedUploadedDoc++;
                            } 
                            $IsDocUpdate++;
                        } 
                    }
                    if($IsDocUpdate > 0){
                        $objVisa->checkUpdatePaxVisaStatusVisaDoc($TPSysId, $TPPaxSysId);
                    } 
                }
                
                $GetTravelPlanUploadedDocuments = $this->_crmcusttravelplan->GetTravelPlanUploadedDocuments($TPSysId,0,'file');
                $TotalDocument = $TotalDocumentUploaded = $RejectedDocUpload = 0;
                if($GetTravelPlanUploadedDocuments){
                    foreach($GetTravelPlanUploadedDocuments as $tpudKey => $tpudValue){
                        if($tpudValue['IsMandatory'] == 1){
                            $TotalDocument++;
                            if($tpudValue['DocImagePath'] != ''){
                               $TotalDocumentUploaded++; 
                               
                            }
                        }
                    }
                }
                
                //$TotalDocument = !empty($GetTravelPlanUploadedDocuments) ? count($GetTravelPlanUploadedDocuments) : 0;
//                $TotalDocumentDocImagePath = array_column($GetTravelPlanUploadedDocuments,"DocImagePath");
//                $FilterDocumentUploaded = array_filter($TotalDocumentDocImagePath);
//                $TotalDocumentUploaded = !empty($FilterDocumentUploaded) ? count($FilterDocumentUploaded) : 0;
                 
                $IsSendMail = (($TotalDocument > 0 && $TotalDocument == $TotalDocumentUploaded) || $TotalRejectedUploadedDoc > 0) ? 1 : 0;
                //$IsSendMail = 0;
                if($IsSendMail == 1 &&  $OpsAgentSysId > 0){
                     
                    $getAgentDetail = $this->_crmcusttravelplan->getAgentDetails($OpsAgentSysId);

                    $UserSalutation = ($getAgentDetail['Salutation'] > 0) ? trim($ARR_SALUTION[$getAgentDetail['Salutation']]) : '';
                    $UserName = $UserSalutation.' '. trim($getAgentDetail['FirstName']).' '.($getAgentDetail['LastName']);

                    $CustomerSalutation = (isset($paramArray['CustomerSalutation']) && $paramArray['CustomerSalutation'] > 0) ? trim($ARR_SALUTION[$paramArray['CustomerSalutation']]) : '';
                    $CustomerFirstName = (isset($paramArray['CustomerFirstName']) && trim($paramArray['CustomerFirstName']) != '') ? trim($paramArray['CustomerFirstName']) : '';
                    $CustomerLastName = (isset($paramArray['CustomerLastName']) && trim($paramArray['CustomerLastName']) != '') ? trim($paramArray['CustomerLastName']) : '';
                    $CustomerContacts = (isset($paramArray['CustomerContacts']) && trim($paramArray['CustomerContacts']) != '') ? trim($paramArray['Customercountrycode'].''.$paramArray['CustomerContacts']) : '';

                    $MemberSalutation = (isset($paramArray['MemberSalutation']) && $paramArray['MemberSalutation'] > 0) ? trim($ARR_SALUTION[$paramArray['MemberSalutation']]) : '';
                    $MemberFirstName = (isset($paramArray['MemberFirstName']) && trim($paramArray['MemberFirstName']) != '') ? trim($paramArray['MemberFirstName']) : '';
                    $MemberLastName = (isset($paramArray['MemberLastName']) && trim($paramArray['MemberLastName']) != '') ? trim($paramArray['MemberLastName']) : '';
                    $MemberContacts = (isset($paramArray['MemberContacts']) && trim($paramArray['MemberContacts']) != '') ? trim($paramArray['Membercountrycode'].''.$paramArray['MemberContacts']) : '';


                    if(!empty($MemberFirstName) && !empty($MemberLastName)){
                        $CustomerSalutation = $MemberSalutation;
                        $CustomerFirstName = $MemberFirstName;
                        $CustomerLastName = $MemberLastName;
                        $CustomerContacts = $MemberContacts;
                    }

                    $LeadPaxName = $CustomerSalutation.' '.$CustomerFirstName.' '.$CustomerLastName;

                    $html = new Zend_View();
                    $html->setScriptPath(APPLICATION_PATH . '/views/emails/');
                    $html->assign(array(
                        'type' => 'DocumentUploadNotification', 
                        'EmailId' => trim($getAgentDetail['EmailId']) ,
                        'UserName' => $UserName, 
                        'B2bAgencyName' => ($paramArray['IsB2BProposal'] == 1) ? $paramArray['DisplayName'] : '',
                        'LeadPaxName' => $LeadPaxName,
                        'LeadPaxContacts' => $CustomerContacts,
                        'TPSysId' => $TPSysId,
                        'DestinationPlaces' => $paramArray['DestinationPlaces'],
                        'IsB2BProposal' => $paramArray['IsB2BProposal'],
                        'VisaTitle' => $paramArray['Title'],
                        'MinPax' => $paramArray['MinPax'],
                        'StartDate' => $paramArray['StartDate']->format('d M y'),
                        'BookingDate' => !empty($paramArray['CreateDate']) ? $paramArray['CreateDate']->format('d-M-y') : 'NA',
                        'GetTravelPlanUploadedDocuments' => $GetTravelPlanUploadedDocuments,
                        'DisplayName' => $paramArray['DisplayName'],
                        'ContactName' => trim($paramArray['FirstName']).' '.trim($paramArray['LastName']),
                        'ContactInfo' => $paramArray['countrycode'].''.$paramArray['ContactNo1'],

                        ));
                    $bodyText = $html->render('VisaDocumentMail.phtml');
                    $subject = 'Document Upload Notification - Proposal ID '.$TPSysId;
                    $emailData = array('fromEmail' => $getAgentDetail['EmailId'], 'fromName' => $getAgentDetail['DisplayName'], 'subject' => $subject, 'to' => array(trim($getAgentDetail['EmailId'])), 'bodyHtml' => $bodyText, 'bodyText' => '');
                    $arrEmailStatisticsType = array_keys(unserialize(ARR_EMAIL_STATISTICS_TYPE));
                    $arrEmailStatistics = array(
                        "TPSysId" => $TPSysId,
                        "TypeSysId" => 1, // 1 For Email 2 For SMS
                        "AgencySysId" => (int) $AgencySysId,
                        "AgentSysId" => $OpsAgentSysId,
                        "Title" => $subject,
                        "Source" => $arrEmailStatisticsType[2], // 6 For Misc
                        "Status" => 0,
                        "RefSysId" => "",
                        "RefSysStatus" => "",
                        "CreateDate" => date('Y-m-d H:s:i')
                    );
                    $resultmail = $this->mailSentByElastice($emailData, $arrEmailStatistics); 
                }
                
                $response = array('success' => true, 'data' => array('CustomerSysId'=>(int)$PaxCustomerSysId,'MemberSysId'=>(int)$PaxMemberSysId), 'msg' => 'Suuccess');
            } else {
                $response = array('success' => false, 'data' => '', 'msg' => 'Please use Post Method');
            }
        } else {
            $response = array('success' => false, 'data' => '', 'msg' => 'Please use Post Method');
        }
        echo json_encode($response);
        exit;
    }
    public function getBookingAgencySupplierAction()
    {
        if ($this->getRequest()->isPost()) {

            $SupplierSysId = (int) $this->getRequest()->getParam("SupplierSysId");
            $model = new Webservice_Model_Master();
            $TblSupplier = new Travel_Model_TblSupplier();
            if (!empty($SupplierSysId)) {
                $getSupplierById = $TblSupplier->getSupplierById($SupplierSysId);

                $resultSet["data"] = $getSupplierById;
                $resultSet["status"] = true;
                $resultSet["Message"] = 'Success';
            } else {
                $resultSet["status"] = false;
                $resultSet["Message"] = "Supplier id missing.";
            }
        } else {
            $resultSet["status"] = false;
            $resultSet["Message"] = "Please use post Method";
        }
        $jsonData = json_encode($resultSet);
        echo $jsonData;
        exit;
    }
    public function getAgencyLeadSourceAction()
    {
        if ($this->getRequest()->isPost()) {

            $AgencySysId = (int) $this->getRequest()->getParam("AgencySysId");
            $TblCustomer = new Travel_Model_CRM_Customer();
            if (!empty($AgencySysId)) {
                $getLeadSource = $TblCustomer->getLeadSource($AgencySysId);
                $resultSet["data"] = $getLeadSource;
                $resultSet["status"] = true;
                $resultSet["Message"] = 'Success';
            } else {
                $resultSet["status"] = false;
                $resultSet["Message"] = "Lead source id missing.";
            }
        } else {
            $resultSet["status"] = false;
            $resultSet["Message"] = "Please use post Method";
        }
        $jsonData = json_encode($resultSet);
        echo $jsonData;
        exit;
    }
    public function getAgencyLeadDetailAction()
    { 
        if ($this->getRequest()->isPost()) { 
            $TblAgency = new Travel_Model_TblAgency(); 
            $params = $this->getRequest()->getParams();
            $customHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('Custom');
            $headers = getallheaders(); 
            $SecurityKey = isset($headers['SecurityKey']) ? trim($headers['SecurityKey']) : false; 
            $checkAgency = $TblAgency->checkAgency($SecurityKey);
            $AgencySysId = (isset($checkAgency['AgencySysId'])) ?  (int)$checkAgency['AgencySysId'] : 0;
             
            if(!empty($AgencySysId)){  
                 
                $CustomerId = (isset($params['CustomerId']) && !empty($params['CustomerId'])) ? trim($params['CustomerId']) : '';
                $SecureCode = isset($params['SecureCode']) ? $params['SecureCode'] : '';
                $B2BAgencySysId = isset($params['B2BAgencySysId']) ? (int)$params['B2BAgencySysId'] : 0; 
                $CustomerSysId =  base64_decode($CustomerId);
                if((int)$CustomerSysId > 0 && $B2BAgencySysId > 0){
                    $code = Catabatic_ValidateCustomer::secureCode($CustomerId, 1);
                    if($SecureCode == $code){ 
                        $getcustomerdetails = $this->_crmcustomerObj->GetCustomerDetailByCustomerSysId($CustomerSysId, $AgencySysId);
                        $getLeadlist = $this->_crmcusttravelplan->GetLatestLeadList($CustomerSysId,$AgencySysId,0,$B2BAgencySysId);
                        $GetTravelPlanStatusName = $customHelper->GetTravelPlanStatusName(1);
                        $resultSet["status"] = true;
                        $resultSet["data"] = $getcustomerdetails;
                        $resultSet["Leadlist"] = $getLeadlist;
                        $resultSet["GetTravelPlanStatusName"] = $GetTravelPlanStatusName;
                    }else{
                        $resultSet["status"] = false;
                        $resultSet["Message"] = "Code Mismatch";
                    }
                }   
            }  
        } else {
            $resultSet["status"] = false;
            $resultSet["Message"] = "Please use post Method";
        }
        $jsonData = json_encode($resultSet);
        echo $jsonData;
        exit;
    }
    public function transactionManagementAction() {
 
        $requestPerameter = $this->getRequest()->getPost();
        $headers = getallheaders();
        $status = false;
        if (!empty($requestPerameter)) {
            $TblAgency = new Travel_Model_TblAgency(); 
            $updateData = new Payment_Model_Checkotp();
            $AgentAuth = new Travel_Model_AgencyAgentAuth();
            
            $OTP =  $requestPerameter['OTP'];
            $IsCheckB2BWallet =  $requestPerameter['Status'];
            $RequestType =  $requestPerameter['RequestType'];
            $AgencySysId =  $requestPerameter['AgencySysId'];
            $UserSysId = $requestPerameter['UserSysId'];
            $MasterAgencySysId =  $requestPerameter['MasterAgencySysId'];
            $SecurityKey = isset($headers['SecurityKey']) ? trim($headers['SecurityKey']) : false; 
            $checkAgency = $TblAgency->checkAgency($SecurityKey);
            if(!empty($checkAgency)){  
                $getUserDataByAgency = $TblAgency->getUserDataByAgency($AgencySysId);
                $getAgencyDataById = $TblAgency->getAgencyDataById($MasterAgencySysId);
                $emailId = $getUserDataByAgency['PrimaryEmail'];    
                $mobileNo = $getUserDataByAgency['ContactInfo'];   
                //echo "<pre>";print_r($getUserDataByAgency);die;
                if($RequestType == 'SendOTP'){ 
                    
                    $returnResponse = array('status'=>false);
                    if($mobileNo){
                        $randomString = $updateData->randomString();
                        $message = "OTP for CRM access is $randomString do not share it with anyone.\nTRVCRM";
                        $this->postFields = "";
                        $this->postFields .= "&method=$this->SMSMETHOD";
                        $this->postFields .= "&api_key=$this->SMSAPIKEY";
                        $this->postFields .= "&to=$mobileNo";
                        $this->postFields .= "&sender=$this->SMSSENDER";
                        $this->postFields .= "&message=$message";
                        $this->postFields .= "&format=$this->SMSFORMAT";
                        $postURL = $this->SMSURL;
                        $arrSMSStatisticsType = array_keys(unserialize(ARR_SMS_STATISTICS_TYPE));
                        $arrSMSStatistics = array(
                            "TPSysId" => 0,
                            "TypeSysId" => 2, // 1 For Email 2 For SMS
                            "AgencySysId" => (int) $AgencySysId,
                            "AgentSysId" => (int) $UserSysId,
                            "Title" => $message,
                            "Source" => $arrSMSStatisticsType[0], // 3 For Misc
                            "Status" => 0,
                            "RefSysId" => "",
                            "RefSysStatus" => "",
                            "CreateDate" => date('Y-m-d H:s:i')
                        );
                        $IsSMSApi = 1;
                        $resultVal = $updateData->sendSmsDetails($postURL, $this->postFields, $arrSMSStatistics, $IsSMSApi);
                        
                        $DisplayName = (isset($getAgencyDataById['DisplayName']) && !empty(trim($getAgencyDataById['DisplayName']))) ? trim($getAgencyDataById['DisplayName']) : trim($getAgencyDataById['Title']);
                        $PrimaryEmail = (isset($getAgencyDataById['PrimaryEmail']) && !empty(trim($getAgencyDataById['PrimaryEmail']))) ? trim($getAgencyDataById['PrimaryEmail']) : trim($getAgencyDataById['EmailIdForCustomer']);
                        $subject = "OTP for access";
                        $html = new Zend_View();
                        $html->setScriptPath(APPLICATION_PATH . '/views/emails/');
                        $html->assign(array('randomString' => $randomString, 'agencyDetails' => $getAgencyDataById));
                        $bodyText = $html->render('OTPEmailMaster.phtml');
                        $emailData = array('fromEmail' => $PrimaryEmail, 'fromName' => $DisplayName, 'subject' => $subject, 'to' => array($emailId), 'bodyHtml' => $bodyText, 'bodyText' => '');
                        $arrEmailStatisticsType = array_keys(unserialize(ARR_EMAIL_STATISTICS_TYPE));
                        $arrEmailStatistics = array(
                            "TPSysId" => 0,
                            "TypeSysId" => 1, // 1 For Email 2 For SMS
                            "AgencySysId" => (int) $AgencySysId,
                            "AgentSysId" => $UserSysId,
                            "Title" => $message,
                            "Source" => $arrEmailStatisticsType[2], // 6 For Misc
                            "Status" => 0,
                            "RefSysId" => "",
                            "RefSysStatus" => "",
                            "CreateDate" => date('Y-m-d H:s:i')
                        );
                        $resultmail = $this->mailSentByElastice($emailData, $arrEmailStatistics);
                        if (!empty($resultVal)) {
                            if (isset($resultVal['status']) && $resultVal['status'] == 'OK') {
                                try {
                                    $updateOne = 1;
                                    $updatedArray = array(
                                        'RandomCode' => $randomString, 
//                                       "FirmType" => new Zend_Db_Expr("FirmType + $updateOne"),
                                    );
                                    $whereA = array('AgencySysId =?' => $AgencySysId);
                                    $updateData->updateTable("TB_Agency", $updatedArray, $whereA);
                                    $mobileNoV = '***'.substr($mobileNo,6,10);
                                    $emailIdV = substr($emailId,0,4).'***';
                                    $returnResponse = array(
                                        'status'=>true,
                                        "smssent" => true, 
                                        'MobileNo'=>$mobileNoV,
                                        'EmailId'=>$emailIdV,
                                    );
                                } catch (Zend_Exception $e) {
                                    $errorMessage = $e->getMessage();
                                    $returnResponse = array(
                                        'status'=>false,
                                        "smssent" => false,
                                        'message' => $errorMessage,
                                    );
                                }
                            } 
                        } 
                    }else{
                        $returnResponse = array(
                            'status'=>false,
                            "smssent" => false, 
                            'message' => 'Unable to send OTP, Please try after some time. ',
                        );
                    }
                    echo json_encode($returnResponse);exit;

                }else{
                    $rmArray = array();
                    if((int)$getUserDataByAgency['ReportingToSysId']>0){
                        $rmArray = $AgentAuth->getUserDetailForRm($getUserDataByAgency['ReportingToSysId']);
                    }
                    $RandomCode = $getUserDataByAgency['RandomCode'];
                    $FirmType = $getUserDataByAgency['FirmType'];
                    if($FirmType > 3 && $IsCheckB2BWallet == 1){
                        $updatedArray = array(
                            'RandomCode' => '',
                            'FirmType' => 0,
                        );
                        $whereA = array('AgencySysId =?' => $AgencySysId);
                        $updateData->updateTable("TB_Agency", $updatedArray, $whereA); 
                        $status = false;
                        $errorMessage = "Incorrect OTP, Limit Exceed";
                    }else{
                        if($OTP == $RandomCode){
                            $updatedArray = array(
                                'RandomCode' => '',
                                'FirmType' => 0,
                                'IsCheckB2BWallet' => $IsCheckB2BWallet,
                            );
                            $whereA = array('AgencySysId =?' => $AgencySysId);
                            $updateData->updateTable("TB_Agency", $updatedArray, $whereA); 
                            $status = true;
                            $errorMessage = "Booking Status Updated Successfully.";
                            $DisplayName = (isset($getAgencyDataById['DisplayName']) && !empty(trim($getAgencyDataById['DisplayName']))) ? trim($getAgencyDataById['DisplayName']) : trim($getAgencyDataById['Title']);
                            $PrimaryEmail = (isset($getAgencyDataById['PrimaryEmail']) && !empty(trim($getAgencyDataById['PrimaryEmail']))) ? trim($getAgencyDataById['PrimaryEmail']) : trim($getAgencyDataById['EmailIdForCustomer']);
                            if($IsCheckB2BWallet == 1){
                                $subject = 'Wallet Activation Notification'; 
                            }else{
                                $subject = 'Wallet Deactivation Notification'; 
                            }
                            $html = new Zend_View();
                            $html->setScriptPath(APPLICATION_PATH . '/views/emails/');
                            $html->assign(array('randomString' => $randomString, 'agencyDetails' => $getAgencyDataById,'IsCheckB2BWallet' => $IsCheckB2BWallet,'UserData'=>$getUserDataByAgency,'rmArray'=>$rmArray));
                            $bodyText = $html->render('wallet_action.phtml');
                            $emailData = array('fromEmail' => $PrimaryEmail, 'fromName' => $DisplayName, 'subject' => $subject, 'to' => array($emailId), 'bodyHtml' => $bodyText, 'bodyText' => '');
                            $arrEmailStatisticsType = array_keys(unserialize(ARR_EMAIL_STATISTICS_TYPE));
                            $arrEmailStatistics = array(
                                "TPSysId" => 0,
                                "TypeSysId" => 1, // 1 For Email 2 For SMS
                                "AgencySysId" => (int) $AgencySysId,
                                "AgentSysId" => $UserSysId,
                                "Title" => $message,
                                "Source" => $arrEmailStatisticsType[2], // 6 For Misc
                                "Status" => 0,
                                "RefSysId" => "",
                                "RefSysStatus" => "",
                                "CreateDate" => date('Y-m-d H:s:i')
                            );
                            $resultmail = $this->mailSentByElastice($emailData, $arrEmailStatistics);
                        }else{ 
                            $updateOne = 1;
                            $updatedArray = array(
                                "FirmType" => new Zend_Db_Expr("FirmType + $updateOne"),
                            );
                            $whereA = array('AgencySysId =?' => $AgencySysId);
                            $updateData->updateTable("TB_Agency", $updatedArray, $whereA);
                            $status = false;
                            $errorMessage = "Incorrect OTP";
                        } 
                    }  
                } 
            }else{
                $status = false;
                $errorMessage = "Please use post method";
            }    
        } else {
            $status = false;
            $errorMessage = "Please use post method";
        }
        $returnArray = array("status" => $status, "message" => $errorMessage);

        echo json_encode($returnArray);
        exit;
    }
    public function getCustomerDetailAction()
    {         
        if ($this->getRequest()->isPost()) {
            $model = new Webservice_Model_Master();
            $params = $this->getRequest()->getParams();
            
            $email = (isset($params['email'])) ?  $params['email'] : '';
            $mobile = (isset($params['mobile'])) ?  $params['mobile'] : ''; 
            $headers = getallheaders();
            $SecurityKey = isset($headers['SecurityKey']) ? trim($headers['SecurityKey']) : '';
            if ($SecurityKey) {
                $result = $model->getCustomerDetailForApi($email,$mobile, $SecurityKey); 
                if (empty($result)) {
                    $result_submit = array('status' => false, 'error' => 'not exist');
                    echo Zend_Json::encode($result_submit);
                    exit;
                } else {
                    if (isset($result['IsActive']) && $result['IsActive'] == 1) {
                        $SecureCode = Catabatic_ValidateCustomer::secureCode(base64_encode($result['CustomerSysId']), 1);
                        $result_submit = [
                            'status' => true,
                            'EmailId' => trim($result['EmailId']),
                            'FirstName' => trim($result['FirstName']),
                            'LastName' => trim($result['LastName']),
                            'CustomerSysId' => base64_encode($result['CustomerSysId']),
                            'SecureCode' => $SecureCode,
                            'AgencySysId' => $result['AgencySysId'],
                            'Contacts' => $result['Contacts'],
                        ];
                        echo Zend_Json::encode($result_submit);
                        exit;
                    } else {
                        $result_submit = array('status' => false, 'error' => 'not active');
                        echo Zend_Json::encode($result_submit);
                        exit;
                    }
                }
            } else {
                $result_submit = array('status' => false, 'error' => 'Please check AgencyID');
                echo Zend_Json::encode($result_submit);
                exit;
            }
        } else {
            $result_submit = array('status' => false, 'error' => 'Please use post method');
            echo Zend_Json::encode($result_submit);
            exit;
        }
    }
    
    public function createAgencyCustomerAction(){
        
        if ($this->getRequest()->isPost()) { 
            $TblAgency = new Travel_Model_TblAgency(); 
            $params = $this->getRequest()->getParams();
            
            $leadSource = (isset($params['leadSource'])) ?  trim($params['leadSource']) : 0;
            $leadStage = (isset($params['leadStage'])) ?  (int)$params['leadStage'] : 53;
            $PlanType = (isset($params['PlanType'])) ?  (int)$params['PlanType'] : 5;
            $CRMCustSysId = (isset($params['CRMCustSysId'])) ?  base64_decode($params['CRMCustSysId']) : '';
            $CustomerSysId = (isset($params['CustomerSysId'])) ?  base64_decode($params['CustomerSysId']) : 0;
            $SearchString = '';
            $headers = getallheaders(); 
            $SecurityKey = isset($headers['SecurityKey']) ? trim($headers['SecurityKey']) : false; 
            $checkAgency = $TblAgency->checkAgency($SecurityKey);
            $AgencySysId = (isset($checkAgency['AgencySysId'])) ?  (int)$checkAgency['AgencySysId'] : 0;
            if(!empty($AgencySysId)){
                $AgencyCRMLeadSysId = 0;
                $detail = array();    
                if (isset($leadSource) && is_numeric($leadSource) && !empty($leadSource)) {
                    $leadSource = $leadSource;
                } else {
                    if(empty($leadSource)){
                        $leadSource = 'Agency';
                    }
                    $intLeadSourceSysId = $this->_crmcustomerObj->getLeadSource($AgencySysId, $leadSource); // for Master LeadSouce Creation
                    $leadSource = (isset($intLeadSourceSysId[0]['LeadSourceSysId']) && !empty($intLeadSourceSysId[0]['LeadSourceSysId'])) ? $intLeadSourceSysId[0]['LeadSourceSysId'] : 0;
                }
                $updatedate = date('Y-m-d H:i:s');
                 
                $salution = (isset($params['salution'])) ?  trim($params['salution']) : 1;
                $fname = (isset($params['fname'])) ?  trim($params['fname']) : '';
                $lname = (isset($params['lname'])) ?  trim($params['lname']) : '';
                $customerEmail = (isset($params['customerEmail'])) ?  trim($params['customerEmail']) : '';
                $countrycode = (isset($params['countrycode'])) ?  trim($params['countrycode']) : 91;
                $mobilenumber = (isset($params['mobilenumber'])) ?  trim($params['mobilenumber']) : '';
                $B2BAgencySysId = (isset($params['B2BAgencySysId'])) ?  (int)$params['B2BAgencySysId'] : 0;
                $AgentSysId = $IsB2Bproposal = 0;
                if($B2BAgencySysId > 0){
                    $getB2bAgencyData = $TblAgency->getAgencyData($B2BAgencySysId);
                    $AgentSysId = (int)$getB2bAgencyData['RMUserSysId'];
                    $AgencyType = (int)$getB2bAgencyData['AgencyType'];
                    $IsB2Bproposal =   ($AgencyType == 3) ? 3 : 0;
                }
                //echo "<pre>";print_r($params);die;
                
                $ContactNo1 = $mobilenumber = (isset($params['mobilenumber'])) ?  trim($params['mobilenumber']) : '';
                
                $custrelation = 0;
                $passnumber = $passexpiry = $custdob = $custanniversary = $customeraddress = $customerpincode = $SecondaryEmail = ''; 
                $CreatedByUserSysId = 0;   
                $getcustomerdetails = array();
                if ((int) $CustomerSysId > 0) {
                    $getcustomerdetails = $this->_crmcustomerObj->GetCustomerDetailByCustomerSysId(trim($CustomerSysId), $AgencySysId);
                } else {
                    if (trim($customerEmail) != '') {
                        $getcustomerdetails = $this->_crmcustomerObj->GetCustomerDetailsByEmail(trim($customerEmail), $AgencySysId);
                    } else if (trim($mobilenumber) != '') {
                        $getcustomerdetails = $this->_crmcustomerObj->ChkMobileExistInAgency(trim($mobilenumber), $AgencySysId, '');
                    }
                }
                $customerRcord = isset($getcustomerdetails['CustomerSysId']) ? $getcustomerdetails['CustomerSysId'] : 0;
                $SecureCode = Catabatic_ValidateCustomer::secureCode(base64_encode($customerRcord), 1);
                if(!empty($getcustomerdetails)){
                    echo json_encode(array('status'=>true,'message' => 'Customer Exist' ,'CustomerSysId' => base64_encode($customerRcord), 'SecureCode' => $SecureCode ));exit;
                }
                if($AgentSysId == 0){
                    $intLeadSourceSysId = $this->_crmcustomerObj->getAgenctIdFormLeadSourceId($AgencySysId, $leadSource);     
                    if (isset($intLeadSourceSysId[0]['AssignUserSysId']) && trim($intLeadSourceSysId[0]['AssignUserSysId']) != '') {
                        $AgentSysId = isset($intLeadSourceSysId[0]['AssignUserSysId']) ? (int) $intLeadSourceSysId[0]['AssignUserSysId'] : 0;
                    } else {
                        $getUserDetailArray = $this->_crmcustomerObj->getSuperUserSysId($AgencySysId);
                        if (!empty($getUserDetailArray) && ($getUserDetailArray[0]['UserSysId'])) {
                            $AgentSysId = $getUserDetailArray[0]['UserSysId'];
                        }
                    }
                }
                
                
                $leadStage = (isset($leadStage) && !empty($leadStage)) ? $leadStage : 53;
                if ($leadStage == 53) {
                    if (empty($CRMCustSysId) && empty($customerRcord)) {
                        $userArray = array(
                            'EmailId' => $customerEmail,
                            'Salutation' => (isset($salution) && !empty($salution)) ? $salution : 1,
                            'PrimaryContactNumber' => trim($mobilenumber),
                            'countrycode' => trim($countrycode),
                            'FullName' => $fname . ' ' . $lname,
                            'FirstName' => trim($fname),
                            'LastName' => trim($lname),
                            'ActiveDate' => $updatedate,
                            'UpdatedDate' => $updatedate,
                            'CreatedDate' => $updatedate,
                            'IsApproved' => '1',
                            'IsActive' => '1',
                            'IsMarkForDelete' => '0'
                        );
                        //for create new customer
                        //echo '<pre>';print_r($userArray);die('dddhh');
                        $CRMCustSysId = $this->_crmcustomerObj->addCustomer($userArray);
                    }

                    if (empty($customerRcord)) {
                        //create new lead agency account
                        $userLeadArray = array(
                            'AgencySysId' => $AgencySysId,
                            'EmailId' => $customerEmail,
                            'Salutation' => (isset($params['salution'])) ?  trim($params['salution']) : 0,
                            'PrimaryContactNumber' => $mobilenumber,
                            'countrycode' => trim($countrycode),
                            'FullName' => $fname . ' ' . $lname,
                            'FirstName' => trim($fname),
                            'LastName' => trim($lname),
                            'LeadSourceSysId' => $leadSource,
                            'LeadStageSysId' => $leadStage,
                            'AssignUserSysId' => $AgentSysId,
                            'ActiveDate' => $updatedate,
                            'UpdatedDate' => $updatedate,
                            'CreatedDate' => $updatedate,
                            'IsApproved' => '1',
                            'IsActive' => '1',
                            'IsMarkForDelete' => '0',
                            'CampaignSysId' => 0,
                            'B2BType' => $IsB2Bproposal,
                            'B2BAgencySysId' => $B2BAgencySysId,
                        );
                        //for create new customer
                        //echo '<pre>';print_r($userLeadArray);die('www');
                        $AgencyCRMLeadSysId = $this->_crmagencyleadaccountObj->addCustomer($userLeadArray);

                        $agencyuserArray = array(
                            'AgencySysId' => $AgencySysId,
                            'AgencyCRMLeadSysId' => $AgencyCRMLeadSysId,
                            'CRMCustSysId' => $CRMCustSysId,
                            'EmailId' => trim($customerEmail),
                            'Title' => (isset($params['salution'])) ?  trim($params['salution']) : 0,
                            'Logo' => '',
                            'IsfromSM' => '0',
                            'UserId' => '0',
                            'CitySysId' => 0,
                            'StateOrZoneSysId' => 0,
                            'CountrySysId' => 0,
                            'IsEmployee' => '0',
                            'Contacts' => trim($mobilenumber),
                            'countrycode' => trim($countrycode),
                            'JoinDate' => $updatedate,
                            'UserName' => $fname . '' . $lname,
                            'FirstName' => trim($fname),
                            'LastName' => trim($lname),
                            'Relation' => $custrelation,
                            'PassportNo' => $passnumber,
                            'PassportExpiry' => $passexpiry,
                            'DOB' => $custdob,
                            'MarriageAnniversary' => $custanniversary,
                            'RegisterDate' => $updatedate,
                            'UpdateDate' => $updatedate,
                            'JoinDate' => $updatedate,
                            'IsApproved' => '0',
                            'CreatedByUserSysId' => $AgentSysId,
                            'Address' => (isset($customeraddress) && !empty($customeraddress) ? $customeraddress : ''),
                            'PinCode' => (isset($customerpincode) && !empty($customerpincode) ? $customerpincode : '0'),
                            'SecondaryEmail' => (isset($SecondaryEmail) && !empty($SecondaryEmail) ? $SecondaryEmail : ''),
                            'ContactNo1' => (isset($ContactNo1) && !empty($ContactNo1) ? $ContactNo1 : ''),
                            'IsActive' => '1',
                            'paxType' => '1',
//                            'IsMarkForDelete' => '0',
                            'LeadSourceSysId' => $leadSource,
                        );
                        //print_r($agencyuserArray);die;
                        ### Insert Record in to Agency Table as well ########
                        $agencyCustomerData = $this->_agencycustomerObj->addAgencyCustomer($agencyuserArray);
                    }
                } else {

                    $CRMCustSysId = !empty($getcustomerdetails['CustomerSysId']) ? $getcustomerdetails['CustomerSysId'] : $CRMCustSysId;
                    $mobilenumber = !empty($getcustomerdetails['Contacts']) ? $getcustomerdetails['Contacts'] : $mobilenumber;
                    $countrycode = !empty($getcustomerdetails['countrycode']) ? trim($getcustomerdetails['countrycode']) : $countrycode;
                    $fname = !empty($getcustomerdetails['FirstName']) ? trim($getcustomerdetails['FirstName']) : $fname;
                    $lname = !empty($getcustomerdetails['FirstName']) ? trim($getcustomerdetails['LastName']) : $lname;
                    $salution = (isset($getcustomerdetails['Salutation']) && !empty($getcustomerdetails['Salutation'])) ? $getcustomerdetails['Salutation'] : $salution;
                    $customerEmail = (isset($getcustomerdetails['EmailId']) && !empty($getcustomerdetails['EmailId'])) ? $getcustomerdetails['EmailId'] : $customerEmail;
                    $userLeadArray = array(
                        'AgencySysId' => $AgencySysId,
                        'EmailId' => $customerEmail,
                        'Salutation' => (isset($salution) && !empty($salution)) ? $salution : 0,
                        'PrimaryContactNumber' => $mobilenumber,
                        'countrycode' => trim($countrycode),
                        'FullName' => $fname . ' ' . $lname,
                        'FirstName' => trim($fname),
                        'LastName' => trim($lname),
                        'LeadSourceSysId' => $leadSource,
                        'LeadStageSysId' => $leadStage,
                        'AssignUserSysId' => $AgentSysId,
                        'ActiveDate' => $updatedate,
                        'UpdatedDate' => $updatedate,
                        'CreatedDate' => $updatedate,
                        'IsApproved' => '1',
                        'IsActive' => '1',
                        'IsMarkForDelete' => '0',
                        'CampaignSysId' =>  0,
                        'B2BType' => $IsB2Bproposal,
                        'B2BAgencySysId' => $B2BAgencySysId,
                    );
                    //for create lead 
                    $AgencyCRMLeadSysId = $this->_crmagencyleadaccountObj->addCustomer($userLeadArray);
                    $agencyCustomerData = $getcustomerdetails['CustomerSysId'];
                }
                $detail['status'] = true;
                $detail['mobilenumber'] = trim($mobilenumber);
                $detail['countrycode'] = trim($countrycode);
                $detail['fname'] = trim($fname);
                $detail['lname'] = trim($lname);
                $detail['customerEmail'] = trim($customerEmail);
                $detail['CustomerSysId'] = (isset($agencyCustomerData) && !empty($agencyCustomerData)) ? base64_encode($agencyCustomerData) : '';
                $detail['CustomerSysIdNew'] = (isset($agencyCustomerData) && !empty($agencyCustomerData)) ? $agencyCustomerData : '';
                $secureCode = Catabatic_ValidateCustomer::secureCode(trim($detail['CustomerSysId']), 1);
                $detail['SecureCode'] = $secureCode;
                $detail['LeadId'] = trim($AgencyCRMLeadSysId);
    //            echo "<pre>";print_r($detail);die;
                echo json_encode($detail);exit;
            }else{
                echo json_encode(array('status'=>false,'message' => 'Id Missing' ));exit;
            }
        }else{
            echo json_encode(array('status'=>false,'message' => 'Please Use Post Method' ));exit;
        }  
    }
    public function savepackagequeryAction(){         
        $response = array('status' => false, 'Message' => 'Error');
        $Message = '';
        if ($this->getRequest()->isPost()) { 
            $TblAgency = new Travel_Model_TblAgency(); 
            $params = $this->getRequest()->getParams();
            //echo "<pre>";print_r($params);die;
            $PackageSearch = new Travel_Model_PackageSearch(); 
            $crmremarkObj = new Travel_Model_CRM_Remark();
            $modelMaster = new Webservice_Model_Master();
            $headers = getallheaders(); 
            $SecurityKey = isset($headers['SecurityKey']) ? trim($headers['SecurityKey']) : false; 
            $checkAgency = $TblAgency->checkAgency($SecurityKey);
            $AgencySysId = (isset($checkAgency['AgencySysId'])) ?  (int)$checkAgency['AgencySysId'] : 0;
            $customerID = (isset($params['customerID'])) ?  (int)$params['customerID'] : 0;
            $PlanType = 5;
            $AgentSysId = 0;
            if(!empty($AgencySysId) && $customerID > 0){  
                $B2BAgencySysId = (isset($params['B2BAgencySysId'])) ?  (int)$params['B2BAgencySysId'] : 0;
                $B2BUserSysId = (isset($params['B2BUserSysId'])) ?  (int)$params['B2BUserSysId'] : 0;
                $getB2bAgencyData = $TblAgency->getAgencyData($B2BAgencySysId);
                $AgentSysId = (int)$getB2bAgencyData['RMUserSysId'];
                $AgencyType = (int)$getB2bAgencyData['AgencyType'];
                $IsB2Bproposal =   ($AgencyType == 3) ? 3 : 0;
                $TPSysId = (isset($params['TPSysId'])) ?  (int)$params['TPSysId'] : 0;
                $roominfojson = (isset($params['roominfojson'])) ?  trim($params['roominfojson']) : '';
                $PriceRange = (isset($params['PriceRange'])) ?  trim($params['PriceRange']) : '';
                $LeadSysId = (isset($params['LeadSysId'])) ?  (int)$params['LeadSysId'] : 0;
                
                $lead_source = (isset($params['lead_source'])) ?  trim($params['lead_source']) : '';
                $noofdaysfrom = (isset($params['noofdaysfrom'])) ?  (int)$params['noofdaysfrom'] : 0;
                $nooftraveler = (isset($params['travelers'])) ?  (int)$params['travelers'] : 0;
                $going_to_cityname = isset($params['search_going_to_city']) ? trim($params['search_going_to_city']) : '';
                $going_to_cityid = (isset($params['search_going_to_id'])) ?  (int)$params['search_going_to_id'] : 0;
                $going_to_countryid = (isset($params['going_to_countryid'])) ?  (int)$params['going_to_countryid'] : 0;
                
                
                $search_going_from = (isset($params['search_going_from'])) ?  trim($params['search_going_from']) : '';
                $search_going_fromE = explode('__',$search_going_from);
                $going_from_cityid = isset($search_going_fromE[0]) ? $search_going_fromE[0] : 0;
                $going_from_cityname = isset($search_going_fromE[1]) ? $search_going_fromE[1] : '';
                $leadRemark = isset($params['leadRemark']) ?  trim($params['leadRemark']) : '';
                if($TPSysId > 0){
                    $getTravelPlanDetailsByTPSysId = $this->_crmcusttravelplan->getTravelPlanDetailsByTPSysId($TPSysId,'Query'); 
                    $customerDetails = $getTravelPlanDetailsByTPSysId[0]; 
                    $LeadSysId = $getTravelPlanDetailsByTPSysId[0]['LeadSysId'];
                }else{
                    $customerDetails = $this->_crmcustomerObj->GetAgencyCustomerById($customerID);
                }   
                
                if (isset($lead_source) && is_numeric($lead_source) && !empty($lead_source)) {
                    $lead_source = $lead_source;
                } else {
                    if(!empty($lead_source)){
                        $lead_source = $lead_source;
                    } else {
                        $lead_source = "Agency";
                    } 
                    if ($AgentSysId == 0) {
                        $intLeadSourceSysId = $this->_crmcustomerObj->getRoundRobin($AgencySysId, $lead_source, $going_to_cityname, $PlanType);
                        if (isset($intLeadSourceSysId[0]['AssignUserSysId']) && trim($intLeadSourceSysId[0]['AssignUserSysId']) != '') {
                            $AgentSysId = isset($intLeadSourceSysId[0]['AssignUserSysId']) ? (int) $intLeadSourceSysId[0]['AssignUserSysId'] : 0;
                        }
                    }
                    $getOnlyLeadSource = $this->_crmcustomerObj->getLeadSource($AgencySysId, $lead_source); // for Master LeadSouce Creation
                    $lead_source = (isset($getOnlyLeadSource[0]['LeadSourceSysId']) && !empty($getOnlyLeadSource[0]['LeadSourceSysId'])) ? $getOnlyLeadSource[0]['LeadSourceSysId'] : 0;
                     
                } 
                $IsB2BCustomer = isset($customerDetails['IsB2BAgent']) ? $customerDetails['IsB2BAgent'] : 0;
                $createDate = date('Y-m-d H:i:s');
                
                $planbookingID = 'Q/' . date('y');
                $additionalRequirement = '';  
                $search_inclusions = isset($params['search_inclusions']) ? $params['search_inclusions'] : array();
                $search_theme = isset($params['search_theme']) ? $params['search_theme'] : array();
                $search_food = isset($params['search_food']) ? $params['search_food'] : array();
                $hotelpreference = isset($params['hotelpreference']) ? $params['hotelpreference'] : array();
                $hotelpreferenceStr = '';
                if (isset($hotelpreference) && !empty($hotelpreference)) {
                    $hotelpreferenceStr = implode(",", $hotelpreference);
                }
                $PackTypeMask = $InclMask = $FoodTypeMask = '';
                if (!empty($search_theme)) {
                    $packageThemeList = $PackageSearch->getPackageThemeList(); 
                    for ($i = 0; $i < count($search_theme); $i++) {
                        $search_theme_list[] = $this->_crmcusttravelplan->searchForInclusionId($search_theme[$i], $packageThemeList, 'PackType');
                    }
                    if (!empty($search_theme_list)) {
                        $PackTypeMask = '1';
                        $char = '';
                        for ($k = 0; $k < count($packageThemeList); $k++) {
                            $char = in_array($packageThemeList[$k]['PackType'], $search_theme_list) ? '1' : '0';
                            $PackTypeMask .= $char;
                        }
                    }
                    
                }
                if (!empty($search_inclusions)) {
                    $packageInclList = $PackageSearch->getPackageInclusionList(); 
                    for ($i = 0; $i < count($search_inclusions); $i++) {
                        $search_inclusion_list[] = $this->_crmcusttravelplan->searchForInclusionId($search_inclusions[$i], $packageInclList, 'InclId');
                    }
                    if (!empty($search_inclusion_list)) { 
                        $InclMask = '1';
                        for ($k = 0; $k < count($packageInclList); $k++) {
                            $char = in_array($packageInclList[$k]['InclId'], $search_inclusion_list) ? '1' : '0';
                            $InclMask .= $char;
                        }
                    }
                }
                if (!empty($search_food)) {
                    $packageFoodPreferenceList = $PackageSearch->getFoodPreferenceList(); 
                    for ($i = 0; $i < count($search_food); $i++) {
                        $search_food_list[] = $this->_crmcusttravelplan->searchForInclusionId($search_food[$i], $packageFoodPreferenceList, 'CuisineSysId');
                    }
                    if (!empty($search_food_list)) { 
                        $FoodTypeMask = '1';
                        $char = '';
                        for ($k = 0; $k < count($packageFoodPreferenceList); $k++) {
                            $char = in_array($packageFoodPreferenceList[$k]['CuisineSysId'], $search_food_list) ? '1' : '0';
                            $FoodTypeMask .= $char;
                        }
                    }
                }
                $search_specific_date = isset($params['search_specific_date']) ? $params['search_specific_date'] : '';
                if (!empty($search_specific_date)) {
                    $search_specific_dateE = explode('/', $search_specific_date);
                    $plan_start_date = $search_specific_dateE[2] . '-' . $search_specific_dateE[1] . '-' . $search_specific_dateE[0];
                } else {
                    $plan_start_date = '1900-01-01';
                } 
                $PKqueryType = 0;
                 
                $OpsAgentSysId = 0;
                $IsOperationalLead = 0;
                if((int)$going_to_cityid > 0){
                    $getSearchCityId = $modelMaster->getSearchCityId((int)$going_to_cityid,1);
                    if(isset($getSearchCityId['Id']) && $getSearchCityId['Id'] > 0){
                        $going_to_cityid = $getSearchCityId['Id'];
                        $going_to_countryid = $getSearchCityId['CountryId'];
                    }
                }
                $getcityvalue = $going_to_cityid; 
                
                
                
                
                if (empty($LeadSysId)) { 
                    $getStageList = $this->_leadstageObj->getLeadStageSatus('New');
                    $leadstage = (isset($getStageList[0]['TPStatusSysId']) && !empty($getStageList[0]['TPStatusSysId'])) ? $getStageList[0]['TPStatusSysId'] : 0;
                    $getDefaultCampaignByAgencyId = $TblAgency->getDefaultCampaignByAgencyId($AgencySysId);
                    $userLeadArray = array(
                        'AgencySysId' => $AgencySysId,
                        'EmailId' => trim($customerDetails['EmailId']),
                        'Salutation' => (int)$customerDetails['Title'],
                        'PrimaryContactNumber' => $customerDetails['Contacts'],
                        'FullName' => trim($customerDetails['FirstName']) . ' ' . trim($customerDetails['LastName']),
                        'FirstName' => trim($customerDetails['FirstName']),
                        'LastName' => trim($customerDetails['LastName']),
                        'LeadSourceSysId' => (int) $lead_source,
                        'LeadStageSysId' => $leadstage,
                        'AssignUserSysId' => $AgentSysId,
                        'Destination' => isset($going_to_cityname) ? $going_to_cityname : '',
                        'ToDestinationSysId' => isset($going_to_cityid) ? (int) $going_to_cityid : '',
                        'Remarks' => '',
                        'ActiveDate' => $createDate,
                        'UpdatedDate' => $createDate,
                        'CreatedDate' => $createDate,
                        'IsApproved' => '0',
                        'IsActive' => '1',
                        'IsMarkForDelete' => '0',
                        'CampaignSysId' => $getDefaultCampaignByAgencyId,
                        'B2BType' => $IsB2Bproposal,
                        'B2BAgencySysId' => $B2BAgencySysId,
                    );
                    
                    $LeadSysId = $this->_crmagencyleadaccountObj->addCustomer($userLeadArray);
                }
                
                $data = array(
                    'PlanBookingId' => $planbookingID,
                    'AgencySysId' => $AgencySysId,
                    'AgentSysId' => $AgentSysId,
                    'CreatorSysId' => $B2BUserSysId, // frenchisee/ agent UserSysId
                    'StatusType' => 1,
                    'CustomerSysId' => $customerID,
                    'PackTypeMask' => $PackTypeMask,
                    'CuisineMask' => $FoodTypeMask,
                    'InclMask' => $InclMask,
                    'AdditionalReq' => $additionalRequirement,
                    'DestinationPlaces' => isset($going_to_cityname) ? $going_to_cityname : '',
                    'DestinationPlacesSysId' => isset($going_to_cityid) ? (int) $going_to_cityid : '',
                    'SourcePlaceSysId' => isset($going_from_cityid) ? $going_from_cityid : '',
                    'SourcePlaces' => isset($going_from_cityname) ? $going_from_cityname : '',
                    'Cities' => $going_to_cityname,
                    'CityIds' => $getcityvalue,
                    'PlanType' => 5,
                    'MinPrice' => 0,
                    'MaxPrice' => 0,
                    'PriceRange' => $PriceRange,
                    'DaysCountFrom' => $noofdaysfrom,
                    'DaysCountTo' => 0,
                    'MinPax' => $nooftraveler,
                    'RoomInfoJson' => $roominfojson,
                    'HotelPreference' => $hotelpreferenceStr,
                    'StartDate' => $plan_start_date,
                    'CreateDate' => $createDate,
                    'UpdateDate' => $createDate,
                    'IsActive' => 1,
                    'IsAprooved' => 1,
                    'Readymade' => 1,
                    'IsB2Bproposal' => trim($IsB2BCustomer),
                    'PKqueryType' => $PKqueryType,
                    'LeadSourceSysId' => (int) $lead_source,
                    'LeadSysId' => (int) $LeadSysId,
                    'Countries' => $going_to_countryid,
                    'OpsAgentSysId' => $OpsAgentSysId,
                    'IsOperationalLead' => $IsOperationalLead, 
                    'IsB2Bproposal' => $IsB2Bproposal,
                    'B2BAgencySysId' => $B2BAgencySysId,
                );
                //echo $LeadSysId.'-'.$TPSysId."<pre>";print_r($data);die; 
                if (empty($TPSysId)) {
                    $where = "AgencyCRMLeadSysId = " . $LeadSysId;
                    $userArray = array(
                        'IsApproved' => '1',
                        'UpdatedDate' => date('Y-m-d'),
                        'LeadStageSysId' => 50
                    );
                    $this->_crmagencyleadaccountObj->UpdateGtxCrmCustomer($userArray, $where);
                    $lastID = $this->_crmcusttravelplan->addCustomerTravelPlanQuery($data);
                    if (isset($leadRemark) && !empty($leadRemark)) {
                        $remarkArray = array(
                            'AgencySysId' => $AgencySysId,
                            'CustomerSysId' => $customerID,
                            'AgentSysId' => $AgentSysId,
                            'Remarks' => $leadRemark,
                            'TPSysId' => $lastID,
                            'RemarkType' => 1,
                            'IsActive' => '1',
                            'CreatedDate' => $createDate,
                            'IsMarkForDelete' => '0'
                        );
                        $saveRemarkRcord = $crmremarkObj->addRemark($remarkArray);
                    }
                    $Message = 'Query Has been Created For Customer .';
                }else{
                    $lastID = $TPSysId;
                    $whereQuery = "TPSysId = " . $TPSysId;
                    unset($data['CreateDate']);
                    $this->_crmcusttravelplan->UpdateCustomerTravelPlanQuery($data, $whereQuery);
                    if (isset($leadRemark) && !empty($leadRemark)) {
                        $remarkArray = array(
                            'AgencySysId' => $AgencySysId,
                            'CustomerSysId' => $customerID,
                            'AgentSysId' => $AgentSysId,
                            'Remarks' => $leadRemark,
                            'TPSysId' => $lastID,
                            'RemarkType' => 1,
                            'IsActive' => '1',
                            'CreatedDate' => $createDate,
                            'IsMarkForDelete' => '0'
                        );
                        $saveRemarkRcord = $this->_crmremarkObj->addRemark($remarkArray);
                    }
                    $Message = 'Query Has been Updated For Customer .';
                }
                $secureCode = Catabatic_ValidateCustomer::secureCode(base64_encode($lastID), 1);
                $formData = array(
                    'queryId' => $lastID,
                    'code' => $secureCode,
                    'customerID' => $customerID,
                    'date' => $plan_start_date,
                    'roomjson' => $roominfojson,
                    
                    'salutation' => (int)$customerDetails['Title'],
                    'firstName' => $customerDetails['FirstName'],
                    'lastName' => $customerDetails['LastName'],
                    'emailId' => trim($customerDetails['EmailId']),
                    'countrycode' => $customerDetails['countrycode'],
                    'contacts' => $customerDetails['Contacts'],
                    
                );
                
                $response = array('status' => true, 'Message' => $Message, 'lastID' => $lastID, 'lastencodeID' => base64_encode($lastID), 'code' => $secureCode, 'data' => $formData);

            }else{
                $response = array('status' => false, 'Message' => 'Agency Key  Missing.');
            } 
        }else{
                $response = array('status' => false, 'Message' => 'Please use post method.');
        } 
        echo json_encode($response);exit;
    }
    public function updatepackagequeryAction(){         
        $response = array('status' => false, 'Message' => 'Error'); 
        if ($this->getRequest()->isPost()) {  
            $params = $this->getRequest()->getParams(); 
            $TPSysId = isset($params['TPSysId']) ? (int)$params['TPSysId']  : 0;
            $updatedata = isset($params['updatedata']) ? $params['updatedata']  : array();
             
            if($TPSysId > 0 && !empty($updatedata)){
                $whereQuery = "TPSysId = " . $TPSysId;  
                $this->_crmcusttravelplan->UpdateCustomerTravelPlanQuery($updatedata, $whereQuery);
                $response = array('status' => true, 'Message' => 'Proposal Requested Successfully.');
            }
        }
        echo json_encode($response);exit;
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit