/lms_debug/protected/models/Lead.php
PHP | 424 lines | 336 code | 29 blank | 59 comment | 31 complexity | 258782512d1bf1115488248abf547060 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, LGPL-2.0
- <?php
-
- /**
- * This is the model class for table "lead".
- *
- * The followings are the available columns in table 'lead':
- * @property string $leadId
- * @property string $email
- * @property string $emailOptOut
- * @property string $mobile
- * @property string $mobileOptOut
- */
- class Lead extends CActiveRecord
- {
-
- public $city;
- public $state;
- public $leadSourceTitle;
- public $leadStage;
- public $customerType;
- public $productName;
- public $policyType;
- public $planType;
- public $campaignName;
- public $leadSourceCode;
- public $import;
- public $leadSearchBox;
- public $leadStatusParentId;
- public $createdOn2;
- public $totalagent;
- public $totalleadstage;
- public $set_period1;
- public $set_period2;
- public $period1;
- public $period2;
- /**
- * Returns the static model of the specified AR class.
- * @param string $className active record class name.
- * @return Lead the static model class
- */
- public static function model($className=__CLASS__)
- {
- return parent::model($className);
- }
-
- /**
- * @return string the associated database table name
- */
- public function tableName()
- {
- return 'lead';
- }
-
- /**
- * @return array validation rules for model attributes.
- */
- public function rules()
- {
- // NOTE: you should only define rules for those attributes that
- // will receive user inputs.
- return array(
- array('mobile','required'),
- array('email,name','required','on'=>'salesclosed'),
- array('email', 'email','on'=>'salesclosed'), //Email has to be a valid email address
- array('mobile', 'length', 'min'=>10,'tooShort'=>'Mobile is too short (minimum is 10 digit)'),
- array('mobile, members, si, premium', 'numerical', 'integerOnly'=>true),
-
- array('import','safe'),
- array('import', 'file','types'=>'xls','message'=>'Only xls format allowed!','on'=>'insert'),
- array('email, createdBy, updatedBy', 'length', 'max'=>255),
- array('emailOptOut, mobileOptOut', 'length', 'max'=>1),
- array('mobile', 'length', 'max'=>12),
- array('createdOn, updatedOn', 'length', 'max'=>20),
- // The following rule is used by search().
- // Please remove those attributes that should not be searched.
- array('leadId, email,isRead,leadDescription, emailOptOut,fileName, mobile, mobileOptOut, status, createdBy, createdOn, updatedBy, updatedOn, children, ageGroup, ws_sourcecode, ws_subject, ws_telephone,agentId, ws_plan, ws_product, ws_quoteid, ws_proposalid, salesClosedUpdatedOn,ws_leadstage, ws_agentid, ws_noofyears, ws_orgnaizationName,utmsource,isBulkImport', 'safe', 'on'=>'search'),
- );
- }
-
- /**
- * @return array relational rules.
- */
- public function relations()
- {
- // NOTE: you may need to adjust the relation name and the related
- // class name for the relations automatically generated below.
- return array(
- 'stateDetails' => array(self::BELONGS_TO, 'State', 'stateId'),
- 'cityDetails' => array(self::BELONGS_TO, 'City', 'cityId'),
- 'customerTypeDetails' => array(self::BELONGS_TO, 'CustomerTypeMaster', 'customerTypeId'),
- 'productDetails' => array(self::BELONGS_TO, 'ProductMaster', 'productId'),
- 'planTypeDetails' => array(self::BELONGS_TO, 'PlanTypeMaster', 'planTypeId'),
- 'policyTypeDetails' => array(self::BELONGS_TO, 'PolicyTypeMaster', 'policyTypeId'),
- 'campaignDetails' => array(self::BELONGS_TO, 'Campaign', 'campaignId'),
- 'leadSourceDetails' => array(self::BELONGS_TO, 'LeadSourceMaster', 'leadSourceId'),
- 'leadStageDetails' => array(self::BELONGS_TO, 'LeadStageMaster', 'leadStageId'),
- 'leadStatusDetails' => array(self::BELONGS_TO, 'LeadStatus', 'leadStatusId'),
- 'ownerDetails' => array(self::BELONGS_TO, 'User', 'currentAllocatedId'),
- 'usermatchedDetails' => array(self::BELONGS_TO, 'User', 'currentAllocatedId','joinType' => ' JOIN',),
- 'agentIds' => array(self::BELONGS_TO, 'lead', 'mobile'),
- 'MTD' => array(self::HAS_ONE, 'lead', 'leadstatusId'),
-
- );
- }
-
- /**
- * @return array customized attribute labels (name=>label)
- */
- public function attributeLabels()
- {
- return array(
- 'leadId' => 'Lead',
- 'email' => 'Email',
- 'emailOptOut' => 'Email Opt Out',
- 'mobile' => 'Mobile',
- 'mobileOptOut' => 'Mobile Opt Out',
- 'name' => 'Name',
- 'address' => 'Address',
- 'stateId' => 'State',
- 'cityId' => 'City',
- 'customerTypeId' => 'Customer Type',
- 'productId' => 'Product',
- 'planTypeId' => 'Plan Type',
- 'policyTypeId' => 'Policy Type',
- 'productDetails' => 'Product Details',
- 'members' => 'Members',
- 'si' => 'SI',
- 'premium' => 'Premium',
- 'isRead' => 'Is Read',
- 'children' => 'Children',
- 'ageGroup' => 'Age Group',
- 'campaignId' => 'Campaign',
- 'leadSourceId' => 'Lead Source',
- 'leadStageId' => 'Lead Stage',
- 'leadStatusId' => 'Lead Status',
- 'status' => 'Status',
- 'fileName' => 'FileName',
- 'leadDescription' => 'Lead Description',
- 'createdBy' => 'Created By',
- 'createdOn' => 'Created On',
- 'updatedBy' => 'Updated By',
- 'updatedOn' => 'Updated On',
- 'ws_sourcecode' => 'ws sourcecode ',
- 'ws_subject' => 'ws subject',
- 'ws_telephone' => 'ws telephone',
- 'ws_plan' => 'ws plan',
- 'ws_product' => 'ws product',
- 'ws_quoteid' => 'ws quoteid',
- 'ws_proposalid' => 'ws proposalid',
- 'ws_leadstage' => 'ws leadstage',
- 'ws_agentid' => 'ws agentid',
- 'ws_noofyears' => 'ws noofyears',
- 'ws_orgnaizationName' => 'ws orgnaizationName',
- 'utmsource' => 'utmsource',
- 'isBulkImport' => 'isBulkImport',
- 'agentId' => 'agentId',
- 'salesClosedUpdatedOn' => 'salesClosedUpdatedOn',
- );
- }
-
- /**
- * Retrieves a list of models based on the current search/filter conditions.
- * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
- */
- public function search1()
- {
- // Warning: Please modify the following code to remove attributes that
- // should not be searched.
-
- $criteria=new CDbCriteria;
- $this->leadSearchBox=@$_POST['lead']['leadSearchBox']?@$_POST['lead']['leadSearchBox']:@$_REQUEST['mob'];
- if($this->leadSearchBox!=''){
- $criteria->with = array('leadStageDetails','leadSourceDetails');
- $criteria->together = true;
-
- $condsc ='';
- if(@$_SESSION['roleId']=='3') {
- $condsc = " AND currentAllocatedId = '".@$_SESSION['id']."'";
- } else {
- $condsc ='';
- /*if(Yii::app()->session->get('type')=='superadmin') {
- $condsc = '';
- } else {
- $relationManager2 = $_SESSION['relationalManager'];
- $managerMemberId2 = implode(",",array_unique(@$relationManager2));
-
- $condsc = " AND currentAllocatedId IN ( '".@$managerMemberId2."' ) ";
- }*/
- }
-
-
-
- $criteria->addCondition("(name LIKE CONCAT('%', :leadSearchBox , '%') OR mobile LIKE CONCAT('%', :leadSearchBox , '%') OR email LIKE CONCAT('%', :leadSearchBox , '%') OR leadStageDetails.leadStage LIKE CONCAT('%', :leadSearchBox , '%') OR leadSourceDetails.leadSourceCode LIKE CONCAT('%', :leadSearchBox , '%') OR mobile LIKE CONCAT('%', :leadSearchBox , '%') ) $condsc");
- $criteria->params = array(':leadSearchBox' => $this->leadSearchBox);
- }
- $criteria->with = array('leadStageDetails','leadSourceDetails');
- $criteria->compare('leadId',$this->leadId,true);
- $criteria->compare('email',$this->email,true);
- $criteria->compare('emailOptOut',$this->emailOptOut,true);
- $criteria->compare('mobile',$this->mobile,true);
- $criteria->compare('mobileOptOut',$this->mobileOptOut,true);
- $criteria->compare('fileName',$this->fileName,true);
- $criteria->compare('leadDescription',$this->leadDescription,true);
- $criteria->compare('status',$this->status,true);
- $criteria->compare('children',$this->children,true);
- $criteria->compare('ageGroup',$this->ageGroup,true);
- $criteria->compare('createdOn',$this->createdOn,true);
- $criteria->compare('createdBy',$this->createdBy,true);
- $criteria->compare('updatedOn',$this->updatedOn,true);
- $criteria->compare('updatedBy',$this->updatedBy,true);
- $criteria->compare('ws_sourcecode',$this->ws_sourcecode,true);
- $criteria->compare('ws_subject',$this->ws_subject,true);
- $criteria->compare('ws_telephone',$this->ws_telephone,true);
- $criteria->compare('ws_plan',$this->ws_plan,true);
- $criteria->compare('ws_product',$this->ws_product,true);
- $criteria->compare('ws_quoteid',$this->ws_quoteid,true);
- $criteria->compare('ws_proposalid',$this->ws_proposalid,true);
- $criteria->compare('ws_leadstage',$this->ws_leadstage,true);
- $criteria->compare('ws_agentid',$this->ws_agentid,true);
- $criteria->compare('ws_noofyears',$this->ws_noofyears,true);
- $criteria->compare('ws_orgnaizationName',$this->ws_orgnaizationName,true);
- $criteria->compare('utmsource',$this->utmsource,true);
- $criteria->compare('isBulkImport',$this->isBulkImport,true);
- $criteria->compare('agentId',$this->agentId,true);
- $criteria->compare('salesClosedUpdatedOn',$this->salesClosedUpdatedOn,true);
-
- return new CActiveDataProvider($this, array(
- 'criteria'=>$criteria,
- 'sort'=>array(
- 'attributes'=>array(
- 'leadSourceDetails_search'=>array(
- 'asc'=>'leadSourceCode',
- 'desc'=>'leadSourceCode DESC',
- ),
- 'leadStageDetails_search'=>array(
- 'asc'=>'leadStage',
- 'desc'=>'leadStage DESC',
- ),
- '*',
- ),
- ),
- 'pagination'=>array(
- 'pageSize'=>20,
- 'params' => array('mob' =>$this->leadSearchBox),
- ),
- ));
- }
-
- /**
- * Retrieves a list of models based on the current search/filter conditions.
- * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
- */
- public function search()
- {
- $criteria = new CDbCriteria;
- $this->leadSearchBox = @$_POST['lead']['leadSearchBox'] ? @$_POST['lead']['leadSearchBox'] : @$_REQUEST['mob'];
- $criteria->limit = 20;
- if ($this->leadSearchBox != '')
- {
- $condsc = '';
-
- if (@$_SESSION['roleId'] == '3')
- {
- $condsc = " AND currentAllocatedId = '" . @$_SESSION['id'] . "'";
- }
- $criteria->together = true;
- $defaultCriteriaCond = trim(LeadsController::searchLeadList($this->leadSearchBox), 'AND ');
- $criteria->addCondition($defaultCriteriaCond . $condsc);
- $criteria->params = array(':leadSearchBox' => $this->leadSearchBox);
- }
-
- //$criteria->compare('leadSourceCode', $this->leadSourceCode, false);
- //$criteria->compare('leadStage', $this->leadStage, false);
-
- return new CActiveDataProvider($this, array(
- 'criteria' => $criteria,
- 'sort' => array(
- 'attributes' => array(
- 'leadSourceDetails_search' => array(
- 'asc' => 'leadSourceCode',
- 'desc' => 'leadSourceCode DESC',
- ),
- 'leadStageDetails_search' => array(
- 'asc' => 'leadStage',
- 'desc' => 'leadStage DESC',
- ),
- '*',
- ),
- ),
- 'pagination' => array(
- 'pageSize' => 20,
- 'params' => array('mob' => $this->leadSearchBox),
- ),
- ));
- }
-
- public function newLeads($userIds){
- $currentDate=date('d-m-Y',time());
- $starttimestamp=strtotime($currentDate);
- $cond='';
- if(isset($_POST['searchDashboard']) && !empty($_POST['searchDashboard'])) {
- $searchDate=@$_POST['searchDashboard'];
- $searchTimestamp=strtotime(@$searchDate);
- $searchEndTimestamp=$searchTimestamp+86400;
- $cond = " and t.updatedOn >= '".@$searchTimestamp."' and t.updatedOn < '".@$searchEndTimestamp."'";
- }
- //die;
- return Lead::model()->count(array("condition"=>" leadStatusId = '35' AND currentAllocatedId >0 AND isRead = 'no' and currentAllocatedId IN ($userIds) ".$cond." "));
- //return Yii::app()->db->createCommand(" ")->queryAll();
- }
- public function overallLeads($userIds){
- $cond='';
- if(isset($_POST['searchDashboard']) && !empty($_POST['searchDashboard'])) {
- $searchDate=@$_POST['searchDashboard'];
- $searchTimestamp=strtotime(@$searchDate);
- $searchEndTimestamp=$searchTimestamp+86400;
- $cond = " and t.updatedOn >= '".@$searchTimestamp."' and t.updatedOn < '".@$searchEndTimestamp."'";
- }
- return Lead::model()->count(array("condition"=>" currentAllocatedId IN ($userIds) ".$cond." "));
- //return Yii::app()->db->createCommand("select count(*) as total from lead where currentAllocatedId IN ($userIds) ".$cond." ")->queryAll();
- }
- public function allocatedLead12Pm($userIds){
- $cond='';
- if(isset($_POST['searchDashboard']) && !empty($_POST['searchDashboard'])) {
- $searchDate=@$_POST['searchDashboard'];
- $searchTimestamp=strtotime(@$searchDate);
- $searchEndTimestamp=$searchTimestamp+86400;
- $cond = " and t.updatedOn >= '".@$searchTimestamp."' and t.updatedOn < '".@$searchEndTimestamp."'";
- }
- $currentDate=date('d-m-Y',time());
- $starttimestamp=strtotime($currentDate);
- $midtimestamp=strtotime($currentDate)+43200;
- return Lead::model()->count(array("condition"=>" currentAllocatedId>0 AND isRead = 'yes' and currentAllocatedId IN ($userIds) ".$cond.""));
- //return Yii::app()->db->createCommand("select count(*) as total from lead where currentAllocatedId>0 AND isRead = 'yes' and currentAllocatedId IN ($userIds) ".$cond." ")->queryAll();
- }
- public function closeLeads($userIds){
- $cond='';
- if(isset($_POST['searchDashboard']) && !empty($_POST['searchDashboard'])) {
- $searchDate=@$_POST['searchDashboard'];
- $searchTimestamp=strtotime(@$searchDate);
- $searchEndTimestamp=$searchTimestamp+86400;
- $cond = " and t.updatedOn >= '".@$searchTimestamp."' and t.updatedOn < '".@$searchEndTimestamp."'";
- }
- return @$userIds?Lead::model()->count(array("condition"=>" (leadStatusId='7' || leadStatusId='1') and currentAllocatedId IN (".@$userIds.") ".$cond."")):0;
- //return Yii::app()->db->createCommand("select count(*) as total from lead where (leadStatusId='7' || leadStatusId='1') and currentAllocatedId IN ($userIds) ".$cond." ")->queryAll();
- }
-
- public function followUpLeads($userIds){
- $cond='';
- if(isset($_POST['searchDashboard']) && !empty($_POST['searchDashboard'])) {
- $searchDate=@$_POST['searchDashboard'];
- $searchTimestamp=strtotime(@$searchDate);
- $searchEndTimestamp=$searchTimestamp+86400;
- $cond = " and t.updatedOn >= '".@$searchTimestamp."' and t.updatedOn < '".@$searchEndTimestamp."'";
- }
- $currentDate=date('d-m-Y',time());
- $starttimestamp=strtotime($currentDate);
- return leadFollowup::model()->count(array("condition"=>" startDate='$starttimestamp' and status='Pending' and userId IN ($userIds) ".$cond.""));
- //return Yii::app()->db->createCommand("select count(*) as total from leadFollowup where startDate='$starttimestamp' and status='Pending' and userId IN ($userIds) ".$cond." ")->queryAll();
- }
- public function closedLeadsAmount($userIds){
- $cond='';
- if(isset($_POST['searchDashboard']) && !empty($_POST['searchDashboard'])) {
- $searchDate=@$_POST['searchDashboard'];
- $searchTimestamp=strtotime(@$searchDate);
- $searchEndTimestamp=$searchTimestamp+86400;
- $cond = " and lead.updatedOn >= '".@$searchTimestamp."' and lead.updatedOn < '".@$searchEndTimestamp."'";
- }
-
- return @$userIds?Yii::app()->db->createCommand("select SUM(premium) as totalAmount from lead where (leadStatusId='7' || leadStatusId='1') and currentAllocatedId IN ($userIds) ".$cond." ")->queryAll():0;
-
- }
- public function fetchteammemberByTeam($teamId){
- return Yii::app()->db->createCommand("select GROUP_CONCAT(distinct userId order by userId,',',true) as teamMemberIds from teamUserMapping where teamId = ".$teamId." ")->queryAll();
- }
- public function getMTD($leadStatusId){
- $cond='';
- if(isset($_POST['searchDashboard']) && !empty($_POST['searchDashboard'])) {
- $searchDate=@$_POST['searchDashboard'];
- $searchTimestamp=strtotime(@$searchDate);
- $searchEndTimestamp=$searchTimestamp+86400;
- $cond = " and t.updatedOn >= '".@$searchTimestamp."' and t.updatedOn <= '".@$searchEndTimestamp."'";
- } else {
- $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1);
- $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"));
- $cond = " and t.updatedOn >= '".@$CurrentMonth_first_minute."' and t.updatedOn <= '".@$CurrentMonth_last_minute."'";
- }
- $currentDate=date('d-m-Y',time());
- $starttimestamp=strtotime($currentDate);
- if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
- return lead::model()->count(array("condition"=>" leadstatusId=".@$leadStatusId." ".$cond." "));
- } else {
- $ids= DashboardController::implodeResult($_SESSION['relationalManager']);
- return lead::model()->count(array("condition"=>" leadstatusId=".@$leadStatusId." and currentAllocatedId IN (".@$ids.") ".$cond.""));
- }
- }
- public function getYTD($leadStatusId){
- $cond='';
- if(isset($_POST['searchDashboard']) && !empty($_POST['searchDashboard'])) {
- $searchDate=@$_POST['searchDashboard'];
- $searchTimestamp=strtotime(@$searchDate);
- $searchEndTimestamp=$searchTimestamp+86400;
- $cond = " and t.updatedOn >= '".@$searchTimestamp."' and t.updatedOn < '".@$searchEndTimestamp."'";
- } else {
- $CurrentYear_first_minute = mktime(0, 0, 0, 1, 1, date('Y'));
- $CurrentYear_last_minute = mktime(0, 0, 0, 13, 0, date('Y'));
- $cond = " and t.updatedOn >= '".@$CurrentYear_first_minute."' and t.updatedOn <= '".@$CurrentYear_last_minute."'";
- }
- $currentDate=date('d-m-Y',time());
- $starttimestamp=strtotime($currentDate);
- if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
- return lead::model()->count(array("condition"=>" leadstatusId=".@$leadStatusId." ".$cond." "));
- } else {
- $ids= DashboardController::implodeResult($_SESSION['relationalManager']);
- return lead::model()->count(array("condition"=>" leadstatusId=".@$leadStatusId." and currentAllocatedId IN (".@$ids.") ".$cond.""));
- }
- }
-
-
-
-
-
-
- }