PageRenderTime 59ms CodeModel.GetById 19ms RepoModel.GetById 1ms 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

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

  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 =

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