PageRenderTime 88ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 1ms

/lms_debug/protected/controllers/DashboardController_19dec2014.php

https://gitlab.com/badelal143/lms_debug
PHP | 1625 lines | 1242 code | 237 blank | 146 comment | 160 complexity | 984b8c96f74af93c2feb85321949b394 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 All Counts. Fetch & return the counts relevent to the access key & status of logged in user.
  233. * @return array
  234. */
  235. public static function getLeadAllCounts()
  236. {
  237. $userId = Yii::app()->session['id'];
  238. return Yii::app()->db->createCommand("select * from leadallcount where userid = $userId")->queryAll();
  239. }
  240. /**
  241. * Get Lead Status Count.(For Teamleader, add counts of his callers as well).
  242. * @see _leadfortoday.php
  243. * @return int
  244. */
  245. public static function getLeadStatusCount($leadStatusId, $accessKey, $leadAllCounts)
  246. {
  247. $financialDate = explode('-', $accessKey);
  248. $financialDate[0] = $financialDate[0] ? $financialDate[0] : date('Y');
  249. $financialDate[1] = @$financialDate[1] ? $financialDate[1] : date('m');
  250. $statusCount = 0;
  251. if(Yii::app()->session->get('type') == 'TeamLeader' || Yii::app()->session->get('type') == 'admin')
  252. {
  253. $callerList = User::model()->fetchCallersList();
  254. if(count($callerList))
  255. {
  256. foreach($callerList as $list)
  257. {
  258. self::insertUserLeadAllCountRecord($financialDate[0], $financialDate[1], $list['id']);
  259. $leadAllCountOfUser = self::getLeadAllCounts($list['id']);
  260. $statusCount = $statusCount + self::getLeadStatusCountByUser($leadStatusId, $accessKey, $leadAllCountOfUser);
  261. }
  262. }
  263. }
  264. return $statusCount + self::getLeadStatusCountByUser($leadStatusId, $accessKey, $leadAllCounts);
  265. }
  266. /**
  267. * Get Lead Status Count of indivisual user.
  268. * @see DashboardController::getLeadStatusCount
  269. * @return int
  270. */
  271. protected static function getLeadStatusCountByUser($leadStatusId, $accessKey, $leadAllCounts)
  272. {
  273. foreach($leadAllCounts as $record)
  274. {
  275. if($record['accesskey'] == $accessKey && $record['leadtype'] == $leadStatusId)
  276. {
  277. return $record['count'];
  278. }
  279. }
  280. }
  281. /**
  282. * This is the 'module master' action that is invoked
  283. * when an action is not explicitly requested by users.
  284. */
  285. public function actionmodule_master()
  286. {
  287. // renders the view file 'protected/views/site/index.php'
  288. // using the default layout 'protected/views/layouts/main.php'
  289. $model = new ModuleMaster();
  290. $model->scenario = 'ModuleMaster';
  291. if (!empty($_GET['moduleId']))
  292. {
  293. $moduleId = $_GET['moduleId'];
  294. $model = ModuleMaster::model()->findByPk($moduleId);
  295. }
  296. if (!empty($_POST['ModuleMaster']['moduleId']))
  297. {
  298. $moduleId = $_POST['ModuleMaster']['moduleId'];
  299. $model = ModuleMaster::model()->findByPk($moduleId);
  300. }
  301. if (isset($_POST['ModuleMaster']))
  302. {
  303. $model->setAttributes(array(
  304. 'createdOn' => time(), //additional data you want to insert
  305. 'updatedOn' => time(), //additional
  306. 'updatedBy' => time(), //additional
  307. 'createdBy' => time(),
  308. 'status' => 'Activated', //additional //additional
  309. ));
  310. foreach ($_POST['ModuleMaster'] as $name => $value)
  311. {
  312. $model->$name = $value;
  313. }
  314. if ($model->validate())
  315. {
  316. $model->save();
  317. $model2 = ModuleMaster::model()->findAll();
  318. $this->render('module_master', array('model' => $model, 'model2' => $model2));
  319. Yii::app()->user->setFlash('module_master_msg_success', 'Successfully Inserted');
  320. }
  321. else
  322. {
  323. Yii::app()->user->setFlash('module_master_msg_error', 'Please check. error occured');
  324. $this->render('module_master', array('model' => $model));
  325. }
  326. }
  327. else
  328. {
  329. $model2 = ModuleMaster::model()->findAll();
  330. //Yii::app()->user->setFlash('lead_stage_msg_error','Please check. error occured');
  331. $this->render('module_master', array('model' => $model, 'model2' => $model2));
  332. }
  333. }
  334. /**
  335. * This is the action to handle external exceptions.
  336. */
  337. public function actionError()
  338. {
  339. if ($error = Yii::app()->errorHandler->error)
  340. {
  341. if (Yii::app()->request->isAjaxRequest)
  342. echo $error['message'];
  343. else
  344. $this->render('error', $error);
  345. }
  346. }
  347. /**
  348. * Displays the contact page
  349. */
  350. public function actionContact()
  351. {
  352. $model = new ContactForm;
  353. if (isset($_POST['ContactForm']))
  354. {
  355. $model->attributes = $_POST['ContactForm'];
  356. if ($model->validate())
  357. {
  358. $name = '=?UTF-8?B?' . base64_encode($model->name) . '?=';
  359. $subject = '=?UTF-8?B?' . base64_encode($model->subject) . '?=';
  360. $headers = "From: $name <{$model->email}>\r\n" .
  361. "Reply-To: {$model->email}\r\n" .
  362. "MIME-Version: 1.0\r\n" .
  363. "Content-type: text/plain; charset=UTF-8";
  364. mail(Yii::app()->params['adminEmail'], $subject, $model->body, $headers);
  365. Yii::app()->user->setFlash('contact', 'Thank you for contacting us. We will respond to you as soon as possible.');
  366. $this->refresh();
  367. }
  368. }
  369. $this->render('contact', array('model' => $model));
  370. }
  371. /**
  372. * Displays the login page
  373. */
  374. public function actionLogin()
  375. {
  376. $model = new User;
  377. // if it is ajax validation request
  378. if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form')
  379. {
  380. echo CActiveForm::validate($model);
  381. Yii::app()->end();
  382. }
  383. // collect user input data
  384. if (isset($_POST['User']))
  385. {
  386. $model->attributes = $_POST['User'];
  387. // validate user input and redirect to the previous page if valid
  388. if ($model->validate() && $model->login())
  389. {
  390. $this->redirect(array('masters/dashboard'));
  391. }
  392. else
  393. {
  394. $this->redirect(Yii::app()->user->returnUrl);
  395. }
  396. }
  397. // display the login form
  398. $this->render('login', array('model' => $model));
  399. }
  400. /**
  401. * Logs out the current user and redirect to homepage.
  402. */
  403. public function actionLogout()
  404. {
  405. Yii::app()->user->logout();
  406. $this->redirect(Yii::app()->homeUrl);
  407. }
  408. public function getPageType()
  409. {
  410. return "";
  411. }
  412. public function actionViewFancyboxData()
  413. {
  414. $userId = @$_REQUEST['id'];
  415. $model = new User;
  416. $model = User::model()->findByPk($userId);
  417. if (!Yii::app()->request->isAjaxRequest)
  418. {
  419. // $this->render('yourView');
  420. }
  421. else
  422. {
  423. $this->renderPartial('/masters/partialNotification');
  424. Yii::app()->end();
  425. }
  426. }
  427. public function actionViewWorkLoadData()
  428. {
  429. if (!Yii::app()->request->isAjaxRequest)
  430. {
  431. // $this->render('yourView');
  432. }
  433. else
  434. {
  435. $this->renderPartial('/leads/partialWorkLoadData');
  436. Yii::app()->end();
  437. }
  438. }
  439. public function actionViewLeadSummaryData()
  440. {
  441. //$this->layout='column3';
  442. $this->layout = false;
  443. $parser = new CHtmlPurifier();
  444. $leadStatusId = $parser->purify(intval(@$_REQUEST['leadStatusId']));
  445. /* $model=new Lead;
  446. $model=Lead::model()->findAll("leadStatusId = '".@$leadStatusId."' ");
  447. */
  448. if (!Yii::app()->request->isAjaxRequest)
  449. {
  450. $this->render('/leads/partialLeadSummary', array('leadStatusId' => $leadStatusId));
  451. }
  452. else
  453. {
  454. $this->layout=false;
  455. $this->render('/leads/partialLeadSummary', array('leadStatusId' => $leadStatusId));
  456. Yii::app()->end();
  457. }
  458. }
  459. public function actionRenewalViewLeadSummaryData()
  460. {
  461. //$this->layout='column3';
  462. $this->layout = false;
  463. $res = new MySanitizeClass;
  464. $leadStatusId = $res->sanitize_description(@$_REQUEST['leadStatusId']);
  465. /* $model=new Lead;
  466. $model=Lead::model()->findAll("leadStatusId = '".@$leadStatusId."' ");
  467. */ if (!Yii::app()->request->isAjaxRequest)
  468. {
  469. $this->render('/renewalleads/renewalpartialLeadSummary', array('leadStatusId' => $leadStatusId));
  470. }
  471. else
  472. {
  473. //$this->layout=false;
  474. $this->render('/renewalleads/renewalpartialLeadSummary', array('leadStatusId' => $leadStatusId));
  475. Yii::app()->end();
  476. }
  477. }
  478. function getparentLeadStatus($parentId)
  479. {
  480. $primary = LeadStatus::model()->findByPk($parentId);
  481. if ($primary['parentId'] > 0)
  482. {
  483. $parentName = LeadStatus::model()->findByPk($primary['parentId']);
  484. $pname = $parentName['leadStatus'];
  485. }
  486. else
  487. {
  488. $pname = "Primary";
  489. }
  490. return $pname;
  491. }
  492. public function actionViewAllWorkLoadData()
  493. {
  494. function ManagerDetails($userIds)
  495. {
  496. $userIds = UserWithManagerIdsImploded($userIds);
  497. if ($userIds != '')
  498. {
  499. return Yii::app()->db->createCommand("select * from user where user.Id IN ($userIds) ")->queryAll();
  500. }
  501. }
  502. function UserWithManagerIdsImploded($userIds)
  503. {
  504. return $userIds = implode(",", $userIds);
  505. }
  506. $managerDetailsArr = ManagerDetails(Yii::app()->session['relationalManager']);
  507. if (!Yii::app()->request->isAjaxRequest)
  508. {
  509. // $this->render('yourView');
  510. }
  511. else
  512. {
  513. $this->renderPartial('/leads/partialAllWorkLoadData', array('managerDetailsArr' => $managerDetailsArr));
  514. Yii::app()->end();
  515. }
  516. }
  517. public function actionViewAllPerformanceData()
  518. {
  519. function ManagerDetails($userIds)
  520. {
  521. $userIds = UserWithManagerIdsImploded($userIds);
  522. if ($userIds != '')
  523. {
  524. return Yii::app()->db->createCommand("select * from user where user.Id IN ($userIds) ")->queryAll();
  525. }
  526. }
  527. function UserWithManagerIdsImploded($userIds)
  528. {
  529. return $userIds = implode(",", $userIds);
  530. }
  531. $managerDetailsArr = ManagerDetails(Yii::app()->session['relationalManager']);
  532. if (!Yii::app()->request->isAjaxRequest)
  533. {
  534. $this->render('/leads/partialAllPerfLoadData', array('managerDetailsArr' => $managerDetailsArr));
  535. // $this->render('yourView');
  536. }
  537. else
  538. {
  539. $this->renderPartial('/leads/partialAllPerfLoadData', array('managerDetailsArr' => $managerDetailsArr));
  540. Yii::app()->end();
  541. }
  542. }
  543. public function actionrenewal()
  544. {
  545. //$this->redirect(array('dashboard/dashboard'));
  546. $leadCond = '';
  547. $PiechartCond = '';
  548. $NotificationCond1 = '';
  549. $NotificationCond2 = '';
  550. $currentDateNot = date('d-m-Y');
  551. $currentTimestamp = strtotime($currentDateNot);
  552. if (isset($_POST['searchDashboard']) && !empty($_POST['searchDashboard']))
  553. {
  554. $searchDate = $_POST['searchDashboard'];
  555. $searchTimestamp = strtotime(@$searchDate);
  556. $searchEndTimestamp = $searchTimestamp + 86400;
  557. $leadCond = " and renewallead.updatedOn >= '" . @$searchTimestamp . "' and renewallead.updatedOn < '" . @$searchEndTimestamp . "'";
  558. $PiechartCond = " and renewalleadSourceMaster.updatedOn >= '" . @$searchTimestamp . "' and renewalleadSourceMaster.updatedOn < '" . @$searchEndTimestamp . "'";
  559. $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') )";
  560. $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') )";
  561. }
  562. if (Yii::app()->session->get('isAllocator') == 'yes' or Yii::app()->session->get('type') == 'superadmin')
  563. {
  564. $LeasStatusCond = '';
  565. }
  566. else
  567. {
  568. $LeasStatusCond = ' AND renewallead.currentAllocatedId = "' . Yii::app()->session->get('id') . '"';
  569. }
  570. $LeadStatus = Yii::app()->db->createCommand('SELECT
  571. me.leadStatusId AS me_id,
  572. me.leadStatus AS me_leadStatus,
  573. renewallead.leadStatusId AS lead_leadStatusId,
  574. renewallead.leadId AS leadId,
  575. count(*) AS total
  576. FROM
  577. renewalleadStatus me
  578. left join renewallead on renewallead.leadStatusId=me.leadStatusId where renewallead.leadStatusId > 0 ' . $leadCond . ' ' . $LeasStatusCond . ' group by renewallead.leadStatusId')->queryAll();
  579. $LeadStatusSql = "SELECT ls.leadstatus,ls.leadstatusId,ls.sortOrder FROM `renewalleadstatus` ls where ls.status='Active' order by ls.sortOrder ASC ";
  580. // $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";
  581. $count = Yii::app()->db->createCommand($LeadStatusSql)->queryAll();
  582. $dataProviderc = new CSqlDataProvider($LeadStatusSql, array(
  583. 'keyField' => 'leadstatusId',
  584. 'totalItemCount' => count($count),
  585. 'sort' => array(
  586. 'attributes' => array(
  587. 'leadStatusId',
  588. ),
  589. ),
  590. 'pagination' => array(
  591. 'pageSize' => 10,
  592. 'pageVar' => 'gyu', //page selector
  593. ),
  594. ));
  595. $where = '';
  596. if (Yii::app()->session->get('type') != 'superadmin')
  597. {
  598. $where = ' where renewalnotificationMapping.roleId="' . Yii::app()->session->get('roleId') . '"';
  599. $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') )";
  600. $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();
  601. }
  602. else
  603. {
  604. $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') )";
  605. $notifications = Yii::app()->db->createCommand("select renewalnotification.* from renewalnotification left join renewalnotificationMapping on renewalnotificationMapping.notificationId=renewalnotification.notificationId " . @$cls . " " . $NotificationCond2 . " group by renewalnotification.notificationId ")->queryAll();
  606. }
  607. $sourcewiseDetails = Yii::app()->db->createCommand("select renewalleadSourceMaster.* from renewalleadSourceMaster ")->queryAll();
  608. $ManagerDetails = Yii::app()->db->createCommand("select user.managerId,user.Id,user.userName from user where managerId='" . Yii::app()->session->get('id') . "'")->queryAll();
  609. function SecondLevel($managerId, $userId)
  610. {
  611. return Yii::app()->db->createCommand("select user.managerId,user.Id,user.userName from user where user.managerId='$managerId' and user.managerId!='$userId' ")->queryAll();
  612. }
  613. function ManagerLevel($userIds, $managerIds)
  614. {
  615. return Yii::app()->db->createCommand("select user.managerId,user.Id,user.userName from user where user.managerId ='$userIds' and id!='$managerIds' ")->queryAll();
  616. }
  617. function ManagerDetails($userIds)
  618. {
  619. $userIds = UserWithManagerIdsImploded($userIds);
  620. if ($userIds != '')
  621. {
  622. return Yii::app()->db->createCommand("select * from user where user.Id IN ($userIds) ")->queryAll();
  623. }
  624. }
  625. function UserWithManagerIdsImploded($userIds)
  626. {
  627. return $userIds = implode(",", $userIds);
  628. }
  629. $total_firstLevel = array();
  630. $total_nextLevel = array();
  631. function fetchAllmanagerLevelRecords(&$total_firstLevel, $ManagerDetails, $currentUserIds)
  632. {
  633. foreach ($ManagerDetails as $key => $value)
  634. {
  635. $total_firstLevel[] = $value['Id'];
  636. $total_res = SecondLevel($value['Id'], $currentUserIds);
  637. $res[] = count($total_res);
  638. if (count($total_res) > 0)
  639. {
  640. $o = 0;
  641. foreach ($total_res as $key1 => $value1)
  642. {
  643. $total_firstLevel[] = $value1['Id'];
  644. $net_res = fetchAllmanagerLevelRecords($total_firstLevel, ManagerLevel($value1['Id'], Yii::app()->session->get('id')), Yii::app()->session->get('id'));
  645. $o++;
  646. }
  647. }
  648. }
  649. return $total_firstLevel;
  650. }
  651. $managerIds = fetchAllmanagerLevelRecords($total_firstLevel, $ManagerDetails, Yii::app()->session->get('id'));
  652. if (empty($managerIds))
  653. {
  654. $managerIds[] = $_SESSION['id'];
  655. }
  656. else
  657. {
  658. $pusharray = array();
  659. $pusharray[] = @$_SESSION['id'];
  660. $managerIds = array_unique(array_merge(@$managerIds, @$pusharray));
  661. }
  662. if (strtolower(Yii::app()->session->get('roleName')) == "teamleader")
  663. {
  664. $teamLeaderTeamUserIdsRes = array();
  665. $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();
  666. if (count($teamLeaderTeamUserIds) > 0)
  667. {
  668. foreach ($teamLeaderTeamUserIds as $keyd => $valued)
  669. {
  670. $teamLeaderTeamUserIdsRes[] = $valued['userId'];
  671. }
  672. $managerIds = array_unique(array_merge($managerIds, $teamLeaderTeamUserIdsRes));
  673. }
  674. }
  675. $managerDetailsArr = ManagerDetails($managerIds);
  676. Yii::app()->session['relationalManager'] = $managerIds;
  677. $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();
  678. $speedmeterUser = @$_REQUEST['speedmeterUser'];
  679. if (isset($speedmeterUser) && !empty($speedmeterUser))
  680. {
  681. $totalAmountOfSpeedometer = Lead::model()->closedLeadsAmount($speedmeterUser);
  682. }
  683. else
  684. {
  685. $totalAmountOfSpeedometer = 0;
  686. }
  687. $this->render('renewaldashboard', array('LeadStatus' => @$LeadStatus, 'notifications' => @$notifications, 'sourcewiseDetails' => @$sourcewiseDetails, 'sourcewiseDetailsWithPiechart' => @$sourcewiseDetailsWithPiechart, 'managerDetailsArr' => @$managerDetailsArr, 'totalAmountOfSpeedometer' => @$totalAmountOfSpeedometer, 'dataProviderc' => $dataProviderc));
  688. }
  689. public function actionrenViewLeadSummaryData()
  690. {
  691. $this->layout = 'column3';
  692. $leadStatusId = @$_REQUEST['leadStatusId'];
  693. //$model=new Renewallead;
  694. //$model=Renewallead::model()->findAll("leadStatusId = '".@$leadStatusId."' ");
  695. if (!Yii::app()->request->isAjaxRequest)
  696. {
  697. $this->redirect('dashboard/renewal');
  698. }
  699. else
  700. {
  701. $this->render('/renewalleads/partialLeadSummary', array('leadStatusId' => $leadStatusId));
  702. Yii::app()->end();
  703. }
  704. }
  705. public function actionrenViewWorkLoadData()
  706. {
  707. if (!Yii::app()->request->isAjaxRequest)
  708. {
  709. // $this->render('yourView');
  710. }
  711. else
  712. {
  713. $this->renderPartial('/renewalleads/partialWorkLoadData');
  714. Yii::app()->end();
  715. }
  716. }
  717. public function actionrenViewAllWorkLoadData()
  718. {
  719. function ManagerDetails($userIds)
  720. {
  721. $userIds = UserWithManagerIdsImploded($userIds);
  722. if ($userIds != '')
  723. {
  724. return Yii::app()->db->createCommand("select id from user where user.Id IN ($userIds) ")->queryAll();
  725. }
  726. }
  727. function UserWithManagerIdsImploded($userIds)
  728. {
  729. return $userIds = implode(",", $userIds);
  730. }
  731. $managerDetailsArr = ManagerDetails(Yii::app()->session['relationalManager']);
  732. if (!Yii::app()->request->isAjaxRequest)
  733. {
  734. // $this->render('yourView');
  735. }
  736. else
  737. {
  738. $this->renderPartial('/renewalleads/partialAllWorkLoadData', array('managerDetailsArr' => $managerDetailsArr));
  739. Yii::app()->end();
  740. }
  741. }
  742. public function actionrenViewFancyboxData()
  743. {
  744. $userId = @$_REQUEST['id'];
  745. $model = new User;
  746. $model = User::model()->findByPk($userId);
  747. if (!Yii::app()->request->isAjaxRequest)
  748. {
  749. // $this->render('yourView');
  750. }
  751. else
  752. {
  753. $this->renderPartial('/renewalmasters/partialNotification');
  754. Yii::app()->end();
  755. }
  756. }
  757. public function actionrenViewAllPerformanceData()
  758. {
  759. function ManagerDetails($userIds)
  760. {
  761. $userIds = UserWithManagerIdsImploded($userIds);
  762. if ($userIds != '')
  763. {
  764. return Yii::app()->db->createCommand("select id from user where user.Id IN ($userIds) ")->queryAll();
  765. }
  766. }
  767. function UserWithManagerIdsImploded($userIds)
  768. {
  769. return $userIds = implode(",", array_filter($userIds));
  770. }
  771. $managerDetailsArr = ManagerDetails(Yii::app()->session['relationalManager']);
  772. if (!Yii::app()->request->isAjaxRequest)
  773. {
  774. $this->render('/renewalleads/partialAllPerfLoadData', array('managerDetailsArr' => $managerDetailsArr));
  775. // $this->render('yourView');
  776. }
  777. else
  778. {
  779. $this->renderPartial('/leads/partialAllPerfLoadData', array('managerDetailsArr' => $managerDetailsArr));
  780. Yii::app()->end();
  781. }
  782. }
  783. public function actionfullcalender()
  784. {
  785. // renders the view file 'protected/views/site/index.php'
  786. // using the default layout 'protected/views/layouts/main.php'
  787. $this->render('fullcalender');
  788. }
  789. public function actionmyteamworkload()
  790. {
  791. // renders the view file 'protected/views/site/index.php'
  792. // using the default layout 'protected/views/layouts/main.php'
  793. $this->layout = false;
  794. function ManagerDetails($userIds)
  795. {
  796. $userIds = UserWithManagerIdsImploded($userIds);
  797. if ($userIds != '')
  798. {
  799. return Yii::app()->db->createCommand("select * from user where user.Id IN ($userIds) ")->queryAll();
  800. }
  801. }
  802. function UserWithManagerIdsImploded($userIds)
  803. {
  804. return $userIds = implode(",", array_filter($userIds));
  805. }
  806. $managerDetailsArr = ManagerDetails(Yii::app()->session['relationalManager']);
  807. $this->render('myteamworkload', array('managerDetailsArr' => @$managerDetailsArr));
  808. }
  809. public static function implodeResult($userIds)
  810. {
  811. $userIds = array_filter($userIds);
  812. return $userIds = implode(",", $userIds);
  813. }
  814. public function actionshowLeadCount()
  815. {
  816. $this->layout = false;
  817. $this->render('showLeadCount');
  818. }
  819. public function actionshowleadcountdisp()
  820. {
  821. $this->layout = false;
  822. $this->render('showleadcountdisp');
  823. }
  824. public static function getMTD($leadStatusId)
  825. {
  826. if (Yii::app()->session->get('type') == 'superadmin')
  827. {
  828. $cond = '';
  829. }
  830. else
  831. {
  832. if (count(@$_SESSION['relationalManager']) > 0)
  833. {
  834. $teamids = implode(",", $_SESSION['relationalManager']);
  835. }
  836. else
  837. {
  838. $teamids = Yii::app()->session->get('id');
  839. }
  840. $cond = "AND l.currentAllocatedId IN (" . @$teamids . ")";
  841. }
  842. $financialyear = @$_POST['financialyear'];
  843. if (isset($financialyear) && !empty($financialyear))
  844. {
  845. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1, $financialyear);
  846. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"), $financialyear);
  847. }
  848. else
  849. {
  850. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1);
  851. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"));
  852. }
  853. $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 ";
  854. $count = Yii::app()->db->createCommand($sql)->queryColumn();
  855. return @$count[0];
  856. //echo Lead::model()->count(array("select"=>'leadid',"condition"=>" leadStatusId = ".@$leadStatusId.""));
  857. }
  858. public static function getYTD($leadStatusId)
  859. {
  860. if (Yii::app()->session->get('type') == 'superadmin')
  861. {
  862. $cond = '';
  863. }
  864. else
  865. {
  866. if (count(@$_SESSION['relationalManager']) > 0)
  867. {
  868. $teamids = implode(",", $_SESSION['relationalManager']);
  869. }
  870. else
  871. {
  872. $teamids = Yii::app()->session->get('id');
  873. }
  874. $cond = "AND l.currentAllocatedId IN (" . @$teamids . ")";
  875. }
  876. $financialyear = @$_POST['financialyear'];
  877. if (isset($financialyear) && !empty($financialyear))
  878. {
  879. $CurrentYear_first_minute = mktime(0, 0, 0, 4, 1, $financialyear);
  880. $CurrentYear_last_minute = mktime(0, 0, 0, 4, 0, $financialyear + 1);
  881. }
  882. else
  883. {
  884. $CurrentYear_first_minute = mktime(0, 0, 0, 4, 1, date('Y'));
  885. $CurrentYear_last_minute = mktime(0, 0, 0, 4, 0, date('Y') + 1);
  886. }
  887. //$CurrentYear_first_minute = mktime(0, 0, 0, 1, 1, date('Y'));
  888. //$CurrentYear_last_minute = mktime(0, 0, 0, 13, 0, date('Y'));
  889. $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 ";
  890. $count = Yii::app()->db->createCommand($sql)->queryColumn();
  891. //echo Lead::model()->count(array("select"=>'leadid',"condition"=>" leadStatusId = ".@$leadStatusId.""));
  892. return @$count[0];
  893. //return @$count[0];
  894. }
  895. public static function rengetMTD($leadStatusId)
  896. {
  897. if (Yii::app()->session->get('type') == 'superadmin')
  898. {
  899. $cond = '';
  900. }
  901. else
  902. {
  903. if (count(@$_SESSION['relationalManager']) > 0)
  904. {
  905. $teamids = implode(",", $_SESSION['relationalManager']);
  906. }
  907. else
  908. {
  909. $teamids = Yii::app()->session->get('id');
  910. }
  911. $cond = "AND l.currentAllocatedId IN (" . @$teamids . ")";
  912. }
  913. $financialyear = @$_POST['financialyear'];
  914. if (isset($financialyear) && !empty($financialyear))
  915. {
  916. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1, $financialyear);
  917. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"), $financialyear);
  918. }
  919. else
  920. {
  921. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1);
  922. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"));
  923. }
  924. $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 ";
  925. $count = Yii::app()->db->createCommand($sql)->queryColumn();
  926. return @$count[0];
  927. //echo Lead::model()->count(array("select"=>'leadid',"condition"=>" leadStatusId = ".@$leadStatusId.""));
  928. }
  929. public static function rengetYTD($leadStatusId)
  930. {
  931. if (Yii::app()->session->get('type') == 'superadmin')
  932. {
  933. $cond = '';
  934. }
  935. else
  936. {
  937. if (count(@$_SESSION['relationalManager']) > 0)
  938. {
  939. $teamids = implode(",", $_SESSION['relationalManager']);
  940. }
  941. else
  942. {
  943. $teamids = Yii::app()->session->get('id');
  944. }
  945. $cond = "AND l.currentAllocatedId IN (" . @$teamids . ")";
  946. }
  947. $financialyear = @$_POST['financialyear'];
  948. if (isset($financialyear) && !empty($financialyear))
  949. {
  950. $CurrentYear_first_minute = mktime(0, 0, 0, 4, 1, $financialyear);
  951. $CurrentYear_last_minute = mktime(0, 0, 0, 4, 0, $financialyear + 1);
  952. }
  953. else
  954. {
  955. $CurrentYear_first_minute = mktime(0, 0, 0, 4, 1, date('Y'));
  956. $CurrentYear_last_minute = mktime(0, 0, 0, 4, 0, date('Y') + 1);
  957. }
  958. //$CurrentYear_first_minute = mktime(0, 0, 0, 1, 1, date('Y'));
  959. //$CurrentYear_last_minute = mktime(0, 0, 0, 13, 0, date('Y'));
  960. $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 ";
  961. $count = Yii::app()->db->createCommand($sql)->queryColumn();
  962. //echo Lead::model()->count(array("select"=>'leadid',"condition"=>" leadStatusId = ".@$leadStatusId.""));
  963. return @$count[0];
  964. //return @$count[0];
  965. }
  966. /**
  967. * added by shakti.
  968. */
  969. public function actionWorkloadIncorrect()
  970. {
  971. $today12PM = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
  972. $tomorrow12PM = mktime(0, 0, 0, date("m"), date("d"), date("Y")) + 86400;
  973. $yesterday12PM = mktime(0, 0, 0, date("m"), date("d"), date("Y")) - 86400;
  974. $LastMonth_first_minute = mktime(0, 0, 0, date("n") - 1, 1);
  975. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1);
  976. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"));
  977. $leadCond = '';
  978. if(isset($_POST['searchDashboard']) && !empty($_POST['searchDashboard']))
  979. {
  980. $searchDate=$_POST['searchDashboard'];
  981. $searchTimestamp=strtotime(@$searchDate);
  982. $searchEndTimestamp=$searchTimestamp+86400;
  983. $leadCond = " and lead.updatedOn >= '".@$searchTimestamp."' and lead.updatedOn < '".@$searchEndTimestamp."'";
  984. }
  985. $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 <= '".@

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