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

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/b2bzend/application/modules/crm/controllers/LeadController.php
<?php

/**
 * Copyright 2013 Catabatic Technology Pvt Ltd.
 * All rights reserved
 *
 * @description: Listachievecustomer.php 
 */
class CRM_LeadController extends Catabatic_ValidateGtx {

    private $intLoggedinUserId;
    private $intLoggedinUserGroupSysId;
    private $intLoggedinUserAgencySysId;
    private $intLoggedinUserTrxCurrency;
    public $baseUrl;
    public $_crmcustomerObj = '';
    public $_crmagencyleadaccountObj = '';
    public $_travelplanObj = '';
    public $_travelplanitenaryObj = '';
    public $_travelitenaryaccom = '';
    public $_travelitenaryair = '';
    public $_travelplanevents = '';
    public $_travelplanplaces = '';
    public $_travelplansight = '';
    public $_travelplanmarketwiserate = '';
    public $_travelinsuranceobj = '';
    public $_travelinsumemberobj = '';
    public $_travelplancostsheet = '';
    public $_crmcustomertodoObj = '';
    public $_crmcusttravelplan = '';
    public $_crmcusttravelplanItenaryAccom = '';
    public $_crmcusttravelplanAir = '';
    public $_crmcusttravelplanHotel = '';
    public $_crmcustomertravelItenary = '';
    public $_crmcustomertravelFixed = '';
    public $_crmcustomertravelItenaryEvents = '';
    public $_crmcustomertravelItenaryPlaces = '';
    public $_crmcustomertravelMarketPlaces = '';
    public $_crmcustomertravelPlanRate = '';
    public $_crmcustomertravelSightSeeing = '';
    public $_crmcustomertravelTransport = '';
    public $_crmcustomertravelTerm = '';
    public $_crmremarkObj = '';
    public $_searchhotelObj = '';
    public $_objAirport = '';
    public $_agencycustomerObj = '';
    public $_customermemberObj = '';
    public $_agencyObj = '';
    public $_objPkg = '';
    private $smtpUserName = '';
    private $smtpPassword = '';
    private $smtpPort = '';
    private $smtpHost = '';
    private $fromEmail = '';
    private $fromName = '';
    public $_HtmlPurifier = '';
    public $_agencyuserroleObj;
    public $_leadstageObj;
    public $arrCustomerSysId = array();
    public $statustypeIDForExpiredArr = [5, 6, 7, 8, 13, 17];
    public $statustypenameForExpiredArr = [
        'Confirmed - Payment Pending',
        'Confirmed - PaymentFailed',
        'Confirmed - Booking Pending',
        'Confirmed - Payment made',
        'Confirmed - Partial Payment',
        'Proposal Booked',
    ];

    public function init() {
        parent::init();
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $this->baseUrl = $request->getScheme() . '://' . $request->getHttpHost();
        $this->view->headScript()->appendFile($this->baseUrl . '/public/assets/js/jquery-ui.js');
        $sessionLogin_user = new Zend_Session_Namespace('sessionLogin_user');
        // $sessionLogin_user->lock();
        $sessionLogin_lead_customer = new Zend_Session_Namespace('customerlead');
        //$lead_customer->lock();
        //Zend_Session::rememberMe(60 * 60 * 24 * 7);
        #get session variable
        $this->intLoggedinUserId = $sessionLogin_user->intLoggedinUserId;
        $this->intLoggedinUserGroupSysId = $sessionLogin_user->intLoggedinUserGroupSysId;
        $this->intLoggedinUserAgencySysId = $sessionLogin_user->intLoggedinUserAgencySysId;
        $this->intLoggedinUserTrxCurrency = $sessionLogin_user->intLoggedinUserTrxCurrency;
        $this->_crmcustomerObj = new Travel_Model_CRM_Customer();
        $this->_crmagencyleadaccountObj = new Travel_Model_CRM_AgencyLeadAccount();
        $this->_travelplanObj = new Travel_Model_Package_PackageModel();
        $this->_travelplanitenaryObj = new Travel_Model_Package_TravelPlanItenary();
        $this->_travelitenaryaccom = new Travel_Model_Package_TravelPlanItenaryAccom();
        $this->_travelitenaryair = new Travel_Model_Package_TravelPlanItenaryAir();
        $this->_travelplanevents = new Travel_Model_Package_TravelPlanItenaryEvents();
        $this->_travelplanplaces = new Travel_Model_Package_TravelPlanItenaryPlaces();
        $this->_travelplansight = new Travel_Model_Package_TravelPlanItenarySight();
        $this->_travelplanmarketwiserate = new Travel_Model_Package_TravelPlanItenaryMarketWise();
        $this->_travelinsuranceobj = new Travel_Model_CRM_CustomerTravelInsurance();
        $this->_travelinsumemberobj = new Travel_Model_CRM_CustomerTravelInsuranceMember();
        $this->_travelplancostsheet = new Travel_Model_CRM_CostSheet();
        $this->_crmcustomertodoObj = new Travel_Model_CRM_AgencyCustomerTodo();
        $this->_crmcusttravelplan = new Travel_Model_CRM_CustomerTravelPlan();
        $this->_crmcusttravelplanItenaryAccom = new Travel_Model_CRM_CustomerTravelPlanAccom();
        $this->_crmcusttravelplanAir = new Travel_Model_CRM_CustomerTravelPlanAir();
        $this->_crmcusttravelplanHotel = new Travel_Model_CRM_CustomerTravelPlanHotel();
        $this->_crmcustomertravelItenary = new Travel_Model_CRM_CustomerTravelItenary();
        $this->_crmcustomertravelFixed = new Travel_Model_CRM_CustomerTravelPlanFixed();
        $this->_crmcustomertravelItenaryEvents = new Travel_Model_CRM_CustomerTravelItenaryEvents();
        $this->_crmcustomertravelItenaryPlaces = new Travel_Model_CRM_CustomerTravelItenaryPlaces();
        $this->_crmcustomertravelMarketPlaces = new Travel_Model_CRM_CustomerTravelItenaryMarketRate();
        $this->_crmcustomertravelPlanRate = new Travel_Model_CRM_CustomerTravelPackRate();
        $this->_crmcustomertravelSightSeeing = new Travel_Model_CRM_CustomerTravelItenarySightSeeing();
        $this->_crmcustomertravelTransport = new Travel_Model_CRM_CustomerTravelTransport();
        $this->_crmcustomertravelTerm = new Travel_Model_CRM_CustomerTravelTerm();
        $this->_crmremarkObj = new Travel_Model_CRM_Remark();
        $this->_searchhotelObj = new Travel_Model_TblHotel();
        $this->_objAirport = new Travel_Model_TblAirport();
        $this->_agencycustomerObj = new Travel_Model_CRM_AgencyCustomer();
        $this->_customermemberObj = new Travel_Model_CRM_CustomerMember();
        $this->_agencyObj = new Travel_Model_TblAgency();

        $objFlight = new Travel_Model_TblFlight();
        $this->_objPkg = new Travel_Model_PackageSearch();
        // this->_objPackage = new Travel_Model_PackageSearch();
        //  $packageInclusionList = $objPackage->getPackageInclusionList();
        ############## For HTML Purifer ####################
        $this->_HtmlPurifier = new Zend_Filter_HtmlPurifier();
        // unlocking read-only lock
        /* if ($sessionLogin_user->isLocked()) {
          $sessionLogin_user->unLock();
          } */

        #### Script to send email ####

        $aConfig = $this->getInvokeArg('bootstrap')->getOptions();
        $this->smtpUserName = $aConfig['smtpUserName'];
        $this->smtpPassword = $aConfig['smtpPassword'];
        $this->smtpPort = $aConfig['smtpPort'];
        $this->smtpHost = $aConfig['smtpHost'];
        $this->fromEmail = $aConfig['fromEmail'];
        $this->fromName = $aConfig['fromName'];

        //for country list
        $objCountry = new Travel_Model_TblCountry();
        $countryList = $objCountry->getCountryList();
        $this->view->countryList = $countryList;
        #### Script to send email End ####
    }

    public function indexAction() {
        //echo "<pre>";print_r($_SESSION);die;
        $sessionLogin_user = new Zend_Session_Namespace('sessionLogin_user');
        $AgencySysId = $sessionLogin_user->intLoggedinUserAgencySysId;
        $AgentSysId = $sessionLogin_user->intLoggedinUserId;
        $ReportingToSysId = $sessionLogin_user->ReportingToSysId;

        $this->_crmcusttravelplan = new Travel_Model_CRM_CustomerTravelPlan();
        $type = $this->getRequest()->getParam('type');
        $leadFilter = $this->getRequest()->getParam('filter', 'fresh');
        $orderBy = $this->_HtmlPurifier->filter($this->getRequest()->getParam('order'));
        $this->view->arrEmailTemplates = $this->_agencyObj->getAgencyEmailTemplates($AgencySysId);
        //update assigned lead header notification 
        $type = $this->getRequest()->getParam('type');
        $uid = $this->getRequest()->getParam('uid');
        if (isset($type) && isset($uid) && !empty($type) && !empty($uid)) {
            $type = $this->_HtmlPurifier->filter($type);
            $uid = $this->_HtmlPurifier->filter(base64_decode($uid));
            if ($uid == $sessionLogin_user->intLoggedinUserId) {
                $where = "UserSysId = " . $uid . " AND MsgType = 3 AND ModuleType = 1";
                $date = date('Y-m-d H:i:s');
                $userArray = array(
                    'IsMarkForDel' => '1',
                    'Accepted' => '1',
                    'IsActive' => '0',
                    'UpdateDate' => $date,
                );
                $this->_agencyuserObj = new Travel_Model_CRM_AgencyUserInbox();
                $updatedUserInbox = $this->_agencyuserObj->updateNotification($userArray, $where);
            }
        }
        //# end of update assigned lead header notification 



        $getData = array();
        if ($this->getRequest()->getPost()) {
            $getData = $this->getRequest()->getPost();
            $getData['POST'] = 1;
            $getData = $this->_HtmlPurifier->filterArray($getData);
        }

        if (isset($type) && !empty($type)) {
            $getData['leadType_' . $type] = $type;
        }

        //echo "<pre>";print_r($getData);die;
        isset($orderBy) ? ($getData['order'] = $orderBy) : '';
        if (isset($getData['assigUnassignFilter']) && ($getData['assigUnassignFilter'] == 1)) {
            $getData['UserSysId'] = $getData['agencyUserFilter'];
        } else if (isset($getData['assigUnassignFilter']) && ($getData['assigUnassignFilter'] == 2)) {
            $getData['UserSysId'] = 0;
        } else {
            $getData['UserSysId'] = 0;
        }

        $this->view->searchData = $getData;
        $this->view->filterFormDisplay = $this->getRequest()->getPost();
        $LeadListArr = array();
        $getCustomerList = array();

        $roleID = $sessionLogin_user->UserRole;
        $this->_agencyuserroleObj = new Travel_Model_TblAgencyUserRole();
        $getRoleDetail = $this->_agencyuserroleObj->getDataByRole($roleID);
        $uid = $this->getRequest()->getParam('uid');
        if (isset($type) && isset($uid) && !empty($type) && !empty($uid)) {
            $type = $this->_HtmlPurifier->filter($type);
            $uid = $this->_HtmlPurifier->filter(base64_decode($uid));
            if ($uid == $sessionLogin_user->intLoggedinUserId) {
                $where = "UserSysId = " . $uid . " AND MsgType = 3 AND ModuleType = 1";
                $date = date('Y-m-d H:i:s');
                $userArray = array(
                    'IsMarkForDel' => '1',
                    'Accepted' => '1',
                    'IsActive' => '0',
                    'UpdateDate' => $date,
                );
                $this->_agencyuserObj = new Travel_Model_CRM_AgencyUserInbox();
                $updatedUserInbox = $this->_agencyuserObj->updateNotification($userArray, $where);
            }
        }
        $this->_crmagencyleadaccountObj->ReportingToSysId = $ReportingToSysId;
        $getleadSource = $this->_crmcustomerObj->getLeadSourceByAgency($AgencySysId);

        if ($leadFilter == 'callback') {
            if (isset($getData['lead_stage']) && $getData['lead_stage'] != '') {
                $getData['lead_stage'] = $getData['lead_stage'];
            } else {
                $getData['lead_stage'] = 52;
            }
        } else if ($leadFilter == 'fresh') {
            if (isset($getData['lead_stage']) && $getData['lead_stage'] != '') {
                $getData['lead_stage'] = $getData['lead_stage'];
            } else {
                $getData['lead_stage'] = array(52,53);
            }
        } else if ($leadFilter == 'overall') {
            if (isset($getData['lead_stage']) && $getData['lead_stage'] != '') {
                $getData['lead_stage'] = $getData['lead_stage'];
            } else {
                $getData['lead_stage'] = array(0,45, 46, 47, 48, 49, 50, 51, 52, 53, 159, 161, 162, 163);
            }
        } else {
            $getData['lead_stage'] = array(0,45, 46, 47, 48, 49, 51, 50, 52, 53, 159, 161, 162, 163);
        }
        $this->view->searchData = $getData;
        $getAllB2bAgency = $this->_crmagencyleadaccountObj->getAllB2bAgency($AgencySysId);

        if (($getRoleDetail['IsAdmin'] == True) || $getRoleDetail['IsSuperAdmin'] == True) {
            $getData['AgencySysId'] = $getAllB2bAgency;
            $getData['MainAgencySysId'] = $AgencySysId;
            $getCustomerList = $this->_crmagencyleadaccountObj->GetGtxCustomerApproved($getData);
        } else {
            $getData['UserSysId'] = $AgentSysId;
            $leadSourcesIds = array();
            $leadSourceExplodedRes = '';
            $getCustomerList = array();

            if (!empty($getleadSource)) {
                foreach ($getleadSource as $k => $v) {
                    $leadSourcesIds[] = $v['LeadSourceSysId'];
                }
                $leadSourceExplodedRes = implode(",", $leadSourcesIds);
                $getData['AgentSourceIds'] = $leadSourceExplodedRes;
                if ($this->getRequest()->isPost()) {
                    $getData['AgencySysId'] = $getAllB2bAgency;
                    $getData['MainAgencySysId'] = $AgencySysId;
                    $getData['AgentSourceIds'] = $leadSourceExplodedRes;
                    $this->view->searchData = $getData;
                    $getCustomerList = $this->_crmagencyleadaccountObj->GetGtxCustomerApproved($getData, $AgencySysId);
                } else {
                    $getData['AgencySysId'] = $getAllB2bAgency;
                    $getData['MainAgencySysId'] = $AgencySysId;
                    $getData['AgentSourceIds'] = "";
                    $getCustomerList = $this->_crmagencyleadaccountObj->GetGtxCustomerApproved($getData, $AgencySysId);
                }
            }
        }

        $responseArray = array();
        $UnAssignedLead = 0;
        $AgencyCRMLeadSysIds = array();
        $i = 0;
        // echo "<pre>";print_r($getCustomerList);die;
//        foreach ($getCustomerList as $key => $getCustomerListArr) {
//            $UnAssignedLead = (trim($getCustomerListArr['AgencyUserFirstName']) == '') ? $UnAssignedLead + 1 : $UnAssignedLead;
//            if (!in_array($getCustomerListArr['AgencyCRMLeadSysId'], $AgencyCRMLeadSysIds)) {
//                $responseArray[$i]['Title'] = $getCustomerListArr['CompanyName'];
//                $responseArray[$i]['ActiveDate'] = $getCustomerListArr['ActiveDate'];
//                $responseArray[$i]['B2BType'] = $getCustomerListArr['B2BType'];
//                $responseArray[$i]['AgencyUserFirstName'] = $getCustomerListArr['AgencyUserFirstName'];
//                $responseArray[$i]['AgencyUserLastName'] = $getCustomerListArr['AgencyUserLastName'];
//                $responseArray[$i]['FullName'] = $getCustomerListArr['FullName'];
//                $responseArray[$i]['EmailId'] = $getCustomerListArr['EmailId'];
//                $responseArray[$i]['Remarks'] = $getCustomerListArr['Remarks'];
//                $responseArray[$i]['countrycode'] = $getCustomerListArr['countrycode'];
//                $responseArray[$i]['PrimaryContactNumber'] = $getCustomerListArr['PrimaryContactNumber'];
//                $responseArray[$i]['ActiveDate'] = $getCustomerListArr['ActiveDate'];
//                $responseArray[$i]['LeadSource'] = $getCustomerListArr['LeadSource'];
//                $responseArray[$i]['LeadStageSysId'] = $getCustomerListArr['LeadStageSysId'];
//                $responseArray[$i]['AgencyCRMLeadSysId'] = $getCustomerListArr['AgencyCRMLeadSysId'];
//                $responseArray[$i]['AgentSysId'] = $getCustomerListArr['AssignUserSysId'];
//                $responseArray[$i]['TPSysId'] = '';
//                $responseArray[$i]['IsB2BAgent'] = $getCustomerListArr['IsB2BAgent'];
//                $responseArray[$i]['hasFollowUp'] = $getCustomerListArr['Subject'];
//                $responseArray[$i]['hasIteration'] = '';
//                $responseArray[$i]['MasterTPSysId'] = '';
//                $responseArray[$i]['VersionId'] = '';
//                $responseArray[$i]['RoomInfoJson'] = $getCustomerListArr['RoomInfoJson'];
//                $responseArray[$i]['CreateDate'] = '';
//                $responseArray[$i]['CustomerSysId'] = $getCustomerListArr['CustomerSysId'];
//                $responseArray[$i]['PlanBookingId'] = '';
//                $responseArray[$i]['PlanType'] = '';
//                $responseArray[$i]['TravelDate'] = $getCustomerListArr['startDate'];
//                $responseArray[$i]['Noofdays'] = $getCustomerListArr['Noofdays'];
//                $responseArray[$i]['IsPriceShared'] = '';
//                $responseArray[$i]['DestinationPlaces'] = '';
//                $responseArray[$i]['Cities'] = $getCustomerListArr['Destination'];
//                $responseArray[$i]['FromCities'] = $getCustomerListArr['FromDestination'];
//                $responseArray[$i]['NetPrice'] = '';
//                $responseArray[$i]['ChkEmailId'] = $getCustomerListArr['ChkEmailId'];
//                $responseArray[$i]['StatusType'] = '';
//                $responseArray[$i]['UpdateDate'] = $getCustomerListArr['UpdatedDate'];
//                $responseArray[$i]['OwnerAgentFirstName'] = trim($getCustomerListArr['AgencyUserFirstName']);
//                $responseArray[$i]['OwnerAgentLastName'] = trim($getCustomerListArr['AgencyUserLastName']);
//                $responseArray[$i]['Owner'] = (isset($getCustomerListArr['AgencyUserFirstName']) && !empty($getCustomerListArr['AgencyUserFirstName'])) ? stripslashes(trim($getCustomerListArr['AgencyUserFirstName'])) . "&nbsp;" . stripslashes(trim($getCustomerListArr['AgencyUserLastName'])) : 'Admin';
//                $responseArray[$i]['TYPE'] = 'LEAD';
//                $AgencyCRMLeadSysIds[] = $getCustomerListArr['AgencyCRMLeadSysId'];
//            }
//            $i++;
//        }
        $this->view->leadSourceList = $getleadSource;
        $this->view->UnAssignedLead = $UnAssignedLead;

        //echo '<pre>';print_r($responseArray);die;
        $this->_leadstageObj = new Travel_Model_TblLeadStage();
        $crmtravelplanstatusObj = new Travel_Model_CRM_TravelPlanStatus();
        $getStageList = $crmtravelplanstatusObj->GetTravelPlanStatusByType(3);
        $crmProcedure = new Crm_Model_CrmProcedure();
        $resultSetCount = array();

        if (!empty($getData['dateFrom']) && !empty($getData['dateTo'] && $getData['dateTo'] != '__-__-____' && $getData['dateFrom'] != '__-__-____')) {
            $dateFromEx = explode('-', $getData['dateFrom']);
            $dateToEx = explode('-', $getData['dateTo']);
            $fromDate = $dateFromEx[2] . '-' . $dateFromEx[1] . '-' . $dateFromEx[0];
            $toDays = $dateToEx[2] . '-' . $dateToEx[1] . '-' . $dateToEx[0];
            // $toDays = date('Y-m-d', strtotime($dateTo . ' +1 days'));
        } else {
            $displayAllLeadArray = array(2645, 33872, 24843);
            if (in_array($AgencySysId, $displayAllLeadArray)) {
                $date = strtotime(date("Y-m-d", strtotime("-24 month")));
            } else {
                $date = strtotime(date("Y-m-d", strtotime("-12 month")));
            }
            $fromDate = date("Y-m-d", $date);
            $toDays = date("Y-m-d");
        }

        if (($getRoleDetail['IsAdmin'] == True) || $getRoleDetail['IsSuperAdmin'] == True) {
            $agencyUser = $this->_crmcustomerObj->getAllAgencyUserList('', $AgencySysId);
          //  $resultSetCount = $crmProcedure->crmLeadCount($getRoleDetail['IsAdmin'], $AgencySysId, '', $fromDate, $toDays);
            $IsAdmin = true;
        } else {
            $agencyUser = $this->_crmcustomerObj->getAllAgencyUserList('', $AgencySysId, $ReportingToSysId);
            //$agencyUser = $this->_crmcustomerObj->getAllAgencyUserList('', $AgencySysId);
           // $resultSetCount = $crmProcedure->crmLeadCount($getRoleDetail['IsAdmin'], $AgencySysId, $ReportingToSysId, $fromDate, $toDays);
            $IsAdmin = false;
        }
        // echo '<pre>';print_r($resultSetCount);exit;
        $this->view->IsAdmin = $IsAdmin;
        $this->view->resultSetCount = $resultSetCount;
        $getData['orderQueryDate'] = SORT_DESC;
        $columnNameOrder = 'UpdateDate';
        if (isset($orderBy) && !empty($orderBy)) {
            $order_type = explode('_', $orderBy);
            if ($order_type[0] == 'queryDate' && $order_type[1] == 1) {
                $columnNameOrder = 'ActiveDate';
                $getData['orderQueryDate'] = SORT_ASC;
            } else if ($order_type[0] == 'travelDate' && $order_type[1] == 1) {
                $columnNameOrder = 'TravelDate';
                $getData['orderQueryDate'] = SORT_ASC;
            } else if ($order_type[0] == 'lastUpdate' && $order_type[1] == 1) {
                $columnNameOrder = 'UpdateDate';
                $getData['orderQueryDate'] = SORT_ASC;
            } else if ($order_type[0] == 'destination' && $order_type[1] == 1) {
                $columnNameOrder = 'DestinationPlaces';
                $getData['orderQueryDate'] = SORT_ASC;
            } else {
                $getData['orderQueryDate'] = SORT_DESC;
            }
        }
        if (!empty(@$responseArray)) {
            foreach ($responseArray as $key => $part) {
                $sort[$key] = ($part[$columnNameOrder] == 'UpdateDate' || $part[$columnNameOrder] == 'ActiveDate' || $part[$columnNameOrder] == 'TravelDate') ? strtotime($part[$columnNameOrder]->format('Y-m-d H:i:s')) : $part[$columnNameOrder];
            }
            array_multisort($sort, $getData['orderQueryDate'], $responseArray);
        }
        //echo "<pre>";print($getCustomerList);exit;
        $paginator = Zend_Paginator::factory($getCustomerList);
        $pageNumber = $this->_getParam('page', 1);
        $paginator->setCurrentPageNumber($pageNumber);
        $paginator->setItemCountPerPage(GRID_PER_PAGE_RECORD_COUNT);
        $this->view->paginator = $paginator;
        $this->view->paginator1 = $paginator;
        $this->view->messages = $this->_helper->flashMessenger->getMessages();
        $ARR_SALUTION = unserialize(ARR_SALUTION);
        $ARR_CUSTOMER_RELATION = unserialize(ARR_CUSTOMER_RELATION);
        $this->view->ARR_CUSTOMER_RELATION = $ARR_CUSTOMER_RELATION;
        $this->view->ARR_SALUTION = $ARR_SALUTION;
        $this->view->leadStageList = $getStageList;
        $this->view->agencyUser = $agencyUser;
        $this->view->getRoleDetail = $getRoleDetail;
        $this->view->getData = $getData;
        $this->view->countLead = is_array($getCustomerList) ? count($getCustomerList) : '';
        $this->view->countQuery = $paginator->getTotalItemCount();
        $this->view->ReportingToSysId = $ReportingToSysId;
        $this->view->leadFilter = $leadFilter;
    }

    public function editLeadDataAction() {
        $sessionLogin_user = new Zend_Session_Namespace('sessionLogin_user');
        $AgencySysId = $sessionLogin_user->intLoggedinUserAgencySysId;
        if ($this->getRequest()->isPost()) {
            $getData = $this->getRequest()->getParams();
            //echo "<pre>";print_r($getData);die;
            if (!empty(trim($getData['mobileNo'])) || !empty(trim($getData['mEmailId']))) {
                if (trim($getData['Type']) == 'Email') {
                    $saveData = array(
                        'EmailId' => trim($getData['mEmailId']),
                    );
                } else {
                    $saveData = array(
                        'countrycode' => $getData['DefaultCountryCode'],
                        'PrimaryContactNumber' => $getData['mobileNo']
                    );
                }

                $where = array(
                    'AgencyCRMLeadSysId=?' => $getData['AgencyCRMLeadSysId']
                );
                error_reporting(E_ALL);
                //  $return = $this->_crmagencyleadaccountObj->updateTable("TB_Agency_CRM_LeadAccount",$saveData,$where);
                $return = $this->_crmagencyleadaccountObj->updateAgencyLeadData($saveData, $where);
                $mobileNo = (isset($getData['mobileNo']) && trim($getData['mobileNo']) != '') ? trim($getData['mobileNo']) : '';
                if (trim($getData['Type']) == 'Phone' && !empty($AgencySysId) && !empty($mobileNo)) {
                    $agencyuserArray = array(
                        'countrycode' => trim($getData['DefaultCountryCode']),
                    );
                    $whereAgencyCustomer = " AgencySysId=" . trim($AgencySysId) . " AND Contacts ='" . trim($mobileNo) . "'";
                    try {
                        $ret = $this->_agencycustomerObj->UpdateAgencyCustomer($agencyuserArray, $whereAgencyCustomer);
                    } catch (Zend_File_Transfer_Exception $e) {
                        echo $this->view->error_msg = $e->getMessage();
                        die;
                    }
                }


                //  echo ($return); die;
                if (trim($getData['Type']) == 'Email') {
                    echo json_encode(array('status' => true, 'AgencyCRMLeadSysId' => $getData['AgencyCRMLeadSysId'], 'mEmailId' => trim($getData['mEmailId'])));
                } else {
                    echo json_encode(array('status' => true, 'AgencyCRMLeadSysId' => $getData['AgencyCRMLeadSysId'], 'countrycode' => $getData['DefaultCountryCode'], 'PrimaryContactNumber' => $getData['mobileNo']));
                }
            }
        }
        exit;
    }

    public function leadBulkUploadAction() { 
        $sessionLogin_user = new Zend_Session_Namespace('sessionLogin_user');
        $AgencySysId = $sessionLogin_user->intLoggedinUserAgencySysId;
        $AgentSysId = $sessionLogin_user->intLoggedinUserId;
        $this->_leadstageObj = new Travel_Model_TblLeadSource();
        if ($this->getRequest()->isPost()) {
            $MasterCampSysId = (isset($_POST['MasterCampSysId']) && $_POST['MasterCampSysId'] != '') ? (int) $_POST['MasterCampSysId'] : 0;
            # start : code for image uploading
            $excelFileName = $_FILES['bulkuploadbtn']['name'];
            $ext = @substr($excelFileName, strrpos($excelFileName, '.'));
            $excelFileNameNew = $excelFileName;
            $upload = new Zend_File_Transfer_Adapter_Http();
            $this->upload_path = 'public/upload/excel/';
            $upload->setDestination($this->upload_path);
            //            $file   = $upload->getFileName();
            if (($ext == ".csv") || ($ext == ".xls") || ($ext == ".xlsx")) {
                try {
                    $upload->receive();
                } catch (Zend_File_Transfer_Exception $e) {
                    echo $this->view->error_msg = $e->getMessage();
                    die;
                }
                # end : code for image uploading
                $file = $this->upload_path . $excelFileNameNew;
                $autoloader = Zend_Loader_Autoloader::getInstance();
                $autoloader->registerNamespace('PHPExcel_');
                $phpexcel_obj = new PHPExcel_Classes_Readexcel;
                $finalData = $phpexcel_obj->importFromExcel($file);
                $leadListArray = array();
                $error = array();
                $i = 0;
                
                foreach ($finalData as $listArray) {
                   if($listArray[0] != '' && $listArray[1] != '') {
                    if (trim($listArray[0]) == '') {
                        $error[$i]['EMAILID'] = 'EmailId cannot be empty.' . "</br>";
                    }
                    if (trim($listArray[0]) != '' && !filter_var(trim($listArray[0]), FILTER_VALIDATE_EMAIL) === true) {
                        $error[$i]['EMAILID'] = 'please enter a valid email address.' . "</br>";
                    }
                    if (trim($listArray[1]) == '') {
                        $error[$i]['MOBILE'] = 'Mobile cannot be empty.' . "</br>";
                    }
                    //if (trim($listArray[1]) != '' && (is_numeric(trim($listArray[1])) == false && (strlen(trim($listArray[1])) > 6)) {
                    if (trim($listArray[2]) != '' && (is_numeric(trim($listArray[1])) == false || (strlen(trim($listArray[1])) < 6 && strlen(trim($listArray[1])) > 14))) {
                        $error[$i]['MOBILE'] = 'Mobile not in correct format.' . "</br>";
                    }
                    if (trim($listArray[3]) == '') {
                        $error[$i]['FIRSTNAME'] = 'First Name cannot be empty.' . "</br>";
                    }
                    /* if(trim($listArray[3])==''){
                      $error[$i]['LASTNAME']='Last Name cannot be empty.'."</br>";
                      } */
                    if (trim($listArray[5]) == '') {
                        $error[$i]['SOURCE'] = 'Source cannot be empty.' . "</br>";
                    }
                    $leadSource = $this->_leadstageObj->GetLeadSourceById(trim($listArray[5]), $AgencySysId);
                    //echo "<pre>";print_r($leadSource);exit;
                    if (isset($listArray[0]) && trim($listArray[0]) != '') {
                        try {
                            $customerDetails = $this->_crmcustomerObj->ChkEmailWithResponse(trim($listArray[0]), $AgencySysId);
                            if (isset($customerDetails['CustomerSysId'])) {
                                $error[$i]['EMAILID'] = 'EmailId Already exist.please try another' . "</br>";
                            }
                        } catch (Zend_Exception $e) {
                            $error[$i]['EMAILID'] = $e->getMessage();
                        }
                    }
                    if (isset($listArray[1]) && trim($listArray[1]) != '') {
                        $customerDetails = $this->_crmcustomerObj->ChkMobileExistInAgency(trim($listArray[1]), $AgencySysId, '');
                        if ($customerDetails) {
                            $error[$i]['MOBILE'] = 'Mobile Already exist.please try another' . "</br>";
                        }
                    }
                    if (empty($leadSource)) {
                        $error[$i]['SOURCE'] = 'Source not exist . Source Id not matched with source listing.' . "</br>";
                    }
                    $leadListArray[$i]['ERROR'] = $error;
                    $leadListArray[$i]['EMAILID'] = stripslashes(trim($listArray[0]));
                    $leadListArray[$i]['COUNTYCODE'] = stripslashes(trim($listArray[1]));
                    $leadListArray[$i]['MOBILE'] = stripslashes(trim($listArray[2]));
                    $leadListArray[$i]['FIRSTNAME'] = stripslashes(trim($listArray[3]));
                    $leadListArray[$i]['LASTNAME'] = stripslashes(trim($listArray[4]));
                    $leadListArray[$i]['SOURCE'] = stripslashes(trim($leadSource['Title']));
                    $leadListArray[$i]['SOURCEID'] = stripslashes(trim($listArray[5]));
                    $leadListArray[$i]['FROMDESTINATION'] = isset($listArray[6]) ? stripslashes(trim($listArray[6])) : '';
                    $leadListArray[$i]['TODESTINATION'] = isset($listArray[7]) ? stripslashes(trim($listArray[7])) : '';
                    $leadListArray[$i]['REMARKS'] = isset($listArray[8]) ? stripslashes(trim($listArray[8])) : '';
                    $leadListArray[$i]['startDate'] = isset($listArray[9]) ? stripslashes(trim($listArray[9])) : '';
                    $leadListArray[$i]['RoomInfoJson'] = isset($listArray[10]) ? stripslashes(trim($listArray[10])) : '';
                    $leadListArray[$i]['Noofdays'] = isset($listArray[11]) ? stripslashes(trim($listArray[11])) : '';
                    $leadListArray[$i]['MasterCampSysId'] = $MasterCampSysId;
                    unset($error[$i]);
                    $i++;
                   }
                }
                // echo "<pre>";print_r($listArray);die;
                $this->view->leadList = $leadListArray;
            }
        }
        $leadSouceList = $this->_leadstageObj->GetAllSouce($AgencySysId);
        $this->view->leadSouceList = $leadSouceList;
    }

    public function leadB2bBulkUploadAction() {  
        $sessionLogin_user = new Zend_Session_Namespace('sessionLogin_user');
        $AgencySysId = $sessionLogin_user->intLoggedinUserAgencySysId;
        $AgentSysId = $sessionLogin_user->intLoggedinUserId;
        $this->_leadstageObj = new Travel_Model_TblLeadSource();
        if ($this->getRequest()->isPost()) {
            # start : code for image uploading
            $MasterCampSysId = (isset($_POST['MasterCampSysId']) && $_POST['MasterCampSysId'] != '') ? (int) $_POST['MasterCampSysId'] : 0;
            $excelFileName = $_FILES['bulkuploadbtn']['name'];
            $ext = @substr($excelFileName, strrpos($excelFileName, '.'));
            $excelFileNameNew = $excelFileName;
            $upload = new Zend_File_Transfer_Adapter_Http();
            $this->upload_path = 'public/upload/excel/';
            $upload->setDestination($this->upload_path);
            //            $file   = $upload->getFileName();
            if (($ext == ".csv") || ($ext == ".xls") || ($ext == ".xlsx")) {
                try {
                    $upload->receive();
                } catch (Zend_File_Transfer_Exception $e) {
                    echo $this->view->error_msg = $e->getMessage();
                    die;
                }
                # end : code for image uploading

                $file = $this->upload_path . $excelFileNameNew;
                $autoloader = Zend_Loader_Autoloader::getInstance();
                $autoloader->registerNamespace('PHPExcel_');

                $phpexcel_obj = new PHPExcel_Classes_Readexcel;

                $finalData = $phpexcel_obj->importFromExcel($file);
                $leadListArray = array();
                $error = array();
                $i = 0;
                //print_r($finalData);die;
                foreach ($finalData as $listArray) {
                    if (trim($listArray[0]) == '') {
                        $error[$i]['EMAILID'] = 'EmailId cannot be empty.' . "</br>";
                    }
                    if (trim($listArray[0]) != '' && !filter_var(trim($listArray[0]), FILTER_VALIDATE_EMAIL) === true) {
                        $error[$i]['EMAILID'] = 'please enter a valid email address.' . "</br>";
                    }
                    if (trim($listArray[1]) == '') {
                        $error[$i]['COUNTYCODE'] = 'Country Code cannot be empty.' . "</br>";
                    }
                    if (trim($listArray[2]) == '') {
                        $error[$i]['MOBILE'] = 'Mobile cannot be empty.' . "</br>";
                    }
                    if (trim($listArray[2]) != '' && (is_numeric(trim($listArray[2])) == false || (strlen(trim($listArray[2])) < 6 && strlen(trim($listArray[2])) > 14))) {
                        $error[$i]['MOBILE'] = 'Mobile not in correct format.' . "</br>";
                    }
                    if (trim($listArray[3]) == '') {
                        $error[$i]['FIRSTNAME'] = 'First Name cannot be empty.' . "</br>";
                    }
                    /* if(trim($listArray[3])==''){
                      $error[$i]['LASTNAME']='Last Name cannot be empty.'."</br>";
                      } */
                    if (trim($listArray[5]) == '') {
                        $error[$i]['SOURCE'] = 'Source cannot be empty.' . "</br>";
                    }
                    if (trim($listArray[6]) == '') {
                        $error[$i]['SOURCE'] = 'Company Name cannot be empty.' . "</br>";
                    }
                    if (trim($listArray[7]) == '') {
                        $error[$i]['SOURCE'] = 'B2B Type cannot be empty.' . "</br>";
                    }
                    $leadSource = $this->_leadstageObj->GetLeadSourceById(trim($listArray[5]), $AgencySysId);
                    if (isset($listArray[0]) && trim($listArray[0]) != '') {
                        $customerDetails = $this->_crmcustomerObj->ChkEmailWithResponseB2B(trim($listArray[0]), $AgencySysId);
                        if (isset($customerDetails['CustomerSysId'])) {
                            $error[$i]['EMAILID'] = 'EmailId Already exist.please try another' . "</br>";
                        }
                    }
                    if (isset($listArray[2]) && trim($listArray[2]) != '') {
                        $customerDetails = $this->_crmcustomerObj->ChkMobileExistInAgencyB2B(trim($listArray[1]), $AgencySysId, '');
                        if ($customerDetails) {
                            $error[$i]['MOBILE'] = 'Mobile Already exist.please try another' . "</br>";
                        }
                    }
                    if (empty($leadSource)) {
                        $error[$i]['SOURCE'] = 'Source not exist . Source Id not matched with source listing.' . "</br>";
                    }
                    /* if(isset($listArray[5]) && trim($listArray[5])!=''){
                      $agencyname=trim($listArray[5]);
                      $objAgency = new Travel_Model_TblAgency();
                      $checkb2bAgencyExist=$objAgency->isB2BAgencyNameExists($agencyname,$AgencySysId);
                      if(count($checkb2bAgencyExist)==0){
                      $error[$i]['AGENCYNAME']='Company Name Not exist.please try another'."</br>";
                      }
                      } */
                    if (isset($listArray[7]) && trim($listArray[7]) != '') {
                        if ($listArray[7] != 1 && $listArray[7] != 2) {
                            $error[$i]['B2BTYPE'] = 'B2B Type Not exist. 1 For Agency, 2 For Corporate' . "</br>";
                        }
                    }


                    $leadListArray[$i]['ERROR'] = $error;
                    $leadListArray[$i]['EMAILID'] = stripslashes(trim($listArray[0]));
                    $leadListArray[$i]['COUNTRYCODE'] = stripslashes(trim($listArray[1]));
                    $leadListArray[$i]['MOBILE'] = stripslashes(trim($listArray[2]));
                    $leadListArray[$i]['FIRSTNAME'] = stripslashes(trim($listArray[3]));
                    $leadListArray[$i]['LASTNAME'] = stripslashes(trim($listArray[4]));
                    $leadListArray[$i]['SOURCE'] = stripslashes(trim($leadSource['Title']));
                    $leadListArray[$i]['SOURCEID'] = stripslashes(trim($listArray[5]));
                    $leadListArray[$i]['AGENCYNAME'] = stripslashes(trim($listArray[6]));
                    $leadListArray[$i]['B2BTYPE'] = stripslashes(trim($listArray[7]));
                    $leadListArray[$i]['PANCARD'] = stripslashes(trim($listArray[8]));
                    $leadListArray[$i]['GSTNUMBER'] = stripslashes(trim($listArray[9]));
                    $leadListArray[$i]['MasterCampSysId'] = $MasterCampSysId;
                    unset($error[$i]);
                    $i++;
                }
                //echo "<pre>";print_r($leadListArray);die;
                $this->view->leadList = $leadListArray;
            }
        }

        $leadSouceList = $this->_leadstageObj->GetAllSouce($AgencySysId);
        $this->view->leadSouceList = $leadSouceList;
    }

    public function exportExcelLeagQueryAction() {
        //echo "prashant"; exit;
        $orderBy = $this->_HtmlPurifier->filter($this->getRequest()->getParam('order'));
        $getData = array();
        $getData['checkALLData'] = $this->getRequest()->getParam('checkALLData', null);
        $getData['dateFrom'] = $this->getRequest()->getParam('dateFrom');
        $getData['dateTo'] = $this->getRequest()->getParam('dateTo');
        $getData['customername'] = $this->getRequest()->getParam('customername');
        $getData['customermobile'] = $this->getRequest()->getParam('customermobile');
        $getData['customeremail'] = $this->getRequest()->getParam('customeremail');
        $getData['Destination'] = $this->getRequest()->getParam('Destination');
        $getData['lead_stage'] = $this->getRequest()->getParam('lead_stage');
        $getData['assigUnassignFilter'] = (NULL !== $this->getRequest()->getParam('assigUnassignFilter')) ? $this->getRequest()->getParam('assigUnassignFilter') : '';
        $getData['agencyUserFilter'] = (NULL !== $this->getRequest()->getParam('agencyUserFilter')) ? $this->getRequest()->getParam('agencyUserFilter') : '';
        $type = $this->getRequest()->getParam('type');
        if (isset($type) && !empty($type)) {
            $getData['leadType_' . $type] = $type;
        }
        isset($orderBy) ? ($getData['order'] = $orderBy) : '';
        $getData['UserSysId'] = 0;
        if ((isset($getData['leadType_LEAD']) && trim($getData['leadType_LEAD']) == 'LEAD')) {
            $sheetTitle = "Lead Data";
        } else {
            $sheetTitle = "Query Data";
        }
        $arrFieldLabel = array(
            'Query Date/Age', 'Name', 'Company Name', 'Mobile', 'Email', 'Type', 'Description', 'Travel Date', 'No. of Pax', 'No. of Days', 'From Destinations', 'Destinations', 
            'Lead Stage', 'Lead Source', 'Lead Campaign', 'Lead Medium', 'Last Updated', 'IsMarkForDel', 'Owner'
        );
        $sessionLogin_user = new Zend_Session_Namespace('sessionLogin_user');
        $AgencySysId = $sessionLogin_user->intLoggedinUserAgencySysId;
        $getData['MainAgencySysId'] = $AgencySysId;
        $AgentSysId = $sessionLogin_user->intLoggedinUserId;
        $ReportingToSysId = $sessionLogin_user->ReportingToSysId;
        $roleID = $sessionLogin_user->UserRole;
        $this->_agencyuserroleObj = new Travel_Model_TblAgencyUserRole();
        $getRoleDetail = $this->_agencyuserroleObj->getDataByRole($roleID);
        $this->_crmcusttravelplan = new Travel_Model_CRM_CustomerTravelPlan();
        $crmtravelplanstatusObj = new Travel_Model_CRM_TravelPlanStatus();
        $getStageList = $crmtravelplanstatusObj->GetTravelPlanStatusByType(3);
        $arrFieldValue = array();
        if ((isset($getData['leadType_LEAD']) && trim($getData['leadType_LEAD']) == 'LEAD')) {
            if (isset($getData['lead_stage']) && $getData['lead_stage'] != '') {
                $getData['lead_stage'] = explode(',', $getData['lead_stage']);
            } else {
                $getData['lead_stage'] = array();
            }
            $getleadSource = $this->_crmcustomerObj->getLeadSourceByAgency($AgencySysId);
            $this->_crmagencyleadaccountObj->ReportingToSysId = $ReportingToSysId;
            if ($getRoleDetail['IsAdmin'] == true || $getRoleDetail['IsSuperAdmin'] == True) {
                $getData['AgencySysId'] = $AgencySysId;
                if (isset($getData['assigUnassignFilter']) && ($getData['assigUnassignFilter'] == 2)) { 
                    $getData['UserSysId'] = 0;
                }
                $getData['ExcelExport'] = true;
                $getCustomerList = $this->_crmagencyleadaccountObj->GetGtxCustomerApproved($getData);
            } else {
                $getData['ExcelExport'] = true;
                $getData['UserSysId'] = $AgentSysId;
                if (isset($getData['assigUnassignFilter']) && ($getData['assigUnassignFilter'] == 2)) { //condition for un assigned lead filter
                    $getData['UserSysId'] = 0;
                }
                $leadSourcesIds = array();
                $leadSourceExplodedRes = '';
                $getCustomerList = array();
                if (!empty($getleadSource)) {
                    foreach ($getleadSource as $k => $v) {
                        $leadSourcesIds[] = $v['LeadSourceSysId'];
                    }
                    $leadSourceExplodedRes = implode(",", $leadSourcesIds);
                    $getData['AgentSourceIds'] = $leadSourceExplodedRes;
                    if ($this->getRequest()->isPost()) {
                        $getData = $this->getRequest()->getPost();
                        $getData['AgencySysId'] = $AgencySysId;
                        $getData['AgentSourceIds'] = $leadSourceExplodedRes;
                        $getData = $this->_HtmlPurifier->filterArray($getData);
                        $this->view->searchData = $getData;
                        $getCustomerList = $this->_crmagencyleadaccountObj->GetGtxCustomerApproved($getData, $AgencySysId);
                    } else {
                        $getData['AgencySysId'] = $AgencySysId;
                        $getData['AgentSourceIds'] = $leadSourceExplodedRes;
                        $getCustomerList = $this->_crmagencyleadaccountObj->GetGtxCustomerApproved($getData, $AgencySysId);
                    }
                }
            }
            $responseArray = array();
            $UnAssignedLead = 0;
            $AgencyCRMLeadSysIds = array();
            $i = 0;
            $paginator = Zend_Paginator::factory($getCustomerList);
            $pageNumber = $this->_getParam('page', 1);
            $paginator->setCurrentPageNumber($pageNumber);
            $paginator->setItemCountPerPage(10000);
            foreach ($paginator as $getCustomerListArr) {
                $UnAssignedLead = (trim($getCustomerListArr['AgencyUserFirstName']) == '') ? $UnAssignedLead + 1 : $UnAssignedLead;
                if (!in_array($getCustomerListArr['AgencyCRMLeadSysId'], $AgencyCRMLeadSysIds)) {
                    $selectedStatus = 53;
                    if (!empty($getStageList)) {
                        foreach ($getStageList as $key => $val) {
                            if (isset($getCustomerListArr['LeadStageSysId']) && !empty($getCustomerListArr['LeadStageSysId']) && trim($getCustomerListArr['LeadStageSysId']) != '') {
                                $selectedStatus = trim($getCustomerListArr['LeadStageSysId']);
                                if ($val['TPStatusSysId'] == $selectedStatus) {
                                    $leadstageName = trim(stripslashes($val['TPStatus']));
                                }
                            }
                        }
                    }
                    $differenceIndays = '';
                    $fromDate = $getCustomerListArr['ActiveDate']->format('Y-m-d');
                    $fromDateTime = time() - strtotime($getCustomerListArr['ActiveDate']->format('Y-m-d H:i:s'));
                    $toDate = date('Y-m-d', time());
                    if ($fromDateTime / 3600 < 24) {
                        $fromDateTime = abs($fromDateTime / 60);
                        $differenceIndays = Zend_Controller_Action_HelperBroker::getStaticHelper('DateFormat')->convertToHoursMins($fromDateTime);
                    } else {
                        $differenceIndays = Zend_Controller_Action_HelperBroker::getStaticHelper('DateFormat')->calculateNoOfDays($fromDate, $toDate);
                        $differenceIndays = $differenceIndays . " Days";
                    }
//                    if (!empty($getCustomerListArr['TPSysId'])) {
//                        $proposalcount = $this->_crmcusttravelplan->GetProposalCount(@$getCustomerListArr['TPSysId']);
//                    }
//                    if ($getCustomerListArr['TPSysId'] != '') {
//                        $totalproposal = $totalproposal;
//                    } else {
//                        $totalproposal = '0';
//                    }
                    $Description = isset($getCustomerListArr['Remarks']) && !empty($getCustomerListArr['Remarks']) ? $getCustomerListArr['Remarks'] . ' ' . $getCustomerListArr['Description'] : '';
                   // $totalproposal = 0;
                    $arrFieldValue[$i]['QueryDateAge'] = !empty($getCustomerListArr['ActiveDate']) ? $getCustomerListArr['ActiveDate']->format('d-M-y H:i') . ' - ' . ($differenceIndays ? $differenceIndays : '') : 'NA';
                    $arrFieldValue[$i]['name'] = !empty($getCustomerListArr['FullName']) ? ucfirst($getCustomerListArr['FullName']) : '';
                    $arrFieldValue[$i]['CompanyName'] = (($getCustomerListArr['IsB2BAgent'] == 1) && !empty($getCustomerListArr['CompanyName'])) ? ucfirst($getCustomerListArr['CompanyName']) : '';
                    $arrFieldValue[$i]['Contacts'] = !empty($getCustomerListArr['PrimaryContactNumber']) ? ucfirst($getCustomerListArr['PrimaryContactNumber']) : '';
                    $arrFieldValue[$i]['EmailId'] = !empty($getCustomerListArr['EmailId']) ? (trim($getCustomerListArr['EmailId'])) : '';
                    $arrFieldValue[$i]['type'] = ($getCustomerListArr['IsB2BAgent'] == 1) ? 'B2B' : 'B2C';
                    $arrFieldValue[$i]['Description'] = $Description;
                    $arrFieldValue[$i]['TravelDate'] = !empty($getCustomerListArr['startDate']) ? $getCustomerListArr['startDate'] : '';
                    $arrFieldValue[$i]['noofpax'] = 'NA';
                    $arrFieldValue[$i]['noofdays'] = !empty($getCustomerListArr['Noofdays']) ? $getCustomerListArr['Noofdays'] : 'NA';
                    $arrFieldValue[$i]['FromDestination'] = !empty($getCustomerListArr['FromDestination']) ? (trim($getCustomerListArr['FromDestination'])) : '';
                    $arrFieldValue[$i]['Destinations'] = !empty($getCustomerListArr['Destination']) ? (trim($getCustomerListArr['Destination'])) : '';
                   // $arrFieldValue[$i]['Proposal'] = $totalproposal;
                    $arrFieldValue[$i]['leadstage'] = $leadstageName;
                    $arrFieldValue[$i]['leadSource'] = isset($getCustomerListArr['LeadSource']) ? trim($getCustomerListArr['LeadSource']) : '';
                    $arrFieldValue[$i]['LeadCampaign'] = isset($getCustomerListArr['LeadCampaign']) ? trim($getCustomerListArr['LeadCampaign']) : '';
                    $arrFieldValue[$i]['LeadMedium'] = isset($getCustomerListArr['LeadMedium']) ? trim($getCustomerListArr['LeadMedium']) : '';
                    $arrFieldValue[$i]['lastupdate'] = (isset($getCustomerListArr['UpdatedDate']) && !empty($getCustomerListArr['UpdatedDate'])) ? $getCustomerListArr['UpdatedDate']->format('d-M-y') : 'NA';
                    $arrFieldValue[$i]['IsMarkForDelete'] = ($getCustomerListArr['IsMarkForDelete'] == 1) ? 'Archived' : '';
                    $arrFieldValue[$i]['owner'] = trim(stripslashes($getCustomerListArr['AgencyUserFirstName'])) . " " . trim(stripslashes($getCustomerListArr['AgencyUserLastName']));
                }
                $i++;
            }
        } 
        
//        else {
//            $this->_crmcusttravelplan->ReportingToSysId = $ReportingToSysId;
//            if ($getRoleDetail['IsAdmin'] == true) {
//                $LeadListArr = $this->_crmcusttravelplan->GetAgencyLeadListFilter($AgencySysId, '', @$getData);
//            } else {
//                $LeadListArr = $this->_crmcusttravelplan->GetAgencyLeadListFilter($AgencySysId, $AgentSysId, @$getData);
//            }
//            $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($LeadListArr));
//            $pageNumber = $this->_getParam('page', 1);
//            $paginator->setCurrentPageNumber($pageNumber);
//            $displayAllLeadArray = array(2645, 33872, 24843);
//            if (in_array($AgencySysId, $displayAllLeadArray)) {
//                $paginator->setItemCountPerPage(10000);
//            } else {
//                $paginator->setItemCountPerPage(5000);
//            }
//            $objagencyCustomer = new Travel_Model_CRM_AgencyLeadAccount();
//            $objCustomer = new Travel_Model_CRM_Customer();
//            $customhelper = Zend_Controller_Action_HelperBroker::getStaticHelper('Custom');
//            $travelPlanStatusName = $customhelper->GetTravelPlanStatusArray(1, '');
//            $intCounter = 0;
//
//            if ($paginator) {
//                foreach ($paginator as $leadlist) {
//
//                    $childinPAckage = 0;
//                    $adultinPAckage = 0;
//                    $infantinPAckage = 0;
//                    $returndate = '';
//                    $departuredate = '';
//                    $totalmember = '';
//                    $paxTOtalArr = json_decode($leadlist['RoomInfoJson']);
//                    //echo "<pre>";print_r($paxTOtalArr);echo "</pre>";
//                    if (!empty($paxTOtalArr)) {
//                        foreach ($paxTOtalArr as $PaxTotal) {
//                            $adultinPAckage += @$PaxTotal->Adult;
//                            $childinPAckage += @$PaxTotal->Child;
//                            $infantinPAckage += @$PaxTotal->Infant;
//                            $departuredate = @$PaxTotal->departuredate;
//                            $returndate = trim(@$PaxTotal->returndate);
//                            $totalmember = trim(@$PaxTotal->totalmember);
//                        }
//                    }
//                    $differenceIndays = '';
//                    //if(isset($leadlist['TYPE']) && ($leadlist['TYPE']=='LEAD')){
//                    $fromDate = $leadlist['CreateDate']->format('Y-m-d');
//                    //echo $leadlist['ActiveDate']->format('Y-m-d')
//                    $fromDateTime = time() - strtotime($leadlist['CreateDate']->format('Y-m-d H:i:s'));
//                    $toDate = date('Y-m-d', time());
//                    if ($fromDateTime / 3600 < 24) {
//                        $fromDateTime = abs($fromDateTime / 60);
//                        $differenceIndays = Zend_Controller_Action_HelperBroker::getStaticHelper('DateFormat')->convertToHoursMins($fromDateTime);
//                    } else {
//                        $differenceIndays = Zend_Controller_Action_HelperBroker::getStaticHelper('DateFormat')->calculateNoOfDays($fromDate, $toDate);
//                        $differenceIndays = $differenceIndays . " Days";
//                    }
//                    if ($leadlist['PlanType'] != '') {
//                        $Description = $customhelper->getPlanTypeName($leadlist['PlanType']);
//                    } else {
//                        $Description = 'Lead';
//                    }
//                    $Forex = '';
//                    $Member = '';
//                    $Adult = '';
//                    $Kid = '';
//                    $Infant = '';
//                    $TravelDate = $departuredate;
//                    if ($leadlist['PlanType'] == 7) {
//                        $Forex = count($paxTOtalArr) . ' Forex Type';
//                    } else if ($leadlist['PlanType'] == 4) {
//                        $Member = !empty($totalmember) ? $totalmember . ' Member(s)' : '';
//                    } else if ($adultinPAckage > 0 || $childinPAckage > 0 || $infantinPAckage > 0) {
//                        $Adult = $adultinPAckage . ' Adult(s)';
//                        $Kid = !empty($childinPAckage) ? ', ' . $childinPAckage . ' Kid ' : '';
//                        $Infant = !empty($infantinPAckage) ? ', ' . $infantinPAckage . ' Infant ' : '';
//                    } else {
//                        echo "NA";
//                    }
//                    if (!empty($leadlist['TPSysId'])) {
//                        $proposalcount = $this->_crmcusttravelplan->GetProposalCount(@$leadlist['TPSysId']);
//                    }
//                    if ($leadlist['TPSysId'] != '') {
//                        $totalproposal = $totalproposal;
//                    } else {
//                        $totalproposal = '0';
//                    }
//                    $totalproposal = !empty($proposalcount) ? count($proposalcount) : 0;
//                    $destination = (!empty($leadlist['Cities']) && trim($leadlist['Cities']) != '') ? stripslashes($leadlist['Cities']) : '';
//                    $arrFieldValue[$intCounter]['QueryDateAge'] = !empty($leadlist['CreateDate']) ? $leadlist['CreateDate']->format('d-M-y') . ' - ' . ($differenceIndays ? $differenceIndays : '') : 'NA';
//                    $arrFieldValue[$intCounter]['name'] = !empty($leadlist['FullName']) ? ucfirst($leadlist['FullName']) : '';
//                    $arrFieldValue[$intCounter]['CompanyName'] = !empty($leadlist['CompanyName']) ? ucfirst($leadlist['CompanyName']) : '';
//                    $arrFieldValue[$intCounter]['Contacts'] = !empty($leadlist['Contacts']) ? ucfirst($leadlist['Contacts']) : '';
//                    $arrFieldValue[$intCounter]['EmailId'] = !empty($leadlist['EmailId']) ? ucfirst(trim($leadlist['EmailId'])) : '';
//                    $arrFieldValue[$intCounter]['type'] = ($leadlist['IsB2BAgent'] == 1) ? 'B2B' : 'B2C';
//                    $arrFieldValue[$intCounter]['Description'] = $Description;
//                    $arrFieldValue[$intCounter]['TravelDate'] = $TravelDate;
//                    $arrFieldValue[$intCounter]['noofpax'] = $Forex . ' ' . $Member . ' ' . $Adult . $Kid . $Infant;
//                    $arrFieldValue[$intCounter]['Destinations'] = str_replace(',', ', ', $destination);
//                    $arrFieldValue[$intCounter]['Proposal'] = $totalproposal;
//                    $arrFieldValue[$intCounter]['leadstage'] = (isset($leadlist['StatusType']) && !empty($leadlist['StatusType']) && isset($travelPlanStatusName[$leadlist['StatusType']]['TPStatus'])) ? $travelPlanStatusName[$leadlist['StatusType']]['TPStatus'] : 'NA';
//                    $arrFieldValue[$intCounter]['lastupdate'] = (isset($leadlist['UpdateDate']) && !empty($leadlist['UpdateDate'])) ? $leadlist['UpdateDate']->format('d-M-y') : 'NA';
//                    $arrFieldValue[$intCounter]['owner'] = trim(stripslashes($leadlist['OwnerAgentFirstName'])) . " " . trim(stripslashes($leadlist['OwnerAgentLastName']));
//                    $intCounter++;
//                }
//            }
//        }
        Zend_Controller_Action_HelperBroker::getStaticHelper("CreateExcel")->exportToExcel($sheetTitle, $arrFieldLabel, $arrFieldValue);
        exit;
    }

    public function leadB2bBulkUploadDataAction() {
        $sessionLogin_user = new Zend_Session_Namespace('sessionLogin_user');
        $AgencySysId = $sessionLogin_user->intLoggedinUserAgencySysId;
        $AgentSysId = $sessionLogin_user->intLoggedinUserId;
        $this->_leadstageObj = new Travel_Model_TblLeadSource();
        if ($this->getRequest()->isPost()) {
            $bulkuploaddata = $this->getRequest()->getParam('bulkuploaddata');
            if (isset($bulkuploaddata) && !empty($bulkuploaddata)) {
                $bulkuploaddata = json_decode(base64_decode($bulkuploaddata), true); 
                if (!empty($bulkuploaddata)) {
                    $this->_crmagencyleadaccountObj = new Travel_Model_CRM_AgencyLeadAccount();
                    $updatedate = date('Y-m-d H:i:s');
                    $this->_leadstageObj = new Travel_Model_TblLeadStage();
                    //$getStageList = $this->_leadstageObj->getLeadStage($AgencySysId,'NewLead');
                    $getStageList = $this->_leadstageObj->getLeadStageSatus('New');
                    $leadstage = (isset($getStageList[0]['TPStatusSysId']) && !empty($getStageList[0]['TPStatusSysId'])) ? $getStageList[0]['TPStatusSysId'] : 0;
                    //$leadstage = (isset($getStageList[0]['LeadStageSysId']) && !empty($getStageList[0]['LeadStageSysId']))?$getStageList[0]['LeadStageSysId']:0;					

                    $roleID = $sessionLogin_user->UserRole;
                    $this->_agencyuserroleObj = new Travel_Model_TblAgencyUserRole();
                    $getRoleDetail = $this->_agencyuserroleObj->getDataByRole($roleID);
                    $AssignUserSysId = $this->intLoggedinUserId;
                    if ($getRoleDetail['IsAdmin'] == true) {
                        $AssignUserSysId = 0;
                    }
                    $AgencySysId = $this->intLoggedinUserAgencySysId;
                    foreach ($bulkuploaddata as $list) {
                        $emailid = stripslashes(trim($list['EMAILID']));
                        $mobile = stripslashes(trim($list['MOBILE']));
                        $firstname = stripslashes(trim($list['FIRSTNAME']));
                        $lastname = stripslashes(trim($list['LASTNAME']));
                        $leadsourceid = stripslashes(trim($list['SOURCEID']));
                        $leadsource = stripslashes(trim($list['SOURCE']));
                        $agencyname = stripslashes(trim($list['AGENCYNAME']));
                        
                        $PANCARD = stripslashes(trim($list['PANCARD']));
                        $GSTNUMBER = stripslashes(trim($list['GSTNUMBER']));
                        
                        $b2btype = stripslashes(trim($list['B2BTYPE']));
                        $MasterCampSysId = (int) $list['MasterCampSysId'];
                        
                        $countrycode = stripslashes(trim($list['COUNTRYCODE']));
                        //insert value in lead table
                        $requestPerameter = array();
                        $requestPerameter['fname'] = $firstname;
                        $requestPerameter['b2bagencyname'] = $agencyname;
                        $requestPerameter['customerEmail'] = $emailid;
                        $requestPerameter['lname'] = $lastname;
                        $requestPerameter['mobilenumber'] = $mobile;
                        $requestPerameter['countrycode'] = $countrycode;
                        $requestPerameter['city'] = '';
                        $requestPerameter['state'] = '';
                        $requestPerameter['country'] = '';
                        $requestPerameter['custrelation'] = 0;
                        $requestPerameter['salutation'] = 1;
                        $requestPerameter['CRMCustSysId'] = '';
                        $requestPerameter['passnumber'] = '';
                        $requestPerameter['passexpiry'] = '';
                        $requestPerameter['custdob'] = '';
                        $requestPerameter['custanniversary'] = '';
                        $requestPerameter['leadsource'] = $leadsource;
                        $requestPerameter['IsB2BAgent'] = 1;
                        $requestPerameter['B2BType'] = $b2btype;
                        $requestPerameter['AgencySysId'] = $AgencySysId;
                        $requestPerameter['AgentSysId'] = $this->intLoggedinUserId;
                        $requestPerameter['Unassigned'] = 1;
                        $requestPerameter['CampaignSysId'] = $MasterCampSysId;
                        $requestPerameter['PANNumber'] = $PANCARD;
                        $requestPerameter['GSTNumber'] = $GSTNUMBER;
                        $returnArray = $this->_crmcustomerObj->saveB2BCustomer($requestPerameter);
                        //echo "<pre>";print_r($returnArray);exit;
                    }
                }
                $this->_redirect('/crm/lead');
                exit;
            }
        }
    }

    public function leadBulkUploadDataAction() {
        $sessionLogin_user = new Zend_Session_Namespace('sessionLogin_user');
        $AgencySysId = $sessionLogin_user->intLoggedinUserAgencySysId;
        $AgentSysId = $sessionLogin_user->intLoggedinUserId;
        $this->_leadstageObj = new Travel_Model_TblLeadSource();
        if ($this->getRequest()->isPost()) {
            $bulkuploaddata = $this->getRequest()->getParam('bulkuploaddata');
            if (isset($bulkuploaddata) && !empty($bulkuploaddata)) {
                $bulkuploaddata = json_decode(base64_decode($bulkuploaddata), true);
                if (!empty($bulkuploaddata)) {
                    $this->_crmagencyleadaccountObj = new Travel_Model_CRM_AgencyLeadAccount();
                    $updatedate = date('Y-m-d H:i:s');
                    $this->_leadstageObj = new Travel_Model_TblLeadStage();
                    //$getStageList = $this->_leadstageObj->getLeadStage($AgencySysId,'NewLead');
                    $getStageList = $this->_leadstageObj->getLeadStageSatus('New');
                    $leadstage = (isset($getStageList[0]['TPStatusSysId']) && !empty($getStageList[0]['TPStatusSysId'])) ? $getStageList[0]['TPStatusSysId'] : 0;
                    //$leadstage = (isset($getStageList[0]['LeadStageSysId']) && !empty($getStageList[0]['LeadStageSysId']))?$getStageList[0]['LeadStageSysId']:0;					

                    $roleID = $sessionLogin_user->UserRole;
                    $this->_agencyuserroleObj = new Travel_Model_TblAgencyUserRole();
                    $getRoleDetail = $this->_agencyuserroleObj->getDataByRole($roleID);
                    $AssignUserSysId = $this->intLoggedinUserId;
//                    if ($getRoleDetail['IsAdmin'] == true) {
//                        $AssignUserSysId = 0;
//                    }

                    foreach ($bulkuploaddata as $list) {
                        $emailid = stripslashes(trim($list['EMAILID']));
                        $mobile = stripslashes(trim($list['MOBILE']));
                        $COUNTYCODE = stripslashes(trim($list['COUNTYCODE']));
                        $firstname = stripslashes(trim($list['FIRSTNAME']));
                        $lastname = stripslashes(trim($list['LASTNAME']));
                        $leadsource = stripslashes(trim($list['SOURCEID']));
                        $remarks = stripslashes(trim($list['REMARKS']));
                        $fromDestination = stripslashes(trim($list['FROMDESTINATION']));
                        $toDestination = stripslashes(trim($list['TODESTINATION']));
                        $MasterCampSysId = (int) $list['MasterCampSysId'];
                        $Noofdays = (int) $list['Noofdays'];
                        $main_trip_start_date  = $startDate = trim($list['startDate']);
                        $NoofTraveler = $list['RoomInfoJson'];
                        
                        //$explode_trip_start = explode('/', $startDate);
                        //$main_trip_start_date = $explode_trip_start[2] . '-' . $explode_trip_start[1] . '-' . $explode_trip_start[0];
                        $roominfojson = array();
                        $p = 1;
                        for ($k = 1; $k <= 1; $k++) {
                            $roominfojson[$k]['Adult'] = $NoofTraveler;
                            $roominfojson[$k]['Child'] = '';
                            $roominfojson[$k]['Infant'] = '';
                            $roominfojson[$k]['departuredate'] = $startDate;
                            $roominfojson[$k]['returndate'] = "";
                            $p++;
                        }
                        $remarksFD = $remarksD = '';
                        if ($fromDestination != "") {
                            $remarksFD = "Destination From " . $fromDestination;
                        }
                        if ($toDestination != "") {
                            $remarksD = "To " . $toDestination;
                        }
                        $remarks = $remarksFD . ' ' . $remarksD . ' ' . $remarks;
                        //insert value in lead table
                        $userLeadArray = array(
                            'AgencySysId' => $AgencySysId,
                            'EmailId' => $emailid,
                            'Salutation' => (isset($salution) && !empty($salution)) ? $salution : 0,
                            'PrimaryContactNumber' => $mobile,
                            'FullName' => $firstname . ' ' . $lastname,
                            'FirstName' => trim($firstname),
                            'LastName' => trim($lastname),
                            'LeadSourceSysId' => $leadsource,
                            'LeadStageSysId' => $leadstage,
                            'FromDestination' => $fromDestination,
                            'countrycode' => $COUNTYCODE,
                            'Destination' => $toDestination,
                            'AssignUserSysId' => $AssignUserSysId, // update by sibo on demand of anshul
                            'Remarks' => $remarks,
                            'ActiveDate' => $updatedate,
                            'UpdatedDate' => $updatedate,
                            'CreatedDate' => $updatedate,
                            'IsApproved' => '0',
                            'IsActive' => '1',
                            'IsMarkForDelete' => '0',
                            'CampaignSysId' => $MasterCampSysId,
                            'Noofdays' => $Noofdays,
                            'RoomInfoJson' => $roominfojson ? json_encode($roominfojson) : '',
                            'startDate' => $main_trip_start_date ? $main_trip_start_date : 0,
                        );
                        //for create new customer
                        //                        echo "<pre>";print_r($userLeadArray);die;
                        $AgencyCRMLeadSysId = $this->_crmagencyleadaccountObj->addCustomer($userLeadArray);
                    }
                }
                $this->_redirect('/crm/lead');
                exit;
            }
        }
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit