/lms_debug/protected/controllers/LeadsController_24dec2014.php
PHP | 4614 lines | 3456 code | 830 blank | 328 comment | 648 complexity | ace6e93ad2d9ca1adf71834e5a41d0d7 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, LGPL-2.0
Large files files are truncated, but you can click here to view the full file
- <?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;
-
- $prevCurrentAllocatedId = $model->currentAllocatedId;
-
-
-
- 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);
-
- }
-
- //Added by shakti
-
- $accesskeyYear = $currentYear = date('Y');
-
- $accesskeyMonth = date('m');
-
- if ($model->currentAllocatedDate)
-
- {
-
- $accesskeyYear = date('Y', $model->currentAllocatedDate);
-
- $accesskeyMonth = date('m', $model->currentAllocatedDate);
-
- }
-
- else
-
- {
-
- if($model->updatedOn)
-
- {
-
- $accesskeyYear = date('Y', $model->updatedOn);
-
- $accesskeyMonth = date('m', $model->updatedOn);
-
- }
-
- }
-
- if($currentYear != $accesskeyYear)
-
- {
-
- DashboardController::insertUserLeadAllCountRecord($accesskeyYear);
-
- }
-
- $currentStatus = $_POST['Lead']['leadStatusId'];
-
- $updatedOn = time();
-
- $updatedBy = Yii::app()->session['id'];
-
- if(!$prevCurrentAllocatedId)
-
- {
-
- $prevCurrentAllocatedId = 1;
-
- }
-
- Yii::app()->db->createCommand('START TRANSACTION;')->execute();
-
-
-
- if ($currentStatus != $prevLeadStatusId && $currentStatus != '')
-
- {
-
- if (Yii::app()->session->get('type') != 'superadmin')
-
- {
-
- Yii::app()->db->createCommand("update leadallcount set count = count - 1, updatedOn = $updatedOn, updatedBy = $updatedBy
-
- where userid = $prevCurrentAllocatedId and leadtype = $prevLeadStatusId
-
- and accesskey = '$accesskeyYear'")->execute();
-
- Yii::app()->db->createCommand("update leadallcount set count = count - 1, updatedOn = $updatedOn, updatedBy = $updatedBy
-
- where userid = $prevCurrentAllocatedId and leadtype = $prevLeadStatusId
-
- and accesskey = '$accesskeyYear-$accesskeyMonth'")->execute();
-
-
-
- Yii::app()->db->createCommand("update leadallcount set count = count + 1, updatedOn = $updatedOn, updatedBy = $updatedBy
-
- where userid = $updatedBy and leadtype = $currentStatus
-
- and accesskey = '$accesskeyYear'")->execute();
-
- Yii::app()->db->createCommand("update leadallcount set count = count + 1, updatedOn = $updatedOn, updatedBy = $updatedBy
-
- where userid = $updatedBy and leadtype = $currentStatus
-
- and accesskey = '$accesskeyYear-$accesskeyMonth'")->execute();
-
- }
-
- Yii::app()->db->createCommand("update leadallcount set count = count - 1, updatedOn = $updatedOn, updatedBy = $updatedBy
-
- where userid = 1 and leadtype = $prevLeadStatusId
-
- and accesskey = '$accesskeyYear'")->execute();
-
- Yii::app()->db->createCommand("update leadallcount set count = count - 1, updatedOn = $updatedOn, updatedBy = $updatedBy
-
- where userid = 1 and leadtype = $prevLeadStatusId
-
- and accesskey = '$accesskeyYear-$accesskeyMonth'")->execute();
-
-
-
- Yii::app()->db->createCommand("update leadallcount set count = count + 1, updatedOn = $updatedOn, updatedBy = $updatedBy
-
- where userid = 1 and leadtype = $currentStatus
-
- and accesskey = '$accesskeyYear'")->execute();
-
- Yii::app()->db->createCommand("update leadallcount set count = count + 1, updatedOn = $updatedOn, updatedBy = $updatedBy
-
- where userid = 1 and leadtype = $currentStatus
-
- and accesskey = '$accesskeyYear-$accesskeyMonth'")->execute();
-
-
-
- Yii::app()->db->createCommand('COMMIT;')->execute();
-
- }
-
- else
-
- {
-
- Yii::app()->db->createCommand('ROLLBACK;')->execute();
-
- }
-
- // Added by shakti upto here.
-
-
-
- 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' => Yii::app()->session->get('id'),
- 'createdBy' => Yii::app()->session->get('id'),
- ));
-
- $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');
- }
- self::updateLeadAllCount($model->leadStatusId);
- $this->redirect(array('leads/lead_list'));
-
- // $model->save(false);
- // $this->redirect(array('leads/lead_list'));
- }
- }
- }
- if ($model->leadStatusId == 36)
- {
- self::updateLeadAllCount($model->leadStatusId);
- $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))
- {
- self::updateLeadAllCount($model->leadStatusId);
- $model->save();
- Yii::app()->user->setFlash('lead_msg_success', 'Successfully Inserted');
- }
- else
- {
- $duplicateLeadId = $checkDuplicateNumber->leadId;
- $model->leadStatusId = '10';
- $model->duplicateLeadId = @$duplicateLeadId;
- self::updateLeadAllCount($model->leadStatusId);
- $model->save();
- Yii::app()->user->setFlash('lead_msg_success', 'Successfully Inserted');
- }
- }
- else
- {
- $model->leadStatusId = '36';
- self::updateLeadAllCount($model->leadStatusId);
- $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'];
- $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;
- $teamIdString = @$teamId ? '' : ",teamId = $teamId, ";
-
- Yii::app()->db->createCommand('START TRANSACTION;')->execute();
-
- 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();
-
- /* Comment by shakti as handled below
- $model = new Lead();
- $model->scenario = 'Lead';
- $updatedOn = time();
- Lead::model()->updateByPk(@$value, array('currentAllocatedId' => @$userId, 'leadStatusId' => '35', 'updatedBy' => @$updatedBy, 'updatedOn' => @$updatedOn, 'currentAllocatedDate' => @$updatedOn));
- */
- 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++;
-
- $leadRecord = Yii::app()->db->createCommand("select leadStatusId, currentAllocatedId from lead where leadId = $value")->queryRow();
- $leadStatus = $leadRecord['leadStatusId'];
- $currentAllocatedId = $leadRecord['currentAllocatedId'];
- $updatedOn = time();
- //if (Yii::app()->session->get('type') == 'Superadmin')
- if ($leadStatus == 34 || (Yii::app()->session->get('type') == 'superadmin' && $leadStatus == 10))
- {
- //Super : status 34(new)/10(duplicate) count decrement
- Yii::app()->db->createCommand("update leadallcount set count = count - 1, updatedOn = $updatedOn, updatedBy = $updatedBy
- where userid = 1 && accesskey = '" . date('Y') . '-' . date('m') . "' && leadtype = $leadStatus")->execute();
- Yii::app()->db->createCommand("update leadallcount set count = count - 1, updatedOn = $updatedOn, updatedBy = $updatedBy
- where userid = 1 && accesskey = '" . date('Y') . "' && leadtype = $leadStatus")->execute();
-
- //Super : status 35(allocated) count increment
- Yii::app()->db->createCommand("update leadallcount set count = count + 1, updatedOn = $updatedOn, updatedBy = $updatedBy
- where userid = 1 && accesskey = '" . date('Y') . '-' . date('m') . "' && leadtype = 35")->execute();
- Yii::app()->db->createCommand("update leadallcount set count = count + 1, updatedOn = $updatedOn, updatedBy = $updatedBy
- where userid = 1 && accesskey = '" . date('Y') . "' && leadtype =…
Large files files are truncated, but you can click here to view the full file