/lms_debug/protected/controllers/LeadsController_11dec2014.php
PHP | 3727 lines | 3051 code | 372 blank | 304 comment | 554 complexity | b2aaec71b70908335013c40e0a8879c4 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, LGPL-2.0
- <?php
- class LeadsController extends Controller
- {
- const SHARED_TITLE = "Admin Panel";
- /**
- * Declares class-based actions.
- */
- public function filters()
- {
- return array( 'accessControl',array(
- 'CHttpCacheFilter + view',
- 'cacheControl' => " max-age=604800, must-revalidate",
- ) ); // perform access control for CRUD operations
- }
- public function actions()
- {
- return array(
- // captcha action renders the CAPTCHA image displayed on the contact page
- 'captcha'=>
- array(
- 'class'=>'CCaptchaAction',
- 'backColor'=>0xFFFFFF,
- ),
- // page action renders "static" pages stored under 'protected/views/site/pages'
- // They can be accessed via: index.php?r=site/page&view=FileName
- 'page'=>array(
- 'class'=>'CViewAction',
- ),
- );
- }
- /**
- * This is the 'roles' action that is invoked
- * when an action is not explicitly requested by users.
- */
- public function actionlead_welcome()
- {
- $model = new WelcomeMaster();
- $model = WelcomeMaster::model()->find("moduleId = '1' ");
- $this->render('lead_welcome',array('model'=>$model));
- }
- /**
- * This is the 'roles' action that is invoked
- * when an action is not explicitly requested by users.
- */
- public function actionlead_list()
- {
- $relationManager = $_SESSION['relationalManager'];
- $managerMemberId = implode(",",array_unique(@$relationManager));
-
- if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
- $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead='no' ";
- } else {
- $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead='no' AND currentAllocatedId IN (".@$managerMemberId.") ";
- }
- //$modelLead = Lead::model()->findAll(" $querycondition ");
- $this->render('lead_list');
- }
-
- /**
- * This is the 'lead_list_allocator' action that is invoked
- * when an action is not explicitly requested by users.
- */
- public function actionlead_list_allocator()
- {
- // renders the view file 'protected/views/site/index.php'
- // using the default layout 'protected/views/layouts/main.php'
- $this->render('lead_list_allocator');
- }
- /**
- * This is the 'lead_list_allocator' action that is invoked
- * when an action is not explicitly requested by users.
- */
- public function actionfollowup_lead_list()
- {
- $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
- $relationManager = $_SESSION['relationalManager'];
- $managerMemberId = implode(",",array_unique(@$relationManager));
- if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
- $querycondition = ' startDate = "'.@$today12PM.'" and status="Pending" ';
- } else {
- $querycondition = " startDate = '".@$today12PM."' AND status = 'Pending' AND userId IN (".@$managerMemberId.") ";
- }
- //$modelLead = LeadFollowup::model()->findAll(" $querycondition ");
-
- $this->render('followup_lead_list');
- }
- public function actionfollowup_overall_lead_list()
- {
-
- $relationManager = $_SESSION['relationalManager'];
- $managerMemberId = implode(",",array_unique(@$relationManager));
- if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
- $querycondition = ' status="Pending" ';
- } else {
- $querycondition = " status = 'Pending' AND userId IN (".@$managerMemberId.") ";
- }
- //$modelLead = LeadFollowup::model()->findAll(" $querycondition ");
-
- $this->render('followup_overall_lead_list');
- }
-
- /**
- * This is the 'lead_list_allocator' action that is invoked
- * when an action is not explicitly requested by users.
- */
- public function actionlead_list_tc()
- {
- // renders the view file 'protected/views/site/index.php'
- // using the default layout 'protected/views/layouts/main.php'
- $this->render('lead_list_tc');
- }
- /**
- * This is the 'lead_list_allocator' action that is invoked
- * when an action is not explicitly requested by users.
- */
- public function actionjunk_lead_list()
- {
- //$modelLead = Lead::model()->findAll(" leadStatusId = '36' ");
- $this->render('junk_lead_list');
- }
- /**
- * This is the 'lead_list_allocator' action that is invoked
- * when an action is not explicitly requested by users.
- */
- public function actionduplicate_lead_list()
- {
- //$modelLead = Lead::model()->findAll(" leadStatusId = '10' ");
- $this->render('duplicate_lead_list');
- }
- public function actionclose_lead_list()
- {
- //$modelLead = Lead::model()->findAll(" leadStatusId = '7' ");
- $this->render('close_lead_list');
- }
- /**
- * This is the 'lead_list_allocator' action that is invoked
- * when an action is not explicitly requested by users.
- */
- public function actionallocated_lead_list()
- {
- $relationManager = $_SESSION['relationalManager'];
- $managerMemberId = implode(",",array_unique(@$relationManager));
-
- if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
- $querycondition = " currentAllocatedId>0 AND isRead = 'yes'";
- } else {
- $querycondition = " currentAllocatedId >0 AND isRead = 'yes' AND currentAllocatedId IN (".@$managerMemberId.") ";
- }
- //$modelLead = Lead::model()->findAll(" $querycondition ");
- $this->render('allocated_lead_list');
- }
- /**
- * This is the 'lead_list_allocator' action that is invoked
- * when an action is not explicitly requested by users.
- */
- public function actionleads_details()
- {
- // renders the view file 'protected/views/site/index.php'
- // using the default layout 'protected/views/layouts/main.php'
-
- //for follow up
- $parser = new CHtmlPurifier();
- if(isset($_POST['LeadFollowup'])){
- if(isset($_POST['LeadFollowup']['chkActionValid']) && @$_POST['LeadFollowup']['chkActionValid']==1){
- $res = $this->actionlead_followup(@$_POST['LeadFollowup'],$parser->purify(intval(@$_POST['Lead']['leadStatusId'])));
- $decodeRes = json_decode($res);
- if(@$decodeRes->status == 'success'){
- echo CJSON::encode(array(
- 'status'=>'success'
- ));
- } else {
- echo $res;
-
- }
- }
- }
-
- $leadFollDesc = @$_POST['LeadFollowup']['description'];
- // end of for follow ups
- $leadId = $parser->purify(intval(@$_GET['leadId']));
- $actionId = $parser->purify(intval(@$_REQUEST['actionId']));
- $actionmodel=LeadFollowup::model()->findByPk($actionId);
- $model = new Lead();
- $this->performAjaxValidation($model);
- $model->scenario = 'Lead';
-
- $managerMemberId = implode(",",$_SESSION['relationalManager']);
- $chkAllocatedLeads = $managerMemberId?Lead::model()->findAll(array("select"=>" leadId","condition"=>" leadStatusId != '26' AND leadStatusId != '25' AND currentAllocatedId IN (".@$managerMemberId.") ")):'0';
- $allocatedArr=array();
- foreach($chkAllocatedLeads as $key=>$value){
- $allocatedArr[]=$chkAllocatedLeads[$key]->leadId;
- }
- //print_r($allocatedArr);
- //die;
- /*if(Yii::app()->session->get('isAllocator')!='yes' and Yii::app()->session->get('type')!='superadmin'){
- if(!in_array($leadId,$allocatedArr)){
- $this->redirect(array('leads/lead_list'));
- }
- }*/
-
- if(!empty($leadId)){
- $model=Lead::model()->findByPk($leadId);
- $chkrecentlyViewed=recentlyViewed::model()->findByAttributes(array('leadId'=>$leadId,'userId'=>Yii::app()->session->get('id')));
- if(count($chkrecentlyViewed) == 0){
- $recentlyViewed = new recentlyViewed;
- $recentlyViewed->setAttributes(array(
- 'userId' => Yii::app()->session->get('id'),
- 'leadId' => $leadId,
- 'moduleId' => 0,
- 'updatedOn' => $_SESSION['id'],
- 'updatedBy' => $_SESSION['id'],
- ));
-
- $recentlyViewed->save(false);
- }
- }
- if(isset($_POST['Lead']))
- {
-
- if($_POST['LeadFollowup']['startDate']!='') {
- $finalLeadDesc = @$leadFollDesc;
- } else {
- $finalLeadDesc = @$_POST['Lead']['leadDescription'];
- }
- $model->setAttributes(array(
- 'updatedOn' => time(), //additional
- 'updatedBy' => $_SESSION['id'], //additional
- 'status' => 'Active', //additional //additional
- 'leadDescription' => @$finalLeadDesc, //additional //additional
- ));
- $prevLeadStatusId=$model->leadStatusId;
-
- foreach($_POST['Lead'] as $name=>$value)
- {
-
- if($model->leadStatusId==''){
- $model->leadStatusId=$model->leadStatusParentId;
- }
- if($model->email=='Email'){
- $model->email='';
- }
- if($model->name=='Name'){
- $model->name='';
- }
- if($model->address=='Address'){
- $model->address='';
- }
- if($model->ws_proposalid=='Proposal No.'){
- $model->ws_proposalid='';
- }
- if($model->children=="Children (Less than 25 Yrs)"){
- $model->children='';
- }
- if($model->ageGroup=="Age of eldest member"){
- $model->ageGroup='';
- }
- if($model->leadDescription=="Lead Description"){
- $model->leadDescription='';
- }
- if($model->leadStatusId==''){
- $model->leadStatusId=$prevLeadStatusId;
- }
-
-
- if(@$leadId!='' && $model->leadStatusId!='34' && @$model->leadStatusId!='35'){
- $model->isRead='yes';
- }
-
-
- if(is_array($value)){
- $value = '';
- } else {
- $value = $value;
- }
- $model->$name=$parser->purify($value);
- }
- if($model->leadStatusParentId=='1'){
- $model->salesClosedUpdatedOn=time();
- }
-
- $fetchAgentDetails=LeadSourceMaster::model()->findByPk($model->leadSourceId);
-
- $model->agentId = @$fetchAgentDetails->leadSourceCode;
- $model->ws_agentid = @$fetchAgentDetails->leadSourceCode;
-
-
- if(@$leadId!='' && $model->leadStatusId!='34'){
-
- $update = Yii::app()->db->createCommand("update `lead` set `isRead`='yes' where `leadId`='$leadId' and currentAllocatedId > 0")->query();
- }
-
- $chkStatusMandatoryOrNot = leadStatus::model()->findByAttributes(array('leadStatusId'=>$model->leadStatusId));
- if($model->leadStatusId=='1'){
- $model->scenario = 'salesclosed';
- }
-
- if(count($chkStatusMandatoryOrNot) > 0){
- $condMandatory = $chkStatusMandatoryOrNot['compulsary'];
-
- if($condMandatory == 'No'){
- if($model->validate(array('mobile'))){
-
- if(@$_POST['Lead']['emailOptOut']=='on') { $model->emailOptOut='Y'; } else { $model->emailOptOut='N'; }
- if(@$_POST['Lead']['mobileOptOut']=='on') { $model->mobileOptOut='Y'; } else { $model->mobileOptOut='N'; }
- if(@$_POST['Lead']['isJunk']=='on') { $model->isJunk='yes'; } else { $model->isJunk='no'; }
- if(@$_POST['Lead']['isDuplicate']=='on') { $model->isDuplicate='yes'; } else { $model->isDuplicate='no'; }
- if(@$_POST['Lead']['status']=='on') { $model->status='Close'; } else { $model->status='Active'; }
-
-
- $modelHistory = new LeadHistory();
- $modelHistory->scenario = 'LeadHistory';
-
- $modelHistory->setAttributes(array(
- 'leadId' => @$leadId, //additional data you want to insert
- 'updatedOn' => time(), //additional
- 'updatedBy' => $_SESSION['id'], //additional
- 'status' => 'Active', //additional
- 'leadDescription' => @$finalLeadDesc,
-
- ));
- foreach($_POST['Lead'] as $name1=>$value1)
- {
- if($modelHistory->leadStatusId==''){
- $modelHistory->leadStatusId=$modelHistory->leadStatusParentId;
- }
- if(@$_POST['LeadFollowup']['description']=='Description'){
- $activitydesc = '';
- } else {
- $activitydesc = @$_POST['LeadFollowup']['description'];
- }
- $modelHistory->activityDescription=@$activitydesc;
- if($model->leadStatusId==''){
- $model->leadStatusId=2;
- }
- if($modelHistory->email=='Email'){
- $modelHistory->email='';
- }
- if($modelHistory->name=='Name'){
- $modelHistory->name='';
- }
- if($modelHistory->address=='Address'){
- $modelHistory->address='';
- }
- if($modelHistory->leadDescription=="Lead Description"){
- $modelHistory->leadDescription='';
- }
- if($modelHistory->children=="Children (Less than 25 Yrs)"){
- $modelHistory->children='';
- }
- if($modelHistory->ageGroup=="Age of eldest member"){
- $modelHistory->ageGroup='';
- }
- if(is_array($value1)){
- $value1 = '';
- } else {
- $value1 = $value1;
- }
-
- $modelHistory->$name1=$parser->purify($value1);
- }
- $model->save(false);
- $modelHistory->save();
- CJSON::encode(array(
- 'status'=>'success'
- ));
- Yii::app()->end();
- }
- }
- }
-
- $model->save();
- if($model->validate()){
- if(@$_POST['Lead']['emailOptOut']=='on') { $model->emailOptOut='Y'; } else { $model->emailOptOut='N'; }
- if(@$_POST['Lead']['mobileOptOut']=='on') { $model->mobileOptOut='Y'; } else { $model->mobileOptOut='N'; }
- if(@$_POST['Lead']['isJunk']=='on') { $model->isJunk='yes'; } else { $model->isJunk='no'; }
- if(@$_POST['Lead']['isDuplicate']=='on') { $model->isDuplicate='yes'; } else { $model->isDuplicate='no'; }
- if(@$_POST['Lead']['status']=='on') { $model->status='Close'; } else { $model->status='Active'; }
-
-
- $modelHistory = new LeadHistory();
- $modelHistory->scenario = 'LeadHistory';
- $modelHistory->setAttributes(array(
- 'leadId' => @$leadId, //additional data you want to insert
- 'updatedOn' => time(), //additional
- 'updatedBy' => $_SESSION['id'], //additional
- 'status' => 'Active', //additional
- 'leadDescription' => @$finalLeadDesc,
-
- ));
- foreach($_POST['Lead'] as $name1=>$value1)
- {
- if($modelHistory->leadStatusId==''){
- $modelHistory->leadStatusId=$modelHistory->leadStatusParentId;
- }
- $modelHistory->activityDescription=@$_POST['LeadFollowup']['description'];
- if($model->leadStatusId==''){
- $model->leadStatusId=2;
- }
- if(is_array($value1)){
- $value1 = '';
- } else {
- $value1 = $value1;
- }
- $modelHistory->$name1=$parser->purify($value1);
- }
-
- $modelHistory->save();
- echo CJSON::encode(array(
- 'status'=>'success'
- ));
- Yii::app()->end();
- //Yii::app()->end();
- //die;
- //$this->redirect(array('leads/leads_details'));
- } else {
-
-
- @$error = CActiveForm::validate(@$model);
- if($error!='[]')
- echo @$error;
- Yii::app()->end();
- //$this->render('leads_details',array('model'=>$model));
- }
- } else {
-
- $this->render('leads_details',array('model'=>@$model,'actionmodel'=>@$actionmodel,'quotesmobile'=>@$model->mobile));
- }
- }
- protected function performAjaxValidation($models)
- {
- if(isset($_POST['ajax']) && $_POST['ajax']==='user-form')
- {
- echo CActiveForm::validate($models);
- Yii::app()->end();
- }
- }
- /**
- * This is the 'lead_list_allocator' action that is invoked
- * when an action is not explicitly requested by users.
- */
- public function actionlead_followup()
- {
- $actionId = @$_REQUEST['actionId'];
- $model = new LeadFollowup();
- $model->scenario = 'LeadFollowup';
- if(isset($actionId) && !empty($actionId)){
- $model=LeadFollowup::model()->findByPk($actionId);
- } else {
-
- }
-
- if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Task'){
- $model->scenario = 'LeadFollowupTask';
- }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Follow Up'){
- $model->scenario = 'LeadFollowup';
- }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Meeting'){
- $model->scenario = 'LeadFollowup';
- }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Notes'){
- $model->scenario = 'LeadFollowupNotes';
- }
- $parser = new CHtmlPurifier();
- $this->performAjaxValidation($model);
- if(isset($_POST['LeadFollowup']))
- {
- $userId = $_POST['LeadFollowup']['userId'];
- $followupstartdatewithtime = strtotime(@$_POST['LeadFollowup']['startDate'])+(@$_POST['LeadFollowup']['hour']*60*60)+(@$_POST['LeadFollowup']['minutes']*60);
- $model->setAttributes(array(
- 'createdOn' => time(), //additional data you want to insert
- 'updatedOn' => time(), //additional
- 'updatedBy' => @$userId, //additional
- 'createdBy' => @$userId, //additional
- 'status' => 'Pending', //additional
-
- ));
- foreach($_POST['LeadFollowup'] as $name=>$value)
- {
- if(is_array($value)){
- $value = '';
- } else {
- $value = $value;
- }
-
- $model->$name=$parser->purify($value);
- }
- $model->leadStatusId=@$_POST['Lead']['leadStatusId'];;
- $model->startDateWithTime=@$followupstartdatewithtime;
- if(@$_POST['LeadFollowup']['actionType']=='Notes') {
- $prefix=substr(time(),0,5);
- $folder = 'siteupload/';
- $model->notesFile=CUploadedFile::getInstance($model,'notesFile');
- if($model->notesFile !='')
- $model->notesFile->saveAs($folder.$prefix.$model->notesFile);
- $model->notesFile=$prefix.CUploadedFile::getInstance($model,'notesFile');
- }
- if(@$_POST['LeadFollowup']['startDate']!='') {
- $startDateVal = strtotime($_POST['LeadFollowup']['startDate']);
- $model->startDate=@$startDateVal;
- }
- if(@$_POST['LeadFollowup']['taskDueDate']!='') {
- $taskDueDateVal = strtotime($_POST['LeadFollowup']['taskDueDate']);
- $model->taskDueDate=@$taskDueDateVal;
- }
- if(@$_POST['LeadFollowup']['taskCompleted']!='') {
- $model->taskCompleted='yes';
- }
- if($model->validate()){
-
- $checkForSameDateExistsOrNot=LeadFollowup::model()->findAll(" leadId='".@$_POST['LeadFollowup']['leadId']."' and startDate <= '".$model->startDate."' and userId = '".@$userId."' and createdBy = '".@$userId."' ");
- if(count(@$checkForSameDateExistsOrNot) > 0){
- $update = Yii::app()->db->createCommand("UPDATE leadFollowup SET taskCompleted = 'yes',status = 'Completed' WHERE startDate <= '".$model->startDate."' and userId = '".@$userId."' and createdBy = '".@$userId."' and leadId='".@$_POST['LeadFollowup']['leadId']."' ")->execute();
- }
- $model->save();
- $leadId = $_POST['LeadFollowup']['leadId'];
- return CJSON::encode(array(
- 'status'=>'success'
- ));
- Yii::app()->end();
- } else {
- $error = CActiveForm::validate($model);
- if($error!='[]')
- return $error;
- Yii::app()->end();
- }
- //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
- }
- $this->redirect(array('leads/lead_list'));
- }
- /**
- * This is the 'lead_list_allocator' action that is invoked
- * when an action is not explicitly requested by users.
- */
- public function actionlead_followupcalender()
- {
- $actionId = @$_REQUEST['actionId'];
- $model = new LeadFollowup();
- $model->scenario = 'LeadFollowup';
- if(isset($actionId) && !empty($actionId)){
- $model=LeadFollowup::model()->findByPk($actionId);
- } else {
-
- }
-
- if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Task'){
- $model->scenario = 'LeadFollowupTask';
- }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Follow Up'){
- $model->scenario = 'LeadFollowup';
- }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Meeting'){
- $model->scenario = 'LeadFollowup';
- }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Notes'){
- $model->scenario = 'LeadFollowupNotes';
- }
- $this->performAjaxValidation($model);
- if(isset($_POST['LeadFollowup']))
- {
- $userId = $_POST['LeadFollowup']['userId'];
- $model->setAttributes(array(
- 'createdOn' => time(), //additional data you want to insert
- 'updatedOn' => time(), //additional
- 'updatedBy' => @$userId, //additional
- 'createdBy' => @$userId, //additional
- 'status' => 'Pending', //additional
- ));
- foreach($_POST['LeadFollowup'] as $name=>$value)
- {
- $model->$name=$value;
- }
- $model->leadStatusId=@$_POST['Lead']['leadStatusId'];;
- if(@$_POST['LeadFollowup']['actionType']=='Notes') {
- $prefix=substr(time(),0,5);
- $folder = 'siteupload/';
- $model->notesFile=CUploadedFile::getInstance($model,'notesFile');
- if($model->notesFile !='')
- $model->notesFile->saveAs($folder.$prefix.$model->notesFile);
- $model->notesFile=$prefix.CUploadedFile::getInstance($model,'notesFile');
- }
- if(@$_POST['LeadFollowup']['startDate']!='') {
- $startDateVal = strtotime($_POST['LeadFollowup']['startDate']);
- $model->startDate=@$startDateVal;
- }
- if(@$_POST['LeadFollowup']['taskDueDate']!='') {
- $taskDueDateVal = strtotime($_POST['LeadFollowup']['taskDueDate']);
- $model->taskDueDate=@$taskDueDateVal;
- }
- if(@$_POST['LeadFollowup']['taskCompleted']!='') {
- $model->taskCompleted='yes';
- }
- if($model->validate()){
- $model->save();
- $leadId = $_POST['LeadFollowup']['leadId'];
- echo CJSON::encode(array(
- 'status'=>'success'
- ));
- Yii::app()->end();
- } else {
- $error = CActiveForm::validate($model);
- if($error!='[]')
- return $error;
- Yii::app()->end();
- }
- //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
- }
- $this->redirect(array('leads/lead_list'));
- }
-
-
- public function actionlead_contacts()
- {
- // renders the view file 'protected/views/site/index.php'
- // using the default layout 'protected/views/layouts/main.php'
- $model = new LeadContacts();
- $model->scenario = 'LeadContacts';
- $this->performAjaxValidation($model);
- if(!empty($_GET['contactId']))
- {
- $leadContactId=$_GET['leadContactId'];
- $model=LeadContacts::model()->findByPk($leadContactId);
- }
- if(!empty($_POST['LeadContacts']['leadContactId']))
- {
- $leadContactId=$_POST['LeadContacts']['leadContactId'];
- $model=LeadContacts::model()->findByPk($leadContactId);
- }
- if(isset($_POST['LeadContacts']))
- {
- $userId = $_POST['LeadContacts']['userId'];
- $leadId = $_POST['LeadContacts']['leadId'];
- $model->setAttributes(array(
- 'createdOn' => time(), //additional data you want to insert
- 'updatedOn' => time(), //additional
- 'updatedBy' => @$userId, //additional
- 'createdBy' => @$userId, //additional
- 'status' => 'Active', //additional
- ));
- foreach($_POST['LeadContacts'] as $name=>$value)
- {
- $model->$name=$value;
- }
- if($model->validate()){
- $model->save();
- echo CJSON::encode(array(
- 'status'=>'success'
- ));
- Yii::app()->end();
- } else {
- $error = CActiveForm::validate($model);
- if($error!='[]')
- echo $error;
- Yii::app()->end();
-
- }
-
- //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
- }
- $this->redirect(array('leads/lead_list'));
- }
- public function actionChangeContactStatus()
- {
-
- $Id=$_REQUEST['contactId'];
- $leadId=$_REQUEST['leadId'];
- $status=$_REQUEST['status'];
- if(isset($status)&&($status=='Inactive')){
- $status="Active";
- } else {
- $status="Inactive";
- }
- if(!empty($Id))
- {
- $model=LeadContacts::model()->findByPk($Id);
- }
- else
- {
- $model = LeadContacts::model()->findAll();
- }
- $model->status=$status;
- $model->save();
- $this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
- }
- /**
- * This is the 'roles' action that is invoked
- * when an action is not explicitly requested by users.
- */
- public function actioncreate_lead()
- {
- $model=new Lead();
- $model->scenario = 'Lead';
- if(!empty($_GET['leadId']))
- {
- $leadId=$_GET['leadId'];
- $model=Lead::model()->findByPk($leadId);
- $chkrecentlyViewed=recentlyViewed::model()->findByAttributes(array('leadId'=>$leadId,'userId'=>Yii::app()->session->get('id')));
- if(count($chkrecentlyViewed) == 0){
- $recentlyViewed = new recentlyViewed;
- $recentlyViewed->setAttributes(array(
- 'userId' => Yii::app()->session->get('id'),
- 'leadId' => $leadId,
- 'moduleId' => 0,
- 'createdOn' => time(),
- 'updatedOn' => time(),
- 'updatedBy' => time(),
- 'createdBy' => time(),
- ));
-
- $recentlyViewed->save(false);
- }
- }
- if(!empty($_POST['Lead']['leadId']))
- {
- $leadId=$_POST['Lead']['leadId'];
- $model=Lead::model()->findByPk($leadId);
- }
- if(isset($_POST['Lead']))
- {
-
- $model->setAttributes(array(
- 'createdOn' => time(), //additional data you want to insert
- 'updatedOn' => time(), //additional
- 'updatedBy' => Yii::app()->session->get('id'), //additional
- 'createdBy' => Yii::app()->session->get('id'),
- ));
- foreach($_POST['Lead'] as $name=>$value)
- {
- $model->$name=$value;
- if($model->leadStatusId==''){
- $model->leadStatusId=$model->leadStatusParentId;
- }
- if($model->leadStatusId==''){
- $model->leadStatusId=34;
- }
- if($model->mobile=='Mobile*'){
- $model->mobile='';
- }
- if($model->email=='Email'){
- $model->email='';
- }
- if($model->name=='Name'){
- $model->name='';
- }
- if($model->address=='Address'){
- $model->address='';
- }
- if($model->children=="Children (Less than 25 Yrs)"){
- $model->children='';
- }
- if($model->ageGroup=="Age of eldest member"){
- $model->ageGroup='';
- }
- }
- if($model->leadStatusParentId=='1'){
- $model->salesClosedUpdatedOn=time();
- }
-
- if($model->leadSourceId=='' or empty($model->leadSourceId)){
- $model->leadSourceId = '2';
- }
- $fetchAgentDetails=LeadSourceMaster::model()->findByPk($model->leadSourceId);
-
- $model->agentId = @$fetchAgentDetails->leadSourceCode;
- $model->ws_agentid = @$fetchAgentDetails->leadSourceCode;
- if(Yii::app()->session->get('isAllocator')!='yes' and Yii::app()->session->get('type')!='superadmin') {
- @$model->leadStatusId=35;
- @$model->currentAllocatedId=Yii::app()->session->get('id');
- }
-
- if(@$leadId!='' && $model->leadStatusId!='34'){
- $update = Yii::app()->db->createCommand("update `lead` set `isRead`='yes' where `leadId`='$leadId' and currentAllocatedId > 0")->query();
- }
-
- if(@$_POST['Lead']['emailOptOut']=='on') { $model->emailOptOut='Y'; } else { $model->emailOptOut='N'; }
- if(@$_POST['Lead']['mobileOptOut']=='on') { $model->mobileOptOut='Y'; } else { $model->mobileOptOut='N'; }
- if(@$_POST['Lead']['isJunk']=='on') { $model->isJunk='yes'; } else { $model->isJunk='no'; }
- if(@$_POST['Lead']['isDuplicate']=='on') { $model->isDuplicate='yes'; } else { $model->isDuplicate='no'; }
- if(@$_POST['Lead']['status']=='on') { $model->status='Close'; } else { $model->status='Active'; }
- $chkStatusMandatoryOrNot = leadStatus::model()->findByAttributes(array('leadStatusId'=>$model->leadStatusId));
-
- if(count($chkStatusMandatoryOrNot) > 0){
- $condMandatory = $chkStatusMandatoryOrNot['compulsary'];
- if($condMandatory == 'No'){
- if($model->validate(array('mobile'))){
-
- $mobileNumber = @$_POST['Lead']['mobile'];
- $checkJunkNumber = JunkNumbersMaster::model()->find('junkLeadNumber = "'.@$mobileNumber.'"');
- if(empty($checkJunkNumber)){
- $beforethreemonth = time()-7776000;
- $checkDuplicateNumber = Lead::model()->find('mobile = "'.@$mobileNumber.'" AND createdOn > "'.@$beforethreemonth.'" AND status = "Active" AND leadId != "'.@$leadId.'" ');
- if(empty($checkDuplicateNumber)){
-
- $model->save(false);
- Yii::app()->user->setFlash('lead_msg_success','Successfully Inserted');
- } else {
- $duplicateLeadId = $checkDuplicateNumber->leadId;
- $model->leadStatusId='10';
- $model->duplicateLeadId=@$duplicateLeadId;
- $model->currentAllocatedId=$checkDuplicateNumber->currentAllocatedId;
- $model->save(false);
- Yii::app()->user->setFlash('lead_msg_success','Successfully Inserted');
- }
- } else {
- $model->leadStatusId='36';
- $model->save(false);
- Yii::app()->user->setFlash('lead_msg_success','Junk Lead');
- }
- $this->redirect(array('leads/lead_list'));
-
- // $model->save(false);
- // $this->redirect(array('leads/lead_list'));
- }
- }
- }
- if($model->leadStatusId==36){
- $model->save(false);
- $this->redirect(array('leads/lead_list'));
- } else {
- if($model->validate()){
- $mobileNumber = $_POST['Lead']['mobile'];
- $checkJunkNumber = JunkNumbersMaster::model()->find('junkLeadNumber = "'.@$mobileNumber.'"');
- if(empty($checkJunkNumber)){
- $beforethreemonth = time()-7776000;
- $checkDuplicateNumber = Lead::model()->find('mobile = "'.@$mobileNumber.'" AND createdOn > "'.@$beforethreemonth.'" AND status = "Active" AND leadId != "'.@$leadId.'" ');
- if(empty($checkDuplicateNumber)){
-
- $model->save();
- Yii::app()->user->setFlash('lead_msg_success','Successfully Inserted');
- } else {
- $duplicateLeadId = $checkDuplicateNumber->leadId;
- $model->leadStatusId='10';
- $model->duplicateLeadId=@$duplicateLeadId;
- $model->save();
- Yii::app()->user->setFlash('lead_msg_success','Successfully Inserted');
- }
- } else {
- $model->leadStatusId='36';
- $model->save();
- Yii::app()->user->setFlash('lead_msg_success','Junk Lead');
- }
- $this->redirect(array('leads/lead_list'));
- } else {
- $this->render('create_lead',array('model'=>$model));
- }
- }
- } else {
- $this->render('create_lead',array('model'=>$model));
- }
- }
- public function actionAllocateLeads()
- {
-
-
- $Id = $_REQUEST['userids'];
-
- $teamId = @$_REQUEST['Team']['teamId'];
-
- $userId = $_REQUEST['Team']['teamMemberId'];
-
- $updatedBy = @$_SESSION['id'];
-
- $updatedOn = time();
-
-
-
- $teamIdString = '';
-
- if($teamId)
-
- {
-
- $teamIdString = ',teamId = ' . $teamId . ', ';
-
- }
-
- foreach($Id as $key => $value)
-
- {
-
- $commonQueryString = ", updatedBy = $updatedBy, updatedOn = $updatedOn where leadId = $value";
-
- $updateLead = "update lead set currentAllocatedId = $userId, leadStatusId = 35, currentAllocatedDate = $updatedOn $commonQueryString";
-
- Yii::app()->db->createCommand($updateLead)->execute();
-
- }
-
-
-
- $red = @$_REQUEST['red'];
-
- if($this->action->id=='AllocateLeads' && $red == 1)
-
- {
-
- $this->redirect(array('leads/lead_list'));
-
- }
-
- $this->redirect(array('leads/fresh_leads'));
-
-
- }
- public function actionAllocateLeads_17nov2014()
- {
- $Id = $_REQUEST['userids'];
- $teamId = @$_REQUEST['Team']['teamId'];
- $userId = $_REQUEST['Team']['teamMemberId'];
- $updatedBy = @$_SESSION['id'];
-
- foreach($Id as $key=>$value){
- $model = new AllocatedLeads();
- $model->scenario = 'AllocatedLeads';
- $model->setAttributes(array(
- 'currentAllocatedDate' => time(), //additional data you want to insert
- //'createdOn' => time(), //additional data you want to insert
- 'updatedOn' => time(), //additional
- 'updatedBy' => @$updatedBy, //additional
- 'createdBy' => @$updatedBy, //additional
- 'leadStatusId' => '35', //additional //additional
- ));
- $leadId = @$value;
- $model->leadId = @$value;
- $model->userId = @$userId;
- $model->teamId = @$teamId;
- //echo @$teamId.' - '.@$userId.' - '.@$leadId;
- $model->allocatedId = null;
- $model->isNewRecord = true;
- $model->save();
- $model=new Lead();
- $model->scenario = 'Lead';
- $updatedOn = time();
- Lead::model()->updateByPk(@$value, array('currentAllocatedId'=>@$userId,'leadStatusId'=>'35','updatedBy'=>@$updatedBy,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
- }
- $red = @$_REQUEST['red'];
-
- if($this->action->id=='AllocateLeads' && $red == 1) {
- $this->redirect(array('leads/lead_list'));
- } else {
- $this->redirect(array('leads/fresh_leads'));
- }
- //$this->redirect(array('leads/lead_list'));
- }
-
- public function actionAllocateLeadswithcount()
- {
- $Id = $_REQUEST['userids'];
- $teamId = @$_REQUEST['Team']['teamId'];
- $userId = $_REQUEST['Team']['teamMemberId'];
- $updatedBy = @$_SESSION['id'];
-
- foreach($Id as $key=>$value){
- $model = new AllocatedLeads();
- $model->scenario = 'AllocatedLeads';
- $model->setAttributes(array(
- 'currentAllocatedDate' => time(), //additional data you want to insert
- //'createdOn' => time(), //additional data you want to insert
- 'updatedOn' => time(), //additional
- 'updatedBy' => @$updatedBy, //additional
- 'createdBy' => @$updatedBy, //additional
- 'leadStatusId' => '35', //additional //additional
- ));
- $leadId = @$value;
- $model->leadId = @$value;
- $model->userId = @$userId;
- $model->teamId = @$teamId;
- //echo @$teamId.' - '.@$userId.' - '.@$leadId;
- $model->allocatedId = null;
- $model->isNewRecord = true;
- $model->save();
-
-
-
-
-
- $model=new Lead();
- $model->scenario = 'Lead';
- $updatedOn = time();
- //Lead::model()->updateByPk(@$value, array('currentAllocatedId'=>@$userId,'leadStatusId'=>'35','updatedBy'=>@$updatedBy,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
- }
- $red = @$_REQUEST['red'];
-
- $chkleadAllocatedOrNot = Lead::model()->findByPk($leadId);
- $oldallocatedid = $chkleadAllocatedOrNot['currentAllocatedId'];
- if(isset($oldallocatedid) && !empty($oldallocatedid)){
-
- $checkLeadExistorNot=Leadallcount::model()->findByAttributes(array('userid'=>$oldallocatedid,'key'=>'2014'));
-
- if(count($checkLeadExistorNot) > 0){
-
- Leadallcount::model()->updateByPk(@$checkLeadExistorNot['id'], array('userid'=>@$oldallocatedid,'key'=>'2014','value'=>'35','updatedBy'=>@$updatedBy,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
-
- } else {
- $leadcount = new Leadallcount();
- $leadcount->setAttributes(array(
- 'userid' => $oldallocatedid, //additional data you want to insert
- 'key' => 2014, //additional data you want to insert
- 'value' => 1, //additional data you want to insert
- 'createdOn' => time(), //additional data you want to insert
- 'updatedOn' => time(), //additional
- 'updatedBy' => time(), //additional
- 'createdBy' => time(), //additional //additional
-
- ));
- $leadcount->save(false);
-
- }
-
-
- }
-
- /*$leadcount->setAttributes(array(
- 'userid' => time(), //additional data you want to insert
- 'key' => 2014, //additional data you want to insert
- 'value' => 1, //additional data you want to insert
- 'createdOn' => time(), //additional data you want to insert
- 'updatedOn' => time(), //additional
- 'updatedBy' => time(), //additional
- 'createdBy' => time(), //additional //additional
-
- ));
- $leadcount->save(false);*/
- die;
-
-
-
- if($this->action->id=='AllocateLeads' && $red == 1) {
- $this->redirect(array('leads/lead_list'));
- } else {
- $this->redirect(array('leads/fresh_leads'));
- }
- //$this->redirect(array('leads/lead_list'));
- }
- /**
- * This is the 'lead_list_allocator' action that is invoked
- * when an action is not explicitly requested by users.
- */
- public function actionlead_assign()
- {
- $model = new Lead();
- $model->scenario = 'Lead';
- $leadId = $_REQUEST['AssignLead']['leadId'];
- $userId = $_REQUEST['AssignLead']['userId'];
- $assign = $_REQUEST['AssignLead']['assign'];
- if($leadId!='') {
- $updatedOn = time();
- $chkleadStatus = Lead::model()->findByPk($leadId);
- $existsOrNot = $chkleadStatus['leadStatusId'];
- $leadStatusIdUpdate = $existsOrNot?$existsOrNot:'34';
- if($leadStatusIdUpdate == 34){
- $leadStatusIdUpdate = 35;
- } else {
- $leadStatusIdUpdate = $leadStatusIdUpdate;
- }
-
- if($assign=='open') {
- Lead::model()->updateByPk(@$leadId, array('currentAllocatedId'=>'','status'=>'Active','leadStatusId'=>34,'updatedBy'=>@$userId,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>''));
- } elseif($assign=='self'){
- Lead::model()->updateByPk(@$leadId, array('currentAllocatedId'=>@$userId,'status'=>'Allocated','leadStatusId'=>@$leadStatusIdUpdate,'updatedBy'=>@$userId,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
- } else {
- Lead::model()->updateByPk(@$leadId, array('currentAllocatedId'=>@$assign,'status'=>'Allocated','leadStatusId'=>@$leadStatusIdUpdate,'updatedBy'=>@$userId,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
- }
- echo CJSON::encode(array(
- 'status'=>'success'
- ));
- Yii::app()->end();
-
- //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
- } else {
-
- $this->redirect(array('leads/lead_list'));
- }
- }
- /**
- * This is the 'roles' action that is invoked
- * when an action is not explicitly requested by users.
- */
- public function actionarchive_leads()
- {
- // renders the view file 'protected/views/site/index.php'
- // using the default layout 'protected/views/layouts/main.php'
- $model=new Lead();
- //$model=Lead::model()->findAll();
- $this->render('archive_leads',array('model'=>$model));
- }
-
- /**
- * This is the 'roles' action that is invoked
- * when an action is not explicitly requested by users.
- */
- public function actionbulk_import_leads()
- {
- // renders the view file 'protected/views/site/index.php'
- // using the default layout 'protected/views/layouts/main.php'
- $model=new Lead();
- $this->render('bulk_import_lead',array('model'=>$model));
- }
-
- /**
- * This is the 'roles' action that is invoked
- * when an action is not explicitly requested by users.
- */
- public function actionjunk_leads()
- {
- // renders the view file 'protected/views/site/index.php'
- // using the default layout 'protected/views/layouts/main.php'
- $this->render('junk_leads');
- }
- /**
- * This is the 'module master' action that is invoked
- * when an action is not explicitly requested by users.
- */
- public function actionmodule_master()
- {
- // renders the view file 'protected/views/site/index.php'
- // using the default layout 'protected/views/layouts/main.php'
-
- $model=new ModuleMaster();
- $model->scenario = 'ModuleMaster';
-
- if(!empty($_GET['moduleId']))
- {
- $moduleId=$_GET['moduleId'];
- $model=ModuleMaster::model()->findByPk($moduleId);
-
- }
-
- if(!empty($_POST['ModuleMaster']['moduleId']))
- {
- $moduleId=$_POST['ModuleMaster']['moduleId'];
- $model=ModuleMaster::model()->findByPk($moduleId);
- }
-
- if(isset($_POST['ModuleMaster']))
- {
- $model->setAttributes(array(
- 'createdOn' => time(), //additional data you want to insert
- 'updatedOn' => time(), //additional
- 'updatedBy' => time(), //additional
- 'createdBy' => time(),
- 'status' => 'Activated', //additional //additional
-
- ));
- foreach($_POST['ModuleMaster'] as $name=>$value)
- {
- $model->$name=$value;
- }
-
- if($model->validate()){
- $model->save();
- $model2=ModuleMaster::model()->findAll();
- $this->render('module_master',array('model'=>$model,'model2'=>$model2));
- Yii::app()->user->setFlash('module_master_msg_success','Successfully Inserted');
- } else {
- Yii::app()->user->setFlash('module_master_msg_error','Please check. error occured');
- $this->render('module_master',array('model'=>$model));
-
- }
- } else {
- $model2=ModuleMaster::model()->findAll();
- //Yii::app()->user->setFlash('lead_stage_msg_error','Please check. error occured');
- $this->render('module_master',array('model'=>$model,'model2'=>$model2));
- }
- }
- /**
- * This is the action to handle external exceptions.
- */
- public function actionError()
- {
- if($error=Yii::app()->errorHandler->error)
- {
- if(Yii::app()->request->isAjaxRequest)
- echo $error['message'];
- else
- $this->render('error', $error);
- }
- }
-
- /**
- * Displays the contact page
- */
- public function actionContact()
- {
- $model=new ContactForm;
- if(isset($_POST['ContactForm']))
- {
- $model->attributes=$_POST['ContactForm'];
- if($model->validate())
- {
- $name='=?UTF-8?B?'.base64_encode($model->name).'?=';
- $subject='=?UTF-8?B?'.base64_encode($model->subject).'?=';
- $headers="From: $name <{$model->email}>\r\n".
- "Reply-To: {$model->email}\r\n".
- "MIME-Version: 1.0\r\n".
- "Content-type: text/plain; charset=UTF-8";
-
- mail(Yii::app()->params['adminEmail'],$subject,$model->body,$headers);
- Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
- $this->refresh();
- }
- }
- $this->render('contact',array('model'=>$model));
- }
-
- /**
- * Displays the login page
- */
- public function actionLogin()
- {
- $model=new User;
-
- // if it is ajax validation request
- if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
- {
- echo CActiveForm::validate($model);
- Yii::app()->end();
- }
-
- // collect user input data
- if(isset($_POST['User']))
- {
-
- $model->attributes=$_POST['User'];
- // validate user input and redirect to the previous page if valid
- if($model->validate() && $model->login()){
- $this->redirect(array('masters/dashboard'));
- } else {
- $this->redirect(Yii::app()->user->returnUrl);
- }
- }
- // display the login form
- $this->render('login',array('model'=>$model));
- }
-
- /**
- * Logs out the current user and redirect to homepage.
- */
- public function actionLogout()
- {
- setcookie ('PHPSESSID', '', time(), '/', '', 0, 0); // Destroy the cookie.
- Yii::app()->user->logout();
- $this->redirect(Yii::app()->homeUrl);
- }
- public function getPageType()
- {
- return "Leads";
- }
- public function init(){
- $obj =new RecentlyViewedController(); // preparing object
- $data=$obj->actionUserRoleAccess();
- $moduleArray=array();
- if(Yii::app()->session->get('type')=='superadmin'){
- $moduleArray['read']='yes';
- $moduleArray['write']='yes';
- $moduleArray['delete']='yes';
- }else{
- foreach($data as $key=>$value){
- if($data[$key]->modules->moduleName=='Leads'){
- $moduleArray['moduleName']=$data[$key]->modules->moduleName;
- $moduleArray['read']=$data[$key]->read;
- $moduleArray['write']=$data[$key]->write;
- $moduleArray['delete']=$data[$key]->delete;
- }
- }
- }
-
- return $moduleArray;
-
- }
-
- public function getNameFromNumber($num) {
- $numeric = $num % 26;
- $letter = chr(65 + $numeric);
- $num2 = intval($num / 26);
- if ($num2 > 0) {
- return getNameFromNumber($num2 - 1) . $letter;
- } else {
- return $letter;
- }
- }
- /*function actionexportArchiveList()
- {
- // generate a resultset
- $model=new User;
- $model=User::model()->findAll();
- // render data to xlsx format and echo resultant file back to browser.
- ExcelExporter::sendAsXLS($model, true, 'closedLeads.xls');
- }*/
-
- public function actionDownloadLeadTemp(){
-
- Yii::import('ext.phpexcel.XPHPExcel');
- $objPHPExcel= XPHPExcel::createPHPExcel();
- $objPHPExcel->getProperties()->setCreator("LeadTemplate")
- ->setLastModifiedBy("LeadTemplate")
- ->setTitle("LeadTemplate")
- ->setSubject("LeadTemplate")
- ->setDescription("LeadTemplate.")
- ->setKeywords("LeadTemplate")
- ->setCategory("LeadTemplate");
-
- //echo $total_excelColumns=$this->getNameFromNumber(4);
- $total_excelColumns='I';
- // Rename worksheet
- $objPHPExcel->getActiveSheet()->setTitle('ClosedLeads');
- $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);
- $objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(30);
- $objPHPExcel->getActiveSheet()->duplicateStyleArray(
- array(
- 'font' => array(
- 'name' => 'Times New Roman',
- 'bold' => true,
- 'italic' => false,
- 'size' => 12
- ),
- 'borders' => array(
- 'top' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
- 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
- 'left' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
- 'right' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE)
- ),
- 'alignment' => array(
- 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
- 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
- 'wrap' => true
- )
- ),
- 'A1:'.$total_excelColumns.'1'
- );
- // Set active sheet index to the first sheet, so Excel opens this as the first sheet
-
- // Add some data
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', 'Name')
- ->setCellValue('B1', 'City')
- ->setCellValue('C1', 'Email')
- ->setCellValue('D1', 'Mobile')
- ->setCellValue('E1', 'Suminsured')
- ->setCellValue('F1', 'Age')
- ->setCellValue('G1', 'No. Of Members')
- ->setCellValue('H1', 'Date on submit')
- ->setCellValue('I1', 'Lead Source');
-
- // Miscellaneous glyphs, UTF-8
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A2', 'Lead Name')
- ->setCellValue('B2', 'city')
- ->setCellValue('C2', 'test@yesk.com')
- ->setCellValue('D2', '9999999999')
- ->setCellValue('E2', '56')
- ->setCellValue('F2', '23')
- ->setCellValue('G2', 'test')
- ->setCellValue('H2', '07-Sep-2013')
- ->setCellValue('I2', 'test');
-
- //To create new sheet in current file
- /*$objPHPExcel->createSheet(1);
- $objPHPExcel->setActiveSheetIndex(1);
- $objPHPExcel->getActiveSheet()->setTitle('Title');
- */
-
- // Redirect output to a clientÂ’s web browser (Excel5)
- header('Content-Type: application/vnd.ms-excel');
- header('Content-Disposition: attachment;filename="LeadTemplates.xls"');
- header('Cache-Control: max-age=0');
- // If you're serving to IE 9, then the following may be needed
- header('Cache-Control: max-age=1');
- // If you're serving to IE over SSL, then the following may be needed
- header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
- header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
- header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
- header ('Pragma: public'); // HTTP/1.0
-
- $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- $objWriter->save('php://output');
- Yii::app()->end();
- }
- public function actionImportLeadTemplate(){
- $model=new lead();
- $data='';
- $final_arr=@$_POST['final_arr']?@$_POST['final_arr']:'';
-
- if(isset($_POST['ImportLeads']) && empty($final_arr) && !empty($_FILES['Lead']['name']['import'])){
-
- Yii::import('ext.phpexcelreader.JPhpExcelReader');
- $model->attributes='import';
- $model->import=CUploadedFile::getInstance($model,'import');
- $prefix=substr(time(),0,5);
- $folder = '/tempdata';
- $model->import->saveAs($folder.$prefix.$model->import);
- $data=new JPhpExcelReader($folder.$prefix.$model->import);
-
- //$this->render('bulk_import_lead',array('data'=>$data,'model'=>$model));
-
- //$this->redirect(Yii::app()->createUrl('leads/bulk_import_leads'),array('data'=>$data,'model'=>$model));
- $this->render('bulk_import_lead',array('data'=>$data,'model'=>$model));
- }
-
- if(isset($_POST['ImportLeads']) && !empty($final_arr) && isset($final_arr) && empty($_FILES['Lead']['name']['import'])){
- $final_arr = unserialize(urldecode($_POST["final_arr"]));
- $dateTime=time();
- /*echo '<pre>';
- print_r($final_arr);*/
- for($i=0;$i<sizeof($final_arr);$i++)
- {
- $leadStatusId = '0';
- $duplicateLeadId = '0';
- $currentAllocatedId = '0';
-
- $junkNumberQuery = Yii::app()->db->createCommand("SELECT `junkLeadNumberId` FROM `junkLeadNumberMaster` WHERE `junkLeadNumber` = '".@$final_arr[$i]['mobile']."' ")->queryAll();
- $junkNumberResult = $junkNumberQuery;
-
-
- $fetchAgentDetails=LeadSourceMaster::model()->findByPk($final_arr[$i]['leadSourceId']);
-
-
- //$duplicateQuery = Yii::app()->db->createCommand("SELECT `leadId` FROM `lead` WHERE `mobile`= '".@$final_arr[$i]['mobile']."' ")->queryAll();(Original, changed below by Baljeet)
- $duplicateQuery = Yii::app()->db->createCommand("SELECT `leadId`,`currentAllocatedId` FROM `lead` WHERE `mobile`= '".@$final_arr[$i]['mobile']."' order by leadId ASC LIMIT 1")->queryAll();
- $duplicateResult = ($duplicateQuery);
- //echo '<br>duplicateResult----------'.count($duplicateResult);
- if(count($junkNumberResult) > 0){
- $leadStatusId = '36';
- $duplicateLeadId = '';
- $currentAllocatedId = '';
- } elseif(count($duplicateResult)>0){
- $leadStatusId = '10';
- $duplicateLeadId = @$duplicateResult[0]['leadId'];
- $currentAllocatedId = @$duplicateResult[0]['currentAllocatedId']; //added by baljeet
- } else {
- $leadStatusId = '34';
- $duplicateLeadId = '';
- $currentAllocatedId = '';
- }
- /*echo '<br>leadStatusId---'.$leadStatusId;
- echo '<br>duplicateLeadId---'.$duplicateLeadId;
- echo '<br>currentAllocatedId---'.$currentAllocatedId;*/
-
- $model=new lead();
- $model->name=$final_arr[$i]['name'];
- $model->cityId=$final_arr[$i]['cityId'];
- $model->email=$final_arr[$i]['email'];
- $model->mobile=$final_arr[$i]['mobile'];
- $model->si=$final_arr[$i]['suminsured'];
- $model->age=$final_arr[$i]['age'];
- $model->members=$final_arr[$i]['noofmembers'];
- $model->dateonSubmit=$final_arr[$i]['dateonsubmit'];
- $model->leadSourceId=$final_arr[$i]['leadSourceId'];
- $model->leadStatusId=$leadStatusId;
- $model->duplicateLeadId=@$duplicateLeadId;
- $model->currentAllocatedId=@$currentAllocatedId;
- $model->productId='1';
- $model->status='Active';
- $model->createdOn=$dateTime;
- $model->createdBy=Yii::app()->session->get('id');
- $model->updatedOn=$dateTime;
- $model->updatedBy=Yii::app()->session->get('id');
- $model->isBulkImport='YES';
- $model->agentId = @$fetchAgentDetails->leadSourceCode;
- $model->ws_agentid = @$fetchAgentDetails->leadSourceCode;
- $model->isNewRecord = true;
- $model->save(false);
-
- }
- $this->redirect(array('leads/lead_list'));
- }
- if(isset($_POST['ImportLeads']) && empty($final_arr) && empty($_FILES['Lead']['name']['import'])){
- $model->validate();
- $this->render('bulk_import_lead',array('model'=>$model));
- }
- }
- public function actionleadSearch()
- {
- $searched = new Lead();
- if(@$_REQUEST['lead']['leadSearchBox']=='' && @$_REQUEST['mob']=='') {
- $this->redirect(array('leads/lead_list'));
- } else {
- $this->render('lead_search',array('searched'=>@$searched));
- }
- }
-
- public function actionExportExcel()
- {
- // It calls the actionCreateExcel to generates excel reports'
- $this->actionCreateExcel();
-
-
- }
-
- public function actionCreateExcel(){
-
- //Here is the code to set conditions for fetch records from database
- $criteria = new CDbCriteria;
- $criteria->select = 't.*,`city`.`city`, `state`.`state`, `leadSourceMaster`.`leadSourceTitle`,`leadSourceMaster`.`leadSourceCode`,`leadStageMaster`.`leadStage`,`leadStatus`.`leadStatus`, `customerTypeMaster`.`customerType`,`productMaster`.`productName`,`policyTypeMaster`.`policyType`,`planTypeMaster`.`planType`,`campaign`.`campaignName`';
- $criteria->join ='LEFT JOIN city ON (city.cityId = t.cityId) LEFT JOIN state ON (state.stateId = t.stateId) LEFT JOIN leadSourceMaster ON (leadSourceMaster.leadSourceId = t.leadSourceId) LEFT JOIN leadStageMaster ON (leadStageMaster.leadStageId = t.leadStageId)LEFT JOIN leadStatus ON (leadStatus.leadStatusId = t.leadStatusId)LEFT JOIN customerTypeMaster ON (customerTypeMaster.customerTypeId = t.customerTypeId)LEFT JOIN productMaster ON (productMaster.productId = t.productId)LEFT JOIN policyTypeMaster ON (policyTypeMaster.policyTypeId = t.policyTypeId)LEFT JOIN planTypeMaster ON (planTypeMaster.planTypeId = t.planTypeId)LEFT JOIN campaign ON (campaign.campaignId = t.campaignId)';
- $criteria->condition='t.status != "Allocated" AND t.leadStatusId != "25" AND t.leadStatusId != "26" ';
- $criteria->order='leadId DESC';
-
- $model=new LeadReport();
- $model->scenario = 'LeadReport';
- $reportmodel=LeadReport::model()->findAll($criteria);
- $data=array();
- $datas = $reportmodel;
- foreach($datas as $key=>$value){
- $data[$key]=$value;
- }
- if(count($data)>0){
- Yii::import('ext.phpexcel.XPHPExcel');
- $objPHPExcel= XPHPExcel::createPHPExcel();
- $objPHPExcel->getProperties()->setCreator("ReligareLMS")
- ->setLastModifiedBy("ReligareLMS")
- ->setTitle("Office 2007 XLSX Test Document")
- ->setSubject("Office 2007 XLSX Test Document")
- ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
- ->setKeywords("office 2007 openxml php")
- ->setCategory("Test result file");
- $total_excelColumns=$this->getNameFromNumber(8);
- // Rename worksheet
- $objPHPExcel->getActiveSheet()->setTitle('Sample Excel');
- $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);
- $objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(6);
- $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
-
- $objPHPExcel->getActiveSheet()->duplicateStyleArray(
- array(
- 'font' => array(
- 'name' => 'Times New Roman',
- 'bold' => true,
- 'italic' => false,
- 'size' => 12
- ),
- 'borders' => array(
- 'top' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
- 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
- 'left' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
- 'right' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE)
- ),
- 'alignment' => array(
- 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
- 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
- 'wrap' => true
- )
- ),
- 'A1:'.$total_excelColumns.'1'
- );
- // Set active sheet index to the first sheet, so Excel opens this as the first sheet
-
- // Add some data
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', 'SNO.')
- ->setCellValue('B1', 'Name')
- ->setCellValue('C1', 'Mobile')
- ->setCellValue('D1', 'Email')
- ->setCellValue('E1', 'Lead Stage')
- ->setCellValue('F1', 'Date and Time')
- ->setCellValue('G1', 'UTM Code')
- ->setCellValue('H1', 'status');
-
- // Miscellaneous glyphs, UTF-8
- $i=0;
- $k=2;
- $sn=1;
- while($i<count($data)){
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A'.$k,$sn)
- ->setCellValue('B'.$k,$data[$i]['name'])
- ->setCellValue('C'.$k,$data[$i]['mobile'])
- ->setCellValue('D'.$k,$data[$i]['email'])
- ->setCellValue('E'.$k,$data[$i]['leadStage'])
- ->setCellValue('F'.$k,date("d/m/y h:i A",$data[$i]['createdOn']))
- ->setCellValue('G'.$k,$data[$i]['leadSourceCode'])
- ->setCellValue('H'.$k,$data[$i]['status']);
-
- $i++;$k++;$sn++;}
- // Redirect output to a clientÂ’s web browser (Excel5)
- header('Content-Type: application/vnd.ms-excel');
- header('Content-Disposition: attachment;filename="lead_report.xls"');
- header('Cache-Control: max-age=0');
- // If you're serving to IE 9, then the following may be needed
- header('Cache-Control: max-age=1');
- // If you're serving to IE over SSL, then the following may be needed
- header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
- header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
- header ('Pragma: public'); // HTTP/1.0
-
- $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- $objWriter->save('php://output');
- Yii::app()->end();
- }
- else{
- $model = new Lead();
- $model = Lead::model()->findAll("status = 'Active'");
- $this->render('lead_list',array('model'=>$model));
- }
- }
-
- public function actiongetSourceResults(){
- $models=new Lead();
- $type=@$_REQUEST['type'];
- $searchTxt=@$_REQUEST['searchTxt'];
- if(isset($searchTxt) && !empty($searchTxt)){
- $this->renderPartial('searchSourceLeads',array('searchTxt'=>$searchTxt,'type'=>@$type));
- } else {
- if($type=='fresh'){
- $functs="fresh_leads";
- }
- if($type=='new'){
- $functs="lead_list";
- }
- if($type=='duplicate'){
- $functs="duplicate_lead_list";
- }
- if($type=='junk'){
- $functs="junk_lead_list";
- }
- if($type=='allocated'){
- $functs="allocated_lead_list";
- }
- if($type=='cip'){
- $functs="cip_lead_list";
- }
- if($type=='plc'){
- $functs="plc_lead_list";
- }
- if($type=='closed'){
- $functs="close_lead_list";
- }
- if($type==''){
- $functs="lead_list";
- }
- echo Yii::app()->createUrl('leads/'.@$functs);
- exit;
- }
- }
- public function actionAutocompleteSearch(){
- $models=new Lead();
- $term=@$_REQUEST['term'];
- $type=@$_REQUEST['type'];
- if($type=="fresh"){
- $models=Lead::model()->findAll(array("condition"=>"leadStatusId = '34' AND currentAllocatedId<1 and concat(name,mobile,email) like '%$term%'","order"=>"leadId desc"));
- }
- if($type=="new"){
- $relationManager = $_SESSION['relationalManager'];
- $managerMemberId = implode(",",array_unique(@$relationManager));
-
- if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
- $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead='no' ";
- } else {
- $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead='no' AND currentAllocatedId IN (".@$managerMemberId.") ";
- }
- $models = Lead::model()->findAll(" $querycondition and concat(name,mobile,email) like '%$term%'");
-
- //$models=Lead::model()->findAll(array("condition"=>"leadStatusId = '34' AND currentAllocatedId<1 and name like '%$term%'","order"=>"leadId desc"));
- }
- if($type=="duplicate"){
- $models=Lead::model()->findAll(array("condition"=>"leadStatusId = '10' and concat(name,mobile,email) like '%$term%'","order"=>"leadId desc"));
- }
- if($type=="dupforday"){
- $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
- $models=Lead::model()->findAll(array("condition"=>"leadStatusId = '10' AND createdOn > '".@$today12PM."' and concat(name,mobile,email) like '%$term%'","order"=>"leadId desc"));
- }
- if($type=="junk"){
- $models=Lead::model()->findAll(array("condition"=>"leadStatusId = '36' and concat(name,mobile,email) like '%$term%'","order"=>"leadId desc"));
- }
- if($type=="allocated"){
- $relationManager = $_SESSION['relationalManager'];
- $managerMemberId = implode(",",array_unique(@$relationManager));
- if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
- $querycondition = " currentAllocatedId>0 AND isRead = 'yes'";
- } else {
- $querycondition = " currentAllocatedId>0 AND isRead = 'yes' AND currentAllocatedId IN (".@$managerMemberId.") ";
- }
- $models = Lead::model()->findAll(" $querycondition and concat(name,mobile,email) like '%$term%'");
- }
- if($type=="followup"){
- $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
- $relationManager = $_SESSION['relationalManager'];
- $managerMemberId = implode(",",array_unique(@$relationManager));
- if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
- $querycondition = ' startDate = "'.@$today12PM.'" and status="Pending" ';
- } else {
- $querycondition = " startDate = '".@$starttimestamp."' AND status = 'Pending' AND userId IN (".@$managerMemberId.") ";
- }
- $models = LeadFollowup::model()->findAll(" $querycondition and description like '%$term%'");
- }
- if($type=="allfollowup"){
- $relationManager = $_SESSION['relationalManager'];
- $managerMemberId = implode(",",array_unique(@$relationManager));
- $currentDate=date('d-m-Y',time());
- $starttimestamp=strtotime($currentDate);
- if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
- $querycondition = ' status="Pending" ';
- } else {
- $querycondition = " status = 'Pending' AND userId IN (".@$managerMemberId.") ";
- }
- $models = LeadFollowup::model()->findAll(" $querycondition and description like '%$term%'");
- }
- if($type=="closed"){
- $relationManager = $_SESSION['relationalManager'];
- $managerMemberId = implode(",",array_unique(@$relationManager));
- if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
- $querycondition = "leadStatusId = '7'";
- } else {
- $querycondition = " leadStatusId = '7' AND currentAllocatedId IN (".@$managerMemberId.") ";
- }
- $models = Lead::model()->with("leadSourceDetails")->findAll(" $querycondition and concat(name,mobile,email) like '%$term%' ");
- }
- if($type=="cip"){
- $contactInProgList=Yii::app()->db->createCommand("select leadStatus.leadStatus,leadStatusId from leadStatus where parentId=3")->queryAll();
- $CIPids = array();
- if(count($contactInProgList) > 0){
- for($w=0;$w<count($contactInProgList);$w++){
- @$CIPids[] = @$contactInProgList[$w]['leadStatusId'];
- }
- } else {
- @$CIPids[] = '';
- }
-
- @$CIPids = implode(",",@$CIPids);
- $relationManager = $_SESSION['relationalManager'];
- $managerMemberId = implode(",",array_unique(@$relationManager));
- if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
- $querycondition = " leadStatusId IN ( ".@$CIPids." ) ";
- } else {
- $querycondition = " leadStatusId IN ( ".@$CIPids." ) AND currentAllocatedId IN (".@$managerMemberId.") ";
- }
- $models = Lead::model()->findAll(" $querycondition and concat(name,mobile,email) like '%$term%'");
- }
- if($type=="plc"){
- $contactInProgList=Yii::app()->db->createCommand("select leadStatus.leadStatus,leadStatusId from leadStatus where parentId=41")->queryAll();
- $CIPids = array();
- if(count($contactInProgList) > 0){
- for($w=0;$w<count($contactInProgList);$w++){
- @$CIPids[] = @$contactInProgList[$w]['leadStatusId'];
- }
- } else {
- @$CIPids[] = '';
- }
-
- @$CIPids = implode(",",@$CIPids);
- $relationManager = $_SESSION['relationalManager'];
- $managerMemberId = implode(",",array_unique(@$relationManager));
- if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
- $querycondition = " leadStatusId IN ( ".@$CIPids." ) ";
- } else {
- $querycondition = " leadStatusId IN ( ".@$CIPids." ) AND currentAllocatedId IN (".@$managerMemberId.") ";
- }
- $models = Lead::model()->findAll(" $querycondition and concat(name,mobile,email) like '%$term%'");
- }
- if($type=="cld"){
- $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
- $relationManager = $_SESSION['relationalManager'];
- $managerMemberId = implode(",",array_unique(@$relationManager));
- if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
- $querycondition = 'leadStatusId = 12 AND startDate = "'.@$today12PM.'" ';
- } else {
- $querycondition = "leadStatusId = 12 AND startDate = '".@$today12PM."' AND userId IN (".@$managerMemberId.") ";
- }
- $models = LeadFollowup::model()->findAll(" $querycondition and description like '%$term%'");
- }
- if($type=="followup" or $type=="allfollowup" or $type=="cld"){
- $arr = array();
- foreach($models as $model) {
- $arr[] = array(
- 'label'=>substr($model->description,0,10), // label for dropdown list
- 'value'=>substr($model->description,0,10), // value for input field
- 'id'=>$model->leadFollowupId, // return value from autocomplete
- );
- }
- if(count($models) > 0){
- $arr['totalRecords'] = array(
- 'totalRecords'=>count($models), // return value from autocomplete
- );
- }
- }else {
- $arr = array();
- foreach($models as $model) {
- $arr[] = array(
- 'label'=>$model->mobile?$model->mobile.($model->name?'/'.$model->name:'').($model->email?'/'.$model->email:''):'', // label for dropdown list
- 'value'=>$model->mobile?$model->mobile:$model->name, // value for input field
- 'id'=>$model->leadId, // return value from autocomplete
- );
- }
- if(count($models) > 0){
- $arr['totalRecords'] = array(
- 'totalRecords'=>count($models), // return value from autocomplete
- );
- }
- }
- echo CJSON::encode($arr);
- Yii::app()->end();
- //$this->renderPartial('searchLeads');
- }
- public function actionAutocompleteSearchSource(){
- $models=new Lead();
- $term=@$_REQUEST['term'];
- $type=@$_REQUEST['type'];
- if($type=="fresh"){
- $models=Lead::model()->with("leadSourceDetails")->findAll(array("condition"=>"leadStatusId = '34' AND currentAllocatedId<1 and concat(leadSourceTitle) like '%$term%'","order"=>"leadId desc"));
- }
- if($type=="new"){
- $relationManager = $_SESSION['relationalManager'];
- $managerMemberId = implode(",",array_unique(@$relationManager));
-
- if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
- $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead='no' ";
- } else {
- $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead='no' AND currentAllocatedId IN (".@$managerMemberId.") ";
- }
- $models = Lead::model()->with("leadSourceDetails")->findAll(" $querycondition and leadSourceTitle like '%$term%'");
-
- //$models=Lead::model()->findAll(array("condition"=>"leadStatusId = '34' AND currentAllocatedId<1 and name like '%$term%'","order"=>"leadId desc"));
- }
- if($type=="duplicate"){
- $models=Lead::model()->with("leadSourceDetails")->findAll(array("condition"=>"leadStatusId = '10' and leadSourceTitle like '%$term%'","order"=>"leadId desc"));
- }
- if($type=="junk"){
- $models=Lead::model()->with("leadSourceDetails")->findAll(array("condition"=>"leadStatusId = '36' and leadSourceTitle like '%$term%'","order"=>"leadId desc"));
- }
- if($type=="allocated"){
- $relationManager = $_SESSION['relationalManager'];
- $managerMemberId = implode(",",array_unique(@$relationManager));
- if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
- $querycondition = " currentAllocatedId>0 AND isRead = 'yes'";
- } else {
- $querycondition = " currentAllocatedId>0 AND isRead = 'yes' AND currentAllocatedId IN (".@$managerMemberId.") ";
- }
- $models = Lead::model()->with("leadSourceDetails")->findAll(" $querycondition and leadSourceTitle like '%$term%'");
- }
- if($type=="followup"){
- $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
- $relationManager = $_SESSION['relationalManager'];
- $managerMemberId = implode(",",array_unique(@$relationManager));
- if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
- $querycondition = ' startDate = "'.@$today12PM.'" and status="Pending" ';
- } else {
- $querycondition = " startDate = '".@$starttimestamp."' AND status = 'Pending' AND userId IN (".@$managerMemberId.") ";
- }
- $models = LeadFollowup::model()->findAll(" $querycondition and description leadSourceTitle '%$term%'");
- }
- if($type=="closed"){
- $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
- $relationManager = $_SESSION['relationalManager'];
- $managerMemberId = implode(",",array_unique(@$relationManager));
- if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
- $querycondition = "leadStatusId = '7'";
- } else {
- $querycondition = " leadStatusId = '7' AND currentAllocatedId IN (".@$managerMemberId.") ";
- }
- $models = Lead::model()->with("leadSourceDetails")->findAll(" $querycondition and leadSourceTitle like '%$term%' ");
- }
-
-
- if($type=="followup"){
- $arr = array();
- foreach($models as $model) {
- $arr[] = array(
- 'label'=>substr($model->description,0,10), // label for dropdown list
- 'value'=>substr($model->description,0,10), // value for input field
- 'id'=>$model->leadFollowupId, // return value from autocomplete
- );
- }
- if(count($models) > 0){
- $arr['totalRecords'] = array(
- 'totalRecords'=>count($models), // return value from autocomplete
- );
- }
- }else {
- $arr = array();
- foreach($models as $model) {
- $arr[] = array(
- 'label'=>$model->mobile?$model->mobile:$model->name, // label for dropdown list
- 'value'=>$model->mobile?$model->mobile:$model->name, // value for input field
- 'id'=>$model->leadId, // return value from autocomplete
- );
- }
- if(count($models) > 0){
- $arr['totalRecords'] = array(
- 'totalRecords'=>count($models), // return value from autocomplete
- );
- }
- }
- echo CJSON::encode($arr);
- Yii::app()->end();
- //$this->renderPartial('searchLeads');
- }
- public function actionAutocompleteSearchRes(){
- $models=new Lead();
- $term=@$_REQUEST['id'];
- $type=@$_REQUEST['type'];
- $models=Lead::model()->findAll(array("condition"=>"leadStatusId = '34' AND currentAllocatedId<1 and name like '%$term%'","order"=>"leadId desc"));
- $arr = array();
- $this->renderPartial('searchLeads',array('name'=>$term));
- }
- public function actionexportArchiveList(){
- $Leadname = @$_REQUEST['name'];
- $Leadstatus = @$_REQUEST['status'];
- $leadStage = @$_REQUEST['statge'];
- $cond ='';
- if(isset($Leadname) && !empty($Leadname)){
- $cond .=" AND name like '%".@$Leadname."%'";
- }
- if(isset($Leadstatus) && !empty($Leadstatus)){
- $cond .=" AND leadStatusId = '".@$Leadstatus."'";
- }
- if(isset($leadStage) && !empty($leadStage)){
- $cond .=" AND leadStageId = '".@$leadStage."'";
- }
-
- $dataProvider = new CActiveDataProvider('Lead', array('criteria'=>array(
- 'condition'=>' FROM_UNIXTIME(updatedOn) >= DATE_SUB(CURDATE(), INTERVAL 120 DAY) '.@$cond.' and leadStatusId NOT IN (12,8,1,4) ',
- 'order'=>'',
- )));
- $iterator = new CDataProviderIterator($dataProvider);
- $data=array();
- $datas = $iterator;
- foreach($datas as $key=>$value){
- $data[$key]=$value;
- }
- Yii::import('ext.phpexcel.XPHPExcel');
- $objPHPExcel= XPHPExcel::createPHPExcel();
- $objPHPExcel->getProperties()->setCreator("ReligareLMS")
- ->setLastModifiedBy("ReligareLMS")
- ->setTitle("Office 2007 XLSX Leads Document")
- ->setSubject("Office 2007 XLSX Leads Document")
- ->setDescription("Archive Leads.")
- ->setKeywords("Archive Leads")
- ->setCategory("Archive Leads");
- // Rename worksheet
- $objPHPExcel->getActiveSheet()->setTitle('Sample Excel');
- $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);
- $objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(6);
- $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('P')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('Q')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('R')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('S')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('T')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('U')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('V')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('W')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('X')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('y')->setWidth(30);
-
- $objPHPExcel->getActiveSheet()->duplicateStyleArray(
- array(
- 'font' => array(
- 'name' => 'Times New Roman',
- 'bold' => true,
- 'italic' => false,
- 'size' => 12
- ),
- 'borders' => array(
- 'top' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
- 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
- 'left' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
- 'right' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE)
- ),
- 'alignment' => array(
- 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
- 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
- 'wrap' => true
- )
- ),
- 'A1:Y1'
- );
- // Set active sheet index to the first sheet, so Excel opens this as the first sheet
-
- // Add some data
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', 'SNO.')
- ->setCellValue('B1', 'Name')
- ->setCellValue('C1', 'Mobile Number')
- ->setCellValue('D1', 'Email Id')
- ->setCellValue('E1', 'Address')
- ->setCellValue('F1', 'City')
- ->setCellValue('G1', 'State')
- ->setCellValue('H1', 'Members')
- ->setCellValue('I1', 'Premium')
- ->setCellValue('J1', 'Product Details')
- ->setCellValue('K1', 'Lead Status')
- ->setCellValue('L1', 'Status')
- ->setCellValue('M1', 'isJunk')
- ->setCellValue('N1', 'Lead Source')
- ->setCellValue('O1', 'Lead Stage')
- ->setCellValue('P1', 'Lead Description')
- ->setCellValue('Q1', 'Activity Description')
- ->setCellValue('R1', 'Customer Type')
- ->setCellValue('S1', 'Product Name')
- ->setCellValue('T1', 'Policy Type')
- ->setCellValue('U1', 'Plan Type')
- ->setCellValue('V1', 'Campaign Name')
- ->setCellValue('W1', 'UTM Code')
- ->setCellValue('X1', 'Owner')
- ->setCellValue('Y1', 'Last Modified Date');
-
-
- // Miscellaneous glyphs, UTF-8
- $i=0;
- $k=2;
- $sn=1;
- while($i<count($data)){
- $str = preg_replace('/\s\s+/', ' ', $data[$i]['address']);
-
- if($data[$i]['currentAllocatedId']==$data[$i]['createdBy']){
- $owner = $data[$i]['ownerDetails']['firstName']." ".$data[$i]['ownerDetails']['lastName']."(C)";
- } else {
- if(isset($data[$i]['ownerDetails']['firstName']) && !empty($data[$i]['ownerDetails']['firstName'])){
- $owner = $data[$i]['ownerDetails']['firstName']." ".$data[$i]['ownerDetails']['lastName'];
- } else {
- $owner = "NA";
- }
- }
-
- $descrecords=Yii::app()->db->createCommand("select leadDescription from lead where leadId='".@$data[$i]['leadId']."' ")->queryAll();
-
-
-
- $records=Yii::app()->db->createCommand("select description from leadFollowup where leadId='".@$data[$i]['leadId']."' ")->queryAll();
- $ActivityRes = '';
- for($j=0;$j<count($records);$j++){
- @$ActivityRes .= @$records[0]['description'].",";
- }
- $lastModifieddate = date("d M Y H:i:s A",$data[$i]['updatedOn']);
-
- //ReportsController::getLeadDescription(@$data->leadId);
- //$data[$i]['ownerDetails']['firstName'];
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A'.$k,$sn)
- ->setCellValue('B'.$k,$data[$i]['name'])
- ->setCellValue('C'.$k,$data[$i]['mobile'])
- ->setCellValue('D'.$k,$data[$i]['email'])
- ->setCellValue('E'.$k,$str)
- ->setCellValue('F'.$k,$data[$i]['city'])
- ->setCellValue('G'.$k,$data[$i]['state'])
- ->setCellValue('H'.$k,$data[$i]['members'])
- ->setCellValue('I'.$k,$data[$i]['premium'])
- ->setCellValue('J'.$k,$data[$i]['productDetails'])
- ->setCellValue('K'.$k,$data[$i]['leadStatusDetails']['leadStatus'])
- ->setCellValue('L'.$k,$data[$i]['status'])
- ->setCellValue('M'.$k,$data[$i]['isJunk'])
- ->setCellValue('N'.$k,$data[$i]['leadSourceTitle'])
- ->setCellValue('O'.$k,$data[$i]['leadStage'])
- ->setCellValue('P'.$k,@$descrecords[0]['leadDescription'])
- ->setCellValue('Q'.$k,@$ActivityRes)
- ->setCellValue('R'.$k,$data[$i]['customerType'])
- ->setCellValue('S'.$k,$data[$i]['productName'])
- ->setCellValue('T'.$k,$data[$i]['policyType'])
- ->setCellValue('U'.$k,$data[$i]['planType'])
- ->setCellValue('V'.$k,$data[$i]['campaignName'])
- ->setCellValue('W'.$k,$data[$i]['leadSourceCode'])
- ->setCellValue('X'.$k,$owner)
- ->setCellValue('Y'.$k,$lastModifieddate);
- $i++;$k++;$sn++;}
- // Redirect output to a clientÂ’s web browser (Excel5)
- header('Content-Type: application/vnd.ms-excel');
- header('Content-Disposition: attachment;filename="lead_report.xls"');
- header('Cache-Control: max-age=0');
- // If you're serving to IE 9, then the following may be needed
- header('Cache-Control: max-age=1');
- // If you're serving to IE over SSL, then the following may be needed
- header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
- header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
- header ('Pragma: public'); // HTTP/1.0
-
- $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- $objWriter->save('php://output');
- Yii::app()->end();
-
- }
- public function actiongetCityList()
- {
- $data=City::model()->findAll(array('condition'=>'stateId=:stateId and status=:status','params'=>array(':stateId'=>(int) $_POST['stateId'],'status'=>'Active')));
- $data=CHtml::listData($data,'cityId','city');
- echo '<select class="styled" name="Lead[cityId]" style="position: absolute; opacity: 0; font-size: 12px; height: 25px;" onchange="changeText();">';
- echo '<option value="" selected="selected">Select City</option>';
- foreach($data as $value=>$name)
- {
- echo CHtml::tag('option',array('value'=>$value),CHtml::encode($name));
- }
- echo '</select>';
- echo '<span id="changeText" class="customStyleSelectBox" style="display: block;width:97px;"><span class="customStyleSelectBoxInner" style="width: 81px; display: block;">Select City</span></span>';
- }
- public function actiongetLeadStatus()
- {
- if(isset($_POST['parentId']) && !empty($_POST['parentId'])){
- $data=LeadStatus::model()->findAll(array('condition'=>'parentId=:parentId and status=:status','params'=>array(':parentId'=>(int) @$_POST['parentId'],'status'=>'Active')));
- $data=CHtml::listData($data,'leadStatusId','leadStatus');
- echo '<select class="styled" name="Lead[leadStatusId]" style="position: absolute; opacity: 0; font-size: 12px; height: 25px;" id="leadprimarystatus" onchange="changeStatusText();getActionRes(this.value);">';
- echo '<option value="" selected="selected">Select lead Status</option>';
- foreach($data as $value=>$name)
- {
- echo CHtml::tag('option',array('value'=>$value),CHtml::encode($name));
- }
- echo '</select>';
- } else {
- echo '<select class="styled" name="Lead[leadStatusId]" style="position: absolute; opacity: 0; font-size: 12px; height: 25px;" id="leadprimarystatus" onchange="changeStatusText();getActionRes(this.value);">';
- echo '<option value="" selected="selected">Select lead Status</option>';
- echo '</select>';
- }
- echo '<span id="changeStatusText" class="customStyleSelectBox" style="display: block;min-width:142px;"><span class="customStyleSelectBoxInner" style="width: 81px; display: block;">Select lead Status</span></span>';
- }
- public function actionexportLeads(){
-
- $model=new Lead();
- $type=@$_REQUEST['type'];
- $relationManager = @$_SESSION['relationalManager'];
- $managerMemberId = implode(",",array_unique(@$relationManager));
- $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
-
- if($type=="freshLeads"){
- if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
- $querycondition = " leadStatusId = '34' AND currentAllocatedId<1";
- } else {
- $querycondition = " leadStatusId = '34' AND currentAllocatedId<1";
- }
- $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
- 'condition'=>@$querycondition,
- 'order'=>'leadId DESC',
- ),
- 'pagination'=>false,
- ));
- }
- if($type=="newLeads"){
- if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
- $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead = 'no' ";
- } else {
- $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead = 'no' AND currentAllocatedId IN (".@$managerMemberId.") ";
- }
-
- $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
- 'condition'=>@$querycondition,
- 'order'=>'leadId DESC',
- ),
- 'pagination'=>array(
- 'pageSize'=> 10,
- ),
- ));
- }
-
- if($type=="allocatedLeads"){
- if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
- $queryCondition = " currentAllocatedId>0 AND isRead = 'yes' ";
- } else {
- $queryCondition = " currentAllocatedId>0 AND isRead = 'yes' AND currentAllocatedId IN (".@$managerMemberId.") ";
- }
- $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
- 'condition'=>@$queryCondition,
- 'order'=>'leadId DESC',
- )));
- }
- if($type=="Allfollowup"){
-
- $currentDate=date('d-m-Y',time());
- $starttimestamp=strtotime($currentDate);
- if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
- $queryCondition = ' status="Pending" and userId = "'.@$_SESSION['id'].'" ';
- } else {
- $queryCondition = " status = 'Pending' AND userId IN (".@$managerMemberId.") ";
- }
- $dataProvider=new CActiveDataProvider('LeadFollowup', array('criteria'=>array(
- 'condition'=>@$queryCondition,
- 'order'=>'leadFollowupId DESC',
- )));
- }
- if($type=="followupLeads"){
-
- $currentDate=date('d-m-Y',time());
- $starttimestamp=strtotime($currentDate);
- if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
- $queryCondition = ' startDate = "'.@$starttimestamp.'" and status="Pending" and userId = "'.@$_SESSION['id'].'" ';
- } else {
- $queryCondition = " startDate = '".@$starttimestamp."' AND status = 'Pending' AND userId IN (".@$managerMemberId.") ";
- }
- $dataProvider=new CActiveDataProvider('LeadFollowup', array('criteria'=>array(
- 'condition'=>@$queryCondition,
- 'order'=>'leadFollowupId DESC',
- )));
- }
- if($type=="duplicateLeads"){
- $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
- 'condition'=>' leadStatusId = "10" ',
- 'order'=>'leadId DESC',
- )));
- }
- if($type=="dupforday"){
- $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
- $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
- 'condition'=>' leadStatusId = "10" AND createdOn > "'.@$today12PM.'" ',
- 'order'=>'leadId DESC',
- )));
- }
- if($type=="junkLeads"){
- $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
- 'condition'=>' leadStatusId = "36" ',
- 'order'=>'leadId DESC',
- )));
- }
- if($type=="closeLeads"){
- if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
- $querycondition = "leadStatusId = '7' ";
- } else {
- $querycondition = " leadStatusId = '7' AND currentAllocatedId IN (".@$managerMemberId.") ";
- }
- $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
- 'condition'=>@$querycondition,
- 'order'=>'leadId desc',
- ),
- ));
- }
- if($type=="cip"){
- $contactInProgList=Yii::app()->db->createCommand("select leadStatus.leadStatus,leadStatusId from leadStatus where parentId=3")->queryAll();
- $CIPids = array();
- if(count($contactInProgList) > 0){
- for($w=0;$w<count($contactInProgList);$w++){
- @$CIPids[] = @$contactInProgList[$w]['leadStatusId'];
- }
- } else {
- @$CIPids[] = '';
- }
- @$CIPids = implode(",",@$CIPids);
-
- if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
- $querycondition = "leadStatusId IN ( ".@$CIPids." ) ";
- } else {
- $querycondition = " leadStatusId IN ( ".@$CIPids." ) AND currentAllocatedId IN (".@$managerMemberId.") ";
- }
- $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
- 'condition'=>@$querycondition,
- 'order'=>'leadId desc',
- ),
- 'pagination'=>false,
- ));
- }
- if($type=="plc"){
- $contactInProgList=Yii::app()->db->createCommand("select leadStatus.leadStatus,leadStatusId from leadStatus where parentId=41")->queryAll();
- $CIPids = array();
- if(count($contactInProgList) > 0){
- for($w=0;$w<count($contactInProgList);$w++){
- @$CIPids[] = @$contactInProgList[$w]['leadStatusId'];
- }
- } else {
- @$CIPids[] = '';
- }
- @$CIPids = implode(",",@$CIPids);
-
- if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
- $querycondition = "leadStatusId IN ( ".@$CIPids." )";
- } else {
- $querycondition = " leadStatusId IN ( ".@$CIPids." ) AND currentAllocatedId IN (".@$managerMemberId.") ";
- }
-
- $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
- 'condition'=>@$querycondition,
- 'order'=>'leadId desc',
- ),
- 'pagination'=>false,
- ));
- }
- $dataProvider->getTotalItemCount($dataProvider);
-
-
-
- if($type=="followupLeads" or $type=="Allfollowup"){
- $iterator = new CDataProviderIterator($dataProvider);
- $file_name = "lms" . "_" . date("Y-m-d_H-i", time()) . ".csv";
- header('Content-Type: text/html; charset=utf-8');
- header("Content-type: application/octet-stream");
- header("Content-Disposition: attachment; filename=\"$file_name\"");
- header("Cache-Control: cache, must-revalidate");
- header("Pragma: public");
- $col = array(
- 'SNO.','Name','Mobile','AgentId','Lead Desciption','Activity Desciption','Email','Action Type','Date and Time','Description','Owner');
-
- foreach ($col as $key => $value) {
- echo $value . ",";
- }
- echo "\n";
- $i=1;
- foreach($iterator as $data) {
- echo $i++ . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->leadDetails->name)) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->leadDetails->mobile)) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->leadDetails->ws_agentid)) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->leadDetails->leadDescription)) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->description)) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->leadDetails->email)) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->actionType)) . ",";
- echo date("d/m/y h:i A",$data->createdOn) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->description)) . ",";
- echo (@$data->userId==@$data->leadDetails->createdBy)?@$data->ownerDetails->firstName." ".@$data->ownerDetails->lastName."(C)":(@$data->ownerDetails->firstName?@$data->ownerDetails->firstName." ".@$data->ownerDetails->lastName:"NA") . ",";
- echo "\n";
- }
- } else {
- $iterator = new CDataProviderIterator($dataProvider);
- $file_name = "lms" . "_" . date("Y-m-d_H-i", time()) . ".csv";
- header('Content-Type: text/html; charset=utf-8');
- header("Content-type: application/octet-stream");
- header("Content-Disposition: attachment; filename=\"$file_name\"");
- header("Cache-Control: cache, must-revalidate");
- header("Pragma: public");
- $col = array(
- 'SNO.','Name','Mobile','AgentId','Lead Desciption','Activity Desciption','Email','Lead Stage','Date and Time','Lead Status','Owner','status');
-
- foreach ($col as $key => $value) {
- echo $value . ",";
- }
-
- echo "\n";
- $i=1;
- foreach($iterator as $data) {
-
- $sqlDesc = "select group_concat(description) as ActivityDescription from leadFollowup where leadId=".@$data->leadId." ";
- $dataDesc=Yii::app()->db->createCommand($sqlDesc)->queryAll();
-
- $leadActivity = @$dataDesc[0]['ActivityDescription']?@$dataDesc[0]['ActivityDescription']:'';
-
-
- echo $i++ . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->name)) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->mobile)) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->ws_agentid)) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->leadDescription)) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$leadActivity)) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->email)) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data['leadStageDetails']['leadStage'])) . ",";
- echo date("d/m/y h:i A",$data->createdOn) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->leadStatusDetails->leadStatus)) . ",";
- echo (@$data->currentAllocatedId==@$data->createdBy)?@$data->ownerDetails->firstName." ".@$data->ownerDetails->lastName."(C)":(@$data->ownerDetails->firstName?@$data->ownerDetails->firstName." ".@$data->ownerDetails->lastName:"NA") . ",";
- echo "\n";
- }
- }
- }
- public function actionapiPremimum()
- {
- $model = new Lead();
- global $INDIVIDUAL,$FAMILYFLOATER,$GroupCareArray;
-
- $INDIVIDUAL = array(
- "200000" => "001",
- "300000" => "003",
- "400000" => "005",
- "500000" => "007",
- "700000" => "009",
- "1000000" => "011",
- "1500000" => "013",
- "2000000" => "015",
- "2500000" => "017",
- "5000000" => "019",
- "6000000" => "021"
- );
- $FAMILYFLOATER = array(
- "200000" => "002",
- "300000" => "004",
- "400000" => "006",
- "500000" => "008",
- "700000" => "010",
- "1000000" => "012",
- "1500000" => "014",
- "2000000" => "016",
- "2500000" => "018",
- "5000000" => "020",
- "6000000" => "022"
- );
- $res = new MySanitizeClass;
- $parser = new CHtmlPurifier();
- if(is_array(@$_REQUEST['ageGroupOfEldestMember'])){
- @$_REQUEST['ageGroupOfEldestMember'] = '';
- } else {
- @$_REQUEST['ageGroupOfEldestMember'] = @$_REQUEST['ageGroupOfEldestMember'];
- }
-
-
- if(is_array(@$_REQUEST['numberOfAdult'])){
- @$_REQUEST['numberOfAdult'] = '';
- } else {
- @$_REQUEST['numberOfAdult'] = @$_REQUEST['numberOfAdult'];
- }
-
-
- if(is_array(@$_REQUEST['coverTypeCd'])){
- @$_REQUEST['coverTypeCd'] = '';
- } else {
- @$_REQUEST['coverTypeCd'] = @$_REQUEST['coverTypeCd'];
- }
-
- if(is_array(@$_REQUEST['numberOfChildren'])){
- @$_REQUEST['numberOfChildren'] = '';
- } else {
- @$_REQUEST['numberOfChildren'] = @$_REQUEST['numberOfChildren'];
- }
-
-
- if(is_array(@$_REQUEST['productId'])){
- @$_REQUEST['productId'] = '';
- } else {
- @$_REQUEST['productId'] = @$_REQUEST['productId'];
- }
-
-
- if(is_array(@$_REQUEST['productTerm'])){
- @$_REQUEST['productTerm'] = '';
- } else {
- @$_REQUEST['productTerm'] = @$_REQUEST['productTerm'];
- }
-
- if(is_array(@$_REQUEST['sumInsured'])){
- @$_REQUEST['sumInsured'] = '';
- } else {
- @$_REQUEST['sumInsured'] = @$_REQUEST['sumInsured'];
- }
- if(is_array(@$_REQUEST['tenure'])){
- @$_REQUEST['tenure'] = '';
- } else {
- @$_REQUEST['tenure'] = @$_REQUEST['tenure'];
- }
- $query['ageGroupOfEldestMember']=$parser->purify(@$_REQUEST['ageGroupOfEldestMember']);
- $query['coverTypeCd']=$parser->purify(@$_REQUEST['coverTypeCd']);
- $query['productId']=$parser->purify(@$productId1);
- $query['productTerm']=$parser->purify(@$_REQUEST['productTerm']);
- $query['sumInsured']=$parser->purify(@$_REQUEST['sumInsured']);
- if(@$_REQUEST['coverTypeCd']=="INDIVIDUAL"){
- $sumInsured=$parser->purify(intval(@$_REQUEST['sumInsured']));
- if(@$sumInsured>0){
- $sumInsured1=@$INDIVIDUAL[@$sumInsured];
- }
- $query['numberOfAdult']=$parser->purify(@$_REQUEST['numberOfAdult']);
- $query['numberOfChildren']=0;
- }else{
- $sumInsured=$parser->purify(intval(@$_REQUEST['sumInsured']));
- if(@$sumInsured>0){
- $sumInsured1=@$FAMILYFLOATER[@$sumInsured];
- }
- $query['numberOfAdult']=$parser->purify(@$_REQUEST['numberOfAdult']);
- $query['numberOfChildren']=$parser->purify(@$_REQUEST['numberOfChildren']);
- }
- $query['sumInsured1']=@$sumInsured1;
-
- /*$_SESSION['ageGroupOfEldestMember']=@$query['ageGroupOfEldestMember'];// assign value to session for product tab
- $_SESSION['coverTypeCd'] =@$query['coverTypeCd'];// assign value to session for product tab
- $_SESSION['numberOfAdult'] =@$query['numberOfAdult']+$query['numberOfChildren'];// assign value to session for product tab
- $_SESSION['numberOfChildren'] =@$query['numberOfChildren'];// assign value to session for product tab
- $_SESSION['sumInsured'] =@$sumInsured;// assign value to session for product tab*/
-
- $premiumArray=$this->csvToArray('tempdata/care_premium.csv');
- $totalMember=$query['numberOfAdult']+$query['numberOfChildren'];
- $planKey=$query['coverTypeCd'].":".$query['ageGroupOfEldestMember'].":".@$totalMember.":".$query['numberOfChildren'].":".$query['sumInsured1'];
- $exactPremiumArray=$this->search(@$premiumArray,'Plan',@$planKey);
-
- $exactCarePremiumArray=explode(":",@$exactPremiumArray[0]['Premium']);
- $tenureidx = @$_REQUEST['tenure']-1;
- $carePremium = @$exactCarePremiumArray[@$tenureidx];
- //print_r($exactCarePremiumArray);
-
- $ncppremiumArray=$this->csvToArray('tempdata/ncb_premium.csv');
- $ncbtotalMember=$query['numberOfAdult']+$query['numberOfChildren'];
- $ncbplanKey=$query['coverTypeCd'].":".$query['ageGroupOfEldestMember'].":".@$ncbtotalMember.":".$query['numberOfChildren'].":".$query['sumInsured1'];
- $ncbexactPremiumArray=$this->search(@$ncppremiumArray,'Plan',@$ncbplanKey);
- $exactNCBPremiumArray=explode(":",@$ncbexactPremiumArray[0]['Premium']);
- //$tenureidx = $_REQUEST['tenure']-1;
- $ncbPremium = @$exactNCBPremiumArray[@$tenureidx];
- $addCarePremium = str_replace(',','',@$carePremium);
- $addNCBPremium = str_replace(',','',@$ncbPremium);
- $finalNcbPremium = number_format($addNCBPremium+$addCarePremium);
-
- //print_r($premiumArray);
- echo trim(@$carePremium).':'.trim(@$finalNcbPremium);
- // echo @$exactPremiumArray[0]['Premium'];
- //$this->render('lead_search',array('searched'=>$searched));
- }
- function csvToArray($csvFileName){
- $row = 1;
- $dataArray=array();
- $columnArray=array();
- $k=0;
- $i=0;
- if (($handle = fopen($csvFileName, "r")) !== FALSE) {
- while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) {
- $num = count($data);
- if($k==0){
- for ($c=0; $c < $num; $c++) {
- $columnArray[$c]=@$data[$c];
- }
- }else{
- for ($c=0; $c < $num; $c++) {
- $columnName=$columnArray[$c];
- $dataArray[$i][$columnName]=@$data[$c];
- }
- $i++;
- }
- $k++;
- $row++;
- }
- fclose($handle);
- }
- return $dataArray;
- }
- function search($array, $key, $value){
- $results = array();
-
- if (is_array($array))
- {
- if (isset($array[$key]) && $array[$key] == $value)
- $results[] = $array;
-
- foreach ($array as $subarray){
- $results = array_merge($results, $this->search($subarray, $key, $value));
- }
- }
-
- return $results;
- }
- function quotesResults(){
-
-
- }
- public function actiongetPlanDetails(){
-
- }
- public function actionleadCreation(){
- include_once("api/api.php");
-
- $pageList = $this->xml2array(@file_get_contents(ADMINURL.'resource/product_subcategory.xml'),'1','');
- $pageListArray = @$pageList['ProductSubCategory'];
- $subcategoryList = $this->subcategory_page_array($pageListArray);
- if(sanitize_data(@$_REQUEST['productId'])>0){
- for($i=0; $i<count($subcategoryList); $i++){
- if($subcategoryList[$i]["subCategoryId"]==sanitize_data($_REQUEST['productId']))
- {
- @$productId1="Care";
- }
- }
- }else{
- @$productId1="";
- }
- $query['coverTypeCd']=(@$_REQUEST['coverTypeCd']);
- $query['productId']=@$productId1;
- $query['sumInsured']=(@$_REQUEST['sumInsured']);
- // if(@$_REQUEST['coverTypeCd']=="INDIVIDUAL"){
- // switch(@$_REQUEST['sumInsured']){
- // case '200000': $sumInsured1="001";
- // break;
- // case '300000': $sumInsured1="003";
- // break;
- // case '500000': $sumInsured1="005";
- // break;
- // case '1000000': $sumInsured1="007";
- // break;
- // default: $sumInsured1="007";
- // break;
- // }
- // }else{
- // switch(@$_REQUEST['sumInsured']){
- // case '200000': $sumInsured1="002";
- // break;
- // case '300000': $sumInsured1="004";
- // break;
- // case '500000': $sumInsured1="006";
- // break;
- // case '1000000': $sumInsured1="008";
- // break;
- // default: $sumInsured1="008";
- // break;
- // }
- // }
- $tenure=(@$_REQUEST['tenure']);
- $leadstage=(@$_POST['leadstage']);
- $subject=(@$_POST['subject']);
- $query['sumInsured1']=(@$_REQUEST['sumInsured']);
- $query['firstname']=(@$_REQUEST["firstname"]);
- $query['lastname']="";
- $query['emailaddress1']=(@$_REQUEST["emailaddress1"]);
- $query['telephone1']=(@$_REQUEST["telephone1"]);
- $query['mobilephone']=(@$_REQUEST["mobilephone"]);
- $query['premium']=(@$_REQUEST["premium".@$tenure]);
- if(@$_SESSION['agentId']!=''){
- $query['agentid']=@$_SESSION['agentId'];
- }else{
- $query['agentid']=AGENTID;
- }
- $query['noofyears']=@$tenure;
- $query['quoteid']=time();
- if(@$leadstage!=''){
- $query['leadstage']=@$leadstage;
- }else{
- $query['leadstage']="SendQuotation";
- }
- if(@$subject!=''){
- $query['subject']=@$subject." - ".(@$_REQUEST["mobilephone"]);
- }else{
- $query['subject']="Web-".(@$_REQUEST["mobilephone"]);
- }
-
- $dataArray= $this->LeadCreation($query);
- $_SESSION["quotationReferenceNum"]=$query['quoteid'];
- $_SESSION['mobileSend']="2";
- $_SESSION['mobilephone']=(@$_REQUEST["mobilephone"]);
-
- }
- public function actionportalProposal(){
- define("_SITEURL", "http://" . @$_SERVER['SERVER_NAME']. '/religare') ;
- define("ADMINURL", "../", true);
- global $INDIVIDUAL,$FAMILYFLOATER,$GroupCareArray;
- $GroupCareArray = array("200000" => "2 Lac + 2 Lac", "300000" => "3 Lac + 3 Lac", "400000" => "4 Lac + 4 Lac", "500000" => "5 Lac + 5 Lac", "700000" => "7 Lac + 7 Lac", "1000000" => "10 Lac + 10 Lac", "1500000" => "15 Lac + 10 Lac", "2000000" => "20 Lac + 10 Lac", "2500000" => "25 Lac + 10 Lac", "5000000" => "50 Lac + 10 Lac", "6000000" => "60 Lac + 10 Lac");
- $INDIVIDUAL = array(
- "200000" => "001",
- "300000" => "003",
- "400000" => "005",
- "500000" => "007",
- "700000" => "009",
- "1000000" => "011",
- "1500000" => "013",
- "2000000" => "015",
- "2500000" => "017",
- "5000000" => "019",
- "6000000" => "021"
- );
- $FAMILYFLOATER = array(
- "200000" => "002",
- "300000" => "004",
- "400000" => "006",
- "500000" => "008",
- "700000" => "010",
- "1000000" => "012",
- "1500000" => "014",
- "2000000" => "016",
- "2500000" => "018",
- "5000000" => "020",
- "6000000" => "022"
- );
- $WEBSUMINSURED = array(
- "200000" => "1",
- "300000" => "2",
- "400000" => "3",
- "500000" => "4",
- "700000" => "5",
- "1000000" => "6",
- "1500000" => "7",
- "2000000" => "8",
- "2500000" => "9",
- "5000000" => "10",
- "6000000" => "11"
- );
- $WEBSUMINSURED1 = array(
- "1" => "200000",
- "2" => "300000",
- "3" => "400000",
- "4" => "500000",
- "5" => "700000",
- "6" => "1000000",
- "7" => "1500000",
- "8" => "2000000",
- "9" => "2500000",
- "10" => "5000000",
- "11" => "6000000"
- );
- $proposalURL="https://rhicluat.religare.com/portalui/PortalExtProposal.run";
-
-
- $pageList = $this->xml2array(@file_get_contents('resource/product_subcategory.xml'),'1','');
- $pageListArray = @$pageList['ProductSubCategory'];
- $subcategoryList = $this->subcategory_page_array($pageListArray);
- $productId=(@$_POST['productId']);
- $sumInsured=(@$_POST['sumInsured']);
- $tenure=(@$_POST['premium']);
- $totalAdults=(@$_POST['numberOfAdult']);
- $numberOfChildren=(@$_POST['numberOfChildren']);
- $numberOfAdult=$totalAdults-$numberOfChildren;
- $mobileNumber=(@$_POST['mobile']);
- $_SESSION['mobilephone']=$mobileNumber;
- if($productId>0){
- for($i=0; $i<count($subcategoryList); $i++){
- if($subcategoryList[$i]["subCategoryId"]==$productId)
- {
- @$productId1=$subcategoryList[$i]["productCode"];
- }
- }
- }else{
- @$productId1="";
- }
-
- if(($tenure==1) || ($tenure==2) || ($tenure==3)){}else{header("Location: "._SITEURL);exit;}
- if($productId1==""){header("Location: "._SITEURL);exit;}else{}
- if(($numberOfChildren==0) || ($numberOfChildren==1) || ($numberOfChildren==2) || ($numberOfChildren==3) || ($numberOfChildren==4)){}else{ header("Location: "._SITEURL);exit;}
- if($totalAdults>1){
-
- $ageGroupOfEldestMember=(@$_POST['ageGroupOfEldestMember']);
- switch($ageGroupOfEldestMember){
- case '18 - 24': $ageGroupOfEldestMember="18 - 24";
- break;
- case '25 - 35': $ageGroupOfEldestMember="25 - 35";
- break;
- case '36 - 40': $ageGroupOfEldestMember="36 - 40";
- break;
- case '41 - 45': $ageGroupOfEldestMember="41 - 45";
- break;
- case '46 - 50': $ageGroupOfEldestMember="46 - 50";
- break;
- case '51 - 55': $ageGroupOfEldestMember="51 - 55";
- break;
- case '56 - 60': $ageGroupOfEldestMember="56 - 60";
- break;
- case '61 - 65': $ageGroupOfEldestMember="61 - 65";
- break;
- case '66 - 70': $ageGroupOfEldestMember="66 - 70";
- break;
- case '71 - 75': $ageGroupOfEldestMember="71 - 75";
- break;
- case '76 - 99': $ageGroupOfEldestMember="76 - 99";
- break;
- default: $ageGroupOfEldestMember="";
- break;
- }
-
- if($ageGroupOfEldestMember==""){header("Location: "._SITEURL);exit;}else{}
- $coverType="FAMILYFLOATER";
- if(@$sumInsured>0){
- $sumInsured1=$FAMILYFLOATER[@$sumInsured];
- }
- if($sumInsured1==""){header("Location: "._SITEURL);exit;}else{}
- //$url1="&numberOfAdult=".@$numberOfAdult."&numberOfChildren=".@$numberOfChildren;
- // $url="Location: ".@$proposalURL."?productFamily=HEALTH&pCode=".@$productId1."&coverType=FAMILYFLOATER&ageGroupOfEldestMember=".@$ageGroupOfEldestMember."&sumInsured=".@$sumInsured1."&tenure=".@$tenure.$url1."&mobileNum=".@$_POST['mobile'];
- }else if($totalAdults=="1"){
- $ageGroupOfEldestMember=@$_POST['ageGroupOfEldestMember'];
-
- switch($ageGroupOfEldestMember){
- case '5 - 24': $ageGroupOfEldestMember="5 - 24";
- break;
- case '25 - 35': $ageGroupOfEldestMember="25 - 35";
- break;
- case '36 - 40': $ageGroupOfEldestMember="36 - 40";
- break;
- case '41 - 45': $ageGroupOfEldestMember="41 - 45";
- break;
- case '46 - 50': $ageGroupOfEldestMember="46 - 50";
- break;
- case '51 - 55': $ageGroupOfEldestMember="51 - 55";
- break;
- case '56 - 60': $ageGroupOfEldestMember="56 - 60";
- break;
- case '61 - 65': $ageGroupOfEldestMember="61 - 65";
- break;
- case '66 - 70': $ageGroupOfEldestMember="66 - 70";
- break;
- case '71 - 75': $ageGroupOfEldestMember="71 - 75";
- break;
- case '76 - 99': $ageGroupOfEldestMember="76 - 99";
- break;
- default: $ageGroupOfEldestMember="";
- break;
- }
- $coverType="INDIVIDUAL";
-
- if($ageGroupOfEldestMember==""){header("Location: "._SITEURL);exit;}else{}
- if(@$sumInsured>0){
- $sumInsured1=$INDIVIDUAL[@$sumInsured];
- }
-
-
- if($sumInsured1==""){header("Location: "._SITEURL);exit;}else{}
- $numberOfAdult=0;
- $numberOfChildren=0;
-
- // $url1="&numberOfAdult=0&numberOfChildren=0";
- //$url="Location: ".@$proposalURL."?productFamily=HEALTH&pCode=".@$productId1."&coverType=INDIVIDUAL&ageGroupOfEldestMember=".@$ageGroupOfEldestMember."&sumInsured=".@$sumInsured1."&tenure=".@$tenure.$url1."&mobileNum=".@$_SESSION['mobilephone'];
- }else{
- header("Location: "._SITEURL);exit;
- }
- ?>
- <form name="PortalProposal" id="PortalProposal" method="post" action="<?=@$proposalURL;?>">
- <input type="hidden" name="productFamily" value="HEALTH" />
- <input type="hidden" name="pCode" value="<?=@$productId1;?>" />
- <input type="hidden" name="coverType" value="<?=@$coverType;?>" />
- <input type="hidden" name="ageGroupOfEldestMember" value="<?=@$ageGroupOfEldestMember;?>" />
- <input type="hidden" name="sumInsured" value="<?=@$sumInsured1;?>" />
- <input type="hidden" name="tenure" value="<?=@$tenure;?>" />
- <input type="hidden" name="numberOfAdult" value="<?=@$numberOfAdult;?>" />
- <input type="hidden" name="numberOfChildren" value="<?=@$numberOfChildren;?>" />
- <input type="hidden" name="mobileNum" value="<?=@$mobileNumber;?>" />
- <input type="hidden" name="quotationReferenceNum" value="<?=@$_SESSION['quotationReferenceNum'];?>" />
- <input type="hidden" name="agentId" value="<?=@$_SESSION['agentId'];?>" />
- </form>
- <script>
- document.PortalProposal.submit();
- </script>
- <?php
-
-
- }
- function xml2array($contents, $get_attributes=1, $priority = 'tag'){
- if(!$contents) return array();
-
- if(!function_exists('xml_parser_create')) {
- //print "'xml_parser_create()' function not found!";
- return array();
- }
-
- //Get the XML parser of PHP - PHP must have this module for the parser to work
- $parser = xml_parser_create('');
- xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); # http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss
- xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
- xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
- xml_parse_into_struct($parser, trim($contents), $xml_values);
- xml_parser_free($parser);
-
- if(!$xml_values) return;//Hmm...
-
- //Initializations
- $xml_array = array();
- $parents = array();
- $opened_tags = array();
- $arr = array();
-
- $current = &$xml_array; //Refference
-
- //Go through the tags.
- $repeated_tag_index = array();//Multiple tags with same name will be turned into an array
- foreach($xml_values as $data) {
- unset($attributes,$value);//Remove existing values, or there will be trouble
-
- //This command will extract these variables into the foreach scope
- // tag(string), type(string), level(int), attributes(array).
- extract($data);//We could use the array by itself, but this cooler.
-
- $result = array();
- $attributes_data = array();
-
- if(isset($value)) {
- if($priority == 'tag') $result = $value;
- else $result['value'] = $value; //Put the value in a assoc array if we are in the 'Attribute' mode
- }
-
- //Set the attributes too.
- if(isset($attributes) and $get_attributes) {
- foreach($attributes as $attr => $val) {
- if($priority == 'tag') $attributes_data[$attr] = $val;
- else $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr'
- }
- }
-
- //See tag status and do the needed.
- if($type == "open") {//The starting of the tag '<tag>'
- $parent[$level-1] = &$current;
- if(!is_array($current) or (!in_array($tag, array_keys($current)))) { //Insert New tag
- $current[$tag] = $result;
- if($attributes_data) $current[$tag. '_attr'] = $attributes_data;
- $repeated_tag_index[$tag.'_'.$level] = 1;
-
- $current = &$current[$tag];
-
- } else { //There was another element with the same tag name
-
- if(isset($current[$tag][0])) {//If there is a 0th element it is already an array
- $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result;
- $repeated_tag_index[$tag.'_'.$level]++;
- } else {//This section will make the value an array if multiple tags with the same name appear together
- $current[$tag] = array($current[$tag],$result);//This will combine the existing item and the new item together to make an array
- $repeated_tag_index[$tag.'_'.$level] = 2;
-
- if(isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well
- $current[$tag]['0_attr'] = $current[$tag.'_attr'];
- unset($current[$tag.'_attr']);
- }
-
- }
- $last_item_index = $repeated_tag_index[$tag.'_'.$level]-1;
- $current = &$current[$tag][$last_item_index];
- }
-
- } elseif($type == "complete") { //Tags that ends in 1 line '<tag />'
- //See if the key is already taken.
- if(!isset($current[$tag])) { //New Key
- $current[$tag] = $result;
- $repeated_tag_index[$tag.'_'.$level] = 1;
- if($priority == 'tag' and $attributes_data) $current[$tag. '_attr'] = $attributes_data;
-
- } else { //If taken, put all things inside a list(array)
- if(isset($current[$tag][0]) and is_array($current[$tag])) {//If it is already an array...
-
- // ...push the new element into that array.
- $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result;
-
- if($priority == 'tag' and $get_attributes and $attributes_data) {
- $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data;
- }
- $repeated_tag_index[$tag.'_'.$level]++;
-
- } else { //If it is not an array...
- $current[$tag] = array($current[$tag],$result); //...Make it an array using using the existing value and the new value
- $repeated_tag_index[$tag.'_'.$level] = 1;
- if($priority == 'tag' and $get_attributes) {
- if(isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well
-
- $current[$tag]['0_attr'] = $current[$tag.'_attr'];
- unset($current[$tag.'_attr']);
- }
-
- if($attributes_data) {
- $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data;
- }
- }
- $repeated_tag_index[$tag.'_'.$level]++; //0 and 1 index is already taken
- }
- }
-
- } elseif($type == 'close') { //End of tag '</tag>'
- $current = &$parent[$level-1];
- }
- }
-
- return($xml_array);
- }
- function subcategory_page_array($pageListArray1){
- $m =0;
- $dataArr=array();
- if(is_array(@$pageListArray1['subcategory'][0]) ) {
- $pageListArray = $pageListArray1['subcategory'];
- for($i=0;$i<sizeof($pageListArray);$i++) {
- if(trim($pageListArray[$i]['isDeleted']['value'])=='no'){
- $dataArr[$m]['subCategoryId'] = trim($pageListArray[$i]['subCategoryId']['value']);
- $dataArr[$m]['categoryId'] =trim(@$pageListArray[$i]['categoryId']['value']);
- $dataArr[$m]['subCategoryName'] = @$pageListArray[$i]['subCategoryName']['value'];
- $dataArr[$m]['productCode'] = @$pageListArray[$i]['productCode']['value'];
- $dataArr[$m]['description'] = @$pageListArray[$i]['description']['value'];
- $dataArr[$m]['briefDescription'] = @$pageListArray[$i]['briefDescription']['value'];
- $dataArr[$m]['metaTitle'] = @$pageListArray[$i]['metaTitle']['value'];
- $dataArr[$m]['metaDescription'] = @$pageListArray[$i]['metaDescription']['value'];
- $dataArr[$m]['metaKeywords'] = @$pageListArray[$i]['metaKeywords']['value'];
- $dataArr[$m]['compare'] = @$pageListArray[$i]['compare']['value'];
- $dataArr[$m]['exclusions'] =@$pageListArray[$i]['exclusions']['value'];
- $dataArr[$m]['policyTerms'] =@$pageListArray[$i]['policyTerms']['value'];
- $dataArr[$m]['agentpolicyTerms'] =@$pageListArray[$i]['agentpolicyTerms']['value'];
- $dataArr[$m]['claim'] = @$pageListArray[$i]['claim']['value'];
- $dataArr[$m]['logo'] = @$pageListArray[$i]['logo']['value'];
- $dataArr[$m]['thumbnail'] = @$pageListArray[$i]['thumbnail']['value'];
- $dataArr[$m]['isDeleted'] = trim($pageListArray[$i]['isDeleted']['value']);
- $m++;
- }
- }
- }else {
- $pageListArray = @$pageListArray1['subcategory'];
- if(trim($pageListArray['isDeleted']['value']) =='no') {
- $dataArr[$m]['subCategoryId'] = trim($pageListArray['subCategoryId']['value']);
- $dataArr[$m]['categoryId'] = trim($pageListArray['categoryId']['value']);
- $dataArr[$m]['subCategoryName'] = $pageListArray['subCategoryName']['value'];
- $dataArr[$m]['productCode'] = @$pageListArray['productCode']['value'];
- $dataArr[$m]['description'] = $pageListArray['description']['value'];
- $dataArr[$m]['briefDescription']= $pageListArray['briefDescription']['value'];
- $dataArr[$m]['metaTitle'] = $pageListArray['metaTitle']['value'];
- $dataArr[$m]['metaDescription'] = $pageListArray['metaDescription']['value'];
- $dataArr[$m]['metaKeywords'] = $pageListArray['metaKeywords']['value'];
- $dataArr[$m]['compare'] = $pageListArray['compare']['value'];
- $dataArr[$m]['exclusions'] = $pageListArray['exclusions']['value'];
- $dataArr[$m]['claim'] = $pageListArray['claim']['value'];
- $dataArr[$m]['policyTerms'] =@$pageListArray['policyTerms']['value'];
- $dataArr[$m]['agentpolicyTerms'] =@$pageListArray['agentpolicyTerms']['value'];
- $dataArr[$m]['logo'] = @$pageListArray['logo']['value'];
- $dataArr[$m]['thumbnail'] = @$pageListArray['thumbnail']['value'];
- $dataArr[$m]['isDeleted'] = trim($pageListArray[$i]['isDeleted']['value']);
- $m++;
- }
- }
- //sort by
- if (count ($dataArr) > 0) {
- foreach ($dataArr as $key => $row) {
- @$order_in_category[$key] = $row[0];//[0] is @$order_in_category
- }
- @array_multisort(@$order_in_category, SORT_ASC, $dataArr);
- }
- return $dataArr;
- }
- public function actiongetWebserviceLeadXMLResponse(){
- $data='';
- $leadURL=$_SERVER['DOCUMENT_ROOT']."/religarewebservices/data";
- $r=0;
-
- foreach(glob($leadURL . '/*request.xml') as $files){
- $checkLeadExistorNot=Lead::model()->findByAttributes(array('fileName'=>$files));
- if(count($checkLeadExistorNot)==0){
- $data=file_get_contents($files);
- $result=$this->xml2array($data);
- $createdLeadDetails=$result['SOAP:Envelope']['SOAP:Body']['Createlead']['Lead'];
- $OrganizationName=$result['SOAP:Envelope']['SOAP:Body']['Createlead']['OrganizationName'];
- $type='Lead';
- $leadsourceCode=$createdLeadDetails['leadsourcecode'];
- $subject=$createdLeadDetails['subject'];
- $firstname=$createdLeadDetails['firstname'];
- $lastname=$createdLeadDetails['lastname'];
- $emailaddress1=$createdLeadDetails['emailaddress1'];
- $telephone1=$createdLeadDetails['telephone1'];
- $mobilephone=$createdLeadDetails['mobilephone'];
- $product=$createdLeadDetails['rhi_product'];
- $suminsured=$createdLeadDetails['rhi_suminsured'];
- $suminsured=(count($suminsured) > 0)?$suminsured:0;
- $premium=$createdLeadDetails['rhi_premium'];
- $premium=(count($premium) > 0)?$premium:0;
- $quoteid=$createdLeadDetails['rhi_quoteid'];
- $proposalid=$createdLeadDetails['rhi_proposalid'];
- $leadstage=$createdLeadDetails['rhi_leadstage'];
- $agentid=$createdLeadDetails['rhi_agentid'];
- $noofyears=$createdLeadDetails['rhi_noofyears'];
- $ProductMaster=ProductMaster::model()->findByAttributes(array('productName'=>$product));
- $productId=$ProductMaster['productId'];
-
- if(count($result) > 0){
- //echo $files;
- $model = new Lead;
- $model->setAttributes(array(
- 'name' => 'web services',
- 'email' => '',
- 'mobile' => $mobilephone,
- 'productId' => $productId,
- 'members' => 0,
- 'si' => $suminsured,
- 'premium' => $premium,
- 'leadStageId' => '',
- 'fileName' => addslashes($files),
- 'status' => 'Active',
- 'createdOn' => time(),
- 'updatedOn' => time(),
- 'updatedBy' => time(),
- 'createdBy' => time(),
- ));
- //print_r($model);
- $model->isNewRecord = true;
- @$model->save(false);
-
- } $r++;
-
- }
- }
- $this->redirect(array('leads/lead_list'));
- }
- public function actionfresh_leads()
- {
- //$modelLead = Lead::model()->findAll("leadStatusId = '34' AND currentAllocatedId<1 ");
- $this->render('fresh_lead_list');
- }
- public function actionviewAllTeams() {
- if (!Yii::app()->request->isAjaxRequest){
- }
- else {
- $this->renderPartial('/leads/partialAllTeamDetails');
- Yii::app()->end();
- }
- }
- public function actionViewLeadActivity() {
- $followupId=@$_REQUEST['id'];
- $model=new LeadFollowup;
- $model=LeadFollowup::model()->findByPk($followupId);
- if (!Yii::app()->request->isAjaxRequest){
- // $this->render('yourView');
- }
- else {
- $this->renderPartial('/leads/ViewLeadActivity',array('model'=>$model));
- Yii::app()->end();
- }
- }
- public function actionViewCalenderActs() {
- //$cs = Yii::app()->getClientScript(); $cs->registerCoreScript('jquery');
- $this->layout=false;
- $startDate=@$_REQUEST['id'];
- $model = LeadFollowup::model()->findAll(array("condition"=>"startDate = '".@$startDate."' AND userId = '".@$_SESSION['id']."' AND STATUS = 'Pending' AND (actionType = 'Meeting' OR actionType = 'Follow Up') ORDER BY hour DESC"));
-
- if (!Yii::app()->request->isAjaxRequest){
- $this->renderPartial('/leads/ViewCalenderActs',array('model'=>$model,'startDate'=>@$startDate));
- }
- else {
- $this->renderPartial('/leads/ViewCalenderActs',array('model'=>$model,'startDate'=>@$startDate));
- Yii::app()->end();
- }
- }
-
- public function actionEditCalenderActivity() {
-
- $this->layout=false;
- $leadId=@$_REQUEST['leadId'];
- $actionId=@$_REQUEST['actionId'];
- $this->renderPartial('EditCalenderActivity',array('leadId'=>$leadId,'actionId'=>$actionId) ,false, true);
- Yii::app()->end();
-
- }
-
- public function actiongetActionRes(){
- $statusids = @$_POST['statusids'];
- $model = new LeadStatus;
- $model=LeadStatus::model()->findByPk($statusids);
- echo $result = @$model['actionCompulsary'];
- }
- public function actioncip_lead_list()
- {
- //$model = new LeadStatus;
- $this->render('contact_in_progress_lead_list');
- }
- public function actioncld_lead_list()
- {
- //$model = new Lead;
- $this->render('cld_lead_list');
- }
- public function actionsearchCIP(){
- if(Yii::app()->request->isAjaxRequest==1){
-
-
- $models=new Lead();
- $searchIDs =@$_REQUEST['searchIDs'];
- if(isset($searchIDs) && !empty($searchIDs)){
- $this->renderPartial('partialcip',array('searchTxt'=>$searchIDs,'type'=>'cip'));
- }
- } else {
- $redirectUrl = Yii::app()->controller->id."/".$this->action->id;
- $this->redirect("index.php?r=leads/cip_lead_list&pageSize=".@$_REQUEST['pageSize']);
- }
- }
- public function actiondup_forthe_day_lead_list()
- {
- //$modelLead = new Lead;
- $this->render('duplicate_forthe_daylead_list');
- }
- public function actionSearchArchiveLeads(){
- $model = new Lead;
- $teamId = @$_POST['Team']['teamId'];
- $Leadname = @$_POST['Lead']['name'];
- $Leadstatus = @$_POST['Lead']['status'];
- $leadStage = @$_POST['Lead']['leadStage'];
- $leadws_agentid = @$_POST['Lead']['ws_agentid'];
- $leademail = @$_POST['Lead']['email'];
- $leadmobile = @$_POST['Lead']['mobile'];
- $this->render('archive_leads',array('model'=>$model,'teamId'=>$teamId,'Leadname'=>$Leadname,'Leadstatus'=>$Leadstatus,'leadStage'=>$leadStage,'Leadmobile'=>$leadmobile,'Leademail'=>$leademail,'Leadws_agentid'=>$leadws_agentid));
-
- }
- public function actionplc_lead_list()
- {
- //$model = new Lead;
- $this->render('plc_lead_list');
- }
- public function getAgentIds($ws_agentid,$mobile){
- $agentIds=Yii::app()->db->createCommand("select group_concat(distinct ws_agentid) as ws_agentid,count(distinct ws_agentid) as total from lead where mobile='".@$mobile."' and ws_agentid!='' order by leadId desc ")->queryAll();
-
-
- if( $agentIds[0]['total'] > 1){
- echo "<label class='linkUnderline' title='".@$agentIds[0]['ws_agentid']."'><a href='#'>".$ws_agentid."</a></label>";
-
- } else if($agentIds[0]['total'] == 1) {
- echo "<label title='".@$agentIds[0]['ws_agentid']."'><a href='#'>".$ws_agentid."</a></label>";
- } else {
- echo "";
- }
-
- //echo explode(',',$agentId);
- }
- public function getLeadStagesIds($leadStageId,$mobile){
- $agentIds=Yii::app()->db->createCommand("select distinct leadStageId from lead where mobile='".@$mobile."' and leadStageId!='' order by leadId desc ")->queryAll();
- $displayedSyage=Yii::app()->db->createCommand("select leadStage from leadStageMaster where leadStageId='".@$leadStageId."' ")->queryAll();
-
- if(count($agentIds) > 0) {
- for($i=0;$i<count($agentIds);$i++){
-
- $leadstages=Yii::app()->db->createCommand("select leadStage from leadStageMaster where leadStageId='".@$agentIds[$i]['leadStageId']."' ")->queryAll();
- $agentId[] = @$agentIds[$i]['leadStageId'];
- $leadstages_new[] = @$leadstages[0]['leadStage'];
- }
- } else {
- echo "";
- }
-
- if( count(@$leadstages_new) > 1){
- echo "<label class='linkUnderline' title='".implode(',',$leadstages_new)."'><a href='#'>".@$displayedSyage[0]['leadStage']."</a></label>";
-
- } else if( count(@$leadstages_new) == 1) {
- echo "<label title='".implode(',',@$leadstages_new)."'><a href='#'>".@$displayedSyage[0]['leadStage']."</a></label>";
- } else {
- echo "";
- }
-
- //echo explode(',',$agentId);
- }
- public function actioninactive_users_leads()
- {
- $this->render('inactive_users_leads');
- }
- public function actionInactiveAllocateLeads()
- {
- $Id = $_REQUEST['userids'];
- $teamId = @$_REQUEST['Team']['teamId'];
- $userId = $_REQUEST['Team']['teamMemberId'];
- $updatedBy = @$_SESSION['id'];
-
- foreach($Id as $key=>$value){
- $model = new AllocatedLeads();
- $model->scenario = 'AllocatedLeads';
- $model->setAttributes(array(
- 'currentAllocatedDate' => time(), //additional data you want to insert
- 'createdOn' => time(), //additional data you want to insert
- 'updatedOn' => time(), //additional
- 'updatedBy' => @$updatedBy, //additional
- 'createdBy' => @$updatedBy, //additional
- 'leadStatusId' => '35', //additional //additional
- ));
- $leadId = @$value;
- $model->leadId = @$value;
- $model->userId = @$userId;
- $model->teamId = @$teamId;
- //echo @$teamId.' - '.@$userId.' - '.@$leadId;
- $model->allocatedId = null;
- $model->isNewRecord = true;
- $model->save();
- $model=new Lead();
- $model->scenario = 'Lead';
- $updatedOn = time();
- Lead::model()->updateByPk(@$value, array('currentAllocatedId'=>@$userId,'leadStatusId'=>'35','updatedBy'=>@$updatedBy,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
- }
- $red = @$_REQUEST['red'];
-
- if($this->action->id=='AllocateLeads' && $red == 1) {
- $this->redirect(array('leads/inactive_users_leads'));
- } else {
- $this->redirect(array('leads/inactive_users_leads'));
- }
- //$this->redirect(array('leads/lead_list'));
- }
- public function getLeadDescription($leadId){
- $records=Yii::app()->db->createCommand("select leadDescription from lead where leadId='".@$leadId."' ")->queryAll();
-
- if(count($records) > 0) {
- for($i=0;$i<count($records);$i++){
- $record[] = @$records[$i]['leadDescription'];
- }
- } else {
- echo "";
- }
-
- if( count(@$record) > 1){
- echo "<label title='".implode(',',$record)."'><a href='#'>".substr(implode(',',$record),0,5)."...</a></label>";
-
- } else if( count(@$record) == 1) {
- echo "<label title='".implode(',',@$record)."'><a href='#'>".implode(',',$record)."</a></label>";
- } else {
- echo "";
- }
- //echo explode(',',$agentId);
- }
- public function getLeadActivityDescription($leadId){
- $records=Yii::app()->db->createCommand("select description from leadFollowup where leadId='".@$leadId."' ")->queryAll();
- if(count($records) > 0) {
- for($i=0;$i<count($records);$i++){
- $record[] = @$records[$i]['description'];
- }
- } else {
- echo "";
- }
-
- if( count(@$record) > 1){
- echo "<label title='".implode(',',$record)."'><a href='#'>".substr(implode(',',$record),0,5)."...</a></label>";
-
- } else if( count(@$record) == 1) {
- echo "<label title='".implode(',',@$record)."'><a href='#'>".substr(implode(',',$record),0,5)."...</a></label>";
- } else {
- echo "";
- }
-
- //echo explode(',',$agentId);
- }
- public function actionloadleadtabs(){
- $this->layout = false;
- $this->renderPartial('leadTabs');
- }
- public function actiondeleted_database_tab()
- {
- $model=new Lead();
- $model->set_period1=@$_POST['Lead']['period1']?@$_POST['Lead']['period1']:@$_REQUEST['period1'];
- $model->set_period2=@$_POST['Lead']['period2']?@$_POST['Lead']['period2']:@$_REQUEST['period2'];
-
- $this->render('deleted_database_tab',array('model'=>$model));
- }
- public function actiondelete_lead()
- {
- $deleteId=@$_REQUEST['leadId'];
-
- if(Yii::app()->request->isAjaxRequest){
- if(!empty($deleteId))
- {
- $model=Lead::model()->findByPk($deleteId);
- }
- else
- {
- $model = new Lead();
- }
- if($model->delete($deleteId)){
- echo "Record deleted successfully";
- } else {
- echo "some error occured please try after some time";
- }
- } else {
- $this->redirect(array('leads/deleted_database_tab'));
- }
- }
- public function actionDeleteAllJunkLeads()
- {
- $model = new lead;
- //print_r($_REQUEST);
- $Id=$_REQUEST['leadids'];
-
- foreach($Id as $key=>$value){
- $model->deleteByPk($value);
- }
- $this->redirect(Yii::app()->request->urlReferrer);
- }
-
- public function actionDeleteAllJunkLeadsOneTime()
- {
- $model = new lead;
-
- echo $startDate = @$_REQUEST['period1'];
- $endDate = @$_REQUEST['period2'];
- $alldeletedIds = @$_POST['alldeletedIds'];
- $Id=unserialize(urldecode($_POST['alldeletedIds']));
- foreach($Id as $key=>$value){
- //echo $value;
- $model->deleteByPk($value);
- }
-
- $modeldel = new leadsdeletedby;
- $modeldel->id='';
- $modeldel->startdate=@$startDate;
- $modeldel->enddate=@$endDate;
- $modeldel->data=$alldeletedIds;
- $modeldel->deletedOn=time();
- $modeldel->deletedBy=Yii::app()->session->get('userName');
- $modeldel->deletedById=Yii::app()->session->get('id');
- /* $modeldel->setAttributes(array(
- 'id' => '', //additional data you want to insert
- 'startdate' => @$startDate, //additional
- 'enddate' => @$endDate, //additional
- 'data' => 'sdfsdf', //additional
- 'deletedOn' => time(), //additional
- 'deletedBy' => Yii::app()->session->get('userName'), //additional
- 'deletedById' =>Yii::app()->session->get('id'), //additional //additional
-
- ));*/
-
- $modeldel->save();
- $this->redirect(Yii::app()->request->urlReferrer);
- }
-
- public function actionuser_monthly_report() {
- $this->render('user_monthly_report');
- }
- public function actionuser_login_report() {
- $this->render('user_login_report');
- }
- public function actiondownload_login_report() {
- $limitvalue = @$_REQUEST['fetchrecordsBydropdown'];
- $userid = @$_REQUEST['User']['id'];
-
- if(isset($limitvalue) && !empty($limitvalue) && isset($userid) && !empty($userid)){
-
- $paginationExcelValue = @$_POST['fetchrecordsBydropdown'];
-
- if(isset($paginationExcelValue) && !empty($paginationExcelValue)){
- $explodedpaginationValue = explode('-',$paginationExcelValue);
- $startLimit = $explodedpaginationValue[0];
- $endLimit = 10000;
- } else {
- $startLimit = '';
- $endLimit = '';
-
- }
- if(isset($startLimit) && isset($endLimit) && !empty($endLimit)){
- $limitCond = " limit $startLimit , $endLimit";
- } else {
- $limitCond = '';
- }
- //Here is the code to set conditions for fetch records from database
- $condfilter = '';
-
- if(isset($userid) && !empty($userid))
- {
-
- if(isset($userid) && !empty($userid))
- {
- $condfilter .= "t.userid = ".$userid." AND ";
- }
- if(isset($condfilter) && !empty($condfilter)){
- $wherecon = "WHERE ";
- } else {
- $wherecon = "";
- }
-
- $data=Yii::app()->db->createCommand("select t.userId,t.userName,t.loginTime,t.type from userloginlog as t $wherecon $condfilter t.userId > 0 order by t.logId DESC $limitCond")->queryAll();
-
- }else{
- $data=0;
- }
-
-
- if(count($data)>0){
- $file_name = "lms" . "_" . date("Y-m-d_H-i", time()) . ".csv";
- header('Content-Type: text/html; charset=utf-8');
- header("Content-type: application/octet-stream");
- header("Content-Disposition: attachment; filename=\"$file_name\"");
- header("Cache-Control: cache, must-revalidate");
- header("Pragma: public");
- $col = array(
- 'SNO.','User Name','loginTime');
- foreach ($col as $key => $value) {
- echo $value . ",";
- }
- echo "\n";
- $i=1;
- foreach ($data as $key => $value) {
- $loginTime = date("d M Y H:i:s A",$value['loginTime']);
- echo $i++ . ",";
- echo @$value["userName"] . ",";
- echo @$loginTime . ",";
- echo "\n";
- }
-
- }
- else{
- $this->redirect('index.php?r=leads/user_login_report');
- //$dataProvider=new CActiveDataProvider('LeadReport', array('criteria'=>@$criteria,));
- //$this->render('reports',array('model'=>$model,'dataProvider'=>$dataProvider));
- }
- } else {
- $this->render('user_login_report');
- }
- }
- public static function getMTD($leadStatusId){
-
-
- $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1);
- $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"));
- $sql = "select count(leadId) as total from lead l join user u on u.id=l.currentAllocatedId where l.leadStatusId = ".@$leadStatusId." and (l.updatedOn between '".@$CurrentMonth_first_minute."' and '".@$CurrentMonth_last_minute."') and u.status='Active' limit 1 ";
- $count=Yii::app()->db->createCommand($sql)->queryColumn();
-
- echo @$count[0];
- //echo Lead::model()->count(array("select"=>'leadid',"condition"=>" leadStatusId = ".@$leadStatusId.""));
- }
- public static function getYTD($leadStatusId){
- $CurrentYear_first_minute = mktime(0, 0, 0, 1, 1, date('Y'));
- $CurrentYear_last_minute = mktime(0, 0, 0, 13, 0, date('Y'));
- $sql = "select count(leadId) as total from lead l join user u on u.id=l.currentAllocatedId where l.leadStatusId = ".@$leadStatusId." and (l.updatedOn between '".@$CurrentYear_first_minute."' and '".@$CurrentYear_last_minute."') and u.status='Active' ";
- $count=Yii::app()->db->createCommand($sql)->queryColumn();
- //echo Lead::model()->count(array("select"=>'leadid',"condition"=>" leadStatusId = ".@$leadStatusId.""));
- echo @$count[0];
- }
- public static function getUniqueMobLeadCountByStatus($leadStatusId){
-
- if(isset($leadStatusId) && !empty($leadStatusId)){
-
- $todayexpiryDate= date('d-M-Y',time());
- $nontydaystime=strtotime("-90 days",strtotime($todayexpiryDate));
-
- $date1Filer = @$_REQUEST['Lead']['createdOn'];
- $date2Filer = @$_REQUEST['Lead']['createdOn2'];
-
- $leadFilter = @$_REQUEST['LeadSourceMaster']['leadSourceId'];
-
- $filterCond ='';
- if(isset($leadFilter) && !empty($leadFilter)){
- $filterCond .= " AND l.leadSourceId = ".$leadFilter."";
- }
- if(isset($date1Filer) && !empty($date1Filer) && isset($date2Filer) && !empty($date2Filer)){
- $date1Filer = strtotime($date1Filer);
- $date2Filer = strtotime($date2Filer);
- $filterCond .= " AND l.createdOn >= ".$date1Filer." and l.createdOn <= ".$date2Filer."";
- }
- if(Yii::app()->session->get('type')=='superadmin'){
- //$sql = "select mobile from lead l where l.leadStatusId=".$leadStatusId." $filterCond ";
- $sql = "select count(l.mobile) as totalunique from lead l where l.leadStatusId=".$leadStatusId." and l.leadStatusId != 10 $filterCond group by l.leadStatusId ";
- } else {
- $impresuser = DashboardController::implodeResult(Yii::app()->session['relationalManager']);
- $sql = "select count(l.mobile) as totalunique from lead l where l.leadStatusId=".$leadStatusId." and l.leadStatusId != 10 and l.currentAllocatedId IN (".@$impresuser.") $filterCond group by l.leadStatusId ";
- }
- //echo $res = Lead::model()->count(array("select"=>"count(distinct mobile) as totalunique","condition"=>" leadStatusId=".$leadStatusId." $filterCond "));
- //$count=Yii::app()->db->createCommand($sql)->queryScalar();
- $count=Yii::app()->db->createCommand($sql)->queryScalar();
- /*$criteria = new CDbCriteria();
- $criteria->select = "mobile";
- $criteria->condition = " leadStatusId=".$leadStatusId."";
- $count=Lead::model()->findAll($criteria);*/
-
- //echo count($count);
-
- echo @$count?@$count:0;
- } else {
- echo 0;
- }
- //echo Lead::model()->count(array("select"=>'leadid',"condition"=>" leadStatusId = ".@$leadStatusId.""));
- }
- public function actiondownload_monthly_report(){
-
- $selectedMonth = @$_REQUEST['selectedMonth'];
- if(Yii::app()->session->get('type')=='superadmin' or Yii::app()->session->get('roleId')==4){
- $userId = @$_REQUEST['User']['id'];
- } else {
- $userId = Yii::app()->session->get('id');
- }
- $startmonthTime = @$_REQUEST['startTime_'.$selectedMonth];
- $endMonthTime = @$_REQUEST['endtime_'.$selectedMonth];
-
-
- $wherecon = "t.updatedOn >= ".$startmonthTime." and t.updatedOn <= ".$endMonthTime." and t.currentAllocatedId=".@$userId." ";
-
- if(empty($startmonthTime) or empty($endMonthTime)){
- $data = array();
- } else {
- $sqlquery = "select t.leadId,t.name,t.mobile,t.email,t.address,t.members,t.premium,t.productDetails,t.ws_agentid,t.status,t.isJunk,t.leadDescription,t.currentAllocatedId,t.createdBy,t.updatedOn,`user`.`id`,`user`.`firstName`,`user`.`lastName`,`city`.`city`, `state`.`state`, `leadSourceMaster`.`leadSourceTitle`,`leadSourceMaster`.`leadSourceCode`,`leadStageMaster`.`leadStage`,`leadStatus`.`leadStatus`, `customerTypeMaster`.`customerType`,`productMaster`.`productName`,`policyTypeMaster`.`policyType`,`planTypeMaster`.`planType`,`campaign`.`campaignName` from lead as t LEFT JOIN city ON (city.cityId = t.cityId) LEFT JOIN state ON (state.stateId = t.stateId) LEFT JOIN leadSourceMaster ON (leadSourceMaster.leadSourceId = t.leadSourceId) LEFT JOIN leadStageMaster ON (leadStageMaster.leadStageId = t.leadStageId)LEFT JOIN leadStatus ON (leadStatus.leadStatusId = t.leadStatusId)LEFT JOIN customerTypeMaster ON (customerTypeMaster.customerTypeId = t.customerTypeId)LEFT JOIN productMaster ON (productMaster.productId = t.productId) LEFT JOIN policyTypeMaster ON (policyTypeMaster.policyTypeId = t.policyTypeId)LEFT JOIN planTypeMaster ON (planTypeMaster.planTypeId = t.planTypeId) LEFT JOIN campaign ON (campaign.campaignId = t.campaignId) LEFT JOIN user ON (user.id=t.currentAllocatedId) where $wherecon and t.leadId > 0 order by t.leadId DESC limit 0,10000";
- $data=Yii::app()->db->createCommand($sqlquery)->queryAll();
- }
-
- if(count($data)>0){
- $file_name = "lmsmonthlyreport" . "_" .$userId. date("Y-m-d_H-i", time()) . ".csv";
- header('Content-Type: text/html; charset=utf-8');
- header("Content-type: application/octet-stream");
- header("Content-Disposition: attachment; filename=\"$file_name\"");
- header("Cache-Control: cache, must-revalidate");
- header("Pragma: public");
- $col = array(
- 'SNO.','Name','Mobile Number',' Email Id','Address','City','State','Members','Premium','Product Details','Lead Status','Status','isJunk','Lead Source','Lead Stage','Lead Description','Activity Description','Customer Type','Product Name','Policy Type','Plan Type','Campaign Name','UTM Code','Owner','Last Modified Date','Agent-Id'
- );
-
- foreach ($col as $key => $value) {
- echo $value . ",";
- }
- echo "\n";
- $i=1;
- foreach ($data as $key => $value) {
-
- if($value['currentAllocatedId']==$value['createdBy']){
- $owner = $value['firstName']." ".$value['lastName']."(C)";
- } else {
- if(isset($value['firstName']) && !empty($value['firstName'])){
- $owner = $value['firstName']." ".$value['lastName'];
- } else {
- $owner = "NA";
- }
- }
- if(isset($value['updatedOn']) && !empty($value['updatedOn'])){
- $strtme = date("d M Y H:i:s A",$value['updatedOn']);
- } else{ $strtme = 'NA'; }
- $lastModifieddate = $strtme;
-
- $sqlDesc = "select group_concat(description) as ActivityDescription from leadFollowup where leadId=".@$value["leadId"]." ";
- $dataDesc=Yii::app()->db->createCommand($sqlDesc)->queryAll();
-
- $leadActivity = @$dataDesc[0]['ActivityDescription']?stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$dataDesc[0]['ActivityDescription'])):'';
-
-
- echo $i++ . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["name"])) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$value["mobile"])) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$value["email"])) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$value["address"])) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$city)) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$state)) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$value["members"])) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$value["premium"])) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$value['productDetails'])) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$value['leadStatus'])) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$value['status'])) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$value['isJunk'])) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$value['leadSourceTitle'])) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$value['leadStage'])) . ",";;
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$value["leadDescription"])) . ",";
- echo @$leadActivity . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$value["customerType"])) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$value["productName"])) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$value["policyType"])) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$value["planType"])) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$value["campaignName"])) . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$value["leadSourceCode"])) . ",";
- echo @$owner . ",";
- echo @$lastModifieddate . ",";
- echo stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$value["ws_agentid"])) . ",";
- echo "\n";
- }
-
- } else {
- Yii::app()->user->setFlash('msg','No Record Found');
- $this->render('user_monthly_report');
- }
-
-
-
- }
-
- //Lead Assignment without page refresh
- public function actionAllocateLeadsByAjax(){
-
- $Id = $_REQUEST['userids'];
- $teamId = @$_REQUEST['Team']['teamId'];
- $userId = $_REQUEST['Team']['teamMemberId'];
- $updatedBy = @$_SESSION['id'];
- $actionurl = @$_REQUEST['actionurl'];
- $paginationsize = Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize'])?Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']):25;
- $userdetails=Yii::app()->db->createCommand("select firstName,lastName from user where id=".$userId." ")->queryAll();
- $myArray = array();
- $responseAll =array();
- $t=0;
- foreach($Id as $key=>$value){
- $model = new AllocatedLeads();
- $model->scenario = 'AllocatedLeads';
- $model->setAttributes(array(
- 'currentAllocatedDate' => time(), //additional data you want to insert
- 'createdOn' => time(), //additional data you want to insert
- 'updatedOn' => time(), //additional
- 'updatedBy' => @$updatedBy, //additional
- 'createdBy' => @$updatedBy, //additional
- 'leadStatusId' => '35', //additional //additional
- ));
- $leadId = @$value;
- $model->leadId = @$value;
- $model->userId = @$userId;
- $model->teamId = @$teamId;
- //echo @$teamId.' - '.@$userId.' - '.@$leadId;
- $model->allocatedId = null;
- $model->isNewRecord = true;
- $model->save();
- $model=new Lead();
- $model->scenario = 'Lead';
- $updatedOn = time();
- Lead::model()->updateByPk(@$value, array('currentAllocatedId'=>@$userId,'leadStatusId'=>'35','updatedBy'=>@$updatedBy,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
-
- $responseAll[$t]['ownername'] = $userdetails[0]['firstName']." ".$userdetails[0]['lastName'];
- $responseAll[$t]['classname'] = "owner_".@$value;
- $responseAll[$t]['rowclass'] = @$value;
- $myArray[0][$t]=$responseAll[$t];
- $myArray[1]['roleId']=Yii::app()->session->get('roleId');
- $myArray[2]['actionurl']=$actionurl;
- $myArray[3]['paginationsize']=$paginationsize;
-
- $t++;
-
- }
-
-
- $red = @$_REQUEST['red'];
-
- if(Yii::app()->request->isAjaxRequest)
- {
- if(Yii::app()->session->get('type')=='superadmin'){
-
-
- //print_r($myArray); die;
- //echo "superadmin".$userdetails[0]['firstName'].$userdetails[0]['lastName'];
-
- echo json_encode($myArray);
-
- } else if(Yii::app()->session->get('roleId')==4 or Yii::app()->session->get('isAllocator')=='yes') {
- echo json_encode($myArray);
- } else {
- $myArray=array('somethingwrong');
- echo json_encode($myArray);
- }
- exit;
- }
-
- if($this->action->id=='AllocateLeads' && $red == 1)
- {
- $this->redirect(array('leads/lead_list'));
- }
- $this->redirect(array('leads/fresh_leads'));
-
-
-
- }
- public function actiongetLeadStagesIds(){
- $leadStageId=@$_REQUEST['leadStageId'];
- $mobile=@$_REQUEST['mobile'];
- $leadid=@$_REQUEST['leadid'];
- $agentIds=Yii::app()->db->createCommand("select group_concat(distinct leadStageMaster.leadStage) as leadStage,count(distinct lead.leadStageId) as total from lead left join leadStageMaster on leadStageMaster.leadStageId=lead.leadStageId where lead.mobile='".@$mobile."' and lead.leadStageId!='' order by lead.leadId desc ")->queryAll();
- //$displayedSyage=Yii::app()->db->createCommand("select leadStage from leadStageMaster where leadStageId='".@$leadStageId."' ")->queryAll();
-
- if( $agentIds[0]['total'] >= 1){
- echo @$agentIds[0]['leadStage'];
-
- } else {
- echo "";
- }
-
- //echo explode(',',$agentId);
- }
-
- public function actiongetAgentIds(){
- $ws_agentid=@$_REQUEST['ws_agentid'];
- $mobile=@$_REQUEST['mobile'];
- echo $leadid=@$_REQUEST['leadid'];
- $agentIds=Yii::app()->db->createCommand("select group_concat(distinct ws_agentid) as ws_agentid,count(distinct ws_agentid) as total from lead where mobile='".@$mobile."' and ws_agentid!='' order by leadId desc ")->queryAll();
-
-
- if( $agentIds[0]['total'] >= 1){
- echo @$agentIds[0]['ws_agentid'];
-
- } else {
- echo "";
- }
-
- //echo explode(',',$agentId);
- }
-
-
- }