PageRenderTime 59ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/lms_debug/protected/controllers/DashboardController_23dec2014.php

https://gitlab.com/badelal143/lms_debug
PHP | 1761 lines | 1297 code | 316 blank | 148 comment | 166 complexity | 3208c7728a4baba26c283499ff750906 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, LGPL-2.0
  1. <?php
  2. class DashboardController 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' => 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. //added by shakti. Please remove if not used.
  56. */
  57. public function actiondashboard()
  58. {
  59. $financialyear = @$_POST['financialyear'] ? $_POST['financialyear'] : date('Y');
  60. $month = date('m');
  61. self::insertUserLeadAllCountRecord($financialyear, $month);
  62. if (empty(Yii::app()->session['id']) or Yii::app()->session['id'] == '')
  63. {
  64. $this->redirect(array('site/index'));
  65. }
  66. $leadCond = '';
  67. $PiechartCond = '';
  68. $NotificationCond1 = '';
  69. $NotificationCond2 = '';
  70. $currentDateNot = date('d-m-Y');
  71. $currentTimestamp = strtotime($currentDateNot);
  72. if (isset($_POST['searchDashboard']) && !empty($_POST['searchDashboard']))
  73. {
  74. $searchDate = $_POST['searchDashboard'];
  75. $searchTimestamp = strtotime(@$searchDate);
  76. $searchEndTimestamp = $searchTimestamp + 86400;
  77. $leadCond = " and lead.updatedOn >= '" . @$searchTimestamp . "' and lead.updatedOn < '" . @$searchEndTimestamp . "'";
  78. $PiechartCond = " and leadSourceMaster.updatedOn >= '" . @$searchTimestamp . "' and leadSourceMaster.updatedOn < '" . @$searchEndTimestamp . "'";
  79. $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') )";
  80. $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') )";
  81. }
  82. if (Yii::app()->session->get('isAllocator') == 'yes' or Yii::app()->session->get('type') == 'superadmin' or Yii::app()->session->get('roleId') == 1)
  83. {
  84. $LeasStatusCond = '';
  85. }
  86. else
  87. {
  88. $LeasStatusCond = ' AND lead.currentAllocatedId = ' . Yii::app()->session->get('id') . '';
  89. }
  90. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1);
  91. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"));
  92. $CurrentYear_first_minute = mktime(0, 0, 0, 1, 1, date('Y'));
  93. $CurrentYear_last_minute = mktime(0, 0, 0, 13, 0, date('Y'));
  94. $where = '';
  95. if (Yii::app()->session->get('type') != 'superadmin')
  96. {
  97. $where = ' where notificationMapping.roleId="' . Yii::app()->session->get('roleId') . '"';
  98. $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') )";
  99. $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();
  100. }
  101. else
  102. {
  103. $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') )";
  104. $notifications = Yii::app()->db->createCommand("select notification.* from notification left join notificationMapping on notificationMapping.notificationId=notification.notificationId " . @$cls . " " . $NotificationCond2 . " group by notification.notificationId ")->queryAll();
  105. }
  106. $sourcewiseDetails = Yii::app()->db->createCommand("select leadSourceMaster.* from leadSourceMaster ")->queryAll();
  107. $ManagerDetails = Yii::app()->db->createCommand("select user.managerId,user.Id,user.userName from user where managerId='" . Yii::app()->session->get('id') . "'")->queryAll();
  108. $total_firstLevel = array();
  109. $total_nextLevel = array();
  110. $managerIds = self::fetchAllmanagerLevelRecords($total_firstLevel, $ManagerDetails, Yii::app()->session->get('id'));
  111. if (empty($managerIds))
  112. {
  113. $managerIds[] = $_SESSION['id'];
  114. }
  115. else
  116. {
  117. $pusharray = array();
  118. $pusharray[] = @$_SESSION['id'];
  119. $managerIds = array_unique(array_merge(@$managerIds, @$pusharray));
  120. }
  121. if (strtolower(Yii::app()->session->get('roleName')) == "teamleader")
  122. {
  123. $teamLeaderTeamUserIdsRes = array();
  124. $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();
  125. if (count($teamLeaderTeamUserIds) > 0)
  126. {
  127. foreach ($teamLeaderTeamUserIds as $keyd => $valued)
  128. {
  129. $teamLeaderTeamUserIdsRes[] = $valued['userId'];
  130. }
  131. $managerIds = array_unique(array_merge($managerIds, $teamLeaderTeamUserIdsRes));
  132. }
  133. }
  134. $managerDetailsArr = self::ManagerDetails($managerIds);
  135. Yii::app()->session['relationalManager'] = $managerIds;
  136. //$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();
  137. $speedmeterUser = @$_REQUEST['speedmeterUser'];
  138. if (isset($speedmeterUser) && !empty($speedmeterUser))
  139. {
  140. $totalAmountOfSpeedometer = Lead::model()->closedLeadsAmount($speedmeterUser);
  141. }
  142. else
  143. {
  144. $totalAmountOfSpeedometer = 0;
  145. }
  146. $LeadStatusSql = "SELECT ls.leadstatus,ls.leadstatusId,ls.sortOrder FROM `leadstatus` ls where ls.status='Active' order by ls.sortOrder ASC ";
  147. // $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";
  148. $count = Yii::app()->db->createCommand($LeadStatusSql)->queryAll();
  149. $dataProviderc = new CSqlDataProvider($LeadStatusSql, array(
  150. 'keyField' => 'leadstatusId',
  151. 'totalItemCount' => count($count),
  152. 'sort' => array(
  153. 'attributes' => array(
  154. 'leadStatusId',
  155. ),
  156. ),
  157. 'pagination' => array(
  158. 'pageSize' => 10,
  159. 'pageVar' => 'gyu', //page selector
  160. ),
  161. ));
  162. if (Yii::app()->session->get('isAllocator') == 'yes')
  163. {
  164. $allocatorTl = Yii::app()->db->createCommand("select group_concat(distinct id) as TLIDS from user where roleId=4")->queryAll();
  165. $impresuser = @$allocatorTl[0]['TLIDS'];
  166. }
  167. else
  168. {
  169. $impresuser = $this->implodeResult(Yii::app()->session['relationalManager']);
  170. }
  171. //calculate performance
  172. /*
  173. $today12PM = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
  174. $tomorrow12PM = mktime(0, 0, 0, date("m"), date("d"), date("Y")) + 86400;
  175. $yesterday12PM = mktime(0, 0, 0, date("m"), date("d"), date("Y")) - 86400;
  176. $LastMonth_first_minute = mktime(0, 0, 0, date("n") - 1, 1);
  177. //echo date('d M Y :: H:i:s',$CurrentMonth_first_minute); die;
  178. $filtercaller = @$_REQUEST['User']['userName'];
  179. $filtersource = @$_REQUEST['LeadSourceMaster']['leadSourceId'];
  180. $filterdate1 = @$_REQUEST['Lead']['createdOn'];
  181. $filterdate2 = @$_REQUEST['Lead']['createdOn2'];
  182. $filterCond = '';
  183. if (isset($filtercaller) && !empty($filtercaller))
  184. {
  185. $filterCond .= " AND lead.currentAllocatedId = " . $filtercaller . "";
  186. }
  187. if (isset($filtersource) && !empty($filtersource))
  188. {
  189. $filterCond .= " AND lead.leadSourceId = " . $filtersource . "";
  190. }
  191. if (isset($filterdate1) && !empty($filterdate1) && isset($filterdate2) && !empty($filterdate2))
  192. {
  193. $date1Filer = strtotime($filterdate1);
  194. $date2Filer = strtotime($filterdate2);
  195. $filterCond .= " AND lead.updatedOn >= " . $date1Filer . " AND lead.updatedOn <= " . $date2Filer . "";
  196. }
  197. */
  198. /* commented by shakti
  199. $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 lead.updatedOn <= '" . @$CurrentMonth_first_minute . "',1,0)) as LM from user u left join lead on lead.currentAllocatedId=u.Id where u.Id IN (" . @$impresuser . ") and u.status='Active' and lead.currentAllocatedId IN (" . @$impresuser . ") " . @$filterCond . " " . $leadCond . " group By u.id ";
  200. $countTeamworkLoad = Yii::app()->db->createCommand($teamworkloadSql)->queryAll();
  201. $dataProviderWorkload = new CSqlDataProvider($teamworkloadSql, array(
  202. 'keyField' => 'Id',
  203. 'totalItemCount' => count($countTeamworkLoad),
  204. 'sort' => array(
  205. 'attributes' => array(
  206. 'Id',
  207. ),
  208. ),
  209. 'pagination' => array(
  210. 'pageSize' => 10,
  211. 'pageVar' => 'workload', //page selector
  212. ),
  213. ));
  214. */
  215. self::getRequiredVariables();
  216. $callerTeamSql = "SELECT user.firstName,user.lastName,user.id as Id,SUM(IF(lead.updatedOn >= '" . @$today12PM . "' and lead.updatedOn <= '" . @$tomorrow12PM . "' and lead.leadSourceId = 1,1,0)) as WT,SUM(IF(lead.updatedOn >= '" . @$yesterday12PM . "' and lead.updatedOn <= '" . @$today12PM . "' and lead.leadSourceId = 1,1,0)) as WY,SUM(IF(lead.updatedOn >= '" . @$CurrentMonth_first_minute . "' and lead.updatedOn <= '" . @$CurrentMonth_last_minute . "' and lead.leadSourceId = 1,1,0)) as WM,SUM(IF(lead.updatedOn >= '" . @$LastMonth_first_minute . "' and lead.updatedOn <= '" . @$CurrentMonth_first_minute . "' and lead.leadSourceId = 1,1,0)) as WLM,SUM(IF(lead.updatedOn >= '" . @$today12PM . "' and lead.updatedOn <= '" . @$tomorrow12PM . "' and lead.leadSourceId != 1,1,0)) as OT,SUM(IF(lead.updatedOn >= '" . @$yesterday12PM . "' and lead.updatedOn <= '" . @$today12PM . "' and lead.leadSourceId != 1,1,0)) as OY,SUM(IF(lead.updatedOn >= '" . @$CurrentMonth_first_minute . "' and lead.updatedOn <= '" . @$CurrentMonth_last_minute . "' and lead.leadSourceId != 1,1,0)) as OM,SUM(IF(lead.updatedOn >= '" . @$LastMonth_first_minute . "' and lead.updatedOn <= '" . @$CurrentMonth_first_minute . "' and lead.leadSourceId != 1,1,0)) as OLM from user left join lead on lead.currentAllocatedId=user.Id where user.Id = " . Yii::app()->session['id'] . " and user.status='Active' and lead.currentAllocatedId =" . Yii::app()->session['id'] . " " . $leadCond . " ";
  217. $countcallerInfo = Yii::app()->db->createCommand($callerTeamSql)->queryAll();
  218. $dataProvidercaller = new CSqlDataProvider($callerTeamSql, array(
  219. 'keyField' => 'Id',
  220. 'totalItemCount' => count($countcallerInfo),
  221. 'sort' => array(
  222. 'attributes' => array(
  223. 'Id',
  224. ),
  225. ),
  226. 'pagination' => false,
  227. ));
  228. $dataProviderPerf = self::getDataProviderPerf();
  229. $this->render('dashboard', array('LeadStatus' => @$LeadStatus, 'notifications' => @$notifications, 'sourcewiseDetails' => @$sourcewiseDetails, 'managerDetailsArr' => @$managerDetailsArr, 'totalAmountOfSpeedometer' => @$totalAmountOfSpeedometer, 'dataProviderc' => $dataProviderc, 'dataProviderPerf' => $dataProviderPerf, 'dataProviderWorkload' => @$dataProviderWorkload, 'dataProvidercaller' => @$dataProvidercaller, 'dataProvideradmin' => @$dataProvideradmin, 'impresuser' => @$impresuser));
  230. }
  231. /**
  232. * Get Lead Status Count.(Eg Manager, add leadtypecount of all Teamleaders & Teamleader, add leadtypecount of all callers).
  233. * @see _leadfortoday.php
  234. * @return int
  235. */
  236. public static function getLeadStatusCount($leadStatusId, $accessKey)
  237. {
  238. $userList = $userId = Yii::app()->session['id'];
  239. if(Yii::app()->session->get('roleId') == 4)
  240. {
  241. $callerList = User::getMemebersList();
  242. if(count($userList))
  243. {
  244. $allCallersList = array();
  245. foreach($callerList as $list)
  246. {
  247. $allCallersList[] = $list['id'];
  248. }
  249. $userList = implode(', ', $allCallersList) . ', '. $userList;
  250. $totalCount = Yii::app()->db->createCommand("select *, sum(count) as count from leadallcount where userid in ( $userList ) AND leadtype = $leadStatusId AND accesskey = '$accessKey'")->queryRow();
  251. return $totalCount['count'];
  252. }
  253. }
  254. else if(Yii::app()->session->get('roleId') == 1)
  255. {
  256. $teamleadList = User::model()->fetchTeamleadList();
  257. $callerList = User::model()->fetchCallersList();
  258. if(count($teamleadList))
  259. {
  260. $allTeamleadsList = array();
  261. foreach($teamleadList as $list)
  262. {
  263. $allTeamleadsList[] = $list['id'];
  264. }
  265. }
  266. if(count($callerList))
  267. {
  268. $allCallersList = array();
  269. foreach($callerList as $list)
  270. {
  271. $allCallersList[] = $list['id'];
  272. }
  273. }
  274. $userList = implode(', ', $allTeamleadsList) . ', '. implode(', ', $allCallersList) . ', '. $userList;
  275. $totalCount = Yii::app()->db->createCommand("select sum(count) as count from leadallcount where userid in ( $userList ) AND leadtype = $leadStatusId AND accesskey = '$accessKey'")->queryRow();
  276. return $totalCount['count'];
  277. }
  278. $count = Yii::app()->db->createCommand("select sum(count) as count from leadallcount where userid = $userId AND leadtype = $leadStatusId AND accesskey = '$accessKey'")->queryRow();
  279. return $count['count'];
  280. }
  281. /**
  282. * Insert Users Record (Eg. call this method to insert all callers record for the teamlead).
  283. * @see _leadfortoday.php
  284. * @return int
  285. */
  286. public static function insertUsersRecord($accessKey)
  287. {
  288. if(Yii::app()->session->get('roleId') == 4)
  289. {
  290. $callerList = User::model()->fetchCallersList();
  291. if(count($callerList))
  292. {
  293. $financialDate = explode('-', $accessKey);
  294. $financialDate[0] = $financialDate[0] ? $financialDate[0] : date('Y');
  295. $financialDate[1] = @$financialDate[1] ? $financialDate[1] : date('m');
  296. foreach($callerList as $list)
  297. {
  298. self::insertUserLeadAllCountRecord($financialDate[0], $financialDate[1], $list['id']);
  299. }
  300. }
  301. }
  302. if(Yii::app()->session->get('roleId') == 1)
  303. {
  304. $teamleadList = User::model()->fetchTeamleadList();
  305. $callerList = User::model()->fetchCallersList();
  306. if(count($teamleadList))
  307. {
  308. $financialDate = explode('-', $accessKey);
  309. $financialDate[0] = $financialDate[0] ? $financialDate[0] : date('Y');
  310. $financialDate[1] = @$financialDate[1] ? $financialDate[1] : date('m');
  311. foreach($callerList as $list)
  312. {
  313. self::insertUserLeadAllCountRecord($financialDate[0], $financialDate[1], $list['id']);
  314. }
  315. }
  316. if(count($callerList))
  317. {
  318. $financialDate = explode('-', $accessKey);
  319. $financialDate[0] = $financialDate[0] ? $financialDate[0] : date('Y');
  320. $financialDate[1] = @$financialDate[1] ? $financialDate[1] : date('m');
  321. foreach($callerList as $list)
  322. {
  323. self::insertUserLeadAllCountRecord($financialDate[0], $financialDate[1], $list['id']);
  324. }
  325. }
  326. }
  327. }
  328. /**
  329. * This is the 'module master' action that is invoked
  330. * when an action is not explicitly requested by users.
  331. */
  332. public function actionmodule_master()
  333. {
  334. // renders the view file 'protected/views/site/index.php'
  335. // using the default layout 'protected/views/layouts/main.php'
  336. $model = new ModuleMaster();
  337. $model->scenario = 'ModuleMaster';
  338. if (!empty($_GET['moduleId']))
  339. {
  340. $moduleId = $_GET['moduleId'];
  341. $model = ModuleMaster::model()->findByPk($moduleId);
  342. }
  343. if (!empty($_POST['ModuleMaster']['moduleId']))
  344. {
  345. $moduleId = $_POST['ModuleMaster']['moduleId'];
  346. $model = ModuleMaster::model()->findByPk($moduleId);
  347. }
  348. if (isset($_POST['ModuleMaster']))
  349. {
  350. $model->setAttributes(array(
  351. 'createdOn' => time(), //additional data you want to insert
  352. 'updatedOn' => time(), //additional
  353. 'updatedBy' => time(), //additional
  354. 'createdBy' => time(),
  355. 'status' => 'Activated', //additional //additional
  356. ));
  357. foreach ($_POST['ModuleMaster'] as $name => $value)
  358. {
  359. $model->$name = $value;
  360. }
  361. if ($model->validate())
  362. {
  363. $model->save();
  364. $model2 = ModuleMaster::model()->findAll();
  365. $this->render('module_master', array('model' => $model, 'model2' => $model2));
  366. Yii::app()->user->setFlash('module_master_msg_success', 'Successfully Inserted');
  367. }
  368. else
  369. {
  370. Yii::app()->user->setFlash('module_master_msg_error', 'Please check. error occured');
  371. $this->render('module_master', array('model' => $model));
  372. }
  373. }
  374. else
  375. {
  376. $model2 = ModuleMaster::model()->findAll();
  377. //Yii::app()->user->setFlash('lead_stage_msg_error','Please check. error occured');
  378. $this->render('module_master', array('model' => $model, 'model2' => $model2));
  379. }
  380. }
  381. /**
  382. * This is the action to handle external exceptions.
  383. */
  384. public function actionError()
  385. {
  386. if ($error = Yii::app()->errorHandler->error)
  387. {
  388. if (Yii::app()->request->isAjaxRequest)
  389. echo $error['message'];
  390. else
  391. $this->render('error', $error);
  392. }
  393. }
  394. /**
  395. * Displays the contact page
  396. */
  397. public function actionContact()
  398. {
  399. $model = new ContactForm;
  400. if (isset($_POST['ContactForm']))
  401. {
  402. $model->attributes = $_POST['ContactForm'];
  403. if ($model->validate())
  404. {
  405. $name = '=?UTF-8?B?' . base64_encode($model->name) . '?=';
  406. $subject = '=?UTF-8?B?' . base64_encode($model->subject) . '?=';
  407. $headers = "From: $name <{$model->email}>\r\n" .
  408. "Reply-To: {$model->email}\r\n" .
  409. "MIME-Version: 1.0\r\n" .
  410. "Content-type: text/plain; charset=UTF-8";
  411. mail(Yii::app()->params['adminEmail'], $subject, $model->body, $headers);
  412. Yii::app()->user->setFlash('contact', 'Thank you for contacting us. We will respond to you as soon as possible.');
  413. $this->refresh();
  414. }
  415. }
  416. $this->render('contact', array('model' => $model));
  417. }
  418. /**
  419. * Displays the login page
  420. */
  421. public function actionLogin()
  422. {
  423. $model = new User;
  424. // if it is ajax validation request
  425. if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form')
  426. {
  427. echo CActiveForm::validate($model);
  428. Yii::app()->end();
  429. }
  430. // collect user input data
  431. if (isset($_POST['User']))
  432. {
  433. $model->attributes = $_POST['User'];
  434. // validate user input and redirect to the previous page if valid
  435. if ($model->validate() && $model->login())
  436. {
  437. $this->redirect(array('masters/dashboard'));
  438. }
  439. else
  440. {
  441. $this->redirect(Yii::app()->user->returnUrl);
  442. }
  443. }
  444. // display the login form
  445. $this->render('login', array('model' => $model));
  446. }
  447. /**
  448. * Logs out the current user and redirect to homepage.
  449. */
  450. public function actionLogout()
  451. {
  452. Yii::app()->user->logout();
  453. $this->redirect(Yii::app()->homeUrl);
  454. }
  455. public function getPageType()
  456. {
  457. return "";
  458. }
  459. public function actionViewFancyboxData()
  460. {
  461. $userId = @$_REQUEST['id'];
  462. $model = new User;
  463. $model = User::model()->findByPk($userId);
  464. if (!Yii::app()->request->isAjaxRequest)
  465. {
  466. // $this->render('yourView');
  467. }
  468. else
  469. {
  470. $this->renderPartial('/masters/partialNotification');
  471. Yii::app()->end();
  472. }
  473. }
  474. public function actionViewWorkLoadData()
  475. {
  476. if (!Yii::app()->request->isAjaxRequest)
  477. {
  478. echo "ddd";
  479. // $this->render('/leads/partialWorkLoadData');
  480. // $this->render('yourView');
  481. }
  482. else
  483. {
  484. $this->renderPartial('/leads/partialWorkLoadData');
  485. Yii::app()->end();
  486. }
  487. }
  488. public function actionViewLeadSummaryData()
  489. {
  490. //$this->layout='column3';
  491. $this->layout = false;
  492. $parser = new CHtmlPurifier();
  493. $leadStatusId = $parser->purify(intval(@$_REQUEST['leadStatusId']));
  494. /* $model=new Lead;
  495. $model=Lead::model()->findAll("leadStatusId = '".@$leadStatusId."' ");
  496. */
  497. if (!Yii::app()->request->isAjaxRequest)
  498. {
  499. $this->render('/leads/partialLeadSummary', array('leadStatusId' => $leadStatusId));
  500. }
  501. else
  502. {
  503. $this->layout=false;
  504. $this->render('/leads/partialLeadSummary', array('leadStatusId' => $leadStatusId));
  505. Yii::app()->end();
  506. }
  507. }
  508. public function actionRenewalViewLeadSummaryData()
  509. {
  510. //$this->layout='column3';
  511. $this->layout = false;
  512. $res = new MySanitizeClass;
  513. $leadStatusId = $res->sanitize_description(@$_REQUEST['leadStatusId']);
  514. /* $model=new Lead;
  515. $model=Lead::model()->findAll("leadStatusId = '".@$leadStatusId."' ");
  516. */ if (!Yii::app()->request->isAjaxRequest)
  517. {
  518. $this->render('/renewalleads/renewalpartialLeadSummary', array('leadStatusId' => $leadStatusId));
  519. }
  520. else
  521. {
  522. //$this->layout=false;
  523. $this->render('/renewalleads/renewalpartialLeadSummary', array('leadStatusId' => $leadStatusId));
  524. Yii::app()->end();
  525. }
  526. }
  527. function getparentLeadStatus($parentId)
  528. {
  529. $primary = LeadStatus::model()->findByPk($parentId);
  530. if ($primary['parentId'] > 0)
  531. {
  532. $parentName = LeadStatus::model()->findByPk($primary['parentId']);
  533. $pname = $parentName['leadStatus'];
  534. }
  535. else
  536. {
  537. $pname = "Primary";
  538. }
  539. return $pname;
  540. }
  541. public function actionViewAllWorkLoadData()
  542. {
  543. function ManagerDetails($userIds)
  544. {
  545. $userIds = UserWithManagerIdsImploded($userIds);
  546. if ($userIds != '')
  547. {
  548. return Yii::app()->db->createCommand("select * from user where user.Id IN ($userIds) ")->queryAll();
  549. }
  550. }
  551. function UserWithManagerIdsImploded($userIds)
  552. {
  553. return $userIds = implode(",", $userIds);
  554. }
  555. $managerDetailsArr = ManagerDetails(Yii::app()->session['relationalManager']);
  556. if (!Yii::app()->request->isAjaxRequest)
  557. {
  558. // $this->render('yourView');
  559. }
  560. else
  561. {
  562. $this->renderPartial('/leads/partialAllWorkLoadData', array('managerDetailsArr' => $managerDetailsArr));
  563. Yii::app()->end();
  564. }
  565. }
  566. public function actionViewAllPerformanceData()
  567. {
  568. function ManagerDetails($userIds)
  569. {
  570. $userIds = UserWithManagerIdsImploded($userIds);
  571. if ($userIds != '')
  572. {
  573. return Yii::app()->db->createCommand("select * from user where user.Id IN ($userIds) ")->queryAll();
  574. }
  575. }
  576. function UserWithManagerIdsImploded($userIds)
  577. {
  578. return $userIds = implode(",", $userIds);
  579. }
  580. $managerDetailsArr = ManagerDetails(Yii::app()->session['relationalManager']);
  581. if (!Yii::app()->request->isAjaxRequest)
  582. {
  583. $this->render('/leads/partialAllPerfLoadData', array('managerDetailsArr' => $managerDetailsArr));
  584. // $this->render('yourView');
  585. }
  586. else
  587. {
  588. $this->renderPartial('/leads/partialAllPerfLoadData', array('managerDetailsArr' => $managerDetailsArr));
  589. Yii::app()->end();
  590. }
  591. }
  592. public function actionrenewal()
  593. {
  594. //$this->redirect(array('dashboard/dashboard'));
  595. $leadCond = '';
  596. $PiechartCond = '';
  597. $NotificationCond1 = '';
  598. $NotificationCond2 = '';
  599. $currentDateNot = date('d-m-Y');
  600. $currentTimestamp = strtotime($currentDateNot);
  601. if (isset($_POST['searchDashboard']) && !empty($_POST['searchDashboard']))
  602. {
  603. $searchDate = $_POST['searchDashboard'];
  604. $searchTimestamp = strtotime(@$searchDate);
  605. $searchEndTimestamp = $searchTimestamp + 86400;
  606. $leadCond = " and renewallead.updatedOn >= '" . @$searchTimestamp . "' and renewallead.updatedOn < '" . @$searchEndTimestamp . "'";
  607. $PiechartCond = " and renewalleadSourceMaster.updatedOn >= '" . @$searchTimestamp . "' and renewalleadSourceMaster.updatedOn < '" . @$searchEndTimestamp . "'";
  608. $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') )";
  609. $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') )";
  610. }
  611. if (Yii::app()->session->get('isAllocator') == 'yes' or Yii::app()->session->get('type') == 'superadmin')
  612. {
  613. $LeasStatusCond = '';
  614. }
  615. else
  616. {
  617. $LeasStatusCond = ' AND renewallead.currentAllocatedId = "' . Yii::app()->session->get('id') . '"';
  618. }
  619. $LeadStatus = Yii::app()->db->createCommand('SELECT
  620. me.leadStatusId AS me_id,
  621. me.leadStatus AS me_leadStatus,
  622. renewallead.leadStatusId AS lead_leadStatusId,
  623. renewallead.leadId AS leadId,
  624. count(*) AS total
  625. FROM
  626. renewalleadStatus me
  627. left join renewallead on renewallead.leadStatusId=me.leadStatusId where renewallead.leadStatusId > 0 ' . $leadCond . ' ' . $LeasStatusCond . ' group by renewallead.leadStatusId')->queryAll();
  628. $LeadStatusSql = "SELECT ls.leadstatus,ls.leadstatusId,ls.sortOrder FROM `renewalleadstatus` ls where ls.status='Active' order by ls.sortOrder ASC ";
  629. // $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";
  630. $count = Yii::app()->db->createCommand($LeadStatusSql)->queryAll();
  631. $dataProviderc = new CSqlDataProvider($LeadStatusSql, array(
  632. 'keyField' => 'leadstatusId',
  633. 'totalItemCount' => count($count),
  634. 'sort' => array(
  635. 'attributes' => array(
  636. 'leadStatusId',
  637. ),
  638. ),
  639. 'pagination' => array(
  640. 'pageSize' => 10,
  641. 'pageVar' => 'gyu', //page selector
  642. ),
  643. ));
  644. $where = '';
  645. if (Yii::app()->session->get('type') != 'superadmin')
  646. {
  647. $where = ' where renewalnotificationMapping.roleId="' . Yii::app()->session->get('roleId') . '"';
  648. $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') )";
  649. $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();
  650. }
  651. else
  652. {
  653. $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') )";
  654. $notifications = Yii::app()->db->createCommand("select renewalnotification.* from renewalnotification left join renewalnotificationMapping on renewalnotificationMapping.notificationId=renewalnotification.notificationId " . @$cls . " " . $NotificationCond2 . " group by renewalnotification.notificationId ")->queryAll();
  655. }
  656. $sourcewiseDetails = Yii::app()->db->createCommand("select renewalleadSourceMaster.* from renewalleadSourceMaster ")->queryAll();
  657. $ManagerDetails = Yii::app()->db->createCommand("select user.managerId,user.Id,user.userName from user where managerId='" . Yii::app()->session->get('id') . "'")->queryAll();
  658. function SecondLevel($managerId, $userId)
  659. {
  660. return Yii::app()->db->createCommand("select user.managerId,user.Id,user.userName from user where user.managerId='$managerId' and user.managerId!='$userId' ")->queryAll();
  661. }
  662. function ManagerLevel($userIds, $managerIds)
  663. {
  664. return Yii::app()->db->createCommand("select user.managerId,user.Id,user.userName from user where user.managerId ='$userIds' and id!='$managerIds' ")->queryAll();
  665. }
  666. function ManagerDetails($userIds)
  667. {
  668. $userIds = UserWithManagerIdsImploded($userIds);
  669. if ($userIds != '')
  670. {
  671. return Yii::app()->db->createCommand("select * from user where user.Id IN ($userIds) ")->queryAll();
  672. }
  673. }
  674. function UserWithManagerIdsImploded($userIds)
  675. {
  676. return $userIds = implode(",", $userIds);
  677. }
  678. $total_firstLevel = array();
  679. $total_nextLevel = array();
  680. function fetchAllmanagerLevelRecords(&$total_firstLevel, $ManagerDetails, $currentUserIds)
  681. {
  682. foreach ($ManagerDetails as $key => $value)
  683. {
  684. $total_firstLevel[] = $value['Id'];
  685. $total_res = SecondLevel($value['Id'], $currentUserIds);
  686. $res[] = count($total_res);
  687. if (count($total_res) > 0)
  688. {
  689. $o = 0;
  690. foreach ($total_res as $key1 => $value1)
  691. {
  692. $total_firstLevel[] = $value1['Id'];
  693. $net_res = fetchAllmanagerLevelRecords($total_firstLevel, ManagerLevel($value1['Id'], Yii::app()->session->get('id')), Yii::app()->session->get('id'));
  694. $o++;
  695. }
  696. }
  697. }
  698. return $total_firstLevel;
  699. }
  700. $managerIds = fetchAllmanagerLevelRecords($total_firstLevel, $ManagerDetails, Yii::app()->session->get('id'));
  701. if (empty($managerIds))
  702. {
  703. $managerIds[] = $_SESSION['id'];
  704. }
  705. else
  706. {
  707. $pusharray = array();
  708. $pusharray[] = @$_SESSION['id'];
  709. $managerIds = array_unique(array_merge(@$managerIds, @$pusharray));
  710. }
  711. if (strtolower(Yii::app()->session->get('roleName')) == "teamleader")
  712. {
  713. $teamLeaderTeamUserIdsRes = array();
  714. $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();
  715. if (count($teamLeaderTeamUserIds) > 0)
  716. {
  717. foreach ($teamLeaderTeamUserIds as $keyd => $valued)
  718. {
  719. $teamLeaderTeamUserIdsRes[] = $valued['userId'];
  720. }
  721. $managerIds = array_unique(array_merge($managerIds, $teamLeaderTeamUserIdsRes));
  722. }
  723. }
  724. $managerDetailsArr = ManagerDetails($managerIds);
  725. Yii::app()->session['relationalManager'] = $managerIds;
  726. $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();
  727. $speedmeterUser = @$_REQUEST['speedmeterUser'];
  728. if (isset($speedmeterUser) && !empty($speedmeterUser))
  729. {
  730. $totalAmountOfSpeedometer = Lead::model()->closedLeadsAmount($speedmeterUser);
  731. }
  732. else
  733. {
  734. $totalAmountOfSpeedometer = 0;
  735. }
  736. $this->render('renewaldashboard', array('LeadStatus' => @$LeadStatus, 'notifications' => @$notifications, 'sourcewiseDetails' => @$sourcewiseDetails, 'sourcewiseDetailsWithPiechart' => @$sourcewiseDetailsWithPiechart, 'managerDetailsArr' => @$managerDetailsArr, 'totalAmountOfSpeedometer' => @$totalAmountOfSpeedometer, 'dataProviderc' => $dataProviderc));
  737. }
  738. public function actionrenViewLeadSummaryData()
  739. {
  740. $this->layout = 'column3';
  741. $leadStatusId = @$_REQUEST['leadStatusId'];
  742. //$model=new Renewallead;
  743. //$model=Renewallead::model()->findAll("leadStatusId = '".@$leadStatusId."' ");
  744. if (!Yii::app()->request->isAjaxRequest)
  745. {
  746. $this->redirect('dashboard/renewal');
  747. }
  748. else
  749. {
  750. $this->render('/renewalleads/partialLeadSummary', array('leadStatusId' => $leadStatusId));
  751. Yii::app()->end();
  752. }
  753. }
  754. public function actionrenViewWorkLoadData()
  755. {
  756. if (!Yii::app()->request->isAjaxRequest)
  757. {
  758. // $this->render('yourView');
  759. }
  760. else
  761. {
  762. $this->renderPartial('/renewalleads/partialWorkLoadData');
  763. Yii::app()->end();
  764. }
  765. }
  766. public function actionrenViewAllWorkLoadData()
  767. {
  768. function ManagerDetails($userIds)
  769. {
  770. $userIds = UserWithManagerIdsImploded($userIds);
  771. if ($userIds != '')
  772. {
  773. return Yii::app()->db->createCommand("select id from user where user.Id IN ($userIds) ")->queryAll();
  774. }
  775. }
  776. function UserWithManagerIdsImploded($userIds)
  777. {
  778. return $userIds = implode(",", $userIds);
  779. }
  780. $managerDetailsArr = ManagerDetails(Yii::app()->session['relationalManager']);
  781. if (!Yii::app()->request->isAjaxRequest)
  782. {
  783. // $this->render('yourView');
  784. }
  785. else
  786. {
  787. $this->renderPartial('/renewalleads/partialAllWorkLoadData', array('managerDetailsArr' => $managerDetailsArr));
  788. Yii::app()->end();
  789. }
  790. }
  791. public function actionrenViewFancyboxData()
  792. {
  793. $userId = @$_REQUEST['id'];
  794. $model = new User;
  795. $model = User::model()->findByPk($userId);
  796. if (!Yii::app()->request->isAjaxRequest)
  797. {
  798. // $this->render('yourView');
  799. }
  800. else
  801. {
  802. $this->renderPartial('/renewalmasters/partialNotification');
  803. Yii::app()->end();
  804. }
  805. }
  806. public function actionrenViewAllPerformanceData()
  807. {
  808. function ManagerDetails($userIds)
  809. {
  810. $userIds = UserWithManagerIdsImploded($userIds);
  811. if ($userIds != '')
  812. {
  813. return Yii::app()->db->createCommand("select id from user where user.Id IN ($userIds) ")->queryAll();
  814. }
  815. }
  816. function UserWithManagerIdsImploded($userIds)
  817. {
  818. return $userIds = implode(",", array_filter($userIds));
  819. }
  820. $managerDetailsArr = ManagerDetails(Yii::app()->session['relationalManager']);
  821. if (!Yii::app()->request->isAjaxRequest)
  822. {
  823. $this->render('/renewalleads/partialAllPerfLoadData', array('managerDetailsArr' => $managerDetailsArr));
  824. // $this->render('yourView');
  825. }
  826. else
  827. {
  828. $this->renderPartial('/leads/partialAllPerfLoadData', array('managerDetailsArr' => $managerDetailsArr));
  829. Yii::app()->end();
  830. }
  831. }
  832. public function actionfullcalender()
  833. {
  834. // renders the view file 'protected/views/site/index.php'
  835. // using the default layout 'protected/views/layouts/main.php'
  836. $this->render('fullcalender');
  837. }
  838. public function actionmyteamworkload()
  839. {
  840. // renders the view file 'protected/views/site/index.php'
  841. // using the default layout 'protected/views/layouts/main.php'
  842. $this->layout = false;
  843. function ManagerDetails($userIds)
  844. {
  845. $userIds = UserWithManagerIdsImploded($userIds);
  846. if ($userIds != '')
  847. {
  848. return Yii::app()->db->createCommand("select * from user where user.Id IN ($userIds) ")->queryAll();
  849. }
  850. }
  851. function UserWithManagerIdsImploded($userIds)
  852. {
  853. return $userIds = implode(",", array_filter($userIds));
  854. }
  855. $managerDetailsArr = ManagerDetails(Yii::app()->session['relationalManager']);
  856. $this->render('myteamworkload', array('managerDetailsArr' => @$managerDetailsArr));
  857. }
  858. public static function implodeResult($userIds)
  859. {
  860. $userIds = array_filter($userIds);
  861. return $userIds = implode(",", $userIds);
  862. }
  863. public function actionshowLeadCount()
  864. {
  865. $this->layout = false;
  866. $this->render('showLeadCount');
  867. }
  868. public function actionshowleadcountdisp()
  869. {
  870. $this->layout = false;
  871. $this->render('showleadcountdisp');
  872. }
  873. public static function getMTD($leadStatusId)
  874. {
  875. if (Yii::app()->session->get('type') == 'superadmin')
  876. {
  877. $cond = '';
  878. }
  879. else
  880. {
  881. if (count(@$_SESSION['relationalManager']) > 0)
  882. {
  883. $teamids = implode(",", $_SESSION['relationalManager']);
  884. }
  885. else
  886. {
  887. $teamids = Yii::app()->session->get('id');
  888. }
  889. $cond = "AND l.currentAllocatedId IN (" . @$teamids . ")";
  890. }
  891. $financialyear = @$_POST['financialyear'];
  892. if (isset($financialyear) && !empty($financialyear))
  893. {
  894. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1, $financialyear);
  895. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"), $financialyear);
  896. }
  897. else
  898. {
  899. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1);
  900. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"));
  901. }
  902. $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 ";
  903. $count = Yii::app()->db->createCommand($sql)->queryColumn();
  904. return @$count[0];
  905. //echo Lead::model()->count(array("select"=>'leadid',"condition"=>" leadStatusId = ".@$leadStatusId.""));
  906. }
  907. public static function getYTD($leadStatusId)
  908. {
  909. if (Yii::app()->session->get('type') == 'superadmin')
  910. {
  911. $cond = '';
  912. }
  913. else
  914. {
  915. if (count(@$_SESSION['relationalManager']) > 0)
  916. {
  917. $teamids = implode(",", $_SESSION['relationalManager']);
  918. }
  919. else
  920. {
  921. $teamids = Yii::app()->session->get('id');
  922. }
  923. $cond = "AND l.currentAllocatedId IN (" . @$teamids . ")";
  924. }
  925. $financialyear = @$_POST['financialyear'];
  926. if (isset($financialyear) && !empty($financialyear))
  927. {
  928. $CurrentYear_first_minute = mktime(0, 0, 0, 4, 1, $financialyear);
  929. $CurrentYear_last_minute = mktime(0, 0, 0, 4, 0, $financialyear + 1);
  930. }
  931. else
  932. {
  933. $CurrentYear_first_minute = mktime(0, 0, 0, 4, 1, date('Y'));
  934. $CurrentYear_last_minute = mktime(0, 0, 0, 4, 0, date('Y') + 1);
  935. }
  936. //$CurrentYear_first_minute = mktime(0, 0, 0, 1, 1, date('Y'));
  937. //$CurrentYear_last_minute = mktime(0, 0, 0, 13, 0, date('Y'));
  938. $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 ";
  939. $count = Yii::app()->db->createCommand($sql)->queryColumn();
  940. //echo Lead::model()->count(array("select"=>'leadid',"condition"=>" leadStatusId = ".@$leadStatusId.""));
  941. return @$count[0];
  942. //return @$count[0];
  943. }
  944. public static function rengetMTD($leadStatusId)
  945. {
  946. if (Yii::app()->session->get('type') == 'superadmin')
  947. {
  948. $cond = '';
  949. }
  950. else
  951. {
  952. if (count(@$_SESSION['relationalManager']) > 0)
  953. {
  954. $teamids = implode(",", $_SESSION['relationalManager']);
  955. }
  956. else
  957. {
  958. $teamids = Yii::app()->session->get('id');
  959. }
  960. $cond = "AND l.currentAllocatedId IN (" . @$teamids . ")";
  961. }
  962. $financialyear = @$_POST['financialyear'];
  963. if (isset($financialyear) && !empty($financialyear))
  964. {
  965. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1, $financialyear);
  966. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"), $financialyear);
  967. }
  968. else
  969. {
  970. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1);
  971. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"));
  972. }
  973. $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 ";
  974. $count = Yii::app()->db->createCommand($sql)->queryColumn();
  975. return @$count[0];
  976. //echo Lead::model()->count(array("select"=>'leadid',"condition"=>" leadStatusId = ".@$leadStatusId.""));
  977. }
  978. public static function rengetYTD($leadStatusId)
  979. {
  980. if (Yii::app()->session->get('type') == 'superadmin')
  981. {
  982. $cond = '';
  983. }
  984. else
  985. {
  986. if (count(@$_SESSION['relationalManager']) > 0)
  987. {
  988. $teamids = implode(",", $_SESSION['relationalManager']);
  989. }
  990. else
  991. {
  992. $teamids = Yii::app()->session->get('id');
  993. }
  994. $cond = "AND l.currentAllocatedId IN (" . @$teamids . ")";
  995. }
  996. $financialyear = @$_POST['financialyear'];
  997. if (isset($financialyear) && !empty($financialyear))
  998. {
  999. $CurrentYear_first_minute = mktime(0, 0, 0, 4, 1, $financialyear);
  1000. $CurrentYear_last_minute = mktime(0, 0, 0, 4, 0, $financialyear + 1);
  1001. }
  1002. else
  1003. {
  1004. $CurrentYear_first_minute = mktime(0, 0, 0, 4, 1, date('Y'));
  1005. $CurrentYear_last_minute = mktime(0, 0, 0, 4, 0, date('Y') + 1);
  1006. }
  1007. //$CurrentYear_first_minute = mktime(0, 0, 0, 1, 1, date('Y'));
  1008. //$CurrentYear_last_minute = mktime(0, 0, 0, 13, 0, date('Y'));
  1009. $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 ";
  1010. $count = Yii::app()->db->createCommand($sql)->queryColumn();
  1011. //echo Lead::model()->count(array("select"=>'leadid',"condition"=>" leadStatusId = ".@$leadStatusId.""));
  1012. return @$count[0];
  1013. //return @$count[0];
  1014. }
  1015. /**
  1016. * added by shakti.
  1017. */
  1018. public function actionWorkloadIncorrect()
  1019. {
  1020. $today12PM = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
  1021. $tomorrow12PM = mktime(0, 0, 0, date("m"), date("d"), date("Y")) + 86400;
  1022. $yesterday12PM = mktime(0, 0, 0, date("m"), date("d"), date("Y")) - 86400;
  1023. $LastMonth_first_minute = mktime(0, 0, 0, date("n") - 1, 1);
  1024. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1);
  1025. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"));
  1026. $leadCond = '';
  1027. if(isset($_POST['searchDashboard']) && !empty($_POST['searchDashboard']))
  1028. {
  1029. $searchDate=$_POST['searchDashboard'];
  1030. $searchTimestamp=strtotime(@$searchDate);
  1031. $searchEndTimestamp=$searchTimestamp+86400;
  1032. $leadCond = " and lead.updatedOn >= '".@$searchTimestamp."' and lead.updatedOn < '".@$searchEndTimestamp."'";
  1033. }
  1034. $callerTeamSql = "SELECT user.firstName,user.lastName,user.id as Id,SUM(IF(lead.updatedOn >= '".@$today12PM."' and lead.updatedOn <= '".@$tomorrow12PM."' and lead.leadSourceId = 1,1,0)) as WT,SUM(IF(lead.updatedOn >= '".@$yesterday12PM."' and lead.updatedOn <= '".@$today12PM."' and lead.leadSourceId = 1,1,0)) as WY,SUM(IF(lead.updatedOn >= '".@$CurrentMonth_first_minute."' and lead.updatedOn <= '".@$CurrentMonth_last_minute."' and lead.leadSourceId = 1,1,0)) as WM,SUM(IF(lead.updatedOn >= '".@$LastMonth_first_minute."' and lead.updatedOn <= '".@$CurrentMonth_first_minute."' and lead.leadSourceId = 1,1,0)) as WLM,SUM(IF(lead.updatedOn >= '".@$today12PM."' and lead.updatedOn <= '".@$tomorrow12PM."' and lead.leadSourceId != 1,1,0)) as OT,SUM(IF(lead.updatedOn >= '".@$yesterday12PM."' and lead.updatedOn <= '".@$today12PM."' and lead.leadSourceId != 1,1,0)) as OY,SUM(IF(lead.updatedOn >= '".@$CurrentMonth_first_minute."' and lead.updatedOn <= '".@$CurrentMonth_last_minute."' and lead.leadSourceId != 1,1,0)) as OM,SUM(IF(lead.updatedOn >= '".@$LastMonth_first_minute."' and lead.updatedOn <= '".@$CurrentMonth_first_minute."' and lead.leadSourceId != 1,1,0)) as OLM from user left join lead on lead.currentAllocatedId=user.Id where user.Id = ".Yii::app()->session['id']." and user.status='Active' and lead.currentAllocatedId =".Yii::app()->session['id']." ".$leadCond." ";
  1035. $countcallerInfo=Yii::app()->db->createCommand($callerTeamSql)->queryAll();
  1036. $dataProvidercaller = new CSqlDataProvider($callerTeamSql, array(
  1037. 'keyField' => 'Id',
  1038. 'totalItemCount'=>count($countcallerInfo),
  1039. 'sort'=>array(
  1040. 'attributes'=>array(
  1041. 'Id',
  1042. ),
  1043. ),
  1044. 'pagination'=>false,
  1045. ));
  1046. $this->renderPartial('_workload', array('dataProviderWorkload' => $dataProviderWorkload));
  1047. }
  1048. //Working
  1049. public function actionWorkload()
  1050. {
  1051. $today12PM = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
  1052. $tomorrow12PM = mktime(0, 0, 0, date("m"), date("d"), date("Y")) + 86400;
  1053. $yesterday12PM = mktime(0, 0, 0, date("m"), date("d"), date("Y")) - 86400;
  1054. $LastMonth_first_minute = mktime(0, 0, 0, date("n") - 1, 1);
  1055. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1);
  1056. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"));
  1057. $leadCond = '';
  1058. if(isset($_POST['searchDashboard']) && !empty($_POST['searchDashboard']))
  1059. {
  1060. $searchDate=$_POST['searchDashboard'];
  1061. $searchTimestamp=strtotime(@$searchDate);
  1062. $searchEndTimestamp=$searchTimestamp+86400;
  1063. $leadCond = " and lead.updatedOn >= '".@$searchTimestamp."' and lead.updatedOn < '".@$searchEndTimestamp."'";
  1064. }
  1065. $filtercaller = @$_REQUEST['User']['userName'];
  1066. $filtersource = @$_REQUEST['LeadSourceMaster']['leadSourceId'];
  1067. $filterdate1 = @$_REQUEST['Lead']['createdOn'];
  1068. $filterdate2 = @$_REQUEST['Lead']['createdOn2'];
  1069. $filterCond = '';
  1070. if (isset($filtercaller) && !empty($filtercaller))
  1071. {
  1072. $filterCond .= " AND lead.currentAllocatedId = " . $filtercaller . "";
  1073. }
  1074. if (isset($filtersource) && !empty($filtersource))
  1075. {
  1076. $filterCond .= " AND lead.leadSourceId = " . $filtersource . "";
  1077. }
  1078. if (isset($filterdate1) && !empty($filterdate1) && isset($filterdate2) && !empty($filterdate2))
  1079. {
  1080. $date1Filer = strtotime($filterdate1);
  1081. $date2Filer = strtotime($filterdate2);
  1082. $filterCond .= " AND lead.updatedOn >= " . $date1Filer . " AND lead.updatedOn <= " . $date2Filer . "";
  1083. }
  1084. if (Yii::app()->session->get('isAllocator') == 'yes')
  1085. {
  1086. $allocatorTl = Yii::app()->db->createCommand("select group_concat(distinct id) as TLIDS from user where roleId=4")->queryAll();
  1087. $impresuser = @$allocatorTl[0]['TLIDS'];
  1088. }
  1089. else
  1090. {
  1091. $impresuser = $this->implodeResult(Yii::app()->session['relationalManager']);
  1092. }
  1093. $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 lead.updatedOn <= '".@$CurrentMonth_first_minute."',1,0)) as LM from user u left join lead on lead.currentAllocatedId=u.Id where u.Id IN (".@$impresuser.") and u.status='Active' and lead.currentAllocatedId IN (".@$impresuser.") ".@$filterCond." ".$leadCond." group By u.id ";
  1094. $countTeamworkLoad=Yii::app()->db->createCommand($teamworkloadSql)->queryAll();
  1095. $dataProviderWorkload = new CSqlDataProvider($teamworkloadSql, array(
  1096. 'keyField' => 'Id',
  1097. 'totalItemCount'=>count($countTeamworkLoad),
  1098. 'sort'=>array(
  1099. 'attributes'=>array(
  1100. 'Id',
  1101. ),
  1102. ),
  1103. 'pagination'=>array(
  1104. 'pageSize'=>10,
  1105. 'pageVar'=>'workload', //page selector
  1106. ),
  1107. ));
  1108. $this->layout = false;
  1109. $this->render('_workload', array('dataProviderWorkload' => $dataProviderWorkload));
  1110. }
  1111. public function actionSpeedometer()
  1112. {
  1113. $ManagerDetails = Yii::app()->db->createCommand("select user.managerId,user.Id,user.userName from user where managerId='" . Yii::app()->session->get('id') . "'")->queryAll();
  1114. $managerIds = self::fetchAllmanagerLevelRecords($total_firstLevel, $ManagerDetails, Yii::app()->session->get('id'));
  1115. if (empty($managerIds))
  1116. {
  1117. $managerIds[] = $_SESSION['id'];
  1118. }
  1119. else
  1120. {
  1121. $pusharray = array();
  1122. $pusharray[] = @$_SESSION['id'];
  1123. $managerIds = array_unique(array_merge(@$managerIds, @$pusharray));
  1124. }
  1125. if (strtolower(Yii::app()->session->get('roleName')) == "teamleader")
  1126. {
  1127. $teamLeaderTeamUserIdsRes = array();
  1128. $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();
  1129. if (count($teamLeaderTeamUserIds) > 0)
  1130. {
  1131. foreach ($teamLeaderTeamUserIds as $keyd => $valued)
  1132. {
  1133. $teamLeaderTeamUserIdsRes[] = $valued['userId'];
  1134. }
  1135. $managerIds = array_unique(array_merge($managerIds, $teamLeaderTeamUserIdsRes));
  1136. }
  1137. }
  1138. $managerDetailsArr = self::ManagerDetails($managerIds);
  1139. Yii::app()->session['relationalManager'] = $managerIds;
  1140. //$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();
  1141. $speedmeterUser = @$_REQUEST['speedmeterUser'];
  1142. if (isset($speedmeterUser) && !empty($speedmeterUser))
  1143. {
  1144. $totalAmountOfSpeedometer = Lead::model()->closedLeadsAmount($speedmeterUser);
  1145. }
  1146. else
  1147. {
  1148. $totalAmountOfSpeedometer = 0;
  1149. }
  1150. $totalClosedAmount = intval(@$totalAmountOfSpeedometer[0]['totalAmount']);
  1151. if ($totalClosedAmount > 1000000)
  1152. {
  1153. $totalClosedAmount = 1000000;
  1154. }
  1155. $totalclosedAmount = 1000000;
  1156. if ($totalClosedAmount > 0)
  1157. {
  1158. $totalClosedAmount = $totalClosedAmount;
  1159. }
  1160. else
  1161. {
  1162. $totalClosedAmount = 1;
  1163. }
  1164. $chartAmount = intval($totalclosedAmount - $totalClosedAmount);
  1165. $this->layout = 'maindashboard';
  1166. $this->render('_speedometer', array('totalClosedAmount' => $totalClosedAmount,'totalAmountOfSpeedometer'=>@$totalAmountOfSpeedometer, 'chartAmount' => $chartAmount, 'managerDetailsArr' => $managerDetailsArr));
  1167. }
  1168. public function actionMeeting()
  1169. {
  1170. $this->layout = false;
  1171. $this->render('_meeting');
  1172. }
  1173. /**
  1174. * Action LeadforToday. Loads monthly and yearly lead count.
  1175. */
  1176. public function actionLeadForToday()
  1177. {
  1178. $financialyear = @$_POST['financialyear'] ? $_POST['financialyear'] : date('Y');
  1179. $monthKey = date('m');
  1180. self::insertUsersRecord($financialyear, $monthKey);
  1181. $this->layout = false;
  1182. $this->renderPartial('_leadfortoday', array('dataProviderc' => self::getDataProviderc()));
  1183. }
  1184. public function actionAnnouncement()
  1185. {
  1186. $this->layout = false;
  1187. $this->renderPartial('_announcement');
  1188. }
  1189. //In Working condition.
  1190. public function actionPerformance()
  1191. {
  1192. $dataProviderPerf = self::getDataProviderPerf();
  1193. $this->layout = false;
  1194. $this->renderPartial('_performance', array('dataProviderPerf' => $dataProviderPerf));
  1195. }
  1196. protected static function SecondLevel($managerId, $userId)
  1197. {
  1198. return Yii::app()->db->createCommand("select user.managerId,user.Id,user.userName from user where user.managerId='$managerId' and user.managerId!='$userId' ")->queryAll();
  1199. }
  1200. protected static function ManagerLevel($userIds, $managerIds)
  1201. {
  1202. return Yii::app()->db->createCommand("select user.managerId,user.Id,user.userName from user where user.managerId ='$userIds' and id!='$managerIds' ")->queryAll();
  1203. }
  1204. protected static function ManagerDetails($userIds)
  1205. {
  1206. $userIds = self::UserWithManagerIdsImploded($userIds);
  1207. if ($userIds != '')
  1208. {
  1209. return Yii::app()->db->createCommand("select * from user where user.Id IN ($userIds) ")->queryAll();
  1210. }
  1211. }
  1212. protected static function UserWithManagerIdsImploded($userIds)
  1213. {
  1214. $userIds = array_filter($userIds);
  1215. return $userIds = implode(",", $userIds);
  1216. }
  1217. protected static function fetchAllmanagerLevelRecords(&$total_firstLevel, $ManagerDetails, $currentUserIds)
  1218. {
  1219. foreach ($ManagerDetails as $key => $value)
  1220. {
  1221. $total_firstLevel[] = $value['Id'];
  1222. $total_res = self::SecondLevel($value['Id'], $currentUserIds);
  1223. $res[] = count($total_res);
  1224. if (count($total_res) > 0)
  1225. {
  1226. $o = 0;
  1227. foreach ($total_res as $key1 => $value1)
  1228. {
  1229. $total_firstLevel[] = $value1['Id'];
  1230. $net_res = self::fetchAllmanagerLevelRecords($total_firstLevel, self::ManagerLevel($value1['Id'],
  1231. Yii::app()->session->get('id')), Yii::app()->session->get('id'));
  1232. $o++;
  1233. }
  1234. }
  1235. }
  1236. return $total_firstLevel;
  1237. }
  1238. protected static function getDataProviderc()
  1239. {
  1240. $LeadStatusSql = "SELECT ls.leadstatus,ls.leadstatusId,ls.sortOrder FROM `leadstatus` ls where ls.status='Active' order by ls.sortOrder ASC ";
  1241. // $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";
  1242. $count = Yii::app()->db->createCommand($LeadStatusSql)->queryAll();
  1243. $dataProviderc = new CSqlDataProvider($LeadStatusSql, array(
  1244. 'keyField' => 'leadstatusId',
  1245. 'totalItemCount' => count($count),
  1246. 'sort' => array(
  1247. 'attributes' => array(
  1248. 'leadStatusId',
  1249. ),
  1250. ),
  1251. 'pagination' => array(
  1252. 'pageSize' => 50,
  1253. 'pageVar' => 'gyu', //page selector
  1254. ),
  1255. ));
  1256. return $dataProviderc;
  1257. }
  1258. protected static function getDataProviderPerf()
  1259. {
  1260. $leadCond='';
  1261. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1);
  1262. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"));
  1263. $CurrentYear_first_minute = mktime(0, 0, 0, 1, 1, date('Y'));
  1264. $CurrentYear_last_minute = mktime(0, 0, 0, 13, 0, date('Y'));
  1265. if(isset($_POST['searchDashboard']) && !empty($_POST['searchDashboard']))
  1266. {
  1267. $searchDate=$_POST['searchDashboard'];
  1268. $searchTimestamp=strtotime(@$searchDate);
  1269. $searchEndTimestamp=$searchTimestamp+86400;
  1270. $leadCond = " and lead.updatedOn >= '".@$searchTimestamp."' and lead.updatedOn < '".@$searchEndTimestamp."'";
  1271. }
  1272. if (Yii::app()->session->get('isAllocator') == 'yes')
  1273. {
  1274. $allocatorTl = Yii::app()->db->createCommand("select group_concat(distinct id) as TLIDS from user where roleId=4")->queryAll();
  1275. $impresuser = @$allocatorTl[0]['TLIDS'];
  1276. }
  1277. else
  1278. {
  1279. $impresuser = Yii::app()->Controller->implodeResult(Yii::app()->session['relationalManager']);
  1280. }
  1281. $performanceSql = "SELECT u.firstName,u.lastName,u.id as Id,SUM(IF(lead.updatedOn >= '".@$CurrentMonth_first_minute."' and lead.updatedOn <= '".@$CurrentMonth_last_minute."' and lead.leadStatusId = 7,1,0)) as MTD,SUM(IF(lead.updatedOn >= '".@$CurrentYear_first_minute."' and lead.updatedOn <= '".@$CurrentYear_last_minute."' and lead.leadStatusId = 7,1,0)) as YTD ,SUM(IF(lead.updatedOn >= '".@$CurrentYear_first_minute."' and lead.updatedOn <= '".@$CurrentYear_last_minute."' and lead.leadStatusId = 7,lead.premium,0)) as premium,SUM(IF(lead.updatedOn >= '".@$CurrentMonth_first_minute."' and lead.updatedOn <= '".time()."' and lead.leadStatusId = 7,lead.premium,0)) as mtdpremium,SUM(IF(lead.leadStatusId=7,1,0)) as closeLeads from user u left join lead on lead.currentAllocatedId=u.Id where u.Id IN (".@$impresuser.") and u.status='Active' and lead.currentAllocatedId IN (".@$impresuser.") ".$leadCond." group By u.id ";
  1282. $countPerf=Yii::app()->db->createCommand($performanceSql)->queryAll();
  1283. $dataProviderPerf = new CSqlDataProvider($performanceSql, array(
  1284. 'keyField' => 'Id',
  1285. 'totalItemCount'=>count($countPerf),
  1286. 'sort'=>array(
  1287. 'attributes'=>array(
  1288. 'Id',
  1289. ),
  1290. ),
  1291. 'pagination'=>array(
  1292. 'pageSize'=>10,
  1293. 'pageVar'=>'performance', //page selector
  1294. ),
  1295. ));
  1296. return $dataProviderPerf;
  1297. }
  1298. public static function getRequiredVariables()
  1299. {
  1300. global $today12PM;
  1301. global $tomorrow12PM;
  1302. global $yesterday12PM;
  1303. global $LastMonth_first_minute;
  1304. global $LastMonth_first_minute;
  1305. global $CurrentMonth_first_minute;
  1306. global $CurrentMonth_last_minute;
  1307. global $filtercaller;
  1308. global $filtersource;
  1309. global $filterdate1;
  1310. global $filterdate2;
  1311. global $filterCond;
  1312. global $searchDate;
  1313. global $searchTimestamp;
  1314. global $searchEndTimestamp;
  1315. global $leadCond;
  1316. global $impresuser;
  1317. $today12PM = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
  1318. $tomorrow12PM = mktime(0, 0, 0, date("m"), date("d"), date("Y")) + 86400;
  1319. $yesterday12PM = mktime(0, 0, 0, date("m"), date("d"), date("Y")) - 86400;
  1320. $LastMonth_first_minute = mktime(0, 0, 0, date("n") - 1, 1);
  1321. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1);
  1322. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"));
  1323. $filtercaller = @$_REQUEST['User']['userName'];
  1324. $filtersource = @$_REQUEST['LeadSourceMaster']['leadSourceId'];
  1325. $filterdate1 = @$_REQUEST['Lead']['createdOn'];
  1326. $filterdate2 = @$_REQUEST['Lead']['createdOn2'];
  1327. $filterCond = '';
  1328. if(isset($_POST['searchDashboard']))
  1329. {
  1330. $searchDate = $_POST['searchDashboard'];
  1331. }
  1332. else
  1333. {
  1334. $searchDate = date('Y');
  1335. }
  1336. $searchTimestamp = strtotime(@$searchDate);
  1337. $searchEndTimestamp = $searchTimestamp + 86400;
  1338. $leadCond = " and lead.updatedOn >= '" . @$searchTimestamp . "' and lead.updatedOn < '" . @$searchEndTimestamp . "'";
  1339. if (isset($filtercaller) && !empty($filtercaller))
  1340. {
  1341. $filterCond .= " AND lead.currentAllocatedId = " . $filtercaller . "";
  1342. }
  1343. if (isset($filtersource) && !empty($filtersource))
  1344. {
  1345. $filterCond .= " AND lead.leadSourceId = " . $filtersource . "";
  1346. }
  1347. if (isset($filterdate1) && !empty($filterdate1) && isset($filterdate2) && !empty($filterdate2))
  1348. {
  1349. $date1Filer = strtotime($filterdate1);
  1350. $date2Filer = strtotime($filterdate2);
  1351. $filterCond .= " AND lead.updatedOn >= " . $date1Filer . " AND lead.updatedOn <= " . $date2Filer . "";
  1352. }
  1353. if (Yii::app()->session->get('isAllocator') == 'yes')
  1354. {
  1355. $allocatorTl = Yii::app()->db->createCommand("select group_concat(distinct id) as TLIDS from user where roleId=4")->queryAll();
  1356. $impresuser = @$allocatorTl[0]['TLIDS'];
  1357. }
  1358. else
  1359. {
  1360. $impresuser = Yii::app()->getController()->implodeResult(Yii::app()->session['relationalManager']);
  1361. }
  1362. }
  1363. public static function getMeetingDate()
  1364. {
  1365. $relationManager = $_SESSION['relationalManager'];
  1366. $managerMemberId = implode(",", array_unique(@$relationManager));
  1367. Yii::app()->getClientScript()->registerScriptFile(Yii::app()->baseUrl . '/js/fullcalendar.js');
  1368. $todayTime = strtotime(date('d M Y'));
  1369. $timbefore3days = strtotime('-3 days', time());
  1370. $timafter3days = strtotime('+3 days', time());
  1371. $models = Yii::app()->db->createCommand("SELECT startDate, count(*) AS total,leadFollowupId FROM leadFollowup WHERE
  1372. userId IN (" . @$managerMemberId . ") AND STATUS = 'Pending' AND (actionType = 'Meeting' OR actionType = 'Follow Up') AND (startDate >= $timbefore3days and startDate <= $timafter3days ) GROUP BY startDate DESC")->queryAll();
  1373. $meetingArray = array();
  1374. for ($i = 0; $i < count($models); $i++)
  1375. {
  1376. $meetingDate = @$models[$i]['startDate'];
  1377. $totalCount = @$models[$i]['total'];
  1378. $monthValue = date('m', @$models[$i]['startDate']);
  1379. $meetingArray[$i]['totalCount'] = @$totalCount;
  1380. $meetingArray[$i]['day'] = date('d', @$models[$i]['startDate']);
  1381. $meetingArray[$i]['month'] = $monthValue - 1;
  1382. $meetingArray[$i]['year'] = date('Y', @$models[$i]['startDate']);
  1383. $meetingArray[$i]['leadFollowupId'] = @$models[$i]['leadFollowupId'];
  1384. $meetingModels = LeadFollowup::model()->findAll(array("condition" => "startDate = '" . @$meetingDate . "' AND userId IN(" . @$managerMemberId . ") AND STATUS = 'Pending' AND (actionType = 'Meeting' OR actionType = 'Follow Up') ORDER BY hour DESC"));
  1385. $meetingArray[$i]['finalDescription'] = '';
  1386. for ($j = 0; $j < count($meetingModels); $j++)
  1387. {
  1388. $srno = $j + 1;
  1389. $meetingArray[$i]['finalDescription'] = @$meetingDate;
  1390. }
  1391. }
  1392. return $meetingArray;
  1393. }
  1394. public static function insertUserLeadAllCountRecord($financialyear, $monthKey = null, $userId = null){
  1395. if(!$userId)
  1396. {
  1397. $userId = Yii::app()->session['id'];
  1398. }
  1399. $monthKey = $monthKey;
  1400. $userCountRecord = Yii::app()->db->createCommand("select count(*) as count from leadallcount where userId = $userId && accesskey = '$financialyear-$monthKey'")->queryRow();
  1401. if(!$userCountRecord['count'])
  1402. {
  1403. $queryString = "insert into leadallcount (userid, accesskey, leadtype, count, createdOn, createdBy, updatedOn, updatedBy) values(";
  1404. $leadStatusRecords = Yii::app()->db->createCommand('select leadStatusId from leadstatus')->queryAll();
  1405. $createdOn = time();
  1406. $totalRecordsInserted = 0;
  1407. Yii::app()->db->createCommand('START TRANSACTION;')->execute();
  1408. foreach($leadStatusRecords as $leadStatusId)
  1409. {
  1410. $statusId = $leadStatusId['leadStatusId'];
  1411. if($monthKey)
  1412. {
  1413. $getMTDStatusCount = DashboardController::getMTD($statusId);
  1414. $insertMTDStatusCount = "$queryString $userId, '$financialyear-$monthKey', $statusId, $getMTDStatusCount, $createdOn, $userId, $createdOn, $userId)";
  1415. Yii::app()->db->createCommand($insertMTDStatusCount)->execute();
  1416. $totalRecordsInserted = $totalRecordsInserted + 1;
  1417. }
  1418. $getYTDStatusCount = DashboardController::getYTD($statusId);
  1419. $insertYTDStatusCount = "$queryString $userId, '$financialyear', $statusId, $getYTDStatusCount, $createdOn, $userId, $createdOn, $userId)";
  1420. Yii::app()->db->createCommand($insertYTDStatusCount)->execute();
  1421. $totalRecordsInserted = $totalRecordsInserted + 1;
  1422. }
  1423. $totalLeadTypes = Yii::app()->db->createCommand('select count(*) as count from leadstatus')->queryRow();
  1424. if(($totalRecordsInserted == $totalLeadTypes['count']*2 && $monthKey) || ($totalRecordsInserted == $totalLeadTypes['count'] && !$monthKey))
  1425. {
  1426. Yii::app()->db->createCommand('COMMIT;')->execute();
  1427. }
  1428. else
  1429. {
  1430. Yii::app()->db->createCommand('ROLLBACK;')->execute();
  1431. }
  1432. }
  1433. }
  1434. }