PageRenderTime 96ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/lms_debug/protected/controllers/LeadsController_2ndJan15.php

https://gitlab.com/badelal143/lms_debug
PHP | 4693 lines | 3531 code | 815 blank | 347 comment | 667 complexity | f5679e01b4b9a006cffd0acf7a3fb6c2 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, LGPL-2.0

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

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