PageRenderTime 87ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/lms_debug/protected/controllers/LeadsController_2ndJan15.php

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