PageRenderTime 68ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/lms_debug/protected/controllers/LeadsController_11dec2014.php

https://gitlab.com/badelal143/lms_debug
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
  1. <?php
  2. class LeadsController extends Controller
  3. {
  4. const SHARED_TITLE = "Admin Panel";
  5. /**
  6. * Declares class-based actions.
  7. */
  8. public function filters()
  9. {
  10. return array( 'accessControl',array(
  11. 'CHttpCacheFilter + view',
  12. 'cacheControl' => " max-age=604800, must-revalidate",
  13. ) ); // perform access control for CRUD operations
  14. }
  15. public function actions()
  16. {
  17. return array(
  18. // captcha action renders the CAPTCHA image displayed on the contact page
  19. 'captcha'=>
  20. array(
  21. 'class'=>'CCaptchaAction',
  22. 'backColor'=>0xFFFFFF,
  23. ),
  24. // page action renders "static" pages stored under 'protected/views/site/pages'
  25. // They can be accessed via: index.php?r=site/page&view=FileName
  26. 'page'=>array(
  27. 'class'=>'CViewAction',
  28. ),
  29. );
  30. }
  31. /**
  32. * This is the 'roles' action that is invoked
  33. * when an action is not explicitly requested by users.
  34. */
  35. public function actionlead_welcome()
  36. {
  37. $model = new WelcomeMaster();
  38. $model = WelcomeMaster::model()->find("moduleId = '1' ");
  39. $this->render('lead_welcome',array('model'=>$model));
  40. }
  41. /**
  42. * This is the 'roles' action that is invoked
  43. * when an action is not explicitly requested by users.
  44. */
  45. public function actionlead_list()
  46. {
  47. $relationManager = $_SESSION['relationalManager'];
  48. $managerMemberId = implode(",",array_unique(@$relationManager));
  49. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  50. $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead='no' ";
  51. } else {
  52. $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead='no' AND currentAllocatedId IN (".@$managerMemberId.") ";
  53. }
  54. //$modelLead = Lead::model()->findAll(" $querycondition ");
  55. $this->render('lead_list');
  56. }
  57. /**
  58. * This is the 'lead_list_allocator' action that is invoked
  59. * when an action is not explicitly requested by users.
  60. */
  61. public function actionlead_list_allocator()
  62. {
  63. // renders the view file 'protected/views/site/index.php'
  64. // using the default layout 'protected/views/layouts/main.php'
  65. $this->render('lead_list_allocator');
  66. }
  67. /**
  68. * This is the 'lead_list_allocator' action that is invoked
  69. * when an action is not explicitly requested by users.
  70. */
  71. public function actionfollowup_lead_list()
  72. {
  73. $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
  74. $relationManager = $_SESSION['relationalManager'];
  75. $managerMemberId = implode(",",array_unique(@$relationManager));
  76. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  77. $querycondition = ' startDate = "'.@$today12PM.'" and status="Pending" ';
  78. } else {
  79. $querycondition = " startDate = '".@$today12PM."' AND status = 'Pending' AND userId IN (".@$managerMemberId.") ";
  80. }
  81. //$modelLead = LeadFollowup::model()->findAll(" $querycondition ");
  82. $this->render('followup_lead_list');
  83. }
  84. public function actionfollowup_overall_lead_list()
  85. {
  86. $relationManager = $_SESSION['relationalManager'];
  87. $managerMemberId = implode(",",array_unique(@$relationManager));
  88. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  89. $querycondition = ' status="Pending" ';
  90. } else {
  91. $querycondition = " status = 'Pending' AND userId IN (".@$managerMemberId.") ";
  92. }
  93. //$modelLead = LeadFollowup::model()->findAll(" $querycondition ");
  94. $this->render('followup_overall_lead_list');
  95. }
  96. /**
  97. * This is the 'lead_list_allocator' action that is invoked
  98. * when an action is not explicitly requested by users.
  99. */
  100. public function actionlead_list_tc()
  101. {
  102. // renders the view file 'protected/views/site/index.php'
  103. // using the default layout 'protected/views/layouts/main.php'
  104. $this->render('lead_list_tc');
  105. }
  106. /**
  107. * This is the 'lead_list_allocator' action that is invoked
  108. * when an action is not explicitly requested by users.
  109. */
  110. public function actionjunk_lead_list()
  111. {
  112. //$modelLead = Lead::model()->findAll(" leadStatusId = '36' ");
  113. $this->render('junk_lead_list');
  114. }
  115. /**
  116. * This is the 'lead_list_allocator' action that is invoked
  117. * when an action is not explicitly requested by users.
  118. */
  119. public function actionduplicate_lead_list()
  120. {
  121. //$modelLead = Lead::model()->findAll(" leadStatusId = '10' ");
  122. $this->render('duplicate_lead_list');
  123. }
  124. public function actionclose_lead_list()
  125. {
  126. //$modelLead = Lead::model()->findAll(" leadStatusId = '7' ");
  127. $this->render('close_lead_list');
  128. }
  129. /**
  130. * This is the 'lead_list_allocator' action that is invoked
  131. * when an action is not explicitly requested by users.
  132. */
  133. public function actionallocated_lead_list()
  134. {
  135. $relationManager = $_SESSION['relationalManager'];
  136. $managerMemberId = implode(",",array_unique(@$relationManager));
  137. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  138. $querycondition = " currentAllocatedId>0 AND isRead = 'yes'";
  139. } else {
  140. $querycondition = " currentAllocatedId >0 AND isRead = 'yes' AND currentAllocatedId IN (".@$managerMemberId.") ";
  141. }
  142. //$modelLead = Lead::model()->findAll(" $querycondition ");
  143. $this->render('allocated_lead_list');
  144. }
  145. /**
  146. * This is the 'lead_list_allocator' action that is invoked
  147. * when an action is not explicitly requested by users.
  148. */
  149. public function actionleads_details()
  150. {
  151. // renders the view file 'protected/views/site/index.php'
  152. // using the default layout 'protected/views/layouts/main.php'
  153. //for follow up
  154. $parser = new CHtmlPurifier();
  155. if(isset($_POST['LeadFollowup'])){
  156. if(isset($_POST['LeadFollowup']['chkActionValid']) && @$_POST['LeadFollowup']['chkActionValid']==1){
  157. $res = $this->actionlead_followup(@$_POST['LeadFollowup'],$parser->purify(intval(@$_POST['Lead']['leadStatusId'])));
  158. $decodeRes = json_decode($res);
  159. if(@$decodeRes->status == 'success'){
  160. echo CJSON::encode(array(
  161. 'status'=>'success'
  162. ));
  163. } else {
  164. echo $res;
  165. }
  166. }
  167. }
  168. $leadFollDesc = @$_POST['LeadFollowup']['description'];
  169. // end of for follow ups
  170. $leadId = $parser->purify(intval(@$_GET['leadId']));
  171. $actionId = $parser->purify(intval(@$_REQUEST['actionId']));
  172. $actionmodel=LeadFollowup::model()->findByPk($actionId);
  173. $model = new Lead();
  174. $this->performAjaxValidation($model);
  175. $model->scenario = 'Lead';
  176. $managerMemberId = implode(",",$_SESSION['relationalManager']);
  177. $chkAllocatedLeads = $managerMemberId?Lead::model()->findAll(array("select"=>" leadId","condition"=>" leadStatusId != '26' AND leadStatusId != '25' AND currentAllocatedId IN (".@$managerMemberId.") ")):'0';
  178. $allocatedArr=array();
  179. foreach($chkAllocatedLeads as $key=>$value){
  180. $allocatedArr[]=$chkAllocatedLeads[$key]->leadId;
  181. }
  182. //print_r($allocatedArr);
  183. //die;
  184. /*if(Yii::app()->session->get('isAllocator')!='yes' and Yii::app()->session->get('type')!='superadmin'){
  185. if(!in_array($leadId,$allocatedArr)){
  186. $this->redirect(array('leads/lead_list'));
  187. }
  188. }*/
  189. if(!empty($leadId)){
  190. $model=Lead::model()->findByPk($leadId);
  191. $chkrecentlyViewed=recentlyViewed::model()->findByAttributes(array('leadId'=>$leadId,'userId'=>Yii::app()->session->get('id')));
  192. if(count($chkrecentlyViewed) == 0){
  193. $recentlyViewed = new recentlyViewed;
  194. $recentlyViewed->setAttributes(array(
  195. 'userId' => Yii::app()->session->get('id'),
  196. 'leadId' => $leadId,
  197. 'moduleId' => 0,
  198. 'updatedOn' => $_SESSION['id'],
  199. 'updatedBy' => $_SESSION['id'],
  200. ));
  201. $recentlyViewed->save(false);
  202. }
  203. }
  204. if(isset($_POST['Lead']))
  205. {
  206. if($_POST['LeadFollowup']['startDate']!='') {
  207. $finalLeadDesc = @$leadFollDesc;
  208. } else {
  209. $finalLeadDesc = @$_POST['Lead']['leadDescription'];
  210. }
  211. $model->setAttributes(array(
  212. 'updatedOn' => time(), //additional
  213. 'updatedBy' => $_SESSION['id'], //additional
  214. 'status' => 'Active', //additional //additional
  215. 'leadDescription' => @$finalLeadDesc, //additional //additional
  216. ));
  217. $prevLeadStatusId=$model->leadStatusId;
  218. foreach($_POST['Lead'] as $name=>$value)
  219. {
  220. if($model->leadStatusId==''){
  221. $model->leadStatusId=$model->leadStatusParentId;
  222. }
  223. if($model->email=='Email'){
  224. $model->email='';
  225. }
  226. if($model->name=='Name'){
  227. $model->name='';
  228. }
  229. if($model->address=='Address'){
  230. $model->address='';
  231. }
  232. if($model->ws_proposalid=='Proposal No.'){
  233. $model->ws_proposalid='';
  234. }
  235. if($model->children=="Children (Less than 25 Yrs)"){
  236. $model->children='';
  237. }
  238. if($model->ageGroup=="Age of eldest member"){
  239. $model->ageGroup='';
  240. }
  241. if($model->leadDescription=="Lead Description"){
  242. $model->leadDescription='';
  243. }
  244. if($model->leadStatusId==''){
  245. $model->leadStatusId=$prevLeadStatusId;
  246. }
  247. if(@$leadId!='' && $model->leadStatusId!='34' && @$model->leadStatusId!='35'){
  248. $model->isRead='yes';
  249. }
  250. if(is_array($value)){
  251. $value = '';
  252. } else {
  253. $value = $value;
  254. }
  255. $model->$name=$parser->purify($value);
  256. }
  257. if($model->leadStatusParentId=='1'){
  258. $model->salesClosedUpdatedOn=time();
  259. }
  260. $fetchAgentDetails=LeadSourceMaster::model()->findByPk($model->leadSourceId);
  261. $model->agentId = @$fetchAgentDetails->leadSourceCode;
  262. $model->ws_agentid = @$fetchAgentDetails->leadSourceCode;
  263. if(@$leadId!='' && $model->leadStatusId!='34'){
  264. $update = Yii::app()->db->createCommand("update `lead` set `isRead`='yes' where `leadId`='$leadId' and currentAllocatedId > 0")->query();
  265. }
  266. $chkStatusMandatoryOrNot = leadStatus::model()->findByAttributes(array('leadStatusId'=>$model->leadStatusId));
  267. if($model->leadStatusId=='1'){
  268. $model->scenario = 'salesclosed';
  269. }
  270. if(count($chkStatusMandatoryOrNot) > 0){
  271. $condMandatory = $chkStatusMandatoryOrNot['compulsary'];
  272. if($condMandatory == 'No'){
  273. if($model->validate(array('mobile'))){
  274. if(@$_POST['Lead']['emailOptOut']=='on') { $model->emailOptOut='Y'; } else { $model->emailOptOut='N'; }
  275. if(@$_POST['Lead']['mobileOptOut']=='on') { $model->mobileOptOut='Y'; } else { $model->mobileOptOut='N'; }
  276. if(@$_POST['Lead']['isJunk']=='on') { $model->isJunk='yes'; } else { $model->isJunk='no'; }
  277. if(@$_POST['Lead']['isDuplicate']=='on') { $model->isDuplicate='yes'; } else { $model->isDuplicate='no'; }
  278. if(@$_POST['Lead']['status']=='on') { $model->status='Close'; } else { $model->status='Active'; }
  279. $modelHistory = new LeadHistory();
  280. $modelHistory->scenario = 'LeadHistory';
  281. $modelHistory->setAttributes(array(
  282. 'leadId' => @$leadId, //additional data you want to insert
  283. 'updatedOn' => time(), //additional
  284. 'updatedBy' => $_SESSION['id'], //additional
  285. 'status' => 'Active', //additional
  286. 'leadDescription' => @$finalLeadDesc,
  287. ));
  288. foreach($_POST['Lead'] as $name1=>$value1)
  289. {
  290. if($modelHistory->leadStatusId==''){
  291. $modelHistory->leadStatusId=$modelHistory->leadStatusParentId;
  292. }
  293. if(@$_POST['LeadFollowup']['description']=='Description'){
  294. $activitydesc = '';
  295. } else {
  296. $activitydesc = @$_POST['LeadFollowup']['description'];
  297. }
  298. $modelHistory->activityDescription=@$activitydesc;
  299. if($model->leadStatusId==''){
  300. $model->leadStatusId=2;
  301. }
  302. if($modelHistory->email=='Email'){
  303. $modelHistory->email='';
  304. }
  305. if($modelHistory->name=='Name'){
  306. $modelHistory->name='';
  307. }
  308. if($modelHistory->address=='Address'){
  309. $modelHistory->address='';
  310. }
  311. if($modelHistory->leadDescription=="Lead Description"){
  312. $modelHistory->leadDescription='';
  313. }
  314. if($modelHistory->children=="Children (Less than 25 Yrs)"){
  315. $modelHistory->children='';
  316. }
  317. if($modelHistory->ageGroup=="Age of eldest member"){
  318. $modelHistory->ageGroup='';
  319. }
  320. if(is_array($value1)){
  321. $value1 = '';
  322. } else {
  323. $value1 = $value1;
  324. }
  325. $modelHistory->$name1=$parser->purify($value1);
  326. }
  327. $model->save(false);
  328. $modelHistory->save();
  329. CJSON::encode(array(
  330. 'status'=>'success'
  331. ));
  332. Yii::app()->end();
  333. }
  334. }
  335. }
  336. $model->save();
  337. if($model->validate()){
  338. if(@$_POST['Lead']['emailOptOut']=='on') { $model->emailOptOut='Y'; } else { $model->emailOptOut='N'; }
  339. if(@$_POST['Lead']['mobileOptOut']=='on') { $model->mobileOptOut='Y'; } else { $model->mobileOptOut='N'; }
  340. if(@$_POST['Lead']['isJunk']=='on') { $model->isJunk='yes'; } else { $model->isJunk='no'; }
  341. if(@$_POST['Lead']['isDuplicate']=='on') { $model->isDuplicate='yes'; } else { $model->isDuplicate='no'; }
  342. if(@$_POST['Lead']['status']=='on') { $model->status='Close'; } else { $model->status='Active'; }
  343. $modelHistory = new LeadHistory();
  344. $modelHistory->scenario = 'LeadHistory';
  345. $modelHistory->setAttributes(array(
  346. 'leadId' => @$leadId, //additional data you want to insert
  347. 'updatedOn' => time(), //additional
  348. 'updatedBy' => $_SESSION['id'], //additional
  349. 'status' => 'Active', //additional
  350. 'leadDescription' => @$finalLeadDesc,
  351. ));
  352. foreach($_POST['Lead'] as $name1=>$value1)
  353. {
  354. if($modelHistory->leadStatusId==''){
  355. $modelHistory->leadStatusId=$modelHistory->leadStatusParentId;
  356. }
  357. $modelHistory->activityDescription=@$_POST['LeadFollowup']['description'];
  358. if($model->leadStatusId==''){
  359. $model->leadStatusId=2;
  360. }
  361. if(is_array($value1)){
  362. $value1 = '';
  363. } else {
  364. $value1 = $value1;
  365. }
  366. $modelHistory->$name1=$parser->purify($value1);
  367. }
  368. $modelHistory->save();
  369. echo CJSON::encode(array(
  370. 'status'=>'success'
  371. ));
  372. Yii::app()->end();
  373. //Yii::app()->end();
  374. //die;
  375. //$this->redirect(array('leads/leads_details'));
  376. } else {
  377. @$error = CActiveForm::validate(@$model);
  378. if($error!='[]')
  379. echo @$error;
  380. Yii::app()->end();
  381. //$this->render('leads_details',array('model'=>$model));
  382. }
  383. } else {
  384. $this->render('leads_details',array('model'=>@$model,'actionmodel'=>@$actionmodel,'quotesmobile'=>@$model->mobile));
  385. }
  386. }
  387. protected function performAjaxValidation($models)
  388. {
  389. if(isset($_POST['ajax']) && $_POST['ajax']==='user-form')
  390. {
  391. echo CActiveForm::validate($models);
  392. Yii::app()->end();
  393. }
  394. }
  395. /**
  396. * This is the 'lead_list_allocator' action that is invoked
  397. * when an action is not explicitly requested by users.
  398. */
  399. public function actionlead_followup()
  400. {
  401. $actionId = @$_REQUEST['actionId'];
  402. $model = new LeadFollowup();
  403. $model->scenario = 'LeadFollowup';
  404. if(isset($actionId) && !empty($actionId)){
  405. $model=LeadFollowup::model()->findByPk($actionId);
  406. } else {
  407. }
  408. if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Task'){
  409. $model->scenario = 'LeadFollowupTask';
  410. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Follow Up'){
  411. $model->scenario = 'LeadFollowup';
  412. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Meeting'){
  413. $model->scenario = 'LeadFollowup';
  414. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Notes'){
  415. $model->scenario = 'LeadFollowupNotes';
  416. }
  417. $parser = new CHtmlPurifier();
  418. $this->performAjaxValidation($model);
  419. if(isset($_POST['LeadFollowup']))
  420. {
  421. $userId = $_POST['LeadFollowup']['userId'];
  422. $followupstartdatewithtime = strtotime(@$_POST['LeadFollowup']['startDate'])+(@$_POST['LeadFollowup']['hour']*60*60)+(@$_POST['LeadFollowup']['minutes']*60);
  423. $model->setAttributes(array(
  424. 'createdOn' => time(), //additional data you want to insert
  425. 'updatedOn' => time(), //additional
  426. 'updatedBy' => @$userId, //additional
  427. 'createdBy' => @$userId, //additional
  428. 'status' => 'Pending', //additional
  429. ));
  430. foreach($_POST['LeadFollowup'] as $name=>$value)
  431. {
  432. if(is_array($value)){
  433. $value = '';
  434. } else {
  435. $value = $value;
  436. }
  437. $model->$name=$parser->purify($value);
  438. }
  439. $model->leadStatusId=@$_POST['Lead']['leadStatusId'];;
  440. $model->startDateWithTime=@$followupstartdatewithtime;
  441. if(@$_POST['LeadFollowup']['actionType']=='Notes') {
  442. $prefix=substr(time(),0,5);
  443. $folder = 'siteupload/';
  444. $model->notesFile=CUploadedFile::getInstance($model,'notesFile');
  445. if($model->notesFile !='')
  446. $model->notesFile->saveAs($folder.$prefix.$model->notesFile);
  447. $model->notesFile=$prefix.CUploadedFile::getInstance($model,'notesFile');
  448. }
  449. if(@$_POST['LeadFollowup']['startDate']!='') {
  450. $startDateVal = strtotime($_POST['LeadFollowup']['startDate']);
  451. $model->startDate=@$startDateVal;
  452. }
  453. if(@$_POST['LeadFollowup']['taskDueDate']!='') {
  454. $taskDueDateVal = strtotime($_POST['LeadFollowup']['taskDueDate']);
  455. $model->taskDueDate=@$taskDueDateVal;
  456. }
  457. if(@$_POST['LeadFollowup']['taskCompleted']!='') {
  458. $model->taskCompleted='yes';
  459. }
  460. if($model->validate()){
  461. $checkForSameDateExistsOrNot=LeadFollowup::model()->findAll(" leadId='".@$_POST['LeadFollowup']['leadId']."' and startDate <= '".$model->startDate."' and userId = '".@$userId."' and createdBy = '".@$userId."' ");
  462. if(count(@$checkForSameDateExistsOrNot) > 0){
  463. $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();
  464. }
  465. $model->save();
  466. $leadId = $_POST['LeadFollowup']['leadId'];
  467. return CJSON::encode(array(
  468. 'status'=>'success'
  469. ));
  470. Yii::app()->end();
  471. } else {
  472. $error = CActiveForm::validate($model);
  473. if($error!='[]')
  474. return $error;
  475. Yii::app()->end();
  476. }
  477. //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  478. }
  479. $this->redirect(array('leads/lead_list'));
  480. }
  481. /**
  482. * This is the 'lead_list_allocator' action that is invoked
  483. * when an action is not explicitly requested by users.
  484. */
  485. public function actionlead_followupcalender()
  486. {
  487. $actionId = @$_REQUEST['actionId'];
  488. $model = new LeadFollowup();
  489. $model->scenario = 'LeadFollowup';
  490. if(isset($actionId) && !empty($actionId)){
  491. $model=LeadFollowup::model()->findByPk($actionId);
  492. } else {
  493. }
  494. if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Task'){
  495. $model->scenario = 'LeadFollowupTask';
  496. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Follow Up'){
  497. $model->scenario = 'LeadFollowup';
  498. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Meeting'){
  499. $model->scenario = 'LeadFollowup';
  500. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Notes'){
  501. $model->scenario = 'LeadFollowupNotes';
  502. }
  503. $this->performAjaxValidation($model);
  504. if(isset($_POST['LeadFollowup']))
  505. {
  506. $userId = $_POST['LeadFollowup']['userId'];
  507. $model->setAttributes(array(
  508. 'createdOn' => time(), //additional data you want to insert
  509. 'updatedOn' => time(), //additional
  510. 'updatedBy' => @$userId, //additional
  511. 'createdBy' => @$userId, //additional
  512. 'status' => 'Pending', //additional
  513. ));
  514. foreach($_POST['LeadFollowup'] as $name=>$value)
  515. {
  516. $model->$name=$value;
  517. }
  518. $model->leadStatusId=@$_POST['Lead']['leadStatusId'];;
  519. if(@$_POST['LeadFollowup']['actionType']=='Notes') {
  520. $prefix=substr(time(),0,5);
  521. $folder = 'siteupload/';
  522. $model->notesFile=CUploadedFile::getInstance($model,'notesFile');
  523. if($model->notesFile !='')
  524. $model->notesFile->saveAs($folder.$prefix.$model->notesFile);
  525. $model->notesFile=$prefix.CUploadedFile::getInstance($model,'notesFile');
  526. }
  527. if(@$_POST['LeadFollowup']['startDate']!='') {
  528. $startDateVal = strtotime($_POST['LeadFollowup']['startDate']);
  529. $model->startDate=@$startDateVal;
  530. }
  531. if(@$_POST['LeadFollowup']['taskDueDate']!='') {
  532. $taskDueDateVal = strtotime($_POST['LeadFollowup']['taskDueDate']);
  533. $model->taskDueDate=@$taskDueDateVal;
  534. }
  535. if(@$_POST['LeadFollowup']['taskCompleted']!='') {
  536. $model->taskCompleted='yes';
  537. }
  538. if($model->validate()){
  539. $model->save();
  540. $leadId = $_POST['LeadFollowup']['leadId'];
  541. echo CJSON::encode(array(
  542. 'status'=>'success'
  543. ));
  544. Yii::app()->end();
  545. } else {
  546. $error = CActiveForm::validate($model);
  547. if($error!='[]')
  548. return $error;
  549. Yii::app()->end();
  550. }
  551. //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  552. }
  553. $this->redirect(array('leads/lead_list'));
  554. }
  555. public function actionlead_contacts()
  556. {
  557. // renders the view file 'protected/views/site/index.php'
  558. // using the default layout 'protected/views/layouts/main.php'
  559. $model = new LeadContacts();
  560. $model->scenario = 'LeadContacts';
  561. $this->performAjaxValidation($model);
  562. if(!empty($_GET['contactId']))
  563. {
  564. $leadContactId=$_GET['leadContactId'];
  565. $model=LeadContacts::model()->findByPk($leadContactId);
  566. }
  567. if(!empty($_POST['LeadContacts']['leadContactId']))
  568. {
  569. $leadContactId=$_POST['LeadContacts']['leadContactId'];
  570. $model=LeadContacts::model()->findByPk($leadContactId);
  571. }
  572. if(isset($_POST['LeadContacts']))
  573. {
  574. $userId = $_POST['LeadContacts']['userId'];
  575. $leadId = $_POST['LeadContacts']['leadId'];
  576. $model->setAttributes(array(
  577. 'createdOn' => time(), //additional data you want to insert
  578. 'updatedOn' => time(), //additional
  579. 'updatedBy' => @$userId, //additional
  580. 'createdBy' => @$userId, //additional
  581. 'status' => 'Active', //additional
  582. ));
  583. foreach($_POST['LeadContacts'] as $name=>$value)
  584. {
  585. $model->$name=$value;
  586. }
  587. if($model->validate()){
  588. $model->save();
  589. echo CJSON::encode(array(
  590. 'status'=>'success'
  591. ));
  592. Yii::app()->end();
  593. } else {
  594. $error = CActiveForm::validate($model);
  595. if($error!='[]')
  596. echo $error;
  597. Yii::app()->end();
  598. }
  599. //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  600. }
  601. $this->redirect(array('leads/lead_list'));
  602. }
  603. public function actionChangeContactStatus()
  604. {
  605. $Id=$_REQUEST['contactId'];
  606. $leadId=$_REQUEST['leadId'];
  607. $status=$_REQUEST['status'];
  608. if(isset($status)&&($status=='Inactive')){
  609. $status="Active";
  610. } else {
  611. $status="Inactive";
  612. }
  613. if(!empty($Id))
  614. {
  615. $model=LeadContacts::model()->findByPk($Id);
  616. }
  617. else
  618. {
  619. $model = LeadContacts::model()->findAll();
  620. }
  621. $model->status=$status;
  622. $model->save();
  623. $this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  624. }
  625. /**
  626. * This is the 'roles' action that is invoked
  627. * when an action is not explicitly requested by users.
  628. */
  629. public function actioncreate_lead()
  630. {
  631. $model=new Lead();
  632. $model->scenario = 'Lead';
  633. if(!empty($_GET['leadId']))
  634. {
  635. $leadId=$_GET['leadId'];
  636. $model=Lead::model()->findByPk($leadId);
  637. $chkrecentlyViewed=recentlyViewed::model()->findByAttributes(array('leadId'=>$leadId,'userId'=>Yii::app()->session->get('id')));
  638. if(count($chkrecentlyViewed) == 0){
  639. $recentlyViewed = new recentlyViewed;
  640. $recentlyViewed->setAttributes(array(
  641. 'userId' => Yii::app()->session->get('id'),
  642. 'leadId' => $leadId,
  643. 'moduleId' => 0,
  644. 'createdOn' => time(),
  645. 'updatedOn' => time(),
  646. 'updatedBy' => time(),
  647. 'createdBy' => time(),
  648. ));
  649. $recentlyViewed->save(false);
  650. }
  651. }
  652. if(!empty($_POST['Lead']['leadId']))
  653. {
  654. $leadId=$_POST['Lead']['leadId'];
  655. $model=Lead::model()->findByPk($leadId);
  656. }
  657. if(isset($_POST['Lead']))
  658. {
  659. $model->setAttributes(array(
  660. 'createdOn' => time(), //additional data you want to insert
  661. 'updatedOn' => time(), //additional
  662. 'updatedBy' => Yii::app()->session->get('id'), //additional
  663. 'createdBy' => Yii::app()->session->get('id'),
  664. ));
  665. foreach($_POST['Lead'] as $name=>$value)
  666. {
  667. $model->$name=$value;
  668. if($model->leadStatusId==''){
  669. $model->leadStatusId=$model->leadStatusParentId;
  670. }
  671. if($model->leadStatusId==''){
  672. $model->leadStatusId=34;
  673. }
  674. if($model->mobile=='Mobile*'){
  675. $model->mobile='';
  676. }
  677. if($model->email=='Email'){
  678. $model->email='';
  679. }
  680. if($model->name=='Name'){
  681. $model->name='';
  682. }
  683. if($model->address=='Address'){
  684. $model->address='';
  685. }
  686. if($model->children=="Children (Less than 25 Yrs)"){
  687. $model->children='';
  688. }
  689. if($model->ageGroup=="Age of eldest member"){
  690. $model->ageGroup='';
  691. }
  692. }
  693. if($model->leadStatusParentId=='1'){
  694. $model->salesClosedUpdatedOn=time();
  695. }
  696. if($model->leadSourceId=='' or empty($model->leadSourceId)){
  697. $model->leadSourceId = '2';
  698. }
  699. $fetchAgentDetails=LeadSourceMaster::model()->findByPk($model->leadSourceId);
  700. $model->agentId = @$fetchAgentDetails->leadSourceCode;
  701. $model->ws_agentid = @$fetchAgentDetails->leadSourceCode;
  702. if(Yii::app()->session->get('isAllocator')!='yes' and Yii::app()->session->get('type')!='superadmin') {
  703. @$model->leadStatusId=35;
  704. @$model->currentAllocatedId=Yii::app()->session->get('id');
  705. }
  706. if(@$leadId!='' && $model->leadStatusId!='34'){
  707. $update = Yii::app()->db->createCommand("update `lead` set `isRead`='yes' where `leadId`='$leadId' and currentAllocatedId > 0")->query();
  708. }
  709. if(@$_POST['Lead']['emailOptOut']=='on') { $model->emailOptOut='Y'; } else { $model->emailOptOut='N'; }
  710. if(@$_POST['Lead']['mobileOptOut']=='on') { $model->mobileOptOut='Y'; } else { $model->mobileOptOut='N'; }
  711. if(@$_POST['Lead']['isJunk']=='on') { $model->isJunk='yes'; } else { $model->isJunk='no'; }
  712. if(@$_POST['Lead']['isDuplicate']=='on') { $model->isDuplicate='yes'; } else { $model->isDuplicate='no'; }
  713. if(@$_POST['Lead']['status']=='on') { $model->status='Close'; } else { $model->status='Active'; }
  714. $chkStatusMandatoryOrNot = leadStatus::model()->findByAttributes(array('leadStatusId'=>$model->leadStatusId));
  715. if(count($chkStatusMandatoryOrNot) > 0){
  716. $condMandatory = $chkStatusMandatoryOrNot['compulsary'];
  717. if($condMandatory == 'No'){
  718. if($model->validate(array('mobile'))){
  719. $mobileNumber = @$_POST['Lead']['mobile'];
  720. $checkJunkNumber = JunkNumbersMaster::model()->find('junkLeadNumber = "'.@$mobileNumber.'"');
  721. if(empty($checkJunkNumber)){
  722. $beforethreemonth = time()-7776000;
  723. $checkDuplicateNumber = Lead::model()->find('mobile = "'.@$mobileNumber.'" AND createdOn > "'.@$beforethreemonth.'" AND status = "Active" AND leadId != "'.@$leadId.'" ');
  724. if(empty($checkDuplicateNumber)){
  725. $model->save(false);
  726. Yii::app()->user->setFlash('lead_msg_success','Successfully Inserted');
  727. } else {
  728. $duplicateLeadId = $checkDuplicateNumber->leadId;
  729. $model->leadStatusId='10';
  730. $model->duplicateLeadId=@$duplicateLeadId;
  731. $model->currentAllocatedId=$checkDuplicateNumber->currentAllocatedId;
  732. $model->save(false);
  733. Yii::app()->user->setFlash('lead_msg_success','Successfully Inserted');
  734. }
  735. } else {
  736. $model->leadStatusId='36';
  737. $model->save(false);
  738. Yii::app()->user->setFlash('lead_msg_success','Junk Lead');
  739. }
  740. $this->redirect(array('leads/lead_list'));
  741. // $model->save(false);
  742. // $this->redirect(array('leads/lead_list'));
  743. }
  744. }
  745. }
  746. if($model->leadStatusId==36){
  747. $model->save(false);
  748. $this->redirect(array('leads/lead_list'));
  749. } else {
  750. if($model->validate()){
  751. $mobileNumber = $_POST['Lead']['mobile'];
  752. $checkJunkNumber = JunkNumbersMaster::model()->find('junkLeadNumber = "'.@$mobileNumber.'"');
  753. if(empty($checkJunkNumber)){
  754. $beforethreemonth = time()-7776000;
  755. $checkDuplicateNumber = Lead::model()->find('mobile = "'.@$mobileNumber.'" AND createdOn > "'.@$beforethreemonth.'" AND status = "Active" AND leadId != "'.@$leadId.'" ');
  756. if(empty($checkDuplicateNumber)){
  757. $model->save();
  758. Yii::app()->user->setFlash('lead_msg_success','Successfully Inserted');
  759. } else {
  760. $duplicateLeadId = $checkDuplicateNumber->leadId;
  761. $model->leadStatusId='10';
  762. $model->duplicateLeadId=@$duplicateLeadId;
  763. $model->save();
  764. Yii::app()->user->setFlash('lead_msg_success','Successfully Inserted');
  765. }
  766. } else {
  767. $model->leadStatusId='36';
  768. $model->save();
  769. Yii::app()->user->setFlash('lead_msg_success','Junk Lead');
  770. }
  771. $this->redirect(array('leads/lead_list'));
  772. } else {
  773. $this->render('create_lead',array('model'=>$model));
  774. }
  775. }
  776. } else {
  777. $this->render('create_lead',array('model'=>$model));
  778. }
  779. }
  780. public function actionAllocateLeads()
  781. {
  782. $Id = $_REQUEST['userids'];
  783. $teamId = @$_REQUEST['Team']['teamId'];
  784. $userId = $_REQUEST['Team']['teamMemberId'];
  785. $updatedBy = @$_SESSION['id'];
  786. $updatedOn = time();
  787. $teamIdString = '';
  788. if($teamId)
  789. {
  790. $teamIdString = ',teamId = ' . $teamId . ', ';
  791. }
  792. foreach($Id as $key => $value)
  793. {
  794. $commonQueryString = ", updatedBy = $updatedBy, updatedOn = $updatedOn where leadId = $value";
  795. $updateLead = "update lead set currentAllocatedId = $userId, leadStatusId = 35, currentAllocatedDate = $updatedOn $commonQueryString";
  796. Yii::app()->db->createCommand($updateLead)->execute();
  797. }
  798. $red = @$_REQUEST['red'];
  799. if($this->action->id=='AllocateLeads' && $red == 1)
  800. {
  801. $this->redirect(array('leads/lead_list'));
  802. }
  803. $this->redirect(array('leads/fresh_leads'));
  804. }
  805. public function actionAllocateLeads_17nov2014()
  806. {
  807. $Id = $_REQUEST['userids'];
  808. $teamId = @$_REQUEST['Team']['teamId'];
  809. $userId = $_REQUEST['Team']['teamMemberId'];
  810. $updatedBy = @$_SESSION['id'];
  811. foreach($Id as $key=>$value){
  812. $model = new AllocatedLeads();
  813. $model->scenario = 'AllocatedLeads';
  814. $model->setAttributes(array(
  815. 'currentAllocatedDate' => time(), //additional data you want to insert
  816. //'createdOn' => time(), //additional data you want to insert
  817. 'updatedOn' => time(), //additional
  818. 'updatedBy' => @$updatedBy, //additional
  819. 'createdBy' => @$updatedBy, //additional
  820. 'leadStatusId' => '35', //additional //additional
  821. ));
  822. $leadId = @$value;
  823. $model->leadId = @$value;
  824. $model->userId = @$userId;
  825. $model->teamId = @$teamId;
  826. //echo @$teamId.' - '.@$userId.' - '.@$leadId;
  827. $model->allocatedId = null;
  828. $model->isNewRecord = true;
  829. $model->save();
  830. $model=new Lead();
  831. $model->scenario = 'Lead';
  832. $updatedOn = time();
  833. Lead::model()->updateByPk(@$value, array('currentAllocatedId'=>@$userId,'leadStatusId'=>'35','updatedBy'=>@$updatedBy,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
  834. }
  835. $red = @$_REQUEST['red'];
  836. if($this->action->id=='AllocateLeads' && $red == 1) {
  837. $this->redirect(array('leads/lead_list'));
  838. } else {
  839. $this->redirect(array('leads/fresh_leads'));
  840. }
  841. //$this->redirect(array('leads/lead_list'));
  842. }
  843. public function actionAllocateLeadswithcount()
  844. {
  845. $Id = $_REQUEST['userids'];
  846. $teamId = @$_REQUEST['Team']['teamId'];
  847. $userId = $_REQUEST['Team']['teamMemberId'];
  848. $updatedBy = @$_SESSION['id'];
  849. foreach($Id as $key=>$value){
  850. $model = new AllocatedLeads();
  851. $model->scenario = 'AllocatedLeads';
  852. $model->setAttributes(array(
  853. 'currentAllocatedDate' => time(), //additional data you want to insert
  854. //'createdOn' => time(), //additional data you want to insert
  855. 'updatedOn' => time(), //additional
  856. 'updatedBy' => @$updatedBy, //additional
  857. 'createdBy' => @$updatedBy, //additional
  858. 'leadStatusId' => '35', //additional //additional
  859. ));
  860. $leadId = @$value;
  861. $model->leadId = @$value;
  862. $model->userId = @$userId;
  863. $model->teamId = @$teamId;
  864. //echo @$teamId.' - '.@$userId.' - '.@$leadId;
  865. $model->allocatedId = null;
  866. $model->isNewRecord = true;
  867. $model->save();
  868. $model=new Lead();
  869. $model->scenario = 'Lead';
  870. $updatedOn = time();
  871. //Lead::model()->updateByPk(@$value, array('currentAllocatedId'=>@$userId,'leadStatusId'=>'35','updatedBy'=>@$updatedBy,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
  872. }
  873. $red = @$_REQUEST['red'];
  874. $chkleadAllocatedOrNot = Lead::model()->findByPk($leadId);
  875. $oldallocatedid = $chkleadAllocatedOrNot['currentAllocatedId'];
  876. if(isset($oldallocatedid) && !empty($oldallocatedid)){
  877. $checkLeadExistorNot=Leadallcount::model()->findByAttributes(array('userid'=>$oldallocatedid,'key'=>'2014'));
  878. if(count($checkLeadExistorNot) > 0){
  879. Leadallcount::model()->updateByPk(@$checkLeadExistorNot['id'], array('userid'=>@$oldallocatedid,'key'=>'2014','value'=>'35','updatedBy'=>@$updatedBy,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
  880. } else {
  881. $leadcount = new Leadallcount();
  882. $leadcount->setAttributes(array(
  883. 'userid' => $oldallocatedid, //additional data you want to insert
  884. 'key' => 2014, //additional data you want to insert
  885. 'value' => 1, //additional data you want to insert
  886. 'createdOn' => time(), //additional data you want to insert
  887. 'updatedOn' => time(), //additional
  888. 'updatedBy' => time(), //additional
  889. 'createdBy' => time(), //additional //additional
  890. ));
  891. $leadcount->save(false);
  892. }
  893. }
  894. /*$leadcount->setAttributes(array(
  895. 'userid' => time(), //additional data you want to insert
  896. 'key' => 2014, //additional data you want to insert
  897. 'value' => 1, //additional data you want to insert
  898. 'createdOn' => time(), //additional data you want to insert
  899. 'updatedOn' => time(), //additional
  900. 'updatedBy' => time(), //additional
  901. 'createdBy' => time(), //additional //additional
  902. ));
  903. $leadcount->save(false);*/
  904. die;
  905. if($this->action->id=='AllocateLeads' && $red == 1) {
  906. $this->redirect(array('leads/lead_list'));
  907. } else {
  908. $this->redirect(array('leads/fresh_leads'));
  909. }
  910. //$this->redirect(array('leads/lead_list'));
  911. }
  912. /**
  913. * This is the 'lead_list_allocator' action that is invoked
  914. * when an action is not explicitly requested by users.
  915. */
  916. public function actionlead_assign()
  917. {
  918. $model = new Lead();
  919. $model->scenario = 'Lead';
  920. $leadId = $_REQUEST['AssignLead']['leadId'];
  921. $userId = $_REQUEST['AssignLead']['userId'];
  922. $assign = $_REQUEST['AssignLead']['assign'];
  923. if($leadId!='') {
  924. $updatedOn = time();
  925. $chkleadStatus = Lead::model()->findByPk($leadId);
  926. $existsOrNot = $chkleadStatus['leadStatusId'];
  927. $leadStatusIdUpdate = $existsOrNot?$existsOrNot:'34';
  928. if($leadStatusIdUpdate == 34){
  929. $leadStatusIdUpdate = 35;
  930. } else {
  931. $leadStatusIdUpdate = $leadStatusIdUpdate;
  932. }
  933. if($assign=='open') {
  934. Lead::model()->updateByPk(@$leadId, array('currentAllocatedId'=>'','status'=>'Active','leadStatusId'=>34,'updatedBy'=>@$userId,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>''));
  935. } elseif($assign=='self'){
  936. Lead::model()->updateByPk(@$leadId, array('currentAllocatedId'=>@$userId,'status'=>'Allocated','leadStatusId'=>@$leadStatusIdUpdate,'updatedBy'=>@$userId,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
  937. } else {
  938. Lead::model()->updateByPk(@$leadId, array('currentAllocatedId'=>@$assign,'status'=>'Allocated','leadStatusId'=>@$leadStatusIdUpdate,'updatedBy'=>@$userId,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
  939. }
  940. echo CJSON::encode(array(
  941. 'status'=>'success'
  942. ));
  943. Yii::app()->end();
  944. //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  945. } else {
  946. $this->redirect(array('leads/lead_list'));
  947. }
  948. }
  949. /**
  950. * This is the 'roles' action that is invoked
  951. * when an action is not explicitly requested by users.
  952. */
  953. public function actionarchive_leads()
  954. {
  955. // renders the view file 'protected/views/site/index.php'
  956. // using the default layout 'protected/views/layouts/main.php'
  957. $model=new Lead();
  958. //$model=Lead::model()->findAll();
  959. $this->render('archive_leads',array('model'=>$model));
  960. }
  961. /**
  962. * This is the 'roles' action that is invoked
  963. * when an action is not explicitly requested by users.
  964. */
  965. public function actionbulk_import_leads()
  966. {
  967. // renders the view file 'protected/views/site/index.php'
  968. // using the default layout 'protected/views/layouts/main.php'
  969. $model=new Lead();
  970. $this->render('bulk_import_lead',array('model'=>$model));
  971. }
  972. /**
  973. * This is the 'roles' action that is invoked
  974. * when an action is not explicitly requested by users.
  975. */
  976. public function actionjunk_leads()
  977. {
  978. // renders the view file 'protected/views/site/index.php'
  979. // using the default layout 'protected/views/layouts/main.php'
  980. $this->render('junk_leads');
  981. }
  982. /**
  983. * This is the 'module master' action that is invoked
  984. * when an action is not explicitly requested by users.
  985. */
  986. public function actionmodule_master()
  987. {
  988. // renders the view file 'protected/views/site/index.php'
  989. // using the default layout 'protected/views/layouts/main.php'
  990. $model=new ModuleMaster();
  991. $model->scenario = 'ModuleMaster';
  992. if(!empty($_GET['moduleId']))
  993. {
  994. $moduleId=$_GET['moduleId'];
  995. $model=ModuleMaster::model()->findByPk($moduleId);
  996. }
  997. if(!empty($_POST['ModuleMaster']['moduleId']))
  998. {
  999. $moduleId=$_POST['ModuleMaster']['moduleId'];
  1000. $model=ModuleMaster::model()->findByPk($moduleId);
  1001. }
  1002. if(isset($_POST['ModuleMaster']))
  1003. {
  1004. $model->setAttributes(array(
  1005. 'createdOn' => time(), //additional data you want to insert
  1006. 'updatedOn' => time(), //additional
  1007. 'updatedBy' => time(), //additional
  1008. 'createdBy' => time(),
  1009. 'status' => 'Activated', //additional //additional
  1010. ));
  1011. foreach($_POST['ModuleMaster'] as $name=>$value)
  1012. {
  1013. $model->$name=$value;
  1014. }
  1015. if($model->validate()){
  1016. $model->save();
  1017. $model2=ModuleMaster::model()->findAll();
  1018. $this->render('module_master',array('model'=>$model,'model2'=>$model2));
  1019. Yii::app()->user->setFlash('module_master_msg_success','Successfully Inserted');
  1020. } else {
  1021. Yii::app()->user->setFlash('module_master_msg_error','Please check. error occured');
  1022. $this->render('module_master',array('model'=>$model));
  1023. }
  1024. } else {
  1025. $model2=ModuleMaster::model()->findAll();
  1026. //Yii::app()->user->setFlash('lead_stage_msg_error','Please check. error occured');
  1027. $this->render('module_master',array('model'=>$model,'model2'=>$model2));
  1028. }
  1029. }
  1030. /**
  1031. * This is the action to handle external exceptions.
  1032. */
  1033. public function actionError()
  1034. {
  1035. if($error=Yii::app()->errorHandler->error)
  1036. {
  1037. if(Yii::app()->request->isAjaxRequest)
  1038. echo $error['message'];
  1039. else
  1040. $this->render('error', $error);
  1041. }
  1042. }
  1043. /**
  1044. * Displays the contact page
  1045. */
  1046. public function actionContact()
  1047. {
  1048. $model=new ContactForm;
  1049. if(isset($_POST['ContactForm']))
  1050. {
  1051. $model->attributes=$_POST['ContactForm'];
  1052. if($model->validate())
  1053. {
  1054. $name='=?UTF-8?B?'.base64_encode($model->name).'?=';
  1055. $subject='=?UTF-8?B?'.base64_encode($model->subject).'?=';
  1056. $headers="From: $name <{$model->email}>\r\n".
  1057. "Reply-To: {$model->email}\r\n".
  1058. "MIME-Version: 1.0\r\n".
  1059. "Content-type: text/plain; charset=UTF-8";
  1060. mail(Yii::app()->params['adminEmail'],$subject,$model->body,$headers);
  1061. Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
  1062. $this->refresh();
  1063. }
  1064. }
  1065. $this->render('contact',array('model'=>$model));
  1066. }
  1067. /**
  1068. * Displays the login page
  1069. */
  1070. public function actionLogin()
  1071. {
  1072. $model=new User;
  1073. // if it is ajax validation request
  1074. if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
  1075. {
  1076. echo CActiveForm::validate($model);
  1077. Yii::app()->end();
  1078. }
  1079. // collect user input data
  1080. if(isset($_POST['User']))
  1081. {
  1082. $model->attributes=$_POST['User'];
  1083. // validate user input and redirect to the previous page if valid
  1084. if($model->validate() && $model->login()){
  1085. $this->redirect(array('masters/dashboard'));
  1086. } else {
  1087. $this->redirect(Yii::app()->user->returnUrl);
  1088. }
  1089. }
  1090. // display the login form
  1091. $this->render('login',array('model'=>$model));
  1092. }
  1093. /**
  1094. * Logs out the current user and redirect to homepage.
  1095. */
  1096. public function actionLogout()
  1097. {
  1098. setcookie ('PHPSESSID', '', time(), '/', '', 0, 0); // Destroy the cookie.
  1099. Yii::app()->user->logout();
  1100. $this->redirect(Yii::app()->homeUrl);
  1101. }
  1102. public function getPageType()
  1103. {
  1104. return "Leads";
  1105. }
  1106. public function init(){
  1107. $obj =new RecentlyViewedController(); // preparing object
  1108. $data=$obj->actionUserRoleAccess();
  1109. $moduleArray=array();
  1110. if(Yii::app()->session->get('type')=='superadmin'){
  1111. $moduleArray['read']='yes';
  1112. $moduleArray['write']='yes';
  1113. $moduleArray['delete']='yes';
  1114. }else{
  1115. foreach($data as $key=>$value){
  1116. if($data[$key]->modules->moduleName=='Leads'){
  1117. $moduleArray['moduleName']=$data[$key]->modules->moduleName;
  1118. $moduleArray['read']=$data[$key]->read;
  1119. $moduleArray['write']=$data[$key]->write;
  1120. $moduleArray['delete']=$data[$key]->delete;
  1121. }
  1122. }
  1123. }
  1124. return $moduleArray;
  1125. }
  1126. public function getNameFromNumber($num) {
  1127. $numeric = $num % 26;
  1128. $letter = chr(65 + $numeric);
  1129. $num2 = intval($num / 26);
  1130. if ($num2 > 0) {
  1131. return getNameFromNumber($num2 - 1) . $letter;
  1132. } else {
  1133. return $letter;
  1134. }
  1135. }
  1136. /*function actionexportArchiveList()
  1137. {
  1138. // generate a resultset
  1139. $model=new User;
  1140. $model=User::model()->findAll();
  1141. // render data to xlsx format and echo resultant file back to browser.
  1142. ExcelExporter::sendAsXLS($model, true, 'closedLeads.xls');
  1143. }*/
  1144. public function actionDownloadLeadTemp(){
  1145. Yii::import('ext.phpexcel.XPHPExcel');
  1146. $objPHPExcel= XPHPExcel::createPHPExcel();
  1147. $objPHPExcel->getProperties()->setCreator("LeadTemplate")
  1148. ->setLastModifiedBy("LeadTemplate")
  1149. ->setTitle("LeadTemplate")
  1150. ->setSubject("LeadTemplate")
  1151. ->setDescription("LeadTemplate.")
  1152. ->setKeywords("LeadTemplate")
  1153. ->setCategory("LeadTemplate");
  1154. //echo $total_excelColumns=$this->getNameFromNumber(4);
  1155. $total_excelColumns='I';
  1156. // Rename worksheet
  1157. $objPHPExcel->getActiveSheet()->setTitle('ClosedLeads');
  1158. $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);
  1159. $objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
  1160. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(30);
  1161. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
  1162. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
  1163. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
  1164. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(30);
  1165. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(30);
  1166. $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
  1167. $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
  1168. $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(30);
  1169. $objPHPExcel->getActiveSheet()->duplicateStyleArray(
  1170. array(
  1171. 'font' => array(
  1172. 'name' => 'Times New Roman',
  1173. 'bold' => true,
  1174. 'italic' => false,
  1175. 'size' => 12
  1176. ),
  1177. 'borders' => array(
  1178. 'top' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1179. 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1180. 'left' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1181. 'right' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE)
  1182. ),
  1183. 'alignment' => array(
  1184. 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
  1185. 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
  1186. 'wrap' => true
  1187. )
  1188. ),
  1189. 'A1:'.$total_excelColumns.'1'
  1190. );
  1191. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  1192. // Add some data
  1193. $objPHPExcel->setActiveSheetIndex(0)
  1194. ->setCellValue('A1', 'Name')
  1195. ->setCellValue('B1', 'City')
  1196. ->setCellValue('C1', 'Email')
  1197. ->setCellValue('D1', 'Mobile')
  1198. ->setCellValue('E1', 'Suminsured')
  1199. ->setCellValue('F1', 'Age')
  1200. ->setCellValue('G1', 'No. Of Members')
  1201. ->setCellValue('H1', 'Date on submit')
  1202. ->setCellValue('I1', 'Lead Source');
  1203. // Miscellaneous glyphs, UTF-8
  1204. $objPHPExcel->setActiveSheetIndex(0)
  1205. ->setCellValue('A2', 'Lead Name')
  1206. ->setCellValue('B2', 'city')
  1207. ->setCellValue('C2', 'test@yesk.com')
  1208. ->setCellValue('D2', '9999999999')
  1209. ->setCellValue('E2', '56')
  1210. ->setCellValue('F2', '23')
  1211. ->setCellValue('G2', 'test')
  1212. ->setCellValue('H2', '07-Sep-2013')
  1213. ->setCellValue('I2', 'test');
  1214. //To create new sheet in current file
  1215. /*$objPHPExcel->createSheet(1);
  1216. $objPHPExcel->setActiveSheetIndex(1);
  1217. $objPHPExcel->getActiveSheet()->setTitle('Title');
  1218. */
  1219. // Redirect output to a clientÂ’s web browser (Excel5)
  1220. header('Content-Type: application/vnd.ms-excel');
  1221. header('Content-Disposition: attachment;filename="LeadTemplates.xls"');
  1222. header('Cache-Control: max-age=0');
  1223. // If you're serving to IE 9, then the following may be needed
  1224. header('Cache-Control: max-age=1');
  1225. // If you're serving to IE over SSL, then the following may be needed
  1226. header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  1227. header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
  1228. header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  1229. header ('Pragma: public'); // HTTP/1.0
  1230. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  1231. $objWriter->save('php://output');
  1232. Yii::app()->end();
  1233. }
  1234. public function actionImportLeadTemplate(){
  1235. $model=new lead();
  1236. $data='';
  1237. $final_arr=@$_POST['final_arr']?@$_POST['final_arr']:'';
  1238. if(isset($_POST['ImportLeads']) && empty($final_arr) && !empty($_FILES['Lead']['name']['import'])){
  1239. Yii::import('ext.phpexcelreader.JPhpExcelReader');
  1240. $model->attributes='import';
  1241. $model->import=CUploadedFile::getInstance($model,'import');
  1242. $prefix=substr(time(),0,5);
  1243. $folder = '/tempdata';
  1244. $model->import->saveAs($folder.$prefix.$model->import);
  1245. $data=new JPhpExcelReader($folder.$prefix.$model->import);
  1246. //$this->render('bulk_import_lead',array('data'=>$data,'model'=>$model));
  1247. //$this->redirect(Yii::app()->createUrl('leads/bulk_import_leads'),array('data'=>$data,'model'=>$model));
  1248. $this->render('bulk_import_lead',array('data'=>$data,'model'=>$model));
  1249. }
  1250. if(isset($_POST['ImportLeads']) && !empty($final_arr) && isset($final_arr) && empty($_FILES['Lead']['name']['import'])){
  1251. $final_arr = unserialize(urldecode($_POST["final_arr"]));
  1252. $dateTime=time();
  1253. /*echo '<pre>';
  1254. print_r($final_arr);*/
  1255. for($i=0;$i<sizeof($final_arr);$i++)
  1256. {
  1257. $leadStatusId = '0';
  1258. $duplicateLeadId = '0';
  1259. $currentAllocatedId = '0';
  1260. $junkNumberQuery = Yii::app()->db->createCommand("SELECT `junkLeadNumberId` FROM `junkLeadNumberMaster` WHERE `junkLeadNumber` = '".@$final_arr[$i]['mobile']."' ")->queryAll();
  1261. $junkNumberResult = $junkNumberQuery;
  1262. $fetchAgentDetails=LeadSourceMaster::model()->findByPk($final_arr[$i]['leadSourceId']);
  1263. //$duplicateQuery = Yii::app()->db->createCommand("SELECT `leadId` FROM `lead` WHERE `mobile`= '".@$final_arr[$i]['mobile']."' ")->queryAll();(Original, changed below by Baljeet)
  1264. $duplicateQuery = Yii::app()->db->createCommand("SELECT `leadId`,`currentAllocatedId` FROM `lead` WHERE `mobile`= '".@$final_arr[$i]['mobile']."' order by leadId ASC LIMIT 1")->queryAll();
  1265. $duplicateResult = ($duplicateQuery);
  1266. //echo '<br>duplicateResult----------'.count($duplicateResult);
  1267. if(count($junkNumberResult) > 0){
  1268. $leadStatusId = '36';
  1269. $duplicateLeadId = '';
  1270. $currentAllocatedId = '';
  1271. } elseif(count($duplicateResult)>0){
  1272. $leadStatusId = '10';
  1273. $duplicateLeadId = @$duplicateResult[0]['leadId'];
  1274. $currentAllocatedId = @$duplicateResult[0]['currentAllocatedId']; //added by baljeet
  1275. } else {
  1276. $leadStatusId = '34';
  1277. $duplicateLeadId = '';
  1278. $currentAllocatedId = '';
  1279. }
  1280. /*echo '<br>leadStatusId---'.$leadStatusId;
  1281. echo '<br>duplicateLeadId---'.$duplicateLeadId;
  1282. echo '<br>currentAllocatedId---'.$currentAllocatedId;*/
  1283. $model=new lead();
  1284. $model->name=$final_arr[$i]['name'];
  1285. $model->cityId=$final_arr[$i]['cityId'];
  1286. $model->email=$final_arr[$i]['email'];
  1287. $model->mobile=$final_arr[$i]['mobile'];
  1288. $model->si=$final_arr[$i]['suminsured'];
  1289. $model->age=$final_arr[$i]['age'];
  1290. $model->members=$final_arr[$i]['noofmembers'];
  1291. $model->dateonSubmit=$final_arr[$i]['dateonsubmit'];
  1292. $model->leadSourceId=$final_arr[$i]['leadSourceId'];
  1293. $model->leadStatusId=$leadStatusId;
  1294. $model->duplicateLeadId=@$duplicateLeadId;
  1295. $model->currentAllocatedId=@$currentAllocatedId;
  1296. $model->productId='1';
  1297. $model->status='Active';
  1298. $model->createdOn=$dateTime;
  1299. $model->createdBy=Yii::app()->session->get('id');
  1300. $model->updatedOn=$dateTime;
  1301. $model->updatedBy=Yii::app()->session->get('id');
  1302. $model->isBulkImport='YES';
  1303. $model->agentId = @$fetchAgentDetails->leadSourceCode;
  1304. $model->ws_agentid = @$fetchAgentDetails->leadSourceCode;
  1305. $model->isNewRecord = true;
  1306. $model->save(false);
  1307. }
  1308. $this->redirect(array('leads/lead_list'));
  1309. }
  1310. if(isset($_POST['ImportLeads']) && empty($final_arr) && empty($_FILES['Lead']['name']['import'])){
  1311. $model->validate();
  1312. $this->render('bulk_import_lead',array('model'=>$model));
  1313. }
  1314. }
  1315. public function actionleadSearch()
  1316. {
  1317. $searched = new Lead();
  1318. if(@$_REQUEST['lead']['leadSearchBox']=='' && @$_REQUEST['mob']=='') {
  1319. $this->redirect(array('leads/lead_list'));
  1320. } else {
  1321. $this->render('lead_search',array('searched'=>@$searched));
  1322. }
  1323. }
  1324. public function actionExportExcel()
  1325. {
  1326. // It calls the actionCreateExcel to generates excel reports'
  1327. $this->actionCreateExcel();
  1328. }
  1329. public function actionCreateExcel(){
  1330. //Here is the code to set conditions for fetch records from database
  1331. $criteria = new CDbCriteria;
  1332. $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`';
  1333. $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)';
  1334. $criteria->condition='t.status != "Allocated" AND t.leadStatusId != "25" AND t.leadStatusId != "26" ';
  1335. $criteria->order='leadId DESC';
  1336. $model=new LeadReport();
  1337. $model->scenario = 'LeadReport';
  1338. $reportmodel=LeadReport::model()->findAll($criteria);
  1339. $data=array();
  1340. $datas = $reportmodel;
  1341. foreach($datas as $key=>$value){
  1342. $data[$key]=$value;
  1343. }
  1344. if(count($data)>0){
  1345. Yii::import('ext.phpexcel.XPHPExcel');
  1346. $objPHPExcel= XPHPExcel::createPHPExcel();
  1347. $objPHPExcel->getProperties()->setCreator("ReligareLMS")
  1348. ->setLastModifiedBy("ReligareLMS")
  1349. ->setTitle("Office 2007 XLSX Test Document")
  1350. ->setSubject("Office 2007 XLSX Test Document")
  1351. ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
  1352. ->setKeywords("office 2007 openxml php")
  1353. ->setCategory("Test result file");
  1354. $total_excelColumns=$this->getNameFromNumber(8);
  1355. // Rename worksheet
  1356. $objPHPExcel->getActiveSheet()->setTitle('Sample Excel');
  1357. $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);
  1358. $objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
  1359. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(6);
  1360. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
  1361. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
  1362. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
  1363. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(30);
  1364. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(30);
  1365. $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
  1366. $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
  1367. $objPHPExcel->getActiveSheet()->duplicateStyleArray(
  1368. array(
  1369. 'font' => array(
  1370. 'name' => 'Times New Roman',
  1371. 'bold' => true,
  1372. 'italic' => false,
  1373. 'size' => 12
  1374. ),
  1375. 'borders' => array(
  1376. 'top' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1377. 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1378. 'left' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1379. 'right' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE)
  1380. ),
  1381. 'alignment' => array(
  1382. 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
  1383. 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
  1384. 'wrap' => true
  1385. )
  1386. ),
  1387. 'A1:'.$total_excelColumns.'1'
  1388. );
  1389. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  1390. // Add some data
  1391. $objPHPExcel->setActiveSheetIndex(0)
  1392. ->setCellValue('A1', 'SNO.')
  1393. ->setCellValue('B1', 'Name')
  1394. ->setCellValue('C1', 'Mobile')
  1395. ->setCellValue('D1', 'Email')
  1396. ->setCellValue('E1', 'Lead Stage')
  1397. ->setCellValue('F1', 'Date and Time')
  1398. ->setCellValue('G1', 'UTM Code')
  1399. ->setCellValue('H1', 'status');
  1400. // Miscellaneous glyphs, UTF-8
  1401. $i=0;
  1402. $k=2;
  1403. $sn=1;
  1404. while($i<count($data)){
  1405. $objPHPExcel->setActiveSheetIndex(0)
  1406. ->setCellValue('A'.$k,$sn)
  1407. ->setCellValue('B'.$k,$data[$i]['name'])
  1408. ->setCellValue('C'.$k,$data[$i]['mobile'])
  1409. ->setCellValue('D'.$k,$data[$i]['email'])
  1410. ->setCellValue('E'.$k,$data[$i]['leadStage'])
  1411. ->setCellValue('F'.$k,date("d/m/y h:i A",$data[$i]['createdOn']))
  1412. ->setCellValue('G'.$k,$data[$i]['leadSourceCode'])
  1413. ->setCellValue('H'.$k,$data[$i]['status']);
  1414. $i++;$k++;$sn++;}
  1415. // Redirect output to a clientÂ’s web browser (Excel5)
  1416. header('Content-Type: application/vnd.ms-excel');
  1417. header('Content-Disposition: attachment;filename="lead_report.xls"');
  1418. header('Cache-Control: max-age=0');
  1419. // If you're serving to IE 9, then the following may be needed
  1420. header('Cache-Control: max-age=1');
  1421. // If you're serving to IE over SSL, then the following may be needed
  1422. header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
  1423. header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  1424. header ('Pragma: public'); // HTTP/1.0
  1425. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  1426. $objWriter->save('php://output');
  1427. Yii::app()->end();
  1428. }
  1429. else{
  1430. $model = new Lead();
  1431. $model = Lead::model()->findAll("status = 'Active'");
  1432. $this->render('lead_list',array('model'=>$model));
  1433. }
  1434. }
  1435. public function actiongetSourceResults(){
  1436. $models=new Lead();
  1437. $type=@$_REQUEST['type'];
  1438. $searchTxt=@$_REQUEST['searchTxt'];
  1439. if(isset($searchTxt) && !empty($searchTxt)){
  1440. $this->renderPartial('searchSourceLeads',array('searchTxt'=>$searchTxt,'type'=>@$type));
  1441. } else {
  1442. if($type=='fresh'){
  1443. $functs="fresh_leads";
  1444. }
  1445. if($type=='new'){
  1446. $functs="lead_list";
  1447. }
  1448. if($type=='duplicate'){
  1449. $functs="duplicate_lead_list";
  1450. }
  1451. if($type=='junk'){
  1452. $functs="junk_lead_list";
  1453. }
  1454. if($type=='allocated'){
  1455. $functs="allocated_lead_list";
  1456. }
  1457. if($type=='cip'){
  1458. $functs="cip_lead_list";
  1459. }
  1460. if($type=='plc'){
  1461. $functs="plc_lead_list";
  1462. }
  1463. if($type=='closed'){
  1464. $functs="close_lead_list";
  1465. }
  1466. if($type==''){
  1467. $functs="lead_list";
  1468. }
  1469. echo Yii::app()->createUrl('leads/'.@$functs);
  1470. exit;
  1471. }
  1472. }
  1473. public function actionAutocompleteSearch(){
  1474. $models=new Lead();
  1475. $term=@$_REQUEST['term'];
  1476. $type=@$_REQUEST['type'];
  1477. if($type=="fresh"){
  1478. $models=Lead::model()->findAll(array("condition"=>"leadStatusId = '34' AND currentAllocatedId<1 and concat(name,mobile,email) like '%$term%'","order"=>"leadId desc"));
  1479. }
  1480. if($type=="new"){
  1481. $relationManager = $_SESSION['relationalManager'];
  1482. $managerMemberId = implode(",",array_unique(@$relationManager));
  1483. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1484. $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead='no' ";
  1485. } else {
  1486. $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead='no' AND currentAllocatedId IN (".@$managerMemberId.") ";
  1487. }
  1488. $models = Lead::model()->findAll(" $querycondition and concat(name,mobile,email) like '%$term%'");
  1489. //$models=Lead::model()->findAll(array("condition"=>"leadStatusId = '34' AND currentAllocatedId<1 and name like '%$term%'","order"=>"leadId desc"));
  1490. }
  1491. if($type=="duplicate"){
  1492. $models=Lead::model()->findAll(array("condition"=>"leadStatusId = '10' and concat(name,mobile,email) like '%$term%'","order"=>"leadId desc"));
  1493. }
  1494. if($type=="dupforday"){
  1495. $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
  1496. $models=Lead::model()->findAll(array("condition"=>"leadStatusId = '10' AND createdOn > '".@$today12PM."' and concat(name,mobile,email) like '%$term%'","order"=>"leadId desc"));
  1497. }
  1498. if($type=="junk"){
  1499. $models=Lead::model()->findAll(array("condition"=>"leadStatusId = '36' and concat(name,mobile,email) like '%$term%'","order"=>"leadId desc"));
  1500. }
  1501. if($type=="allocated"){
  1502. $relationManager = $_SESSION['relationalManager'];
  1503. $managerMemberId = implode(",",array_unique(@$relationManager));
  1504. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1505. $querycondition = " currentAllocatedId>0 AND isRead = 'yes'";
  1506. } else {
  1507. $querycondition = " currentAllocatedId>0 AND isRead = 'yes' AND currentAllocatedId IN (".@$managerMemberId.") ";
  1508. }
  1509. $models = Lead::model()->findAll(" $querycondition and concat(name,mobile,email) like '%$term%'");
  1510. }
  1511. if($type=="followup"){
  1512. $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
  1513. $relationManager = $_SESSION['relationalManager'];
  1514. $managerMemberId = implode(",",array_unique(@$relationManager));
  1515. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1516. $querycondition = ' startDate = "'.@$today12PM.'" and status="Pending" ';
  1517. } else {
  1518. $querycondition = " startDate = '".@$starttimestamp."' AND status = 'Pending' AND userId IN (".@$managerMemberId.") ";
  1519. }
  1520. $models = LeadFollowup::model()->findAll(" $querycondition and description like '%$term%'");
  1521. }
  1522. if($type=="allfollowup"){
  1523. $relationManager = $_SESSION['relationalManager'];
  1524. $managerMemberId = implode(",",array_unique(@$relationManager));
  1525. $currentDate=date('d-m-Y',time());
  1526. $starttimestamp=strtotime($currentDate);
  1527. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1528. $querycondition = ' status="Pending" ';
  1529. } else {
  1530. $querycondition = " status = 'Pending' AND userId IN (".@$managerMemberId.") ";
  1531. }
  1532. $models = LeadFollowup::model()->findAll(" $querycondition and description like '%$term%'");
  1533. }
  1534. if($type=="closed"){
  1535. $relationManager = $_SESSION['relationalManager'];
  1536. $managerMemberId = implode(",",array_unique(@$relationManager));
  1537. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1538. $querycondition = "leadStatusId = '7'";
  1539. } else {
  1540. $querycondition = " leadStatusId = '7' AND currentAllocatedId IN (".@$managerMemberId.") ";
  1541. }
  1542. $models = Lead::model()->with("leadSourceDetails")->findAll(" $querycondition and concat(name,mobile,email) like '%$term%' ");
  1543. }
  1544. if($type=="cip"){
  1545. $contactInProgList=Yii::app()->db->createCommand("select leadStatus.leadStatus,leadStatusId from leadStatus where parentId=3")->queryAll();
  1546. $CIPids = array();
  1547. if(count($contactInProgList) > 0){
  1548. for($w=0;$w<count($contactInProgList);$w++){
  1549. @$CIPids[] = @$contactInProgList[$w]['leadStatusId'];
  1550. }
  1551. } else {
  1552. @$CIPids[] = '';
  1553. }
  1554. @$CIPids = implode(",",@$CIPids);
  1555. $relationManager = $_SESSION['relationalManager'];
  1556. $managerMemberId = implode(",",array_unique(@$relationManager));
  1557. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1558. $querycondition = " leadStatusId IN ( ".@$CIPids." ) ";
  1559. } else {
  1560. $querycondition = " leadStatusId IN ( ".@$CIPids." ) AND currentAllocatedId IN (".@$managerMemberId.") ";
  1561. }
  1562. $models = Lead::model()->findAll(" $querycondition and concat(name,mobile,email) like '%$term%'");
  1563. }
  1564. if($type=="plc"){
  1565. $contactInProgList=Yii::app()->db->createCommand("select leadStatus.leadStatus,leadStatusId from leadStatus where parentId=41")->queryAll();
  1566. $CIPids = array();
  1567. if(count($contactInProgList) > 0){
  1568. for($w=0;$w<count($contactInProgList);$w++){
  1569. @$CIPids[] = @$contactInProgList[$w]['leadStatusId'];
  1570. }
  1571. } else {
  1572. @$CIPids[] = '';
  1573. }
  1574. @$CIPids = implode(",",@$CIPids);
  1575. $relationManager = $_SESSION['relationalManager'];
  1576. $managerMemberId = implode(",",array_unique(@$relationManager));
  1577. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1578. $querycondition = " leadStatusId IN ( ".@$CIPids." ) ";
  1579. } else {
  1580. $querycondition = " leadStatusId IN ( ".@$CIPids." ) AND currentAllocatedId IN (".@$managerMemberId.") ";
  1581. }
  1582. $models = Lead::model()->findAll(" $querycondition and concat(name,mobile,email) like '%$term%'");
  1583. }
  1584. if($type=="cld"){
  1585. $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
  1586. $relationManager = $_SESSION['relationalManager'];
  1587. $managerMemberId = implode(",",array_unique(@$relationManager));
  1588. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1589. $querycondition = 'leadStatusId = 12 AND startDate = "'.@$today12PM.'" ';
  1590. } else {
  1591. $querycondition = "leadStatusId = 12 AND startDate = '".@$today12PM."' AND userId IN (".@$managerMemberId.") ";
  1592. }
  1593. $models = LeadFollowup::model()->findAll(" $querycondition and description like '%$term%'");
  1594. }
  1595. if($type=="followup" or $type=="allfollowup" or $type=="cld"){
  1596. $arr = array();
  1597. foreach($models as $model) {
  1598. $arr[] = array(
  1599. 'label'=>substr($model->description,0,10), // label for dropdown list
  1600. 'value'=>substr($model->description,0,10), // value for input field
  1601. 'id'=>$model->leadFollowupId, // return value from autocomplete
  1602. );
  1603. }
  1604. if(count($models) > 0){
  1605. $arr['totalRecords'] = array(
  1606. 'totalRecords'=>count($models), // return value from autocomplete
  1607. );
  1608. }
  1609. }else {
  1610. $arr = array();
  1611. foreach($models as $model) {
  1612. $arr[] = array(
  1613. 'label'=>$model->mobile?$model->mobile.($model->name?'/'.$model->name:'').($model->email?'/'.$model->email:''):'', // label for dropdown list
  1614. 'value'=>$model->mobile?$model->mobile:$model->name, // value for input field
  1615. 'id'=>$model->leadId, // return value from autocomplete
  1616. );
  1617. }
  1618. if(count($models) > 0){
  1619. $arr['totalRecords'] = array(
  1620. 'totalRecords'=>count($models), // return value from autocomplete
  1621. );
  1622. }
  1623. }
  1624. echo CJSON::encode($arr);
  1625. Yii::app()->end();
  1626. //$this->renderPartial('searchLeads');
  1627. }
  1628. public function actionAutocompleteSearchSource(){
  1629. $models=new Lead();
  1630. $term=@$_REQUEST['term'];
  1631. $type=@$_REQUEST['type'];
  1632. if($type=="fresh"){
  1633. $models=Lead::model()->with("leadSourceDetails")->findAll(array("condition"=>"leadStatusId = '34' AND currentAllocatedId<1 and concat(leadSourceTitle) like '%$term%'","order"=>"leadId desc"));
  1634. }
  1635. if($type=="new"){
  1636. $relationManager = $_SESSION['relationalManager'];
  1637. $managerMemberId = implode(",",array_unique(@$relationManager));
  1638. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1639. $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead='no' ";
  1640. } else {
  1641. $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead='no' AND currentAllocatedId IN (".@$managerMemberId.") ";
  1642. }
  1643. $models = Lead::model()->with("leadSourceDetails")->findAll(" $querycondition and leadSourceTitle like '%$term%'");
  1644. //$models=Lead::model()->findAll(array("condition"=>"leadStatusId = '34' AND currentAllocatedId<1 and name like '%$term%'","order"=>"leadId desc"));
  1645. }
  1646. if($type=="duplicate"){
  1647. $models=Lead::model()->with("leadSourceDetails")->findAll(array("condition"=>"leadStatusId = '10' and leadSourceTitle like '%$term%'","order"=>"leadId desc"));
  1648. }
  1649. if($type=="junk"){
  1650. $models=Lead::model()->with("leadSourceDetails")->findAll(array("condition"=>"leadStatusId = '36' and leadSourceTitle like '%$term%'","order"=>"leadId desc"));
  1651. }
  1652. if($type=="allocated"){
  1653. $relationManager = $_SESSION['relationalManager'];
  1654. $managerMemberId = implode(",",array_unique(@$relationManager));
  1655. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1656. $querycondition = " currentAllocatedId>0 AND isRead = 'yes'";
  1657. } else {
  1658. $querycondition = " currentAllocatedId>0 AND isRead = 'yes' AND currentAllocatedId IN (".@$managerMemberId.") ";
  1659. }
  1660. $models = Lead::model()->with("leadSourceDetails")->findAll(" $querycondition and leadSourceTitle like '%$term%'");
  1661. }
  1662. if($type=="followup"){
  1663. $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
  1664. $relationManager = $_SESSION['relationalManager'];
  1665. $managerMemberId = implode(",",array_unique(@$relationManager));
  1666. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1667. $querycondition = ' startDate = "'.@$today12PM.'" and status="Pending" ';
  1668. } else {
  1669. $querycondition = " startDate = '".@$starttimestamp."' AND status = 'Pending' AND userId IN (".@$managerMemberId.") ";
  1670. }
  1671. $models = LeadFollowup::model()->findAll(" $querycondition and description leadSourceTitle '%$term%'");
  1672. }
  1673. if($type=="closed"){
  1674. $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
  1675. $relationManager = $_SESSION['relationalManager'];
  1676. $managerMemberId = implode(",",array_unique(@$relationManager));
  1677. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1678. $querycondition = "leadStatusId = '7'";
  1679. } else {
  1680. $querycondition = " leadStatusId = '7' AND currentAllocatedId IN (".@$managerMemberId.") ";
  1681. }
  1682. $models = Lead::model()->with("leadSourceDetails")->findAll(" $querycondition and leadSourceTitle like '%$term%' ");
  1683. }
  1684. if($type=="followup"){
  1685. $arr = array();
  1686. foreach($models as $model) {
  1687. $arr[] = array(
  1688. 'label'=>substr($model->description,0,10), // label for dropdown list
  1689. 'value'=>substr($model->description,0,10), // value for input field
  1690. 'id'=>$model->leadFollowupId, // return value from autocomplete
  1691. );
  1692. }
  1693. if(count($models) > 0){
  1694. $arr['totalRecords'] = array(
  1695. 'totalRecords'=>count($models), // return value from autocomplete
  1696. );
  1697. }
  1698. }else {
  1699. $arr = array();
  1700. foreach($models as $model) {
  1701. $arr[] = array(
  1702. 'label'=>$model->mobile?$model->mobile:$model->name, // label for dropdown list
  1703. 'value'=>$model->mobile?$model->mobile:$model->name, // value for input field
  1704. 'id'=>$model->leadId, // return value from autocomplete
  1705. );
  1706. }
  1707. if(count($models) > 0){
  1708. $arr['totalRecords'] = array(
  1709. 'totalRecords'=>count($models), // return value from autocomplete
  1710. );
  1711. }
  1712. }
  1713. echo CJSON::encode($arr);
  1714. Yii::app()->end();
  1715. //$this->renderPartial('searchLeads');
  1716. }
  1717. public function actionAutocompleteSearchRes(){
  1718. $models=new Lead();
  1719. $term=@$_REQUEST['id'];
  1720. $type=@$_REQUEST['type'];
  1721. $models=Lead::model()->findAll(array("condition"=>"leadStatusId = '34' AND currentAllocatedId<1 and name like '%$term%'","order"=>"leadId desc"));
  1722. $arr = array();
  1723. $this->renderPartial('searchLeads',array('name'=>$term));
  1724. }
  1725. public function actionexportArchiveList(){
  1726. $Leadname = @$_REQUEST['name'];
  1727. $Leadstatus = @$_REQUEST['status'];
  1728. $leadStage = @$_REQUEST['statge'];
  1729. $cond ='';
  1730. if(isset($Leadname) && !empty($Leadname)){
  1731. $cond .=" AND name like '%".@$Leadname."%'";
  1732. }
  1733. if(isset($Leadstatus) && !empty($Leadstatus)){
  1734. $cond .=" AND leadStatusId = '".@$Leadstatus."'";
  1735. }
  1736. if(isset($leadStage) && !empty($leadStage)){
  1737. $cond .=" AND leadStageId = '".@$leadStage."'";
  1738. }
  1739. $dataProvider = new CActiveDataProvider('Lead', array('criteria'=>array(
  1740. 'condition'=>' FROM_UNIXTIME(updatedOn) >= DATE_SUB(CURDATE(), INTERVAL 120 DAY) '.@$cond.' and leadStatusId NOT IN (12,8,1,4) ',
  1741. 'order'=>'',
  1742. )));
  1743. $iterator = new CDataProviderIterator($dataProvider);
  1744. $data=array();
  1745. $datas = $iterator;
  1746. foreach($datas as $key=>$value){
  1747. $data[$key]=$value;
  1748. }
  1749. Yii::import('ext.phpexcel.XPHPExcel');
  1750. $objPHPExcel= XPHPExcel::createPHPExcel();
  1751. $objPHPExcel->getProperties()->setCreator("ReligareLMS")
  1752. ->setLastModifiedBy("ReligareLMS")
  1753. ->setTitle("Office 2007 XLSX Leads Document")
  1754. ->setSubject("Office 2007 XLSX Leads Document")
  1755. ->setDescription("Archive Leads.")
  1756. ->setKeywords("Archive Leads")
  1757. ->setCategory("Archive Leads");
  1758. // Rename worksheet
  1759. $objPHPExcel->getActiveSheet()->setTitle('Sample Excel');
  1760. $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);
  1761. $objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
  1762. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(6);
  1763. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
  1764. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
  1765. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
  1766. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(30);
  1767. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(30);
  1768. $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
  1769. $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
  1770. $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(30);
  1771. $objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(30);
  1772. $objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(30);
  1773. $objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(30);
  1774. $objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(30);
  1775. $objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(30);
  1776. $objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth(30);
  1777. $objPHPExcel->getActiveSheet()->getColumnDimension('P')->setWidth(30);
  1778. $objPHPExcel->getActiveSheet()->getColumnDimension('Q')->setWidth(30);
  1779. $objPHPExcel->getActiveSheet()->getColumnDimension('R')->setWidth(30);
  1780. $objPHPExcel->getActiveSheet()->getColumnDimension('S')->setWidth(30);
  1781. $objPHPExcel->getActiveSheet()->getColumnDimension('T')->setWidth(30);
  1782. $objPHPExcel->getActiveSheet()->getColumnDimension('U')->setWidth(30);
  1783. $objPHPExcel->getActiveSheet()->getColumnDimension('V')->setWidth(30);
  1784. $objPHPExcel->getActiveSheet()->getColumnDimension('W')->setWidth(30);
  1785. $objPHPExcel->getActiveSheet()->getColumnDimension('X')->setWidth(30);
  1786. $objPHPExcel->getActiveSheet()->getColumnDimension('y')->setWidth(30);
  1787. $objPHPExcel->getActiveSheet()->duplicateStyleArray(
  1788. array(
  1789. 'font' => array(
  1790. 'name' => 'Times New Roman',
  1791. 'bold' => true,
  1792. 'italic' => false,
  1793. 'size' => 12
  1794. ),
  1795. 'borders' => array(
  1796. 'top' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1797. 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1798. 'left' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1799. 'right' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE)
  1800. ),
  1801. 'alignment' => array(
  1802. 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
  1803. 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
  1804. 'wrap' => true
  1805. )
  1806. ),
  1807. 'A1:Y1'
  1808. );
  1809. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  1810. // Add some data
  1811. $objPHPExcel->setActiveSheetIndex(0)
  1812. ->setCellValue('A1', 'SNO.')
  1813. ->setCellValue('B1', 'Name')
  1814. ->setCellValue('C1', 'Mobile Number')
  1815. ->setCellValue('D1', 'Email Id')
  1816. ->setCellValue('E1', 'Address')
  1817. ->setCellValue('F1', 'City')
  1818. ->setCellValue('G1', 'State')
  1819. ->setCellValue('H1', 'Members')
  1820. ->setCellValue('I1', 'Premium')
  1821. ->setCellValue('J1', 'Product Details')
  1822. ->setCellValue('K1', 'Lead Status')
  1823. ->setCellValue('L1', 'Status')
  1824. ->setCellValue('M1', 'isJunk')
  1825. ->setCellValue('N1', 'Lead Source')
  1826. ->setCellValue('O1', 'Lead Stage')
  1827. ->setCellValue('P1', 'Lead Description')
  1828. ->setCellValue('Q1', 'Activity Description')
  1829. ->setCellValue('R1', 'Customer Type')
  1830. ->setCellValue('S1', 'Product Name')
  1831. ->setCellValue('T1', 'Policy Type')
  1832. ->setCellValue('U1', 'Plan Type')
  1833. ->setCellValue('V1', 'Campaign Name')
  1834. ->setCellValue('W1', 'UTM Code')
  1835. ->setCellValue('X1', 'Owner')
  1836. ->setCellValue('Y1', 'Last Modified Date');
  1837. // Miscellaneous glyphs, UTF-8
  1838. $i=0;
  1839. $k=2;
  1840. $sn=1;
  1841. while($i<count($data)){
  1842. $str = preg_replace('/\s\s+/', ' ', $data[$i]['address']);
  1843. if($data[$i]['currentAllocatedId']==$data[$i]['createdBy']){
  1844. $owner = $data[$i]['ownerDetails']['firstName']." ".$data[$i]['ownerDetails']['lastName']."(C)";
  1845. } else {
  1846. if(isset($data[$i]['ownerDetails']['firstName']) && !empty($data[$i]['ownerDetails']['firstName'])){
  1847. $owner = $data[$i]['ownerDetails']['firstName']." ".$data[$i]['ownerDetails']['lastName'];
  1848. } else {
  1849. $owner = "NA";
  1850. }
  1851. }
  1852. $descrecords=Yii::app()->db->createCommand("select leadDescription from lead where leadId='".@$data[$i]['leadId']."' ")->queryAll();
  1853. $records=Yii::app()->db->createCommand("select description from leadFollowup where leadId='".@$data[$i]['leadId']."' ")->queryAll();
  1854. $ActivityRes = '';
  1855. for($j=0;$j<count($records);$j++){
  1856. @$ActivityRes .= @$records[0]['description'].",";
  1857. }
  1858. $lastModifieddate = date("d M Y H:i:s A",$data[$i]['updatedOn']);
  1859. //ReportsController::getLeadDescription(@$data->leadId);
  1860. //$data[$i]['ownerDetails']['firstName'];
  1861. $objPHPExcel->setActiveSheetIndex(0)
  1862. ->setCellValue('A'.$k,$sn)
  1863. ->setCellValue('B'.$k,$data[$i]['name'])
  1864. ->setCellValue('C'.$k,$data[$i]['mobile'])
  1865. ->setCellValue('D'.$k,$data[$i]['email'])
  1866. ->setCellValue('E'.$k,$str)
  1867. ->setCellValue('F'.$k,$data[$i]['city'])
  1868. ->setCellValue('G'.$k,$data[$i]['state'])
  1869. ->setCellValue('H'.$k,$data[$i]['members'])
  1870. ->setCellValue('I'.$k,$data[$i]['premium'])
  1871. ->setCellValue('J'.$k,$data[$i]['productDetails'])
  1872. ->setCellValue('K'.$k,$data[$i]['leadStatusDetails']['leadStatus'])
  1873. ->setCellValue('L'.$k,$data[$i]['status'])
  1874. ->setCellValue('M'.$k,$data[$i]['isJunk'])
  1875. ->setCellValue('N'.$k,$data[$i]['leadSourceTitle'])
  1876. ->setCellValue('O'.$k,$data[$i]['leadStage'])
  1877. ->setCellValue('P'.$k,@$descrecords[0]['leadDescription'])
  1878. ->setCellValue('Q'.$k,@$ActivityRes)
  1879. ->setCellValue('R'.$k,$data[$i]['customerType'])
  1880. ->setCellValue('S'.$k,$data[$i]['productName'])
  1881. ->setCellValue('T'.$k,$data[$i]['policyType'])
  1882. ->setCellValue('U'.$k,$data[$i]['planType'])
  1883. ->setCellValue('V'.$k,$data[$i]['campaignName'])
  1884. ->setCellValue('W'.$k,$data[$i]['leadSourceCode'])
  1885. ->setCellValue('X'.$k,$owner)
  1886. ->setCellValue('Y'.$k,$lastModifieddate);
  1887. $i++;$k++;$sn++;}
  1888. // Redirect output to a clientÂ’s web browser (Excel5)
  1889. header('Content-Type: application/vnd.ms-excel');
  1890. header('Content-Disposition: attachment;filename="lead_report.xls"');
  1891. header('Cache-Control: max-age=0');
  1892. // If you're serving to IE 9, then the following may be needed
  1893. header('Cache-Control: max-age=1');
  1894. // If you're serving to IE over SSL, then the following may be needed
  1895. header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
  1896. header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  1897. header ('Pragma: public'); // HTTP/1.0
  1898. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  1899. $objWriter->save('php://output');
  1900. Yii::app()->end();
  1901. }
  1902. public function actiongetCityList()
  1903. {
  1904. $data=City::model()->findAll(array('condition'=>'stateId=:stateId and status=:status','params'=>array(':stateId'=>(int) $_POST['stateId'],'status'=>'Active')));
  1905. $data=CHtml::listData($data,'cityId','city');
  1906. echo '<select class="styled" name="Lead[cityId]" style="position: absolute; opacity: 0; font-size: 12px; height: 25px;" onchange="changeText();">';
  1907. echo '<option value="" selected="selected">Select City</option>';
  1908. foreach($data as $value=>$name)
  1909. {
  1910. echo CHtml::tag('option',array('value'=>$value),CHtml::encode($name));
  1911. }
  1912. echo '</select>';
  1913. echo '<span id="changeText" class="customStyleSelectBox" style="display: block;width:97px;"><span class="customStyleSelectBoxInner" style="width: 81px; display: block;">Select City</span></span>';
  1914. }
  1915. public function actiongetLeadStatus()
  1916. {
  1917. if(isset($_POST['parentId']) && !empty($_POST['parentId'])){
  1918. $data=LeadStatus::model()->findAll(array('condition'=>'parentId=:parentId and status=:status','params'=>array(':parentId'=>(int) @$_POST['parentId'],'status'=>'Active')));
  1919. $data=CHtml::listData($data,'leadStatusId','leadStatus');
  1920. echo '<select class="styled" name="Lead[leadStatusId]" style="position: absolute; opacity: 0; font-size: 12px; height: 25px;" id="leadprimarystatus" onchange="changeStatusText();getActionRes(this.value);">';
  1921. echo '<option value="" selected="selected">Select lead Status</option>';
  1922. foreach($data as $value=>$name)
  1923. {
  1924. echo CHtml::tag('option',array('value'=>$value),CHtml::encode($name));
  1925. }
  1926. echo '</select>';
  1927. } else {
  1928. echo '<select class="styled" name="Lead[leadStatusId]" style="position: absolute; opacity: 0; font-size: 12px; height: 25px;" id="leadprimarystatus" onchange="changeStatusText();getActionRes(this.value);">';
  1929. echo '<option value="" selected="selected">Select lead Status</option>';
  1930. echo '</select>';
  1931. }
  1932. 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>';
  1933. }
  1934. public function actionexportLeads(){
  1935. $model=new Lead();
  1936. $type=@$_REQUEST['type'];
  1937. $relationManager = @$_SESSION['relationalManager'];
  1938. $managerMemberId = implode(",",array_unique(@$relationManager));
  1939. $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
  1940. if($type=="freshLeads"){
  1941. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1942. $querycondition = " leadStatusId = '34' AND currentAllocatedId<1";
  1943. } else {
  1944. $querycondition = " leadStatusId = '34' AND currentAllocatedId<1";
  1945. }
  1946. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  1947. 'condition'=>@$querycondition,
  1948. 'order'=>'leadId DESC',
  1949. ),
  1950. 'pagination'=>false,
  1951. ));
  1952. }
  1953. if($type=="newLeads"){
  1954. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1955. $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead = 'no' ";
  1956. } else {
  1957. $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead = 'no' AND currentAllocatedId IN (".@$managerMemberId.") ";
  1958. }
  1959. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  1960. 'condition'=>@$querycondition,
  1961. 'order'=>'leadId DESC',
  1962. ),
  1963. 'pagination'=>array(
  1964. 'pageSize'=> 10,
  1965. ),
  1966. ));
  1967. }
  1968. if($type=="allocatedLeads"){
  1969. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1970. $queryCondition = " currentAllocatedId>0 AND isRead = 'yes' ";
  1971. } else {
  1972. $queryCondition = " currentAllocatedId>0 AND isRead = 'yes' AND currentAllocatedId IN (".@$managerMemberId.") ";
  1973. }
  1974. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  1975. 'condition'=>@$queryCondition,
  1976. 'order'=>'leadId DESC',
  1977. )));
  1978. }
  1979. if($type=="Allfollowup"){
  1980. $currentDate=date('d-m-Y',time());
  1981. $starttimestamp=strtotime($currentDate);
  1982. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1983. $queryCondition = ' status="Pending" and userId = "'.@$_SESSION['id'].'" ';
  1984. } else {
  1985. $queryCondition = " status = 'Pending' AND userId IN (".@$managerMemberId.") ";
  1986. }
  1987. $dataProvider=new CActiveDataProvider('LeadFollowup', array('criteria'=>array(
  1988. 'condition'=>@$queryCondition,
  1989. 'order'=>'leadFollowupId DESC',
  1990. )));
  1991. }
  1992. if($type=="followupLeads"){
  1993. $currentDate=date('d-m-Y',time());
  1994. $starttimestamp=strtotime($currentDate);
  1995. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1996. $queryCondition = ' startDate = "'.@$starttimestamp.'" and status="Pending" and userId = "'.@$_SESSION['id'].'" ';
  1997. } else {
  1998. $queryCondition = " startDate = '".@$starttimestamp."' AND status = 'Pending' AND userId IN (".@$managerMemberId.") ";
  1999. }
  2000. $dataProvider=new CActiveDataProvider('LeadFollowup', array('criteria'=>array(
  2001. 'condition'=>@$queryCondition,
  2002. 'order'=>'leadFollowupId DESC',
  2003. )));
  2004. }
  2005. if($type=="duplicateLeads"){
  2006. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  2007. 'condition'=>' leadStatusId = "10" ',
  2008. 'order'=>'leadId DESC',
  2009. )));
  2010. }
  2011. if($type=="dupforday"){
  2012. $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
  2013. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  2014. 'condition'=>' leadStatusId = "10" AND createdOn > "'.@$today12PM.'" ',
  2015. 'order'=>'leadId DESC',
  2016. )));
  2017. }
  2018. if($type=="junkLeads"){
  2019. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  2020. 'condition'=>' leadStatusId = "36" ',
  2021. 'order'=>'leadId DESC',
  2022. )));
  2023. }
  2024. if($type=="closeLeads"){
  2025. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  2026. $querycondition = "leadStatusId = '7' ";
  2027. } else {
  2028. $querycondition = " leadStatusId = '7' AND currentAllocatedId IN (".@$managerMemberId.") ";
  2029. }
  2030. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  2031. 'condition'=>@$querycondition,
  2032. 'order'=>'leadId desc',
  2033. ),
  2034. ));
  2035. }
  2036. if($type=="cip"){
  2037. $contactInProgList=Yii::app()->db->createCommand("select leadStatus.leadStatus,leadStatusId from leadStatus where parentId=3")->queryAll();
  2038. $CIPids = array();
  2039. if(count($contactInProgList) > 0){
  2040. for($w=0;$w<count($contactInProgList);$w++){
  2041. @$CIPids[] = @$contactInProgList[$w]['leadStatusId'];
  2042. }
  2043. } else {
  2044. @$CIPids[] = '';
  2045. }
  2046. @$CIPids = implode(",",@$CIPids);
  2047. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  2048. $querycondition = "leadStatusId IN ( ".@$CIPids." ) ";
  2049. } else {
  2050. $querycondition = " leadStatusId IN ( ".@$CIPids." ) AND currentAllocatedId IN (".@$managerMemberId.") ";
  2051. }
  2052. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  2053. 'condition'=>@$querycondition,
  2054. 'order'=>'leadId desc',
  2055. ),
  2056. 'pagination'=>false,
  2057. ));
  2058. }
  2059. if($type=="plc"){
  2060. $contactInProgList=Yii::app()->db->createCommand("select leadStatus.leadStatus,leadStatusId from leadStatus where parentId=41")->queryAll();
  2061. $CIPids = array();
  2062. if(count($contactInProgList) > 0){
  2063. for($w=0;$w<count($contactInProgList);$w++){
  2064. @$CIPids[] = @$contactInProgList[$w]['leadStatusId'];
  2065. }
  2066. } else {
  2067. @$CIPids[] = '';
  2068. }
  2069. @$CIPids = implode(",",@$CIPids);
  2070. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  2071. $querycondition = "leadStatusId IN ( ".@$CIPids." )";
  2072. } else {
  2073. $querycondition = " leadStatusId IN ( ".@$CIPids." ) AND currentAllocatedId IN (".@$managerMemberId.") ";
  2074. }
  2075. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  2076. 'condition'=>@$querycondition,
  2077. 'order'=>'leadId desc',
  2078. ),
  2079. 'pagination'=>false,
  2080. ));
  2081. }
  2082. $dataProvider->getTotalItemCount($dataProvider);
  2083. if($type=="followupLeads" or $type=="Allfollowup"){
  2084. $iterator = new CDataProviderIterator($dataProvider);
  2085. $file_name = "lms" . "_" . date("Y-m-d_H-i", time()) . ".csv";
  2086. header('Content-Type: text/html; charset=utf-8');
  2087. header("Content-type: application/octet-stream");
  2088. header("Content-Disposition: attachment; filename=\"$file_name\"");
  2089. header("Cache-Control: cache, must-revalidate");
  2090. header("Pragma: public");
  2091. $col = array(
  2092. 'SNO.','Name','Mobile','AgentId','Lead Desciption','Activity Desciption','Email','Action Type','Date and Time','Description','Owner');
  2093. foreach ($col as $key => $value) {
  2094. echo $value . ",";
  2095. }
  2096. echo "\n";
  2097. $i=1;
  2098. foreach($iterator as $data) {
  2099. echo $i++ . ",";
  2100. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->leadDetails->name)) . ",";
  2101. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->leadDetails->mobile)) . ",";
  2102. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->leadDetails->ws_agentid)) . ",";
  2103. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->leadDetails->leadDescription)) . ",";
  2104. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->description)) . ",";
  2105. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->leadDetails->email)) . ",";
  2106. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->actionType)) . ",";
  2107. echo date("d/m/y h:i A",$data->createdOn) . ",";
  2108. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->description)) . ",";
  2109. echo (@$data->userId==@$data->leadDetails->createdBy)?@$data->ownerDetails->firstName." ".@$data->ownerDetails->lastName."(C)":(@$data->ownerDetails->firstName?@$data->ownerDetails->firstName." ".@$data->ownerDetails->lastName:"NA") . ",";
  2110. echo "\n";
  2111. }
  2112. } else {
  2113. $iterator = new CDataProviderIterator($dataProvider);
  2114. $file_name = "lms" . "_" . date("Y-m-d_H-i", time()) . ".csv";
  2115. header('Content-Type: text/html; charset=utf-8');
  2116. header("Content-type: application/octet-stream");
  2117. header("Content-Disposition: attachment; filename=\"$file_name\"");
  2118. header("Cache-Control: cache, must-revalidate");
  2119. header("Pragma: public");
  2120. $col = array(
  2121. 'SNO.','Name','Mobile','AgentId','Lead Desciption','Activity Desciption','Email','Lead Stage','Date and Time','Lead Status','Owner','status');
  2122. foreach ($col as $key => $value) {
  2123. echo $value . ",";
  2124. }
  2125. echo "\n";
  2126. $i=1;
  2127. foreach($iterator as $data) {
  2128. $sqlDesc = "select group_concat(description) as ActivityDescription from leadFollowup where leadId=".@$data->leadId." ";
  2129. $dataDesc=Yii::app()->db->createCommand($sqlDesc)->queryAll();
  2130. $leadActivity = @$dataDesc[0]['ActivityDescription']?@$dataDesc[0]['ActivityDescription']:'';
  2131. echo $i++ . ",";
  2132. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->name)) . ",";
  2133. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->mobile)) . ",";
  2134. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->ws_agentid)) . ",";
  2135. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->leadDescription)) . ",";
  2136. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$leadActivity)) . ",";
  2137. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->email)) . ",";
  2138. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data['leadStageDetails']['leadStage'])) . ",";
  2139. echo date("d/m/y h:i A",$data->createdOn) . ",";
  2140. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->leadStatusDetails->leadStatus)) . ",";
  2141. echo (@$data->currentAllocatedId==@$data->createdBy)?@$data->ownerDetails->firstName." ".@$data->ownerDetails->lastName."(C)":(@$data->ownerDetails->firstName?@$data->ownerDetails->firstName." ".@$data->ownerDetails->lastName:"NA") . ",";
  2142. echo "\n";
  2143. }
  2144. }
  2145. }
  2146. public function actionapiPremimum()
  2147. {
  2148. $model = new Lead();
  2149. global $INDIVIDUAL,$FAMILYFLOATER,$GroupCareArray;
  2150. $INDIVIDUAL = array(
  2151. "200000" => "001",
  2152. "300000" => "003",
  2153. "400000" => "005",
  2154. "500000" => "007",
  2155. "700000" => "009",
  2156. "1000000" => "011",
  2157. "1500000" => "013",
  2158. "2000000" => "015",
  2159. "2500000" => "017",
  2160. "5000000" => "019",
  2161. "6000000" => "021"
  2162. );
  2163. $FAMILYFLOATER = array(
  2164. "200000" => "002",
  2165. "300000" => "004",
  2166. "400000" => "006",
  2167. "500000" => "008",
  2168. "700000" => "010",
  2169. "1000000" => "012",
  2170. "1500000" => "014",
  2171. "2000000" => "016",
  2172. "2500000" => "018",
  2173. "5000000" => "020",
  2174. "6000000" => "022"
  2175. );
  2176. $res = new MySanitizeClass;
  2177. $parser = new CHtmlPurifier();
  2178. if(is_array(@$_REQUEST['ageGroupOfEldestMember'])){
  2179. @$_REQUEST['ageGroupOfEldestMember'] = '';
  2180. } else {
  2181. @$_REQUEST['ageGroupOfEldestMember'] = @$_REQUEST['ageGroupOfEldestMember'];
  2182. }
  2183. if(is_array(@$_REQUEST['numberOfAdult'])){
  2184. @$_REQUEST['numberOfAdult'] = '';
  2185. } else {
  2186. @$_REQUEST['numberOfAdult'] = @$_REQUEST['numberOfAdult'];
  2187. }
  2188. if(is_array(@$_REQUEST['coverTypeCd'])){
  2189. @$_REQUEST['coverTypeCd'] = '';
  2190. } else {
  2191. @$_REQUEST['coverTypeCd'] = @$_REQUEST['coverTypeCd'];
  2192. }
  2193. if(is_array(@$_REQUEST['numberOfChildren'])){
  2194. @$_REQUEST['numberOfChildren'] = '';
  2195. } else {
  2196. @$_REQUEST['numberOfChildren'] = @$_REQUEST['numberOfChildren'];
  2197. }
  2198. if(is_array(@$_REQUEST['productId'])){
  2199. @$_REQUEST['productId'] = '';
  2200. } else {
  2201. @$_REQUEST['productId'] = @$_REQUEST['productId'];
  2202. }
  2203. if(is_array(@$_REQUEST['productTerm'])){
  2204. @$_REQUEST['productTerm'] = '';
  2205. } else {
  2206. @$_REQUEST['productTerm'] = @$_REQUEST['productTerm'];
  2207. }
  2208. if(is_array(@$_REQUEST['sumInsured'])){
  2209. @$_REQUEST['sumInsured'] = '';
  2210. } else {
  2211. @$_REQUEST['sumInsured'] = @$_REQUEST['sumInsured'];
  2212. }
  2213. if(is_array(@$_REQUEST['tenure'])){
  2214. @$_REQUEST['tenure'] = '';
  2215. } else {
  2216. @$_REQUEST['tenure'] = @$_REQUEST['tenure'];
  2217. }
  2218. $query['ageGroupOfEldestMember']=$parser->purify(@$_REQUEST['ageGroupOfEldestMember']);
  2219. $query['coverTypeCd']=$parser->purify(@$_REQUEST['coverTypeCd']);
  2220. $query['productId']=$parser->purify(@$productId1);
  2221. $query['productTerm']=$parser->purify(@$_REQUEST['productTerm']);
  2222. $query['sumInsured']=$parser->purify(@$_REQUEST['sumInsured']);
  2223. if(@$_REQUEST['coverTypeCd']=="INDIVIDUAL"){
  2224. $sumInsured=$parser->purify(intval(@$_REQUEST['sumInsured']));
  2225. if(@$sumInsured>0){
  2226. $sumInsured1=@$INDIVIDUAL[@$sumInsured];
  2227. }
  2228. $query['numberOfAdult']=$parser->purify(@$_REQUEST['numberOfAdult']);
  2229. $query['numberOfChildren']=0;
  2230. }else{
  2231. $sumInsured=$parser->purify(intval(@$_REQUEST['sumInsured']));
  2232. if(@$sumInsured>0){
  2233. $sumInsured1=@$FAMILYFLOATER[@$sumInsured];
  2234. }
  2235. $query['numberOfAdult']=$parser->purify(@$_REQUEST['numberOfAdult']);
  2236. $query['numberOfChildren']=$parser->purify(@$_REQUEST['numberOfChildren']);
  2237. }
  2238. $query['sumInsured1']=@$sumInsured1;
  2239. /*$_SESSION['ageGroupOfEldestMember']=@$query['ageGroupOfEldestMember'];// assign value to session for product tab
  2240. $_SESSION['coverTypeCd'] =@$query['coverTypeCd'];// assign value to session for product tab
  2241. $_SESSION['numberOfAdult'] =@$query['numberOfAdult']+$query['numberOfChildren'];// assign value to session for product tab
  2242. $_SESSION['numberOfChildren'] =@$query['numberOfChildren'];// assign value to session for product tab
  2243. $_SESSION['sumInsured'] =@$sumInsured;// assign value to session for product tab*/
  2244. $premiumArray=$this->csvToArray('tempdata/care_premium.csv');
  2245. $totalMember=$query['numberOfAdult']+$query['numberOfChildren'];
  2246. $planKey=$query['coverTypeCd'].":".$query['ageGroupOfEldestMember'].":".@$totalMember.":".$query['numberOfChildren'].":".$query['sumInsured1'];
  2247. $exactPremiumArray=$this->search(@$premiumArray,'Plan',@$planKey);
  2248. $exactCarePremiumArray=explode(":",@$exactPremiumArray[0]['Premium']);
  2249. $tenureidx = @$_REQUEST['tenure']-1;
  2250. $carePremium = @$exactCarePremiumArray[@$tenureidx];
  2251. //print_r($exactCarePremiumArray);
  2252. $ncppremiumArray=$this->csvToArray('tempdata/ncb_premium.csv');
  2253. $ncbtotalMember=$query['numberOfAdult']+$query['numberOfChildren'];
  2254. $ncbplanKey=$query['coverTypeCd'].":".$query['ageGroupOfEldestMember'].":".@$ncbtotalMember.":".$query['numberOfChildren'].":".$query['sumInsured1'];
  2255. $ncbexactPremiumArray=$this->search(@$ncppremiumArray,'Plan',@$ncbplanKey);
  2256. $exactNCBPremiumArray=explode(":",@$ncbexactPremiumArray[0]['Premium']);
  2257. //$tenureidx = $_REQUEST['tenure']-1;
  2258. $ncbPremium = @$exactNCBPremiumArray[@$tenureidx];
  2259. $addCarePremium = str_replace(',','',@$carePremium);
  2260. $addNCBPremium = str_replace(',','',@$ncbPremium);
  2261. $finalNcbPremium = number_format($addNCBPremium+$addCarePremium);
  2262. //print_r($premiumArray);
  2263. echo trim(@$carePremium).':'.trim(@$finalNcbPremium);
  2264. // echo @$exactPremiumArray[0]['Premium'];
  2265. //$this->render('lead_search',array('searched'=>$searched));
  2266. }
  2267. function csvToArray($csvFileName){
  2268. $row = 1;
  2269. $dataArray=array();
  2270. $columnArray=array();
  2271. $k=0;
  2272. $i=0;
  2273. if (($handle = fopen($csvFileName, "r")) !== FALSE) {
  2274. while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) {
  2275. $num = count($data);
  2276. if($k==0){
  2277. for ($c=0; $c < $num; $c++) {
  2278. $columnArray[$c]=@$data[$c];
  2279. }
  2280. }else{
  2281. for ($c=0; $c < $num; $c++) {
  2282. $columnName=$columnArray[$c];
  2283. $dataArray[$i][$columnName]=@$data[$c];
  2284. }
  2285. $i++;
  2286. }
  2287. $k++;
  2288. $row++;
  2289. }
  2290. fclose($handle);
  2291. }
  2292. return $dataArray;
  2293. }
  2294. function search($array, $key, $value){
  2295. $results = array();
  2296. if (is_array($array))
  2297. {
  2298. if (isset($array[$key]) && $array[$key] == $value)
  2299. $results[] = $array;
  2300. foreach ($array as $subarray){
  2301. $results = array_merge($results, $this->search($subarray, $key, $value));
  2302. }
  2303. }
  2304. return $results;
  2305. }
  2306. function quotesResults(){
  2307. }
  2308. public function actiongetPlanDetails(){
  2309. }
  2310. public function actionleadCreation(){
  2311. include_once("api/api.php");
  2312. $pageList = $this->xml2array(@file_get_contents(ADMINURL.'resource/product_subcategory.xml'),'1','');
  2313. $pageListArray = @$pageList['ProductSubCategory'];
  2314. $subcategoryList = $this->subcategory_page_array($pageListArray);
  2315. if(sanitize_data(@$_REQUEST['productId'])>0){
  2316. for($i=0; $i<count($subcategoryList); $i++){
  2317. if($subcategoryList[$i]["subCategoryId"]==sanitize_data($_REQUEST['productId']))
  2318. {
  2319. @$productId1="Care";
  2320. }
  2321. }
  2322. }else{
  2323. @$productId1="";
  2324. }
  2325. $query['coverTypeCd']=(@$_REQUEST['coverTypeCd']);
  2326. $query['productId']=@$productId1;
  2327. $query['sumInsured']=(@$_REQUEST['sumInsured']);
  2328. // if(@$_REQUEST['coverTypeCd']=="INDIVIDUAL"){
  2329. // switch(@$_REQUEST['sumInsured']){
  2330. // case '200000': $sumInsured1="001";
  2331. // break;
  2332. // case '300000': $sumInsured1="003";
  2333. // break;
  2334. // case '500000': $sumInsured1="005";
  2335. // break;
  2336. // case '1000000': $sumInsured1="007";
  2337. // break;
  2338. // default: $sumInsured1="007";
  2339. // break;
  2340. // }
  2341. // }else{
  2342. // switch(@$_REQUEST['sumInsured']){
  2343. // case '200000': $sumInsured1="002";
  2344. // break;
  2345. // case '300000': $sumInsured1="004";
  2346. // break;
  2347. // case '500000': $sumInsured1="006";
  2348. // break;
  2349. // case '1000000': $sumInsured1="008";
  2350. // break;
  2351. // default: $sumInsured1="008";
  2352. // break;
  2353. // }
  2354. // }
  2355. $tenure=(@$_REQUEST['tenure']);
  2356. $leadstage=(@$_POST['leadstage']);
  2357. $subject=(@$_POST['subject']);
  2358. $query['sumInsured1']=(@$_REQUEST['sumInsured']);
  2359. $query['firstname']=(@$_REQUEST["firstname"]);
  2360. $query['lastname']="";
  2361. $query['emailaddress1']=(@$_REQUEST["emailaddress1"]);
  2362. $query['telephone1']=(@$_REQUEST["telephone1"]);
  2363. $query['mobilephone']=(@$_REQUEST["mobilephone"]);
  2364. $query['premium']=(@$_REQUEST["premium".@$tenure]);
  2365. if(@$_SESSION['agentId']!=''){
  2366. $query['agentid']=@$_SESSION['agentId'];
  2367. }else{
  2368. $query['agentid']=AGENTID;
  2369. }
  2370. $query['noofyears']=@$tenure;
  2371. $query['quoteid']=time();
  2372. if(@$leadstage!=''){
  2373. $query['leadstage']=@$leadstage;
  2374. }else{
  2375. $query['leadstage']="SendQuotation";
  2376. }
  2377. if(@$subject!=''){
  2378. $query['subject']=@$subject." - ".(@$_REQUEST["mobilephone"]);
  2379. }else{
  2380. $query['subject']="Web-".(@$_REQUEST["mobilephone"]);
  2381. }
  2382. $dataArray= $this->LeadCreation($query);
  2383. $_SESSION["quotationReferenceNum"]=$query['quoteid'];
  2384. $_SESSION['mobileSend']="2";
  2385. $_SESSION['mobilephone']=(@$_REQUEST["mobilephone"]);
  2386. }
  2387. public function actionportalProposal(){
  2388. define("_SITEURL", "http://" . @$_SERVER['SERVER_NAME']. '/religare') ;
  2389. define("ADMINURL", "../", true);
  2390. global $INDIVIDUAL,$FAMILYFLOATER,$GroupCareArray;
  2391. $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");
  2392. $INDIVIDUAL = array(
  2393. "200000" => "001",
  2394. "300000" => "003",
  2395. "400000" => "005",
  2396. "500000" => "007",
  2397. "700000" => "009",
  2398. "1000000" => "011",
  2399. "1500000" => "013",
  2400. "2000000" => "015",
  2401. "2500000" => "017",
  2402. "5000000" => "019",
  2403. "6000000" => "021"
  2404. );
  2405. $FAMILYFLOATER = array(
  2406. "200000" => "002",
  2407. "300000" => "004",
  2408. "400000" => "006",
  2409. "500000" => "008",
  2410. "700000" => "010",
  2411. "1000000" => "012",
  2412. "1500000" => "014",
  2413. "2000000" => "016",
  2414. "2500000" => "018",
  2415. "5000000" => "020",
  2416. "6000000" => "022"
  2417. );
  2418. $WEBSUMINSURED = array(
  2419. "200000" => "1",
  2420. "300000" => "2",
  2421. "400000" => "3",
  2422. "500000" => "4",
  2423. "700000" => "5",
  2424. "1000000" => "6",
  2425. "1500000" => "7",
  2426. "2000000" => "8",
  2427. "2500000" => "9",
  2428. "5000000" => "10",
  2429. "6000000" => "11"
  2430. );
  2431. $WEBSUMINSURED1 = array(
  2432. "1" => "200000",
  2433. "2" => "300000",
  2434. "3" => "400000",
  2435. "4" => "500000",
  2436. "5" => "700000",
  2437. "6" => "1000000",
  2438. "7" => "1500000",
  2439. "8" => "2000000",
  2440. "9" => "2500000",
  2441. "10" => "5000000",
  2442. "11" => "6000000"
  2443. );
  2444. $proposalURL="https://rhicluat.religare.com/portalui/PortalExtProposal.run";
  2445. $pageList = $this->xml2array(@file_get_contents('resource/product_subcategory.xml'),'1','');
  2446. $pageListArray = @$pageList['ProductSubCategory'];
  2447. $subcategoryList = $this->subcategory_page_array($pageListArray);
  2448. $productId=(@$_POST['productId']);
  2449. $sumInsured=(@$_POST['sumInsured']);
  2450. $tenure=(@$_POST['premium']);
  2451. $totalAdults=(@$_POST['numberOfAdult']);
  2452. $numberOfChildren=(@$_POST['numberOfChildren']);
  2453. $numberOfAdult=$totalAdults-$numberOfChildren;
  2454. $mobileNumber=(@$_POST['mobile']);
  2455. $_SESSION['mobilephone']=$mobileNumber;
  2456. if($productId>0){
  2457. for($i=0; $i<count($subcategoryList); $i++){
  2458. if($subcategoryList[$i]["subCategoryId"]==$productId)
  2459. {
  2460. @$productId1=$subcategoryList[$i]["productCode"];
  2461. }
  2462. }
  2463. }else{
  2464. @$productId1="";
  2465. }
  2466. if(($tenure==1) || ($tenure==2) || ($tenure==3)){}else{header("Location: "._SITEURL);exit;}
  2467. if($productId1==""){header("Location: "._SITEURL);exit;}else{}
  2468. if(($numberOfChildren==0) || ($numberOfChildren==1) || ($numberOfChildren==2) || ($numberOfChildren==3) || ($numberOfChildren==4)){}else{ header("Location: "._SITEURL);exit;}
  2469. if($totalAdults>1){
  2470. $ageGroupOfEldestMember=(@$_POST['ageGroupOfEldestMember']);
  2471. switch($ageGroupOfEldestMember){
  2472. case '18 - 24': $ageGroupOfEldestMember="18 - 24";
  2473. break;
  2474. case '25 - 35': $ageGroupOfEldestMember="25 - 35";
  2475. break;
  2476. case '36 - 40': $ageGroupOfEldestMember="36 - 40";
  2477. break;
  2478. case '41 - 45': $ageGroupOfEldestMember="41 - 45";
  2479. break;
  2480. case '46 - 50': $ageGroupOfEldestMember="46 - 50";
  2481. break;
  2482. case '51 - 55': $ageGroupOfEldestMember="51 - 55";
  2483. break;
  2484. case '56 - 60': $ageGroupOfEldestMember="56 - 60";
  2485. break;
  2486. case '61 - 65': $ageGroupOfEldestMember="61 - 65";
  2487. break;
  2488. case '66 - 70': $ageGroupOfEldestMember="66 - 70";
  2489. break;
  2490. case '71 - 75': $ageGroupOfEldestMember="71 - 75";
  2491. break;
  2492. case '76 - 99': $ageGroupOfEldestMember="76 - 99";
  2493. break;
  2494. default: $ageGroupOfEldestMember="";
  2495. break;
  2496. }
  2497. if($ageGroupOfEldestMember==""){header("Location: "._SITEURL);exit;}else{}
  2498. $coverType="FAMILYFLOATER";
  2499. if(@$sumInsured>0){
  2500. $sumInsured1=$FAMILYFLOATER[@$sumInsured];
  2501. }
  2502. if($sumInsured1==""){header("Location: "._SITEURL);exit;}else{}
  2503. //$url1="&numberOfAdult=".@$numberOfAdult."&numberOfChildren=".@$numberOfChildren;
  2504. // $url="Location: ".@$proposalURL."?productFamily=HEALTH&pCode=".@$productId1."&coverType=FAMILYFLOATER&ageGroupOfEldestMember=".@$ageGroupOfEldestMember."&sumInsured=".@$sumInsured1."&tenure=".@$tenure.$url1."&mobileNum=".@$_POST['mobile'];
  2505. }else if($totalAdults=="1"){
  2506. $ageGroupOfEldestMember=@$_POST['ageGroupOfEldestMember'];
  2507. switch($ageGroupOfEldestMember){
  2508. case '5 - 24': $ageGroupOfEldestMember="5 - 24";
  2509. break;
  2510. case '25 - 35': $ageGroupOfEldestMember="25 - 35";
  2511. break;
  2512. case '36 - 40': $ageGroupOfEldestMember="36 - 40";
  2513. break;
  2514. case '41 - 45': $ageGroupOfEldestMember="41 - 45";
  2515. break;
  2516. case '46 - 50': $ageGroupOfEldestMember="46 - 50";
  2517. break;
  2518. case '51 - 55': $ageGroupOfEldestMember="51 - 55";
  2519. break;
  2520. case '56 - 60': $ageGroupOfEldestMember="56 - 60";
  2521. break;
  2522. case '61 - 65': $ageGroupOfEldestMember="61 - 65";
  2523. break;
  2524. case '66 - 70': $ageGroupOfEldestMember="66 - 70";
  2525. break;
  2526. case '71 - 75': $ageGroupOfEldestMember="71 - 75";
  2527. break;
  2528. case '76 - 99': $ageGroupOfEldestMember="76 - 99";
  2529. break;
  2530. default: $ageGroupOfEldestMember="";
  2531. break;
  2532. }
  2533. $coverType="INDIVIDUAL";
  2534. if($ageGroupOfEldestMember==""){header("Location: "._SITEURL);exit;}else{}
  2535. if(@$sumInsured>0){
  2536. $sumInsured1=$INDIVIDUAL[@$sumInsured];
  2537. }
  2538. if($sumInsured1==""){header("Location: "._SITEURL);exit;}else{}
  2539. $numberOfAdult=0;
  2540. $numberOfChildren=0;
  2541. // $url1="&numberOfAdult=0&numberOfChildren=0";
  2542. //$url="Location: ".@$proposalURL."?productFamily=HEALTH&pCode=".@$productId1."&coverType=INDIVIDUAL&ageGroupOfEldestMember=".@$ageGroupOfEldestMember."&sumInsured=".@$sumInsured1."&tenure=".@$tenure.$url1."&mobileNum=".@$_SESSION['mobilephone'];
  2543. }else{
  2544. header("Location: "._SITEURL);exit;
  2545. }
  2546. ?>
  2547. <form name="PortalProposal" id="PortalProposal" method="post" action="<?=@$proposalURL;?>">
  2548. <input type="hidden" name="productFamily" value="HEALTH" />
  2549. <input type="hidden" name="pCode" value="<?=@$productId1;?>" />
  2550. <input type="hidden" name="coverType" value="<?=@$coverType;?>" />
  2551. <input type="hidden" name="ageGroupOfEldestMember" value="<?=@$ageGroupOfEldestMember;?>" />
  2552. <input type="hidden" name="sumInsured" value="<?=@$sumInsured1;?>" />
  2553. <input type="hidden" name="tenure" value="<?=@$tenure;?>" />
  2554. <input type="hidden" name="numberOfAdult" value="<?=@$numberOfAdult;?>" />
  2555. <input type="hidden" name="numberOfChildren" value="<?=@$numberOfChildren;?>" />
  2556. <input type="hidden" name="mobileNum" value="<?=@$mobileNumber;?>" />
  2557. <input type="hidden" name="quotationReferenceNum" value="<?=@$_SESSION['quotationReferenceNum'];?>" />
  2558. <input type="hidden" name="agentId" value="<?=@$_SESSION['agentId'];?>" />
  2559. </form>
  2560. <script>
  2561. document.PortalProposal.submit();
  2562. </script>
  2563. <?php
  2564. }
  2565. function xml2array($contents, $get_attributes=1, $priority = 'tag'){
  2566. if(!$contents) return array();
  2567. if(!function_exists('xml_parser_create')) {
  2568. //print "'xml_parser_create()' function not found!";
  2569. return array();
  2570. }
  2571. //Get the XML parser of PHP - PHP must have this module for the parser to work
  2572. $parser = xml_parser_create('');
  2573. 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
  2574. xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
  2575. xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
  2576. xml_parse_into_struct($parser, trim($contents), $xml_values);
  2577. xml_parser_free($parser);
  2578. if(!$xml_values) return;//Hmm...
  2579. //Initializations
  2580. $xml_array = array();
  2581. $parents = array();
  2582. $opened_tags = array();
  2583. $arr = array();
  2584. $current = &$xml_array; //Refference
  2585. //Go through the tags.
  2586. $repeated_tag_index = array();//Multiple tags with same name will be turned into an array
  2587. foreach($xml_values as $data) {
  2588. unset($attributes,$value);//Remove existing values, or there will be trouble
  2589. //This command will extract these variables into the foreach scope
  2590. // tag(string), type(string), level(int), attributes(array).
  2591. extract($data);//We could use the array by itself, but this cooler.
  2592. $result = array();
  2593. $attributes_data = array();
  2594. if(isset($value)) {
  2595. if($priority == 'tag') $result = $value;
  2596. else $result['value'] = $value; //Put the value in a assoc array if we are in the 'Attribute' mode
  2597. }
  2598. //Set the attributes too.
  2599. if(isset($attributes) and $get_attributes) {
  2600. foreach($attributes as $attr => $val) {
  2601. if($priority == 'tag') $attributes_data[$attr] = $val;
  2602. else $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr'
  2603. }
  2604. }
  2605. //See tag status and do the needed.
  2606. if($type == "open") {//The starting of the tag '<tag>'
  2607. $parent[$level-1] = &$current;
  2608. if(!is_array($current) or (!in_array($tag, array_keys($current)))) { //Insert New tag
  2609. $current[$tag] = $result;
  2610. if($attributes_data) $current[$tag. '_attr'] = $attributes_data;
  2611. $repeated_tag_index[$tag.'_'.$level] = 1;
  2612. $current = &$current[$tag];
  2613. } else { //There was another element with the same tag name
  2614. if(isset($current[$tag][0])) {//If there is a 0th element it is already an array
  2615. $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result;
  2616. $repeated_tag_index[$tag.'_'.$level]++;
  2617. } else {//This section will make the value an array if multiple tags with the same name appear together
  2618. $current[$tag] = array($current[$tag],$result);//This will combine the existing item and the new item together to make an array
  2619. $repeated_tag_index[$tag.'_'.$level] = 2;
  2620. if(isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well
  2621. $current[$tag]['0_attr'] = $current[$tag.'_attr'];
  2622. unset($current[$tag.'_attr']);
  2623. }
  2624. }
  2625. $last_item_index = $repeated_tag_index[$tag.'_'.$level]-1;
  2626. $current = &$current[$tag][$last_item_index];
  2627. }
  2628. } elseif($type == "complete") { //Tags that ends in 1 line '<tag />'
  2629. //See if the key is already taken.
  2630. if(!isset($current[$tag])) { //New Key
  2631. $current[$tag] = $result;
  2632. $repeated_tag_index[$tag.'_'.$level] = 1;
  2633. if($priority == 'tag' and $attributes_data) $current[$tag. '_attr'] = $attributes_data;
  2634. } else { //If taken, put all things inside a list(array)
  2635. if(isset($current[$tag][0]) and is_array($current[$tag])) {//If it is already an array...
  2636. // ...push the new element into that array.
  2637. $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result;
  2638. if($priority == 'tag' and $get_attributes and $attributes_data) {
  2639. $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data;
  2640. }
  2641. $repeated_tag_index[$tag.'_'.$level]++;
  2642. } else { //If it is not an array...
  2643. $current[$tag] = array($current[$tag],$result); //...Make it an array using using the existing value and the new value
  2644. $repeated_tag_index[$tag.'_'.$level] = 1;
  2645. if($priority == 'tag' and $get_attributes) {
  2646. if(isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well
  2647. $current[$tag]['0_attr'] = $current[$tag.'_attr'];
  2648. unset($current[$tag.'_attr']);
  2649. }
  2650. if($attributes_data) {
  2651. $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data;
  2652. }
  2653. }
  2654. $repeated_tag_index[$tag.'_'.$level]++; //0 and 1 index is already taken
  2655. }
  2656. }
  2657. } elseif($type == 'close') { //End of tag '</tag>'
  2658. $current = &$parent[$level-1];
  2659. }
  2660. }
  2661. return($xml_array);
  2662. }
  2663. function subcategory_page_array($pageListArray1){
  2664. $m =0;
  2665. $dataArr=array();
  2666. if(is_array(@$pageListArray1['subcategory'][0]) ) {
  2667. $pageListArray = $pageListArray1['subcategory'];
  2668. for($i=0;$i<sizeof($pageListArray);$i++) {
  2669. if(trim($pageListArray[$i]['isDeleted']['value'])=='no'){
  2670. $dataArr[$m]['subCategoryId'] = trim($pageListArray[$i]['subCategoryId']['value']);
  2671. $dataArr[$m]['categoryId'] =trim(@$pageListArray[$i]['categoryId']['value']);
  2672. $dataArr[$m]['subCategoryName'] = @$pageListArray[$i]['subCategoryName']['value'];
  2673. $dataArr[$m]['productCode'] = @$pageListArray[$i]['productCode']['value'];
  2674. $dataArr[$m]['description'] = @$pageListArray[$i]['description']['value'];
  2675. $dataArr[$m]['briefDescription'] = @$pageListArray[$i]['briefDescription']['value'];
  2676. $dataArr[$m]['metaTitle'] = @$pageListArray[$i]['metaTitle']['value'];
  2677. $dataArr[$m]['metaDescription'] = @$pageListArray[$i]['metaDescription']['value'];
  2678. $dataArr[$m]['metaKeywords'] = @$pageListArray[$i]['metaKeywords']['value'];
  2679. $dataArr[$m]['compare'] = @$pageListArray[$i]['compare']['value'];
  2680. $dataArr[$m]['exclusions'] =@$pageListArray[$i]['exclusions']['value'];
  2681. $dataArr[$m]['policyTerms'] =@$pageListArray[$i]['policyTerms']['value'];
  2682. $dataArr[$m]['agentpolicyTerms'] =@$pageListArray[$i]['agentpolicyTerms']['value'];
  2683. $dataArr[$m]['claim'] = @$pageListArray[$i]['claim']['value'];
  2684. $dataArr[$m]['logo'] = @$pageListArray[$i]['logo']['value'];
  2685. $dataArr[$m]['thumbnail'] = @$pageListArray[$i]['thumbnail']['value'];
  2686. $dataArr[$m]['isDeleted'] = trim($pageListArray[$i]['isDeleted']['value']);
  2687. $m++;
  2688. }
  2689. }
  2690. }else {
  2691. $pageListArray = @$pageListArray1['subcategory'];
  2692. if(trim($pageListArray['isDeleted']['value']) =='no') {
  2693. $dataArr[$m]['subCategoryId'] = trim($pageListArray['subCategoryId']['value']);
  2694. $dataArr[$m]['categoryId'] = trim($pageListArray['categoryId']['value']);
  2695. $dataArr[$m]['subCategoryName'] = $pageListArray['subCategoryName']['value'];
  2696. $dataArr[$m]['productCode'] = @$pageListArray['productCode']['value'];
  2697. $dataArr[$m]['description'] = $pageListArray['description']['value'];
  2698. $dataArr[$m]['briefDescription']= $pageListArray['briefDescription']['value'];
  2699. $dataArr[$m]['metaTitle'] = $pageListArray['metaTitle']['value'];
  2700. $dataArr[$m]['metaDescription'] = $pageListArray['metaDescription']['value'];
  2701. $dataArr[$m]['metaKeywords'] = $pageListArray['metaKeywords']['value'];
  2702. $dataArr[$m]['compare'] = $pageListArray['compare']['value'];
  2703. $dataArr[$m]['exclusions'] = $pageListArray['exclusions']['value'];
  2704. $dataArr[$m]['claim'] = $pageListArray['claim']['value'];
  2705. $dataArr[$m]['policyTerms'] =@$pageListArray['policyTerms']['value'];
  2706. $dataArr[$m]['agentpolicyTerms'] =@$pageListArray['agentpolicyTerms']['value'];
  2707. $dataArr[$m]['logo'] = @$pageListArray['logo']['value'];
  2708. $dataArr[$m]['thumbnail'] = @$pageListArray['thumbnail']['value'];
  2709. $dataArr[$m]['isDeleted'] = trim($pageListArray[$i]['isDeleted']['value']);
  2710. $m++;
  2711. }
  2712. }
  2713. //sort by
  2714. if (count ($dataArr) > 0) {
  2715. foreach ($dataArr as $key => $row) {
  2716. @$order_in_category[$key] = $row[0];//[0] is @$order_in_category
  2717. }
  2718. @array_multisort(@$order_in_category, SORT_ASC, $dataArr);
  2719. }
  2720. return $dataArr;
  2721. }
  2722. public function actiongetWebserviceLeadXMLResponse(){
  2723. $data='';
  2724. $leadURL=$_SERVER['DOCUMENT_ROOT']."/religarewebservices/data";
  2725. $r=0;
  2726. foreach(glob($leadURL . '/*request.xml') as $files){
  2727. $checkLeadExistorNot=Lead::model()->findByAttributes(array('fileName'=>$files));
  2728. if(count($checkLeadExistorNot)==0){
  2729. $data=file_get_contents($files);
  2730. $result=$this->xml2array($data);
  2731. $createdLeadDetails=$result['SOAP:Envelope']['SOAP:Body']['Createlead']['Lead'];
  2732. $OrganizationName=$result['SOAP:Envelope']['SOAP:Body']['Createlead']['OrganizationName'];
  2733. $type='Lead';
  2734. $leadsourceCode=$createdLeadDetails['leadsourcecode'];
  2735. $subject=$createdLeadDetails['subject'];
  2736. $firstname=$createdLeadDetails['firstname'];
  2737. $lastname=$createdLeadDetails['lastname'];
  2738. $emailaddress1=$createdLeadDetails['emailaddress1'];
  2739. $telephone1=$createdLeadDetails['telephone1'];
  2740. $mobilephone=$createdLeadDetails['mobilephone'];
  2741. $product=$createdLeadDetails['rhi_product'];
  2742. $suminsured=$createdLeadDetails['rhi_suminsured'];
  2743. $suminsured=(count($suminsured) > 0)?$suminsured:0;
  2744. $premium=$createdLeadDetails['rhi_premium'];
  2745. $premium=(count($premium) > 0)?$premium:0;
  2746. $quoteid=$createdLeadDetails['rhi_quoteid'];
  2747. $proposalid=$createdLeadDetails['rhi_proposalid'];
  2748. $leadstage=$createdLeadDetails['rhi_leadstage'];
  2749. $agentid=$createdLeadDetails['rhi_agentid'];
  2750. $noofyears=$createdLeadDetails['rhi_noofyears'];
  2751. $ProductMaster=ProductMaster::model()->findByAttributes(array('productName'=>$product));
  2752. $productId=$ProductMaster['productId'];
  2753. if(count($result) > 0){
  2754. //echo $files;
  2755. $model = new Lead;
  2756. $model->setAttributes(array(
  2757. 'name' => 'web services',
  2758. 'email' => '',
  2759. 'mobile' => $mobilephone,
  2760. 'productId' => $productId,
  2761. 'members' => 0,
  2762. 'si' => $suminsured,
  2763. 'premium' => $premium,
  2764. 'leadStageId' => '',
  2765. 'fileName' => addslashes($files),
  2766. 'status' => 'Active',
  2767. 'createdOn' => time(),
  2768. 'updatedOn' => time(),
  2769. 'updatedBy' => time(),
  2770. 'createdBy' => time(),
  2771. ));
  2772. //print_r($model);
  2773. $model->isNewRecord = true;
  2774. @$model->save(false);
  2775. } $r++;
  2776. }
  2777. }
  2778. $this->redirect(array('leads/lead_list'));
  2779. }
  2780. public function actionfresh_leads()
  2781. {
  2782. //$modelLead = Lead::model()->findAll("leadStatusId = '34' AND currentAllocatedId<1 ");
  2783. $this->render('fresh_lead_list');
  2784. }
  2785. public function actionviewAllTeams() {
  2786. if (!Yii::app()->request->isAjaxRequest){
  2787. }
  2788. else {
  2789. $this->renderPartial('/leads/partialAllTeamDetails');
  2790. Yii::app()->end();
  2791. }
  2792. }
  2793. public function actionViewLeadActivity() {
  2794. $followupId=@$_REQUEST['id'];
  2795. $model=new LeadFollowup;
  2796. $model=LeadFollowup::model()->findByPk($followupId);
  2797. if (!Yii::app()->request->isAjaxRequest){
  2798. // $this->render('yourView');
  2799. }
  2800. else {
  2801. $this->renderPartial('/leads/ViewLeadActivity',array('model'=>$model));
  2802. Yii::app()->end();
  2803. }
  2804. }
  2805. public function actionViewCalenderActs() {
  2806. //$cs = Yii::app()->getClientScript(); $cs->registerCoreScript('jquery');
  2807. $this->layout=false;
  2808. $startDate=@$_REQUEST['id'];
  2809. $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"));
  2810. if (!Yii::app()->request->isAjaxRequest){
  2811. $this->renderPartial('/leads/ViewCalenderActs',array('model'=>$model,'startDate'=>@$startDate));
  2812. }
  2813. else {
  2814. $this->renderPartial('/leads/ViewCalenderActs',array('model'=>$model,'startDate'=>@$startDate));
  2815. Yii::app()->end();
  2816. }
  2817. }
  2818. public function actionEditCalenderActivity() {
  2819. $this->layout=false;
  2820. $leadId=@$_REQUEST['leadId'];
  2821. $actionId=@$_REQUEST['actionId'];
  2822. $this->renderPartial('EditCalenderActivity',array('leadId'=>$leadId,'actionId'=>$actionId) ,false, true);
  2823. Yii::app()->end();
  2824. }
  2825. public function actiongetActionRes(){
  2826. $statusids = @$_POST['statusids'];
  2827. $model = new LeadStatus;
  2828. $model=LeadStatus::model()->findByPk($statusids);
  2829. echo $result = @$model['actionCompulsary'];
  2830. }
  2831. public function actioncip_lead_list()
  2832. {
  2833. //$model = new LeadStatus;
  2834. $this->render('contact_in_progress_lead_list');
  2835. }
  2836. public function actioncld_lead_list()
  2837. {
  2838. //$model = new Lead;
  2839. $this->render('cld_lead_list');
  2840. }
  2841. public function actionsearchCIP(){
  2842. if(Yii::app()->request->isAjaxRequest==1){
  2843. $models=new Lead();
  2844. $searchIDs =@$_REQUEST['searchIDs'];
  2845. if(isset($searchIDs) && !empty($searchIDs)){
  2846. $this->renderPartial('partialcip',array('searchTxt'=>$searchIDs,'type'=>'cip'));
  2847. }
  2848. } else {
  2849. $redirectUrl = Yii::app()->controller->id."/".$this->action->id;
  2850. $this->redirect("index.php?r=leads/cip_lead_list&pageSize=".@$_REQUEST['pageSize']);
  2851. }
  2852. }
  2853. public function actiondup_forthe_day_lead_list()
  2854. {
  2855. //$modelLead = new Lead;
  2856. $this->render('duplicate_forthe_daylead_list');
  2857. }
  2858. public function actionSearchArchiveLeads(){
  2859. $model = new Lead;
  2860. $teamId = @$_POST['Team']['teamId'];
  2861. $Leadname = @$_POST['Lead']['name'];
  2862. $Leadstatus = @$_POST['Lead']['status'];
  2863. $leadStage = @$_POST['Lead']['leadStage'];
  2864. $leadws_agentid = @$_POST['Lead']['ws_agentid'];
  2865. $leademail = @$_POST['Lead']['email'];
  2866. $leadmobile = @$_POST['Lead']['mobile'];
  2867. $this->render('archive_leads',array('model'=>$model,'teamId'=>$teamId,'Leadname'=>$Leadname,'Leadstatus'=>$Leadstatus,'leadStage'=>$leadStage,'Leadmobile'=>$leadmobile,'Leademail'=>$leademail,'Leadws_agentid'=>$leadws_agentid));
  2868. }
  2869. public function actionplc_lead_list()
  2870. {
  2871. //$model = new Lead;
  2872. $this->render('plc_lead_list');
  2873. }
  2874. public function getAgentIds($ws_agentid,$mobile){
  2875. $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();
  2876. if( $agentIds[0]['total'] > 1){
  2877. echo "<label class='linkUnderline' title='".@$agentIds[0]['ws_agentid']."'><a href='#'>".$ws_agentid."</a></label>";
  2878. } else if($agentIds[0]['total'] == 1) {
  2879. echo "<label title='".@$agentIds[0]['ws_agentid']."'><a href='#'>".$ws_agentid."</a></label>";
  2880. } else {
  2881. echo "";
  2882. }
  2883. //echo explode(',',$agentId);
  2884. }
  2885. public function getLeadStagesIds($leadStageId,$mobile){
  2886. $agentIds=Yii::app()->db->createCommand("select distinct leadStageId from lead where mobile='".@$mobile."' and leadStageId!='' order by leadId desc ")->queryAll();
  2887. $displayedSyage=Yii::app()->db->createCommand("select leadStage from leadStageMaster where leadStageId='".@$leadStageId."' ")->queryAll();
  2888. if(count($agentIds) > 0) {
  2889. for($i=0;$i<count($agentIds);$i++){
  2890. $leadstages=Yii::app()->db->createCommand("select leadStage from leadStageMaster where leadStageId='".@$agentIds[$i]['leadStageId']."' ")->queryAll();
  2891. $agentId[] = @$agentIds[$i]['leadStageId'];
  2892. $leadstages_new[] = @$leadstages[0]['leadStage'];
  2893. }
  2894. } else {
  2895. echo "";
  2896. }
  2897. if( count(@$leadstages_new) > 1){
  2898. echo "<label class='linkUnderline' title='".implode(',',$leadstages_new)."'><a href='#'>".@$displayedSyage[0]['leadStage']."</a></label>";
  2899. } else if( count(@$leadstages_new) == 1) {
  2900. echo "<label title='".implode(',',@$leadstages_new)."'><a href='#'>".@$displayedSyage[0]['leadStage']."</a></label>";
  2901. } else {
  2902. echo "";
  2903. }
  2904. //echo explode(',',$agentId);
  2905. }
  2906. public function actioninactive_users_leads()
  2907. {
  2908. $this->render('inactive_users_leads');
  2909. }
  2910. public function actionInactiveAllocateLeads()
  2911. {
  2912. $Id = $_REQUEST['userids'];
  2913. $teamId = @$_REQUEST['Team']['teamId'];
  2914. $userId = $_REQUEST['Team']['teamMemberId'];
  2915. $updatedBy = @$_SESSION['id'];
  2916. foreach($Id as $key=>$value){
  2917. $model = new AllocatedLeads();
  2918. $model->scenario = 'AllocatedLeads';
  2919. $model->setAttributes(array(
  2920. 'currentAllocatedDate' => time(), //additional data you want to insert
  2921. 'createdOn' => time(), //additional data you want to insert
  2922. 'updatedOn' => time(), //additional
  2923. 'updatedBy' => @$updatedBy, //additional
  2924. 'createdBy' => @$updatedBy, //additional
  2925. 'leadStatusId' => '35', //additional //additional
  2926. ));
  2927. $leadId = @$value;
  2928. $model->leadId = @$value;
  2929. $model->userId = @$userId;
  2930. $model->teamId = @$teamId;
  2931. //echo @$teamId.' - '.@$userId.' - '.@$leadId;
  2932. $model->allocatedId = null;
  2933. $model->isNewRecord = true;
  2934. $model->save();
  2935. $model=new Lead();
  2936. $model->scenario = 'Lead';
  2937. $updatedOn = time();
  2938. Lead::model()->updateByPk(@$value, array('currentAllocatedId'=>@$userId,'leadStatusId'=>'35','updatedBy'=>@$updatedBy,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
  2939. }
  2940. $red = @$_REQUEST['red'];
  2941. if($this->action->id=='AllocateLeads' && $red == 1) {
  2942. $this->redirect(array('leads/inactive_users_leads'));
  2943. } else {
  2944. $this->redirect(array('leads/inactive_users_leads'));
  2945. }
  2946. //$this->redirect(array('leads/lead_list'));
  2947. }
  2948. public function getLeadDescription($leadId){
  2949. $records=Yii::app()->db->createCommand("select leadDescription from lead where leadId='".@$leadId."' ")->queryAll();
  2950. if(count($records) > 0) {
  2951. for($i=0;$i<count($records);$i++){
  2952. $record[] = @$records[$i]['leadDescription'];
  2953. }
  2954. } else {
  2955. echo "";
  2956. }
  2957. if( count(@$record) > 1){
  2958. echo "<label title='".implode(',',$record)."'><a href='#'>".substr(implode(',',$record),0,5)."...</a></label>";
  2959. } else if( count(@$record) == 1) {
  2960. echo "<label title='".implode(',',@$record)."'><a href='#'>".implode(',',$record)."</a></label>";
  2961. } else {
  2962. echo "";
  2963. }
  2964. //echo explode(',',$agentId);
  2965. }
  2966. public function getLeadActivityDescription($leadId){
  2967. $records=Yii::app()->db->createCommand("select description from leadFollowup where leadId='".@$leadId."' ")->queryAll();
  2968. if(count($records) > 0) {
  2969. for($i=0;$i<count($records);$i++){
  2970. $record[] = @$records[$i]['description'];
  2971. }
  2972. } else {
  2973. echo "";
  2974. }
  2975. if( count(@$record) > 1){
  2976. echo "<label title='".implode(',',$record)."'><a href='#'>".substr(implode(',',$record),0,5)."...</a></label>";
  2977. } else if( count(@$record) == 1) {
  2978. echo "<label title='".implode(',',@$record)."'><a href='#'>".substr(implode(',',$record),0,5)."...</a></label>";
  2979. } else {
  2980. echo "";
  2981. }
  2982. //echo explode(',',$agentId);
  2983. }
  2984. public function actionloadleadtabs(){
  2985. $this->layout = false;
  2986. $this->renderPartial('leadTabs');
  2987. }
  2988. public function actiondeleted_database_tab()
  2989. {
  2990. $model=new Lead();
  2991. $model->set_period1=@$_POST['Lead']['period1']?@$_POST['Lead']['period1']:@$_REQUEST['period1'];
  2992. $model->set_period2=@$_POST['Lead']['period2']?@$_POST['Lead']['period2']:@$_REQUEST['period2'];
  2993. $this->render('deleted_database_tab',array('model'=>$model));
  2994. }
  2995. public function actiondelete_lead()
  2996. {
  2997. $deleteId=@$_REQUEST['leadId'];
  2998. if(Yii::app()->request->isAjaxRequest){
  2999. if(!empty($deleteId))
  3000. {
  3001. $model=Lead::model()->findByPk($deleteId);
  3002. }
  3003. else
  3004. {
  3005. $model = new Lead();
  3006. }
  3007. if($model->delete($deleteId)){
  3008. echo "Record deleted successfully";
  3009. } else {
  3010. echo "some error occured please try after some time";
  3011. }
  3012. } else {
  3013. $this->redirect(array('leads/deleted_database_tab'));
  3014. }
  3015. }
  3016. public function actionDeleteAllJunkLeads()
  3017. {
  3018. $model = new lead;
  3019. //print_r($_REQUEST);
  3020. $Id=$_REQUEST['leadids'];
  3021. foreach($Id as $key=>$value){
  3022. $model->deleteByPk($value);
  3023. }
  3024. $this->redirect(Yii::app()->request->urlReferrer);
  3025. }
  3026. public function actionDeleteAllJunkLeadsOneTime()
  3027. {
  3028. $model = new lead;
  3029. echo $startDate = @$_REQUEST['period1'];
  3030. $endDate = @$_REQUEST['period2'];
  3031. $alldeletedIds = @$_POST['alldeletedIds'];
  3032. $Id=unserialize(urldecode($_POST['alldeletedIds']));
  3033. foreach($Id as $key=>$value){
  3034. //echo $value;
  3035. $model->deleteByPk($value);
  3036. }
  3037. $modeldel = new leadsdeletedby;
  3038. $modeldel->id='';
  3039. $modeldel->startdate=@$startDate;
  3040. $modeldel->enddate=@$endDate;
  3041. $modeldel->data=$alldeletedIds;
  3042. $modeldel->deletedOn=time();
  3043. $modeldel->deletedBy=Yii::app()->session->get('userName');
  3044. $modeldel->deletedById=Yii::app()->session->get('id');
  3045. /* $modeldel->setAttributes(array(
  3046. 'id' => '', //additional data you want to insert
  3047. 'startdate' => @$startDate, //additional
  3048. 'enddate' => @$endDate, //additional
  3049. 'data' => 'sdfsdf', //additional
  3050. 'deletedOn' => time(), //additional
  3051. 'deletedBy' => Yii::app()->session->get('userName'), //additional
  3052. 'deletedById' =>Yii::app()->session->get('id'), //additional //additional
  3053. ));*/
  3054. $modeldel->save();
  3055. $this->redirect(Yii::app()->request->urlReferrer);
  3056. }
  3057. public function actionuser_monthly_report() {
  3058. $this->render('user_monthly_report');
  3059. }
  3060. public function actionuser_login_report() {
  3061. $this->render('user_login_report');
  3062. }
  3063. public function actiondownload_login_report() {
  3064. $limitvalue = @$_REQUEST['fetchrecordsBydropdown'];
  3065. $userid = @$_REQUEST['User']['id'];
  3066. if(isset($limitvalue) && !empty($limitvalue) && isset($userid) && !empty($userid)){
  3067. $paginationExcelValue = @$_POST['fetchrecordsBydropdown'];
  3068. if(isset($paginationExcelValue) && !empty($paginationExcelValue)){
  3069. $explodedpaginationValue = explode('-',$paginationExcelValue);
  3070. $startLimit = $explodedpaginationValue[0];
  3071. $endLimit = 10000;
  3072. } else {
  3073. $startLimit = '';
  3074. $endLimit = '';
  3075. }
  3076. if(isset($startLimit) && isset($endLimit) && !empty($endLimit)){
  3077. $limitCond = " limit $startLimit , $endLimit";
  3078. } else {
  3079. $limitCond = '';
  3080. }
  3081. //Here is the code to set conditions for fetch records from database
  3082. $condfilter = '';
  3083. if(isset($userid) && !empty($userid))
  3084. {
  3085. if(isset($userid) && !empty($userid))
  3086. {
  3087. $condfilter .= "t.userid = ".$userid." AND ";
  3088. }
  3089. if(isset($condfilter) && !empty($condfilter)){
  3090. $wherecon = "WHERE ";
  3091. } else {
  3092. $wherecon = "";
  3093. }
  3094. $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();
  3095. }else{
  3096. $data=0;
  3097. }
  3098. if(count($data)>0){
  3099. $file_name = "lms" . "_" . date("Y-m-d_H-i", time()) . ".csv";
  3100. header('Content-Type: text/html; charset=utf-8');
  3101. header("Content-type: application/octet-stream");
  3102. header("Content-Disposition: attachment; filename=\"$file_name\"");
  3103. header("Cache-Control: cache, must-revalidate");
  3104. header("Pragma: public");
  3105. $col = array(
  3106. 'SNO.','User Name','loginTime');
  3107. foreach ($col as $key => $value) {
  3108. echo $value . ",";
  3109. }
  3110. echo "\n";
  3111. $i=1;
  3112. foreach ($data as $key => $value) {
  3113. $loginTime = date("d M Y H:i:s A",$value['loginTime']);
  3114. echo $i++ . ",";
  3115. echo @$value["userName"] . ",";
  3116. echo @$loginTime . ",";
  3117. echo "\n";
  3118. }
  3119. }
  3120. else{
  3121. $this->redirect('index.php?r=leads/user_login_report');
  3122. //$dataProvider=new CActiveDataProvider('LeadReport', array('criteria'=>@$criteria,));
  3123. //$this->render('reports',array('model'=>$model,'dataProvider'=>$dataProvider));
  3124. }
  3125. } else {
  3126. $this->render('user_login_report');
  3127. }
  3128. }
  3129. public static function getMTD($leadStatusId){
  3130. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1);
  3131. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"));
  3132. $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 ";
  3133. $count=Yii::app()->db->createCommand($sql)->queryColumn();
  3134. echo @$count[0];
  3135. //echo Lead::model()->count(array("select"=>'leadid',"condition"=>" leadStatusId = ".@$leadStatusId.""));
  3136. }
  3137. public static function getYTD($leadStatusId){
  3138. $CurrentYear_first_minute = mktime(0, 0, 0, 1, 1, date('Y'));
  3139. $CurrentYear_last_minute = mktime(0, 0, 0, 13, 0, date('Y'));
  3140. $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' ";
  3141. $count=Yii::app()->db->createCommand($sql)->queryColumn();
  3142. //echo Lead::model()->count(array("select"=>'leadid',"condition"=>" leadStatusId = ".@$leadStatusId.""));
  3143. echo @$count[0];
  3144. }
  3145. public static function getUniqueMobLeadCountByStatus($leadStatusId){
  3146. if(isset($leadStatusId) && !empty($leadStatusId)){
  3147. $todayexpiryDate= date('d-M-Y',time());
  3148. $nontydaystime=strtotime("-90 days",strtotime($todayexpiryDate));
  3149. $date1Filer = @$_REQUEST['Lead']['createdOn'];
  3150. $date2Filer = @$_REQUEST['Lead']['createdOn2'];
  3151. $leadFilter = @$_REQUEST['LeadSourceMaster']['leadSourceId'];
  3152. $filterCond ='';
  3153. if(isset($leadFilter) && !empty($leadFilter)){
  3154. $filterCond .= " AND l.leadSourceId = ".$leadFilter."";
  3155. }
  3156. if(isset($date1Filer) && !empty($date1Filer) && isset($date2Filer) && !empty($date2Filer)){
  3157. $date1Filer = strtotime($date1Filer);
  3158. $date2Filer = strtotime($date2Filer);
  3159. $filterCond .= " AND l.createdOn >= ".$date1Filer." and l.createdOn <= ".$date2Filer."";
  3160. }
  3161. if(Yii::app()->session->get('type')=='superadmin'){
  3162. //$sql = "select mobile from lead l where l.leadStatusId=".$leadStatusId." $filterCond ";
  3163. $sql = "select count(l.mobile) as totalunique from lead l where l.leadStatusId=".$leadStatusId." and l.leadStatusId != 10 $filterCond group by l.leadStatusId ";
  3164. } else {
  3165. $impresuser = DashboardController::implodeResult(Yii::app()->session['relationalManager']);
  3166. $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 ";
  3167. }
  3168. //echo $res = Lead::model()->count(array("select"=>"count(distinct mobile) as totalunique","condition"=>" leadStatusId=".$leadStatusId." $filterCond "));
  3169. //$count=Yii::app()->db->createCommand($sql)->queryScalar();
  3170. $count=Yii::app()->db->createCommand($sql)->queryScalar();
  3171. /*$criteria = new CDbCriteria();
  3172. $criteria->select = "mobile";
  3173. $criteria->condition = " leadStatusId=".$leadStatusId."";
  3174. $count=Lead::model()->findAll($criteria);*/
  3175. //echo count($count);
  3176. echo @$count?@$count:0;
  3177. } else {
  3178. echo 0;
  3179. }
  3180. //echo Lead::model()->count(array("select"=>'leadid',"condition"=>" leadStatusId = ".@$leadStatusId.""));
  3181. }
  3182. public function actiondownload_monthly_report(){
  3183. $selectedMonth = @$_REQUEST['selectedMonth'];
  3184. if(Yii::app()->session->get('type')=='superadmin' or Yii::app()->session->get('roleId')==4){
  3185. $userId = @$_REQUEST['User']['id'];
  3186. } else {
  3187. $userId = Yii::app()->session->get('id');
  3188. }
  3189. $startmonthTime = @$_REQUEST['startTime_'.$selectedMonth];
  3190. $endMonthTime = @$_REQUEST['endtime_'.$selectedMonth];
  3191. $wherecon = "t.updatedOn >= ".$startmonthTime." and t.updatedOn <= ".$endMonthTime." and t.currentAllocatedId=".@$userId." ";
  3192. if(empty($startmonthTime) or empty($endMonthTime)){
  3193. $data = array();
  3194. } else {
  3195. $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";
  3196. $data=Yii::app()->db->createCommand($sqlquery)->queryAll();
  3197. }
  3198. if(count($data)>0){
  3199. $file_name = "lmsmonthlyreport" . "_" .$userId. date("Y-m-d_H-i", time()) . ".csv";
  3200. header('Content-Type: text/html; charset=utf-8');
  3201. header("Content-type: application/octet-stream");
  3202. header("Content-Disposition: attachment; filename=\"$file_name\"");
  3203. header("Cache-Control: cache, must-revalidate");
  3204. header("Pragma: public");
  3205. $col = array(
  3206. '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'
  3207. );
  3208. foreach ($col as $key => $value) {
  3209. echo $value . ",";
  3210. }
  3211. echo "\n";
  3212. $i=1;
  3213. foreach ($data as $key => $value) {
  3214. if($value['currentAllocatedId']==$value['createdBy']){
  3215. $owner = $value['firstName']." ".$value['lastName']."(C)";
  3216. } else {
  3217. if(isset($value['firstName']) && !empty($value['firstName'])){
  3218. $owner = $value['firstName']." ".$value['lastName'];
  3219. } else {
  3220. $owner = "NA";
  3221. }
  3222. }
  3223. if(isset($value['updatedOn']) && !empty($value['updatedOn'])){
  3224. $strtme = date("d M Y H:i:s A",$value['updatedOn']);
  3225. } else{ $strtme = 'NA'; }
  3226. $lastModifieddate = $strtme;
  3227. $sqlDesc = "select group_concat(description) as ActivityDescription from leadFollowup where leadId=".@$value["leadId"]." ";
  3228. $dataDesc=Yii::app()->db->createCommand($sqlDesc)->queryAll();
  3229. $leadActivity = @$dataDesc[0]['ActivityDescription']?stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$dataDesc[0]['ActivityDescription'])):'';
  3230. echo $i++ . ",";
  3231. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["name"])) . ",";
  3232. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$value["mobile"])) . ",";
  3233. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$value["email"])) . ",";
  3234. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$value["address"])) . ",";
  3235. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$city)) . ",";
  3236. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$state)) . ",";
  3237. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$value["members"])) . ",";
  3238. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$value["premium"])) . ",";
  3239. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$value['productDetails'])) . ",";
  3240. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$value['leadStatus'])) . ",";
  3241. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$value['status'])) . ",";
  3242. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$value['isJunk'])) . ",";
  3243. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$value['leadSourceTitle'])) . ",";
  3244. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$value['leadStage'])) . ",";;
  3245. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$value["leadDescription"])) . ",";
  3246. echo @$leadActivity . ",";
  3247. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$value["customerType"])) . ",";
  3248. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$value["productName"])) . ",";
  3249. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$value["policyType"])) . ",";
  3250. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$value["planType"])) . ",";
  3251. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$value["campaignName"])) . ",";
  3252. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$value["leadSourceCode"])) . ",";
  3253. echo @$owner . ",";
  3254. echo @$lastModifieddate . ",";
  3255. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$value["ws_agentid"])) . ",";
  3256. echo "\n";
  3257. }
  3258. } else {
  3259. Yii::app()->user->setFlash('msg','No Record Found');
  3260. $this->render('user_monthly_report');
  3261. }
  3262. }
  3263. //Lead Assignment without page refresh
  3264. public function actionAllocateLeadsByAjax(){
  3265. $Id = $_REQUEST['userids'];
  3266. $teamId = @$_REQUEST['Team']['teamId'];
  3267. $userId = $_REQUEST['Team']['teamMemberId'];
  3268. $updatedBy = @$_SESSION['id'];
  3269. $actionurl = @$_REQUEST['actionurl'];
  3270. $paginationsize = Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize'])?Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']):25;
  3271. $userdetails=Yii::app()->db->createCommand("select firstName,lastName from user where id=".$userId." ")->queryAll();
  3272. $myArray = array();
  3273. $responseAll =array();
  3274. $t=0;
  3275. foreach($Id as $key=>$value){
  3276. $model = new AllocatedLeads();
  3277. $model->scenario = 'AllocatedLeads';
  3278. $model->setAttributes(array(
  3279. 'currentAllocatedDate' => time(), //additional data you want to insert
  3280. 'createdOn' => time(), //additional data you want to insert
  3281. 'updatedOn' => time(), //additional
  3282. 'updatedBy' => @$updatedBy, //additional
  3283. 'createdBy' => @$updatedBy, //additional
  3284. 'leadStatusId' => '35', //additional //additional
  3285. ));
  3286. $leadId = @$value;
  3287. $model->leadId = @$value;
  3288. $model->userId = @$userId;
  3289. $model->teamId = @$teamId;
  3290. //echo @$teamId.' - '.@$userId.' - '.@$leadId;
  3291. $model->allocatedId = null;
  3292. $model->isNewRecord = true;
  3293. $model->save();
  3294. $model=new Lead();
  3295. $model->scenario = 'Lead';
  3296. $updatedOn = time();
  3297. Lead::model()->updateByPk(@$value, array('currentAllocatedId'=>@$userId,'leadStatusId'=>'35','updatedBy'=>@$updatedBy,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
  3298. $responseAll[$t]['ownername'] = $userdetails[0]['firstName']." ".$userdetails[0]['lastName'];
  3299. $responseAll[$t]['classname'] = "owner_".@$value;
  3300. $responseAll[$t]['rowclass'] = @$value;
  3301. $myArray[0][$t]=$responseAll[$t];
  3302. $myArray[1]['roleId']=Yii::app()->session->get('roleId');
  3303. $myArray[2]['actionurl']=$actionurl;
  3304. $myArray[3]['paginationsize']=$paginationsize;
  3305. $t++;
  3306. }
  3307. $red = @$_REQUEST['red'];
  3308. if(Yii::app()->request->isAjaxRequest)
  3309. {
  3310. if(Yii::app()->session->get('type')=='superadmin'){
  3311. //print_r($myArray); die;
  3312. //echo "superadmin".$userdetails[0]['firstName'].$userdetails[0]['lastName'];
  3313. echo json_encode($myArray);
  3314. } else if(Yii::app()->session->get('roleId')==4 or Yii::app()->session->get('isAllocator')=='yes') {
  3315. echo json_encode($myArray);
  3316. } else {
  3317. $myArray=array('somethingwrong');
  3318. echo json_encode($myArray);
  3319. }
  3320. exit;
  3321. }
  3322. if($this->action->id=='AllocateLeads' && $red == 1)
  3323. {
  3324. $this->redirect(array('leads/lead_list'));
  3325. }
  3326. $this->redirect(array('leads/fresh_leads'));
  3327. }
  3328. public function actiongetLeadStagesIds(){
  3329. $leadStageId=@$_REQUEST['leadStageId'];
  3330. $mobile=@$_REQUEST['mobile'];
  3331. $leadid=@$_REQUEST['leadid'];
  3332. $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();
  3333. //$displayedSyage=Yii::app()->db->createCommand("select leadStage from leadStageMaster where leadStageId='".@$leadStageId."' ")->queryAll();
  3334. if( $agentIds[0]['total'] >= 1){
  3335. echo @$agentIds[0]['leadStage'];
  3336. } else {
  3337. echo "";
  3338. }
  3339. //echo explode(',',$agentId);
  3340. }
  3341. public function actiongetAgentIds(){
  3342. $ws_agentid=@$_REQUEST['ws_agentid'];
  3343. $mobile=@$_REQUEST['mobile'];
  3344. echo $leadid=@$_REQUEST['leadid'];
  3345. $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();
  3346. if( $agentIds[0]['total'] >= 1){
  3347. echo @$agentIds[0]['ws_agentid'];
  3348. } else {
  3349. echo "";
  3350. }
  3351. //echo explode(',',$agentId);
  3352. }
  3353. }