PageRenderTime 90ms CodeModel.GetById 15ms RepoModel.GetById 2ms app.codeStats 0ms

/lms_debug/protected/controllers/DashboardController_24dec2014.php

https://gitlab.com/badelal143/lms_debug
PHP | 1812 lines | 1312 code | 346 blank | 154 comment | 166 complexity | 394e6e3f5a3a4803e04ea46ae8c38922 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, LGPL-2.0

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

  1. <?php
  2. class DashboardController extends Controller
  3. {
  4. const SHARED_TITLE = "Admin Panel";
  5. /**
  6. * Declares class-based actions.
  7. */
  8. public function filters()
  9. {
  10. return array('accessControl', array(
  11. 'CHttpCacheFilter + view',
  12. 'cacheControl' => " max-age=604800, must-revalidate",
  13. )); // perform access control for CRUD operations
  14. }
  15. public function actions()
  16. {
  17. return array(
  18. // captcha action renders the CAPTCHA image displayed on the contact page
  19. 'captcha' => array(
  20. 'class' => 'CCaptchaAction',
  21. 'backColor' => 0xFFFFFF,
  22. ),
  23. // page action renders "static" pages stored under 'protected/views/site/pages'
  24. // They can be accessed via: index.php?r=site/page&view=FileName
  25. 'page' => array(
  26. 'class' => 'CViewAction',
  27. ),
  28. );
  29. }
  30. /**
  31. * This is the 'roles' action that is invoked
  32. * when an action is not explicitly requested by users.
  33. */
  34. protected function array_flatten($array)
  35. {
  36. if (!is_array($array))
  37. {
  38. return FALSE;
  39. }
  40. $result = array();
  41. foreach ($array as $key => $value)
  42. {
  43. if (is_array($value))
  44. {
  45. $result = array_merge($result, $this->array_flatten($value));
  46. }
  47. else
  48. {
  49. $result[$key] = $value;
  50. }
  51. }
  52. return $result;
  53. }
  54. /**
  55. * Action dashboard. //added by shakti. Please remove if not used.
  56. */
  57. public function actiondashboard()
  58. {
  59. $financialyear = @$_POST['financialyear'] ? $_POST['financialyear'] : date('Y');
  60. $month = date('m');
  61. self::insertUserLeadAllCountRecord($financialyear, $month);
  62. if (empty(Yii::app()->session['id']) or Yii::app()->session['id'] == '')
  63. {
  64. $this->redirect(array('site/index'));
  65. }
  66. $leadCond = '';
  67. $PiechartCond = '';
  68. $NotificationCond1 = '';
  69. $NotificationCond2 = '';
  70. $currentDateNot = date('d-m-Y');
  71. $currentTimestamp = strtotime($currentDateNot);
  72. if (isset($_POST['searchDashboard']) && !empty($_POST['searchDashboard']))
  73. {
  74. $searchDate = $_POST['searchDashboard'];
  75. $searchTimestamp = strtotime(@$searchDate);
  76. $searchEndTimestamp = $searchTimestamp + 86400;
  77. $leadCond = " and lead.updatedOn >= '" . @$searchTimestamp . "' and lead.updatedOn < '" . @$searchEndTimestamp . "'";
  78. $PiechartCond = " and leadSourceMaster.updatedOn >= '" . @$searchTimestamp . "' and leadSourceMaster.updatedOn < '" . @$searchEndTimestamp . "'";
  79. $NotificationCond1 = " and notification.updatedOn >= '" . @$searchTimestamp . "' and notification.updatedOn < '" . @$searchEndTimestamp . "' AND (STR_TO_DATE('$currentDateNot', '%d-%m-%Y') >= STR_TO_DATE(notification.startDate, '%d-%m-%Y') AND STR_TO_DATE(notification.endDate, '%d-%m-%Y') >= STR_TO_DATE('$currentDateNot', '%d-%m-%Y') )";
  80. $NotificationCond2 = " and notification.updatedOn >= '" . @$searchTimestamp . "' and notification.updatedOn < '" . @$searchEndTimestamp . "' AND (STR_TO_DATE('$currentDateNot', '%d-%m-%Y') >= STR_TO_DATE(notification.startDate, '%d-%m-%Y') AND STR_TO_DATE(notification.endDate, '%d-%m-%Y') >= STR_TO_DATE('$currentDateNot', '%d-%m-%Y') )";
  81. }
  82. if (Yii::app()->session->get('isAllocator') == 'yes' or Yii::app()->session->get('type') == 'superadmin' or Yii::app()->session->get('roleId') == 1)
  83. {
  84. $LeasStatusCond = '';
  85. }
  86. else
  87. {
  88. $LeasStatusCond = ' AND lead.currentAllocatedId = ' . Yii::app()->session->get('id') . '';
  89. }
  90. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1);
  91. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"));
  92. $CurrentYear_first_minute = mktime(0, 0, 0, 1, 1, date('Y'));
  93. $CurrentYear_last_minute = mktime(0, 0, 0, 13, 0, date('Y'));
  94. $where = '';
  95. if (Yii::app()->session->get('type') != 'superadmin')
  96. {
  97. $where = ' where notificationMapping.roleId="' . Yii::app()->session->get('roleId') . '"';
  98. $cls = " AND (STR_TO_DATE('$currentDateNot', '%d-%m-%Y') >= STR_TO_DATE(notification.startDate, '%d-%m-%Y') AND STR_TO_DATE(notification.endDate, '%d-%m-%Y') >= STR_TO_DATE('$currentDateNot', '%d-%m-%Y') )";
  99. $notifications = Yii::app()->db->createCommand("select notification.* from notification left join notificationMapping on notificationMapping.notificationId=notification.notificationId $where " . $NotificationCond1 . " " . @$cls . " group by notification.notificationId ")->queryAll();
  100. }
  101. else
  102. {
  103. $cls = " WHERE (STR_TO_DATE('$currentDateNot', '%d-%m-%Y') >= STR_TO_DATE(notification.startDate, '%d-%m-%Y') AND STR_TO_DATE(notification.endDate, '%d-%m-%Y') >= STR_TO_DATE('$currentDateNot', '%d-%m-%Y') )";
  104. $notifications = Yii::app()->db->createCommand("select notification.* from notification left join notificationMapping on notificationMapping.notificationId=notification.notificationId " . @$cls . " " . $NotificationCond2 . " group by notification.notificationId ")->queryAll();
  105. }
  106. $sourcewiseDetails = Yii::app()->db->createCommand("select leadSourceMaster.* from leadSourceMaster ")->queryAll();
  107. $ManagerDetails = Yii::app()->db->createCommand("select user.managerId,user.Id,user.userName from user where managerId='" . Yii::app()->session->get('id') . "'")->queryAll();
  108. $total_firstLevel = array();
  109. $total_nextLevel = array();
  110. $managerIds = self::fetchAllmanagerLevelRecords($total_firstLevel, $ManagerDetails, Yii::app()->session->get('id'));
  111. if (empty($managerIds))
  112. {
  113. $managerIds[] = $_SESSION['id'];
  114. }
  115. else
  116. {
  117. $pusharray = array();
  118. $pusharray[] = @$_SESSION['id'];
  119. $managerIds = array_unique(array_merge(@$managerIds, @$pusharray));
  120. }
  121. if (strtolower(Yii::app()->session->get('roleName')) == "teamleader")
  122. {
  123. $teamLeaderTeamUserIdsRes = array();
  124. $teamLeaderTeamUserIds = Yii::app()->db->createCommand("select id as userId from user where id IN (select distinct userId from teamUserMapping where teamId IN (select distinct teamId from teamUserMapping where userId='" . Yii::app()->session->get('id') . "') ) and status='Active' and type!='superadmin' ")->queryAll();
  125. if (count($teamLeaderTeamUserIds) > 0)
  126. {
  127. foreach ($teamLeaderTeamUserIds as $keyd => $valued)
  128. {
  129. $teamLeaderTeamUserIdsRes[] = $valued['userId'];
  130. }
  131. $managerIds = array_unique(array_merge($managerIds, $teamLeaderTeamUserIdsRes));
  132. }
  133. }
  134. $managerDetailsArr = self::ManagerDetails($managerIds);
  135. Yii::app()->session['relationalManager'] = $managerIds;
  136. //$sourcewiseDetailsWithPiechart=Yii::app()->db->createCommand("SELECT leadSourceMaster.*,count(*) as total FROM `leadSourceMaster` left join lead on leadSourceMaster.leadSourceId=lead.leadSourceId where leadSourceMaster.status='Active' ".$PiechartCond." group by leadSourceMaster.leadSourceId ")->queryAll();
  137. $speedmeterUser = @$_REQUEST['speedmeterUser'];
  138. if (isset($speedmeterUser) && !empty($speedmeterUser))
  139. {
  140. $totalAmountOfSpeedometer = Lead::model()->closedLeadsAmount($speedmeterUser);
  141. }
  142. else
  143. {
  144. $totalAmountOfSpeedometer = 0;
  145. }
  146. $LeadStatusSql = "SELECT ls.leadstatus,ls.leadstatusId,ls.sortOrder FROM `leadstatus` ls where ls.status='Active' order by ls.sortOrder ASC ";
  147. // $LeadStatusSql = "SELECT ls.leadstatus,ls.leadstatusId,ls.sortOrder,SUM(IF(lead.updatedOn >= '".@$CurrentMonth_first_minute."' and lead.updatedOn <= '".@$CurrentMonth_last_minute."' and ls.leadstatusId=lead.leadstatusId and u.status='Active',1,0)) as MTD,SUM(IF(lead.updatedOn >= '".@$CurrentYear_first_minute."' and lead.updatedOn <= '".@$CurrentYear_last_minute."' and u.status='Active',1,0)) as YTD FROM `leadstatus` ls join lead on lead.leadstatusId=ls.leadstatusId left join user u on u.id=lead.currentAllocatedId where ls.status='Active' ".$leadCond." ".$LeasStatusCond." group By lead.leadstatusId order by ls.sortOrder ASC";
  148. $count = Yii::app()->db->createCommand($LeadStatusSql)->queryAll();
  149. $dataProviderc = new CSqlDataProvider($LeadStatusSql, array(
  150. 'keyField' => 'leadstatusId',
  151. 'totalItemCount' => count($count),
  152. 'sort' => array(
  153. 'attributes' => array(
  154. 'leadStatusId',
  155. ),
  156. ),
  157. 'pagination' => array(
  158. 'pageSize' => 10,
  159. 'pageVar' => 'gyu', //page selector
  160. ),
  161. ));
  162. if (Yii::app()->session->get('isAllocator') == 'yes')
  163. {
  164. $allocatorTl = Yii::app()->db->createCommand("select group_concat(distinct id) as TLIDS from user where roleId=4")->queryAll();
  165. $impresuser = @$allocatorTl[0]['TLIDS'];
  166. }
  167. else
  168. {
  169. $impresuser = $this->implodeResult(Yii::app()->session['relationalManager']);
  170. }
  171. //calculate performance
  172. /*
  173. $today12PM = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
  174. $tomorrow12PM = mktime(0, 0, 0, date("m"), date("d"), date("Y")) + 86400;
  175. $yesterday12PM = mktime(0, 0, 0, date("m"), date("d"), date("Y")) - 86400;
  176. $LastMonth_first_minute = mktime(0, 0, 0, date("n") - 1, 1);
  177. //echo date('d M Y :: H:i:s',$CurrentMonth_first_minute); die;
  178. $filtercaller = @$_REQUEST['User']['userName'];
  179. $filtersource = @$_REQUEST['LeadSourceMaster']['leadSourceId'];
  180. $filterdate1 = @$_REQUEST['Lead']['createdOn'];
  181. $filterdate2 = @$_REQUEST['Lead']['createdOn2'];
  182. $filterCond = '';
  183. if (isset($filtercaller) && !empty($filtercaller))
  184. {
  185. $filterCond .= " AND lead.currentAllocatedId = " . $filtercaller . "";
  186. }
  187. if (isset($filtersource) && !empty($filtersource))
  188. {
  189. $filterCond .= " AND lead.leadSourceId = " . $filtersource . "";
  190. }
  191. if (isset($filterdate1) && !empty($filterdate1) && isset($filterdate2) && !empty($filterdate2))
  192. {
  193. $date1Filer = strtotime($filterdate1);
  194. $date2Filer = strtotime($filterdate2);
  195. $filterCond .= " AND lead.updatedOn >= " . $date1Filer . " AND lead.updatedOn <= " . $date2Filer . "";
  196. }
  197. */
  198. /* commented by shakti
  199. $teamworkloadSql = "SELECT u.firstName,u.lastName,u.id as Id,SUM(IF(lead.updatedOn >= '" . @$today12PM . "' and lead.updatedOn <= '" . @$tomorrow12PM . "',1,0)) as T,SUM(IF(lead.updatedOn >= '" . @$yesterday12PM . "' and lead.updatedOn <= '" . @$today12PM . "',1,0)) as Y,SUM(IF(lead.updatedOn >= '" . @$CurrentMonth_first_minute . "' and lead.updatedOn <= '" . @$CurrentMonth_last_minute . "',1,0)) as M,SUM(IF(lead.updatedOn >= '" . @$LastMonth_first_minute . "' and lead.updatedOn <= '" . @$CurrentMonth_first_minute . "',1,0)) as LM from user u left join lead on lead.currentAllocatedId=u.Id where u.Id IN (" . @$impresuser . ") and u.status='Active' and lead.currentAllocatedId IN (" . @$impresuser . ") " . @$filterCond . " " . $leadCond . " group By u.id ";
  200. $countTeamworkLoad = Yii::app()->db->createCommand($teamworkloadSql)->queryAll();
  201. $dataProviderWorkload = new CSqlDataProvider($teamworkloadSql, array(
  202. 'keyField' => 'Id',
  203. 'totalItemCount' => count($countTeamworkLoad),
  204. 'sort' => array(
  205. 'attributes' => array(
  206. 'Id',
  207. ),
  208. ),
  209. 'pagination' => array(
  210. 'pageSize' => 10,
  211. 'pageVar' => 'workload', //page selector
  212. ),
  213. ));
  214. */
  215. self::getRequiredVariables();
  216. $callerTeamSql = "SELECT user.firstName,user.lastName,user.id as Id,SUM(IF(lead.updatedOn >= '" . @$today12PM . "' and lead.updatedOn <= '" . @$tomorrow12PM . "' and lead.leadSourceId = 1,1,0)) as WT,SUM(IF(lead.updatedOn >= '" . @$yesterday12PM . "' and lead.updatedOn <= '" . @$today12PM . "' and lead.leadSourceId = 1,1,0)) as WY,SUM(IF(lead.updatedOn >= '" . @$CurrentMonth_first_minute . "' and lead.updatedOn <= '" . @$CurrentMonth_last_minute . "' and lead.leadSourceId = 1,1,0)) as WM,SUM(IF(lead.updatedOn >= '" . @$LastMonth_first_minute . "' and lead.updatedOn <= '" . @$CurrentMonth_first_minute . "' and lead.leadSourceId = 1,1,0)) as WLM,SUM(IF(lead.updatedOn >= '" . @$today12PM . "' and lead.updatedOn <= '" . @$tomorrow12PM . "' and lead.leadSourceId != 1,1,0)) as OT,SUM(IF(lead.updatedOn >= '" . @$yesterday12PM . "' and lead.updatedOn <= '" . @$today12PM . "' and lead.leadSourceId != 1,1,0)) as OY,SUM(IF(lead.updatedOn >= '" . @$CurrentMonth_first_minute . "' and lead.updatedOn <= '" . @$CurrentMonth_last_minute . "' and lead.leadSourceId != 1,1,0)) as OM,SUM(IF(lead.updatedOn >= '" . @$LastMonth_first_minute . "' and lead.updatedOn <= '" . @$CurrentMonth_first_minute . "' and lead.leadSourceId != 1,1,0)) as OLM from user left join lead on lead.currentAllocatedId=user.Id where user.Id = " . Yii::app()->session['id'] . " and user.status='Active' and lead.currentAllocatedId =" . Yii::app()->session['id'] . " " . $leadCond . " ";
  217. $countcallerInfo = Yii::app()->db->createCommand($callerTeamSql)->queryAll();
  218. $dataProvidercaller = new CSqlDataProvider($callerTeamSql, array(
  219. 'keyField' => 'Id',
  220. 'totalItemCount' => count($countcallerInfo),
  221. 'sort' => array(
  222. 'attributes' => array(
  223. 'Id',
  224. ),
  225. ),
  226. 'pagination' => false,
  227. ));
  228. $dataProviderPerf = self::getDataProviderPerf();
  229. $this->render('dashboard', array('LeadStatus' => @$LeadStatus, 'notifications' => @$notifications, 'sourcewiseDetails' => @$sourcewiseDetails, 'managerDetailsArr' => @$managerDetailsArr, 'totalAmountOfSpeedometer' => @$totalAmountOfSpeedometer, 'dataProviderc' => $dataProviderc, 'dataProviderPerf' => $dataProviderPerf, 'dataProviderWorkload' => @$dataProviderWorkload, 'dataProvidercaller' => @$dataProvidercaller, 'dataProvideradmin' => @$dataProvideradmin, 'impresuser' => @$impresuser));
  230. }
  231. /**
  232. * Get Lead Status Count.(Eg Manager, add leadtypecount of all Teamleaders & Teamleader, add leadtypecount of all callers).
  233. * @see _leadfortoday.php
  234. * @return int
  235. */
  236. public static function getLeadStatusCount($leadStatusId, $accessKey)
  237. {
  238. $userList = $userId = Yii::app()->session['id'];
  239. $userList = User::getMemebersList();
  240. if(count($userList))
  241. {
  242. $allCallersList = array();
  243. $lCount = array();
  244. foreach($userList as $list)
  245. {
  246. $allCallersList[] = $list['id'];
  247. }
  248. $userList = implode(', ', $allCallersList);
  249. //print $userList . '==';
  250. $totalCount = Yii::app()->db->createCommand("select sum(count) as count from leadallcount where userid in ( $userList ) AND leadtype = $leadStatusId AND accesskey = '$accessKey'")->queryRow();
  251. return $totalCount['count'];
  252. }
  253. $count = Yii::app()->db->createCommand("select sum(count) as count from leadallcount where userid = $userId AND leadtype = $leadStatusId AND accesskey = '$accessKey'")->queryRow();
  254. return $count['count'];
  255. }
  256. /**
  257. * Insert Users Record (Eg. call this method to insert all callers and the logged in teamleader (callers, teamleader & logged in manager)).
  258. * @see _leadfortoday.php
  259. * @return int
  260. */
  261. public static function insertUsersRecord($accessKey)
  262. {
  263. $userList = User::getMemebersList();
  264. $financialDate = explode('-', $accessKey);
  265. $financialDate[0] = $financialDate[0] ? $financialDate[0] : date('Y');
  266. $financialDate[1] = @$financialDate[1] ? $financialDate[1] : date('m');
  267. if (count($userList))
  268. {
  269. foreach ($userList as $list)
  270. {
  271. self::insertUserLeadAllCountRecord($financialDate[0], $financialDate[1], $list['id']);
  272. }
  273. } else if(Yii::app()->session->get('type') == 'superadmin')
  274. {
  275. self::insertUserLeadAllCountRecord($financialDate[0], $financialDate[1], Yii::app()->session['id']);
  276. }
  277. }
  278. public static function getMTDForUser($leadStatusId, $userId)
  279. {
  280. if (Yii::app()->session->get('type') == 'superadmin')
  281. {
  282. $cond = '';
  283. }
  284. else
  285. {
  286. if (count(@$_SESSION['relationalManager']) > 0)
  287. {
  288. $teamids = implode(",", $_SESSION['relationalManager']);
  289. }
  290. else
  291. {
  292. $teamids = Yii::app()->session->get('id');
  293. }
  294. $cond = "AND l.currentAllocatedId = " . $userId;
  295. }
  296. $financialyear = @$_POST['financialyear'];
  297. if (isset($financialyear) && !empty($financialyear))
  298. {
  299. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1, $financialyear);
  300. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"), $financialyear);
  301. }
  302. else
  303. {
  304. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1);
  305. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"));
  306. }
  307. $sql = "select count(leadId) as total from lead l join user u on u.id=l.currentAllocatedId where l.leadStatusId = " . $leadStatusId . " and (l.updatedOn between '" . @$CurrentMonth_first_minute . "' and '" . @$CurrentMonth_last_minute . "') and u.status='Active' $cond limit 1 ";
  308. $count = Yii::app()->db->createCommand($sql)->queryColumn();
  309. return @$count[0];
  310. //echo Lead::model()->count(array("select"=>'leadid',"condition"=>" leadStatusId = ".@$leadStatusId.""));
  311. }
  312. public static function getYTDForUser($leadStatusId, $userId)
  313. {
  314. if (Yii::app()->session->get('type') == 'superadmin')
  315. {
  316. $cond = '';
  317. }
  318. else
  319. {
  320. if (count(@$_SESSION['relationalManager']) > 0)
  321. {
  322. $teamids = implode(",", $_SESSION['relationalManager']);
  323. }
  324. else
  325. {
  326. $teamids = Yii::app()->session->get('id');
  327. }
  328. $cond = "AND l.currentAllocatedId = " . $userId;
  329. }
  330. $financialyear = @$_POST['financialyear'];
  331. if (isset($financialyear) && !empty($financialyear))
  332. {
  333. $CurrentYear_first_minute = mktime(0, 0, 0, 4, 1, $financialyear);
  334. $CurrentYear_last_minute = mktime(0, 0, 0, 4, 0, $financialyear + 1);
  335. }
  336. else
  337. {
  338. $CurrentYear_first_minute = mktime(0, 0, 0, 4, 1, date('Y'));
  339. $CurrentYear_last_minute = mktime(0, 0, 0, 4, 0, date('Y') + 1);
  340. }
  341. //$CurrentYear_first_minute = mktime(0, 0, 0, 1, 1, date('Y'));
  342. //$CurrentYear_last_minute = mktime(0, 0, 0, 13, 0, date('Y'));
  343. $sql = "select count(leadId) as total from lead l join user u on u.id=l.currentAllocatedId where l.leadStatusId = " . $leadStatusId . " and (l.updatedOn between '" . @$CurrentYear_first_minute . "' and '" . @$CurrentYear_last_minute . "') and u.status='Active' $cond ";
  344. $count = Yii::app()->db->createCommand($sql)->queryColumn();
  345. //echo Lead::model()->count(array("select"=>'leadid',"condition"=>" leadStatusId = ".@$leadStatusId.""));
  346. return @$count[0];
  347. //return @$count[0];
  348. }
  349. /**
  350. * This is the 'module master' action that is invoked
  351. * when an action is not explicitly requested by users.
  352. */
  353. public function actionmodule_master()
  354. {
  355. // renders the view file 'protected/views/site/index.php'
  356. // using the default layout 'protected/views/layouts/main.php'
  357. $model = new ModuleMaster();
  358. $model->scenario = 'ModuleMaster';
  359. if (!empty($_GET['moduleId']))
  360. {
  361. $moduleId = $_GET['moduleId'];
  362. $model = ModuleMaster::model()->findByPk($moduleId);
  363. }
  364. if (!empty($_POST['ModuleMaster']['moduleId']))
  365. {
  366. $moduleId = $_POST['ModuleMaster']['moduleId'];
  367. $model = ModuleMaster::model()->findByPk($moduleId);
  368. }
  369. if (isset($_POST['ModuleMaster']))
  370. {
  371. $model->setAttributes(array(
  372. 'createdOn' => time(), //additional data you want to insert
  373. 'updatedOn' => time(), //additional
  374. 'updatedBy' => time(), //additional
  375. 'createdBy' => time(),
  376. 'status' => 'Activated', //additional //additional
  377. ));
  378. foreach ($_POST['ModuleMaster'] as $name => $value)
  379. {
  380. $model->$name = $value;
  381. }
  382. if ($model->validate())
  383. {
  384. $model->save();
  385. $model2 = ModuleMaster::model()->findAll();
  386. $this->render('module_master', array('model' => $model, 'model2' => $model2));
  387. Yii::app()->user->setFlash('module_master_msg_success', 'Successfully Inserted');
  388. }
  389. else
  390. {
  391. Yii::app()->user->setFlash('module_master_msg_error', 'Please check. error occured');
  392. $this->render('module_master', array('model' => $model));
  393. }
  394. }
  395. else
  396. {
  397. $model2 = ModuleMaster::model()->findAll();
  398. //Yii::app()->user->setFlash('lead_stage_msg_error','Please check. error occured');
  399. $this->render('module_master', array('model' => $model, 'model2' => $model2));
  400. }
  401. }
  402. /**
  403. * This is the action to handle external exceptions.
  404. */
  405. public function actionError()
  406. {
  407. if ($error = Yii::app()->errorHandler->error)
  408. {
  409. if (Yii::app()->request->isAjaxRequest)
  410. echo $error['message'];
  411. else
  412. $this->render('error', $error);
  413. }
  414. }
  415. /**
  416. * Displays the contact page
  417. */
  418. public function actionContact()
  419. {
  420. $model = new ContactForm;
  421. if (isset($_POST['ContactForm']))
  422. {
  423. $model->attributes = $_POST['ContactForm'];
  424. if ($model->validate())
  425. {
  426. $name = '=?UTF-8?B?' . base64_encode($model->name) . '?=';
  427. $subject = '=?UTF-8?B?' . base64_encode($model->subject) . '?=';
  428. $headers = "From: $name <{$model->email}>\r\n" .
  429. "Reply-To: {$model->email}\r\n" .
  430. "MIME-Version: 1.0\r\n" .
  431. "Content-type: text/plain; charset=UTF-8";
  432. mail(Yii::app()->params['adminEmail'], $subject, $model->body, $headers);
  433. Yii::app()->user->setFlash('contact', 'Thank you for contacting us. We will respond to you as soon as possible.');
  434. $this->refresh();
  435. }
  436. }
  437. $this->render('contact', array('model' => $model));
  438. }
  439. /**
  440. * Displays the login page
  441. */
  442. public function actionLogin()
  443. {
  444. $model = new User;
  445. // if it is ajax validation request
  446. if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form')
  447. {
  448. echo CActiveForm::validate($model);
  449. Yii::app()->end();
  450. }
  451. // collect user input data
  452. if (isset($_POST['User']))
  453. {
  454. $model->attributes = $_POST['User'];
  455. // validate user input and redirect to the previous page if valid
  456. if ($model->validate() && $model->login())
  457. {
  458. $this->redirect(array('masters/dashboard'));
  459. }
  460. else
  461. {
  462. $this->redirect(Yii::app()->user->returnUrl);
  463. }
  464. }
  465. // display the login form
  466. $this->render('login', array('model' => $model));
  467. }
  468. /**
  469. * Logs out the current user and redirect to homepage.
  470. */
  471. public function actionLogout()
  472. {
  473. Yii::app()->user->logout();
  474. $this->redirect(Yii::app()->homeUrl);
  475. }
  476. public function getPageType()
  477. {
  478. return "";
  479. }
  480. public function actionViewFancyboxData()
  481. {
  482. $userId = @$_REQUEST['id'];
  483. $model = new User;
  484. $model = User::model()->findByPk($userId);
  485. if (!Yii::app()->request->isAjaxRequest)
  486. {
  487. // $this->render('yourView');
  488. }
  489. else
  490. {
  491. $this->renderPartial('/masters/partialNotification');
  492. Yii::app()->end();
  493. }
  494. }
  495. public function actionViewWorkLoadData()
  496. {
  497. if (!Yii::app()->request->isAjaxRequest)
  498. {
  499. echo "ddd";
  500. // $this->render('/leads/partialWorkLoadData');
  501. // $this->render('yourView');
  502. }
  503. else
  504. {
  505. $this->renderPartial('/leads/partialWorkLoadData');
  506. Yii::app()->end();
  507. }
  508. }
  509. public function actionViewLeadSummaryData()
  510. {
  511. //$this->layout='column3';
  512. $this->layout = false;
  513. $parser = new CHtmlPurifier();
  514. $leadStatusId = $parser->purify(intval(@$_REQUEST['leadStatusId']));
  515. /* $model=new Lead;
  516. $model=Lead::model()->findAll("leadStatusId = '".@$leadStatusId."' ");
  517. */
  518. if (!Yii::app()->request->isAjaxRequest)
  519. {
  520. $this->render('/leads/partialLeadSummary', array('leadStatusId' => $leadStatusId));
  521. }
  522. else
  523. {
  524. $this->layout=false;
  525. $this->render('/leads/partialLeadSummary', array('leadStatusId' => $leadStatusId));
  526. Yii::app()->end();
  527. }
  528. }
  529. public function actionRenewalViewLeadSummaryData()
  530. {
  531. //$this->layout='column3';
  532. $this->layout = false;
  533. $res = new MySanitizeClass;
  534. $leadStatusId = $res->sanitize_description(@$_REQUEST['leadStatusId']);
  535. /* $model=new Lead;
  536. $model=Lead::model()->findAll("leadStatusId = '".@$leadStatusId."' ");
  537. */ if (!Yii::app()->request->isAjaxRequest)
  538. {
  539. $this->render('/renewalleads/renewalpartialLeadSummary', array('leadStatusId' => $leadStatusId));
  540. }
  541. else
  542. {
  543. //$this->layout=false;
  544. $this->render('/renewalleads/renewalpartialLeadSummary', array('leadStatusId' => $leadStatusId));
  545. Yii::app()->end();
  546. }
  547. }
  548. function getparentLeadStatus($parentId)
  549. {
  550. $primary = LeadStatus::model()->findByPk($parentId);
  551. if ($primary['parentId'] > 0)
  552. {
  553. $parentName = LeadStatus::model()->findByPk($primary['parentId']);
  554. $pname = $parentName['leadStatus'];
  555. }
  556. else
  557. {
  558. $pname = "Primary";
  559. }
  560. return $pname;
  561. }
  562. public function actionViewAllWorkLoadData()
  563. {
  564. function ManagerDetails($userIds)
  565. {
  566. $userIds = UserWithManagerIdsImploded($userIds);
  567. if ($userIds != '')
  568. {
  569. return Yii::app()->db->createCommand("select * from user where user.Id IN ($userIds) ")->queryAll();
  570. }
  571. }
  572. function UserWithManagerIdsImploded($userIds)
  573. {
  574. return $userIds = implode(",", $userIds);
  575. }
  576. $managerDetailsArr = ManagerDetails(Yii::app()->session['relationalManager']);
  577. if (!Yii::app()->request->isAjaxRequest)
  578. {
  579. // $this->render('yourView');
  580. }
  581. else
  582. {
  583. $this->renderPartial('/leads/partialAllWorkLoadData', array('managerDetailsArr' => $managerDetailsArr));
  584. Yii::app()->end();
  585. }
  586. }
  587. public function actionViewAllPerformanceData()
  588. {
  589. function ManagerDetails($userIds)
  590. {
  591. $userIds = UserWithManagerIdsImploded($userIds);
  592. if ($userIds != '')
  593. {
  594. return Yii::app()->db->createCommand("select * from user where user.Id IN ($userIds) ")->queryAll();
  595. }
  596. }
  597. function UserWithManagerIdsImploded($userIds)
  598. {
  599. return $userIds = implode(",", $userIds);
  600. }
  601. $managerDetailsArr = ManagerDetails(Yii::app()->session['relationalManager']);
  602. if (!Yii::app()->request->isAjaxRequest)
  603. {
  604. $this->render('/leads/partialAllPerfLoadData', array('managerDetailsArr' => $managerDetailsArr));
  605. // $this->render('yourView');
  606. }
  607. else
  608. {
  609. $this->renderPartial('/leads/partialAllPerfLoadData', array('managerDetailsArr' => $managerDetailsArr));
  610. Yii::app()->end();
  611. }
  612. }
  613. public function actionrenewal()
  614. {
  615. //$this->redirect(array('dashboard/dashboard'));
  616. $leadCond = '';
  617. $PiechartCond = '';
  618. $NotificationCond1 = '';
  619. $NotificationCond2 = '';
  620. $currentDateNot = date('d-m-Y');
  621. $currentTimestamp = strtotime($currentDateNot);
  622. if (isset($_POST['searchDashboard']) && !empty($_POST['searchDashboard']))
  623. {
  624. $searchDate = $_POST['searchDashboard'];
  625. $searchTimestamp = strtotime(@$searchDate);
  626. $searchEndTimestamp = $searchTimestamp + 86400;
  627. $leadCond = " and renewallead.updatedOn >= '" . @$searchTimestamp . "' and renewallead.updatedOn < '" . @$searchEndTimestamp . "'";
  628. $PiechartCond = " and renewalleadSourceMaster.updatedOn >= '" . @$searchTimestamp . "' and renewalleadSourceMaster.updatedOn < '" . @$searchEndTimestamp . "'";
  629. $NotificationCond1 = " and renewalnotification.updatedOn >= '" . @$searchTimestamp . "' and renewalnotification.updatedOn < '" . @$searchEndTimestamp . "' AND (STR_TO_DATE('$currentDateNot', '%d-%m-%Y') >= STR_TO_DATE(notification.startDate, '%d-%m-%Y') AND STR_TO_DATE(renewalnotification.endDate, '%d-%m-%Y') >= STR_TO_DATE('$currentDateNot', '%d-%m-%Y') )";
  630. $NotificationCond2 = " and renewalnotification.updatedOn >= '" . @$searchTimestamp . "' and renewalnotification.updatedOn < '" . @$searchEndTimestamp . "' AND (STR_TO_DATE('$currentDateNot', '%d-%m-%Y') >= STR_TO_DATE(renewalnotification.startDate, '%d-%m-%Y') AND STR_TO_DATE(renewalnotification.endDate, '%d-%m-%Y') >= STR_TO_DATE('$currentDateNot', '%d-%m-%Y') )";
  631. }
  632. if (Yii::app()->session->get('isAllocator') == 'yes' or Yii::app()->session->get('type') == 'superadmin')
  633. {
  634. $LeasStatusCond = '';
  635. }
  636. else
  637. {
  638. $LeasStatusCond = ' AND renewallead.currentAllocatedId = "' . Yii::app()->session->get('id') . '"';
  639. }
  640. $LeadStatus = Yii::app()->db->createCommand('SELECT
  641. me.leadStatusId AS me_id,
  642. me.leadStatus AS me_leadStatus,
  643. renewallead.leadStatusId AS lead_leadStatusId,
  644. renewallead.leadId AS leadId,
  645. count(*) AS total
  646. FROM
  647. renewalleadStatus me
  648. left join renewallead on renewallead.leadStatusId=me.leadStatusId where renewallead.leadStatusId > 0 ' . $leadCond . ' ' . $LeasStatusCond . ' group by renewallead.leadStatusId')->queryAll();
  649. $LeadStatusSql = "SELECT ls.leadstatus,ls.leadstatusId,ls.sortOrder FROM `renewalleadstatus` ls where ls.status='Active' order by ls.sortOrder ASC ";
  650. // $LeadStatusSql = "SELECT ls.leadstatus,ls.leadstatusId,ls.sortOrder,SUM(IF(lead.updatedOn >= '".@$CurrentMonth_first_minute."' and lead.updatedOn <= '".@$CurrentMonth_last_minute."' and ls.leadstatusId=lead.leadstatusId and u.status='Active',1,0)) as MTD,SUM(IF(lead.updatedOn >= '".@$CurrentYear_first_minute."' and lead.updatedOn <= '".@$CurrentYear_last_minute."' and u.status='Active',1,0)) as YTD FROM `leadstatus` ls join lead on lead.leadstatusId=ls.leadstatusId left join user u on u.id=lead.currentAllocatedId where ls.status='Active' ".$leadCond." ".$LeasStatusCond." group By lead.leadstatusId order by ls.sortOrder ASC";
  651. $count = Yii::app()->db->createCommand($LeadStatusSql)->queryAll();
  652. $dataProviderc = new CSqlDataProvider($LeadStatusSql, array(
  653. 'keyField' => 'leadstatusId',
  654. 'totalItemCount' => count($count),
  655. 'sort' => array(
  656. 'attributes' => array(
  657. 'leadStatusId',
  658. ),
  659. ),
  660. 'pagination' => array(
  661. 'pageSize' => 10,
  662. 'pageVar' => 'gyu', //page selector
  663. ),
  664. ));
  665. $where = '';
  666. if (Yii::app()->session->get('type') != 'superadmin')
  667. {
  668. $where = ' where renewalnotificationMapping.roleId="' . Yii::app()->session->get('roleId') . '"';
  669. $cls = " AND (STR_TO_DATE('$currentDateNot', '%d-%m-%Y') >= STR_TO_DATE(renewalnotification.startDate, '%d-%m-%Y') AND STR_TO_DATE(renewalnotification.endDate, '%d-%m-%Y') >= STR_TO_DATE('$currentDateNot', '%d-%m-%Y') )";
  670. $notifications = Yii::app()->db->createCommand("select renewalnotification.* from renewalnotification left join renewalnotificationMapping on renewalnotificationMapping.notificationId=renewalnotification.notificationId $where " . $NotificationCond1 . " " . @$cls . " group by renewalnotification.notificationId ")->queryAll();
  671. }
  672. else
  673. {
  674. $cls = " WHERE (STR_TO_DATE('$currentDateNot', '%d-%m-%Y') >= STR_TO_DATE(renewalnotification.startDate, '%d-%m-%Y') AND STR_TO_DATE(renewalnotification.endDate, '%d-%m-%Y') >= STR_TO_DATE('$currentDateNot', '%d-%m-%Y') )";
  675. $notifications = Yii::app()->db->createCommand("select renewalnotification.* from renewalnotification left join renewalnotificationMapping on renewalnotificationMapping.notificationId=renewalnotification.notificationId " . @$cls . " " . $NotificationCond2 . " group by renewalnotification.notificationId ")->queryAll();
  676. }
  677. $sourcewiseDetails = Yii::app()->db->createCommand("select renewalleadSourceMaster.* from renewalleadSourceMaster ")->queryAll();
  678. $ManagerDetails = Yii::app()->db->createCommand("select user.managerId,user.Id,user.userName from user where managerId='" . Yii::app()->session->get('id') . "'")->queryAll();
  679. function SecondLevel($managerId, $userId)
  680. {
  681. return Yii::app()->db->createCommand("select user.managerId,user.Id,user.userName from user where user.managerId='$managerId' and user.managerId!='$userId' ")->queryAll();
  682. }
  683. function ManagerLevel($userIds, $managerIds)
  684. {
  685. return Yii::app()->db->createCommand("select user.managerId,user.Id,user.userName from user where user.managerId ='$userIds' and id!='$managerIds' ")->queryAll();
  686. }
  687. function ManagerDetails($userIds)
  688. {
  689. $userIds = UserWithManagerIdsImploded($userIds);
  690. if ($userIds != '')
  691. {
  692. return Yii::app()->db->createCommand("select * from user where user.Id IN ($userIds) ")->queryAll();
  693. }
  694. }
  695. function UserWithManagerIdsImploded($userIds)
  696. {
  697. return $userIds = implode(",", $userIds);
  698. }
  699. $total_firstLevel = array();
  700. $total_nextLevel = array();
  701. function fetchAllmanagerLevelRecords(&$total_firstLevel, $ManagerDetails, $currentUserIds)
  702. {
  703. foreach ($ManagerDetails as $key => $value)
  704. {
  705. $total_firstLevel[] = $value['Id'];
  706. $total_res = SecondLevel($value['Id'], $currentUserIds);
  707. $res[] = count($total_res);
  708. if (count($total_res) > 0)
  709. {
  710. $o = 0;
  711. foreach ($total_res as $key1 => $value1)
  712. {
  713. $total_firstLevel[] = $value1['Id'];
  714. $net_res = fetchAllmanagerLevelRecords($total_firstLevel, ManagerLevel($value1['Id'], Yii::app()->session->get('id')), Yii::app()->session->get('id'));
  715. $o++;
  716. }
  717. }
  718. }
  719. return $total_firstLevel;
  720. }
  721. $managerIds = fetchAllmanagerLevelRecords($total_firstLevel, $ManagerDetails, Yii::app()->session->get('id'));
  722. if (empty($managerIds))
  723. {
  724. $managerIds[] = $_SESSION['id'];
  725. }
  726. else
  727. {
  728. $pusharray = array();
  729. $pusharray[] = @$_SESSION['id'];
  730. $managerIds = array_unique(array_merge(@$managerIds, @$pusharray));
  731. }
  732. if (strtolower(Yii::app()->session->get('roleName')) == "teamleader")
  733. {
  734. $teamLeaderTeamUserIdsRes = array();
  735. $teamLeaderTeamUserIds = Yii::app()->db->createCommand("select id as userId from user where id IN (select distinct userId from renewalteamUserMapping where teamId IN (select distinct teamId from renewalteamUserMapping where userId='" . Yii::app()->session->get('id') . "') ) and status='Active' and type!='superadmin' ")->queryAll();
  736. if (count($teamLeaderTeamUserIds) > 0)
  737. {
  738. foreach ($teamLeaderTeamUserIds as $keyd => $valued)
  739. {
  740. $teamLeaderTeamUserIdsRes[] = $valued['userId'];
  741. }
  742. $managerIds = array_unique(array_merge($managerIds, $teamLeaderTeamUserIdsRes));
  743. }
  744. }
  745. $managerDetailsArr = ManagerDetails($managerIds);
  746. Yii::app()->session['relationalManager'] = $managerIds;
  747. $sourcewiseDetailsWithPiechart = Yii::app()->db->createCommand("SELECT renewalleadSourceMaster.*,count(*) as total FROM `renewalleadSourceMaster` left join renewallead on renewalleadSourceMaster.leadSourceId=renewallead.leadSourceId where renewalleadSourceMaster.status='Active' " . $PiechartCond . " group by renewalleadSourceMaster.leadSourceId ")->queryAll();
  748. $speedmeterUser = @$_REQUEST['speedmeterUser'];
  749. if (isset($speedmeterUser) && !empty($speedmeterUser))
  750. {
  751. $totalAmountOfSpeedometer = Lead::model()->closedLeadsAmount($speedmeterUser);
  752. }
  753. else
  754. {
  755. $totalAmountOfSpeedometer = 0;
  756. }
  757. $this->render('renewaldashboard', array('LeadStatus' => @$LeadStatus, 'notifications' => @$notifications, 'sourcewiseDetails' => @$sourcewiseDetails, 'sourcewiseDetailsWithPiechart' => @$sourcewiseDetailsWithPiechart, 'managerDetailsArr' => @$managerDetailsArr, 'totalAmountOfSpeedometer' => @$totalAmountOfSpeedometer, 'dataProviderc' => $dataProviderc));
  758. }
  759. public function actionrenViewLeadSummaryData()
  760. {
  761. $this->layout = 'column3';
  762. $leadStatusId = @$_REQUEST['leadStatusId'];
  763. //$model=new Renewallead;
  764. //$model=Renewallead::model()->findAll("leadStatusId = '".@$leadStatusId."' ");
  765. if (!Yii::app()->request->isAjaxRequest)
  766. {
  767. $this->redirect('dashboard/renewal');
  768. }
  769. else
  770. {
  771. $this->render('/renewalleads/partialLeadSummary', array('leadStatusId' => $leadStatusId));
  772. Yii::app()->end();
  773. }
  774. }
  775. public function actionrenViewWorkLoadData()
  776. {
  777. if (!Yii::app()->request->isAjaxRequest)
  778. {
  779. // $this->render('yourView');
  780. }
  781. else
  782. {
  783. $this->renderPartial('/renewalleads/partialWorkLoadData');
  784. Yii::app()->end();
  785. }
  786. }
  787. public function actionrenViewAllWorkLoadData()
  788. {
  789. function ManagerDetails($userIds)
  790. {
  791. $userIds = UserWithManagerIdsImploded($userIds);
  792. if ($userIds != '')
  793. {
  794. return Yii::app()->db->createCommand("select id from user where user.Id IN ($userIds) ")->queryAll();
  795. }
  796. }
  797. function UserWithManagerIdsImploded($userIds)
  798. {
  799. return $userIds = implode(",", $userIds);
  800. }
  801. $managerDetailsArr = ManagerDetails(Yii::app()->session['relationalManager']);
  802. if (!Yii::app()->request->isAjaxRequest)
  803. {
  804. // $this->render('yourView');
  805. }
  806. else
  807. {
  808. $this->renderPartial('/renewalleads/partialAllWorkLoadData', array('managerDetailsArr' => $managerDetailsArr));
  809. Yii::app()->end();
  810. }
  811. }
  812. public function actionrenViewFancyboxData()
  813. {
  814. $userId = @$_REQUEST['id'];
  815. $model = new User;
  816. $model = User::model()->findByPk($userId);
  817. if (!Yii::app()->request->isAjaxRequest)
  818. {
  819. // $this->render('yourView');
  820. }
  821. else
  822. {
  823. $this->renderPartial('/renewalmasters/partialNotification');
  824. Yii::app()->end();
  825. }
  826. }
  827. public function actionrenViewAllPerformanceData()
  828. {
  829. function ManagerDetails($userIds)
  830. {
  831. $userIds = UserWithManagerIdsImploded($userIds);
  832. if ($userIds != '')
  833. {
  834. return Yii::app()->db->createCommand("select id from user where user.Id IN ($userIds) ")->queryAll();
  835. }
  836. }
  837. function UserWithManagerIdsImploded($userIds)
  838. {
  839. return $userIds = implode(",", array_filter($userIds));
  840. }
  841. $managerDetailsArr = ManagerDetails(Yii::app()->session['relationalManager']);
  842. if (!Yii::app()->request->isAjaxRequest)
  843. {
  844. $this->render('/renewalleads/partialAllPerfLoadData', array('managerDetailsArr' => $managerDetailsArr));
  845. // $this->render('yourView');
  846. }
  847. else
  848. {
  849. $this->renderPartial('/leads/partialAllPerfLoadData', array('managerDetailsArr' => $managerDetailsArr));
  850. Yii::app()->end();
  851. }
  852. }
  853. public function actionfullcalender()
  854. {
  855. // renders the view file 'protected/views/site/index.php'
  856. // using the default layout 'protected/views/layouts/main.php'
  857. $this->render('fullcalender');
  858. }
  859. public function actionmyteamworkload()
  860. {
  861. // renders the view file 'protected/views/site/index.php'
  862. // using the default layout 'protected/views/layouts/main.php'
  863. $this->layout = false;
  864. function ManagerDetails($userIds)
  865. {
  866. $userIds = UserWithManagerIdsImploded($userIds);
  867. if ($userIds != '')
  868. {
  869. return Yii::app()->db->createCommand("select * from user where user.Id IN ($userIds) ")->queryAll();
  870. }
  871. }
  872. function UserWithManagerIdsImploded($userIds)
  873. {
  874. return $userIds = implode(",", array_filter($userIds));
  875. }
  876. $managerDetailsArr = ManagerDetails(Yii::app()->session['relationalManager']);
  877. $this->render('myteamworkload', array('managerDetailsArr' => @$managerDetailsArr));
  878. }
  879. public static function implodeResult($userIds)
  880. {
  881. $userIds = array_filter($userIds);
  882. return $userIds = implode(",", $userIds);
  883. }
  884. public function actionshowLeadCount()
  885. {
  886. $this->layout = false;
  887. $this->render('showLeadCount');
  888. }
  889. public function actionshowleadcountdisp()
  890. {
  891. $this->layout = false;
  892. $this->render('showleadcountdisp');
  893. }
  894. public static function getMTD($leadStatusId)
  895. {
  896. if (Yii::app()->session->get('type') == 'superadmin')
  897. {
  898. $cond = '';
  899. }
  900. else
  901. {
  902. if (count(@$_SESSION['relationalManager']) > 0)
  903. {
  904. $teamids = implode(",", $_SESSION['relationalManager']);
  905. }
  906. else
  907. {
  908. $teamids = Yii::app()->session->get('id');
  909. }
  910. $cond = "AND l.currentAllocatedId IN (" . @$teamids . ")";
  911. }
  912. $financialyear = @$_POST['financialyear'];
  913. if (isset($financialyear) && !empty($financialyear))
  914. {
  915. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1, $financialyear);
  916. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"), $financialyear);
  917. }
  918. else
  919. {
  920. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1);
  921. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"));
  922. }
  923. $sql = "select count(leadId) as total from lead l join user u on u.id=l.currentAllocatedId where l.leadStatusId = " . $leadStatusId . " and (l.updatedOn between '" . @$CurrentMonth_first_minute . "' and '" . @$CurrentMonth_last_minute . "') and u.status='Active' $cond limit 1 ";
  924. $count = Yii::app()->db->createCommand($sql)->queryColumn();
  925. return @$count[0];
  926. //echo Lead::model()->count(array("select"=>'leadid',"condition"=>" leadStatusId = ".@$leadStatusId.""));
  927. }
  928. public static function getYTD($leadStatusId)
  929. {
  930. if (Yii::app()->session->get('type') == 'superadmin')
  931. {
  932. $cond = '';
  933. }
  934. else
  935. {
  936. if (count(@$_SESSION['relationalManager']) > 0)
  937. {
  938. $teamids = implode(",", $_SESSION['relationalManager']);
  939. }
  940. else
  941. {
  942. $teamids = Yii::app()->session->get('id');
  943. }
  944. $cond = "AND l.currentAllocatedId IN (" . @$teamids . ")";
  945. }
  946. $financialyear = @$_POST['financialyear'];
  947. if (isset($financialyear) && !empty($financialyear))
  948. {
  949. $CurrentYear_first_minute = mktime(0, 0, 0, 4, 1, $financialyear);
  950. $CurrentYear_last_minute = mktime(0, 0, 0, 4, 0, $financialyear + 1);
  951. }
  952. else
  953. {
  954. $CurrentYear_first_minute = mktime(0, 0, 0, 4, 1, date('Y'));
  955. $CurrentYear_last_minute = mktime(0, 0, 0, 4, 0, date('Y') + 1);
  956. }
  957. //$CurrentYear_first_minute = mktime(0, 0, 0, 1, 1, date('Y'));
  958. //$CurrentYear_last_minute = mktime(0, 0, 0, 13, 0, date('Y'));
  959. $sql = "select count(leadId) as total from lead l join user u on u.id=l.currentAllocatedId where l.leadStatusId = " . $leadStatusId . " and (l.updatedOn between '" . @$CurrentYear_first_minute . "' and '" . @$CurrentYear_last_minute . "') and u.status='Active' $cond ";
  960. $count = Yii::app()->db->createCommand($sql)->queryColumn();
  961. //echo Lead::model()->count(array("select"=>'leadid',"condition"=>" leadStatusId = ".@$leadStatusId.""));
  962. return @$count[0];
  963. //return @$count[0];
  964. }
  965. public static function rengetMTD($leadStatusId)
  966. {
  967. if (Yii::app()->session->get('type') == 'superadmin')
  968. {
  969. $cond = '';
  970. }
  971. else
  972. {
  973. if (count(@$_SESSION['relationalManager']) > 0)
  974. {
  975. $teamids = implode(",", $_SESSION['relationalManager']);
  976. }
  977. else
  978. {
  979. $teamids = Yii::app()->session->get('id');
  980. }
  981. $cond = "AND l.currentAllocatedId IN (" . @$teamids . ")";
  982. }
  983. $financialyear = @$_POST['financialyear'];
  984. if (isset($financialyear) && !empty($financialyear))
  985. {
  986. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1, $financialyear);
  987. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"), $financialyear);
  988. }
  989. else
  990. {
  991. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1);
  992. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"));
  993. }
  994. $sql = "select count(leadId) as total from renewallead l join user u on u.id=l.currentAllocatedId where l.leadStatusId = " . $leadStatusId . " and (l.updatedOn between '" . @$CurrentMonth_first_minute . "' and '" . @$CurrentMonth_last_minute . "') and u.status='Active' and u.isRenewalUser='yes' $cond limit 1 ";
  995. $count

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