PageRenderTime 29ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

/lms_debug/protected/controllers/DashboardController.php

https://gitlab.com/badelal143/lms_debug
PHP | 1545 lines | 1245 code | 173 blank | 127 comment | 161 complexity | e0ccb9a4e328b23d28f38e3c561ca824 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 DashboardController 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' => array(
  20. 'class' => 'CCaptchaAction',
  21. 'backColor' => 0xFFFFFF,
  22. ),
  23. // page action renders "static" pages stored under 'protected/views/site/pages'
  24. // They can be accessed via: index.php?r=site/page&view=FileName
  25. 'page' => array(
  26. 'class' => 'CViewAction',
  27. ),
  28. );
  29. }
  30. /**
  31. * This is the 'roles' action that is invoked
  32. * when an action is not explicitly requested by users.
  33. */
  34. protected function array_flatten($array)
  35. {
  36. if (!is_array($array))
  37. {
  38. return FALSE;
  39. }
  40. $result = array();
  41. foreach ($array as $key => $value)
  42. {
  43. if (is_array($value))
  44. {
  45. $result = array_merge($result, $this->array_flatten($value));
  46. }
  47. else
  48. {
  49. $result[$key] = $value;
  50. }
  51. }
  52. return $result;
  53. }
  54. /**
  55. * Action dashboard.
  56. */
  57. public function actiondashboard()
  58. {
  59. $financialyear = @$_POST['financialyear'] ? $_POST['financialyear'] : date('Y');
  60. $month = date('m');
  61. if(BaseController::getConfigurationValue('leadallcount'))
  62. {
  63. self::insertUsersRecord($financialyear);
  64. }
  65. if (empty(Yii::app()->session['id']) or Yii::app()->session['id'] == '')
  66. {
  67. $this->redirect(array('site/index'));
  68. }
  69. $leadCond = '';
  70. $PiechartCond = '';
  71. $NotificationCond1 = '';
  72. $NotificationCond2 = '';
  73. $currentDateNot = date('d-m-Y');
  74. $currentTimestamp = strtotime($currentDateNot);
  75. if (isset($_POST['searchDashboard']) && !empty($_POST['searchDashboard']))
  76. {
  77. $searchDate = $_POST['searchDashboard'];
  78. $searchTimestamp = strtotime(@$searchDate);
  79. $searchEndTimestamp = $searchTimestamp + 86400;
  80. $leadCond = " and lead.updatedOn >= '" . @$searchTimestamp . "' and lead.updatedOn < '" . @$searchEndTimestamp . "'";
  81. $PiechartCond = " and leadSourceMaster.updatedOn >= '" . @$searchTimestamp . "' and leadSourceMaster.updatedOn < '" . @$searchEndTimestamp . "'";
  82. $NotificationCond1 = " and notification.updatedOn >= '" . @$searchTimestamp . "' and notification.updatedOn < '" . @$searchEndTimestamp . "' AND (STR_TO_DATE('$currentDateNot', '%d-%m-%Y') >= STR_TO_DATE(notification.startDate, '%d-%m-%Y') AND STR_TO_DATE(notification.endDate, '%d-%m-%Y') >= STR_TO_DATE('$currentDateNot', '%d-%m-%Y') )";
  83. $NotificationCond2 = " and notification.updatedOn >= '" . @$searchTimestamp . "' and notification.updatedOn < '" . @$searchEndTimestamp . "' AND (STR_TO_DATE('$currentDateNot', '%d-%m-%Y') >= STR_TO_DATE(notification.startDate, '%d-%m-%Y') AND STR_TO_DATE(notification.endDate, '%d-%m-%Y') >= STR_TO_DATE('$currentDateNot', '%d-%m-%Y') )";
  84. }
  85. if (Yii::app()->session->get('isAllocator') == 'yes' or Yii::app()->session->get('type') == 'superadmin' or Yii::app()->session->get('roleId') == 1)
  86. {
  87. $LeasStatusCond = '';
  88. }
  89. else
  90. {
  91. $LeasStatusCond = ' AND lead.currentAllocatedId = ' . Yii::app()->session->get('id') . '';
  92. }
  93. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1);
  94. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"));
  95. $CurrentYear_first_minute = mktime(0, 0, 0, 1, 1, date('Y'));
  96. $CurrentYear_last_minute = mktime(0, 0, 0, 13, 0, date('Y'));
  97. $where = '';
  98. if (Yii::app()->session->get('type') != 'superadmin')
  99. {
  100. $where = ' where notificationMapping.roleId="' . Yii::app()->session->get('roleId') . '"';
  101. $cls = " AND (STR_TO_DATE('$currentDateNot', '%d-%m-%Y') >= STR_TO_DATE(notification.startDate, '%d-%m-%Y') AND STR_TO_DATE(notification.endDate, '%d-%m-%Y') >= STR_TO_DATE('$currentDateNot', '%d-%m-%Y') )";
  102. $notifications = Yii::app()->db->createCommand("select notification.* from notification left join notificationMapping on notificationMapping.notificationId=notification.notificationId $where " . $NotificationCond1 . " " . @$cls . " group by notification.notificationId ")->queryAll();
  103. }
  104. else
  105. {
  106. $cls = " WHERE (STR_TO_DATE('$currentDateNot', '%d-%m-%Y') >= STR_TO_DATE(notification.startDate, '%d-%m-%Y') AND STR_TO_DATE(notification.endDate, '%d-%m-%Y') >= STR_TO_DATE('$currentDateNot', '%d-%m-%Y') )";
  107. $notifications = Yii::app()->db->createCommand("select notification.* from notification left join notificationMapping on notificationMapping.notificationId=notification.notificationId " . @$cls . " " . $NotificationCond2 . " group by notification.notificationId ")->queryAll();
  108. }
  109. $ManagerDetails = Yii::app()->db->createCommand("select user.managerId,user.Id,user.userName from user where managerId='" . Yii::app()->session->get('id') . "'")->queryAll();
  110. $total_firstLevel = array();
  111. $total_nextLevel = array();
  112. $managerIds = self::fetchAllmanagerLevelRecords($total_firstLevel, $ManagerDetails, Yii::app()->session->get('id'));
  113. if (empty($managerIds))
  114. {
  115. $managerIds[] = $_SESSION['id'];
  116. }
  117. else
  118. {
  119. $pusharray = array();
  120. $pusharray[] = @$_SESSION['id'];
  121. $managerIds = array_unique(array_merge(@$managerIds, @$pusharray));
  122. }
  123. if (strtolower(Yii::app()->session->get('roleName')) == "teamleader")
  124. {
  125. $teamLeaderTeamUserIdsRes = array();
  126. $teamLeaderTeamUserIds = Yii::app()->db->createCommand("select id as userId from user where id IN (select distinct userId from teamUserMapping where teamId IN (select distinct teamId from teamUserMapping where userId='" . Yii::app()->session->get('id') . "') ) and status='Active' and type!='superadmin' ")->queryAll();
  127. if (count($teamLeaderTeamUserIds) > 0)
  128. {
  129. foreach ($teamLeaderTeamUserIds as $keyd => $valued)
  130. {
  131. $teamLeaderTeamUserIdsRes[] = $valued['userId'];
  132. }
  133. $managerIds = array_unique(array_merge($managerIds, $teamLeaderTeamUserIdsRes));
  134. }
  135. }
  136. $managerDetailsArr = self::ManagerDetails($managerIds);
  137. Yii::app()->session['relationalManager'] = $managerIds;
  138. //$sourcewiseDetailsWithPiechart=Yii::app()->db->createCommand("SELECT leadSourceMaster.*,count(*) as total FROM `leadSourceMaster` left join lead on leadSourceMaster.leadSourceId=lead.leadSourceId where leadSourceMaster.status='Active' ".$PiechartCond." group by leadSourceMaster.leadSourceId ")->queryAll();
  139. $speedmeterUser = @$_REQUEST['speedmeterUser'];
  140. if (isset($speedmeterUser) && !empty($speedmeterUser))
  141. {
  142. $totalAmountOfSpeedometer = Lead::model()->closedLeadsAmount($speedmeterUser);
  143. }
  144. else
  145. {
  146. $totalAmountOfSpeedometer = 0;
  147. }
  148. $LeadStatusSql = "SELECT ls.leadstatus,ls.leadstatusId,ls.sortOrder FROM `leadstatus` ls where ls.status='Active' order by ls.sortOrder ASC ";
  149. $count = Yii::app()->db->createCommand($LeadStatusSql)->queryAll();
  150. $dataProviderc = new CSqlDataProvider($LeadStatusSql, array(
  151. 'keyField' => 'leadstatusId',
  152. 'totalItemCount' => count($count),
  153. 'sort' => array(
  154. 'attributes' => array(
  155. 'leadStatusId',
  156. ),
  157. ),
  158. 'pagination' => array(
  159. 'pageSize' => 10,
  160. 'pageVar' => 'gyu', //page selector
  161. ),
  162. ));
  163. //Required Variables
  164. $today12PM = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
  165. $tomorrow12PM = mktime(0, 0, 0, date("m"), date("d"), date("Y")) + 86400;
  166. $yesterday12PM = mktime(0, 0, 0, date("m"), date("d"), date("Y")) - 86400;
  167. $LastMonth_first_minute = mktime(0, 0, 0, date("n") - 1, 1);
  168. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1);
  169. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"));
  170. $filtercaller = @$_REQUEST['User']['userName'];
  171. $filtersource = @$_REQUEST['LeadSourceMaster']['leadSourceId'];
  172. $filterdate1 = @$_REQUEST['Lead']['createdOn'];
  173. $filterdate2 = @$_REQUEST['Lead']['createdOn2'];
  174. $filterCond = '';
  175. if (isset($_POST['searchDashboard']))
  176. {
  177. $searchDate = $_POST['searchDashboard'];
  178. }
  179. else
  180. {
  181. $searchDate = date('Y');
  182. }
  183. $searchTimestamp = strtotime(@$searchDate);
  184. $searchEndTimestamp = $searchTimestamp + 86400;
  185. $leadCond = " and lead.updatedOn >= '" . @$searchTimestamp . "' and lead.updatedOn < '" . @$searchEndTimestamp . "'";
  186. if (isset($filtercaller) && !empty($filtercaller))
  187. {
  188. $filterCond .= " AND lead.currentAllocatedId = " . $filtercaller . "";
  189. }
  190. if (isset($filtersource) && !empty($filtersource))
  191. {
  192. $filterCond .= " AND lead.leadSourceId = " . $filtersource . "";
  193. }
  194. if (isset($filterdate1) && !empty($filterdate1) && isset($filterdate2) && !empty($filterdate2))
  195. {
  196. $date1Filer = strtotime($filterdate1);
  197. $date2Filer = strtotime($filterdate2);
  198. $filterCond .= " AND lead.updatedOn >= " . $date1Filer . " AND lead.updatedOn <= " . $date2Filer . "";
  199. }
  200. if (Yii::app()->session->get('isAllocator') == 'yes')
  201. {
  202. $allocatorTl = Yii::app()->db->createCommand("select group_concat(distinct id) as TLIDS from user where roleId=4")->queryAll();
  203. $impresuser = @$allocatorTl[0]['TLIDS'];
  204. }
  205. else
  206. {
  207. $impresuser = Yii::app()->getController()->implodeResult(Yii::app()->session['relationalManager']);
  208. }
  209. //Required Variables
  210. $this->render('dashboard', array('LeadStatus' => @$LeadStatus, 'notifications' => @$notifications, 'managerDetailsArr' => @$managerDetailsArr, 'totalAmountOfSpeedometer' => @$totalAmountOfSpeedometer, 'dataProviderc' => $dataProviderc, 'dataProvideradmin' => @$dataProvideradmin, 'impresuser' => @$impresuser));
  211. }
  212. /**
  213. * Get Lead Status Count.(Eg Manager, add leadtypecount of all Teamleaders & Teamleader, add leadtypecount of all callers).
  214. * @see _leadfortoday.php
  215. * @return int
  216. */
  217. public static function getLeadStatusCount($leadStatusId, $accessKey)
  218. {
  219. $userList = $userId = Yii::app()->session['id'];
  220. if(Yii::app()->session->get('roleId') != 3)
  221. {
  222. $userList = User::getMemebersList();
  223. if(count($userList))
  224. {
  225. $allCallersList = array();
  226. $lCount = array();
  227. foreach($userList as $list)
  228. {
  229. $allCallersList[] = $list['id'];
  230. }
  231. $userList = implode(', ', $allCallersList);
  232. //print $userList . '==';
  233. $totalCount = Yii::app()->db->createCommand("select sum(count) as count from leadallcount where userid in ( $userList ) AND leadtype = $leadStatusId AND accesskey = '$accessKey'")->queryRow();
  234. return $totalCount['count'];
  235. }
  236. }
  237. $count = Yii::app()->db->createCommand("select sum(count) as count from leadallcount where userid = $userId AND leadtype = $leadStatusId AND accesskey = '$accessKey'")->queryRow();
  238. return $count['count'];
  239. }
  240. /**
  241. * Insert Users Record (Eg. call this method to insert all callers and the logged in teamleader (callers, teamleader & logged in manager)).
  242. * @see _leadfortoday.php
  243. * @return int
  244. */
  245. public static function insertUsersRecord($accessKey)
  246. {
  247. $userList = User::getMemebersList();
  248. $financialDate = explode('-', $accessKey);
  249. $financialDate[0] = $financialDate[0] ? $financialDate[0] : date('Y');
  250. $financialDate[1] = @$financialDate[1] ? $financialDate[1] : date('m');
  251. if (count($userList))
  252. {
  253. foreach ($userList as $list)
  254. {
  255. self::insertUserLeadAllCountRecord($financialDate[0], $financialDate[1], $list['id']);
  256. }
  257. }
  258. else if (Yii::app()->session->get('type') == 'superadmin')
  259. {
  260. self::insertUserLeadAllCountRecord($financialDate[0], $financialDate[1], Yii::app()->session['id']);
  261. }
  262. }
  263. /**
  264. * Get monthly lead count of User by leadstatus.
  265. * @param int $leadStatusId
  266. * @param int $userId
  267. * @return int
  268. */
  269. public static function getMTDForUser($leadStatusId, $userId)
  270. {
  271. if (Yii::app()->session->get('type') == 'superadmin')
  272. {
  273. $cond = '';
  274. }
  275. else
  276. {
  277. if (count(@$_SESSION['relationalManager']) > 0)
  278. {
  279. $teamids = implode(",", $_SESSION['relationalManager']);
  280. }
  281. else
  282. {
  283. $teamids = Yii::app()->session->get('id');
  284. }
  285. $cond = "AND l.currentAllocatedId = " . $userId;
  286. }
  287. $financialyear = @$_POST['financialyear'];
  288. if (isset($financialyear) && !empty($financialyear))
  289. {
  290. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1, $financialyear);
  291. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"), $financialyear);
  292. }
  293. else
  294. {
  295. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1);
  296. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"));
  297. }
  298. $sql = "select count(leadId) as total from lead l join user u on u.id=l.currentAllocatedId where l.leadStatusId = " . $leadStatusId . " and (l.updatedOn between '" . @$CurrentMonth_first_minute . "' and '" . @$CurrentMonth_last_minute . "') and u.status='Active' $cond limit 1 ";
  299. $count = Yii::app()->db->createCommand($sql)->queryColumn();
  300. return @$count[0];
  301. }
  302. /**
  303. * Get yearly lead count of User by leadstatus.
  304. * @param int $leadStatusId
  305. * @param int $userId
  306. * @return int
  307. */
  308. public static function getYTDForUser($leadStatusId, $userId)
  309. {
  310. if (Yii::app()->session->get('type') == 'superadmin')
  311. {
  312. $cond = '';
  313. }
  314. else
  315. {
  316. if (count(@$_SESSION['relationalManager']) > 0)
  317. {
  318. $teamids = implode(",", $_SESSION['relationalManager']);
  319. }
  320. else
  321. {
  322. $teamids = Yii::app()->session->get('id');
  323. }
  324. $cond = "AND l.currentAllocatedId = " . $userId;
  325. }
  326. $financialyear = @$_POST['financialyear'];
  327. if (isset($financialyear) && !empty($financialyear))
  328. {
  329. $CurrentYear_first_minute = mktime(0, 0, 0, 4, 1, $financialyear);
  330. $CurrentYear_last_minute = mktime(0, 0, 0, 4, 0, $financialyear + 1);
  331. }
  332. else
  333. {
  334. $CurrentYear_first_minute = mktime(0, 0, 0, 4, 1, date('Y'));
  335. $CurrentYear_last_minute = mktime(0, 0, 0, 4, 0, date('Y') + 1);
  336. }
  337. $sql = "select count(leadId) as total from lead l join user u on u.id=l.currentAllocatedId where l.leadStatusId = " . $leadStatusId . " and (l.updatedOn between '" . @$CurrentYear_first_minute . "' and '" . @$CurrentYear_last_minute . "') and u.status='Active' $cond ";
  338. $count = Yii::app()->db->createCommand($sql)->queryColumn();
  339. return @$count[0];
  340. }
  341. /**
  342. * This is the 'module master' action that is invoked
  343. * when an action is not explicitly requested by users.
  344. */
  345. public function actionmodule_master()
  346. {
  347. // renders the view file 'protected/views/site/index.php'
  348. // using the default layout 'protected/views/layouts/main.php'
  349. $model = new ModuleMaster();
  350. $model->scenario = 'ModuleMaster';
  351. if (!empty($_GET['moduleId']))
  352. {
  353. $moduleId = $_GET['moduleId'];
  354. $model = ModuleMaster::model()->findByPk($moduleId);
  355. }
  356. if (!empty($_POST['ModuleMaster']['moduleId']))
  357. {
  358. $moduleId = $_POST['ModuleMaster']['moduleId'];
  359. $model = ModuleMaster::model()->findByPk($moduleId);
  360. }
  361. if (isset($_POST['ModuleMaster']))
  362. {
  363. $model->setAttributes(array(
  364. 'createdOn' => time(), //additional data you want to insert
  365. 'updatedOn' => time(), //additional
  366. 'updatedBy' => time(), //additional
  367. 'createdBy' => time(),
  368. 'status' => 'Activated', //additional //additional
  369. ));
  370. foreach ($_POST['ModuleMaster'] as $name => $value)
  371. {
  372. $model->$name = $value;
  373. }
  374. if ($model->validate())
  375. {
  376. $model->save();
  377. $model2 = ModuleMaster::model()->findAll();
  378. $this->render('module_master', array('model' => $model, 'model2' => $model2));
  379. Yii::app()->user->setFlash('module_master_msg_success', 'Successfully Inserted');
  380. }
  381. else
  382. {
  383. Yii::app()->user->setFlash('module_master_msg_error', 'Please check. error occured');
  384. $this->render('module_master', array('model' => $model));
  385. }
  386. }
  387. else
  388. {
  389. $model2 = ModuleMaster::model()->findAll();
  390. //Yii::app()->user->setFlash('lead_stage_msg_error','Please check. error occured');
  391. $this->render('module_master', array('model' => $model, 'model2' => $model2));
  392. }
  393. }
  394. /**
  395. * This is the action to handle external exceptions.
  396. */
  397. public function actionError()
  398. {
  399. if ($error = Yii::app()->errorHandler->error)
  400. {
  401. if (Yii::app()->request->isAjaxRequest)
  402. echo $error['message'];
  403. else
  404. $this->render('error', $error);
  405. }
  406. }
  407. /**
  408. * Displays the contact page
  409. */
  410. public function actionContact()
  411. {
  412. $model = new ContactForm;
  413. if (isset($_POST['ContactForm']))
  414. {
  415. $model->attributes = $_POST['ContactForm'];
  416. if ($model->validate())
  417. {
  418. $name = '=?UTF-8?B?' . base64_encode($model->name) . '?=';
  419. $subject = '=?UTF-8?B?' . base64_encode($model->subject) . '?=';
  420. $headers = "From: $name <{$model->email}>\r\n" .
  421. "Reply-To: {$model->email}\r\n" .
  422. "MIME-Version: 1.0\r\n" .
  423. "Content-type: text/plain; charset=UTF-8";
  424. mail(Yii::app()->params['adminEmail'], $subject, $model->body, $headers);
  425. Yii::app()->user->setFlash('contact', 'Thank you for contacting us. We will respond to you as soon as possible.');
  426. $this->refresh();
  427. }
  428. }
  429. $this->render('contact', array('model' => $model));
  430. }
  431. /**
  432. * Displays the login page
  433. */
  434. public function actionLogin()
  435. {
  436. $model = new User;
  437. // if it is ajax validation request
  438. if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form')
  439. {
  440. echo CActiveForm::validate($model);
  441. Yii::app()->end();
  442. }
  443. // collect user input data
  444. if (isset($_POST['User']))
  445. {
  446. $model->attributes = $_POST['User'];
  447. // validate user input and redirect to the previous page if valid
  448. if ($model->validate() && $model->login())
  449. {
  450. $this->redirect(array('masters/dashboard'));
  451. }
  452. else
  453. {
  454. $this->redirect(Yii::app()->user->returnUrl);
  455. }
  456. }
  457. // display the login form
  458. $this->render('login', array('model' => $model));
  459. }
  460. /**
  461. * Logs out the current user and redirect to homepage.
  462. */
  463. public function actionLogout()
  464. {
  465. Yii::app()->user->logout();
  466. $this->redirect(Yii::app()->homeUrl);
  467. }
  468. public function getPageType()
  469. {
  470. return "";
  471. }
  472. public function actionViewFancyboxData()
  473. {
  474. $userId = @$_REQUEST['id'];
  475. $model = new User;
  476. $model = User::model()->findByPk($userId);
  477. if (!Yii::app()->request->isAjaxRequest)
  478. {
  479. // $this->render('yourView');
  480. }
  481. else
  482. {
  483. $this->renderPartial('/masters/partialNotification');
  484. Yii::app()->end();
  485. }
  486. }
  487. public function actionViewWorkLoadData()
  488. {
  489. if (!Yii::app()->request->isAjaxRequest)
  490. {
  491. echo "ddd";
  492. // $this->render('/leads/partialWorkLoadData');
  493. // $this->render('yourView');
  494. }
  495. else
  496. {
  497. $this->renderPartial('/leads/partialWorkLoadData');
  498. Yii::app()->end();
  499. }
  500. }
  501. public function actionViewLeadSummaryData()
  502. {
  503. //$this->layout='column3';
  504. $this->layout = false;
  505. $parser = new CHtmlPurifier();
  506. $leadStatusId = $parser->purify(intval(@$_REQUEST['leadStatusId']));
  507. /* $model=new Lead;
  508. $model=Lead::model()->findAll("leadStatusId = '".@$leadStatusId."' ");
  509. */
  510. if (!Yii::app()->request->isAjaxRequest)
  511. {
  512. $this->render('/leads/partialLeadSummary', array('leadStatusId' => $leadStatusId));
  513. }
  514. else
  515. {
  516. $this->layout = false;
  517. $this->render('/leads/partialLeadSummary', array('leadStatusId' => $leadStatusId));
  518. Yii::app()->end();
  519. }
  520. }
  521. public function actionRenewalViewLeadSummaryData()
  522. {
  523. //$this->layout='column3';
  524. $this->layout = false;
  525. $res = new MySanitizeClass;
  526. $leadStatusId = $res->sanitize_description(@$_REQUEST['leadStatusId']);
  527. /* $model=new Lead;
  528. $model=Lead::model()->findAll("leadStatusId = '".@$leadStatusId."' ");
  529. */ if (!Yii::app()->request->isAjaxRequest)
  530. {
  531. $this->render('/renewalleads/renewalpartialLeadSummary', array('leadStatusId' => $leadStatusId));
  532. }
  533. else
  534. {
  535. //$this->layout=false;
  536. $this->render('/renewalleads/renewalpartialLeadSummary', array('leadStatusId' => $leadStatusId));
  537. Yii::app()->end();
  538. }
  539. }
  540. function getparentLeadStatus($parentId)
  541. {
  542. $primary = LeadStatus::model()->findByPk($parentId);
  543. if ($primary['parentId'] > 0)
  544. {
  545. $parentName = LeadStatus::model()->findByPk($primary['parentId']);
  546. $pname = $parentName['leadStatus'];
  547. }
  548. else
  549. {
  550. $pname = "Primary";
  551. }
  552. return $pname;
  553. }
  554. public function actionViewAllWorkLoadData()
  555. {
  556. function ManagerDetails($userIds)
  557. {
  558. $userIds = UserWithManagerIdsImploded($userIds);
  559. if ($userIds != '')
  560. {
  561. return Yii::app()->db->createCommand("select * from user where user.Id IN ($userIds) ")->queryAll();
  562. }
  563. }
  564. function UserWithManagerIdsImploded($userIds)
  565. {
  566. return $userIds = implode(",", $userIds);
  567. }
  568. $managerDetailsArr = ManagerDetails(Yii::app()->session['relationalManager']);
  569. if (!Yii::app()->request->isAjaxRequest)
  570. {
  571. // $this->render('yourView');
  572. }
  573. else
  574. {
  575. $this->renderPartial('/leads/partialAllWorkLoadData', array('managerDetailsArr' => $managerDetailsArr));
  576. Yii::app()->end();
  577. }
  578. }
  579. public function actionViewAllPerformanceData()
  580. {
  581. function ManagerDetails($userIds)
  582. {
  583. $userIds = UserWithManagerIdsImploded($userIds);
  584. if ($userIds != '')
  585. {
  586. return Yii::app()->db->createCommand("select * from user where user.Id IN ($userIds) ")->queryAll();
  587. }
  588. }
  589. function UserWithManagerIdsImploded($userIds)
  590. {
  591. return $userIds = implode(",", $userIds);
  592. }
  593. $managerDetailsArr = ManagerDetails(Yii::app()->session['relationalManager']);
  594. if (!Yii::app()->request->isAjaxRequest)
  595. {
  596. $this->render('/leads/partialAllPerfLoadData', array('managerDetailsArr' => $managerDetailsArr));
  597. // $this->render('yourView');
  598. }
  599. else
  600. {
  601. $this->renderPartial('/leads/partialAllPerfLoadData', array('managerDetailsArr' => $managerDetailsArr));
  602. Yii::app()->end();
  603. }
  604. }
  605. public function actionrenewal()
  606. {
  607. //$this->redirect(array('dashboard/dashboard'));
  608. $leadCond = '';
  609. $PiechartCond = '';
  610. $NotificationCond1 = '';
  611. $NotificationCond2 = '';
  612. $currentDateNot = date('d-m-Y');
  613. $currentTimestamp = strtotime($currentDateNot);
  614. if (isset($_POST['searchDashboard']) && !empty($_POST['searchDashboard']))
  615. {
  616. $searchDate = $_POST['searchDashboard'];
  617. $searchTimestamp = strtotime(@$searchDate);
  618. $searchEndTimestamp = $searchTimestamp + 86400;
  619. $leadCond = " and renewallead.updatedOn >= '" . @$searchTimestamp . "' and renewallead.updatedOn < '" . @$searchEndTimestamp . "'";
  620. $PiechartCond = " and renewalleadSourceMaster.updatedOn >= '" . @$searchTimestamp . "' and renewalleadSourceMaster.updatedOn < '" . @$searchEndTimestamp . "'";
  621. $NotificationCond1 = " and renewalnotification.updatedOn >= '" . @$searchTimestamp . "' and renewalnotification.updatedOn < '" . @$searchEndTimestamp . "' AND (STR_TO_DATE('$currentDateNot', '%d-%m-%Y') >= STR_TO_DATE(notification.startDate, '%d-%m-%Y') AND STR_TO_DATE(renewalnotification.endDate, '%d-%m-%Y') >= STR_TO_DATE('$currentDateNot', '%d-%m-%Y') )";
  622. $NotificationCond2 = " and renewalnotification.updatedOn >= '" . @$searchTimestamp . "' and renewalnotification.updatedOn < '" . @$searchEndTimestamp . "' AND (STR_TO_DATE('$currentDateNot', '%d-%m-%Y') >= STR_TO_DATE(renewalnotification.startDate, '%d-%m-%Y') AND STR_TO_DATE(renewalnotification.endDate, '%d-%m-%Y') >= STR_TO_DATE('$currentDateNot', '%d-%m-%Y') )";
  623. }
  624. if (Yii::app()->session->get('isAllocator') == 'yes' or Yii::app()->session->get('type') == 'superadmin')
  625. {
  626. $LeasStatusCond = '';
  627. }
  628. else
  629. {
  630. $LeasStatusCond = ' AND renewallead.currentAllocatedId = "' . Yii::app()->session->get('id') . '"';
  631. }
  632. $LeadStatus = Yii::app()->db->createCommand('SELECT
  633. me.leadStatusId AS me_id,
  634. me.leadStatus AS me_leadStatus,
  635. renewallead.leadStatusId AS lead_leadStatusId,
  636. renewallead.leadId AS leadId,
  637. count(*) AS total
  638. FROM
  639. renewalleadStatus me
  640. left join renewallead on renewallead.leadStatusId=me.leadStatusId where renewallead.leadStatusId > 0 ' . $leadCond . ' ' . $LeasStatusCond . ' group by renewallead.leadStatusId')->queryAll();
  641. $LeadStatusSql = "SELECT ls.leadstatus,ls.leadstatusId,ls.sortOrder FROM `renewalleadstatus` ls where ls.status='Active' order by ls.sortOrder ASC ";
  642. // $LeadStatusSql = "SELECT ls.leadstatus,ls.leadstatusId,ls.sortOrder,SUM(IF(lead.updatedOn >= '".@$CurrentMonth_first_minute."' and lead.updatedOn <= '".@$CurrentMonth_last_minute."' and ls.leadstatusId=lead.leadstatusId and u.status='Active',1,0)) as MTD,SUM(IF(lead.updatedOn >= '".@$CurrentYear_first_minute."' and lead.updatedOn <= '".@$CurrentYear_last_minute."' and u.status='Active',1,0)) as YTD FROM `leadstatus` ls join lead on lead.leadstatusId=ls.leadstatusId left join user u on u.id=lead.currentAllocatedId where ls.status='Active' ".$leadCond." ".$LeasStatusCond." group By lead.leadstatusId order by ls.sortOrder ASC";
  643. $count = Yii::app()->db->createCommand($LeadStatusSql)->queryAll();
  644. $dataProviderc = new CSqlDataProvider($LeadStatusSql, array(
  645. 'keyField' => 'leadstatusId',
  646. 'totalItemCount' => count($count),
  647. 'sort' => array(
  648. 'attributes' => array(
  649. 'leadStatusId',
  650. ),
  651. ),
  652. 'pagination' => array(
  653. 'pageSize' => 10,
  654. 'pageVar' => 'gyu', //page selector
  655. ),
  656. ));
  657. $where = '';
  658. if (Yii::app()->session->get('type') != 'superadmin')
  659. {
  660. $where = ' where renewalnotificationMapping.roleId="' . Yii::app()->session->get('roleId') . '"';
  661. $cls = " AND (STR_TO_DATE('$currentDateNot', '%d-%m-%Y') >= STR_TO_DATE(renewalnotification.startDate, '%d-%m-%Y') AND STR_TO_DATE(renewalnotification.endDate, '%d-%m-%Y') >= STR_TO_DATE('$currentDateNot', '%d-%m-%Y') )";
  662. $notifications = Yii::app()->db->createCommand("select renewalnotification.* from renewalnotification left join renewalnotificationMapping on renewalnotificationMapping.notificationId=renewalnotification.notificationId $where " . $NotificationCond1 . " " . @$cls . " group by renewalnotification.notificationId ")->queryAll();
  663. }
  664. else
  665. {
  666. $cls = " WHERE (STR_TO_DATE('$currentDateNot', '%d-%m-%Y') >= STR_TO_DATE(renewalnotification.startDate, '%d-%m-%Y') AND STR_TO_DATE(renewalnotification.endDate, '%d-%m-%Y') >= STR_TO_DATE('$currentDateNot', '%d-%m-%Y') )";
  667. $notifications = Yii::app()->db->createCommand("select renewalnotification.* from renewalnotification left join renewalnotificationMapping on renewalnotificationMapping.notificationId=renewalnotification.notificationId " . @$cls . " " . $NotificationCond2 . " group by renewalnotification.notificationId ")->queryAll();
  668. }
  669. $sourcewiseDetails = Yii::app()->db->createCommand("select renewalleadSourceMaster.* from renewalleadSourceMaster ")->queryAll();
  670. $ManagerDetails = Yii::app()->db->createCommand("select user.managerId,user.Id,user.userName from user where managerId='" . Yii::app()->session->get('id') . "'")->queryAll();
  671. function SecondLevel($managerId, $userId)
  672. {
  673. return Yii::app()->db->createCommand("select user.managerId,user.Id,user.userName from user where user.managerId='$managerId' and user.managerId!='$userId' ")->queryAll();
  674. }
  675. function ManagerLevel($userIds, $managerIds)
  676. {
  677. return Yii::app()->db->createCommand("select user.managerId,user.Id,user.userName from user where user.managerId ='$userIds' and id!='$managerIds' ")->queryAll();
  678. }
  679. function ManagerDetails($userIds)
  680. {
  681. $userIds = UserWithManagerIdsImploded($userIds);
  682. if ($userIds != '')
  683. {
  684. return Yii::app()->db->createCommand("select * from user where user.Id IN ($userIds) ")->queryAll();
  685. }
  686. }
  687. function UserWithManagerIdsImploded($userIds)
  688. {
  689. return $userIds = implode(",", $userIds);
  690. }
  691. $total_firstLevel = array();
  692. $total_nextLevel = array();
  693. function fetchAllmanagerLevelRecords(&$total_firstLevel, $ManagerDetails, $currentUserIds)
  694. {
  695. foreach ($ManagerDetails as $key => $value)
  696. {
  697. $total_firstLevel[] = $value['Id'];
  698. $total_res = SecondLevel($value['Id'], $currentUserIds);
  699. $res[] = count($total_res);
  700. if (count($total_res) > 0)
  701. {
  702. $o = 0;
  703. foreach ($total_res as $key1 => $value1)
  704. {
  705. $total_firstLevel[] = $value1['Id'];
  706. $net_res = fetchAllmanagerLevelRecords($total_firstLevel, ManagerLevel($value1['Id'], Yii::app()->session->get('id')), Yii::app()->session->get('id'));
  707. $o++;
  708. }
  709. }
  710. }
  711. return $total_firstLevel;
  712. }
  713. $managerIds = fetchAllmanagerLevelRecords($total_firstLevel, $ManagerDetails, Yii::app()->session->get('id'));
  714. if (empty($managerIds))
  715. {
  716. $managerIds[] = $_SESSION['id'];
  717. }
  718. else
  719. {
  720. $pusharray = array();
  721. $pusharray[] = @$_SESSION['id'];
  722. $managerIds = array_unique(array_merge(@$managerIds, @$pusharray));
  723. }
  724. if (strtolower(Yii::app()->session->get('roleName')) == "teamleader")
  725. {
  726. $teamLeaderTeamUserIdsRes = array();
  727. $teamLeaderTeamUserIds = Yii::app()->db->createCommand("select id as userId from user where id IN (select distinct userId from renewalteamUserMapping where teamId IN (select distinct teamId from renewalteamUserMapping where userId='" . Yii::app()->session->get('id') . "') ) and status='Active' and type!='superadmin' ")->queryAll();
  728. if (count($teamLeaderTeamUserIds) > 0)
  729. {
  730. foreach ($teamLeaderTeamUserIds as $keyd => $valued)
  731. {
  732. $teamLeaderTeamUserIdsRes[] = $valued['userId'];
  733. }
  734. $managerIds = array_unique(array_merge($managerIds, $teamLeaderTeamUserIdsRes));
  735. }
  736. }
  737. $managerDetailsArr = ManagerDetails($managerIds);
  738. Yii::app()->session['relationalManager'] = $managerIds;
  739. $sourcewiseDetailsWithPiechart = Yii::app()->db->createCommand("SELECT renewalleadSourceMaster.*,count(*) as total FROM `renewalleadSourceMaster` left join renewallead on renewalleadSourceMaster.leadSourceId=renewallead.leadSourceId where renewalleadSourceMaster.status='Active' " . $PiechartCond . " group by renewalleadSourceMaster.leadSourceId ")->queryAll();
  740. $speedmeterUser = @$_REQUEST['speedmeterUser'];
  741. if (isset($speedmeterUser) && !empty($speedmeterUser))
  742. {
  743. $totalAmountOfSpeedometer = Lead::model()->closedLeadsAmount($speedmeterUser);
  744. }
  745. else
  746. {
  747. $totalAmountOfSpeedometer = 0;
  748. }
  749. $this->render('renewaldashboard', array('LeadStatus' => @$LeadStatus, 'notifications' => @$notifications, 'sourcewiseDetails' => @$sourcewiseDetails, 'sourcewiseDetailsWithPiechart' => @$sourcewiseDetailsWithPiechart, 'managerDetailsArr' => @$managerDetailsArr, 'totalAmountOfSpeedometer' => @$totalAmountOfSpeedometer, 'dataProviderc' => $dataProviderc));
  750. }
  751. public function actionrenViewLeadSummaryData()
  752. {
  753. $this->layout = 'column3';
  754. $leadStatusId = @$_REQUEST['leadStatusId'];
  755. //$model=new Renewallead;
  756. //$model=Renewallead::model()->findAll("leadStatusId = '".@$leadStatusId."' ");
  757. if (!Yii::app()->request->isAjaxRequest)
  758. {
  759. $this->redirect('dashboard/renewal');
  760. }
  761. else
  762. {
  763. $this->render('/renewalleads/partialLeadSummary', array('leadStatusId' => $leadStatusId));
  764. Yii::app()->end();
  765. }
  766. }
  767. public function actionrenViewWorkLoadData()
  768. {
  769. if (!Yii::app()->request->isAjaxRequest)
  770. {
  771. // $this->render('yourView');
  772. }
  773. else
  774. {
  775. $this->renderPartial('/renewalleads/partialWorkLoadData');
  776. Yii::app()->end();
  777. }
  778. }
  779. public function actionrenViewAllWorkLoadData()
  780. {
  781. function ManagerDetails($userIds)
  782. {
  783. $userIds = UserWithManagerIdsImploded($userIds);
  784. if ($userIds != '')
  785. {
  786. return Yii::app()->db->createCommand("select id from user where user.Id IN ($userIds) ")->queryAll();
  787. }
  788. }
  789. function UserWithManagerIdsImploded($userIds)
  790. {
  791. return $userIds = implode(",", $userIds);
  792. }
  793. $managerDetailsArr = ManagerDetails(Yii::app()->session['relationalManager']);
  794. if (!Yii::app()->request->isAjaxRequest)
  795. {
  796. // $this->render('yourView');
  797. }
  798. else
  799. {
  800. $this->renderPartial('/renewalleads/partialAllWorkLoadData', array('managerDetailsArr' => $managerDetailsArr));
  801. Yii::app()->end();
  802. }
  803. }
  804. public function actionrenViewFancyboxData()
  805. {
  806. $userId = @$_REQUEST['id'];
  807. $model = new User;
  808. $model = User::model()->findByPk($userId);
  809. if (!Yii::app()->request->isAjaxRequest)
  810. {
  811. // $this->render('yourView');
  812. }
  813. else
  814. {
  815. $this->renderPartial('/renewalmasters/partialNotification');
  816. Yii::app()->end();
  817. }
  818. }
  819. public function actionrenViewAllPerformanceData()
  820. {
  821. function ManagerDetails($userIds)
  822. {
  823. $userIds = UserWithManagerIdsImploded($userIds);
  824. if ($userIds != '')
  825. {
  826. return Yii::app()->db->createCommand("select id from user where user.Id IN ($userIds) ")->queryAll();
  827. }
  828. }
  829. function UserWithManagerIdsImploded($userIds)
  830. {
  831. return $userIds = implode(",", array_filter($userIds));
  832. }
  833. $managerDetailsArr = ManagerDetails(Yii::app()->session['relationalManager']);
  834. if (!Yii::app()->request->isAjaxRequest)
  835. {
  836. $this->render('/renewalleads/partialAllPerfLoadData', array('managerDetailsArr' => $managerDetailsArr));
  837. }
  838. else
  839. {
  840. $this->renderPartial('/leads/partialAllPerfLoadData', array('managerDetailsArr' => $managerDetailsArr));
  841. Yii::app()->end();
  842. }
  843. }
  844. public function actionfullcalender()
  845. {
  846. // renders the view file 'protected/views/site/index.php'
  847. // using the default layout 'protected/views/layouts/main.php'
  848. $this->render('fullcalender');
  849. }
  850. public function actionmyteamworkload()
  851. {
  852. // renders the view file 'protected/views/site/index.php'
  853. // using the default layout 'protected/views/layouts/main.php'
  854. $this->layout = false;
  855. function ManagerDetails($userIds)
  856. {
  857. $userIds = UserWithManagerIdsImploded($userIds);
  858. if ($userIds != '')
  859. {
  860. return Yii::app()->db->createCommand("select * from user where user.Id IN ($userIds) ")->queryAll();
  861. }
  862. }
  863. function UserWithManagerIdsImploded($userIds)
  864. {
  865. return $userIds = implode(",", array_filter($userIds));
  866. }
  867. $managerDetailsArr = ManagerDetails(Yii::app()->session['relationalManager']);
  868. $this->render('myteamworkload', array('managerDetailsArr' => @$managerDetailsArr));
  869. }
  870. public static function implodeResult($userIds)
  871. {
  872. $userIds = array_filter($userIds);
  873. return $userIds = implode(",", $userIds);
  874. }
  875. public function actionshowLeadCount()
  876. {
  877. $this->layout = false;
  878. $this->render('showLeadCount');
  879. }
  880. public function actionshowleadcountdisp()
  881. {
  882. $this->layout = false;
  883. $this->render('showleadcountdisp');
  884. }
  885. public static function getMTD($leadStatusId)
  886. {
  887. if (Yii::app()->session->get('type') == 'superadmin')
  888. {
  889. $cond = '';
  890. }
  891. else
  892. {
  893. if (count(@$_SESSION['relationalManager']) > 0)
  894. {
  895. $teamids = implode(",", $_SESSION['relationalManager']);
  896. }
  897. else
  898. {
  899. $teamids = Yii::app()->session->get('id');
  900. }
  901. $cond = "AND l.currentAllocatedId IN (" . @$teamids . ")";
  902. }
  903. $financialyear = @$_POST['financialyear'];
  904. if (isset($financialyear) && !empty($financialyear))
  905. {
  906. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1, $financialyear);
  907. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"), $financialyear);
  908. }
  909. else
  910. {
  911. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1);
  912. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"));
  913. }
  914. $sql = "select count(leadId) as total from lead l join user u on u.id=l.currentAllocatedId where l.leadStatusId = " . $leadStatusId . " and (l.updatedOn between '" . @$CurrentMonth_first_minute . "' and '" . @$CurrentMonth_last_minute . "') and u.status='Active' $cond limit 1 ";
  915. $count = Yii::app()->db->createCommand($sql)->queryColumn();
  916. return @$count[0];
  917. //echo Lead::model()->count(array("select"=>'leadid',"condition"=>" leadStatusId = ".@$leadStatusId.""));
  918. }
  919. public static function getYTD($leadStatusId)
  920. {
  921. if (Yii::app()->session->get('type') == 'superadmin')
  922. {
  923. $cond = '';
  924. }
  925. else
  926. {
  927. if (count(@$_SESSION['relationalManager']) > 0)
  928. {
  929. $teamids = implode(",", $_SESSION['relationalManager']);
  930. }
  931. else
  932. {
  933. $teamids = Yii::app()->session->get('id');
  934. }
  935. $cond = "AND l.currentAllocatedId IN (" . @$teamids . ")";
  936. }
  937. $financialyear = @$_POST['financialyear'];
  938. if (isset($financialyear) && !empty($financialyear))
  939. {
  940. $CurrentYear_first_minute = mktime(0, 0, 0, 4, 1, $financialyear);
  941. $CurrentYear_last_minute = mktime(0, 0, 0, 4, 0, $financialyear + 1);
  942. }
  943. else
  944. {
  945. $CurrentYear_first_minute = mktime(0, 0, 0, 4, 1, date('Y'));
  946. $CurrentYear_last_minute = mktime(0, 0, 0, 4, 0, date('Y') + 1);
  947. }
  948. $sql = "select count(leadId) as total from lead l join user u on u.id=l.currentAllocatedId where l.leadStatusId = " . $leadStatusId . " and (l.updatedOn between '" . @$CurrentYear_first_minute . "' and '" . @$CurrentYear_last_minute . "') and u.status='Active' $cond ";
  949. $count = Yii::app()->db->createCommand($sql)->queryColumn();
  950. return @$count[0];
  951. }
  952. public static function rengetMTD($leadStatusId)
  953. {
  954. if (Yii::app()->session->get('type') == 'superadmin')
  955. {
  956. $cond = '';
  957. }
  958. else
  959. {
  960. if (count(@$_SESSION['relationalManager']) > 0)
  961. {
  962. $teamids = implode(",", $_SESSION['relationalManager']);
  963. }
  964. else
  965. {
  966. $teamids = Yii::app()->session->get('id');
  967. }
  968. $cond = "AND l.currentAllocatedId IN (" . @$teamids . ")";
  969. }
  970. $financialyear = @$_POST['financialyear'];
  971. if (isset($financialyear) && !empty($financialyear))
  972. {
  973. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1, $financialyear);
  974. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"), $financialyear);
  975. }
  976. else
  977. {
  978. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1);
  979. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"));
  980. }
  981. $sql = "select count(leadId) as total from renewallead l join user u on u.id=l.currentAllocatedId where l.leadStatusId = " . $leadStatusId . " and (l.updatedOn between '" . @$CurrentMonth_first_minute . "' and '" . @$CurrentMonth_last_minute . "') and u.status='Active' and u.isRenewalUser='yes' $cond limit 1 ";
  982. $count = Yii::app()->db->createCommand($sql)->queryColumn();
  983. return @$count[0];
  984. }
  985. public static function rengetYTD($leadStatusId)
  986. {
  987. if (Yii::app()->session->get('type') == 'superadmin')
  988. {
  989. $cond = '';
  990. }
  991. else
  992. {
  993. if (count(@$_SESSION['relationalManager']) > 0)
  994. {
  995. $teamids = implode(",", $_SESSION['relationalManager']);
  996. }
  997. else
  998. {
  999. $teamids = Yii::app()->session->get('id');
  1000. }
  1001. $cond = "AND l.currentAllocatedId IN (" . @$teamids . ")";
  1002. }
  1003. $financialyear = @$_POST['financialyear'];
  1004. if (isset($financialyear) && !empty($financialyear))
  1005. {
  1006. $CurrentYear_first_minute = mktime(0, 0, 0, 4, 1, $financialyear);
  1007. $CurrentYear_last_minute = mktime(0, 0, 0, 4, 0, $financialyear + 1);
  1008. }
  1009. else
  1010. {
  1011. $CurrentYear_first_minute = mktime(0, 0, 0, 4, 1, date('Y'));
  1012. $CurrentYear_last_minute = mktime(0, 0, 0, 4, 0, date('Y') + 1);
  1013. }
  1014. $sql = "select count(leadId) as total from renewallead l join user u on u.id=l.currentAllocatedId where l.leadStatusId = " . $leadStatusId . " and (l.updatedOn between '" . @$CurrentYear_first_minute . "' and '" . @$CurrentYear_last_minute . "') and u.status='Active' and u.isRenewalUser='yes' $cond ";
  1015. $count = Yii::app()->db->createCommand($sql)->queryColumn();
  1016. return @$count[0];
  1017. }
  1018. /**
  1019. * Action Workload
  1020. */
  1021. public function actionWorkload()
  1022. {
  1023. $today12PM = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
  1024. $tomorrow12PM = mktime(0, 0, 0, date("m"), date("d"), date("Y")) + 86400;
  1025. $yesterday12PM = mktime(0, 0, 0, date("m"), date("d"), date("Y")) - 86400;
  1026. $LastMonth_first_minute = mktime(0, 0, 0, date("n") - 1, 1);
  1027. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1);
  1028. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"));
  1029. $leadCond = '';
  1030. if (isset($_POST['searchDashboard']) && !empty($_POST['searchDashboard']))
  1031. {
  1032. $searchDate = $_POST['searchDashboard'];
  1033. $searchTimestamp = strtotime(@$searchDate);
  1034. $searchEndTimestamp = $searchTimestamp + 86400;
  1035. $leadCond = " and lead.updatedOn >= '" . @$searchTimestamp . "' and lead.updatedOn < '" . @$searchEndTimestamp . "'";
  1036. }
  1037. $filtercaller = @$_REQUEST['User']['userName'];
  1038. $filtersource = @$_REQUEST['LeadSourceMaster']['leadSourceId'];
  1039. $filterdate1 = @$_REQUEST['Lead']['createdOn'];
  1040. $filterdate2 = @$_REQUEST['Lead']['createdOn2'];
  1041. $filterCond = '';
  1042. if (isset($filtercaller) && !empty($filtercaller))
  1043. {
  1044. $filterCond .= " AND lead.currentAllocatedId = " . $filtercaller . "";
  1045. }
  1046. if (isset($filtersource) && !empty($filtersource))
  1047. {
  1048. $filterCond .= " AND lead.leadSourceId = " . $filtersource . "";
  1049. }
  1050. if (isset($filterdate1) && !empty($filterdate1) && isset($filterdate2) && !empty($filterdate2))
  1051. {
  1052. $date1Filer = strtotime($filterdate1);
  1053. $date2Filer = strtotime($filterdate2);
  1054. $filterCond .= " AND lead.updatedOn >= " . $date1Filer . " AND lead.updatedOn <= " . $date2Filer . "";
  1055. }
  1056. if (Yii::app()->session->get('isAllocator') == 'yes')
  1057. {
  1058. $allocatorTl = Yii::app()->db->createCommand("select group_concat(distinct id) as TLIDS from user where roleId=4")->queryAll();
  1059. $impresuser = @$allocatorTl[0]['TLIDS'];
  1060. }
  1061. else
  1062. {
  1063. $impresuser = $this->implodeResult(Yii::app()->session['relationalManager']);
  1064. }
  1065. //dataProviderWorkload
  1066. $teamworkloadSql = "SELECT u.firstName,u.lastName,u.id as Id,SUM(IF(lead.updatedOn >= '" . @$today12PM . "' and lead.updatedOn <= '" . @$tomorrow12PM . "',1,0)) as T,SUM(IF(lead.updatedOn >= '" . @$yesterday12PM . "' and lead.updatedOn <= '" . @$today12PM . "',1,0)) as Y,SUM(IF(lead.updatedOn >= '" . @$CurrentMonth_first_minute . "' and lead.updatedOn <= '" . @$CurrentMonth_last_minute . "',1,0)) as M,SUM(IF(lead.updatedOn >= '" . @$LastMonth_first_minute . "' and…

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