PageRenderTime 50ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/lms_debug/protected/controllers/DashboardController_24dec2014.php

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