PageRenderTime 83ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/lms_debug/protected/controllers/LeadsController_24dec2014.php

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