PageRenderTime 79ms CodeModel.GetById 22ms 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

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

  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. $CurrentYea

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