PageRenderTime 57ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/lms_debug/protected/controllers/DashboardController_18dec2014.php

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

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