PageRenderTime 238ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 1ms

/lms_debug/protected/controllers/LeadsController_11Jan15.php

https://gitlab.com/badelal143/lms_debug
PHP | 4481 lines | 3520 code | 597 blank | 364 comment | 665 complexity | 1a97629889fcdcdb6295c2273f98b269 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, LGPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. class LeadsController extends BaseController
  3. {
  4. const SHARED_TITLE = "Admin Panel";
  5. /**
  6. * Declares class-based actions.
  7. */
  8. public function filters()
  9. {
  10. return array( 'accessControl',array(
  11. 'CHttpCacheFilter + view',
  12. 'cacheControl' => " max-age=604800, must-revalidate",
  13. ) ); // perform access control for CRUD operations
  14. }
  15. public function actions()
  16. {
  17. return array(
  18. // captcha action renders the CAPTCHA image displayed on the contact page
  19. 'captcha'=>
  20. array(
  21. 'class'=>'CCaptchaAction',
  22. 'backColor'=>0xFFFFFF,
  23. ),
  24. // page action renders "static" pages stored under 'protected/views/site/pages'
  25. // They can be accessed via: index.php?r=site/page&view=FileName
  26. 'page'=>array(
  27. 'class'=>'CViewAction',
  28. ),
  29. );
  30. }
  31. /**
  32. * This is the 'roles' action that is invoked
  33. * when an action is not explicitly requested by users.
  34. */
  35. public function actionlead_welcome()
  36. {
  37. $model = new WelcomeMaster();
  38. $model = WelcomeMaster::model()->find("moduleId = '1' ");
  39. $this->render('lead_welcome',array('model'=>$model));
  40. }
  41. /**
  42. * This is the 'roles' action that is invoked
  43. * when an action is not explicitly requested by users.
  44. */
  45. public function actionlead_list()
  46. {
  47. $this->render('lead_list');
  48. }
  49. /**
  50. * This is the 'lead_list_allocator' action that is invoked
  51. * when an action is not explicitly requested by users.
  52. */
  53. public function actionlead_list_allocator()
  54. {
  55. // renders the view file 'protected/views/site/index.php'
  56. // using the default layout 'protected/views/layouts/main.php'
  57. $this->render('lead_list_allocator');
  58. }
  59. /**
  60. * This is the 'lead_list_allocator' action that is invoked
  61. * when an action is not explicitly requested by users.
  62. */
  63. public function actionfollowup_lead_list()
  64. {
  65. $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
  66. $relationManager = $_SESSION['relationalManager'];
  67. $managerMemberId = implode(",",array_unique(@$relationManager));
  68. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  69. $querycondition = ' startDate = "'.@$today12PM.'" and status="Pending" ';
  70. } else {
  71. $querycondition = " startDate = '".@$today12PM."' AND status = 'Pending' AND userId IN (".@$managerMemberId.") ";
  72. }
  73. //$modelLead = LeadFollowup::model()->findAll(" $querycondition ");
  74. $this->render('followup_lead_list');
  75. }
  76. public function actionfollowup_overall_lead_list()
  77. {
  78. $relationManager = $_SESSION['relationalManager'];
  79. $managerMemberId = implode(",",array_unique(@$relationManager));
  80. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  81. $querycondition = ' status="Pending" ';
  82. } else {
  83. $querycondition = " status = 'Pending' AND userId IN (".@$managerMemberId.") ";
  84. }
  85. //$modelLead = LeadFollowup::model()->findAll(" $querycondition ");
  86. $this->render('followup_overall_lead_list');
  87. }
  88. /**
  89. * This is the 'lead_list_allocator' action that is invoked
  90. * when an action is not explicitly requested by users.
  91. */
  92. public function actionlead_list_tc()
  93. {
  94. // renders the view file 'protected/views/site/index.php'
  95. // using the default layout 'protected/views/layouts/main.php'
  96. $this->render('lead_list_tc');
  97. }
  98. /**
  99. * This is the 'lead_list_allocator' action that is invoked
  100. * when an action is not explicitly requested by users.
  101. */
  102. public function actionjunk_lead_list()
  103. {
  104. //$modelLead = Lead::model()->findAll(" leadStatusId = '36' ");
  105. $this->render('junk_lead_list');
  106. }
  107. /**
  108. * This is the 'lead_list_allocator' action that is invoked
  109. * when an action is not explicitly requested by users.
  110. */
  111. public function actionduplicate_lead_list()
  112. {
  113. //$modelLead = Lead::model()->findAll(" leadStatusId = '10' ");
  114. $this->render('duplicate_lead_list');
  115. }
  116. public function actionclose_lead_list()
  117. {
  118. //$modelLead = Lead::model()->findAll(" leadStatusId = '7' ");
  119. $this->render('close_lead_list');
  120. }
  121. /**
  122. * This is the 'lead_list_allocator' action that is invoked
  123. * when an action is not explicitly requested by users.
  124. */
  125. public function actionallocated_lead_list()
  126. {
  127. $relationManager = $_SESSION['relationalManager'];
  128. $managerMemberId = implode(",",array_unique(@$relationManager));
  129. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  130. $querycondition = " currentAllocatedId>0 AND isRead = 'yes'";
  131. } else {
  132. $querycondition = " currentAllocatedId >0 AND isRead = 'yes' AND currentAllocatedId IN (".@$managerMemberId.") ";
  133. }
  134. //$modelLead = Lead::model()->findAll(" $querycondition ");
  135. $this->render('allocated_lead_list');
  136. }
  137. /**
  138. * This is the 'lead_list_allocator' action that is invoked
  139. * when an action is not explicitly requested by users.
  140. */
  141. public function actionleads_details()
  142. {
  143. // renders the view file 'protected/views/site/index.php'
  144. // using the default layout 'protected/views/layouts/main.php'
  145. //for follow up
  146. $parser = new CHtmlPurifier();
  147. if (isset($_POST['LeadFollowup']))
  148. {
  149. if (isset($_POST['LeadFollowup']['chkActionValid']) && @$_POST['LeadFollowup']['chkActionValid'] == 1)
  150. {
  151. $res = $this->actionlead_followup(@$_POST['LeadFollowup'], $parser->purify(intval(@$_POST['Lead']['leadStatusId'])));
  152. $decodeRes = json_decode($res);
  153. if (@$decodeRes->status == 'success')
  154. {
  155. echo CJSON::encode(array(
  156. 'status' => 'success'
  157. ));
  158. }
  159. else
  160. {
  161. echo $res;
  162. }
  163. }
  164. }
  165. $leadFollDesc = @$_POST['LeadFollowup']['description'];
  166. // end of for follow ups
  167. $leadId = $parser->purify(intval(@$_GET['leadId']));
  168. $actionId = $parser->purify(intval(@$_REQUEST['actionId']));
  169. $actionmodel = LeadFollowup::model()->findByPk($actionId);
  170. $model = new Lead();
  171. $this->performAjaxValidation($model);
  172. $model->scenario = 'Lead';
  173. $managerMemberId = implode(",", $_SESSION['relationalManager']);
  174. $chkAllocatedLeads = $managerMemberId ? Lead::model()->findAll(array("select" => " leadId", "condition" => " leadStatusId != '26' AND leadStatusId != '25' AND currentAllocatedId IN (" . @$managerMemberId . ") ")) : '0';
  175. /* $allocatedArr = array();
  176. foreach ($chkAllocatedLeads as $key => $value)
  177. {
  178. $allocatedArr[] = $chkAllocatedLeads[$key]->leadId;
  179. }
  180. //print_r($allocatedArr);
  181. //die;
  182. if(Yii::app()->session->get('isAllocator')!='yes' and Yii::app()->session->get('type')!='superadmin'){
  183. if(!in_array($leadId,$allocatedArr)){
  184. $this->redirect(array('leads/lead_list'));
  185. }
  186. } */
  187. if (!empty($leadId))
  188. {
  189. $model = Lead::model()->findByPk($leadId);
  190. $chkrecentlyViewed = recentlyViewed::model()->findByAttributes(array('leadId' => $leadId, 'userId' => Yii::app()->session->get('id')));
  191. if (count($chkrecentlyViewed) == 0)
  192. {
  193. $recentlyViewed = new recentlyViewed();
  194. $recentlyViewed->setAttributes(array(
  195. 'userId' => Yii::app()->session->get('id'),
  196. 'leadId' => $leadId,
  197. 'moduleId' => 0,
  198. 'updatedOn' => $_SESSION['id'],
  199. 'updatedBy' => $_SESSION['id'],
  200. ));
  201. $recentlyViewed->save(false);
  202. }
  203. }
  204. if (isset($_POST['Lead']))
  205. {
  206. if ($_POST['LeadFollowup']['startDate'] != '')
  207. {
  208. $finalLeadDesc = @$leadFollDesc;
  209. }
  210. else
  211. {
  212. $finalLeadDesc = @$_POST['Lead']['leadDescription'];
  213. }
  214. $model->setAttributes(array(
  215. 'updatedOn' => time(), //additional
  216. 'updatedBy' => $_SESSION['id'], //additional
  217. 'status' => 'Active', //additional //additional
  218. 'leadDescription' => @$finalLeadDesc, //additional //additional
  219. ));
  220. $prevLeadStatusId = $model->leadStatusId;
  221. $prevCurrentAllocatedId = $model->currentAllocatedId;
  222. foreach ($_POST['Lead'] as $name => $value)
  223. {
  224. if ($model->leadStatusId == '')
  225. {
  226. $model->leadStatusId = $model->leadStatusParentId;
  227. }
  228. if ($model->email == 'Email')
  229. {
  230. $model->email = '';
  231. }
  232. if ($model->name == 'Name')
  233. {
  234. $model->name = '';
  235. }
  236. if ($model->address == 'Address')
  237. {
  238. $model->address = '';
  239. }
  240. if ($model->ws_proposalid == 'Proposal No.')
  241. {
  242. $model->ws_proposalid = '';
  243. }
  244. if ($model->children == "Children (Less than 25 Yrs)")
  245. {
  246. $model->children = '';
  247. }
  248. if ($model->ageGroup == "Age of eldest member")
  249. {
  250. $model->ageGroup = '';
  251. }
  252. if ($model->leadDescription == "Lead Description")
  253. {
  254. $model->leadDescription = '';
  255. }
  256. if ($model->leadStatusId == '')
  257. {
  258. $model->leadStatusId = $prevLeadStatusId;
  259. }
  260. if (@$leadId != '' && $model->leadStatusId != '34' && @$model->leadStatusId != '35')
  261. {
  262. $model->isRead = 'yes';
  263. }
  264. if (is_array($value))
  265. {
  266. $value = '';
  267. }
  268. else
  269. {
  270. $value = $value;
  271. }
  272. $model->$name = $parser->purify($value);
  273. }
  274. //------------------------------------------------------
  275. $accesskeyYear = $currentYear = date('Y');
  276. $accesskeyMonth = date('m');
  277. if ($model->currentAllocatedDate)
  278. {
  279. $accesskeyYear = date('Y', $model->currentAllocatedDate);
  280. $accesskeyMonth = date('m', $model->currentAllocatedDate);
  281. }
  282. else
  283. {
  284. if ($model->updatedOn)
  285. {
  286. $accesskeyYear = date('Y', $model->updatedOn);
  287. $accesskeyMonth = date('m', $model->updatedOn);
  288. }
  289. }
  290. if ($currentYear != $accesskeyYear)
  291. {
  292. if (BaseController::getConfigurationValue('leadallcount'))
  293. ;
  294. {
  295. DashboardController::insertUserLeadAllCountRecord($accesskeyYear);
  296. }
  297. }
  298. $currentStatus = $_POST['Lead']['leadStatusId'];
  299. $updatedOn = time();
  300. $updatedBy = Yii::app()->session['id'];
  301. if (!$prevCurrentAllocatedId)
  302. {
  303. $prevCurrentAllocatedId = 1;
  304. }
  305. Yii::app()->db->createCommand('START TRANSACTION;')->execute();
  306. if ($currentStatus != $prevLeadStatusId && $currentStatus != '')
  307. {
  308. if (BaseController::getConfigurationValue('leadallcount'))
  309. {
  310. if (Yii::app()->session->get('type') != 'superadmin')
  311. {
  312. Yii::app()->db->createCommand("update leadallcount set count = count - 1, updatedOn = $updatedOn, updatedBy = $updatedBy
  313. where userid = $prevCurrentAllocatedId and leadtype = $prevLeadStatusId
  314. and accesskey = '$accesskeyYear'")->execute();
  315. Yii::app()->db->createCommand("update leadallcount set count = count - 1, updatedOn = $updatedOn, updatedBy = $updatedBy
  316. where userid = $prevCurrentAllocatedId and leadtype = $prevLeadStatusId
  317. and accesskey = '$accesskeyYear-$accesskeyMonth'")->execute();
  318. Yii::app()->db->createCommand("update leadallcount set count = count + 1, updatedOn = $updatedOn, updatedBy = $updatedBy
  319. where userid = $updatedBy and leadtype = $currentStatus
  320. and accesskey = '$accesskeyYear'")->execute();
  321. Yii::app()->db->createCommand("update leadallcount set count = count + 1, updatedOn = $updatedOn, updatedBy = $updatedBy
  322. where userid = $updatedBy and leadtype = $currentStatus
  323. and accesskey = '$accesskeyYear-$accesskeyMonth'")->execute();
  324. }
  325. Yii::app()->db->createCommand("update leadallcount set count = count - 1, updatedOn = $updatedOn, updatedBy = $updatedBy
  326. where userid = 1 and leadtype = $prevLeadStatusId
  327. and accesskey = '$accesskeyYear'")->execute();
  328. Yii::app()->db->createCommand("update leadallcount set count = count - 1, updatedOn = $updatedOn, updatedBy = $updatedBy
  329. where userid = 1 and leadtype = $prevLeadStatusId
  330. and accesskey = '$accesskeyYear-$accesskeyMonth'")->execute();
  331. Yii::app()->db->createCommand("update leadallcount set count = count + 1, updatedOn = $updatedOn, updatedBy = $updatedBy
  332. where userid = 1 and leadtype = $currentStatus
  333. and accesskey = '$accesskeyYear'")->execute();
  334. Yii::app()->db->createCommand("update leadallcount set count = count + 1, updatedOn = $updatedOn, updatedBy = $updatedBy
  335. where userid = 1 and leadtype = $currentStatus
  336. and accesskey = '$accesskeyYear-$accesskeyMonth'")->execute();
  337. }
  338. Yii::app()->db->createCommand('COMMIT;')->execute();
  339. }
  340. else
  341. {
  342. Yii::app()->db->createCommand('ROLLBACK;')->execute();
  343. }
  344. // Added by shakti upto here.
  345. if ($model->leadStatusParentId == '1')
  346. {
  347. $model->salesClosedUpdatedOn = time();
  348. }
  349. $fetchAgentDetails = LeadSourceMaster::model()->findByPk($model->leadSourceId);
  350. $model->agentId = @$fetchAgentDetails->leadSourceCode;
  351. $model->ws_agentid = @$fetchAgentDetails->leadSourceCode;
  352. if (@$leadId != '' && $model->leadStatusId != '34')
  353. {
  354. $update = Yii::app()->db->createCommand("update `lead` set `isRead`='yes' where `leadId`='$leadId' and currentAllocatedId > 0")->query();
  355. }
  356. $chkStatusMandatoryOrNot = leadStatus::model()->findByAttributes(array('leadStatusId' => $model->leadStatusId));
  357. if ($model->leadStatusId == '1')
  358. {
  359. $model->scenario = 'salesclosed';
  360. }
  361. if (count($chkStatusMandatoryOrNot) > 0)
  362. {
  363. $condMandatory = $chkStatusMandatoryOrNot['compulsary'];
  364. if ($condMandatory == 'No')
  365. {
  366. if ($model->validate(array('mobile')))
  367. {
  368. if (@$_POST['Lead']['emailOptOut'] == 'on')
  369. {
  370. $model->emailOptOut = 'Y';
  371. }
  372. else
  373. {
  374. $model->emailOptOut = 'N';
  375. }
  376. if (@$_POST['Lead']['mobileOptOut'] == 'on')
  377. {
  378. $model->mobileOptOut = 'Y';
  379. }
  380. else
  381. {
  382. $model->mobileOptOut = 'N';
  383. }
  384. if (@$_POST['Lead']['isJunk'] == 'on')
  385. {
  386. $model->isJunk = 'yes';
  387. }
  388. else
  389. {
  390. $model->isJunk = 'no';
  391. }
  392. if (@$_POST['Lead']['isDuplicate'] == 'on')
  393. {
  394. $model->isDuplicate = 'yes';
  395. }
  396. else
  397. {
  398. $model->isDuplicate = 'no';
  399. }
  400. if (@$_POST['Lead']['status'] == 'on')
  401. {
  402. $model->status = 'Close';
  403. }
  404. else
  405. {
  406. $model->status = 'Active';
  407. }
  408. $modelHistory = new LeadHistory();
  409. $modelHistory->scenario = 'LeadHistory';
  410. $modelHistory->setAttributes(array(
  411. 'leadId' => @$leadId, //additional data you want to insert
  412. 'updatedOn' => time(), //additional
  413. 'updatedBy' => $_SESSION['id'], //additional
  414. 'status' => 'Active', //additional
  415. 'leadDescription' => @$finalLeadDesc,
  416. ));
  417. foreach ($_POST['Lead'] as $name1 => $value1)
  418. {
  419. if ($modelHistory->leadStatusId == '')
  420. {
  421. $modelHistory->leadStatusId = $modelHistory->leadStatusParentId;
  422. }
  423. if (@$_POST['LeadFollowup']['description'] == 'Description')
  424. {
  425. $activitydesc = '';
  426. }
  427. else
  428. {
  429. $activitydesc = @$_POST['LeadFollowup']['description'];
  430. }
  431. $modelHistory->activityDescription = @$activitydesc;
  432. if ($model->leadStatusId == '')
  433. {
  434. $model->leadStatusId = 2;
  435. }
  436. if ($modelHistory->email == 'Email')
  437. {
  438. $modelHistory->email = '';
  439. }
  440. if ($modelHistory->name == 'Name')
  441. {
  442. $modelHistory->name = '';
  443. }
  444. if ($modelHistory->address == 'Address')
  445. {
  446. $modelHistory->address = '';
  447. }
  448. if ($modelHistory->leadDescription == "Lead Description")
  449. {
  450. $modelHistory->leadDescription = '';
  451. }
  452. if ($modelHistory->children == "Children (Less than 25 Yrs)")
  453. {
  454. $modelHistory->children = '';
  455. }
  456. if ($modelHistory->ageGroup == "Age of eldest member")
  457. {
  458. $modelHistory->ageGroup = '';
  459. }
  460. if (is_array($value1))
  461. {
  462. $value1 = '';
  463. }
  464. else
  465. {
  466. $value1 = $value1;
  467. }
  468. $modelHistory->$name1 = $parser->purify($value1);
  469. }
  470. $model->save(false);
  471. $modelHistory->save();
  472. CJSON::encode(array(
  473. 'status' => 'success'
  474. ));
  475. Yii::app()->end();
  476. }
  477. }
  478. }
  479. $model->save();
  480. if ($model->validate())
  481. {
  482. if (@$_POST['Lead']['emailOptOut'] == 'on')
  483. {
  484. $model->emailOptOut = 'Y';
  485. }
  486. else
  487. {
  488. $model->emailOptOut = 'N';
  489. }
  490. if (@$_POST['Lead']['mobileOptOut'] == 'on')
  491. {
  492. $model->mobileOptOut = 'Y';
  493. }
  494. else
  495. {
  496. $model->mobileOptOut = 'N';
  497. }
  498. if (@$_POST['Lead']['isJunk'] == 'on')
  499. {
  500. $model->isJunk = 'yes';
  501. }
  502. else
  503. {
  504. $model->isJunk = 'no';
  505. }
  506. if (@$_POST['Lead']['isDuplicate'] == 'on')
  507. {
  508. $model->isDuplicate = 'yes';
  509. }
  510. else
  511. {
  512. $model->isDuplicate = 'no';
  513. }
  514. if (@$_POST['Lead']['status'] == 'on')
  515. {
  516. $model->status = 'Close';
  517. }
  518. else
  519. {
  520. $model->status = 'Active';
  521. }
  522. $modelHistory = new LeadHistory();
  523. $modelHistory->scenario = 'LeadHistory';
  524. $modelHistory->setAttributes(array(
  525. 'leadId' => @$leadId, //additional data you want to insert
  526. 'updatedOn' => time(), //additional
  527. 'updatedBy' => $_SESSION['id'], //additional
  528. 'status' => 'Active', //additional
  529. 'leadDescription' => @$finalLeadDesc,
  530. ));
  531. foreach ($_POST['Lead'] as $name1 => $value1)
  532. {
  533. if ($modelHistory->leadStatusId == '')
  534. {
  535. $modelHistory->leadStatusId = $modelHistory->leadStatusParentId;
  536. }
  537. $modelHistory->activityDescription = @$_POST['LeadFollowup']['description'];
  538. if ($model->leadStatusId == '')
  539. {
  540. $model->leadStatusId = 2;
  541. }
  542. if (is_array($value1))
  543. {
  544. $value1 = '';
  545. }
  546. else
  547. {
  548. $value1 = $value1;
  549. }
  550. $modelHistory->$name1 = $parser->purify($value1);
  551. }
  552. $modelHistory->save();
  553. echo CJSON::encode(array(
  554. 'status' => 'success'
  555. ));
  556. Yii::app()->end();
  557. //Yii::app()->end();
  558. //die;
  559. //$this->redirect(array('leads/leads_details'));
  560. }
  561. else
  562. {
  563. @$error = CActiveForm::validate(@$model);
  564. if ($error != '[]')
  565. echo @$error;
  566. Yii::app()->end();
  567. //$this->render('leads_details',array('model'=>$model));
  568. }
  569. } else
  570. {
  571. $this->render('leads_details', array('model' => @$model, 'actionmodel' => @$actionmodel, 'quotesmobile' => @$model->mobile));
  572. }
  573. }
  574. protected function performAjaxValidation($models)
  575. {
  576. if(isset($_POST['ajax']) && $_POST['ajax']==='user-form')
  577. {
  578. echo CActiveForm::validate($models);
  579. Yii::app()->end();
  580. }
  581. }
  582. /**
  583. * This is the 'lead_list_allocator' action that is invoked
  584. * when an action is not explicitly requested by users.
  585. */
  586. public function actionlead_followup()
  587. {
  588. $actionId = @$_REQUEST['actionId'];
  589. $model = new LeadFollowup();
  590. $model->scenario = 'LeadFollowup';
  591. if(isset($actionId) && !empty($actionId)){
  592. $model=LeadFollowup::model()->findByPk($actionId);
  593. } else {
  594. }
  595. if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Task'){
  596. $model->scenario = 'LeadFollowupTask';
  597. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Follow Up'){
  598. $model->scenario = 'LeadFollowup';
  599. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Meeting'){
  600. $model->scenario = 'LeadFollowup';
  601. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Notes'){
  602. $model->scenario = 'LeadFollowupNotes';
  603. }
  604. $parser = new CHtmlPurifier();
  605. $this->performAjaxValidation($model);
  606. if(isset($_POST['LeadFollowup']))
  607. {
  608. $userId = $_POST['LeadFollowup']['userId'];
  609. $followupstartdatewithtime = strtotime(@$_POST['LeadFollowup']['startDate'])+(@$_POST['LeadFollowup']['hour']*60*60)+(@$_POST['LeadFollowup']['minutes']*60);
  610. $model->setAttributes(array(
  611. 'createdOn' => time(), //additional data you want to insert
  612. 'updatedOn' => time(), //additional
  613. 'updatedBy' => @$userId, //additional
  614. 'createdBy' => @$userId, //additional
  615. 'status' => 'Pending', //additional
  616. ));
  617. foreach($_POST['LeadFollowup'] as $name=>$value)
  618. {
  619. if(is_array($value)){
  620. $value = '';
  621. } else {
  622. $value = $value;
  623. }
  624. $model->$name=$parser->purify($value);
  625. }
  626. $model->leadStatusId=@$_POST['Lead']['leadStatusId'];;
  627. $model->startDateWithTime=@$followupstartdatewithtime;
  628. if(@$_POST['LeadFollowup']['actionType']=='Notes') {
  629. $prefix=substr(time(),0,5);
  630. $folder = 'siteupload/';
  631. $model->notesFile=CUploadedFile::getInstance($model,'notesFile');
  632. if($model->notesFile !='')
  633. $model->notesFile->saveAs($folder.$prefix.$model->notesFile);
  634. $model->notesFile=$prefix.CUploadedFile::getInstance($model,'notesFile');
  635. }
  636. if(@$_POST['LeadFollowup']['startDate']!='') {
  637. $startDateVal = strtotime($_POST['LeadFollowup']['startDate']);
  638. $model->startDate=@$startDateVal;
  639. }
  640. if(@$_POST['LeadFollowup']['taskDueDate']!='') {
  641. $taskDueDateVal = strtotime($_POST['LeadFollowup']['taskDueDate']);
  642. $model->taskDueDate=@$taskDueDateVal;
  643. }
  644. if(@$_POST['LeadFollowup']['taskCompleted']!='') {
  645. $model->taskCompleted='yes';
  646. }
  647. if($model->validate()){
  648. $checkForSameDateExistsOrNot=LeadFollowup::model()->findAll(" leadId='".@$_POST['LeadFollowup']['leadId']."' and startDate <= '".$model->startDate."' and userId = '".@$userId."' and createdBy = '".@$userId."' ");
  649. if(count(@$checkForSameDateExistsOrNot) > 0){
  650. $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();
  651. }
  652. $model->save();
  653. $leadId = $_POST['LeadFollowup']['leadId'];
  654. return CJSON::encode(array(
  655. 'status'=>'success'
  656. ));
  657. Yii::app()->end();
  658. } else {
  659. $error = CActiveForm::validate($model);
  660. if($error!='[]')
  661. return $error;
  662. Yii::app()->end();
  663. }
  664. //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  665. }
  666. $this->redirect(array('leads/lead_list'));
  667. }
  668. /**
  669. * This is the 'lead_list_allocator' action that is invoked
  670. * when an action is not explicitly requested by users.
  671. */
  672. public function actionlead_followupcalender()
  673. {
  674. $actionId = @$_REQUEST['actionId'];
  675. $model = new LeadFollowup();
  676. $model->scenario = 'LeadFollowup';
  677. if(isset($actionId) && !empty($actionId)){
  678. $model=LeadFollowup::model()->findByPk($actionId);
  679. } else {
  680. }
  681. if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Task'){
  682. $model->scenario = 'LeadFollowupTask';
  683. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Follow Up'){
  684. $model->scenario = 'LeadFollowup';
  685. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Meeting'){
  686. $model->scenario = 'LeadFollowup';
  687. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Notes'){
  688. $model->scenario = 'LeadFollowupNotes';
  689. }
  690. $this->performAjaxValidation($model);
  691. if(isset($_POST['LeadFollowup']))
  692. {
  693. $userId = $_POST['LeadFollowup']['userId'];
  694. $model->setAttributes(array(
  695. 'createdOn' => time(), //additional data you want to insert
  696. 'updatedOn' => time(), //additional
  697. 'updatedBy' => @$userId, //additional
  698. 'createdBy' => @$userId, //additional
  699. 'status' => 'Pending', //additional
  700. ));
  701. foreach($_POST['LeadFollowup'] as $name=>$value)
  702. {
  703. $model->$name=$value;
  704. }
  705. $model->leadStatusId=@$_POST['Lead']['leadStatusId'];;
  706. if(@$_POST['LeadFollowup']['actionType']=='Notes') {
  707. $prefix=substr(time(),0,5);
  708. $folder = 'siteupload/';
  709. $model->notesFile=CUploadedFile::getInstance($model,'notesFile');
  710. if($model->notesFile !='')
  711. $model->notesFile->saveAs($folder.$prefix.$model->notesFile);
  712. $model->notesFile=$prefix.CUploadedFile::getInstance($model,'notesFile');
  713. }
  714. if(@$_POST['LeadFollowup']['startDate']!='') {
  715. $startDateVal = strtotime($_POST['LeadFollowup']['startDate']);
  716. $model->startDate=@$startDateVal;
  717. }
  718. if(@$_POST['LeadFollowup']['taskDueDate']!='') {
  719. $taskDueDateVal = strtotime($_POST['LeadFollowup']['taskDueDate']);
  720. $model->taskDueDate=@$taskDueDateVal;
  721. }
  722. if(@$_POST['LeadFollowup']['taskCompleted']!='') {
  723. $model->taskCompleted='yes';
  724. }
  725. if($model->validate()){
  726. $model->save();
  727. $leadId = $_POST['LeadFollowup']['leadId'];
  728. echo CJSON::encode(array(
  729. 'status'=>'success'
  730. ));
  731. Yii::app()->end();
  732. } else {
  733. $error = CActiveForm::validate($model);
  734. if($error!='[]')
  735. return $error;
  736. Yii::app()->end();
  737. }
  738. //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  739. }
  740. $this->redirect(array('leads/lead_list'));
  741. }
  742. public function actionlead_contacts()
  743. {
  744. // renders the view file 'protected/views/site/index.php'
  745. // using the default layout 'protected/views/layouts/main.php'
  746. $model = new LeadContacts();
  747. $model->scenario = 'LeadContacts';
  748. $this->performAjaxValidation($model);
  749. if(!empty($_GET['contactId']))
  750. {
  751. $leadContactId=$_GET['leadContactId'];
  752. $model=LeadContacts::model()->findByPk($leadContactId);
  753. }
  754. if(!empty($_POST['LeadContacts']['leadContactId']))
  755. {
  756. $leadContactId=$_POST['LeadContacts']['leadContactId'];
  757. $model=LeadContacts::model()->findByPk($leadContactId);
  758. }
  759. if(isset($_POST['LeadContacts']))
  760. {
  761. $userId = $_POST['LeadContacts']['userId'];
  762. $leadId = $_POST['LeadContacts']['leadId'];
  763. $model->setAttributes(array(
  764. 'createdOn' => time(), //additional data you want to insert
  765. 'updatedOn' => time(), //additional
  766. 'updatedBy' => @$userId, //additional
  767. 'createdBy' => @$userId, //additional
  768. 'status' => 'Active', //additional
  769. ));
  770. foreach($_POST['LeadContacts'] as $name=>$value)
  771. {
  772. $model->$name=$value;
  773. }
  774. if($model->validate()){
  775. $model->save();
  776. echo CJSON::encode(array(
  777. 'status'=>'success'
  778. ));
  779. Yii::app()->end();
  780. } else {
  781. $error = CActiveForm::validate($model);
  782. if($error!='[]')
  783. echo $error;
  784. Yii::app()->end();
  785. }
  786. //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  787. }
  788. $this->redirect(array('leads/lead_list'));
  789. }
  790. public function actionChangeContactStatus()
  791. {
  792. $Id=$_REQUEST['contactId'];
  793. $leadId=$_REQUEST['leadId'];
  794. $status=$_REQUEST['status'];
  795. if(isset($status)&&($status=='Inactive')){
  796. $status="Active";
  797. } else {
  798. $status="Inactive";
  799. }
  800. if(!empty($Id))
  801. {
  802. $model=LeadContacts::model()->findByPk($Id);
  803. }
  804. else
  805. {
  806. $model = LeadContacts::model()->findAll();
  807. }
  808. $model->status=$status;
  809. $model->save();
  810. $this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  811. }
  812. /**
  813. * This is the 'roles' action that is invoked
  814. * when an action is not explicitly requested by users.
  815. */
  816. public function actioncreate_lead()
  817. {
  818. $model = new Lead();
  819. $model->scenario = 'Lead';
  820. if (!empty($_GET['leadId']))
  821. {
  822. $leadId = $_GET['leadId'];
  823. $model = Lead::model()->findByPk($leadId);
  824. $chkrecentlyViewed = recentlyViewed::model()->findByAttributes(array('leadId' => $leadId, 'userId' => Yii::app()->session->get('id')));
  825. if (count($chkrecentlyViewed) == 0)
  826. {
  827. $recentlyViewed = new recentlyViewed;
  828. $recentlyViewed->setAttributes(array(
  829. 'userId' => Yii::app()->session->get('id'),
  830. 'leadId' => $leadId,
  831. 'moduleId' => 0,
  832. 'createdOn' => time(),
  833. 'updatedOn' => time(),
  834. 'updatedBy' => Yii::app()->session->get('id'),
  835. 'createdBy' => Yii::app()->session->get('id'),
  836. ));
  837. $recentlyViewed->save(false);
  838. }
  839. }
  840. if (!empty($_POST['Lead']['leadId']))
  841. {
  842. $leadId = $_POST['Lead']['leadId'];
  843. $model = Lead::model()->findByPk($leadId);
  844. }
  845. if (isset($_POST['Lead']))
  846. {
  847. $model->setAttributes(array(
  848. 'createdOn' => time(), //additional data you want to insert
  849. 'updatedOn' => time(), //additional
  850. 'updatedBy' => Yii::app()->session->get('id'), //additional
  851. 'createdBy' => Yii::app()->session->get('id'),
  852. ));
  853. foreach ($_POST['Lead'] as $name => $value)
  854. {
  855. $model->$name = $value;
  856. if ($model->leadStatusId == '')
  857. {
  858. $model->leadStatusId = $model->leadStatusParentId;
  859. }
  860. if ($model->leadStatusId == '')
  861. {
  862. $model->leadStatusId = 34;
  863. }
  864. if ($model->mobile == 'Mobile*')
  865. {
  866. $model->mobile = '';
  867. }
  868. if ($model->email == 'Email')
  869. {
  870. $model->email = '';
  871. }
  872. if ($model->name == 'Name')
  873. {
  874. $model->name = '';
  875. }
  876. if ($model->address == 'Address')
  877. {
  878. $model->address = '';
  879. }
  880. if ($model->children == "Children (Less than 25 Yrs)")
  881. {
  882. $model->children = '';
  883. }
  884. if ($model->ageGroup == "Age of eldest member")
  885. {
  886. $model->ageGroup = '';
  887. }
  888. }
  889. if ($model->leadStatusParentId == '1')
  890. {
  891. $model->salesClosedUpdatedOn = time();
  892. }
  893. if ($model->leadSourceId == '' or empty($model->leadSourceId))
  894. {
  895. $model->leadSourceId = '2';
  896. }
  897. $fetchAgentDetails = LeadSourceMaster::model()->findByPk($model->leadSourceId);
  898. $model->agentId = @$fetchAgentDetails->leadSourceCode;
  899. $model->ws_agentid = @$fetchAgentDetails->leadSourceCode;
  900. if (Yii::app()->session->get('isAllocator') != 'yes' and Yii::app()->session->get('type') != 'superadmin')
  901. {
  902. @$model->leadStatusId = 35;
  903. @$model->currentAllocatedId = Yii::app()->session->get('id');
  904. }
  905. if (@$leadId != '' && $model->leadStatusId != '34')
  906. {
  907. $update = Yii::app()->db->createCommand("update `lead` set `isRead`='yes' where `leadId`='$leadId' and currentAllocatedId > 0")->query();
  908. }
  909. if (@$_POST['Lead']['emailOptOut'] == 'on')
  910. {
  911. $model->emailOptOut = 'Y';
  912. }
  913. else
  914. {
  915. $model->emailOptOut = 'N';
  916. }
  917. if (@$_POST['Lead']['mobileOptOut'] == 'on')
  918. {
  919. $model->mobileOptOut = 'Y';
  920. }
  921. else
  922. {
  923. $model->mobileOptOut = 'N';
  924. }
  925. if (@$_POST['Lead']['isJunk'] == 'on')
  926. {
  927. $model->isJunk = 'yes';
  928. }
  929. else
  930. {
  931. $model->isJunk = 'no';
  932. }
  933. if (@$_POST['Lead']['isDuplicate'] == 'on')
  934. {
  935. $model->isDuplicate = 'yes';
  936. }
  937. else
  938. {
  939. $model->isDuplicate = 'no';
  940. }
  941. if (@$_POST['Lead']['status'] == 'on')
  942. {
  943. $model->status = 'Close';
  944. }
  945. else
  946. {
  947. $model->status = 'Active';
  948. }
  949. $chkStatusMandatoryOrNot = leadStatus::model()->findByAttributes(array('leadStatusId' => $model->leadStatusId));
  950. if (count($chkStatusMandatoryOrNot) > 0)
  951. {
  952. $condMandatory = $chkStatusMandatoryOrNot['compulsary'];
  953. if ($condMandatory == 'No')
  954. {
  955. if ($model->validate(array('mobile')))
  956. {
  957. $mobileNumber = @$_POST['Lead']['mobile'];
  958. $checkJunkNumber = JunkNumbersMaster::model()->find('junkLeadNumber = "' . @$mobileNumber . '"');
  959. if (empty($checkJunkNumber))
  960. {
  961. $beforethreemonth = time() - 7776000;
  962. $checkDuplicateNumber = Lead::model()->find('mobile = "' . @$mobileNumber . '" AND createdOn > "' . @$beforethreemonth . '" AND status = "Active" AND leadId != "' . @$leadId . '" ');
  963. if (empty($checkDuplicateNumber))
  964. {
  965. $model->save(false);
  966. Yii::app()->user->setFlash('lead_msg_success', 'Successfully Inserted');
  967. }
  968. else
  969. {
  970. $duplicateLeadId = $checkDuplicateNumber->leadId;
  971. $model->leadStatusId = '10';
  972. $model->duplicateLeadId = @$duplicateLeadId;
  973. $model->currentAllocatedId = $checkDuplicateNumber->currentAllocatedId;
  974. $model->save(false);
  975. Yii::app()->user->setFlash('lead_msg_success', 'Successfully Inserted');
  976. }
  977. }
  978. else
  979. {
  980. $model->leadStatusId = '36';
  981. $model->save(false);
  982. Yii::app()->user->setFlash('lead_msg_success', 'Junk Lead');
  983. }
  984. self::updateLeadAllCount($model->leadStatusId);
  985. $this->redirect(array('leads/lead_list'));
  986. // $model->save(false);
  987. // $this->redirect(array('leads/lead_list'));
  988. }
  989. }
  990. }
  991. if ($model->leadStatusId == 36)
  992. {
  993. self::updateLeadAllCount($model->leadStatusId);
  994. $model->save(false);
  995. $this->redirect(array('leads/lead_list'));
  996. }
  997. else
  998. {
  999. if ($model->validate())
  1000. {
  1001. $mobileNumber = $_POST['Lead']['mobile'];
  1002. $checkJunkNumber = JunkNumbersMaster::model()->find('junkLeadNumber = "' . @$mobileNumber . '"');
  1003. if (empty($checkJunkNumber))
  1004. {
  1005. $beforethreemonth = time() - 7776000;
  1006. $checkDuplicateNumber = Lead::model()->find('mobile = "' . @$mobileNumber . '" AND createdOn > "' . @$beforethreemonth . '" AND status = "Active" AND leadId != "' . @$leadId . '" ');
  1007. if (empty($checkDuplicateNumber))
  1008. {
  1009. self::updateLeadAllCount($model->leadStatusId);
  1010. $model->save();
  1011. Yii::app()->user->setFlash('lead_msg_success', 'Successfully Inserted');
  1012. }
  1013. else
  1014. {
  1015. $duplicateLeadId = $checkDuplicateNumber->leadId;
  1016. $model->leadStatusId = '10';
  1017. $model->duplicateLeadId = @$duplicateLeadId;
  1018. self::updateLeadAllCount($model->leadStatusId);
  1019. $model->save();
  1020. Yii::app()->user->setFlash('lead_msg_success', 'Successfully Inserted');
  1021. }
  1022. }
  1023. else
  1024. {
  1025. $model->leadStatusId = '36';
  1026. self::updateLeadAllCount($model->leadStatusId);
  1027. $model->save();
  1028. Yii::app()->user->setFlash('lead_msg_success', 'Junk Lead');
  1029. }
  1030. $this->redirect(array('leads/lead_list'));
  1031. }
  1032. else
  1033. {
  1034. $this->render('create_lead', array('model' => $model));
  1035. }
  1036. }
  1037. }
  1038. else
  1039. {
  1040. $this->render('create_lead', array('model' => $model));
  1041. }
  1042. }
  1043. /**
  1044. * AllocateLeads.
  1045. * @return void
  1046. */
  1047. public function actionAllocateLeads()
  1048. {
  1049. $Id = $_REQUEST['userids'];
  1050. $teamId = @$_REQUEST['Team']['teamId'];
  1051. $userId = $_REQUEST['Team']['teamMemberId'];
  1052. $updatedBy = @$_SESSION['id'];
  1053. $userdetails = Yii::app()->db->createCommand("select firstName,lastName from user where id=" . $userId . " ")->queryAll();
  1054. $actionurl = @$_REQUEST['actionurl'];
  1055. $paginationsize = Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize'])?Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']):25;
  1056. $myArray = array();
  1057. $responseAll = array();
  1058. $t = 0;
  1059. $teamIdString = @$teamId ? '' : ",teamId = $teamId, ";
  1060. //Yii::app()->db->createCommand('START TRANSACTION;')->execute();
  1061. foreach ($Id as $key => $value)
  1062. {
  1063. $model = new AllocatedLeads();
  1064. $model->scenario = 'AllocatedLeads';
  1065. $model->setAttributes(array(
  1066. 'currentAllocatedDate' => time(), //additional data you want to insert
  1067. 'createdOn' => time(), //additional data you want to insert
  1068. 'updatedOn' => time(), //additional
  1069. 'updatedBy' => @$updatedBy, //additional
  1070. 'createdBy' => @$updatedBy, //additional
  1071. 'leadStatusId' => '35', //additional //additional
  1072. ));
  1073. $leadId = @$value;
  1074. $model->leadId = @$value;
  1075. $model->userId = @$userId;
  1076. $model->teamId = @$teamId;
  1077. //echo @$teamId.' - '.@$userId.' - '.@$leadId;
  1078. $model->allocatedId = null;
  1079. $model->isNewRecord = true;
  1080. $model->save();
  1081. /* Comment by shakti as handled below
  1082. $model = new Lead();
  1083. $model->scenario = 'Lead';
  1084. */
  1085. //currentAllocateId is getting updated so update it after all processessing.
  1086. /*
  1087. $updatedOn = time();
  1088. Lead::model()->updateByPk(@$value, array('currentAllocatedId' => @$userId, 'leadStatusId' => '35', 'updatedBy' => @$updatedBy, 'updatedOn' => @$updatedOn, 'currentAllocatedDate' => @$updatedOn));
  1089. */
  1090. // $responseAll[$t]['ownername'] = $userdetails[0]['firstName'] . $userdetails[0]['lastName'];
  1091. // $responseAll[$t]['classname'] = "owner_" . @$value;
  1092. // $responseAll[$t]['rowclass'] = @$value;
  1093. // $myArray[0][$t] = $responseAll[$t];
  1094. // $myArray[1]['roleId'] = Yii::app()->session->get('roleId');
  1095. // $myArray[2]['actionurl']=$actionurl;
  1096. // $myArray[3]['paginationsize']=$paginationsize;
  1097. // $t++;
  1098. $leadRecord = Yii::app()->db->createCommand("select leadStatusId, currentAllocatedId from lead where leadId = $value")->queryRow();
  1099. $leadStatus = $leadRecord['leadStatusId'];
  1100. $currentAllocatedId = $leadRecord['currentAllocatedId'];
  1101. $updatedOn = time();
  1102. if(BaseController::getConfigurationValue('leadallcount'))
  1103. {
  1104. //if (Yii::app()->session->get('type') == 'Superadmin')
  1105. if ($leadStatus == 34 || (Yii::app()->session->get('type') == 'superadmin' && $leadStatus == 10))
  1106. {
  1107. //Super : status 34(new)/10(duplicate) count decrement
  1108. Yii::app()->db->createCommand("update leadallcount set count = count - 1, updatedOn = $updatedOn, updatedBy = $updatedBy
  1109. where userid = 1 && accesskey = '" . date('Y') . '-' . date('m') . "' && leadtype = $leadStatus")->execute();
  1110. Yii::app()->db->createCommand("update leadallcount set count = count - 1, updatedOn = $updatedOn, updatedBy = $updatedBy
  1111. where userid = 1 && accesskey = '" . date('Y') . "' && leadtype = $leadStatus")->execute();
  1112. //Super : status 35(allocated) count increment
  1113. Yii::app()->db->createCommand("update leadallcount set count = count + 1, updatedOn = $updatedOn, updatedBy = $updatedBy
  1114. where userid = 1 && accesskey = '" . date('Y') . '-' . date('m') . "' && leadtype = 35")->execute();
  1115. Yii::app()->db->createCommand("update leadallcount set count = count + 1, updatedOn = $updatedOn, updatedBy = $updatedBy
  1116. where userid = 1 && accesskey = '" . date('Y') . "' && leadtype = 35")->execute();
  1117. //New Allocated Teamlead : status 35(allocated) count increment
  1118. Yii::app()->db->createCommand("update leadallcount set count = count + 1, updatedOn = $updatedOn, updatedBy = $updatedBy
  1119. where userid = $userId && accesskey = '" . date('Y') . '-' . date('m') . "' && leadtype = 35")->execute();
  1120. Yii::app()->db->createCommand("update l…

Large files files are truncated, but you can click here to view the full file