Advertisement
Guest User

Untitled

a guest
Jun 29th, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 374.62 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Short description for file
  5. *
  6. * Long description (if any) ...
  7. *
  8. * PHP version 5
  9. *
  10. * The license text...
  11. *
  12. * @category PHP
  13. * @package Roster
  14. * @author vineet singh
  15. * @license a
  16. * @version CVS: $Id:$
  17. * @link http://pear.php.net/package/Roster
  18. * @see References to other sections (if any)...
  19. */
  20.  
  21. /**
  22. * Short description for class
  23. *
  24. * Long description (if any) ...
  25. *
  26. * @category PHP
  27. * @package Roster
  28. * @author vineet singh
  29. * @license a
  30. * @version Release: @package_version@
  31. * @link http://pear.php.net/package/Roster
  32. * @see References to other sections (if any)...
  33. */
  34. class Reports extends CFormModel {
  35.  
  36. /**
  37. * Short description for function
  38. *
  39. * Long description (if any) ...
  40. *
  41. * @param string $className Parameter description (if any) ...
  42. * @return string Return description (if any) ...
  43. * @access public
  44. * @static
  45. */
  46. public static function model($className = __CLASS__) {
  47. return parent::model($className);
  48. }
  49.  
  50. /**
  51. * Short description for function
  52. *
  53. * Long description (if any) ...
  54. *
  55. * @return string Return description (if any) ...
  56. * @access public
  57. */
  58. public function primaryKey() {
  59. return 'id';
  60. }
  61.  
  62. /**
  63. * Short description for function
  64. *
  65. * Long description (if any) ...
  66. *
  67. * @return string Return description (if any) ...
  68. * @access public
  69. */
  70. public function getCollectionName() {
  71. return 'users';
  72. }
  73.  
  74. /**
  75. * Short description for function
  76. *
  77. * Long description (if any) ...
  78. *
  79. * @param date $to_date Parameter description (if any) ...
  80. * @param date $from_date Parameter description (if any) ...
  81. * @return mixed Return description (if any) ...
  82. * @access public
  83. * @static
  84. */
  85. public static function calculate_experience($to_date, $from_date) {
  86. $interval = date_diff(date_create(date('Y-m-d', $to_date)), date_create(date('Y-m-d', $from_date)));
  87. $diff = $interval->format("Years:%Y,Months:%M,Days:%d");
  88. $a_out = array();
  89. array_walk(explode(',', $diff), function($val, $key) use(&$a_out) {
  90. $v = explode(':', $val);
  91. $a_out[$v[0]] = $v[1];
  92. });
  93.  
  94. return $a_out;
  95. }
  96.  
  97. /**
  98. * Short description for function
  99. *
  100. * Long description (if any) ...
  101. *
  102. * @param array $post_data Parameter description (if any) ...
  103. * @param unknown $tenant_id Parameter description (if any) ...
  104. * @return array Return description (if any) ...
  105. * @access public
  106. * @static
  107. */
  108. public static function getExperienceRoster($post_data, $tenant_id = null) {
  109. $return = array();
  110. //$sr_no=1;
  111. $filter = $post_data['filter_id'];
  112. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  113. $output = array();
  114.  
  115. foreach ($users as $key => $user) {
  116. $total_past_y = 0;
  117. $total_past_m = 0;
  118. $total_cur_y = 0;
  119. $total_cur_m = 0;
  120. $total_ex_m = 0;
  121. $total_ex_y = 0;
  122. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  123. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  124. $user_post = $user->getCurrentPosition($tenant_id);
  125. $job_title = $user_post['designation'];
  126. $department = $user_post['department'];
  127. $business_unit = $user_post['business_unit'];
  128. if (isset($user['past_work']) && !empty($user['past_work'])) {
  129. foreach ($user['past_work'] as $key => $work) {
  130. $diff_work = self::calculate_experience($work['to_date']->sec, $work['from_date']->sec);
  131. $total_past_y += intval($diff_work['Years']);
  132. $total_past_m += intval($diff_work['Months']);
  133. }
  134.  
  135. if ($total_past_m > 12) {
  136. $total_past_y += intval($total_past_m / 12);
  137. $total_past_m = $total_past_m % 12;
  138. }
  139. $past_work_ex = $total_past_y . "y " . $total_past_m . "m";
  140. } else {
  141. $past_work_ex = "";
  142. }
  143. if (isset($user->doj->sec) && $user->doj->sec != "") {
  144. $diff_cur_work = self::calculate_experience(time(), $user->doj->sec);
  145. $total_cur_y = $diff_cur_work['Years'];
  146. $total_cur_m = $diff_cur_work['Months'];
  147. $cur_work_ex = $total_cur_y . "y " . $total_cur_m . "m";
  148. } else {
  149. $cur_work_ex = "";
  150. }
  151. if (!empty($user['past_work'])) {
  152.  
  153. $total_ex_m = intval($total_past_m) + intval($total_cur_m);
  154. $total_ex_y = intval($total_past_y) + intval($total_cur_y);
  155. if ($total_ex_m > 12) {
  156. $total_ex_y += intval($total_ex_m / 12);
  157. $total_ex_m = $total_ex_m % 12;
  158. }
  159. $total_ex = $total_ex_y . "y " . $total_ex_m . "m";
  160. } elseif (!empty($user['designation'])) {
  161. $total_ex = $total_cur_y . "y " . $total_cur_m . "m";
  162. } else {
  163. $total_ex = "";
  164. }
  165.  
  166.  
  167. // $action_checkbox = "<input type=\"checkbox\" name=\"roster_action\" value=\"\">";
  168.  
  169. $output[] = array(
  170. // $action_checkbox,
  171. $employee_number,
  172. $user_name,
  173. $job_title,
  174. $department,
  175. $business_unit,
  176. $past_work_ex,
  177. $cur_work_ex,
  178. $total_ex
  179. );
  180. } // EOF foreach
  181. // echo "<pre>"; print_r($output); exit("</pre> \n exited here ");
  182. $cols = array(
  183. // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
  184. //'Sr No',
  185. 'Employee ID',
  186. 'Name',
  187. 'Job Title',
  188. 'Department',
  189. 'Business Unit',
  190. 'Past Experience',
  191. 'Current Experience',
  192. 'Total Experience'
  193. );
  194.  
  195. $roster_type = "Experience Report";
  196. $filenameexport = $roster_type;
  197. $final_output = array('output' => $output,
  198. 'cols' => $cols,
  199. 'filenameexport' => $filenameexport);
  200. return $final_output;
  201. }
  202.  
  203. // EOF function
  204.  
  205. /**
  206. * Short description for function
  207. *
  208. * Long description (if any) ...
  209. *
  210. * @param array $post_data Parameter description (if any) ...
  211. * @param unknown $tenant_id Parameter description (if any) ...
  212. * @param unknown $user_id Parameter description (if any) ...
  213. * @return array Return description (if any) ...
  214. * @access public
  215. * @static
  216. */
  217. public static function getLeavesCredited($post_data, $tenant_id = null, $user_id = null) {
  218. $return = array();
  219. //$sr_no=1;
  220. $filter = $post_data['filter_id'];
  221. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  222. $output = array();
  223. $leaves = Leaves::model()->getTenantLeaveListWithoutCompoff($tenant_id);
  224.  
  225. $index = 0;
  226. foreach ($users as $key => $user) {
  227. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  228. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  229. $user_post = $user->getCurrentPosition($tenant_id);
  230. $job_title = $user_post['designation'];
  231. $department = $user_post['department'];
  232. $business_unit = $user_post['business_unit'];
  233. // $action_checkbox = "<input type=\"checkbox\" name=\"roster_action\" value=\"\">";
  234. $leaves_user_allowed = Leaves::model()->getLeaveListWithoutCompOff($tenant_id, $user->user_id);
  235. unset($userleaves);
  236. foreach ($leaves as $leave_id => $leave) {
  237. if (array_key_exists($leave_id, $leaves_user_allowed)) {
  238. $userleaves[] = LeavesHelper::individualLeaveBalance($user->user_id, $tenant_id, $leave_id);
  239. } else {
  240. $userleaves[] = array(
  241. 'leave_name' => 'NA',
  242. 'balance' => 'NA',
  243. 'total' => 'NA',
  244. 'prevBalance' => 'NA'
  245. );
  246. }
  247. }
  248. $output[] = array(
  249. // $action_checkbox,
  250. $employee_number,
  251. $user_name,
  252. $job_title,
  253. $department,
  254. $business_unit,
  255. );
  256. for ($i = 0; $i < count($userleaves); $i++) {
  257. array_push($output[$index], $userleaves[$i]['total']);
  258. }
  259. $index++;
  260. } // EOF foreach user
  261.  
  262. $cols = array(
  263. // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
  264. //'Sr No',
  265. 'Employee ID',
  266. 'Name',
  267. 'Job Title',
  268. 'Department',
  269. 'Business Unit',
  270. );
  271.  
  272. foreach ($leaves as $leave_id => $leave_name) {
  273. array_push($cols, $leave_name);
  274. }
  275. $roster_type = "Leaves-Credited";
  276. $filenameexport = $roster_type;
  277. $final_output = array('output' => $output,
  278. 'cols' => $cols,
  279. 'filenameexport' => $filenameexport);
  280. return $final_output;
  281. }
  282.  
  283. // EOF function
  284.  
  285. /**
  286. * Short description for function
  287. *
  288. * Long description (if any) ...
  289. *
  290. * @param array $post_data Parameter description (if any) ...
  291. * @param unknown $tenant_id Parameter description (if any) ...
  292. * @param unknown $user_id Parameter description (if any) ...
  293. * @return array Return description (if any) ...
  294. * @access public
  295. * @static
  296. */
  297. public static function getLeavesNew($post_data, $tenant_id = null, $user_id = null, $from, $to) {
  298. $return = array();
  299. $filter = $post_data['filter_id'];
  300. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  301. $output = array();
  302. // $leaves = TenantLeaves::model()->findAllByAttributes(array('tenant_id'=>$tenant_id));
  303. // $leaves = Leaves::getLeaveList(null,null,true);
  304. $leavesModel = Leaves::model()->tenant($tenant_id)->findAll();
  305. foreach ($leavesModel as $key => $value) {
  306. $leaves[$value->id] = $value->name;
  307. }
  308. $index = 0;
  309.  
  310. $begin = new DateTime($from);
  311. $end = new DateTime($to);
  312. $end = $end->modify('+1 day');
  313. $interval = new DateInterval('P1D');
  314. $daterange = new DatePeriod($begin, $interval, $end);
  315.  
  316. $from = strtotime($from);
  317. $to = strtotime($to);
  318.  
  319. $criteria = new EMongoCriteria();
  320.  
  321. foreach ($users as $key => $user) {
  322. $totalDays = 0;
  323. $workingDays = 0;
  324. $workingDaysCount = 0;
  325. $appliedOn = "";
  326. $leaveType = "";
  327. $fromDate = "";
  328. $toDate = "";
  329. $totalDays = "";
  330. $workingDays = "";
  331. $isHalfDay = "";
  332. $isUnpaid = "";
  333. $approvedBy = "";
  334. $approvalDate = "";
  335. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  336. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  337. $user_post = $user->getCurrentPosition($tenant_id);
  338. $job_title = $user_post['designation'];
  339. $department = $user_post['department'];
  340.  
  341. $criteria->from_date('>=', new MongoDate($from));
  342. $criteria->from_date('<=', new MongoDate($to));
  343. $criteria->user_id = $user->id;
  344. $userLeaves = UserLeaves::model()->tenant($tenant_id)->findAll($criteria);
  345. if (!empty($userLeaves)) {
  346. foreach ($userLeaves as $userLeave) {
  347. $leaveMessage = $userLeave->message();
  348. if ($userLeave->status == UserLeaves::STATUS_APPROVED) {
  349. $approvedBy = $leaveMessage->getLeaveApprover();
  350. if (isset($leaveMessage->last_modified->sec)) {
  351. $approvalDate = date("Y-m-d", $leaveMessage->last_modified->sec);
  352. }
  353.  
  354. $appliedOn = date("d-m-Y", $userLeave->created->sec);
  355. $leaveType = ($userLeave->leave_id == "unpaid") ? "Unpaid Leave" : $leaves[$userLeave->leave_id];
  356. $fromDate = date("Y-m-d", $userLeave->from_date->sec);
  357. $toDate = date("Y-m-d", $userLeave->to_date->sec);
  358.  
  359. $totalDays = count($leaveMessage->attachments["items"]["total_days"]);
  360. $isUnpaid = ($userLeave->isUnpaid == UserLeaves::LEAVE_PAID ) ? "Paid" : "Unpaid";
  361. $workingDays = RandomHelper::getWorkingDays($userLeave->from_date->sec, $userLeave->to_date->sec, $user->id, $tenant_id);
  362. $workingDaysCount = $totalDays;
  363. if($userLeave->is_half_day == UserLeaves::HALF_DAY_YES)
  364. {
  365. $isHalfDay = "Half Day";
  366. $totalDays = "0.5";
  367. $workingDaysCount = "0.5";
  368. }
  369. else{
  370. $isHalfDay = "Full Day";
  371. }
  372. $output[] = array(
  373. $employee_number,
  374. $user_name,
  375. $job_title,
  376. $department,
  377. $appliedOn,
  378. $leaveType,
  379. $fromDate,
  380. $toDate,
  381. $totalDays,
  382. $workingDaysCount,
  383. $isHalfDay,
  384. $isUnpaid,
  385. $approvedBy,
  386. $approvalDate
  387. );
  388. }
  389. }
  390. }
  391.  
  392.  
  393. $index++;
  394. } // EOF foreach user
  395.  
  396. $cols = array(
  397. // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
  398. //'Sr No',
  399. 'Employee ID',
  400. 'Name',
  401. 'Job Title',
  402. 'Department',
  403. 'Applied on||date on which leave application request was created/made',
  404. 'Leave Type||this is the type of leave applied',
  405. 'From||date from which leave duration begins',
  406. 'To||date on which leave duration ends',
  407. 'Total Days||total days covered during leave period including holidays, weekly offs and working days',
  408. 'Working Days||total working days covered in leave period',
  409. 'Is it Half-day||this column says whether this is a half-day leave or not',
  410. 'Paid/Unpaid||here you\'ll see if it\'s been counted as a paid or an unpaid leave',
  411. 'Approved by||leave was approved by the person mentioned in this column',
  412. 'Approval date||leave was approved on the date mentioned here',
  413. );
  414.  
  415.  
  416. $roster_type = "New Leave Report";
  417. $filenameexport = $roster_type;
  418. $final_output = array('output' => $output,
  419. 'cols' => $cols,
  420. 'filenameexport' => $filenameexport);
  421. return $final_output;
  422. }
  423.  
  424. // EOF function
  425.  
  426. /**
  427. * Short description for function
  428. *
  429. * Long description (if any) ...
  430. *
  431. * @param array $post_data Parameter description (if any) ...
  432. * @param unknown $tenant_id Parameter description (if any) ...
  433. * @param unknown $user_id Parameter description (if any) ...
  434. * @return array Return description (if any) ...
  435. * @access public
  436. * @static
  437. */
  438. public static function getLeavesTaken($post_data, $tenant_id, $from, $to) {
  439. $return = array();
  440. if(date('Y-m',strtotime($to)) == date('Y-m'))
  441. {
  442. $to = date('Y-m')."-".date('t', strtotime($from));
  443. }
  444. //$for_month = "2015-08";
  445. //$sr_no=1;
  446. $filter = $post_data['filter_id'];
  447. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  448. $output = array();
  449. // $leaves = Leaves::model()->getLeaveList($tenant_id, $user_id);
  450. $leaves = Leaves::model()->getTenantLeaveListWithoutCompoff($tenant_id);
  451. $index = 0;
  452. foreach ($users as $key => $user) {
  453. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  454. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  455. $user_post = $user->getCurrentPosition($tenant_id);
  456. $job_title = $user_post['designation'];
  457. $department = $user_post['department'];
  458. $business_unit = $user_post['business_unit'];
  459. $action_checkbox = "<input type=\"checkbox\" name=\"roster_action\" value=\"\">";
  460. $leaves_user_allowed = Leaves::model()->getLeaveListWithoutCompOff($tenant_id, $user->user_id);
  461. unset($userleaves);
  462. foreach ($leaves as $leave_id => $leave) {
  463. //$userleaves[] = LeavesHelper::individualLeaveBalance($user->user_id, $tenant_id, $leave_id);
  464. /*if (array_key_exists($leave_id, $leaves_user_allowed)) {
  465. $userleaves[] = LeavesHelper::individualLeaveBalance($user->user_id, $tenant_id, $leave_id, $from, $to);
  466. } else {
  467. $userleaves[] = array(
  468. 'leave_name' => 'NA',
  469. 'balance' => 'NA',
  470. 'total' => 'NA',
  471. 'prevBalance' => 'NA'
  472. );
  473. }*/
  474. $leaves_approved = UserLeaves::model()->user_approved_leave($user->id, $leave_id)->forMonth(null, $from, $to)->paid()->findAll();
  475. //$leaves_approved = UserLeaves::model()->user_approved_leave($user->id, $leave_id)->forMonth($for_month)->paid()->findAll();
  476. $total_days = 0;
  477. foreach ($leaves_approved as $le)
  478. {
  479. $wekly_off_days = RandomHelper::getWorkingDays($le->from_date->sec, $le->to_date->sec, $le->user_id, $le->tenant_id);
  480. if (!empty($wekly_off_days))
  481. {
  482. if ($le->is_half_day == UserLeaves::HALF_DAY_YES)
  483. {
  484. $total_days += 0.5;
  485. }
  486. }
  487. else
  488. {
  489. if ($total_days > 0)
  490. {
  491. $total_days -= 0.5;
  492. }
  493. }
  494. }
  495. $counter = 0;
  496. $total_data_of_leaves = UserLeaves::getCountOfMonths($user->id, $leave_id,null, 1, $from, $to);
  497. //$total_data_of_leaves = UserLeaves::getCountOfMonths($user->id, $leave_id,$for_month, 1);
  498. if ($total_data_of_leaves > 0)
  499. {
  500. $counter = $total_data_of_leaves - $total_days;
  501. }
  502. else
  503. {
  504. $counter = $total_data_of_leaves;
  505. }
  506. $userleaves[] = $counter;
  507. }
  508. $output[] = array(
  509. // $action_checkbox,
  510. $employee_number,
  511. $user_name,
  512. $job_title,
  513. $department,
  514. $business_unit,
  515. );
  516. for ($i = 0; $i < count($userleaves); $i++) {
  517. /* if ($userleaves[$i]['total'] != "NA") {
  518. $prev_bal_leaves = (isset($userleaves[$i]['prevBalance'])) ? $userleaves[$i]['prevBalance'] : 0;
  519. $total_leaves_with_prev = $userleaves[$i]['total'] + $userleaves[$i]['prevBalance'];
  520. $newfinal = $total_leaves_with_prev - $userleaves[$i]['balance'];
  521. } else {
  522. $newfinal = "NA";
  523. }*/
  524. $newfinal = $userleaves[$i];
  525. array_push($output[$index], $newfinal);
  526. }
  527. $index++;
  528. } // EOF foreach user
  529.  
  530.  
  531.  
  532. $cols = array(
  533. // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
  534. //'Sr No',
  535. 'Employee ID',
  536. 'Name',
  537. 'Job Title',
  538. 'Department',
  539. 'Business Unit',
  540. );
  541.  
  542. foreach ($leaves as $leave_id => $leave_name) {
  543. array_push($cols, $leave_name);
  544. }
  545.  
  546. $roster_type = "Leaves-Taken-or-Used";
  547. $filenameexport = $roster_type;
  548. $final_output = array('output' => $output,
  549. 'cols' => $cols,
  550. 'filenameexport' => $filenameexport);
  551. return $final_output;
  552. }
  553.  
  554. // EOF function
  555.  
  556. /**
  557. * Short description for function
  558. *
  559. * Long description (if any) ...
  560. *
  561. * @param array $post_data Parameter description (if any) ...
  562. * @param unknown $tenant_id Parameter description (if any) ...
  563. * @param unknown $user_id Parameter description (if any) ...
  564. * @return array Return description (if any) ...
  565. * @access public
  566. * @static
  567. */
  568. public static function getLeavesBalance($post_data, $tenant_id, $user_id = null) {
  569. $return = array();
  570. //$sr_no=1;
  571. $filter = $post_data['filter_id'];
  572. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  573. $output = array();
  574. //$leaves = Leaves::model()->getLeaveList($tenant_id, $user_id);
  575. $leaves = Leaves::model()->getTenantLeaveListWithoutCompoff($tenant_id);
  576. $index = 0;
  577. foreach ($users as $key => $user) {
  578. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  579. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  580. $user_post = $user->getCurrentPosition($tenant_id);
  581. $job_title = $user_post['designation'];
  582. $department = $user_post['department'];
  583. $business_unit = $user_post['business_unit'];
  584. $leaves_user_allowed = Leaves::model()->getLeaveListWithoutCompOff($tenant_id, $user->user_id);
  585. $action_checkbox = "<input type=\"checkbox\" name=\"roster_action\" value=\"\">";
  586. unset($userleaves);
  587. foreach ($leaves as $leave_id => $leave) {
  588. // echo "<pre>"; print_r($leaves); exit("</pre> \n exited here ");
  589. //$userleaves[] = LeavesHelper::IndividualLeaveBalance($user->user_id, $tenant_id, $leave_id);
  590. if (array_key_exists($leave_id, $leaves_user_allowed)) {
  591. $userleaves[] = LeavesHelper::individualLeaveBalance($user->user_id, $tenant_id, $leave_id);
  592. } else {
  593. $userleaves[] = array(
  594. 'leave_name' => 'NA',
  595. 'balance' => 'NA',
  596. 'total' => 'NA',
  597. 'prevBalance' => 'NA'
  598. );
  599. }
  600. }
  601.  
  602. $output[] = array(
  603. // $action_checkbox,
  604. $employee_number,
  605. $user_name,
  606. $job_title,
  607. $department,
  608. $business_unit,
  609. );
  610. for ($i = 0; $i < count($userleaves); $i++) {
  611. array_push($output[$index], $userleaves[$i]['balance']);
  612. }
  613. $index++;
  614. } // EOF foreach user
  615. // echo "<pre>"; print_r($output); exit("</pre> \n exited here ");
  616. $leaves = Leaves::model()->getTenantLeaveListWithoutCompoff($tenant_id);
  617. $cols = array(
  618. // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
  619. //'Sr No',
  620. 'Employee ID',
  621. 'Name',
  622. 'Job Title',
  623. 'Department',
  624. 'Business Unit',
  625. );
  626.  
  627. foreach ($leaves as $leave_id => $leave_name) {
  628. array_push($cols, $leave_name);
  629. }
  630. $roster_type = "Leaves-Balance";
  631. $filenameexport = $roster_type;
  632. $final_output = array('output' => $output,
  633. 'cols' => $cols,
  634. 'filenameexport' => $filenameexport);
  635. return $final_output;
  636. }
  637.  
  638. // EOF function
  639.  
  640. /**
  641. * Short description for function
  642. *
  643. * Long description (if any) ...
  644. *
  645. * @param array $post_data Parameter description (if any) ...
  646. * @param unknown $tenant_id Parameter description (if any) ...
  647. * @param unknown $user_id Parameter description (if any) ...
  648. * @return array Return description (if any) ...
  649. * @access public
  650. * @static
  651. */
  652. public static function getLeavesSummary($post_data, $tenant_id, $user_id = null) {
  653. /* $name = "leavesSummary_{$tenant_id}_all";
  654. $cache = Yii::app()->cache->get($name);
  655. if (isset($cache) && !empty($cache)) {
  656. return $cache;
  657. } else { */
  658.  
  659. $return = array();
  660. //$sr_no=1;
  661. $userleaves = array();
  662. $filter = $post_data['filter_id'];
  663. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  664. $output = array();
  665. //$leaves = Leaves::model()->getLeaveList($tenant_id, $user_id);
  666. $leaves = Leaves::model()->getTenantLeaveListWithoutCompoff($tenant_id);
  667. /* removing compoff from the list */
  668. if (isset($leaves) && !empty($leaves)) {
  669. foreach ($leaves as $key => $leave) {
  670. if ($leave != "Compensatory Off") {
  671. $output_userleaves[$key] = $leave;
  672. }
  673. }
  674. $leaves = $output_userleaves;
  675. }
  676. /* removing compoff from the list */
  677. $index = 0;
  678. foreach ($users as $key => $user) {
  679. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  680. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  681. $user_post = $user->getCurrentPosition($tenant_id);
  682. $job_title = $user_post['designation'];
  683. $department = $user_post['department'];
  684. $business_unit = $user_post['business_unit'];
  685. $leaves_user_allowed = Leaves::model()->getLeaveListWithoutCompOff($tenant_id, $user->user_id);
  686. $action_checkbox = "<input type=\"checkbox\" name=\"roster_action\" value=\"\">";
  687. unset($userleaves);
  688. foreach ($leaves as $leave_id => $leave) {
  689. //$userleaves[] = LeavesHelper::individualLeaveBalance($user->user_id, $tenant_id, $leave_id);
  690. if (array_key_exists($leave_id, $leaves_user_allowed)) {
  691. $userleaves[] = LeavesHelper::individualLeaveBalance($user->user_id, $tenant_id, $leave_id);
  692. } else {
  693. $userleaves[] = array(
  694. 'leave_name' => 'NA',
  695. 'balance' => 'NA',
  696. 'total' => 'NA',
  697. 'prevBalance' => 'NA'
  698. );
  699. }
  700. }
  701.  
  702.  
  703. $output[] = array(
  704. // $action_checkbox,
  705. $employee_number,
  706. $user_name,
  707. );
  708. if (isset($userleaves)) {
  709. for ($i = 0; $i < count($userleaves); $i++) {
  710. for ($j = 0; $j < 3; $j++) {
  711. switch ($j) {
  712. case 0:
  713. $column = $userleaves[$i]['total'];
  714. break;
  715. case 1:
  716. if ($userleaves[$i]['total'] != "NA") {
  717. $column = $userleaves[$i]['total'] - $userleaves[$i]['balance'] + $userleaves[$i]['prevBalance'];
  718. } else {
  719. $column = "NA";
  720. }
  721. break;
  722. case 2:
  723. $column = $userleaves[$i]['balance'];
  724. break;
  725. }
  726. array_push($output[$index], $column);
  727. }
  728. //array_push($output[$index], $column);
  729. }
  730. }
  731. $index++;
  732. } // EOF foreach user
  733.  
  734.  
  735. $cols = array(
  736. // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
  737. //'Sr No',
  738. 'Employee ID',
  739. 'Name',
  740. );
  741. foreach ($leaves as $leave_id => $leave_name) {
  742. for ($i = 0; $i < 3; $i++) {
  743. switch ($i) {
  744. case 0:
  745. $colname = $leave_name . "\\n(Credited)";
  746. break;
  747. case 1:
  748. $colname = $leave_name . "\\n(Taken)";
  749. break;
  750. case 2:
  751. $colname = $leave_name . "\\n(Balance)";
  752. break;
  753. }
  754. array_push($cols, $colname);
  755. }
  756. }
  757. $roster_type = "Leaves-Summary";
  758. $filenameexport = $roster_type;
  759. $final_output = array('output' => $output,
  760. 'cols' => $cols,
  761. 'filenameexport' => $filenameexport);
  762. // Yii::app()->cache->set($name, $final_output, 0);
  763. return $final_output;
  764. // }
  765. }
  766.  
  767. // EOF function
  768.  
  769. /**
  770. * Short description for function
  771. *
  772. * Long description (if any) ...
  773. *
  774. * @param array $post_data Parameter description (if any) ...
  775. * @param unknown $tenant_id Parameter description (if any) ...
  776. * @return array Return description (if any) ...
  777. * @access public
  778. * @static
  779. */
  780. public static function getBirthdayRoster($post_data, $tenant_id = null) {
  781. $return = array();
  782. $filter = $post_data['filter_id'];
  783. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  784. $output = array();
  785. foreach ($users as $key => $user) {
  786. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  787. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  788. $user_post = $user->getCurrentPosition($tenant_id);
  789. $job_title = $user_post['designation'];
  790. $department = $user_post['department'];
  791. $business_unit = $user_post['business_unit'];
  792. if (isset($user['personal']['dob']->sec)) {
  793. $user_dob = date("Y-m-d", $user['personal']['dob']->sec);
  794. if (($timestamp = strtotime($user_dob)) !== false) {
  795. $php_date = getdate($timestamp);
  796. $dob_year = date("Y", $timestamp);
  797. $dob_month = date("M", $timestamp);
  798. $dob_day = date("d", $timestamp);
  799. $age = date("Y") - date("Y", $timestamp) . " y ";
  800. $age .= (date("m") > date("m", $timestamp)) ? date("m") - date("m", $timestamp) : date("m") - date("m", $timestamp) + 12;
  801. $age .= " m";
  802. $no_days_remain = self::days_till_birthday(date("d", $timestamp) . " " . date("M", $timestamp));
  803. }
  804. } else {
  805. $dob_year = "N.A.";
  806. $dob_month = "N.A.";
  807. $dob_day = "N.A.";
  808. $age = "N.A.";
  809. $no_days_remain = "N.A.";
  810. }
  811.  
  812. // $action_checkbox = "<input type=\"checkbox\" name=\"roster_action\" value=\"\">";
  813.  
  814. $output[] = array(
  815. // $action_checkbox,
  816. $employee_number,
  817. $user_name,
  818. $job_title,
  819. $department,
  820. $business_unit,
  821. $dob_day,
  822. $dob_month,
  823. $dob_year,
  824. $age,
  825. $no_days_remain,
  826. );
  827. } // EOF foreach
  828. // echo "<pre>"; print_r($output); exit("</pre> \n exited here ");
  829. $cols = array(
  830. // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
  831. //'SR NO',
  832. 'Employee ID',
  833. 'Name',
  834. 'Job Title',
  835. 'Department',
  836. 'Business Unit',
  837. 'Day',
  838. 'Month',
  839. 'Year',
  840. 'Age',
  841. 'Days Remain'
  842. );
  843.  
  844. $filenameexport = "Birthday-Data";
  845. $final_output = array('output' => $output,
  846. 'cols' => $cols,
  847. 'filenameexport' => $filenameexport);
  848. return $final_output;
  849. }
  850.  
  851. // EOF function
  852.  
  853. /**
  854. * Short description for function
  855. *
  856. * Long description (if any) ...
  857. *
  858. * @param array $post_data Parameter description (if any) ...
  859. * @param unknown $tenant_id Parameter description (if any) ...
  860. * @return array Return description (if any) ...
  861. * @access public
  862. * @static
  863. */
  864. /*public static function getCustomRoster($post_data, $tenant_id = null) {
  865. //echo "<pre>"; print_r($post_data); exit("</pre> \n exited here");
  866. $fields_arrary = explode("|", $post_data['fields']);
  867. $return = array();
  868. $filter = $post_data['filter_id'];
  869. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  870. $output = array();
  871. $idx = 0;
  872. foreach ($users as $key => $user) {
  873. // echo "<pre>"; print_r($user); exit("</pre> \n exited here ");
  874. foreach ($fields_arrary as $fields_key => $fields_value) {
  875. $a = array('');
  876. $a = explode("->", $fields_value);
  877. switch ($a[1]) {
  878. case 'cur_address':
  879. $cur_add = "";
  880. $cur_add .= (isset($user[$a[0]]['address'][0]['address'])) ? $user[$a[0]]['address'][0]['address'] : "";
  881. $cur_add .= (isset($user[$a[0]]['address'][0]['city'])) ? $user[$a[0]]['address'][0]['city'] : "";
  882. $cur_add .= (isset($user[$a[0]]['address'][0]['state'])) ? $user[$a[0]]['address'][0]['state'] : "";
  883. $op[$idx][] = $cur_add;
  884. break;
  885.  
  886. case 'additional_contact':
  887. $add_con = "";
  888. // echo "<pre>"; print_r($a); echo("</pre>");
  889. // echo "<pre>"; print_r($user['contact']['additional_contact']); exit("</pre> \n exited here ");
  890. foreach ($user['contact']['additional_contact'] as $key => $value) {
  891. if (isset($value)) {
  892. if ($value['type'] == $a[2]) {
  893. $add_con .= (isset($value['value'])) ? $value['value'] : "";
  894. $add_con .= ",";
  895. }
  896. }
  897. }
  898. $add_con = rtrim($add_con, ",");
  899. $op[$idx][] = $add_con;
  900. break;
  901.  
  902. case 'per_address':
  903. $per_add = "";
  904. $per_add .= (isset($user[$a[0]]['address'][0]['address'])) ? $user[$a[0]]['address'][0]['address'] : "";
  905. $per_add .= (isset($user[$a[0]]['address'][0]['city'])) ? $user[$a[0]]['address'][0]['city'] : "";
  906. $per_add .= (isset($user[$a[0]]['address'][0]['state'])) ? $user[$a[0]]['address'][0]['state'] : "";
  907. $op[$idx][] = $per_add;
  908. break;
  909.  
  910. case 'dob':
  911. $dob = (isset($user['personal']['dob']->sec)) ? date("d-M-Y", $user['personal']['dob']->sec) : "";
  912.  
  913. $op[$idx][] = $dob;
  914. break;
  915.  
  916. case 'gender':
  917. // echo "<pre>"; print_r($a); exit("</pre> \n exited here ");
  918. if (isset($user['personal']['gender'])) {
  919. switch ($user['personal']['gender']) {
  920. case 1:
  921. $gender = "Male";
  922. break;
  923. case 2:
  924. $gender = "Female";
  925. break;
  926. default:
  927. $gender = "";
  928. break;
  929. }
  930. } else {
  931. $gender = "";
  932. }
  933.  
  934. $op[$idx][] = $gender;
  935. break;
  936.  
  937. case 'marital_status':
  938. // echo "<pre>"; print_r($a); exit("</pre> \n exited here ");
  939. if (isset($user['personal']['marital_status'])) {
  940. switch ($user['personal']['marital_status']) {
  941. case 1:
  942. $marital_status = "Married";
  943. break;
  944. case 2:
  945. $marital_status = "Single";
  946. break;
  947. default:
  948. $marital_status = "";
  949. break;
  950. }
  951. } else {
  952. $marital_status = "";
  953. }
  954.  
  955. $op[$idx][] = $marital_status;
  956. break;
  957.  
  958. case 'anniversary_date':
  959. $anniversary_date = (isset($user['personal']['anniversary_date']->sec)) ? date("d-M-Y", $user['personal']['anniversary_date']->sec) : "";
  960.  
  961. $op[$idx][] = $anniversary_date;
  962. break;
  963.  
  964. case 'office_location':
  965. // echo "<pre>"; print_r($a); exit("</pre> \n exited here ");
  966. $tentaoffice_obj = TenantOffices::model()->findAllByAttributes(array('id' => $user[$a[0]][$a[1]]));
  967. if (isset($tentaoffice_obj) && !empty($tentaoffice_obj)) {
  968. $city = City::model()->findByPk($tentaoffice_obj[0]['city']);
  969. // echo "<pre>"; print_r($city); exit("</pre> \n exited here ");
  970. $office_location = (isset($city) && isset($city->name)) ? $city->name : "";
  971. } else {
  972. $office_location = "Not Found";
  973. }
  974.  
  975. $op[$idx][] = $office_location;
  976. break;
  977.  
  978. default:
  979. $op[$idx][] = $user[$a[0]][$a[1]];
  980. break;
  981. }
  982. }
  983.  
  984. $idx += 1;
  985. } // EOF foreach
  986. // echo "<pre>"; print_r($output); echo("</pre>");
  987. // echo "<pre>"; print_r($op[11]); exit("</pre> \n exited here ");
  988. $custom_roster_data = self::loadCustomRosterFilter();
  989. $cols = array(
  990. // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
  991. );
  992.  
  993. $fields_arrary = explode("|", $post_data['fields']);
  994. $idx = 0;
  995. foreach ($fields_arrary as $fields_key => $fields_value) {
  996. $a = array('');
  997. $a = explode("->", $fields_value);
  998. if (isset($a[2])) {
  999. $colname = $custom_roster_data[$a[0]][$a[1]][$a[2]];
  1000. } else {
  1001.  
  1002. $colname = $custom_roster_data[$a[0]][$a[1]];
  1003. }
  1004.  
  1005. array_push($cols, $colname);
  1006. }
  1007. $filenameexport = "Custom Roster";
  1008. $final_output = array('output' => $op,
  1009. 'cols' => $cols,
  1010. 'filenameexport' => $filenameexport
  1011. );
  1012. return $final_output;
  1013. }
  1014.  
  1015. // EOF function Name month day list P A WO H L AdjL
  1016.  
  1017. /**
  1018. * Short description for function
  1019. *
  1020. * Long description (if any) ...
  1021. *
  1022. * @param array $post_data Parameter description (if any) ...
  1023. * @param unknown $tenant_id Parameter description (if any) ...
  1024. * @param unknown $from Parameter description (if any) ...
  1025. * @param unknown $to Parameter description (if any) ...
  1026. * @return array Return description (if any) ...
  1027. * @access public
  1028. * @static
  1029. */
  1030. public static function getCustomRoster($post_data, $tenant_id = null) {
  1031. $fields_arrary = explode("|", $post_data['fields']);
  1032. if(in_array("company->inactive", $fields_arrary)){
  1033. $post_data['active_inactive'] = 2;
  1034. if (($key = array_search('company->inactive', $fields_arrary)) !== false) {
  1035. unset($fields_arrary[$key]);
  1036. array_values($fields_arrary);
  1037. }
  1038. }
  1039. $return = array();
  1040. $filter = $post_data['filter_id'];
  1041. $tenant_id = Yii::app()->user->getTenantId();
  1042. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  1043. $output = array();
  1044. $idx = 0;
  1045. foreach ($users as $key => $user) {
  1046. // echo "<pre>"; print_r($user); exit("</pre> \n exited here ");
  1047. foreach ($fields_arrary as $fields_key => $fields_value) {
  1048. $a = array('');
  1049. $a = explode("->", $fields_value);
  1050. switch ($a[1]) {
  1051. case 'cur_address':
  1052. $current = array();
  1053. $contact_details = $user->contact;
  1054. $current['address'] = (isset($contact_details['address'][0]['address']) && $contact_details['address'][0]['address'] != "") ? $contact_details['address'][0]['address'] : "";
  1055. $current['city'] = (isset($contact_details['address'][0]['city']) && $contact_details['address'][0]['city'] != "") ? City::getCityById($contact_details['address'][0]['city']) : "";
  1056. $current['state'] = (isset($contact_details['address'][0]['state']) && $contact_details['address'][0]['state'] != "") ? State::getStateById($contact_details['address'][0]['state']) : "";
  1057. $current['country'] = (isset($contact_details['address'][0]['country']) && $contact_details['address'][0]['country'] != "") ? Country::getCountryById($contact_details['address'][0]['country']) : "";
  1058. $current['pincode'] = (isset($contact_details['address'][0]['pincode']) && $contact_details['address'][0]['pincode'] != "") ? $contact_details['address'][0]['pincode'] : "";
  1059. $op[$idx][] = implode(", ", $current);
  1060. break;
  1061.  
  1062. case 'additional_contact':
  1063. $add_con = "";
  1064. foreach ($user['contact']['additional_contact'] as $key => $value) {
  1065. if (isset($value)) {
  1066. if ($value['type'] == $a[2]) {
  1067. $add_con .= (isset($value['value'])) ? $value['value'] : "";
  1068. $add_con .= ",";
  1069. }
  1070. }
  1071. }
  1072. $add_con = rtrim($add_con, ",");
  1073. $op[$idx][] = $add_con;
  1074. break;
  1075.  
  1076. case 'per_address':
  1077. $permanent = array();
  1078. $contact_details = $user->contact;
  1079. $permanent['address'] = (isset($contact_details['address'][1]['address']) && $contact_details['address'][1]['address'] != "") ? $contact_details['address'][1]['address'] : "";
  1080. $permanent['city'] = (isset($contact_details['address'][1]['city']) && $contact_details['address'][1]['city'] != "") ? City::getCityById($contact_details['address'][1]['city']) : "";
  1081. $permanent['state'] = (isset($contact_details['address'][1]['state']) && $contact_details['address'][1]['state'] != "") ? State::getStateById($contact_details['address'][1]['state']) : "";
  1082. $permanent['country'] = (isset($contact_details['address'][1]['country']) && $contact_details['address'][1]['country'] != "") ? Country::getCountryById($contact_details['address'][1]['country']) : "";
  1083. $permanent['pincode'] = (isset($contact_details['address'][1]['pincode']) && $contact_details['address'][1]['pincode'] != "") ? $contact_details['address'][1]['pincode'] : "";
  1084. $op[$idx][] = implode(", ", $permanent);
  1085. break;
  1086. case 'custom_fields':
  1087. $cus_field = "";
  1088.  
  1089. if (isset($user->personal->custom_fields[$a[2]]))
  1090. {
  1091. if ($user->personal->custom_fields[$a[2]] == "1")
  1092. {
  1093. $cus_field .= 'Yes';
  1094. }
  1095. else if ($user->personal->custom_fields[$a[2]] == "0" || $user->personal->custom_fields[$a[2]] == "")
  1096. {
  1097. $cus_field .= 'No';
  1098. }
  1099. else
  1100. {
  1101. $cus_field .= (is_array($user->personal->custom_fields[$a[2]])) ? implode(", ", $user->personal->custom_fields[$a[2]]) : $user->personal->custom_fields[$a[2]];
  1102. }
  1103. }
  1104. else
  1105. {
  1106. if (isset($user->payroll_profile->custom_fields[$a[2]]))
  1107. {
  1108. if ($user->payroll_profile->custom_fields[$a[2]] == "1")
  1109. {
  1110. $cus_field .= "Yes";
  1111. } else {
  1112. $cus_field .= "No";
  1113. }
  1114. } else {
  1115. $cus_field .= "No";
  1116. }
  1117. }
  1118.  
  1119. $op[$idx][] = $cus_field;
  1120. break;
  1121.  
  1122. case 'dob':
  1123. $dob = (isset($user['personal']['dob']->sec)) ? date("d-M-Y", $user['personal']['dob']->sec) : "";
  1124. $op[$idx][] = $dob;
  1125. break;
  1126.  
  1127. case 'deactivate_date':
  1128. $deactivate_date = (isset($user['deactivate_date']->sec)) ? date("d-M-Y", $user['deactivate_date']->sec) : "";
  1129. $op[$idx][] = $deactivate_date;
  1130. break;
  1131.  
  1132. case 'manager':
  1133. $direct_manager = (isset($user->manager_id) && $user->manager_id != "") ? UserMongo::getFullnameById($user->manager_id) : "No Direct Manager";
  1134. $op[$idx][] = $direct_manager;
  1135. break;
  1136.  
  1137. case 'dotted_manager':
  1138. $dotted_line_manager = (isset($user->dotted_line_manager) && $user->dotted_line_manager != "") ? UserMongo::getFullnameById($user->dotted_line_manager) : "No Dotted Manager";
  1139. $op[$idx][] = $dotted_line_manager;
  1140. break;
  1141.  
  1142. case 'emp_type':
  1143. $emp_type = (isset($user['personal']['type'])) ? TenantUserTypes::getTypesNameById($user['personal']['type']) : "";
  1144. $op[$idx][] = $emp_type;
  1145. break;
  1146.  
  1147. case 'probation':
  1148. $probation = (isset($user->probation_period)) ? ProbationPeriod::getProbationNameById($user->probation_period) : "";
  1149. $op[$idx][] = $probation;
  1150. break;
  1151.  
  1152. case 'emp_id':
  1153. $emp_id = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "";
  1154. $op[$idx][] = $emp_id;
  1155. break;
  1156.  
  1157. case 'confirmation':
  1158. //Date of confirmation
  1159. if(isset($user->date_of_confirmation) && $user->date_of_confirmation != ""){
  1160. $date_confirmation = (isset($user->date_of_confirmation->sec)) ? date('d-m-Y',$user->date_of_confirmation->sec) : $user->date_of_confirmation;
  1161. } else {
  1162. if(isset($user->doj->sec,$user->probation_period) && $user->probation_period != "")
  1163. {
  1164. $prb = ProbationPeriod::model()->tenant()->findByPk($user->probation_period);
  1165. if(isset($prb) && !empty($prb))
  1166. {
  1167. $number_of_days = $prb->number_of_days + 1;
  1168. $date = strtotime(date("Y-m-d", $user->doj->sec) . " +".$number_of_days ."days");
  1169. $date_confirmation = date('d-m-Y' ,$date);
  1170. }
  1171. }
  1172. else{
  1173. $date_confirmation = (isset($user->doj->sec)) ? date('d-m-Y',$user->doj->sec) : "";
  1174. }
  1175. }
  1176. $op[$idx][] = $date_confirmation;
  1177. break;
  1178.  
  1179. case 'pf_number':
  1180. $pf_number = (isset($user->pf_number)) ? $user->pf_number : "";
  1181. $op[$idx][] = $pf_number;
  1182. break;
  1183.  
  1184. case 'esic_number':
  1185. $esic_number = (isset($user->esic_number)) ? $user->esic_number : "";
  1186. $op[$idx][] = $esic_number;
  1187. break;
  1188.  
  1189. case 'uan_number':
  1190. $uan_number = (isset($user->uan_number)) ? $user->uan_number : "";
  1191. $op[$idx][] = $uan_number;
  1192. break;
  1193.  
  1194. case 'emergency_contact_person':
  1195. $emergency_contact_person = (isset($user->emergency_contact_person)) ? $user->emergency_contact_person : "";
  1196. $op[$idx][] = $emergency_contact_person;
  1197. break;
  1198.  
  1199. case 'emergency_contact_number':
  1200. $emergency_contact_number = (isset($user->emergency_contact_number)) ? $user->emergency_contact_number : "";
  1201. $op[$idx][] = $emergency_contact_number;
  1202. break;
  1203.  
  1204. case 'ctc':
  1205. $ctc_data = Ctc::model()->tenant($user->tenant_id)->user($user->id)->find();
  1206. if(isset($ctc_data) && !empty($ctc_data)){
  1207. $ctc = $ctc_data->getCtc();
  1208. }else{
  1209. $ctc = "N.A.";
  1210. }
  1211. $op[$idx][] = $ctc;
  1212. break;
  1213.  
  1214. case 'email':
  1215. $email = "";
  1216. $user_sql_data = User::model()->tenant()->findByPk($user->user_id);
  1217. if(isset($user_sql_data) && !empty($user_sql_data)){
  1218. $email = (isset($user_sql_data->selfservice) && $user_sql_data->selfservice == User::EMPLOYEE_SELFSERVICE_YES) ? $user_sql_data->email : "";
  1219. }
  1220. $op[$idx][] = $email;
  1221. break;
  1222.  
  1223. case 'gender':
  1224. // echo "<pre>"; print_r($a); exit("</pre> \n exited here ");
  1225. if (isset($user['personal']['gender'])) {
  1226. switch ($user['personal']['gender']) {
  1227. case 1:
  1228. $gender = "Male";
  1229. break;
  1230. case 2:
  1231. $gender = "Female";
  1232. break;
  1233. default:
  1234. $gender = "";
  1235. break;
  1236. }
  1237. } else {
  1238. $gender = "";
  1239. }
  1240.  
  1241. $op[$idx][] = $gender;
  1242. break;
  1243.  
  1244. case 'marital_status':
  1245. // echo "<pre>"; print_r($a); exit("</pre> \n exited here ");
  1246. if (isset($user['personal']['marital_status'])) {
  1247. switch ($user['personal']['marital_status']) {
  1248. case 1:
  1249. $marital_status = "Married";
  1250. break;
  1251. case 2:
  1252. $marital_status = "Single";
  1253. break;
  1254. default:
  1255. $marital_status = "";
  1256. break;
  1257. }
  1258. } else {
  1259. $marital_status = "";
  1260. }
  1261.  
  1262. $op[$idx][] = $marital_status;
  1263. break;
  1264.  
  1265. case 'anniversary_date':
  1266. $anniversary_date = (isset($user['personal']['anniversary_date']->sec)) ? date("d-M-Y", $user['personal']['anniversary_date']->sec) : "";
  1267.  
  1268. $op[$idx][] = $anniversary_date;
  1269. break;
  1270.  
  1271. case 'doj':
  1272. $doj = (isset($user['doj']->sec)) ? date("d-M-Y", $user['doj']->sec) : "";
  1273. $op[$idx][] = $doj;
  1274. break;
  1275.  
  1276. case 'department':
  1277. $user_post = $user->getCurrentPosition($tenant_id);
  1278. $department = (isset($user_post['department']) && $user_post['department'] != "") ? $user_post['department'] : "N.A.";
  1279. $op[$idx][] = $department;
  1280. break;
  1281.  
  1282. case 'designation':
  1283. $user_post = $user->getCurrentPosition($tenant_id);
  1284. $job_title = (isset($user_post['designation']) && $user_post['designation'] != "") ? $user_post['designation'] : "N.A.";
  1285. $op[$idx][] = $job_title;
  1286. break;
  1287.  
  1288. case 'tenure':
  1289. $diff_cur_work = self::calculate_experience(time(), $user->doj->sec);
  1290. $total_cur_y = $diff_cur_work['Years'];
  1291. $total_cur_m = $diff_cur_work['Months'];
  1292. $cur_work_ex = $total_cur_y . "y " . $total_cur_m . "m";
  1293. $op[$idx][] = $cur_work_ex;
  1294. break;
  1295.  
  1296. case 'dependents':
  1297. if (isset($user['dependents']) && !empty($user['dependents'])) {
  1298. $user_dependent = "";
  1299. foreach ($user['dependents'] as $key => $dependents) {
  1300. $dep_name = (isset($dependents['first_name'],$dependents['last_name'])) ? ucfirst($dependents['first_name'])." ".$dependents['last_name'] ." - " : "N.A.";
  1301. $dep_relation = (isset($dependents['relation_type'])) ? $dependents['relation_type'] ." - " : "N.A.";
  1302. $get_dep_age = (isset($dependents['dob']->sec)) ? self::calculate_experience(time(), $dependents['dob']->sec) : "N.A.";
  1303. $age_dep = (isset($get_dep_age) && $get_dep_age != "N.A.") ? $get_dep_age['Years']."y ".$get_dep_age['Months']."m" : "N.A.";
  1304. if(isset($dep_name) && $dep_name != "N.A."){
  1305. $user_dependent = (isset($user_dependent) && $user_dependent != "") ? $user_dependent . "<br/>". $dep_name ." ". $dep_relation ." ". $age_dep : $dep_name ." ". $dep_relation ." ". $age_dep;
  1306. }
  1307. }
  1308. } else {
  1309. $user_dependent = "N.A.";
  1310. }
  1311. $op[$idx][] = $user_dependent;
  1312. break;
  1313.  
  1314. case 'band':
  1315. $user_post = $user->getCurrentPosition($tenant_id);
  1316. $band = (isset($user_post['band']) && $user_post['band'] != "") ? $user_post['band'] : "N.A.";
  1317. $op[$idx][] = $band;
  1318. break;
  1319.  
  1320. case 'grade':
  1321. $user_post = $user->getCurrentPosition($tenant_id);
  1322. $grade = (isset($user_post['grade']) && $user_post['grade'] != "") ? $user_post['grade'] : "N.A.";
  1323. $op[$idx][] = $grade;
  1324. break;
  1325.  
  1326. case 'business_unit':
  1327. $user_post = $user->getCurrentPosition($tenant_id);
  1328. $business_unit = (isset($user_post['business_unit']) && $user_post['business_unit'] != "") ? $user_post['business_unit'] : "N.A.";
  1329. $op[$idx][] = $business_unit;
  1330. break;
  1331.  
  1332. case 'parent_company_id':
  1333. $company_name = SubTenantProfile::getGroupCompanyNameId($user->getIsSubCompany());
  1334. $parent_company = (isset($company_name) && $company_name != "") ? $company_name : "N.A.";
  1335. $op[$idx][] = $parent_company;
  1336. break;
  1337.  
  1338. case 'office_location':
  1339. if (isset($user->personal->office_location) && !empty($user->personal->office_location)) {
  1340. $office_location = TenantOffices::getTenantOfficeLocationsNameWithCountryById($user->personal->office_location);
  1341. } else {
  1342. $office_location = "NA";
  1343. }
  1344. $op[$idx][] = $office_location;
  1345. break;
  1346.  
  1347. case 'office_area':
  1348. if (isset($user->personal->office_location) && !empty($user->personal->office_location)) {
  1349. $office_location_area = TenantOffices::getTenantOfficeLocationsArea($user->personal->office_location);
  1350. } else {
  1351. $office_location_area = "NA";
  1352. }
  1353. $op[$idx][] = $office_location_area;
  1354. break;
  1355. case 'office_city':
  1356. if (isset($user->personal->office_location) && !empty($user->personal->office_location)) {
  1357. $office_location_city = TenantOffices::getTenantOfficeLocationsCity($user->personal->office_location);
  1358. } else {
  1359. $office_location_city = "NA";
  1360. }
  1361. $op[$idx][] = $office_location_city;
  1362. break;
  1363. case 'office_state':
  1364. if (isset($user->personal->office_location) && !empty($user->personal->office_location)) {
  1365. $office_location_state = TenantOffices::getTenantOfficeLocationsState($user->personal->office_location);
  1366. } else {
  1367. $office_location_state = "NA";
  1368. }
  1369. $op[$idx][] = $office_location_state;
  1370. break;
  1371. case 'office_country':
  1372. if (isset($user->personal->office_location) && !empty($user->personal->office_location)) {
  1373. $office_location_country = TenantOffices::getTenantOfficeLocationsCountry($user->personal->office_location);
  1374. } else {
  1375. $office_location_country = "NA";
  1376. }
  1377. $op[$idx][] = $office_location_country;
  1378. break;
  1379. case 'shift':
  1380. $shift_name = "";
  1381. $timestamp = time();
  1382. $user_shift_planner = UserShiftPlanner::getUserShift($user->id, $timestamp, null, 1);
  1383. if(isset($user_shift_planner) && !empty($user_shift_planner)){
  1384. $tenant_shift = TenantShift::getTenantShift($user_shift_planner['shift_id'],$user->tenant_id);
  1385. if(isset($tenant_shift) && !empty($tenant_shift)){
  1386. $shift_name = $tenant_shift->shift_name . " (". AttendanceHelper::getFormatedTime($tenant_shift->begin_time) ."-". AttendanceHelper::getFormatedTime($tenant_shift->end_time).")";
  1387. }
  1388. }
  1389. $op[$idx][] = $shift_name;
  1390. break;
  1391. case 'policy':
  1392. $policy_name = "";
  1393. $timestamp = time();
  1394. $user_shift_planner = UserShiftPlanner::getUserShift($user->id, $timestamp, null, 1);
  1395. if(isset($user_shift_planner) && !empty($user_shift_planner)){
  1396. $attendance_policy = AttendancePolicy::getAttendancePolicy($user_shift_planner['policy_id'],$user->tenant_id);
  1397. if(isset($attendance_policy) && !empty($attendance_policy)){
  1398. $policy_name = $attendance_policy->policy_name;
  1399. }
  1400. }
  1401. $op[$idx][] = $policy_name;
  1402. break;
  1403. case 'weeklyoff':
  1404. $weeklyoff = "";
  1405. $timestamp = time();
  1406. $user_shift_planner = UserShiftPlanner::getUserShift($user->id, $timestamp, null, 1);
  1407. if(isset($user_shift_planner) && !empty($user_shift_planner)){
  1408. $user_weekly_off = WeeklyOff::getWeeklyOff($user_shift_planner['weekly_off_id'],$user->tenant_id);
  1409. if(isset($user_weekly_off) && !empty($user_weekly_off)){
  1410. $non_working_days = $user_weekly_off->getNonWorkingDays();
  1411. $weeklyoff = $user_weekly_off->weekly_off_name . " (". $non_working_days.")";
  1412. }
  1413. }
  1414. $op[$idx][] = $weeklyoff;
  1415. break;
  1416. case 'location_type':
  1417. $tentaoffice_obj_typ = TenantOffices::model()->findByAttributes(array('id' => $user->personal->office_location));
  1418. if (isset($tentaoffice_obj_typ) && !empty($tentaoffice_obj_typ)) {
  1419. $type_loc = (isset($tentaoffice_obj_typ->location_type) && $tentaoffice_obj_typ->location_type != "") ? '('. TenantLocationTypes::getTypesNameById($tentaoffice_obj_typ->location_type).')' :"";
  1420. $office_location_type = $type_loc;
  1421. } else {
  1422. $office_location_type = "";
  1423. }
  1424. $op[$idx][] = $office_location_type;
  1425. break;
  1426. case 'bank_account':
  1427. if(!empty($user[$a[0]][$a[1]])){
  1428. $op[$idx][] = (string)$user[$a[0]][$a[1]];
  1429. }else{
  1430. $op[$idx][] = "N.A";
  1431. }
  1432. break;
  1433. default:
  1434. $op[$idx][] = $user[$a[0]][$a[1]];
  1435. break;
  1436. }
  1437. }
  1438.  
  1439. $idx += 1;
  1440. } // EOF foreach
  1441. // echo "<pre>"; print_r($output); echo("</pre>");
  1442. // echo "<pre>"; print_r($op[11]); exit("</pre> \n exited here ");
  1443. $custom_roster_data = self::loadCustomRosterFilter();
  1444. $cols = array(
  1445. // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
  1446. );
  1447.  
  1448. $fields_arrary = explode("|", $post_data['fields']);
  1449. if (($key = array_search('company->inactive', $fields_arrary)) !== false) {
  1450. unset($fields_arrary[$key]);
  1451. array_values($fields_arrary);
  1452. }
  1453. $idx = 0;
  1454. foreach ($fields_arrary as $fields_key => $fields_value) {
  1455. $a = array('');
  1456. $a = explode("->", $fields_value);
  1457. if (isset($a[2])) {
  1458. $colname = $custom_roster_data[$a[0]][$a[1]][$a[2]];
  1459. } else {
  1460.  
  1461. $colname = $custom_roster_data[$a[0]][$a[1]];
  1462. }
  1463.  
  1464. array_push($cols, $colname);
  1465. }
  1466. $filenameexport = "Custom Roster";
  1467. $final_output = array('output' => $op,
  1468. 'cols' => $cols,
  1469. 'filenameexport' => $filenameexport
  1470. );
  1471. // echo '<pre>';
  1472. // print_r($final_output); exit;
  1473. return $final_output;
  1474. }
  1475.  
  1476. // EOF function Name month day list P A WO H L AdjL
  1477.  
  1478. /**
  1479. * Short description for function
  1480. *
  1481. * Long description (if any) ...
  1482. *
  1483. * @param array $post_data Parameter description (if any) ...
  1484. * @param unknown $tenant_id Parameter description (if any) ...
  1485. * @param unknown $from Parameter description (if any) ...
  1486. * @param unknown $to Parameter description (if any) ...
  1487. * @return array Return description (if any) ...
  1488. * @access public
  1489. * @static
  1490. */
  1491. public static function getAttendanceSummaryRoster($post_data, $tenant_id = null, $from = null, $to = null) {
  1492.  
  1493. $return = array();
  1494. $index = 0;
  1495. $output = array();
  1496. $finaldata = array();
  1497.  
  1498. $filter = $post_data['filter_id'];
  1499. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  1500.  
  1501. $begin = new DateTime($from);
  1502. $end = new DateTime($to);
  1503. $end = $end->modify('+1 day');
  1504. $interval = new DateInterval('P1D');
  1505. $daterange = new DatePeriod($begin, $interval, $end);
  1506. $from = strtotime($from);
  1507. $to = strtotime($to);
  1508.  
  1509. $criteria = new EMongoCriteria();
  1510. $criteria->shift_date('>=', new MongoDate($from));
  1511. $criteria->shift_date('<=', new MongoDate($to));
  1512.  
  1513. foreach ($users as $key => $user) {
  1514. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  1515. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  1516. $criteria->user_id = $user->id;
  1517. $userAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
  1518. // echo "<pre>"; print_r($userAttendanceLogs); exit("</pre> \n exited here \n");
  1519. $present = 0;
  1520. $absent = 0;
  1521. $weeklyoff_count = 0;
  1522. $holiday_count = 0;
  1523. $leave_count = 0;
  1524. $unpaidleave_count = 0;
  1525. $return = array();
  1526. $output[] = array(
  1527. $employee_number,
  1528. $user_name,
  1529. );
  1530. $jindex = 0;
  1531. foreach ($daterange as $date) {
  1532. $unpaidFlag = false;
  1533. if (isset($userAttendanceLogs[$jindex])) {
  1534. if ($date->format("d") == date("d", $userAttendanceLogs[$jindex]->shift_date->sec)) {
  1535. $date = date("d", $userAttendanceLogs[$jindex]->shift_date->sec);
  1536. if (isset($userAttendanceLogs[$jindex]->attendance_status)) {
  1537. $status = $userAttendanceLogs[$jindex]->attendance_status;
  1538.  
  1539. if ($status == UserAttendance::ATTENDANCE_STATUS_ABSENT)
  1540. {
  1541. $checkBothClockInClockOut = false;
  1542. $checkOnlyClockIn = false;
  1543. // Get policy_id to check policy for markin / markout / markboth
  1544. $shift_planner_id = $userAttendanceLogs[$jindex]->shift_planner;
  1545. // Get shift planner
  1546. $useShiftPlanner = UserShiftPlanner::model()->user($user->id)->findByPk($shift_planner_id);
  1547. if (!empty($useShiftPlanner))
  1548. {
  1549. $policy_id = $useShiftPlanner->policy_id;
  1550. }
  1551. else
  1552. {
  1553. $policy_id = "";
  1554. }
  1555.  
  1556. // Get user policy using policy Id.
  1557. $attendancePolicy = AttendancePolicy::getAttendancePolicy($policy_id, $tenant_id);
  1558. if (!empty($attendancePolicy))
  1559. {
  1560. if ($attendancePolicy->markin_policy->status == MarkinPolicy::MARKIN_BOTH)
  1561. {
  1562. $checkBothClockInClockOut = true;
  1563. $checkOnlyClockIn = false;
  1564. }
  1565. else if ($attendancePolicy->markin_policy->status == MarkinPolicy::MARKIN_IN)
  1566. {
  1567. $checkBothClockInClockOut = false;
  1568. $checkOnlyClockIn = true;
  1569. }
  1570. }
  1571.  
  1572. if ($checkBothClockInClockOut)
  1573. {
  1574. if(($userAttendanceLogs[$jindex]->punchin_time != '') && ($userAttendanceLogs[$jindex]->punchout_time != ''))
  1575. {
  1576. $status = UserAttendanceLog::ATTENDANCE_STATUS_PRESENT;
  1577. }
  1578. else
  1579. {
  1580. $status = UserAttendanceLog::ATTENDANCE_STATUS_ABSENT;
  1581. }
  1582. }
  1583. else if ($checkOnlyClockIn)
  1584. {
  1585. if(($userAttendanceLogs[$jindex]->punchin_time != ''))
  1586. {
  1587. $status = UserAttendanceLog::ATTENDANCE_STATUS_PRESENT;
  1588. }
  1589. else
  1590. {
  1591. $status = UserAttendanceLog::ATTENDANCE_STATUS_ABSENT;
  1592. }
  1593. }
  1594. else
  1595. {
  1596. $status = UserAttendanceLog::ATTENDANCE_STATUS_ABSENT;
  1597. }
  1598. }
  1599. elseif ($status == UserAttendance::ATTENDANCE_STATUS_PRESENT)
  1600. {
  1601. $status = UserAttendanceLog::ATTENDANCE_STATUS_PRESENT;
  1602. }
  1603. // ***************************** <END> *****************************
  1604.  
  1605. /*
  1606. // OLD CODE Commented
  1607. if ($status == UserAttendance::ATTENDANCE_STATUS_ABSENT) {
  1608. $status = UserAttendanceLog::ATTENDANCE_STATUS_ABSENT;
  1609. } elseif ($status == UserAttendance::ATTENDANCE_STATUS_PRESENT) {
  1610. $status = UserAttendanceLog::ATTENDANCE_STATUS_PRESENT;
  1611. }
  1612. */
  1613.  
  1614. $weeklyoff = $userAttendanceLogs[$jindex]->is_weekly_off->status;
  1615. $holiday = $userAttendanceLogs[$jindex]->is_holiday->status;
  1616. $leave = $userAttendanceLogs[$jindex]->in_leave->status;
  1617. $leave_revoked = false;
  1618. if (isset($userAttendanceLogs[$jindex]->in_leave->leave_id)) {
  1619. $unpaidLeave = UserLeaves::model()->findByPk($userAttendanceLogs[$jindex]->in_leave->leave_id);
  1620. if ($unpaidLeave->isUnpaid == UserLeaves::LEAVE_UNPAID) {
  1621. $unpaidleave_count++;
  1622. $unpaidFlag = true;
  1623. } else {
  1624. $unpaidFlag = false;
  1625. }
  1626. if ($unpaidLeave->status == UserLeaves::STATUS_REVOKED || $unpaidLeave->status == UserLeaves::STATUS_REJECTED)
  1627. {
  1628. $leave_revoked = true;
  1629. }
  1630. } else {
  1631. $unpaidFlag = false;
  1632. }
  1633. if (isset($weeklyoff) && $weeklyoff == "1") {
  1634. $status = "W";
  1635. $weeklyoff_count++;
  1636. } elseif (isset($holiday) && $holiday == "1") {
  1637. $status = "H";
  1638. $holiday_count++;
  1639. } elseif ((isset($leave)) && ($leave == "1") && ($leave_revoked == false)) {
  1640. $status = "<font color = #0033FF><b>L</b></font>";
  1641. $leave_count++;
  1642. } elseif ($status == UserAttendanceLog::ATTENDANCE_STATUS_PRESENT || $status == UserAttendanceLog::ATTENDANCE_STATUS_PENDING) {
  1643. $status = "<font color = #009900><b>P</b></font>";
  1644. $present++;
  1645. } /* elseif ($status == UserAttendanceLog::ATTENDANCE_STATUS_PENDING) {
  1646. $status = "n";
  1647. } */ elseif ($status == UserAttendanceLog::ATTENDANCE_STATUS_ABSENT || $status == UserAttendance::ATTENDANCE_STATUS_ABSENT) {
  1648. $status = "<font color = #FF0000><b>A</b></font>";
  1649. $absent++;
  1650. } else {
  1651. $status = "";
  1652. }
  1653. } else {
  1654. $status = "";
  1655. }
  1656. $jindex++;
  1657. } else {
  1658. $status = "-";
  1659. }
  1660. } else {
  1661. $status = "-";
  1662. }
  1663. if ($unpaidFlag) {
  1664. $status = "U";
  1665. }
  1666. array_push($output[$index], $status);
  1667. } // my good loop
  1668.  
  1669. array_push($output[$index], $present);
  1670. array_push($output[$index], $absent);
  1671. array_push($output[$index], $weeklyoff_count);
  1672. array_push($output[$index], $leave_count);
  1673. array_push($output[$index], $unpaidleave_count);
  1674. $index++;
  1675. } // EOF foreach all user
  1676.  
  1677. $flag = true;
  1678. $cols = array(
  1679. // 'Name||Column displays the Name of the employees.'
  1680. 'Employee ID',
  1681. 'Name||Column displays the Name of the employees.'
  1682. );
  1683.  
  1684. foreach ($daterange as $date) {
  1685. $finaldatacols = $date->format("d") . "<br>" . substr((String) $date->format("D"), 0, 2);
  1686. array_push($cols, $finaldatacols);
  1687. }
  1688.  
  1689. array_push($cols, 'P||Column displays the total number days when an employee was Present in the specified duration.');
  1690. array_push($cols, 'A||Column displays the total number of days when an employee was Absent in the specified duration.');
  1691. array_push($cols, 'W||Column displays the total number of Weekly Offs assigned to an employee in the specified duration.');
  1692. array_push($cols, 'L||Column displays the total number of days when an employee was on a Leave in the specified duration.');
  1693. array_push($cols, 'U||Column displays the total number of days when an employee was on a Unpaid Leave in the specified duration.');
  1694.  
  1695. $roster_type = "Attendance-Summary";
  1696. $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
  1697. $filenameexport = $roster_type . "_" . $date;
  1698. $final_output = array('output' => $output,
  1699. 'cols' => $cols,
  1700. 'filenameexport' => $filenameexport);
  1701. return $final_output;
  1702. }
  1703.  
  1704. // EOF function
  1705.  
  1706. /**
  1707. * Short description for function
  1708. *
  1709. * Long description (if any) ...
  1710. *
  1711. * @param array $post_data Parameter description (if any) ...
  1712. * @param unknown $tenant_id Parameter description (if any) ...
  1713. * @param unknown $from Parameter description (if any) ...
  1714. * @param unknown $to Parameter description (if any) ...
  1715. * @return array Return description (if any) ...
  1716. * @access public
  1717. * @static
  1718. */
  1719. public static function getAbsenteesSummaryRoster($post_data, $tenant_id = null, $from = null, $to = null) {
  1720. $return = array();
  1721. $index = 0;
  1722. $filter = $post_data['filter_id'];
  1723. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  1724. $output = array();
  1725. $finaldata = array();
  1726. $begin = new DateTime($from);
  1727. $end = new DateTime($to);
  1728. $end = $end->modify('+1 day');
  1729. $interval = new DateInterval('P1D');
  1730. $daterange = new DatePeriod($begin, $interval, $end);
  1731. $from = strtotime($from);
  1732. $to = strtotime($to);
  1733. $criteria = new EMongoCriteria();
  1734. $criteria->shift_date('>=', new MongoDate($from));
  1735. $criteria->shift_date('<=', new MongoDate($to));
  1736. foreach ($users as $key => $user) {
  1737. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  1738. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  1739. $user_post = $user->getCurrentPosition($tenant_id);
  1740. $job_title = $user_post['designation'];
  1741. $department = $user_post['department'];
  1742. $business_unit = $user_post['business_unit'];
  1743. $criteria->user_id = $user->id;
  1744. $userAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
  1745. $present = 0;
  1746. $absent = 0;
  1747. $weeklyoff_count = 0;
  1748. $holiday_count = 0;
  1749. $leave_count = 0;
  1750. $counter_var = 0;
  1751. $present_count = 0;
  1752. $return = array();
  1753. $output[] = array(
  1754. $employee_number,
  1755. $user_name,
  1756. $job_title,
  1757. $department,
  1758. );
  1759.  
  1760. foreach ($userAttendanceLogs as $key => $userAttendance) {
  1761. if (!empty($userAttendance)) {
  1762. $status = $userAttendance->attendance_status;
  1763. if ($status == UserAttendance::ATTENDANCE_STATUS_ABSENT) {
  1764. $status = UserAttendanceLog::ATTENDANCE_STATUS_ABSENT;
  1765. } elseif ($status == UserAttendance::ATTENDANCE_STATUS_PRESENT) {
  1766. $status = UserAttendanceLog::ATTENDANCE_STATUS_PRESENT;
  1767. }
  1768. if ($status == UserAttendanceLog::ATTENDANCE_STATUS_ABSENT) {
  1769. $weeklyoff = $userAttendance->is_weekly_off->status;
  1770. $leave = $userAttendance->in_leave->status;
  1771. $holiday = $userAttendance->is_holiday->status;
  1772. if (is_null($weeklyoff) || $weeklyoff == IsWeeklyOff::WEEKLYOFF_YES) {
  1773. continue;
  1774. } elseif (is_null($leave) || $leave == InLeave::INLEAVE_YES) {
  1775. continue;
  1776. } elseif (is_null($holiday) || $holiday == IsHoliday::HOLIDAY_YES) {
  1777. continue;
  1778. } else {
  1779. $absent++;
  1780. }
  1781. } // EOF abset status if
  1782. } // EOF !empty if
  1783. } // EOF userattendance foreach
  1784. array_push($output[$index++], $absent);
  1785. } // EOF foreach all user
  1786. $flag = true;
  1787. $cols = array(
  1788. 'Employee ID',
  1789. 'Name||Column displays the Name of the employees.',
  1790. 'Job Title||Column displays the Job Tittle of the particular employee.',
  1791. 'Department||Column displays the Department to which the employee belongs.',
  1792. 'Absent Count||Column displays the total number of days when an employee was Absent in the specified duration.',
  1793. );
  1794. $roster_type = "Absentees-Summary";
  1795. $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
  1796. $filenameexport = $roster_type . "_" . $date;
  1797. $final_output = array('output' => $output,
  1798. 'cols' => $cols,
  1799. 'filenameexport' => $filenameexport);
  1800. return $final_output;
  1801. }
  1802.  
  1803. // EOF function
  1804.  
  1805. /**
  1806. * Short description for function
  1807. *
  1808. * Long description (if any) ...
  1809. *
  1810. * @param array $post_data Parameter description (if any) ...
  1811. * @param unknown $tenant_id Parameter description (if any) ...
  1812. * @param unknown $from Parameter description (if any) ...
  1813. * @param unknown $to Parameter description (if any) ...
  1814. * @return array Return description (if any) ...
  1815. * @access public
  1816. * @static
  1817. */
  1818. public static function getAttendanceLocationSummaryRoster($post_data, $tenant_id = null, $from = null, $to = null) {
  1819. $return = array();
  1820. $index = 0;
  1821. $filter = $post_data['filter_id'];
  1822. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  1823. $output = array();
  1824. $finaldata = array();
  1825. $begin = new DateTime($from);
  1826. $end = new DateTime($to);
  1827. $end = $end->modify('+1 day');
  1828. $interval = new DateInterval('P1D');
  1829. $daterange = new DatePeriod($begin, $interval, $end);
  1830. $from = strtotime($from);
  1831. $to = strtotime($to);
  1832. $criteria = new EMongoCriteria();
  1833. $criteria->shift_date('>=', new MongoDate($from));
  1834. $criteria->shift_date('<=', new MongoDate($to));
  1835. foreach ($users as $key => $user) {
  1836. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  1837. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  1838. $user_post = $user->getCurrentPosition($tenant_id);
  1839. $job_title = $user_post['designation'];
  1840. $department = $user_post['department'];
  1841. $business_unit = $user_post['business_unit'];
  1842. $criteria->user_id = $user->id;
  1843. $UserAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
  1844. $office = 0;
  1845. $home = 0;
  1846. $out = 0;
  1847. $return = array();
  1848. $output[] = array(
  1849. $employee_number,
  1850. $user_name,
  1851. $job_title,
  1852. $department,
  1853. );
  1854. $jindex = 0;
  1855. foreach ($daterange as $date) {
  1856. if (isset($UserAttendanceLogs[$jindex])) {
  1857. $date = date("d", $UserAttendanceLogs[$jindex]->shift_date->sec);
  1858. if (isset($UserAttendanceLogs[$jindex]->shift_planner)) {
  1859. $timestamp = $UserAttendanceLogs[$jindex]->shift_date->sec;
  1860. $data = UserShiftPlanner::getUserShift($user->id, $timestamp, $tenant_id);
  1861. $shift_obj = TenantShift::getTenantShift($data['shift_id'], $tenant_id);
  1862.  
  1863.  
  1864. $request = Request::getAttendanceRequestnew($UserAttendanceLogs[$jindex]->user_id, $shift_obj->is_next_day, $UserAttendanceLogs[$jindex]->shift_date->sec);
  1865.  
  1866. if (!empty($request)) {
  1867. //$request_location_array = AttendanceRequestForm::loadLocation();
  1868. //$request_location = $request_location_array[$request->attendance->request_from];
  1869. if ($request->attendance->request_from == UserAttendance::WORK_FROM_OFFICE) {
  1870. $office++;
  1871. }
  1872. if ($request->attendance->request_from == UserAttendance::WORK_FROM_HOME) {
  1873. $home++;
  1874. }
  1875. if ($request->attendance->request_from == UserAttendance::WORK_OUT_DUTY) {
  1876. $out++;
  1877. }
  1878. }
  1879. } else {
  1880. $office++;
  1881. }
  1882. }
  1883. /* array_push($output[$index], $status); */
  1884. $jindex++;
  1885. } // my good loop
  1886. array_push($output[$index], $office);
  1887. array_push($output[$index], $out);
  1888. array_push($output[$index], $home);
  1889. $index++;
  1890. } // EOF foreach all user
  1891. $flag = true;
  1892. $cols = array(
  1893. 'Employee ID',
  1894. 'Name||Column displays the Name of the employees.',
  1895. 'Job Title||Column displays the Job Tittle of the particular employee.',
  1896. 'Department||Column displays the Department to which the employee belongs.',
  1897. 'Office Days||Column displays the total number of days where attendance location is Office in the specified duration.',
  1898. 'Field Duty Days||Column displays the total number of days where attendance location is Out - Duty in the specified duration.',
  1899. 'Home Days||Column displays the total number of days where attendance location is Home in the specified duration.',
  1900. );
  1901. $roster_type = "Attendance-Location-Summary";
  1902. $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
  1903. $filenameexport = $roster_type . "_" . $date;
  1904.  
  1905. $final_output = array('output' => $output,
  1906. 'cols' => $cols,
  1907. 'filenameexport' => $filenameexport);
  1908. return $final_output;
  1909. }
  1910.  
  1911. // EOF function
  1912.  
  1913. /**
  1914. * Short description for function
  1915. *
  1916. * Long description (if any) ...
  1917. *
  1918. * @param array $post_data Parameter description (if any) ...
  1919. * @param unknown $tenant_id Parameter description (if any) ...
  1920. * @param unknown $from Parameter description (if any) ...
  1921. * @param unknown $to Parameter description (if any) ...
  1922. * @return array Return description (if any) ...
  1923. * @access public
  1924. * @static
  1925. */
  1926. public static function getOverTimeSummaryRoster($post_data, $tenant_id = null, $from = null, $to = null) {
  1927. $return = array();
  1928. $index = 0;
  1929. $filter = $post_data['filter_id'];
  1930. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  1931. $output = array();
  1932. $finaldata = array();
  1933. $begin = new DateTime($from);
  1934. $end = new DateTime($to);
  1935. $end = $end->modify('+1 day');
  1936. $interval = new DateInterval('P1D');
  1937. $daterange = new DatePeriod($begin, $interval, $end);
  1938. $from = strtotime($from);
  1939. $to = strtotime($to);
  1940. $criteria = new EMongoCriteria();
  1941. $criteria->shift_date('>=', new MongoDate($from));
  1942. $criteria->shift_date('<=', new MongoDate($to));
  1943. foreach ($users as $key => $user) {
  1944. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  1945. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  1946. $user_post = $user->getCurrentPosition($tenant_id);
  1947. $job_title = $user_post['designation'];
  1948. $department = $user_post['department'];
  1949. $business_unit = $user_post['business_unit'];
  1950. $criteria->user_id = $user->id;
  1951. $userAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
  1952. $overtime = 0;
  1953. $overtimesum = 0;
  1954. $return = array();
  1955. $output[] = array(
  1956. $employee_number,
  1957. $user_name,
  1958. $job_title,
  1959. $department,
  1960. );
  1961. $jindex = 0;
  1962. foreach ($daterange as $date) {
  1963. if (isset($userAttendanceLogs[$jindex])) {
  1964. if (isset($userAttendanceLogs[$jindex]->over_time) && $userAttendanceLogs[$jindex]->over_time != '0') {
  1965. $shift_date = $userAttendanceLogs[$jindex]->shift_date->sec;
  1966. $user_id = $user->id;
  1967. $logCalc = AttendanceHelper::logCalculator($user_id, $shift_date, $tenant_id);
  1968.  
  1969. $overtimesum = $logCalc['rosterOverTimeSec'];
  1970. // $overtimesum += strtotime($overtimedata);
  1971. $overtime++;
  1972. }
  1973. }
  1974. /* array_push($output[$index], $status); */
  1975. $jindex++;
  1976. } // my good loop
  1977. if ($overtime != 0) {
  1978. // $avgtime = $overtimesum / $overtime;
  1979. $finalavg = RandomHelper::sec2hms($overtimesum);
  1980. } else {
  1981. $avgtime = '0';
  1982. $finalavg = "0:00";
  1983. }
  1984. array_push($output[$index], $overtime);
  1985. array_push($output[$index], $finalavg);
  1986. $index++;
  1987. } // EOF foreach all user
  1988. $flag = true;
  1989. $cols = array(
  1990. 'Employee ID',
  1991. 'Name||Column displays the Name of the employees.',
  1992. 'Job Title||Column displays the Job Tittle of the particular employee.',
  1993. 'Department||Column displays the Department to which the employee belongs.',
  1994. 'No of Over Time Days||Column displays the total number of days when there is an overtime recorded in the attendance logs for the employee in the specified duration.',
  1995. 'Average Over Time||Column dsiplays the average amount of time by which an employee is working over time in the specified duration.'
  1996. );
  1997. $roster_type = "Overtime-Summary";
  1998. $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
  1999. $filenameexport = $roster_type . "_" . $date;
  2000.  
  2001. $final_output = array('output' => $output,
  2002. 'cols' => $cols,
  2003. 'filenameexport' => $filenameexport);
  2004. return $final_output;
  2005. }
  2006.  
  2007. // EOF function
  2008.  
  2009. /**
  2010. * Short description for function
  2011. *
  2012. * Long description (if any) ...
  2013. *
  2014. * @param array $post_data Parameter description (if any) ...
  2015. * @param unknown $tenant_id Parameter description (if any) ...
  2016. * @param unknown $from Parameter description (if any) ...
  2017. * @param unknown $to Parameter description (if any) ...
  2018. * @return array Return description (if any) ...
  2019. * @access public
  2020. * @static
  2021. */
  2022. public static function getWorkDurationSummaryRoster($post_data, $tenant_id = null, $from = null, $to = null) {
  2023.  
  2024. $return = array();
  2025. $output = array();
  2026. $finaldata = array();
  2027. $index = 0;
  2028. $totalDays = 0;
  2029.  
  2030. $filter = $post_data['filter_id'];
  2031. $begin = new DateTime($from);
  2032. $end = new DateTime($to);
  2033. $end = $end->modify('+1 day');
  2034. $interval = new DateInterval('P1D');
  2035. $daterange = new DatePeriod($begin, $interval, $end);
  2036. $from = strtotime($from);
  2037. $to = strtotime($to);
  2038. $criteria = new EMongoCriteria();
  2039. $criteria->shift_date('>=', new MongoDate($from));
  2040. $criteria->shift_date('<=', new MongoDate($to));
  2041.  
  2042.  
  2043. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  2044.  
  2045. foreach ($users as $key => $user) {
  2046. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  2047. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  2048. $user_post = $user->getCurrentPosition($tenant_id);
  2049. $job_title = $user_post['designation'];
  2050. $department = $user_post['department'];
  2051. $business_unit = $user_post['business_unit'];
  2052.  
  2053. $criteria->user_id = $user->id;
  2054. $userAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
  2055. // echo "<pre>"; print_r($userAttendanceLogs); exit("</pre> \n exited here ");
  2056. $total = 0;
  2057. $totaltime = 0;
  2058. $isholiday = 0;
  2059. $isweeklyoff = 0;
  2060. $jindex = 0;
  2061. $return = array();
  2062.  
  2063. $totalWorkDuration = 0;
  2064. $totalDays = 0;
  2065. $totalWorkedDays = 0;
  2066. $workingDaysCount = 0;
  2067. $totalWorkDurationSc = 0;
  2068. $totalWorkDurationTimeStamp = 0;
  2069.  
  2070. $output[] = array(
  2071. $employee_number,
  2072. $user_name,
  2073. $job_title,
  2074. $department,
  2075. );
  2076.  
  2077. foreach ($daterange as $date) {
  2078.  
  2079. if (isset($userAttendanceLogs[$jindex])) {
  2080. $status = $userAttendanceLogs[$jindex]->attendance_status;
  2081. if ($status == UserAttendance::ATTENDANCE_STATUS_ABSENT) {
  2082. $status = UserAttendanceLog::ATTENDANCE_STATUS_ABSENT;
  2083. } elseif ($status == UserAttendance::ATTENDANCE_STATUS_PRESENT) {
  2084. $status = UserAttendanceLog::ATTENDANCE_STATUS_PRESENT;
  2085. }
  2086. if ($status == UserAttendanceLog::ATTENDANCE_STATUS_PRESENT || $status == UserAttendanceLog::ATTENDANCE_STATUS_PENDING) {
  2087. if (isset($userAttendanceLogs[$jindex]->total_duration) && $userAttendanceLogs[$jindex]->total_duration != 0) {
  2088. $totalWorkDurationTimeStamp += $userAttendanceLogs[$jindex]->total_duration;
  2089. $workingDaysCount++;
  2090. $totalWorkedDays++;
  2091. }
  2092. }
  2093. }
  2094. $jindex++;
  2095. $totalDays++;
  2096. } // my good loop
  2097.  
  2098. if (isset($totalWorkDurationTimeStamp) && $workingDaysCount != 0) {
  2099. $totalWorkedHr = RandomHelper::sec2hms($totalWorkDurationTimeStamp);
  2100. $week = $totalDays / 7;
  2101. $weeklyAverageNo = $totalWorkDurationTimeStamp / $week;
  2102. $weeklyAverage = RandomHelper::sec2hms($weeklyAverageNo);
  2103. // echo "<pre>"; print_r($weeklyAverage); exit("</pre> \n exited here ");
  2104. $daillyAverage = $totalWorkDurationTimeStamp / $workingDaysCount;
  2105. $daillyAverage = RandomHelper::sec2hms($daillyAverage);
  2106. } else {
  2107. $totalWorkedHr = 0;
  2108. $weeklyAverage = 0;
  2109. $daillyAverage = 0;
  2110. }
  2111.  
  2112. array_push($output[$index], $totalWorkedHr);
  2113. array_push($output[$index], $weeklyAverage);
  2114. array_push($output[$index], $daillyAverage);
  2115.  
  2116.  
  2117.  
  2118. $index++;
  2119. // break;
  2120. } // EOF foreach all user
  2121.  
  2122. $cols = array(
  2123. 'Employee ID',
  2124. 'Name||Column displays the Name of the employees.',
  2125. 'Job Title||Column displays the Job Tittle of the particular employee.',
  2126. 'Department||Column displays the Department to which the employee belongs.',
  2127. 'Total worked hours||Column displays the total worked hours for the specified duration.',
  2128. 'Weekly Average||Column displays the weekly average work hours duration of the employee in the specified duration.',
  2129. 'Daily Average||Column displays the daily average work hours duration of the employee in the specified duration.'
  2130. );
  2131.  
  2132. $roster_type = "Work-Duration-Summary";
  2133. $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
  2134. $filenameexport = $roster_type . "_" . $date;
  2135.  
  2136. $final_output = array('output' => $output,
  2137. 'cols' => $cols,
  2138. 'filenameexport' => $filenameexport);
  2139. return $final_output;
  2140. }
  2141.  
  2142. // EOF function
  2143.  
  2144. /**
  2145. * Short description for function
  2146. *
  2147. * Long description (if any) ...
  2148. *
  2149. * @param array $post_data Parameter description (if any) ...
  2150. * @param unknown $tenant_id Parameter description (if any) ...
  2151. * @param unknown $from Parameter description (if any) ...
  2152. * @param unknown $to Parameter description (if any) ...
  2153. * @return array Return description (if any) ...
  2154. * @access public
  2155. * @static
  2156. */
  2157. public static function getLatemarkDateWiseRoster($post_data, $tenant_id = null, $from = null, $to = null) {
  2158. $return = array();
  2159. $index = 0;
  2160. $filter = $post_data['filter_id'];
  2161. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  2162. $output = array();
  2163. $finaldata = array();
  2164. $begin = new DateTime($from);
  2165. $end = new DateTime($to);
  2166. $end = $end->modify('+1 day');
  2167. $interval = new DateInterval('P1D');
  2168. $daterange = new DatePeriod($begin, $interval, $end);
  2169. $from = strtotime($from);
  2170. $to = strtotime($to);
  2171. $criteria = new EMongoCriteria();
  2172. foreach ($daterange as $date) {
  2173. $todaydate = strtotime($date->format("d-m-Y"));
  2174. $criteria->shift_date('==', new MongoDate($todaydate));
  2175. $criteria->coming_late_by('!=', null);
  2176. $UserAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
  2177.  
  2178. foreach ($UserAttendanceLogs as $logs) {
  2179. $userid = $logs->user_id;
  2180. $usermodel = UserMongo::model()->tenant($tenant_id)->findByPk($userid);
  2181. if (array_key_exists($usermodel->user_id, $users)) {
  2182. $user_name = $usermodel->getFullname();
  2183. $employee_number = (isset($usermodel['personal']['employee_no'])) ? $usermodel['personal']['employee_no'] : "N.A.";
  2184. $user_post = $usermodel->getCurrentPosition($tenant_id);
  2185. $job_title = $user_post['designation'];
  2186. $department = $user_post['department'];
  2187. $business_unit = $user_post['business_unit'];
  2188. $present = 0;
  2189. $absent = 0;
  2190. $weeklyoff_count = 0;
  2191. $holiday_count = 0;
  2192. $leave_count = 0;
  2193. $return = array();
  2194.  
  2195. $jindex = 0;
  2196.  
  2197. if (isset($logs) && $logs != null) {
  2198. if (isset($logs->coming_late_by) && $logs->coming_late_by != null) {
  2199. if (isset($logs->punchin_timestamp->sec) && $logs->punchin_timestamp->sec != null) {
  2200. $punchin_timestamp = (isset($logs->punchin_timestamp->sec) && $logs->punchin_timestamp->sec != null) ? date("H:i", $logs->punchin_timestamp->sec) : "-";
  2201. } else {
  2202. $punchin_timestamp = (isset($logs->punchin_timestamp) && $logs->punchin_timestamp != null) ? date("H:i", $logs->punchin_timestamp) : "-";
  2203. }
  2204. if (isset($logs->punchout_timestamp->sec) && $logs->punchout_timestamp->sec != null) {
  2205. $punchout_timestamp = (isset($logs->punchout_timestamp->sec) && $logs->punchout_timestamp->sec != null) ? date("H:i", $logs->punchout_timestamp->sec) : "-";
  2206. } else {
  2207. if (!is_object($logs->punchout_timestamp)) {
  2208. $punchout_timestamp = (isset($logs->punchout_timestamp) && $logs->punchout_timestamp != null) ? date("H:i", $logs->punchout_timestamp) : "-";
  2209. }
  2210. }
  2211. $coming_late_bydata = (isset($logs->coming_late_by) && $logs->coming_late_by != null) ? $logs->coming_late_by : "-";
  2212. $coming_late_by = str_replace('.', ':', $coming_late_bydata);
  2213. $new_come_late = explode(":", $coming_late_by);
  2214. if(isset($new_come_late[0],$new_come_late[1]) && ($new_come_late[0] < 10 || $new_come_late[1] < 10))
  2215. {
  2216. $new_come_late_hrs = ($new_come_late[0] < 10) ? "0".$new_come_late[0] : $new_come_late[0];
  2217. $new_come_late_mins = ($new_come_late[1] < 10) ? "0".$new_come_late[1] : $new_come_late[1];
  2218. $coming_late_by = $new_come_late_hrs . ":".$new_come_late_mins;
  2219. }
  2220. // $date = date("d", $logs->shift_date->sec);
  2221. } else {
  2222. $punchin_timestamp = "-";
  2223. $punchout_timestamp = "-";
  2224. $coming_late_by = "-";
  2225. }
  2226. $attdate = date("d-M-Y", $logs->shift_date->sec);
  2227. $attdateday = date("l", $logs->shift_date->sec);
  2228. /* $attdate = $attdateonly.','. $attdateday; */
  2229. $output[] = array($attdate);
  2230. // array_push($output[$index], $attdate);
  2231. array_push($output[$index], $attdateday);
  2232. array_push($output[$index], $employee_number);
  2233. array_push($output[$index], $user_name);
  2234. array_push($output[$index], $job_title);
  2235. array_push($output[$index], $department);
  2236. array_push($output[$index], $punchin_timestamp);
  2237. array_push($output[$index], $punchout_timestamp);
  2238. array_push($output[$index], $coming_late_by);
  2239. }
  2240.  
  2241. $index++;
  2242. }//check users if
  2243. } // EOF foreach for all logs
  2244. } // EOF foreach all date
  2245. $flag = true;
  2246. $cols = array(
  2247. 'Date||Column displays all the Dates selected in the specified duration.',
  2248. 'Day||Column displays the Particular Day corresponding to the date.',
  2249. 'Employee ID',
  2250. 'Name||Column displays the Name of the employees.',
  2251. 'Job Title||Column displays the Job Tittle of the particular employee.',
  2252. 'Department||Column displays the Department to which the employee belongs.',
  2253. 'Punch In Time||Column displays the Time when the employee is suppose to start his Shift.',
  2254. 'Punch Out Time||Column displays the Time at which the particular employee started his Shift.',
  2255. 'Coming Late By||Column displays the Time by which the employee was late by on the particular date.'
  2256. );
  2257.  
  2258. $roster_type = "LateMark-Datewise";
  2259. $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
  2260. $filenameexport = $roster_type . "_" . $date;
  2261. $final_output = array('output' => $output,
  2262. 'cols' => $cols,
  2263. 'filenameexport' => $filenameexport);
  2264. return $final_output;
  2265. }
  2266.  
  2267. // EOF function
  2268.  
  2269. /**
  2270. * Short description for function
  2271. *
  2272. * Long description (if any) ...
  2273. *
  2274. * @param array $post_data Parameter description (if any) ...
  2275. * @param unknown $tenant_id Parameter description (if any) ...
  2276. * @param unknown $from Parameter description (if any) ...
  2277. * @param unknown $to Parameter description (if any) ...
  2278. * @return array Return description (if any) ...
  2279. * @access public
  2280. * @static
  2281. */
  2282. public static function getAbsenteesDatewiseRoster($post_data, $tenant_id = null, $from = null, $to = null) {
  2283. $return = array();
  2284. $index = 0;
  2285. $filter = $post_data['filter_id'];
  2286. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  2287. $output = array();
  2288. $finaldata = array();
  2289. $begin = new DateTime($from);
  2290. $end = new DateTime($to);
  2291. $end = $end->modify('+1 day');
  2292. $interval = new DateInterval('P1D');
  2293. $daterange = new DatePeriod($begin, $interval, $end);
  2294. $from = strtotime($from);
  2295. $to = strtotime($to);
  2296. $criteria = new EMongoCriteria();
  2297. foreach ($daterange as $date) {
  2298. $todaydate = strtotime($date->format("d-m-Y"));
  2299. $criteria->shift_date('==', new MongoDate($todaydate));
  2300. $userAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
  2301. foreach ($userAttendanceLogs as $logs) {
  2302. $status = $logs->attendance_status;
  2303. if ($status == UserAttendanceLog::ATTENDANCE_STATUS_ABSENT && $status == UserAttendance::ATTENDANCE_STATUS_ABSENT) { // echo "<pre>"; print_r($status);
  2304. $weeklyoff = $logs->is_weekly_off->status;
  2305. $leave = $logs->in_leave->status;
  2306. $holiday = $logs->is_holiday->status;
  2307. if (is_null($weeklyoff) || $weeklyoff == IsWeeklyOff::WEEKLYOFF_YES) {
  2308. continue;
  2309. } elseif (is_null($leave) || $leave == InLeave::INLEAVE_YES) {
  2310. continue;
  2311. } elseif (is_null($holiday) || $holiday == IsHoliday::HOLIDAY_YES) {
  2312. continue;
  2313. } else {
  2314.  
  2315.  
  2316. $userid = $logs->user_id;
  2317. $usermodel = UserMongo::model()->tenant($tenant_id)->findByPk($userid);
  2318. if (array_key_exists($usermodel->user_id, $users)) {
  2319. $employee_id = (isset($usermodel->personal->employee_no)) ? $usermodel->personal->employee_no : "N.A.";
  2320. $user_name = $usermodel->getFullname();
  2321. $user_post = $usermodel->getCurrentPosition($tenant_id);
  2322. $job_title = (isset($user_post['designation']) && $user_post['designation'] != null) ? $user_post['designation'] : "-";
  2323. $department = (isset($user_post['department']) && $user_post['department'] != null) ? $user_post['department'] : "-";
  2324. $business_unit = (isset($user_post['business_unit']) && $user_post['business_unit'] != null) ? $user_post['business_unit'] : "-";
  2325. $present = 0;
  2326. $absent = 0;
  2327. $weeklyoff_count = 0;
  2328. $holiday_count = 0;
  2329. $leave_count = 0;
  2330. $return = array();
  2331. $jindex = 0;
  2332. $attdate = date("d-M-Y", $logs->shift_date->sec);
  2333. $attdateday = date("l", $logs->shift_date->sec);
  2334. /* $attdate = $attdateonly.','. $attdateday; */
  2335. $output[] = array($attdate);
  2336. array_push($output[$index], $attdateday);
  2337. array_push($output[$index], $employee_id);
  2338. array_push($output[$index], $user_name);
  2339. array_push($output[$index], $job_title);
  2340. array_push($output[$index], $department);
  2341. $index++;
  2342. }
  2343. }
  2344. } // EOF user if
  2345. } // EOF foreach logs
  2346. } // EOF foreach all date
  2347. $flag = true;
  2348. $cols = array(
  2349. 'Date||Column displays all the Dates selected in the specified duration.',
  2350. 'Day||Column displays the Particular Day corresponding to the date.',
  2351. 'Employee ID||Employee id',
  2352. 'Name||Column displays the Name of the employees.',
  2353. 'Job Title||Column displays the Job Tittle of the particular employee.',
  2354. 'Department||Column displays the Department to which the employee belongs.'
  2355. );
  2356.  
  2357. $roster_type = "Absentees-Datewise-Summary";
  2358. $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
  2359. $filenameexport = $roster_type . "_" . $date;
  2360. $final_output = array('output' => $output,
  2361. 'cols' => $cols,
  2362. 'filenameexport' => $filenameexport);
  2363. return $final_output;
  2364. }
  2365.  
  2366. // EOF function
  2367.  
  2368. /**
  2369. * Short description for function
  2370. *
  2371. * Long description (if any) ...
  2372. *
  2373. * @param array $post_data Parameter description (if any) ...
  2374. * @param unknown $tenant_id Parameter description (if any) ...
  2375. * @param unknown $from Parameter description (if any) ...
  2376. * @param unknown $to Parameter description (if any) ...
  2377. * @return array Return description (if any) ...
  2378. * @access public
  2379. * @static
  2380. */
  2381. public static function getLateMarksSummaryRoster($post_data, $tenant_id = null, $from = null, $to = null) {
  2382.  
  2383. $return = array();
  2384. $index = 0;
  2385. $output = array();
  2386. $finaldata = array();
  2387.  
  2388. $filter = $post_data['filter_id'];
  2389. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  2390.  
  2391. $begin = new DateTime($from);
  2392. $end = new DateTime($to);
  2393. $end = $end->modify('+1 day');
  2394. $interval = new DateInterval('P1D');
  2395. $daterange = new DatePeriod($begin, $interval, $end);
  2396. $from = strtotime($from);
  2397. $to = strtotime($to);
  2398.  
  2399. $criteria = new EMongoCriteria();
  2400. $criteria->shift_date('>=', new MongoDate($from));
  2401. $criteria->shift_date('<=', new MongoDate($to));
  2402.  
  2403. foreach ($users as $key => $user) {
  2404.  
  2405. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  2406. $user_post = $user->getCurrentPosition($tenant_id);
  2407. $job_title = $user_post['designation'];
  2408. $department = $user_post['department'];
  2409. $business_unit = $user_post['business_unit'];
  2410. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  2411. $criteria->user_id = $user->id;
  2412. $userAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
  2413.  
  2414. $present = 0;
  2415. $absent = 0;
  2416. $comingLateCounter = 0;
  2417. $weeklyoff_count = 0;
  2418. $holiday_count = 0;
  2419. $leave_count = 0;
  2420. $cominglatetotal = 0;
  2421. $punchintimetotal = 0;
  2422. $punchInCounter = 0;
  2423. $jindex = 0;
  2424. $timeInTotalSec = 0;
  2425. $punchInTimeStamp = 0;
  2426. $avgLateBy = 0;
  2427. $comingLateBy = 0;
  2428. $return = array();
  2429.  
  2430. $output[] = array(
  2431. $employee_number,
  2432. $user_name,
  2433. $job_title,
  2434. $department,
  2435. );
  2436.  
  2437. foreach ($daterange as $date) {
  2438. if (isset($userAttendanceLogs[$jindex])) {
  2439. if (isset($userAttendanceLogs[$jindex]->punchin_timestamp->sec) && $userAttendanceLogs[$jindex]->punchin_timestamp->sec != null) {
  2440. $shift_date = $userAttendanceLogs[$jindex]->shift_date->sec;
  2441. $user_id = $user->id;
  2442. $logCalc = AttendanceHelper::logCalculator($user_id, $shift_date, $tenant_id);
  2443. // $comingLateBy += $logCalc["rosterLateBySec"];
  2444. // echo "<pre>"; print_r($logCalc); exit("</pre> \n exited here \n");
  2445. $punchInTimeStamp += $logCalc["rosterClockInSec"];
  2446. // echo "<pre>"; print_r($punchInTimeStamp); exit("</pre> \n exited here ");
  2447. $punchInCounter++;
  2448. }
  2449.  
  2450.  
  2451. if (isset($userAttendanceLogs[$jindex]->coming_late_by) && $userAttendanceLogs[$jindex]->coming_late_by != null) {
  2452. /* $shift_date = $userAttendanceLogs[$jindex]->shift_date->sec;
  2453. $user_id = $user->id;
  2454. $logCalc = AttendanceHelper::logCalculator($user_id,$shift_date,$tenant_id); */
  2455. if (isset($logCalc["rosterLateBySec"])) {
  2456.  
  2457. $comingLateBy += $logCalc["rosterLateBySec"];
  2458. $comingLateCounter++;
  2459. }
  2460. // echo "<pre>"; print_r($logCalc); exit("</pre> \n exited here \n");
  2461. }
  2462. }
  2463. $jindex++;
  2464. } // my good loop
  2465.  
  2466. if (isset($comingLateBy) && $comingLateCounter != 0) {
  2467. $avgLateBy = $comingLateBy / $comingLateCounter;
  2468. $avgLateBy = RandomHelper::sec2hms($avgLateBy);
  2469. } else {
  2470. $avgLateBy = "00:00";
  2471. }
  2472.  
  2473. if (isset($punchInTimeStamp) && $punchInCounter != 0) {
  2474. $avgPunchInTimeSec = $punchInTimeStamp / $punchInCounter;
  2475. $avgPunchInTime = RandomHelper::sec2hms($avgPunchInTimeSec);
  2476. } else {
  2477. $avgpunchintime = 0;
  2478. $avgPunchInTime = '00:00';
  2479. }
  2480. array_push($output[$index], $comingLateCounter);
  2481. array_push($output[$index], $avgLateBy);
  2482. array_push($output[$index], $avgPunchInTime);
  2483.  
  2484. $index++;
  2485. // break;
  2486. } // EOF foreach all user
  2487. $flag = true;
  2488. $cols = array(
  2489. 'Employee ID ||Column to display employee id',
  2490. 'Name||Column displays the Name of the employees.',
  2491. 'Job Title||Column displays the Job Tittle of the particular employee.',
  2492. 'Department||Column displays the Department to which the employee belongs.',
  2493. 'No Of Late Mark Days||Column displays the the total number of days when the employees attendance logs show clock-in time more than grace time specified in policy.',
  2494. 'Average Late By||Column displays what is the average duration by which an employee is late by in the specified duration.',
  2495. 'Average Clock In Time||Column displays the average clock-in time of the employee for the specified duration.'
  2496. );
  2497. $roster_type = "Latemark-Summary";
  2498. $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
  2499. $filenameexport = $roster_type . "_" . $date;
  2500.  
  2501. $final_output = array('output' => $output,
  2502. 'cols' => $cols,
  2503. 'filenameexport' => $filenameexport);
  2504. return $final_output;
  2505. }
  2506.  
  2507. //EOF function
  2508.  
  2509. /**
  2510. * Short description for function
  2511. *
  2512. * Long description (if any) ...
  2513. *
  2514. * @param array $post_data Parameter description (if any) ...
  2515. * @param unknown $tenant_id Parameter description (if any) ...
  2516. * @param unknown $from Parameter description (if any) ...
  2517. * @param unknown $to Parameter description (if any) ...
  2518. * @return array Return description (if any) ...
  2519. * @access public
  2520. * @static
  2521. */
  2522. public static function getEarlyClockOutSummaryRoster($post_data, $tenant_id = null, $from = null, $to = null) {
  2523. $return = array();
  2524. $index = 0;
  2525. $output = array();
  2526. $finaldata = array();
  2527.  
  2528. $filter = $post_data['filter_id'];
  2529. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  2530.  
  2531. $begin = new DateTime($from);
  2532. $end = new DateTime($to);
  2533. $end = $end->modify('+1 day');
  2534. $interval = new DateInterval('P1D');
  2535. $daterange = new DatePeriod($begin, $interval, $end);
  2536. $from = strtotime($from);
  2537. $to = strtotime($to);
  2538.  
  2539. $criteria = new EMongoCriteria();
  2540. $criteria->shift_date('>=', new MongoDate($from));
  2541. $criteria->shift_date('<=', new MongoDate($to));
  2542.  
  2543. foreach ($users as $key => $user) {
  2544.  
  2545. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  2546. $user_post = $user->getCurrentPosition($tenant_id);
  2547. $job_title = $user_post['designation'];
  2548. $department = $user_post['department'];
  2549. $business_unit = $user_post['business_unit'];
  2550. $criteria->user_id = $user->id;
  2551. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  2552. $userAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
  2553.  
  2554. $present = 0;
  2555. $absent = 0;
  2556. $goingearly = 0;
  2557. $weeklyoff_count = 0;
  2558. $holiday_count = 0;
  2559. $leave_count = 0;
  2560. $goingearlytotal = 0;
  2561. $totalpunchout = 0;
  2562. $punchouttimetotal = 0;
  2563. $return = array();
  2564. $output[] = array(
  2565. $employee_number,
  2566. $user_name,
  2567. $job_title,
  2568. $department,
  2569. );
  2570. foreach ($userAttendanceLogs as $userAttendanceLog) {
  2571. if (isset($userAttendanceLog)) {
  2572. if (isset($userAttendanceLog->shift_date->sec)) {
  2573.  
  2574. $shift_date = $userAttendanceLog->shift_date->sec;
  2575. $user_id = $user->id;
  2576. $logCalc = AttendanceHelper::logCalculator($user_id, $shift_date, $tenant_id);
  2577. // echo "<pre>"; print_r($logCalc); exit("</pre> \n exited here ");
  2578. if (isset($userAttendanceLog->punchout_time) && $userAttendanceLog->punchout_time != null) {
  2579. $punchouttimetotal += $logCalc["rosterClockOutSec"];
  2580. $totalpunchout++;
  2581. }
  2582.  
  2583. if (!empty($logCalc["total_duration"])) {
  2584. if ($logCalc["total_duration"] < $logCalc["rosterShiftSeconds"]) {
  2585. $goingearlytotal += $logCalc["rosterShiftSeconds"] - $logCalc["total_duration"];
  2586. $goingearly++;
  2587. }
  2588. }
  2589. }
  2590. }
  2591. } // my good loop
  2592. if (isset($goingearlytotal) && $goingearlytotal != 0) {
  2593.  
  2594. $avgtime = $goingearlytotal / $goingearly;
  2595.  
  2596. $finalavg = RandomHelper::sec2hms($avgtime);
  2597. //echo "<pre>"; print_r($avgtime); exit("</pre> \n exited here");
  2598. } else {
  2599. $avgtime = 0;
  2600. $finalavg = '00:00';
  2601. }
  2602. if (isset($punchouttimetotal) && $punchouttimetotal != 0) {
  2603. // $totalpunchoutdur = date('H.i', $punchouttimetotal);
  2604. $avgpunchouttime = $punchouttimetotal / $totalpunchout;
  2605. $finalavgpunchout = RandomHelper::sec2hms($avgpunchouttime);
  2606.  
  2607. // echo "<pre>"; print_r($finalavgpunchin); exit("</pre> \n exited here");
  2608. } else {
  2609.  
  2610. $finalavgpunchout = '00:00';
  2611. }
  2612. array_push($output[$index], $goingearly);
  2613. array_push($output[$index], $finalavg);
  2614. array_push($output[$index], $finalavgpunchout);
  2615. $index++;
  2616. // break;
  2617. } // EOF foreach all user
  2618. $flag = true;
  2619. $cols = array(
  2620. 'Employee ID||Column to display Employee id',
  2621. 'Name||Column displays the Name of the employees.',
  2622. 'Job Title||Column displays the Job Tittle of the particular employee.',
  2623. 'Department||Column displays the Department to which the employee belongs.',
  2624. 'No Of Early Clock Out Days||Column displays the Number of days the employee has clocked out early.',
  2625. 'Average Of Early Clock Out||Column displays the average by which an employee clocks out early in the specified duration.',
  2626. 'Average Of Clock Out Time||Column displays a simple average of the clock-out times recorded for the specified duration.'
  2627. );
  2628. $roster_type = "Early-Clockout-Summary";
  2629. $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
  2630. $filenameexport = $roster_type . "_" . $date;
  2631.  
  2632. $final_output = array('output' => $output,
  2633. 'cols' => $cols,
  2634. 'filenameexport' => $filenameexport);
  2635. return $final_output;
  2636. }
  2637.  
  2638. //EOF function
  2639.  
  2640. /**
  2641. * Short description for function
  2642. *
  2643. * Long description (if any) ...
  2644. *
  2645. * @param array $post_data Parameter description (if any) ...
  2646. * @param unknown $tenant_id Parameter description (if any) ...
  2647. * @param unknown $from Parameter description (if any) ...
  2648. * @param unknown $to Parameter description (if any) ...
  2649. * @return array Return description (if any) ...
  2650. * @access public
  2651. * @static
  2652. */
  2653. public static function getEarlyClockOutDatewiseRoster($post_data, $tenant_id = null, $from = null, $to = null) {
  2654. $return = array();
  2655. $output = array();
  2656. $finaldata = array();
  2657. $index = 0;
  2658. $filter = $post_data['filter_id'];
  2659. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  2660. //echo "<pre>"; print_r($users); exit("</pre> \n exited here");
  2661.  
  2662. $begin = new DateTime($from);
  2663. $end = new DateTime($to);
  2664. $end = $end->modify('+1 day');
  2665. $interval = new DateInterval('P1D');
  2666. $daterange = new DatePeriod($begin, $interval, $end);
  2667. $from = strtotime($from);
  2668. $to = strtotime($to);
  2669.  
  2670. $criteria = new EMongoCriteria();
  2671. foreach ($daterange as $date) {
  2672. $todaydate = strtotime($date->format("d-m-Y"));
  2673. $criteria->shift_date('==', new MongoDate($todaydate));
  2674. // $criteria->going_early_by('!=', null);
  2675. $UserAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
  2676.  
  2677. foreach ($UserAttendanceLogs as $logs) {
  2678. $userid = $logs->user_id;
  2679. $usermodel = UserMongo::model()->tenant($tenant_id)->findByPk($userid);
  2680.  
  2681. if (array_key_exists($usermodel->user_id, $users)) {
  2682.  
  2683. $user_name = $usermodel->getFullname();
  2684. $user_post = $usermodel->getCurrentPosition($tenant_id);
  2685. $job_title = $user_post['designation'];
  2686. $department = $user_post['department'];
  2687. $business_unit = $user_post['business_unit'];
  2688. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  2689. $present = 0;
  2690. $absent = 0;
  2691. $weeklyoff_count = 0;
  2692. $holiday_count = 0;
  2693. $leave_count = 0;
  2694. $jindex = 0;
  2695. $return = array();
  2696.  
  2697. $shift_date = $logs->shift_date->sec;
  2698. $user_id = $usermodel->id;
  2699. $logCalc = AttendanceHelper::logCalculator($user_id, $shift_date, $tenant_id);
  2700. if (!empty($logCalc["total_duration"])) {
  2701. if ($logCalc["total_duration"] < $logCalc["rosterShiftSeconds"]) {
  2702. if (isset($logs->shift_planner)) {
  2703. $begin_time = date("H:i", $logCalc["rosterShiftBegin"]);
  2704. $end_time = date("H:i", $logCalc["rosterShiftEnd"]);
  2705. $going_early_by = $logCalc["rosterShiftSeconds"] - $logCalc["total_duration"];
  2706. $going_early_by = RandomHelper::sec2hms($going_early_by);
  2707. } else {
  2708. $begin_time = "-";
  2709. $end_time = "-";
  2710. }
  2711.  
  2712. // $going_early_bydata = (isset($logs->going_early_by) && $logs->going_early_by != null) ? $logs->going_early_by : "-";
  2713. // $going_early_by = str_replace('.', ':', $going_early_bydata);
  2714. $attdate = date("d-M-Y", $logs->shift_date->sec);
  2715. $attdateday = date("l", $logs->shift_date->sec);
  2716. $output[] = array($attdate);
  2717.  
  2718. array_push($output[$index], $employee_number);
  2719. array_push($output[$index], $attdateday);
  2720. array_push($output[$index], $user_name);
  2721. array_push($output[$index], $job_title);
  2722. array_push($output[$index], $department);
  2723. array_push($output[$index], $begin_time);
  2724. array_push($output[$index], $end_time);
  2725. array_push($output[$index], $going_early_by);
  2726. $index++;
  2727. }
  2728. }
  2729. } // EOF foreach for all logs
  2730. }
  2731. } // EOF foreach all date
  2732. $flag = true;
  2733. $cols = array(
  2734. 'Employee ID ||Column to display Employee id ',
  2735. 'Date||Column displays all the Dates selected in the specified duration.',
  2736. 'Day||Column displays the Particular Day corresponding to the date.',
  2737. 'Name||Column displays the Name of the employees.',
  2738. 'Job Title||Column displays the Job Tittle of the particular employee.',
  2739. 'Department||Column displays the Department to which the employee belongs.',
  2740. 'Shift Begin Time||Column displays the Time when the employee shift starts.',
  2741. 'Shift End Time||Column displays the Time when the employee shift ',
  2742. 'Going Early By||Column displays the Time by which the employee is leaving early than the stipulated time.'
  2743. );
  2744.  
  2745. $roster_type = "Early-Clockout-Datewise-Summary";
  2746. $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
  2747. $filenameexport = $roster_type . "_" . $date;
  2748. $final_output = array('output' => $output,
  2749. 'cols' => $cols,
  2750. 'filenameexport' => $filenameexport);
  2751. return $final_output;
  2752. }
  2753.  
  2754. // EOF function
  2755.  
  2756. /**
  2757. * Short description for function
  2758. *
  2759. * Long description (if any) ...
  2760. *
  2761. * @param array $post_data Parameter description (if any) ...
  2762. * @param unknown $tenant_id Parameter description (if any) ...
  2763. * @param unknown $from Parameter description (if any) ...
  2764. * @param unknown $to Parameter description (if any) ...
  2765. * @return array Return description (if any) ...
  2766. * @access public
  2767. * @static
  2768. */
  2769. public static function getOverTimeDatewiseRoster($post_data, $tenant_id = null, $from = null, $to = null) {
  2770. $return = array();
  2771. $index = 0;
  2772. $filter = $post_data['filter_id'];
  2773. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  2774. $output = array();
  2775. $finaldata = array();
  2776. $begin = new DateTime($from);
  2777. $end = new DateTime($to);
  2778. $end = $end->modify('+1 day');
  2779. $interval = new DateInterval('P1D');
  2780. $daterange = new DatePeriod($begin, $interval, $end);
  2781. $from = strtotime($from);
  2782. $to = strtotime($to);
  2783. $criteria = new EMongoCriteria();
  2784. foreach ($daterange as $date) {
  2785. $todaydate = strtotime($date->format("d-m-Y"));
  2786. $criteria->shift_date('==', new MongoDate($todaydate));
  2787. $criteria->over_time('!=', 0);
  2788. $UserAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
  2789.  
  2790. foreach ($UserAttendanceLogs as $logs) {
  2791. $userid = $logs->user_id;
  2792. $usermodel = UserMongo::model()->tenant($tenant_id)->findByPk($userid);
  2793. if (array_key_exists($usermodel->user_id, $users)) {
  2794. $user_name = $usermodel->getFullname();
  2795. $user_post = $usermodel->getCurrentPosition($tenant_id);
  2796. $job_title = $user_post['designation'];
  2797. $department = $user_post['department'];
  2798. $business_unit = $user_post['business_unit'];
  2799. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  2800. $present = 0;
  2801. $absent = 0;
  2802. $weeklyoff_count = 0;
  2803. $holiday_count = 0;
  2804. $leave_count = 0;
  2805. $return = array();
  2806.  
  2807. $jindex = 0;
  2808.  
  2809. if (isset($logs)) {
  2810. if (isset($logs->shift_planner)) {
  2811. $timestamp = $logs->shift_date->sec;
  2812. $logs->shift_date->sec;
  2813. $data = UserShiftPlanner::getUserShift($usermodel->id, $timestamp, $tenant_id);
  2814. $shift_obj = TenantShift::getTenantShift($data['shift_id'], $tenant_id);
  2815. $begin_time = (isset($shift_obj->begin_time) && $shift_obj->begin_time != null) ? $shift_obj->begin_time : null;
  2816. $new_come_begin_time = explode(":", $begin_time);
  2817. if(isset($new_come_begin_time[0],$new_come_begin_time[1]) && ($new_come_begin_time[0] < 10 || $new_come_begin_time[1] < 10))
  2818. {
  2819. $new_come_begin_time_hrs = ($new_come_begin_time[0] < 10) ? "0".$new_come_begin_time[0] : $new_come_begin_time[0];
  2820. $new_come_begin_time_mins = ($new_come_begin_time[1] < 10) ? "0".$new_come_begin_time[1] : $new_come_begin_time[1];
  2821. $begin_time = $new_come_begin_time_hrs . ":".$new_come_begin_time_mins;
  2822. }
  2823. $end_time = (isset($shift_obj->end_time) && $shift_obj->end_time != null) ? $shift_obj->end_time : null;
  2824. $new_come_end_time = explode(":", $end_time);
  2825. if(isset($new_come_end_time[0],$new_come_end_time[1]) && ($new_come_end_time[0] < 10 || $new_come_end_time[1] < 10))
  2826. {
  2827. $new_come_end_time_hrs = ($new_come_end_time[0] < 10) ? "0".$new_come_end_time[0] : $new_come_end_time[0];
  2828. $new_come_end_time_mins = ($new_come_end_time[1] < 10) ? "0".$new_come_end_time[1] : $new_come_end_time[1];
  2829. $end_time = $new_come_end_time_hrs . ":".$new_come_end_time_mins;
  2830. }
  2831. } else {
  2832. $begin_time = "-";
  2833. $end_time = "-";
  2834. }
  2835. $over_time = (isset($logs->over_time) && $logs->over_time != null) ? $logs->over_time : "-";
  2836. $attdate = date("d-M-Y", $logs->shift_date->sec);
  2837. $attdateday = date("l", $logs->shift_date->sec);
  2838. /* $attdate = $attdateonly.','. $attdateday; */
  2839. $output[] = array($attdate);
  2840. // array_push($output[$index], $attdate);
  2841. array_push($output[$index], $employee_number);
  2842. array_push($output[$index], $attdateday);
  2843. array_push($output[$index], $user_name);
  2844. array_push($output[$index], $job_title);
  2845. array_push($output[$index], $department);
  2846. array_push($output[$index], $begin_time);
  2847. array_push($output[$index], $end_time);
  2848. array_push($output[$index], $over_time);
  2849. }
  2850.  
  2851. $index++;
  2852. } //EOF user IF
  2853. } // EOF foreach for all logs
  2854. } // EOF foreach all date
  2855. $flag = true;
  2856. $cols = array(
  2857. 'Employee ID ||Column to display employee ',
  2858. 'Date||Column displays all the Dates selected in the specified duration.',
  2859. 'Day||Column displays the Particular Day corresponding to the date.',
  2860. 'Name||Column displays the Name of the employees.',
  2861. 'Job Title||Column displays the Job Tittle of the particular employee.',
  2862. 'Department||Column displays the Department to which the employee belongs.',
  2863. 'Shift Begin Time||Column displays the Time when the employee shift starts.',
  2864. 'Shift End Time||Column displays the Time when the employee shift ',
  2865. 'Over Time Duration||Column displays the Time by which the employee is doing overtime on that particular day.'
  2866. );
  2867.  
  2868. $roster_type = "Overtime-Datewise-Summary";
  2869. $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
  2870. $filenameexport = $roster_type . "_" . $date;
  2871. $final_output = array('output' => $output,
  2872. 'cols' => $cols,
  2873. 'filenameexport' => $filenameexport);
  2874. return $final_output;
  2875. }
  2876.  
  2877. // EOF function
  2878.  
  2879. /**
  2880. * Short description for function
  2881. *
  2882. * Long description (if any) ...
  2883. *
  2884. * @param array $post_data Parameter description (if any) ...
  2885. * @param unknown $tenant_id Parameter description (if any) ...
  2886. * @return array Return description (if any) ...
  2887. * @access public
  2888. * @static
  2889. */
  2890. public static function getAttendanceRoster($post_data, $tenant_id = null) {
  2891. $return = array();
  2892. //$sr_no=1;
  2893. $filter = $post_data['filter_id'];
  2894. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  2895. // echo "<pre>"; print_r($users); exit("</pre> \n exited here ");
  2896. $output = array();
  2897. foreach ($users as $key => $user) {
  2898. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  2899. $user_post = $user->getCurrentPosition($tenant_id);
  2900. $job_title = $user_post['designation'];
  2901. $department = $user_post['department'];
  2902. $business_unit = $user_post['business_unit'];
  2903. $date = strtotime(date('Y-m-d'));
  2904. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  2905. $userShift = UserShift::getUserShift($user->id, $user->tenant_id);
  2906. if (!empty($userShift)) {
  2907. if ($userShift['type'] == UserShift::ROTATING_SHIFT) {
  2908. $userShift = UserShiftPlanner::getUserShift($user->id, $date, $user->tenant_id);
  2909. $weekly_obj = WeeklyOff::getWeeklyOff($userShift['weekly_off_id'], $user->tenant_id);
  2910. } else {
  2911. $get_weekly_obj = UserWeeklyOff::getUserWeeklyOffByUserId($user->id, $user->tenant_id);
  2912. if (isset($get_weekly_obj->weekly_off_id)) {
  2913. $weekly_obj = WeeklyOff::getWeeklyOff($get_weekly_obj->weekly_off_id, $user->tenant_id);
  2914. } else {
  2915. $weekly_obj = "";
  2916. }
  2917. }
  2918.  
  2919. // echo "<pre>"; print_r($weekly_obj); echo("</pre>"); exit();
  2920. $weekly_name = (isset($weekly_obj->weekly_off_name)) ? $weekly_obj->weekly_off_name : "";
  2921. $shift_obj = TenantShift::getTenantShift($userShift['shift_id'], $user->tenant_id);
  2922. $shift_name = (isset($shift_obj->shift_name)) ? $shift_obj->shift_name : "";
  2923. $policy_obj = AttendancePolicy::getAttendancePolicy($userShift['policy_id'], $user->tenant_id);
  2924. $policy_name = (isset($policy_obj->policy_name)) ? $policy_obj->policy_name : "";
  2925. if (isset($userShift['clocking_priority']['clocking_priority'])) {
  2926. switch ($userShift['clocking_priority']['clocking_priority']) {
  2927. case 0:
  2928. $clocking_priority = "Web";
  2929. break;
  2930. case 1:
  2931. $clocking_priority = "Hardware";
  2932. break;
  2933.  
  2934. default:
  2935. $clocking_priority = "Web";
  2936. break;
  2937. }
  2938. }
  2939. /**/
  2940. if(isset($userShift->controls['clocking_warning']) && $userShift->controls['clocking_warning'] == 1)
  2941. {
  2942. $clocking_warning_check = "ON";
  2943. }
  2944. else{
  2945. $clocking_warning_check = "OFF";
  2946. }
  2947. if(isset($userShift->controls['absent_warning']) && $userShift->controls['absent_warning'] == 1)
  2948. {
  2949. $absent_warning_check = "ON";
  2950. }
  2951. else{
  2952. $absent_warning_check = "OFF";
  2953. }
  2954.  
  2955.  
  2956. if ($userShift->clocking_priority->clocking_priority == 0 && !empty($userShift->ip_restriction)) {
  2957. $all_names = "";
  2958. if (!is_array($userShift->ip_restriction)) {
  2959. $userShift->ip_restriction = array($userShift->ip_restriction);
  2960. }
  2961. foreach ($userShift->ip_restriction as $key => $restriction) {
  2962. $ip_name = AttendanceIp::getNameById($restriction);
  2963. $ip_only_name = $ip_name['name'];
  2964. $new_array[$restriction]['name'] = $ip_name['name'];
  2965. $new_array[$restriction]['ip_from'] = $ip_name['ip_from'];
  2966. $new_array[$restriction]['ip_to'] = (isset($ip_name['ip_to']) && $ip_name['ip_to'] != "") ? $ip_name['ip_to'] : "N.A.";
  2967. $all_names = $all_names . $ip_only_name . ", ";
  2968. }
  2969. $all_names = substr_replace($all_names, "", -2);
  2970. }
  2971. else{
  2972. $all_names = "N.A.";
  2973. }
  2974. /**/
  2975. } // EOF empty if check
  2976. else {
  2977. $get_weekly_obj = UserWeeklyOff::getUserWeeklyOffByUserId($user->id, $user->tenant_id);
  2978. if (isset($get_weekly_obj->weekly_off_id)) {
  2979. $weekly_obj = WeeklyOff::getWeeklyOff($get_weekly_obj->weekly_off_id, $user->tenant_id);
  2980. $weekly_name = (isset($weekly_obj->weekly_off_name)) ? $weekly_obj->weekly_off_name : "";
  2981. } else {
  2982. $weekly_obj = "";
  2983. $weekly_name = "";
  2984. }
  2985. $shift_name = "";
  2986. $policy_name = "";
  2987. // $weekly_name = "";
  2988. $clocking_priority = "";
  2989. $clocking_warning_check = "";
  2990. $absent_warning_check = "";
  2991. $all_names = "N.A.";
  2992. // $action_checkbox = "<input type=\"checkbox\" name=\"roster_action\" value=\"\">";
  2993. }
  2994. $output[] = array(
  2995. // $action_checkbox,
  2996. $employee_number,
  2997. $user_name,
  2998. $job_title,
  2999. $department,
  3000. $business_unit,
  3001. $clocking_priority,
  3002. $shift_name,
  3003. $policy_name,
  3004. $weekly_name,
  3005. $all_names,
  3006. $clocking_warning_check,
  3007. $absent_warning_check,
  3008. );
  3009. } // EOF foreach
  3010. //echo "<pre>"; print_r($output); exit("</pre> \n exited here ");
  3011. $cols = array(
  3012. // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
  3013. //'Sr No',
  3014. 'Employee ID ||Column displays employee id',
  3015. 'Name||Column displays the Name of the employees.',
  3016. 'Job Title||Column displays the Job Tittle of the particular employee.',
  3017. 'Department||Column displays the Department to which the employee belongs.',
  3018. 'Business Unit||Column displays the Business Unit to which the employee belongs.',
  3019. 'Clocking Priority||Column displays the details of employees Clocking Source.',
  3020. 'Shift Name||Column displays the details of the Shift assigned to the employee.',
  3021. 'Policy Name||Column displays the details of the Policy assigned to the employee.',
  3022. 'Weekly Off Name||Column displays the details of Weekly off type assigned to the employee.',
  3023. 'IP restriction Name||Column displays the details of IP restriction assigned to the employee.',
  3024. 'Clock-in reminder||Column displays whether clock-in reminder will be sent or not.',
  3025. 'Absent reminder||Column displays whether Absent reminder will be sent or not.',
  3026. );
  3027. $roster_type = "Attendance-Assignments";
  3028. $filenameexport = $roster_type;
  3029.  
  3030. $final_output = array('output' => $output,
  3031. 'cols' => $cols,
  3032. 'filenameexport' => $filenameexport);
  3033. return $final_output;
  3034. }
  3035.  
  3036. // EOF function
  3037.  
  3038. /**
  3039. * Short description for function
  3040. *
  3041. * Long description (if any) ...
  3042. *
  3043. * @param array $post_data Parameter description (if any) ...
  3044. * @param unknown $tenant_id Parameter description (if any) ...
  3045. * @param unknown $from Parameter description (if any) ...
  3046. * @param unknown $to Parameter description (if any) ...
  3047. * @return array Return description (if any) ...
  3048. * @access public
  3049. * @static
  3050. */
  3051. public static function getDailyAttendanceRoster($post_data, $tenant_id = null, $from = null, $to = null) {
  3052. $from = $from." 00:00:00";
  3053. $to = $to." 23:59:59";
  3054. $return = array();
  3055. $output = array();
  3056. $finaldata = array();
  3057. $index = 0;
  3058. $status_msg = "";
  3059. $todays_day = date("d");
  3060. $filter = $post_data['filter_id'];
  3061. $criteria = new EMongoCriteria();
  3062. $criteria->shift_date('>=', new MongoDate(strtotime($from)));
  3063. $criteria->shift_date('<=', new MongoDate(strtotime($to)));
  3064. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  3065.  
  3066. $begin = new DateTime($from);
  3067. $end = new DateTime($to);
  3068. $end = $end->modify('+1 day');
  3069. $interval = new DateInterval('P1D');
  3070. $daterange = new DatePeriod($begin, $interval, $end);
  3071. $from = strtotime($from);
  3072. $to = strtotime($to);
  3073. $clockInSec = 0;
  3074. $clockOutSec = 0;
  3075. foreach ($users as $user)
  3076. {
  3077. // Getting users details...
  3078. $usermodel = UserMongo::model()->tenant($tenant_id)->findByPk($user->id);
  3079.  
  3080. $user_name = "";
  3081. $job_title_department = "";
  3082. $employee_id = (isset($usermodel->personal->employee_no)) ? $usermodel->personal->employee_no : "N.A.";
  3083. $user_name = $usermodel->getFullname();
  3084. $user_post = $usermodel->getCurrentPosition($tenant_id);
  3085. $job_title = $user_post['designation'];
  3086. $department = $user_post['department'];
  3087. $job_title_department = $job_title . "({$department})";
  3088.  
  3089. $criteria->user_id('==', $user->id);
  3090. $userAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
  3091. $user_shift_id = '';
  3092. $user_policy_id = '';
  3093.  
  3094. foreach ($userAttendanceLogs as $key => $userAttendanceLog)
  3095. {
  3096. if (isset($userAttendanceLog))
  3097. {
  3098. $unpaidFlag = false;
  3099. $userid = $userAttendanceLog->user_id;
  3100.  
  3101. $shift_date = $userAttendanceLog->shift_date->sec;
  3102. $user_shift_planner = UserShiftPlanner::model()->findByPk($userAttendanceLog->shift_planner);
  3103.  
  3104. if ($user_shift_planner->shift_id != $user_shift_id)
  3105. {
  3106. $tenant_shift = TenantShift::model()->findByPk($user_shift_planner->shift_id);
  3107. }
  3108. $user_shift_id = $user_shift_planner->shift_id;
  3109.  
  3110. if ($user_shift_planner->policy_id != $user_policy_id)
  3111. {
  3112. $attendance_policy = AttendancePolicy::model()->findByPk($user_shift_planner->policy_id);
  3113. }
  3114. $user_policy_id = $user_shift_planner->policy_id;
  3115.  
  3116. /**/
  3117. //$shift_name = $logCalc["rosterShiftName"];
  3118. $shift_name = (isset($tenant_shift->shift_name) && $tenant_shift->shift_name != "") ? $tenant_shift->shift_name : "N.A.";
  3119. //$policy_name = $logCalc["rosterPolicyName"];
  3120. $policy_name = (isset($attendance_policy->policy_name) && $attendance_policy->policy_name != "") ? $attendance_policy->policy_name : "N.A.";
  3121.  
  3122. /*$clockInSec = (isset($logCalc["punchin_time"])) ? AttendanceHelper::getFormatedTime($logCalc["punchin_time"]) : "N.A.";
  3123. ;
  3124. $clockOutSec = (isset($logCalc["punchout_time"])) ? AttendanceHelper::getFormatedTime($logCalc["punchout_time"]) : "N.A.";
  3125. ;*/
  3126. $clockInSec = (isset($userAttendanceLog["punchin_time"]) && $userAttendanceLog["punchin_time"] != null) ? AttendanceHelper::getFormatedTime($userAttendanceLog["punchin_time"]) : "N.A.";
  3127. ;
  3128. $clockOutSec = (isset($userAttendanceLog["punchout_time"]) && $userAttendanceLog["punchout_time"] != null) ? AttendanceHelper::getFormatedTime($userAttendanceLog["punchout_time"]) : "N.A.";
  3129. ;
  3130.  
  3131. /*if (isset($logCalc["rosterOverTimeSec"])) {
  3132. if ($logCalc["rosterOverTimeSec"] > 0) {
  3133. $overTimeSec = RandomHelper::sec2hms($logCalc["rosterOverTimeSec"]);
  3134. } else {
  3135. $overTimeSec = "0:00";
  3136. }
  3137. } else {
  3138. $overTimeSec = "0:00";
  3139. }*/
  3140. $total_duration = (isset($userAttendanceLog["total_work_duration"]) && $userAttendanceLog["total_work_duration"] != null) ? AttendanceHelper::getFormatedTimeNewHrs($userAttendanceLog["total_work_duration"]) : "0:00";
  3141. //$lateBySec = (isset($logCalc["rosterLateBySec"])) ? RandomHelper::sec2hms($logCalc["rosterLateBySec"]) : "0:00";
  3142. $lateBySec = (isset($userAttendanceLog["coming_late_by"]) && $userAttendanceLog["coming_late_by"] != null) ? AttendanceHelper::getFormatedTimeNewHrs($userAttendanceLog["coming_late_by"]) : "0:00";
  3143. $overTimeSec = (isset($userAttendanceLog["over_time"]) && $userAttendanceLog["over_time"] != null) ? AttendanceHelper::getFormatedTimeNewHrs($userAttendanceLog["over_time"]) : "0:00";
  3144. ;
  3145. ////// status
  3146.  
  3147.  
  3148. $date = date("d", $shift_date);
  3149. if (isset($userAttendanceLog->attendance_status))
  3150. {
  3151. $status = $userAttendanceLog->attendance_status;
  3152. if ($status == UserAttendance::ATTENDANCE_STATUS_ABSENT) {
  3153. $status = UserAttendanceLog::ATTENDANCE_STATUS_ABSENT;
  3154. } elseif ($status == UserAttendance::ATTENDANCE_STATUS_PRESENT) {
  3155. $status = UserAttendanceLog::ATTENDANCE_STATUS_PRESENT;
  3156. }
  3157.  
  3158. $weeklyoff = $userAttendanceLog->is_weekly_off->status;
  3159. $holiday = $userAttendanceLog->is_holiday->status;
  3160. $leave = $userAttendanceLog->in_leave->status;
  3161.  
  3162. if (isset($userAttendanceLog->in_leave->leave_id))
  3163. {
  3164. $unpaidLeave = UserLeaves::model()->findByPk($userAttendanceLog->in_leave->leave_id);
  3165. if (isset($unpaidLeave->isUnpaid) && $unpaidLeave->isUnpaid == UserLeaves::LEAVE_UNPAID) {
  3166. $unpaidFlag = true;
  3167. } else {
  3168. $unpaidFlag = false;
  3169. }
  3170. } else {
  3171. $unpaidFlag = false;
  3172. }
  3173. $present_or_not = '';
  3174. if (isset($weeklyoff) && $weeklyoff == "1")
  3175. {
  3176. $status = "W";
  3177. }
  3178. elseif (isset($holiday) && $holiday == "1")
  3179. {
  3180. $status = "H";
  3181. }
  3182. elseif (isset($leave) && $leave == "1")
  3183. {
  3184. if ($status == UserAttendanceLog::ATTENDANCE_STATUS_PRESENT || $status == UserAttendanceLog::ATTENDANCE_STATUS_PENDING)
  3185. {
  3186. $present_or_not = 'Present ';
  3187. }
  3188. $status = "L";
  3189. }
  3190. elseif ($status == UserAttendanceLog::ATTENDANCE_STATUS_PRESENT || $status == UserAttendanceLog::ATTENDANCE_STATUS_PENDING)
  3191. {
  3192. $status = "P";
  3193. } /* elseif ($status == UserAttendanceLog::ATTENDANCE_STATUS_PENDING) {
  3194. $status = "n";
  3195. } */
  3196. elseif ($status == UserAttendanceLog::ATTENDANCE_STATUS_ABSENT || $status == UserAttendance::ATTENDANCE_STATUS_ABSENT)
  3197. {
  3198. $status = "A";
  3199. }
  3200. else
  3201. {
  3202. $status = "";
  3203. }
  3204. }
  3205. else
  3206. {
  3207. $status = "";
  3208. }
  3209.  
  3210. if ($unpaidFlag)
  3211. {
  3212. $status = "U";
  3213. }
  3214.  
  3215. switch ($status)
  3216. {
  3217. case 'P':
  3218. $status_msg = "Present";
  3219. break;
  3220. case 'A':
  3221. $status_msg = "Absent";
  3222. break;
  3223. case 'W':
  3224. $status_msg = "Weekly Off";
  3225. break;
  3226. case 'H':
  3227. $status_msg = "Holiday" . '(' . $userAttendanceLog->is_holiday->holiday_name . ')';
  3228. break;
  3229. case 'L':
  3230. case 'U':
  3231.  
  3232. //in leave
  3233. $leave_id = $userAttendanceLog->in_leave->leave_id;
  3234. $userLeaves = UserLeaves::model()->tenant()->findByPk($leave_id);
  3235. if (!empty($userLeaves))
  3236. {
  3237. $tenantLeave = $userLeaves->leaveType();
  3238. $leave_type = (isset($tenantLeave->name))? $tenantLeave->name : 'Unpaid Leave';
  3239.  
  3240. if ($userLeaves->is_half_day == UserLeaves::HALF_DAY_NO) {
  3241.  
  3242. $wired_msg = $present_or_not."On Leave" . ' (' . $leave_type . ')';
  3243. } else {
  3244. $wired_msg = $present_or_not."HalfDay Leave" . ' (' . $leave_type . ')';
  3245. }
  3246. }
  3247. $status_msg = $wired_msg;
  3248. break;
  3249.  
  3250. default:
  3251. $status_msg = "-";
  3252. break;
  3253. }
  3254.  
  3255. ////// status
  3256. $attdate = date("d-M-Y", $shift_date);
  3257. $attdateday = date("l", $shift_date);
  3258. $attdate_day = $attdate . "(" . substr($attdateday, 0, 3) . ")";
  3259. $output[] = array($attdate_day);
  3260.  
  3261. array_push($output[$index],$employee_id, $user_name, $job_title_department, $shift_name, $policy_name, $clockInSec, $clockOutSec, $total_duration, $lateBySec, $overTimeSec, $status_msg);
  3262.  
  3263. /*
  3264. array_push($output[$index], $user_name);
  3265. array_push($output[$index], $job_title_department);
  3266. array_push($output[$index], $shift_name);
  3267. array_push($output[$index], $policy_name);
  3268. array_push($output[$index], $clockInSec);
  3269. array_push($output[$index], $clockOutSec);
  3270. array_push($output[$index], $total_duration);
  3271. array_push($output[$index], $lateBySec);
  3272. array_push($output[$index], $overTimeSec);
  3273. array_push($output[$index], $status_msg);
  3274. */
  3275. $index++;
  3276. }
  3277. } // EOF foreach all date
  3278. // break;
  3279. } // EOF foreach for users count...
  3280. $flag = true;
  3281. $cols = array(
  3282. 'Date||Column displays Date.',
  3283. 'Employee ID',
  3284. 'Name||Column displays Name.',
  3285. 'Job Title||Column displays Job Title.',
  3286. 'Shift Name||Column displays Shift Name.',
  3287. 'Policy Name||Column displays Policy Name.',
  3288. 'Clock In||Column displays Clock In.',
  3289. 'Clock Out||Column displays Clock Out.',
  3290. 'Work Duration||Column displays Work Duration.',
  3291. 'Late by||Column displays Late By.',
  3292. 'Overtime||Column displays Overtime.',
  3293. 'Status||Column displays Status.'
  3294. );
  3295.  
  3296. $roster_type = "Daily-Attendance-Report";
  3297. $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
  3298. $filenameexport = $roster_type . "_" . $date;
  3299. $final_output = array('output' => $output,
  3300. 'cols' => $cols,
  3301. 'filenameexport' => $filenameexport);
  3302. return $final_output;
  3303. }
  3304.  
  3305. // EOF function
  3306.  
  3307. /**
  3308. * Short description for function
  3309. *
  3310. * Long description (if any) ...
  3311. *
  3312. * @param array $post_data Parameter description (if any) ...
  3313. * @param unknown $tenant_id Parameter description (if any) ...
  3314. * @param unknown $from Parameter description (if any) ...
  3315. * @param unknown $to Parameter description (if any) ...
  3316. * @return array Return description (if any) ...
  3317. * @access public
  3318. * @static
  3319. */
  3320. public static function getCompleteAttendanceSummaryRoster($post_data, $tenant_id = null, $from = null, $to = null) {
  3321. $return = array();
  3322. $output = array();
  3323. $finaldata = array();
  3324. $index = 0;
  3325.  
  3326. $status_msg = "";
  3327. $todays_day = date("d");
  3328. $filter = $post_data['filter_id'];
  3329. $criteria = new EMongoCriteria();
  3330. $criteria->shift_date('>=', new MongoDate(strtotime($from)));
  3331. $criteria->shift_date('<=', new MongoDate(strtotime($to)));
  3332. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  3333.  
  3334. $begin = new DateTime($from);
  3335. $end = new DateTime($to);
  3336. $end = $end->modify('+1 day');
  3337. $interval = new DateInterval('P1D');
  3338. $daterange = new DatePeriod($begin, $interval, $end);
  3339. $from = strtotime($from);
  3340. $to = strtotime($to);
  3341.  
  3342. foreach ($users as $user) {
  3343. $employee_id = (isset($user->personal->employee_no)) ? $user->personal->employee_no : "N.A.";
  3344. $jindex = 0;
  3345. $present_count = 0;
  3346. $absent_count = 0;
  3347. $leave_count = 0;
  3348. $unpaid_leaves_count = 0;
  3349. $weeklyoff_count = 0;
  3350. $holiday_count = 0;
  3351. $totalWorkDurationTimeStamp = 0;
  3352. $workingDaysCount = 0;
  3353. $comingLateBy = 0;
  3354. $comingLateCounter = 0;
  3355. $goingearly = 0;
  3356. $goingearlytotal = 0;
  3357. $overTimeSecCounter = 0;
  3358. $overTimeSec = 0;
  3359. $unpaidleave_count = 0;
  3360. $shift_name = "";
  3361. $policy_name = "";
  3362. $weeklyOffName = "";
  3363. $clockingPriority = "";
  3364. $criteria->user_id('==', $user->id);
  3365. $userAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
  3366. $unpaidFlag = false;
  3367. $user_name = "";
  3368. $job_title_department = "";
  3369. $userid = $user->id;
  3370. $usermodel = UserMongo::model()->tenant($tenant_id)->findByPk($userid);
  3371. $user_name = $usermodel->getFullname();
  3372. $user_post = $usermodel->getCurrentPosition($tenant_id);
  3373. $job_title = $user_post['designation'];
  3374. $department = $user_post['department'];
  3375. $job_title_department = $job_title . "({$department})";
  3376. $user_id = $usermodel->id;
  3377. // echo "<pre>"; print_r($userAttendanceLogs); //exit("</pre> \n exited here ");
  3378. foreach ($daterange as $date) {
  3379. if (isset($userAttendanceLogs[$jindex])) {
  3380. $shift_date = $userAttendanceLogs[$jindex]->shift_date->sec;
  3381. $logCalc = AttendanceHelper::logCalculator($user_id, $shift_date, $tenant_id, true);
  3382. // echo "<pre>"; print_r($logCalc); //exit("</pre> \n exited here \n");
  3383. $shift_name = (isset($logCalc["rosterShiftName"])) ? $logCalc["rosterShiftName"] : "";
  3384. $policy_name = $logCalc["rosterPolicyName"];
  3385. $weeklyOffName = (isset($logCalc["rosterWeeklyOffName"])) ? $logCalc["rosterWeeklyOffName"] : "";
  3386. $clockingPriority = (isset($logCalc["rosterClockingPriority"])) ? $logCalc["rosterClockingPriority"] : "";
  3387.  
  3388. ////// status
  3389.  
  3390. if (isset($userAttendanceLogs[$jindex]->attendance_status)) {
  3391. $status = $userAttendanceLogs[$jindex]->attendance_status;
  3392.  
  3393. if ($status == UserAttendance::ATTENDANCE_STATUS_ABSENT) {
  3394. $status = UserAttendanceLog::ATTENDANCE_STATUS_ABSENT;
  3395. } elseif ($status == UserAttendance::ATTENDANCE_STATUS_PRESENT) {
  3396. $status = UserAttendanceLog::ATTENDANCE_STATUS_PRESENT;
  3397. }
  3398.  
  3399. $weeklyoff = $userAttendanceLogs[$jindex]->is_weekly_off->status;
  3400. $holiday = $userAttendanceLogs[$jindex]->is_holiday->status;
  3401. $leave = $userAttendanceLogs[$jindex]->in_leave->status;
  3402. if (isset($userAttendanceLogs[$jindex]->in_leave->leave_id)) {
  3403. $unpaidLeave = UserLeaves::model()->findByPk($userAttendanceLogs[$jindex]->in_leave->leave_id);
  3404. if ($unpaidLeave->isUnpaid == UserLeaves::LEAVE_UNPAID) {
  3405. $unpaidleave_count++;
  3406. }
  3407. }
  3408. if (isset($weeklyoff) && $weeklyoff == "1") {
  3409. $weeklyoff_count++;
  3410. } elseif (isset($holiday) && $holiday == "1") {
  3411. $holiday_count++;
  3412. } elseif (isset($leave) && $leave == "1") {
  3413. $leave_count++;
  3414. } elseif ($status == UserAttendanceLog::ATTENDANCE_STATUS_PRESENT || $status == UserAttendanceLog::ATTENDANCE_STATUS_PENDING) {
  3415. $present_count++;
  3416. } /* elseif ($status == UserAttendanceLog::ATTENDANCE_STATUS_PENDING) {
  3417. $status = "n";
  3418. } */ elseif ($status == UserAttendanceLog::ATTENDANCE_STATUS_ABSENT || $status == UserAttendance::ATTENDANCE_STATUS_ABSENT) {
  3419. $absent_count++;
  3420. }
  3421. }
  3422.  
  3423. ////// status
  3424. /// attendance
  3425.  
  3426. if ($status == UserAttendanceLog::ATTENDANCE_STATUS_PRESENT || $status == UserAttendanceLog::ATTENDANCE_STATUS_PENDING) {
  3427. if (isset($userAttendanceLogs[$jindex]->total_duration) && $userAttendanceLogs[$jindex]->total_duration != 0) {
  3428. $totalWorkDurationTimeStamp += $userAttendanceLogs[$jindex]->total_duration;
  3429. $workingDaysCount++;
  3430. }
  3431. }
  3432.  
  3433.  
  3434. if (isset($userAttendanceLogs[$jindex]->coming_late_by) && $userAttendanceLogs[$jindex]->coming_late_by != null) {
  3435. if (isset($logCalc["rosterLateBySec"])) {
  3436.  
  3437. // echo $userAttendanceLogs[$jindex]->coming_late_by . "<br>";
  3438. // echo $logCalc["rosterLateBySec"] . "<br>";
  3439. $comingLateBy += $logCalc["rosterLateBySec"];
  3440. $comingLateCounter++;
  3441. }
  3442. }
  3443.  
  3444. if (isset($userAttendanceLogs[$jindex]->over_time) && $userAttendanceLogs[$jindex]->over_time != '0') {
  3445.  
  3446. $overTimeSec += $logCalc['rosterOverTimeSec'];
  3447. $overTimeSecCounter++;
  3448. }
  3449. if (!empty($logCalc["total_duration"])) {
  3450. if ($logCalc["total_duration"] < $logCalc["rosterShiftSeconds"]) {
  3451. $goingearlytotal += $logCalc["rosterShiftSeconds"] - $logCalc["total_duration"];
  3452. $goingearly++;
  3453. }
  3454. }
  3455.  
  3456.  
  3457.  
  3458. $attdate = date("d-M-Y", $shift_date);
  3459. $attdateday = date("l", $shift_date);
  3460. $attdate_day = $attdate . "(" . substr($attdateday, 0, 3) . ")";
  3461. /// attendance
  3462. $jindex++;
  3463. } // EOF if isset
  3464. } // EOF foreach all date
  3465. if (isset($totalWorkDurationTimeStamp)) {
  3466. $totalWorkedHr = RandomHelper::sec2hms($totalWorkDurationTimeStamp);
  3467. if ($workingDaysCount > 0) {
  3468.  
  3469. $daillyAverage = $totalWorkDurationTimeStamp / $workingDaysCount;
  3470. $daillyAverage = RandomHelper::sec2hms($daillyAverage);
  3471. } else {
  3472. $daillyAverage = 0;
  3473. $daillyAverage = "0:00";
  3474. }
  3475. } else {
  3476. $totalWorkedHr = 0;
  3477. $weeklyAverage = 0;
  3478. $daillyAverage = 0;
  3479. }
  3480. if (isset($comingLateBy) && $comingLateCounter != 0) {
  3481. $avgLateBy = $comingLateBy / $comingLateCounter;
  3482. $avgLateBy = RandomHelper::sec2hms($avgLateBy);
  3483. } else {
  3484. $avgLateBy = "00:00";
  3485. }
  3486.  
  3487. if (isset($goingearlytotal) && $goingearlytotal != 0) {
  3488. $avgtime = $goingearlytotal / $goingearly;
  3489. $finalavg = RandomHelper::sec2hms($avgtime);
  3490. } else {
  3491. $avgtime = 0;
  3492. $finalavg = '00:00';
  3493. }
  3494.  
  3495. if ($overTimeSec != 0) {
  3496. $overTimeSec = $overTimeSec / $overTimeSecCounter;
  3497. $overTimeSec = RandomHelper::sec2hms($overTimeSec);
  3498. } else {
  3499. $overTimeSec = "0";
  3500. }
  3501. $output[] = array($employee_id);
  3502. array_push($output[$index], $user_name);
  3503. array_push($output[$index], $job_title_department);
  3504. array_push($output[$index], $shift_name);
  3505. array_push($output[$index], $policy_name);
  3506. array_push($output[$index], $weeklyOffName);
  3507. array_push($output[$index], $clockingPriority);
  3508. array_push($output[$index], $present_count);
  3509. array_push($output[$index], $absent_count);
  3510. array_push($output[$index], $leave_count);
  3511. array_push($output[$index], $unpaid_leaves_count);
  3512. // array_push($output[$index], $overTimeSec);
  3513. array_push($output[$index], $totalWorkedHr);
  3514. array_push($output[$index], $daillyAverage);
  3515. array_push($output[$index], $comingLateCounter);
  3516. array_push($output[$index], $avgLateBy);
  3517. array_push($output[$index], $goingearly);
  3518. array_push($output[$index], $finalavg);
  3519. array_push($output[$index], $overTimeSecCounter);
  3520. array_push($output[$index], $overTimeSec);
  3521. $index++;
  3522. // break;
  3523. } // EOF user foreach
  3524. $flag = true;
  3525. $cols = array(
  3526. 'Employee ID||Employee id',
  3527. 'Name||Name',
  3528. 'Job Title||Job Title',
  3529. 'Shift||Shift Assinged',
  3530. 'Policy||Policy Name',
  3531. 'Weekly Off||Weekly off Name',
  3532. 'Mode||The method by which employee clocks in and out, either Web/Online or Biometric/Hardware.',
  3533. 'Present||Total days when employee was marked Present.',
  3534. 'Absent||Total days when employee was marked Absent.',
  3535. 'Leaves||Total leaves taken by employee during this period.',
  3536. 'Unpaid||Unpaid leaves taken during this period.',
  3537. 'Total Worked Hours||Total number of hours employee has worked during this period.',
  3538. 'Daily Avg. Work Duration||An average of daily work duration for this period.',
  3539. 'Late Marks||Total number of days when employee was marked late to work.',
  3540. 'Avg. Late By||Average number of hours by which employee was on late marked days during this period.',
  3541. 'Early Clock Outs||Number of days when employee clocked out before completing shift duration.',
  3542. 'Avg. Early Clock Out by||Average number of hours by which employee clocked out on days marked as Early clock out.',
  3543. 'Over Time Days||Number of days when employee clocked over time hours during this period.',
  3544. 'Avg. Over Time||Average number of hours by which employee worked over time during this period.'
  3545. );
  3546.  
  3547. $roster_type = "Complete-Attendance-Summary";
  3548. $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
  3549. $filenameexport = $roster_type . "_" . $date;
  3550. $final_output = array('output' => $output,
  3551. 'cols' => $cols,
  3552. 'filenameexport' => $filenameexport);
  3553. return $final_output;
  3554. }
  3555.  
  3556. // EOF function
  3557.  
  3558. /**
  3559. * Short description for function
  3560. *
  3561. * Long description (if any) ...
  3562. *
  3563.  
  3564. * @param string $birth_day_month Parameter description (if any) ...
  3565. * @return number Return description (if any) ...
  3566. * @access public
  3567. * @static
  3568. */
  3569. public static function days_till_birthday($birth_day_month) {
  3570. $bts = strtotime($birth_day_month . " " . date("y"));
  3571. $ts = time();
  3572. if ($bts < $ts) {
  3573. $bts = strtotime($birth_day_month . " " . date("y", strtotime("+1 year")));
  3574. }
  3575. return round(($bts - $ts) / 86400);
  3576. }
  3577.  
  3578. /**
  3579. * Short description for function
  3580. *
  3581. * Long description (if any) ...
  3582. *
  3583. * @return array Return description (if any) ...
  3584. * @access public
  3585. * @static
  3586. */
  3587. public static function loadFilters() {
  3588. $filters = array();
  3589. $userMongo = UserMongo::model()->tenant()->findByAttributes(array('user_id' => Yii::app()->user->id));
  3590. if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")) && Yii::app()->session['menu_owner'])
  3591. {
  3592. //$filters['ALL'] = array('ALL_0' => 'All Employees');
  3593. // $filters['Designations'] = self::getAllDesignations();
  3594. // $filters['Departments'] = UserDepartments::getAllDepartments();
  3595. // $filters['Locations'] = TenantOffices::getTenantOfficeLocation();
  3596. // $filters['Employee Type'] = TenantUserTypes::getTenantTypes();
  3597. }
  3598. /* if(isset($userMongo) && !empty($userMongo))
  3599. {*/
  3600. elseif($userMongo->checkManager())
  3601. {
  3602. $filters['ALL'] = array('ALL_0' => 'All Reportees');
  3603. $filters['Reportees'] = $userMongo->getManagedUsersForRosters();
  3604. }
  3605. // }
  3606. // $filters['Shift'] = TenantShift::getTenantShiftArray();
  3607. return $filters;
  3608. }
  3609.  
  3610. /**
  3611. * Short description for function
  3612. *
  3613. * Long description (if any) ...
  3614. *
  3615. * @return array Return description (if any) ...
  3616. * @access public
  3617. * @static
  3618. */
  3619. public static function loadCustomRosterFilter() {
  3620. $roster_attribute_labels = array();
  3621. $usermongo_obj = new UserMongo;
  3622. $roster_attribute_labels = $usermongo_obj::model()->rosterAttributeLabels();
  3623. // echo "<pre>"; print_r($roster_attribute_labels); exit("</pre> \n exited here ");
  3624. return $roster_attribute_labels;
  3625. /* //remove later
  3626. $embedded_documents = $usermongo_obj::model()->embeddedDocuments();
  3627. foreach ($embedded_documents as $model_name => $model) {
  3628. $m = new $model;
  3629. $filters[$model_name] = $m->attributes;
  3630. // echo "<pre>"; print_r($filters); exit("</pre> \n exited here ");
  3631. } */
  3632. }
  3633.  
  3634. /**
  3635. * Short description for function
  3636. *
  3637. * Long description (if any) ...
  3638. *
  3639. * @return array Return description (if any) ...
  3640. * @access public
  3641. * @static
  3642. */
  3643. public static function getAllDesignations() {
  3644. $desigs = UserDesignations::model()->tenant()->findAll();
  3645. $collection = array();
  3646. foreach ($desigs as $desig) {
  3647. $collection['DESG_' . $desig->id] = $desig->designation_name;
  3648. }
  3649. return $collection;
  3650. }
  3651.  
  3652. /**
  3653. * Short description for function
  3654. *
  3655. * Long description (if any) ...
  3656. *
  3657. * @param unknown $tenant_id Parameter description (if any) ...
  3658. * @return object Return description (if any) ...
  3659. * @access public
  3660. */
  3661. public function tenant($tenant_id = null) {
  3662. $this->getDbCriteria()->mergeWith(array(
  3663. 'conditions' => array(
  3664. 'tenant_id' => array('==' => ($tenant_id == null) ? Yii::app()->user->getTenantId() : $tenant_id),
  3665. ),
  3666. 'sort' => array(
  3667. 'unit_name' => EMongoCriteria::SORT_ASC,
  3668. ),
  3669. ));
  3670. return $this;
  3671. }
  3672.  
  3673. public static function getLeavesCarriedForwardBalance($post_data, $tenant_id = null, $from = null, $to = null) {
  3674. //$tenat_leave = Leaves::model()->tenant($tenant_id)->findAll();
  3675. //echo "<pre>"; print_r($tenat_leave); exit("\n exited in " . __FILE__ . " @ " . __LINE__. "</pre>");
  3676. $return = array();
  3677. //$sr_no=1;
  3678. $filter = $post_data['filter_id'];
  3679. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  3680. $output = array();
  3681. $leaves = Leaves::model()->getTenantLeaveList($tenant_id);
  3682.  
  3683. $index = 0;
  3684. foreach ($users as $key => $user) {
  3685. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  3686. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  3687. $user_post = $user->getCurrentPosition($tenant_id);
  3688. $job_title = $user_post['designation'];
  3689. $department = $user_post['department'];
  3690. $business_unit = $user_post['business_unit'];
  3691. // $action_checkbox = "<input type=\"checkbox\" name=\"roster_action\" value=\"\">";
  3692. $leaves_user_allowed = Leaves::model()->getLeaveList($tenant_id, $user->user_id);
  3693. unset($userleaves);
  3694. foreach ($leaves as $leave_id => $leave) {
  3695. if (array_key_exists($leave_id, $leaves_user_allowed)) {
  3696. $userleaves[] = LeavesHelper::individualLeaveBalance($user->user_id, $tenant_id, $leave_id);
  3697. } else {
  3698. $userleaves[] = array(
  3699. 'leave_name' => 'NA',
  3700. 'balance' => 'NA',
  3701. 'total' => 'NA',
  3702. 'prevBalance' => 'NA'
  3703. );
  3704. }
  3705. }
  3706. $output[] = array(
  3707. // $action_checkbox,
  3708. $employee_number,
  3709. $user_name,
  3710. $job_title,
  3711. $department,
  3712. $business_unit,
  3713. );
  3714. for ($i = 0; $i < count($userleaves); $i++) {
  3715. array_push($output[$index], $userleaves[$i]['prevBalance']);
  3716. }
  3717. $index++;
  3718. } // EOF foreach user
  3719.  
  3720. $cols = array(
  3721. // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
  3722. //'Sr No',
  3723. 'Employee ID',
  3724. 'Name',
  3725. 'Job Title',
  3726. 'Department',
  3727. 'Business Unit',
  3728. );
  3729.  
  3730. foreach ($leaves as $leave_id => $leave_name) {
  3731. array_push($cols, $leave_name);
  3732. }
  3733. $roster_type = "Leaves-Credited";
  3734. $filenameexport = $roster_type;
  3735. $final_output = array('output' => $output,
  3736. 'cols' => $cols,
  3737. 'filenameexport' => $filenameexport);
  3738. return $final_output;
  3739. }
  3740.  
  3741. public static function getEmployeeExitReport($post_data, $tenant_id = null,$from, $to) {
  3742. $return = array();
  3743. $filter = $post_data['filter_id'];
  3744. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, 3);
  3745.  
  3746. $output = array();
  3747. foreach ($users as $key => $user) {
  3748. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  3749. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  3750. $user_post = $user->getCurrentPosition($tenant_id);
  3751. $job_title = $user_post['designation'];
  3752. $department = $user_post['department'];
  3753. $business_unit = $user_post['business_unit'];
  3754.  
  3755. if (isset($user->deactivate_date) && $user->deactivate_date->sec != null) {
  3756. // checking whether it is in range
  3757. $deactivateDate = date('Y-m-d',$user->deactivate_date->sec);
  3758. $deactivation_Begin = date('Y-m-d', strtotime($from));
  3759. $deactivation_End = date('Y-m-d', strtotime($to));
  3760. if (($deactivateDate > $deactivation_Begin) && ($deactivateDate < $deactivation_End))
  3761. {
  3762. // checking whether it is in range
  3763. if (isset($user->doj) && isset($user->deactivate_date)) {
  3764. $doj = new DateTime(date("Y-m-d", $user->doj->sec)); // or your date as well
  3765. $deactivate_date = new DateTime(date("Y-m-d", $user->deactivate_date->sec));
  3766. $interval = $doj->diff($deactivate_date);
  3767. $final_exp = $interval->format('%y years %m months and %d days');
  3768. $job_experience = $final_exp;
  3769. } else {
  3770. $job_experience = "NA";
  3771. }
  3772. if (isset($user->deactivate_reason)) {
  3773. $deactivateReason = UserDeactivate::model()->tenant()->findByPk($user->deactivate_reason);
  3774. $exit_type = (isset($deactivateReason->type) && $deactivateReason->type == UserDeactivate::USER_DEACTIVATE_TERMINATED) ? "Terminated" : "Resigned";
  3775. $exit_reason = (isset($deactivateReason->value) && $deactivateReason->value != null) ? $deactivateReason->value : "NA";
  3776. } else {
  3777. $exit_type = "NA";
  3778. $exit_reason = "NA";
  3779. }
  3780. $doj = (isset($user->doj) && $user->doj != null) ? date('d/m/Y', $user->doj->sec) : "NA";
  3781. $exit_date = (isset($user->deactivate_date) && $user->deactivate_date != null) ? date('d/m/Y', $user->deactivate_date->sec) : "NA";
  3782. $deactivate_by = (isset($user->deactivate_by) && $user->deactivate_by != null) ? UserMongo::getFullnameById($user->deactivate_by) : "NA";
  3783. $deactivate_on = (isset($user->deactivate_created_on) && $user->deactivate_created_on != null) ? date('d/m/Y', $user->deactivate_created_on->sec) : "NA";
  3784. // } else {
  3785. // $dob_year = "N.A.";
  3786. // $dob_month = "N.A.";
  3787. // $dob_day = "N.A.";
  3788. // $age = "N.A.";
  3789. // $no_days_remain = "N.A.";
  3790. // }
  3791. // $action_checkbox = "<input type=\"checkbox\" name=\"roster_action\" value=\"\">";
  3792. $output[] = array(
  3793. $employee_number,
  3794. $user_name,
  3795. $job_title,
  3796. $department,
  3797. $business_unit,
  3798. $doj,
  3799. $job_experience,
  3800. $exit_date,
  3801. $exit_type,
  3802. $exit_reason,
  3803. $deactivate_by,
  3804. $deactivate_on,
  3805. );
  3806. }
  3807. }
  3808. } // EOF foreach
  3809. // echo "<pre>"; print_r($output); exit("</pre> \n exited here ");
  3810. $cols = array(
  3811. // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
  3812. //'SR NO',
  3813. 'Employee ID',
  3814. 'Name',
  3815. 'Job Title',
  3816. 'Department',
  3817. 'Business Unit',
  3818. 'Joining Date',
  3819. 'Job experience',
  3820. 'Exit Date',
  3821. 'Exit Type',
  3822. 'Exit Reason',
  3823. 'Deactivated by',
  3824. 'Deactivated on'
  3825. );
  3826.  
  3827. $filenameexport = "Employee-Deactivated-Data";
  3828. $final_output = array('output' => $output,
  3829. 'cols' => $cols,
  3830. 'filenameexport' => $filenameexport);
  3831. return $final_output;
  3832. }
  3833.  
  3834. /**
  3835.  
  3836. * Short description for function
  3837. *
  3838. * Long description (if any) ...
  3839. *
  3840. * @param array $post_data Parameter description (if any) ...
  3841. * @param unknown $tenant_id Parameter description (if any) ...
  3842. * @param unknown $user_id Parameter description (if any) ...
  3843. * @return array Return description (if any) ...
  3844. * @access public
  3845. * @static
  3846. */
  3847. public static function getUnpaidLeavesTaken($post_data, $tenant_id, $from, $to) {
  3848.  
  3849. $return = array();
  3850. //$sr_no=1;
  3851. $filter = $post_data['filter_id'];
  3852. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  3853. $output = array();
  3854. $leave_settings = TenantLeavesSettings::model()->findByAttributes(array('tenant_id' => $tenant_id));
  3855. // $leaves = Leaves::model()->getLeaveList($tenant_id, $user_id);
  3856. if(isset($leave_settings->unpaid_refresh) && $leave_settings->unpaid_refresh == TenantLeavesSettings::FINANCIAL_UNPAID_REFRESH){
  3857. $tenantProfile = TenantProfile::model()->tenant($tenant_id)->find();
  3858. $year_to_pass = date('Y');
  3859. $month_list = $tenantProfile->getMonthList('Y-m','M', $year_to_pass);
  3860. }
  3861. else{
  3862. $tenantProfile = TenantProfile::model()->tenant($tenant_id)->find();
  3863. $month_list = $tenantProfile->getMonthListCalendar('Y-m','M');
  3864. }
  3865. //$leaves = Leaves::model()->getTenantLeaveList($tenant_id);
  3866. $index = 0;
  3867. foreach ($users as $key => $user) {
  3868. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  3869. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  3870. $user_post = $user->getCurrentPosition($tenant_id);
  3871. $job_title = $user_post['designation'];
  3872. $department = $user_post['department'];
  3873. $business_unit = $user_post['business_unit'];
  3874. // $action_checkbox = "<input type=\"checkbox\" name=\"roster_action\" value=\"\">";
  3875. // $leaves_user_allowed = Leaves::model()->getLeaveList($tenant_id, $user->user_id);
  3876. // unset($userleaves);
  3877. $check_total = 0;
  3878. foreach ($month_list as $for_month => $month){
  3879. $leaves_approved = UserLeaves::model()->user_approved_leave($user->id)->forMonth($for_month)->unpaid()->findAll();
  3880. $total_days = 0;
  3881. foreach ($leaves_approved as $le){
  3882. $wekly_off_days = RandomHelper::getWorkingDays($le->from_date->sec, $le->to_date->sec, $le->user_id, $le->tenant_id);
  3883. if (!empty($wekly_off_days)){
  3884. if ($le->is_half_day == UserLeaves::HALF_DAY_YES){
  3885. $total_days += 0.5;
  3886. }
  3887. }
  3888. else{
  3889. if ($total_days > 0){
  3890. $total_days -= 0.5;
  3891. }
  3892. }
  3893. }
  3894. /**/
  3895. $counter = 0;
  3896. $counter_new = 0;
  3897. $counter = UserLeaves::getCountOfMonthsUnpaid($user->id, $for_month);
  3898. if ($counter > 0)
  3899. {
  3900. $counter = $counter - $total_days;
  3901. }
  3902. else
  3903. {
  3904. $counter = $counter;
  3905. }
  3906. $check_total += $counter;
  3907. }
  3908. //
  3909.  
  3910. $output[] = array(
  3911. // $action_checkbox,
  3912. $employee_number,
  3913. $user_name,
  3914. $job_title,
  3915. $department,
  3916. $business_unit,
  3917. $check_total,
  3918. );
  3919. // for ($i = 0; $i < count($userleaves); $i++) {
  3920. // $newfinal = $userleaves[$i];
  3921. // array_push($output[$index], $newfinal);
  3922. // }
  3923. $index++;
  3924. } // EOF foreach user
  3925.  
  3926.  
  3927.  
  3928. $cols = array(
  3929. // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
  3930. //'Sr No',
  3931. 'Employee ID',
  3932. 'Name',
  3933. 'Job Title',
  3934. 'Department',
  3935. 'Business Unit',
  3936. 'Unpaid Leaves'
  3937. );
  3938.  
  3939. // foreach ($leaves as $leave_id => $leave_name) {
  3940. // array_push($cols, $leave_name);
  3941. // }
  3942.  
  3943. $roster_type = "Leaves-Taken-or-Used";
  3944. $filenameexport = $roster_type;
  3945. $final_output = array('output' => $output,
  3946. 'cols' => $cols,
  3947. 'filenameexport' => $filenameexport);
  3948.  
  3949. return $final_output;
  3950. }
  3951.  
  3952. // EOF function
  3953.  
  3954.  
  3955. public static function getSummaryMonth($post_data, $tenant_id, $from, $to) {
  3956. $for_date = date('Y-m', strtotime($from));
  3957. $return = array();
  3958. $deactivated_user = 0;
  3959. $bank_details_user = 0;
  3960. $no_bank_details_user = 0;
  3961. $fandfamount = 0;
  3962. $bankamount = 0;
  3963. $nobankamount = 0;
  3964. $current_month = date("m");
  3965. //$sr_no=1;
  3966. $filter = $post_data['filter_id'];
  3967. $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
  3968. foreach ($userSalarySlip as $salaryslip) {
  3969. //$users = UserMongo::model()->getUsersByFilter($filter, $tenant_id,$post_data['active_inactive']);
  3970. $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  3971. if (isset($users) && !empty($users)) {
  3972. $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
  3973. /*if (isset($users->deactivate_date) && $users->deactivate_date != null && date('m', $users->deactivate_date->sec) == $current_month) {
  3974. $deactivated_user++;
  3975. $fandfamount += $salaryslip->total_net;
  3976. } */if (isset($users->banking) && isset($users->banking->bank_name) && isset($users->banking->bank_account)) {
  3977. $bank_details_user++;
  3978. $bankamount += $salaryslip->total_net;
  3979. } elseif (empty($users->banking) && !isset($users->banking->bank_name) && !isset($users->banking->bank_account)) {
  3980. $no_bank_details_user++;
  3981. $nobankamount += $salaryslip->total_net;
  3982. }
  3983. }
  3984. }
  3985.  
  3986. $output = array();
  3987. $index = 0;
  3988. $particulars_name = array("Bank List", "No Bank List");
  3989. foreach ($particulars_name as $key => $particular) {
  3990. if ($particular == "Bank List") {
  3991. $employee_count = $bank_details_user;
  3992. $amount = $bankamount;
  3993. } elseif ($particular == "No Bank List") {
  3994. $employee_count = $no_bank_details_user;
  3995. $amount = $nobankamount;
  3996. } /*else {
  3997. $employee_count = $deactivated_user;
  3998. $amount = $fandfamount;
  3999. }*/
  4000. $output[] = array(
  4001. $particular,
  4002. $employee_count,
  4003. $amount,
  4004. );
  4005. }
  4006.  
  4007. $cols = array(
  4008. 'Particulars',
  4009. 'Employees Count',
  4010. 'Amount',
  4011. );
  4012.  
  4013.  
  4014.  
  4015. $roster_type = "payroll-summary-month".$for_date;
  4016. $filenameexport = $roster_type;
  4017. $final_output = array('output' => $output,
  4018. 'cols' => $cols,
  4019. 'filenameexport' => $filenameexport);
  4020. return $final_output;
  4021. }
  4022.  
  4023. public static function getBankListMonth($post_data, $tenant_id, $from, $to) {
  4024. $for_date = date('Y-m', strtotime($from));
  4025. $return = array();
  4026. $output = array();
  4027. $current_month = date("m");
  4028. $filter = $post_data['filter_id'];
  4029. $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
  4030. foreach ($userSalarySlip as $salaryslip) {
  4031. //$users = UserMongo::model()->getUsersByFilter($filter, $tenant_id,$post_data['active_inactive']);
  4032. //$users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  4033. if($post_data['active_inactive'] == 1)
  4034. {
  4035. $users = UserMongo::model()->tenant($tenant_id)->active()->findByPk($salaryslip->user_id);
  4036. }
  4037. else if($post_data['active_inactive'] == 2)
  4038. {
  4039. $users = UserMongo::model()->tenant($tenant_id)->disabled()->findByPk($salaryslip->user_id);
  4040. }
  4041. else
  4042. {
  4043. $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  4044. }
  4045. if (isset($users) && !empty($users)) {
  4046. $office_location = TenantOffices::model()->tenant($tenant_id)->findByAttributes(array('id' => $users->personal->office_location));
  4047. $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
  4048. if (isset($office_location) && !empty($office_location) && isset($office_location->city) && $office_location->city != "") {
  4049. $city_name = City::model()->findByPk($office_location->city);
  4050. if (isset($city_name) && !empty($city_name)) {
  4051. $office_location_name = $city_name->name;
  4052. } else {
  4053. $office_location_name = "N.A";
  4054. }
  4055. } else {
  4056. $office_location_name = "N.A";
  4057. }
  4058. if (isset($users->banking) && isset($users->banking->bank_name) && $users->banking->bank_name != "" && isset($users->banking->bank_account) && $users->banking->bank_account != "") {
  4059. $account_number = $users->banking->bank_account;
  4060. $account_bank_name = $users->banking->bank_name;
  4061. $account_branch_name = (isset($users->banking->bank_branch) && $users->banking->bank_branch != "") ? $users->banking->bank_branch : "N.A.";
  4062. //$account_bank_branch = (isset($users->banking->bank_branch) && $users->banking->bank_branch != "") ? $users->banking->bank_branch : "N.A.";
  4063. $ifsc_code = (isset($users->banking->bank_ifsc) && $users->banking->bank_ifsc != "") ? $users->banking->bank_ifsc : "N.A.";
  4064. $net_salary = $salaryslip->total_net;
  4065. $full_name = $users->getFullname();
  4066. $output[] = array(
  4067. $employee_code,
  4068. $full_name,
  4069. $office_location_name,
  4070. $account_number,
  4071. $account_bank_name,
  4072. $account_branch_name,
  4073. $ifsc_code,
  4074. $net_salary,
  4075. );
  4076. }
  4077. }
  4078. }
  4079.  
  4080.  
  4081. $cols = array(
  4082. 'Employee Code',
  4083. 'Employee Name',
  4084. 'Location',
  4085. 'Account Number',
  4086. 'Bank Name',
  4087. 'Bank Branch',
  4088. 'IFSC Code',
  4089. 'Net Salary',
  4090. );
  4091.  
  4092.  
  4093.  
  4094. $roster_type = "payroll-Bank-List-month".$for_date;
  4095. $filenameexport = $roster_type;
  4096. $final_output = array('output' => $output,
  4097. 'cols' => $cols,
  4098. 'filenameexport' => $filenameexport);
  4099. return $final_output;
  4100. }
  4101.  
  4102. public static function getNoBankListMonth($post_data, $tenant_id, $from, $to) {
  4103. $for_date = date('Y-m', strtotime($from));
  4104. $return = array();
  4105. $output = array();
  4106.  
  4107. $current_month = date("m");
  4108. $filter = $post_data['filter_id'];
  4109. $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
  4110. foreach ($userSalarySlip as $salaryslip) {
  4111. //$users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  4112. if($post_data['active_inactive'] == 1)
  4113. {
  4114. $users = UserMongo::model()->tenant($tenant_id)->active()->findByPk($salaryslip->user_id);
  4115. }
  4116. else if($post_data['active_inactive'] == 2)
  4117. {
  4118. $users = UserMongo::model()->tenant($tenant_id)->disabled()->findByPk($salaryslip->user_id);
  4119. }
  4120. else
  4121. {
  4122. $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  4123. }
  4124. if (isset($users) && !empty($users)) {
  4125. $office_location = TenantOffices::model()->tenant($tenant_id)->findByAttributes(array('id' => $users->personal->office_location));
  4126. $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
  4127. if (isset($office_location) && !empty($office_location) && isset($office_location->city) && $office_location->city != "") {
  4128. $city_name = City::model()->findByPk($office_location->city);
  4129. if (isset($city_name) && !empty($city_name)) {
  4130. $office_location_name = $city_name->name;
  4131. } else {
  4132. $office_location_name = "N.A";
  4133. }
  4134. } else {
  4135. $office_location_name = "N.A";
  4136. }
  4137. if ((isset($users->banking->bank_name) || !isset($users->banking->bank_name)) && $users->banking->bank_name == "" && (isset($users->banking->bank_account) || !isset($users->banking->bank_account)) && $users->banking->bank_account == "") {
  4138. $account_number = $users->banking->bank_account;
  4139. $account_bank_name = "Cheque Payment";
  4140. $account_branch_name = (isset($users->banking->bank_branch) && $users->banking->bank_branch != "") ? $users->banking->bank_branch : "N.A.";
  4141. $net_salary = $salaryslip->total_net;
  4142. $full_name = $users->getFullname();
  4143. $output[] = array(
  4144. $employee_code,
  4145. $full_name,
  4146. $office_location_name,
  4147. $account_number,
  4148. $account_bank_name,
  4149. $net_salary,
  4150. );
  4151. }
  4152. }
  4153. }
  4154. $cols = array(
  4155. 'Employee Code',
  4156. 'Employee Name',
  4157. 'Location',
  4158. 'Account Number',
  4159. 'Bank Name',
  4160. 'Net Salary',
  4161. );
  4162.  
  4163.  
  4164.  
  4165. $roster_type = "payroll-No-Bank-List-month".$for_date;
  4166. $filenameexport = $roster_type;
  4167. $final_output = array('output' => $output,
  4168. 'cols' => $cols,
  4169. 'filenameexport' => $filenameexport);
  4170. return $final_output;
  4171. }
  4172.  
  4173. public static function getFandFListMonth($post_data, $tenant_id, $from, $to) {
  4174. $for_date = date('Y-m', strtotime($from));
  4175. $return = array();
  4176. $output = array();
  4177.  
  4178. $current_month = date("m");
  4179. $filter = $post_data['filter_id'];
  4180. $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
  4181. foreach ($userSalarySlip as $salaryslip) {
  4182. //$users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  4183. if($post_data['active_inactive'] == 1)
  4184. {
  4185. $users = UserMongo::model()->tenant($tenant_id)->active()->findByPk($salaryslip->user_id);
  4186. }
  4187. else if($post_data['active_inactive'] == 2)
  4188. {
  4189. $users = UserMongo::model()->tenant($tenant_id)->disabled()->findByPk($salaryslip->user_id);
  4190. }
  4191. else
  4192. {
  4193. $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  4194. }
  4195. if (isset($users) && !empty($users)) {
  4196. $office_location = TenantOffices::model()->tenant($tenant_id)->findByAttributes(array('id' => $users->personal->office_location));
  4197. if (isset($office_location) && !empty($office_location) && isset($office_location->city) && $office_location->city != "") {
  4198. $city_name = City::model()->findByPk($office_location->city);
  4199. if (isset($city_name) && !empty($city_name)) {
  4200. $office_location_name = $city_name->name;
  4201. } else {
  4202. $office_location_name = "N.A";
  4203. }
  4204. } else {
  4205. $office_location_name = "N.A";
  4206. }
  4207. if (isset($users->deactivate_date) && $users->deactivate_date != null && date('m', $users->deactivate_date->sec) == $current_month) {
  4208. $net_salary = $salaryslip->total_net;
  4209. $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
  4210. $full_name = $users->getFullname();
  4211. $output[] = array(
  4212. $employee_code,
  4213. $full_name,
  4214. $office_location_name,
  4215. $net_salary,
  4216. );
  4217. }
  4218. }
  4219. }
  4220. $cols = array(
  4221. 'Employee Code',
  4222. 'Employee Name',
  4223. 'Location',
  4224. 'Net Salary',
  4225. );
  4226.  
  4227.  
  4228.  
  4229. $roster_type = "payroll-FandF-List-month".$for_date;
  4230. $filenameexport = $roster_type;
  4231. $final_output = array('output' => $output,
  4232. 'cols' => $cols,
  4233. 'filenameexport' => $filenameexport);
  4234. return $final_output;
  4235. }
  4236.  
  4237. public static function getTDSReportMonth($post_data, $tenant_id, $from, $to) {
  4238. $for_date = date('Y-m', strtotime($from));
  4239. $return = array();
  4240. $output = array();
  4241.  
  4242. $current_month = date("m");
  4243. $filter = $post_data['filter_id'];
  4244. $active_inactive = (!empty($post_data['active_inactive'])) ? $post_data['active_inactive'] : '';
  4245. $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
  4246. foreach ($userSalarySlip as $salaryslip) {
  4247. //$users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  4248. if($active_inactive == 1)
  4249. {
  4250. $users = UserMongo::model()->tenant($tenant_id)->active()->findByPk($salaryslip->user_id);
  4251. }
  4252. else if($active_inactive == 2)
  4253. {
  4254. $users = UserMongo::model()->tenant($tenant_id)->disabled()->findByPk($salaryslip->user_id);
  4255. }
  4256. else
  4257. {
  4258. $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  4259. }
  4260.  
  4261. $gross_salary = (isset($salaryslip->total_gross)) ? $salaryslip->total_gross : 0;
  4262.  
  4263. if (isset($users) && !empty($users)) {
  4264. $full_name = $users->getFullname();
  4265. $office_location = TenantOffices::model()->tenant($tenant_id)->findByAttributes(array('id' => $users->personal->office_location));
  4266. $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
  4267. if (isset($office_location) && !empty($office_location) && isset($office_location->city) && $office_location->city != "") {
  4268. $city_name = City::model()->findByPk($office_location->city);
  4269. if (isset($city_name) && !empty($city_name)) {
  4270. $office_location_name = $city_name->name;
  4271. } else {
  4272. $office_location_name = "N.A";
  4273. }
  4274. } else {
  4275. $office_location_name = "N.A";
  4276. }
  4277. $pan_number = (isset($users->banking->bank_pan_num) && $users->banking->bank_pan_num != "") ? $users->banking->bank_pan_num : "N.A.";
  4278. //$total_tds = (isset($salaryslip->tds) && $salaryslip->tds != "") ? $salaryslip->tds : "N.A.";
  4279. $total_tds = $salaryslip->tds;
  4280. $education_cess_cal = $total_tds * 0.03;
  4281. $education_cess = PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $education_cess_cal);
  4282. $income_tax = $total_tds - $education_cess;
  4283. $surcharges =0;
  4284.  
  4285. if($income_tax > 0)
  4286. {
  4287. $output[] = array(
  4288. $employee_code,
  4289. $full_name,
  4290. $office_location_name,
  4291. $pan_number,
  4292. $gross_salary,
  4293. $income_tax,
  4294. $education_cess,
  4295. $surcharges,
  4296. $total_tds,
  4297. );
  4298. }
  4299. }
  4300. }
  4301. $cols = array(
  4302. 'Employee Code',
  4303. 'Employee Name',
  4304. 'Location',
  4305. 'PAN Number',
  4306. 'Gross',
  4307. 'Income Tax',
  4308. 'Education Cess',
  4309. 'Surcharge',
  4310. 'Total Income Tax',
  4311. );
  4312.  
  4313.  
  4314.  
  4315. $roster_type = "payroll-TDS-Report-List-month".$for_date;
  4316. $filenameexport = $roster_type;
  4317. $final_output = array('output' => $output,
  4318. 'cols' => $cols,
  4319. 'filenameexport' => $filenameexport);
  4320. return $final_output;
  4321. }
  4322.  
  4323. public static function getPTReportMonth($post_data, $tenant_id, $from, $to) {
  4324. $for_date = date('Y-m', strtotime($from));
  4325. $month = date('m', strtotime($from));
  4326. $return = array();
  4327. $output = array();
  4328.  
  4329. $current_month = date("m");
  4330. $filter = $post_data['filter_id'];
  4331. $active_inactive = (!empty($post_data['active_inactive'])) ? $post_data['active_inactive'] : '';
  4332. $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
  4333. foreach ($userSalarySlip as $salaryslip) {
  4334. //$users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  4335. if($active_inactive == 1)
  4336. {
  4337. $users = UserMongo::model()->tenant($tenant_id)->active()->findByPk($salaryslip->user_id);
  4338. }
  4339. else if($active_inactive == 2)
  4340. {
  4341. $users = UserMongo::model()->tenant($tenant_id)->disabled()->findByPk($salaryslip->user_id);
  4342. }
  4343. else
  4344. {
  4345. $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  4346. }
  4347. if (isset($users) && !empty($users)) {
  4348. $full_name = $users->getFullname();
  4349. $office_location = TenantOffices::model()->tenant($tenant_id)->findByAttributes(array('id' => $users->personal->office_location));
  4350. $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
  4351. if (isset($office_location) && !empty($office_location) && isset($office_location->city) && $office_location->city != "") {
  4352. $city_name = City::model()->findByPk($office_location->city);
  4353. if (isset($city_name) && !empty($city_name)) {
  4354. $office_location_name = $city_name->name;
  4355. } else {
  4356. $office_location_name = "N.A";
  4357. }
  4358. } else {
  4359. $office_location_name = "N.A";
  4360. }
  4361. foreach ($salaryslip->items as $item) {
  4362. if ($item->variable_name == "professional_tax") {
  4363. //print_r($item);
  4364. //$d = new DateTime($this->for_month);
  4365. $professional_tax = $item->max_value_month;
  4366.  
  4367. if ($office_location->state == "1927" && $month == "02")
  4368. {
  4369. $professional_tax = (isset($professional_tax) && $professional_tax > 0 && $professional_tax == 200) ? $professional_tax + 100 : $professional_tax;
  4370. }
  4371. } else {
  4372. $professional_tax = "N.A.";
  4373. }
  4374. }
  4375.  
  4376. // Do not show the employees in the report whose PT is ZERO - KT - 9th March 2015
  4377. if($professional_tax > 0)
  4378. {
  4379. $output[] = array(
  4380. $employee_code,
  4381. $full_name,
  4382. $office_location_name,
  4383. $professional_tax,
  4384. );
  4385. }
  4386.  
  4387. }
  4388. }
  4389. $cols = array(
  4390. 'Employee Code',
  4391. 'Employee Name',
  4392. 'Location',
  4393. 'Professional Tax',
  4394. );
  4395.  
  4396.  
  4397.  
  4398. $roster_type = "payroll-PT-Report-month".$for_date;
  4399. $filenameexport = $roster_type;
  4400. $final_output = array('output' => $output,
  4401. 'cols' => $cols,
  4402. 'filenameexport' => $filenameexport);
  4403. return $final_output;
  4404. }
  4405.  
  4406. public static function getPFReportMonth($post_data, $tenant_id, $from, $to) {
  4407. $for_date = date('Y-m', strtotime($from));
  4408. $return = array();
  4409. $output = array();
  4410.  
  4411. $current_month = date("m");
  4412. $filter = $post_data['filter_id'];
  4413. $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
  4414. $tenantProfile = TenantProfile::model()->tenant($tenant_id)->find();
  4415. if(!empty($tenantProfile))
  4416. {
  4417. if(isset($tenantProfile->pf_edli) && $tenantProfile->pf_edli == TenantProfile::ACTIVE){
  4418. $edli_value = 6500;
  4419. }
  4420. else{
  4421. if(strtotime($for_date) > strtotime('2014-10')){
  4422. $edli_value = 15000;
  4423. }
  4424. else{
  4425. $edli_value = 6500;
  4426. }
  4427. }
  4428. }
  4429. foreach ($userSalarySlip as $salaryslip) {
  4430. $employees_contribution = 0;
  4431. $edli = 0;
  4432. $employees_contribution_pf = 0;
  4433. $total_pension = 0;
  4434. $voluntary_pf = 0;
  4435. $total_pf = 0;
  4436. $administartive_amount = 0;
  4437. $insurance_fund = 0;
  4438. $inspection_charges = 0;
  4439. $final_amount = 0;
  4440. $basic_eps = 0;
  4441. $accountnooneepf = 0;
  4442. $accountnotenepf = 0;
  4443. $accountnotwo = 0;
  4444. $accountnotwentyone = 0;
  4445. $accountnotwentytwo = 0;
  4446. //$users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  4447. if($post_data['active_inactive'] == 1)
  4448. {
  4449. $users = UserMongo::model()->tenant($tenant_id)->active()->findByPk($salaryslip->user_id);
  4450. }
  4451. else if($post_data['active_inactive'] == 2)
  4452. {
  4453. $users = UserMongo::model()->tenant($tenant_id)->disabled()->findByPk($salaryslip->user_id);
  4454. }
  4455. else
  4456. {
  4457. $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  4458. }
  4459. if (isset($users) && !empty($users)) {
  4460. $full_name = $users->getFullname();
  4461. $employee_id = (isset($users->personal->employee_no)) ? $users->personal->employee_no : "N.A.";
  4462. $doj = (isset($users->doj->sec))? date('d/m/Y', $users->doj->sec) : 'N.A.';
  4463. $date_of_exit = (isset($users->deactivate_date->sec))? date('d/m/Y', $users->deactivate_date->sec) : 'N.A.';
  4464. $date_of_exit_month = (isset($users->deactivate_date->sec))? date('Y-m', $users->deactivate_date->sec) : 'N.A.';
  4465. $dob = (isset($users->personal->dob->sec) && $users->personal->dob->sec != "") ? date('d/m/Y', $users->personal->dob->sec) : "N.A.";
  4466. $doj = (isset($users->doj->sec) && $users->doj->sec != "") ? date('d/m/Y', $users->doj->sec) : "N.A.";
  4467. $doj_month = (isset($users->doj->sec) && $users->doj->sec != "") ? date('Y-m', $users->doj->sec) : "N.A.";
  4468. $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
  4469. $gender = (isset($users->personal->gender) && $users->personal->gender == UserPersonal::GENDER_MALE) ? "M" : "F";
  4470. // Calculate Age from Date of Birth
  4471. // if($dob != '')
  4472. // {
  4473. // $from = new DateTime($dob);
  4474. // $to = new DateTime('today');
  4475. // $age = $from->diff($to)->y;
  4476. // }
  4477. // else
  4478. // {
  4479. // $age = 'N.A.';
  4480. // }
  4481.  
  4482. // Get employee father name.
  4483. $emp_father_name = '';
  4484. $emp_husband_name = '';
  4485. $display_realation_name = '';
  4486.  
  4487. if (isset($users->dependents) && count($users->dependents) > 0)
  4488. {
  4489. foreach ($users->dependents as $key => $value_dependent)
  4490. {
  4491. if ($value_dependent->relation_type == "Father")
  4492. {
  4493. $emp_father_first_name = (isset($value_dependent->first_name))? $value_dependent->first_name : '';
  4494. $emp_father_last_name = (isset($value_dependent->last_name))? $value_dependent->last_name : '';
  4495. $emp_father_name = $emp_father_first_name." ".$emp_father_last_name;
  4496. }
  4497. if ($value_dependent->relation_type == "Husband")
  4498. {
  4499. $emp_husband_first_name = (isset($value_dependent->first_name))? $value_dependent->first_name : '';
  4500. $emp_husband_last_name = (isset($value_dependent->last_name))? $value_dependent->last_name : '';
  4501. $emp_husband_name = $emp_father_first_name." ".$emp_father_last_name;
  4502. }
  4503. }
  4504. }
  4505. if(isset($emp_husband_name) && $emp_husband_name != ""){
  4506. $display_realation_name = (isset($emp_husband_name) && $emp_husband_name != "") ? $emp_husband_name : "N.A.";
  4507. $relation_type = 'S';
  4508. }else{
  4509. $display_realation_name = (isset($emp_father_name) && $emp_father_name != "") ? $emp_father_name : "N.A.";
  4510. $relation_type = (isset($emp_father_name) && $emp_father_name != "") ? 'F' : "N.A.";
  4511. }
  4512.  
  4513. $office_location = TenantOffices::model()->tenant($tenant_id)->findByAttributes(array('id' => $users->personal->office_location));
  4514. if (isset($office_location) && !empty($office_location) && isset($office_location->city) && $office_location->city != "") {
  4515. $city_name = City::model()->findByPk($office_location->city);
  4516. if (isset($city_name) && !empty($city_name)) {
  4517. $office_location_name = $city_name->name;
  4518. } else {
  4519. $office_location_name = "N.A";
  4520. }
  4521. } else {
  4522. $office_location_name = "N.A";
  4523. }
  4524. foreach ($salaryslip->items as $item) {
  4525. if ($item->variable_name == "basic") {
  4526. if(isset($tenantProfile->is_pf_restricted) && $tenantProfile->is_pf_restricted == TenantProfile::ACTIVE){
  4527. $basic = $item->max_value_month;
  4528. $basic = ($basic > 15000) ? 15000 : $basic;
  4529. }else{
  4530. $basic = $item->max_value_month;
  4531. }
  4532. }
  4533.  
  4534. if ($item->variable_name == "provident_fund") {
  4535. // basic basic_eps 3 conditions
  4536. // if age is greater than 58 years then 0 else basic
  4537. // if not existing PF member and basic > 15000 then basic_eps = 0
  4538. // if basic > 15000 then basic_eps = 15000 as max limit is 15000
  4539. $age = RandomHelper::CalculateAge(date('Y-m-d',$users->personal->dob->sec));
  4540. $basic_eps = $basic;
  4541. if($age > 58){
  4542. $basic_eps = 0;
  4543. }
  4544. if(isset($user->existing_pf_member) && $user->existing_pf_member == 0 && $basic > 15000){
  4545. $basic_eps = 0;
  4546. }
  4547. if($basic > 15000){
  4548. $basic_eps = 15000;
  4549. }
  4550. // basic basic_eps 3 conditions
  4551.  
  4552. $employees_contribution = $item->max_value_month;
  4553.  
  4554. $eps_contribution = ($basic_eps > 0) ? ($basic_eps * 8.33)/100 : 0;
  4555. $eps_contribution = PayrollHelper::roundingValues(Items::ROUND_TO_HIGEST_INTEGER,$eps_contribution);
  4556.  
  4557. $diff_epf_eps = $employees_contribution - $eps_contribution;
  4558.  
  4559. $lop_days = $salaryslip->lop;
  4560.  
  4561. $arrear_basic = 0; //differnece of basic after salary increment
  4562.  
  4563. $arrears_epf_wages = 0;
  4564.  
  4565. $arrears_epf_ee_wages = 0;
  4566.  
  4567. $arrears_epf_er_wages = 0;
  4568.  
  4569. $arrears_eps = 0;
  4570.  
  4571. if(strtotime($for_date) != strtotime($doj_month)){
  4572. $display_realation_name = "";
  4573. $relation_type = "";
  4574. $dob = "";
  4575. $gender = "";
  4576. $doj = "";
  4577. }
  4578. if(isset($date_of_exit) && strtotime($for_date) == strtotime($date_of_exit_month)){
  4579. $reason_of_exit = "C";
  4580. }else{
  4581. $date_of_exit = "";
  4582. $reason_of_exit = "";
  4583. }
  4584. // $employee_pf = (12 * $basic) / 100;
  4585. // $epf = ($employees_contribution/12) * 3.67;
  4586. // $eps = ($employees_contribution/12) * 8.33;
  4587. $lop_edli = 0;
  4588. if ($salaryslip->lop > 0) {
  4589. $lop_edli = ($edli_value / $salaryslip->total_working_days) * $salaryslip->lop;
  4590. } else {
  4591. $lop_edli = ($edli_value / $salaryslip->total_working_days) * ($salaryslip->total_working_days - $salaryslip->effective_working_days);
  4592. }
  4593.  
  4594. // Show E. D. L. I. is equal to BASIC if basic < 6500 - KT 9th March 2015
  4595. if($basic < $edli_value){
  4596. $edli = $basic;
  4597. }
  4598. else{
  4599. $edli = ($edli_value - $lop_edli);
  4600. }
  4601.  
  4602. // $total_pension = ($edli * 8.33) / 100;
  4603. // $employees_contribution_pf = ($employees_contribution - $total_pension);
  4604. // $voluntary_pf = 0;
  4605. // if(strtotime($for_date) >= strtotime('2015-01'))
  4606. // {
  4607. // $administartive_amount = ($basic * 0.85) / 100;
  4608. // }
  4609. // else{
  4610. // $administartive_amount = ($basic * 1.1) / 100;
  4611. // }
  4612. // $insurance_fund = ($edli * 0.5) / 100;
  4613. // $inspection_charges = ($edli * 0.01) / 100;
  4614. // $total_pf = $employees_contribution + $employees_contribution_pf + $total_pension + $voluntary_pf;
  4615. // $final_amount = $total_pf + $administartive_amount + $insurance_fund + $inspection_charges;
  4616. }
  4617. }
  4618.  
  4619. // Do not show the row if $employees_contribution is ZERO
  4620. if($employees_contribution > 0)
  4621. {
  4622.  
  4623. // Account no1 EPF(employee total pf + employeers diff btw epf and eps)
  4624. $accountnooneepf += ($employees_contribution + $diff_epf_eps);
  4625. // Account no1 EPF(employee total pf + employeers diff btw epf and eps)
  4626. //Account number 10 = sum of all emp EPS
  4627. $accountnotenepf += $eps_contribution;
  4628. //Account number 10 = sum of all emp EPS
  4629. //Account number 2 = PF admin charges
  4630. $accountnotwo += ($basic * 0.85) / 100;
  4631. //Account number 2 = PF admin charges
  4632. //Account number 21 = 0.5% on edli wages
  4633. $accountnotwentyone += ($edli * 0.5) / 100;
  4634. //Account number 21 = 0.5% on edli wages
  4635. //Account number 22 = 0.01% on edli wages
  4636. $accountnotwentytwo += ($edli * 0.01) / 100;
  4637. //Account number 22 = 0.01% on edli wages
  4638.  
  4639. $pf_account_number = (isset($users->pf_number) && $users->pf_number != null) ? $users->pf_number : "N.A.";
  4640. $employee_code_pf_exp = explode('/', $pf_account_number);
  4641. $employee_code_pf = (isset($employee_code_pf_exp[4]) && $employee_code_pf_exp[4] != "") ? $employee_code_pf_exp[4] : "";
  4642. $output[] = array(
  4643. $employee_id,
  4644. $employee_code_pf,
  4645. $full_name,
  4646. $basic,
  4647. $basic_eps,
  4648. $employees_contribution,
  4649. $employees_contribution,
  4650. $eps_contribution,
  4651. $eps_contribution,
  4652. $diff_epf_eps,
  4653. $diff_epf_eps,
  4654. $lop_days,
  4655. 0,
  4656. $arrears_epf_wages,
  4657. $arrears_epf_ee_wages,
  4658. $arrears_epf_er_wages,
  4659. $arrears_eps,
  4660. $display_realation_name,
  4661. $relation_type,
  4662. $dob,
  4663. $gender,
  4664. $doj,
  4665. $doj,
  4666. $date_of_exit,
  4667. $date_of_exit,
  4668. $reason_of_exit,
  4669. );
  4670. }
  4671. }
  4672. }
  4673. $cols = array(
  4674. 'Employee ID',
  4675. 'Employee Code',
  4676. 'Employee Name',
  4677. 'EPF Wages', //that month earned basic
  4678. 'EPS Wages', // basic amount 3 conditions
  4679. 'EPF Contribution (EE Share) due',
  4680. 'EPF Contribution (EE Share) being remitted',
  4681. 'EPS Contribution due',
  4682. 'EPS Contribution being remitted',
  4683. 'Diff EPF and EPS contribution (ER share) due',
  4684. 'Diff EPF and EPS contribution (ER share) being remitted',
  4685. 'NCP Days',
  4686. 'Refund Of Advances',
  4687. 'Arrear EPF Wages',
  4688. 'Arrear EPF EE share',
  4689. 'Arrear EPF ER share',
  4690. 'Arrear EPS',
  4691. 'Fathers/Husbands Name',
  4692. 'Relationship with the Member',
  4693. 'Date of Birth',
  4694. 'Gender',
  4695. 'Date of Joining EPF',
  4696. 'Date of Joining EPS',
  4697. 'Date of Exit EPF',
  4698. 'Date of Exit EPS',
  4699. 'Reason For Leaving',
  4700. );
  4701.  
  4702.  
  4703.  
  4704. $roster_type = "payroll-PF-Report-month".$for_date;
  4705. $filenameexport = $roster_type;
  4706. $final_output = array('output' => $output,
  4707. 'cols' => $cols,
  4708. 'filenameexport' => $filenameexport);
  4709. return $final_output;
  4710. }
  4711.  
  4712. public static function getSalaryRegisterMonth($post_data, $tenant_id, $from, $to) {
  4713. $for_date = date('Y-m', strtotime($from));
  4714. $return = array();
  4715. $output = array();
  4716. $index = 0;
  4717. $current_month = date("m");
  4718. $filter = $post_data['filter_id'];
  4719. $active_inactive = (!empty($post_data['active_inactive'])) ? $post_data['active_inactive'] : '';
  4720. /*get filter users*/
  4721. $filter_users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $active_inactive);
  4722. $filtered_users =array();
  4723. foreach ($filter_users as $key_filter_user => $value_filter_user) {
  4724. $filtered_users[] = $value_filter_user->id;
  4725. }
  4726. /*get filter users*/
  4727. /**/
  4728. $tenant_salary_structure = SalaryStructure::model()->tenant($tenant_id)->findAll();
  4729. foreach ($tenant_salary_structure as $salstructure) {
  4730. foreach ($salstructure->items as $key => $i) {
  4731. if($i->type == Items::ITEM_TYPE_INCOME){
  4732. $claims_to_be_made[] = array(
  4733. "id" => $i->id,
  4734. "label" => $i->label,
  4735. "variable_name" => $i->variable_name,
  4736. "declared_value" => 0.0,
  4737. "map_to" => $i->map_to,
  4738. );
  4739. }
  4740. }
  4741. }
  4742. foreach ($tenant_salary_structure as $salstructure) {
  4743. foreach ($salstructure->items as $key => $i) {
  4744. if($i->type == Items::ITEM_TYPE_BALANCING_INCOME){
  4745. $claims_to_be_made[] = array(
  4746. "id" => $i->id,
  4747. "label" => $i->label,
  4748. "variable_name" => $i->variable_name,
  4749. "declared_value" => 0.0,
  4750. "map_to" => $i->map_to,
  4751. );
  4752. }
  4753. }
  4754. }
  4755. $claims_to_be_made = array_map("unserialize", array_unique(array_map("serialize", $claims_to_be_made)));
  4756. $taken = array();
  4757. foreach ($claims_to_be_made as $key => $item) {
  4758. if (isset($item['variable_name']) && $item['variable_name'] != null) {
  4759. if (!in_array($item['variable_name'], $taken)) {
  4760. $taken[] = $item['variable_name'];
  4761. } else {
  4762. unset($claims_to_be_made[$key]);
  4763. }
  4764. }
  4765. }
  4766. /**/
  4767. $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
  4768. foreach ($userSalarySlip as $salaryslip) {
  4769. if(in_array($salaryslip->user_id, $filtered_users)){
  4770. //$users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  4771. if($active_inactive == 1)
  4772. {
  4773. $users = UserMongo::model()->tenant($tenant_id)->active()->findByPk($salaryslip->user_id);
  4774. }
  4775. else if($active_inactive == 2)
  4776. {
  4777. $users = UserMongo::model()->tenant($tenant_id)->disabled()->findByPk($salaryslip->user_id);
  4778. }
  4779. else
  4780. {
  4781. $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  4782. }
  4783. if (isset($users) && !empty($users)) {
  4784. $user_post = $users->getCurrentPosition($tenant_id);
  4785. $job_title = $user_post['designation'];
  4786. $department = $user_post['department'];
  4787. $business_unit = $user_post['business_unit'];
  4788. $full_name = $users->getFullname();
  4789. $date_of_joining = date('Y-m-d', $users->doj->sec);
  4790. $quit_date = (isset($users->deactivate_date->sec) && $users->deactivate_date->sec != "") ? date('Y-m-d', $users->deactivate_date->sec) : "N.A.";
  4791. $office_location = TenantOffices::model()->tenant($tenant_id)->findByAttributes(array('id' => $users->personal->office_location));
  4792. $state_value = (isset($office_location->state) && $office_location->state != "") ? $office_location->state : null;
  4793. $bank_account_number = (isset($users->banking->bank_account) && $users->banking->bank_account != "") ? $users->banking->bank_account : "N.A.";
  4794. $bank_name = (isset($users->banking->bank_name) && $users->banking->bank_name != "") ? $users->banking->bank_name : "N.A.";
  4795. $pan_number = (isset($users->banking->bank_pan_num) && $users->banking->bank_pan_num != "") ? $users->banking->bank_pan_num : "N.A.";
  4796. $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
  4797.  
  4798. if (isset($office_location) && !empty($office_location) && isset($office_location->city) && $office_location->city != "") {
  4799. $city_name = City::model()->findByPk($office_location->city);
  4800. if (isset($city_name) && !empty($city_name)) {
  4801. $office_location_name = $city_name->name;
  4802. } else {
  4803. $office_location_name = "N.A";
  4804. }
  4805. } else {
  4806. $office_location_name = "N.A";
  4807. }
  4808. $esic = 0;
  4809. $professional_tax = 0;
  4810. $hra = 0;
  4811. $conveyance = 0;
  4812. $special_allowance = 0;
  4813. $lta = 0;
  4814. $medical = 0;
  4815. $pf = 0;
  4816. $check_month = date('m',strtotime($salaryslip->for_month));
  4817. $get_final_value = array();
  4818. /**/
  4819. foreach ($salaryslip->items as $item) {
  4820. if ($item->variable_name == "professional_tax") {
  4821. //$professional_tax = $item->actual_value_month;
  4822. if($check_month == "02" && $state_value == "1927")
  4823. {
  4824. $professional_tax = (isset($state_value) && $state_value == "1927" && $item->actual_value_month != 300 && $item->actual_value_month > 0 && $item->actual_value_month != 175) ? $item->actual_value_month + 100 : $item->actual_value_month;
  4825. }
  4826. else{
  4827. $professional_tax =$item->actual_value_month;
  4828. }
  4829. }
  4830. if ($item->variable_name == "provident_fund") {
  4831. $pf =$item->actual_value_month;
  4832. }
  4833. if ($item->variable_name == "esic") {
  4834. $esic =$item->actual_value_month;
  4835. }
  4836. }
  4837. /**/
  4838. foreach ($claims_to_be_made as $key => $value) {
  4839. foreach ($salaryslip->items as $item) {
  4840. if($value['variable_name'] == $item->variable_name)
  4841. {
  4842. $get_final_value[$item->variable_name] = $item->actual_value_month;
  4843. }
  4844. }
  4845. }
  4846. $lwf = 0;
  4847. /*foreach ($claims_to_be_made as $key => $value) {
  4848. if($value['variable_name'] == "lwf"){
  4849. if (isset($salaryslip->lwf) && $salaryslip->lwf != null) {
  4850. $get_final_value['lwf'] = $salaryslip->lwf;
  4851. }
  4852. else{
  4853. $lwf = "N.A.";
  4854. }
  4855. }
  4856. }*/
  4857. $present_days = $salaryslip->effective_working_days;
  4858. $loan = (isset($salaryslip->loan_deduction)) ? $salaryslip->loan_deduction : 0;
  4859. if (isset($salaryslip->loan) && !empty($salaryslip->loan)) {
  4860. $loan = "";
  4861. foreach ($salaryslip->loan as $key => $value) {
  4862. $loan_name = UserLoan::model()->tenant()->findByPk($value['id']);
  4863. if(isset($loan_name) && !empty($loan_name)){
  4864. $amount = PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS,$value['loan_deduction']);
  4865. $loan = $loan .$loan_name->loan_name ." (" . $amount ."),";
  4866. }
  4867. }
  4868. $loan = rtrim($loan, ",");
  4869. }
  4870. $advance = (isset($salaryslip->advance_deduction)) ? $salaryslip->advance_deduction : 0;
  4871. /**/
  4872. if(isset($salaryslip->advance_deduction) && !empty($salaryslip->advance_deduction))
  4873. {
  4874. $advance = 0;
  4875. foreach ($salaryslip->advance_deduction as $key => $value) {
  4876. $advance_name = UserAdvances::model()->tenant()->findByPk($value['id']);
  4877. if(isset($advance_name) && !empty($advance_name)){
  4878. $amount = PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS,$value['amount']);
  4879. $advance = $advance .$advance_name->advance_name ." (" . $amount ."),";
  4880. }
  4881. }
  4882. if($advance != 0){
  4883. $advance = rtrim($advance, ",");
  4884. }
  4885. }
  4886. else{
  4887. $advance = 0;
  4888. }
  4889.  
  4890. /**/
  4891. //$total_days = $salaryslip->total_working_days;
  4892. //$present_days = $salaryslip->total_working_days;
  4893. // $base_salary = $salaryslip->total_gross;
  4894. // $bonus = $salaryslip->total_transactions;
  4895. // $gross_salary = $base_salary;
  4896.  
  4897. $base_salary = ($salaryslip->total_gross - $salaryslip->total_transactions);
  4898. if($salaryslip->total_working_days != $salaryslip->effective_working_days){
  4899. $base_salary = PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS,($base_salary/$salaryslip->effective_working_days) * $salaryslip->total_working_days);
  4900. }
  4901. $bonus = $salaryslip->total_transactions;
  4902. $gross_salary = $salaryslip->total_gross;
  4903.  
  4904. $incometax = $salaryslip->tds;
  4905.  
  4906. $total_deductions = $salaryslip->total_deductions + $incometax;
  4907. $net_salary = $gross_salary - $total_deductions;
  4908. $arrears_days = 0;
  4909.  
  4910. $output[] = array(
  4911. $employee_code,
  4912. $full_name,
  4913. $date_of_joining,
  4914. $quit_date,
  4915. $present_days,
  4916. $arrears_days,
  4917. $job_title,
  4918. $department,
  4919. $business_unit,
  4920. $office_location_name,
  4921. $bank_account_number,
  4922. $bank_name,
  4923. $base_salary,
  4924. $pan_number,
  4925. /*$basic,
  4926. $hra,
  4927. $conveyance,
  4928. $lta,
  4929. $medical,
  4930. $special_allowance,*/
  4931. /* $lta_taxable,
  4932. $lta_non_taxable,
  4933. $medical_taxable,
  4934. $medical_non_taxable, */
  4935.  
  4936. );
  4937. /*echo "<pre>"; print_r($get_final_value); exit("\n exited in " . __FILE__ . " @ " . __LINE__. "</pre>");
  4938. $matching_records = array();
  4939. foreach ($claims_to_be_made as $key_claims => $value_claims)
  4940. {
  4941. foreach ($get_final_value as $key_final_value => $value_final_value) {
  4942. if($key_final_value == $value_claims['variable_name']){
  4943. $matching_records[$value_claims['variable_name']] = $value_final_value;
  4944. }
  4945. }
  4946. }*/
  4947. $count_of_claims = count($claims_to_be_made);
  4948. $claims_key_value_array = array();
  4949. $diff_in_two_arrays = array();
  4950. $tempArray = array();
  4951. foreach ($claims_to_be_made as $key_make_new => $value_make_new) {
  4952. $claims_key_value_array[$value_make_new['variable_name']] = $value_make_new['variable_name'];
  4953. }
  4954. $diff_in_two_arrays = array_diff_key($claims_key_value_array, $get_final_value);
  4955. if(isset($diff_in_two_arrays) && !empty($diff_in_two_arrays))
  4956. {
  4957. foreach ($diff_in_two_arrays as $key => $value) {
  4958. $get_final_value[$key] = 0;
  4959. }
  4960. }
  4961. foreach ($get_final_value as $key_fv => $value) {
  4962. foreach(array_keys($claims_key_value_array) as $key)
  4963. {
  4964. $tempArray[$key] = $get_final_value[$key];
  4965. }
  4966. $get_final_value = $tempArray;
  4967. }
  4968. /*foreach ($sal_str_deduction as $key_income => $value_income) {
  4969. $abc = count($value_income);
  4970. if($abc != 12)
  4971. {
  4972. $i = 1;
  4973. foreach ($month_list as $key => $value) {
  4974. if($i <= (12 - $abc)){
  4975. $sal_str_deduction[$key_income][$key] = 0.00;
  4976. $i++;
  4977. }
  4978. }
  4979. }
  4980. foreach(array_keys($month_list) as $key)
  4981. {
  4982. $tempArray[$key] = $sal_str_deduction[$key_income][$key];
  4983. }
  4984. $sal_str_deduction[$key_income] = $tempArray;
  4985. }*/
  4986.  
  4987. foreach ($get_final_value as $key_matching => $value_matching) {
  4988. array_push($output[$index], (isset($value_matching)) ? $value_matching : 0);
  4989. }
  4990. //array_push($output[$index],$base_salary);
  4991. array_push($output[$index],$bonus);
  4992. array_push($output[$index],$gross_salary);
  4993. array_push($output[$index],$incometax);
  4994. array_push($output[$index],$professional_tax);
  4995. array_push($output[$index],$esic);
  4996. array_push($output[$index],$pf);
  4997. array_push($output[$index],$lwf);
  4998. array_push($output[$index],$loan);
  4999. array_push($output[$index],$advance);
  5000. array_push($output[$index],$total_deductions);
  5001. array_push($output[$index],$net_salary);
  5002. $index++;
  5003. //echo "<pre>"; print_r($output); exit("\n exited in " . __FILE__ . " @ " . __LINE__. "</pre>");
  5004. }
  5005. }
  5006. }
  5007. $cols = array(
  5008. 'Employee Code',
  5009. 'Employee Name',
  5010. 'Joining Date',
  5011. 'Quit Date',
  5012. 'Present Days',
  5013. 'Arrears Days',
  5014. 'Designation',
  5015. 'Department',
  5016. 'Business Unit',
  5017. 'Location',
  5018. 'Saving Account Number',
  5019. 'Bank Name',
  5020. 'Base Salary',
  5021. 'PAN Number',
  5022. /*'Basic Salary',
  5023. 'House Rent Allowances',
  5024. 'Conveyance Allowances',
  5025. 'LTA',
  5026. 'Medical',
  5027. 'Special Allowances',*/
  5028. /* 'LT Expenses Taxable',
  5029. 'LT Expenses Allowance',
  5030. 'Medical Taxable',
  5031. 'Medical Non Taxable', */
  5032.  
  5033. );
  5034. foreach ($claims_to_be_made as $value) {
  5035. $finaldatacols = $value['label'];
  5036. array_push($cols, $finaldatacols);
  5037. }
  5038.  
  5039. //array_push($cols,'Base Salary');
  5040. array_push($cols,'Bonus');
  5041. array_push($cols,'Gross Salary');
  5042. array_push($cols,'Income Tax');
  5043. array_push($cols,'Professional Tax');
  5044. array_push($cols,'Statutory ESIC');
  5045. array_push($cols,'Statutory PF');
  5046. array_push($cols,'LWF');
  5047. array_push($cols,'Loan');
  5048. array_push($cols,'Advance');
  5049. array_push($cols,'Total Deduction');
  5050. array_push($cols,'Net Salary');
  5051. $roster_type = "payroll-Salary-Register-month-" .$for_date;
  5052. $filenameexport = $roster_type;
  5053. $final_output = array('output' => $output,
  5054. 'cols' => $cols,
  5055. 'filenameexport' => $filenameexport);
  5056. return $final_output;
  5057. }
  5058.  
  5059. public static function getESICReportMonth($post_data, $tenant_id, $from, $to)
  5060. {
  5061. $tenant_profile = TenantProfile::model()->tenant()->find();
  5062. $cal_esic_on_gross = (isset($tenant_profile->cal_esic_on_gross))? $tenant_profile->cal_esic_on_gross : 0;
  5063.  
  5064. $for_date = date('Y-m', strtotime($from));
  5065. $return = array();
  5066. $output = array();
  5067. $employees_contribution = "N.A.";
  5068. $employeers_contribution = "N.A.";
  5069. $total = "N.A.";
  5070. $total_no_days = "N.A.";
  5071. $current_month = date("m");
  5072. $filter = $post_data['filter_id'];
  5073. $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
  5074. foreach ($userSalarySlip as $salaryslip) {
  5075.  
  5076. //$users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  5077. if($post_data['active_inactive'] == 1)
  5078. {
  5079. $users = UserMongo::model()->tenant($tenant_id)->active()->findByPk($salaryslip->user_id);
  5080. }
  5081. else if($post_data['active_inactive'] == 2)
  5082. {
  5083. $users = UserMongo::model()->tenant($tenant_id)->disabled()->findByPk($salaryslip->user_id);
  5084. }
  5085. else
  5086. {
  5087. $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  5088. }
  5089.  
  5090. // Getting user gross salary - 9th March 2015
  5091. $gross_salary = $salaryslip->total_gross;
  5092.  
  5093. $total_transactions = (isset($salaryslip->total_transactions))? $salaryslip->total_transactions : 0;
  5094. // Minus Extra payment from gross salary if any
  5095. if($total_transactions > 0)
  5096. {
  5097. $gross_salary = $gross_salary - $total_transactions;
  5098. }
  5099.  
  5100. if (isset($users) && !empty($users)) {
  5101. $cal_esic = false;
  5102. foreach ($salaryslip->items as $item) {
  5103. /* if ($item->type == Items::ITEM_TYPE_INCOME) {
  5104. $all_items_total += $item->actual_value_month;
  5105. } */
  5106. if ($item->variable_name == "esic") {
  5107. $cal_esic = true;
  5108. $employees_contribution_sal = $item->actual_value_month;
  5109. }
  5110. if ($item->variable_name == "basic") {
  5111. $basic = $item->actual_value_month;
  5112. }
  5113. if($item->variable_name == 'provident_fund')
  5114. {
  5115. $pf = $item->actual_value_month;
  5116. }
  5117. }
  5118. if ($cal_esic) {
  5119. $all_items_total = 0;
  5120. $full_name = $users->getFullname();
  5121. $doj = date('Y-m-d', $users->doj->sec);
  5122. $office_location = TenantOffices::model()->tenant($tenant_id)->findByAttributes(array('id' => $users->personal->office_location));
  5123. $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
  5124. if (isset($office_location) && !empty($office_location) && isset($office_location->city) && $office_location->city != "") {
  5125. $city_name = City::model()->findByPk($office_location->city);
  5126. if (isset($city_name) && !empty($city_name)) {
  5127. $office_location_name = $city_name->name;
  5128. } else {
  5129. $office_location_name = "N.A";
  5130. }
  5131. } else {
  5132. $office_location_name = "N.A";
  5133. }
  5134.  
  5135. $employees_contribution = $employees_contribution_sal;
  5136. $original_esic = $employees_contribution / 0.0175;
  5137. $employeers_contribution = number_format($original_esic * 0.0475);
  5138. $total = number_format($employees_contribution + $employeers_contribution);
  5139.  
  5140. // Calculate "GROSS + PF (Employeer) + EMPLOYEERS ESIC"
  5141. // If checkbox in Payroll setting is checked for "Calculate ESIC on Gross" - KT - 9th March 2015
  5142. if($cal_esic_on_gross == TenantProfile::ACTIVE)
  5143. {
  5144. $gross_salary = $gross_salary + $pf + $employeers_contribution;
  5145. }
  5146.  
  5147. $esic_account_number = (isset($users->esic_number) && $users->esic_number != null) ? $users->esic_number : "N.A.";
  5148. $total_no_days = (isset($salaryslip->effective_working_days)) ? $salaryslip->effective_working_days : "N.A.";
  5149. $output[] = array(
  5150. $employee_code,
  5151. $full_name,
  5152. $doj,
  5153. $office_location_name,
  5154. $esic_account_number,
  5155. $total_no_days,
  5156. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $gross_salary),
  5157. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $employees_contribution),
  5158. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $employeers_contribution),
  5159. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $total),
  5160. );
  5161. }
  5162. }
  5163. }
  5164. $cols = array(
  5165. 'Employee Code',
  5166. 'Employee Name',
  5167. 'Date Of Joining',
  5168. 'Location',
  5169. 'ESIC Account No',
  5170. 'Number Of Working Days',
  5171. 'Gross',
  5172. 'Employees Contribution',
  5173. 'Employeers Contribution',
  5174. 'Total',
  5175. );
  5176.  
  5177.  
  5178.  
  5179. $roster_type = "Payroll-ESIC-Report-month".$for_date;
  5180. $filenameexport = $roster_type;
  5181. $final_output = array('output' => $output,
  5182. 'cols' => $cols,
  5183. 'filenameexport' => $filenameexport);
  5184. return $final_output;
  5185. }
  5186.  
  5187. public static function getAttendanceSummaryRosterPayroll($post_data, $tenant_id = null, $from = null, $to = null) {
  5188. $return = array();
  5189. $index = 0;
  5190. $output = array();
  5191. $finaldata = array();
  5192. $final_output = array();
  5193. $filter = $post_data['filter_id'];
  5194. $users = RunPayroll::getWithoutFNFUsers($filter, $tenant_id, $post_data['month_year']);
  5195.  
  5196. $begin = new DateTime($from);
  5197. $end = new DateTime($to);
  5198. $end = $end->modify('+1 day');
  5199. $interval = new DateInterval('P1D');
  5200. $daterange = new DatePeriod($begin, $interval, $end);
  5201. $from = strtotime($from);
  5202. $to = strtotime($to);
  5203.  
  5204. $criteria = new EMongoCriteria();
  5205. $criteria->shift_date('>=', new MongoDate($from));
  5206. $criteria->shift_date('<=', new MongoDate($to));
  5207. foreach ($users as $key => $user) {
  5208. if (!isset($user->fandf_done) || ($user->fandf_done != USermongo::PROCESS_FANDF_PENDING && $user->fandf_done != Usermongo::STATUS_NOACTIVE && $user->fandf_done != Usermongo::PROCESS_FANDF_ACTIVE)) {
  5209. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  5210. $criteria->user_id = $user->id;
  5211. $userAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
  5212. //echo "<pre>"; print_r($userAttendanceLogs); exit("</pre> \n exited here \n");
  5213. $present = 0;
  5214. $absent = 0;
  5215. $weeklyoff_count = 0;
  5216. $holiday_count = 0;
  5217. $leave_count = 0;
  5218. $unpaidleave_count = 0;
  5219. $return = array();
  5220. $output[] = array(
  5221. $user_name,
  5222. );
  5223. $jindex = 0;
  5224. foreach ($daterange as $date) {
  5225. $unpaidFlag = false;
  5226. if (isset($userAttendanceLogs[$jindex])) {
  5227. if ($date->format("d") == date("d", $userAttendanceLogs[$jindex]->shift_date->sec)) {
  5228. $date = date("d", $userAttendanceLogs[$jindex]->shift_date->sec);
  5229. if (isset($userAttendanceLogs[$jindex]->attendance_status)) {
  5230. $status = $userAttendanceLogs[$jindex]->attendance_status;
  5231.  
  5232. if ($status == UserAttendance::ATTENDANCE_STATUS_ABSENT) {
  5233. $status = UserAttendanceLog::ATTENDANCE_STATUS_ABSENT;
  5234. } elseif ($status == UserAttendance::ATTENDANCE_STATUS_PRESENT) {
  5235. $status = UserAttendanceLog::ATTENDANCE_STATUS_PRESENT;
  5236. }
  5237. $weeklyoff = $userAttendanceLogs[$jindex]->is_weekly_off->status;
  5238. $holiday = $userAttendanceLogs[$jindex]->is_holiday->status;
  5239. $leave = $userAttendanceLogs[$jindex]->in_leave->status;
  5240. if (isset($userAttendanceLogs[$jindex]->in_leave->leave_id)) {
  5241. $unpaidLeave = UserLeaves::model()->findByPk($userAttendanceLogs[$jindex]->in_leave->leave_id);
  5242. if (isset($unpaidLeave) && $unpaidLeave != null) {
  5243. if ($unpaidLeave->isUnpaid == UserLeaves::LEAVE_UNPAID) {
  5244. $unpaidleave_count++;
  5245. $unpaidFlag = true;
  5246. } else {
  5247. $unpaidFlag = false;
  5248. }
  5249. }
  5250. } else {
  5251. $unpaidFlag = false;
  5252. }
  5253. if (isset($weeklyoff) && $weeklyoff == "1") {
  5254. $status = "W";
  5255. $weeklyoff_count++;
  5256. } elseif (isset($holiday) && $holiday == "1") {
  5257. $status = "H";
  5258. $holiday_count++;
  5259. } elseif (isset($leave) && $leave == "1") {
  5260. $status = "L";
  5261. $leave_count++;
  5262. } elseif ($status == UserAttendanceLog::ATTENDANCE_STATUS_PRESENT || $status == UserAttendanceLog::ATTENDANCE_STATUS_PENDING) {
  5263. $status = "P";
  5264. $present++;
  5265. } /* elseif ($status == UserAttendanceLog::ATTENDANCE_STATUS_PENDING) {
  5266. $status = "n";
  5267. } */ elseif ($status == UserAttendanceLog::ATTENDANCE_STATUS_ABSENT || $status == UserAttendance::ATTENDANCE_STATUS_ABSENT) {
  5268. $status = "A";
  5269. $absent++;
  5270. } else {
  5271. $status = "";
  5272. }
  5273. } else {
  5274. $status = "";
  5275. }
  5276. $jindex++;
  5277. } else {
  5278. $status = "-";
  5279. }
  5280. } else {
  5281. $status = "-";
  5282. }
  5283. if ($unpaidFlag) {
  5284. $status = "U";
  5285. }
  5286. array_push($output[$index], $status);
  5287. } // my good loop
  5288.  
  5289. array_push($output[$index], $present);
  5290. array_push($output[$index], $absent);
  5291. array_push($output[$index], $weeklyoff_count);
  5292. array_push($output[$index], $leave_count);
  5293. array_push($output[$index], $unpaidleave_count);
  5294. $index++;
  5295. } // EOF foreach all user
  5296. $flag = true;
  5297. $cols = array(
  5298. // 'Name||Column displays the Name of the employees.'
  5299. 'Name||Column displays the Name of the employees.'
  5300. );
  5301.  
  5302. foreach ($daterange as $date) {
  5303. $finaldatacols = $date->format("d") . "<br>" . substr((String) $date->format("D"), 0, 2);
  5304. array_push($cols, $finaldatacols);
  5305. }
  5306.  
  5307. array_push($cols, 'P||Column displays the total number days when an employee was Present in the specified duration.');
  5308. array_push($cols, 'A||Column displays the total number of days when an employee was Absent in the specified duration.');
  5309. array_push($cols, 'W||Column displays the total number of Weekly Offs assigned to an employee in the specified duration.');
  5310. array_push($cols, 'L||Column displays the total number of days when an employee was on a Leave in the specified duration.');
  5311. array_push($cols, 'U||Column displays the total number of days when an employee was on a Unpaid Leave in the specified duration.');
  5312.  
  5313. $roster_type = "Attendance-Summary";
  5314. $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
  5315. $filenameexport = $roster_type . "_" . $date;
  5316. $final_output = array('output' => $output,
  5317. 'cols' => $cols,
  5318. 'filenameexport' => $filenameexport);
  5319. }
  5320. return $final_output;
  5321. }
  5322.  
  5323. public static function getMasterCtcReport($post_data, $tenant_id, $from, $to) {
  5324. $for_date = date('Y-m', strtotime($from));
  5325. $return = array();
  5326. $output = array();
  5327.  
  5328. $current_month = date("m");
  5329. $filter = $post_data['filter_id'];
  5330. $gratuity_show = false;
  5331. /**/
  5332. $tenant_salary_structure = SalaryStructure::model()->tenant($tenant_id)->findAll();
  5333. foreach ($tenant_salary_structure as $salstructure) {
  5334. foreach ($salstructure->items as $key => $i) {
  5335. if($i->variable_name == "gratuity")
  5336. {
  5337. $gratuity_show = true;
  5338. }
  5339. $claims_to_be_made[] = array(
  5340. "id" => $i->id,
  5341. "label" => $i->label,
  5342. "variable_name" => $i->variable_name,
  5343. "declared_value" => 0.0,
  5344. "map_to" => $i->map_to
  5345. );
  5346. }
  5347. }
  5348. $claims_to_be_made = array_map("unserialize", array_unique(array_map("serialize", $claims_to_be_made)));
  5349. /**/
  5350. //$users_all = UserMongo::model()->tenant($tenant_id)->findAll();
  5351. $users_all = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  5352. foreach ($users_all as $users) {
  5353. if (isset($users) && !empty($users)) {
  5354. $user_sql = UserMongoView::model()->tenant($tenant_id)->findByAttributes(array('user_id'=>$users->user_id));
  5355. if (isset($user_sql) && !empty($user_sql)) {
  5356. $email_id_sql = (isset($user_sql->email) && $user_sql->email != "") ? $user_sql->email : "N.A.";
  5357. } else {
  5358. $email_id_sql = "N.A.";
  5359. }
  5360. $user_post = $users->getCurrentPosition($tenant_id);
  5361. $job_title = $user_post['designation'];
  5362. $department = $user_post['department'];
  5363. $business_unit = $user_post['business_unit'];
  5364. if (isset($users->personal->gender) && $users->personal->gender != "") {
  5365. $gender = ($users->personal->gender == "1") ? "Male" : "Female";
  5366. } else {
  5367. $gender = "N.A.";
  5368. }
  5369. $dob = (isset($users->personal->dob->sec) && $users->personal->dob->sec != "") ? date('Y-m-d', $users->personal->dob->sec) : "N.A.";
  5370. if (isset($users->dependents) && count($users->dependents) > 0) {
  5371. foreach ($users->dependents as $key => $value_dependent) {
  5372. if ($value_dependent->relation_type == "Father") {
  5373. $emp_father_name = $value_dependent->first_name;
  5374. }
  5375. }
  5376. }
  5377. $emp_father_name = (isset($emp_father_name) && $emp_father_name != "") ? $emp_father_name : "N.A.";
  5378. $full_name = $users->getFullname();
  5379. $date_of_joining = date('Y-m-d', $users->doj->sec);
  5380. $quit_date = (isset($users->deactivate_date->sec) && $users->deactivate_date->sec != "") ? date('Y-m-d', $users->deactivate_date->sec) : "N.A.";
  5381. $office_location = TenantOffices::model()->tenant($tenant_id)->findByAttributes(array('id' => $users->personal->office_location));
  5382. $bank_account_number = (isset($users->banking->bank_account) && $users->banking->bank_account != "") ? $users->banking->bank_account : "N.A.";
  5383. $bank_name = (isset($users->banking->bank_name) && $users->banking->bank_name != "") ? $users->banking->bank_name : "N.A.";
  5384. $pan_number = (isset($users->banking->bank_pan_num) && $users->banking->bank_pan_num != "") ? $users->banking->bank_pan_num : "N.A.";
  5385. $pf_number = (isset($users->pf_number) && $users->pf_number != "") ? $users->pf_number : "N.A.";
  5386. $esic_number = (isset($users->esic_number) && $users->esic_number != "") ? $users->esic_number : "N.A.";
  5387. $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
  5388. if (isset($office_location) && !empty($office_location) && isset($office_location->city) && $office_location->city != "") {
  5389. $city_name = City::model()->findByPk($office_location->city);
  5390. if (isset($city_name) && !empty($city_name)) {
  5391. $office_location_name = $city_name->name;
  5392. } else {
  5393. $office_location_name = "N.A";
  5394. }
  5395. } else {
  5396. $office_location_name = "N.A";
  5397. }
  5398. /**/
  5399. $for_month = date('Y-m');
  5400. $year = date('Y');
  5401. $month = ($year + 1) . "-03";
  5402. $where = "1";
  5403. $taxCalculator = new TaxCalculator($users->id, $tenant_id, $year, $month, 0.0, $where);
  5404. $professional_tax = 0;
  5405. $deduction_total = $taxCalculator->getItemsTotal(Items::ITEM_TYPE_DEDUCTIONS);
  5406. foreach ($deduction_total as $key => $value) {
  5407. $professional_tax += $value['professional_tax'];
  5408. foreach ($value as $keys => $value_name) {
  5409. if ($keys == "professional_tax") {
  5410. $office_location = TenantOffices::model()->findByPk($users->personal->office_location);
  5411. if ($office_location->state == "1927" && date('m', strtotime($key)) == "02") {
  5412. $professional_tax = (isset($professional_tax) && $professional_tax > 0) ? $professional_tax + 100 : 0;
  5413. } elseif ($office_location->state == "1926" && date('m', strtotime($key)) == "03") {
  5414. $professional_tax = (isset($professional_tax) && $professional_tax > 0) ? $professional_tax + 4 : 0;
  5415. }
  5416. }
  5417. }
  5418. }
  5419.  
  5420.  
  5421. $salaryCalculator = new SalCalculator($users->id, $tenant_id, $for_month, '', '', '', 1);
  5422. $ctc_proration = $salaryCalculator->userSalarySlip;
  5423. if (isset($ctc_proration) && !empty($ctc_proration)) {
  5424. $basic = 0;
  5425. $hra = 0;
  5426. $conveyance = 0;
  5427. $medical = 0;
  5428. $lta = 0;
  5429. $special_allowance = 0;
  5430. $base_salary = 0;
  5431. $bonus = 0;
  5432. $gross_salary = 0;
  5433. $incometax = 0;
  5434. //$professional_tax = 0;
  5435. $esic = 0;
  5436. $pf = 0;
  5437. $total_deductions = 0;
  5438. $net_salary = 0;
  5439. $esic_is_yes_no = 'No';
  5440. $bonus_allowance = 0;
  5441. $laptop_allowance = 0;
  5442. foreach ($ctc_proration->items as $item) {
  5443. /* if ($item->variable_name == "professional_tax") {
  5444. $professional_tax = $item->max_value_month;
  5445. } */
  5446. if ($item->variable_name == "basic") {
  5447. $basic = $item->max_value_year;
  5448. }
  5449. if ($item->variable_name == "hra") {
  5450. $hra = $item->max_value_year;
  5451. }
  5452. if ($item->variable_name == "conveyance") {
  5453. $conveyance = $item->max_value_year;
  5454. }
  5455. if ($item->variable_name == "special_allowance") {
  5456. $special_allowance = $item->max_value_year;
  5457. }
  5458. if ($item->variable_name == "lta") {
  5459. $lta = $item->max_value_year;
  5460. }
  5461. if ($item->variable_name == "medical") {
  5462. $medical = $item->max_value_year;
  5463. }
  5464. if ($item->variable_name == "provident_fund") {
  5465. $pf = $item->max_value_year;
  5466. }
  5467. if ($item->variable_name == "esic") {
  5468. $esic_is_yes_no = 'Yes';
  5469. $esic = $item->max_value_year;
  5470. }
  5471. if ($item->variable_name == "bonus_allowance") {
  5472. $bonus_allowance = $item->max_value_year;
  5473. }
  5474. if ($item->variable_name == "laptop_allowance") {
  5475. $laptop_allowance = $item->max_value_year;
  5476. }
  5477. }
  5478. } else {
  5479. $esic_is_yes_no = 'No';
  5480. $basic = "N.A.";
  5481. $hra = "N.A.";
  5482. $conveyance = "N.A.";
  5483. $medical = "N.A.";
  5484. $lta = "N.A.";
  5485. $special_allowance = "N.A.";
  5486. $base_salary = "N.A.";
  5487. $bonus = "N.A.";
  5488. $gross_salary = "N.A.";
  5489. $incometax = "N.A.";
  5490. $professional_tax = "N.A.";
  5491. $esic = "N.A.";
  5492. $pf = "N.A.";
  5493. $total_deductions = "N.A.";
  5494. $net_salary = "N.A.";
  5495. $bonus_allowance = "N.A.";
  5496. $laptop_allowance = "N.A.";
  5497. }
  5498. if($gratuity_show && $basic > 0)
  5499. {
  5500. $gratuity = $basic * 0.0481;
  5501. }
  5502. else{
  5503. $gratuity = "N.A.";
  5504. }
  5505. /**/
  5506. $basic = (isset($basic)) ? $basic : "N.A.";
  5507. $hra = (isset($hra)) ? $hra : "N.A.";
  5508. $conveyance = (isset($conveyance)) ? $conveyance : "N.A.";
  5509. $special_allowance = (isset($special_allowance)) ? $special_allowance : "N.A.";
  5510. $lta = (isset($lta)) ? $lta : "N.A.";
  5511. $medical = (isset($medical)) ? $medical : "N.A.";
  5512. $pf = (isset($pf)) ? $pf : "N.A.";
  5513. $base_salary = $salaryslip->total_gross;
  5514. $gross_salary = $base_salary + $bonus;
  5515. $incometax = $salaryslip->tds;
  5516. $esic = (isset($esic) && $esic != "") ? $esic : 0;
  5517. $bonus_allowance = (isset($bonus_allowance) && $bonus_allowance != "") ? $bonus_allowance : 0;
  5518. $laptop_allowance = (isset($laptop_allowance) && $laptop_allowance != "") ? $laptop_allowance : 0;
  5519. $total_ctc = $ctc_proration->ctc;
  5520.  
  5521. $output[] = array(
  5522. $employee_code,
  5523. $full_name,
  5524. $date_of_joining,
  5525. $gender,
  5526. $dob,
  5527. $quit_date,
  5528. $job_title,
  5529. $department,
  5530. $business_unit,
  5531. $office_location_name,
  5532. $bank_account_number,
  5533. $bank_name,
  5534. $pan_number,
  5535. $pf_number,
  5536. $esic_number,
  5537. $email_id_sql,
  5538. $esic_is_yes_no,
  5539. $emp_father_name,
  5540. $basic,
  5541. $hra,
  5542. $conveyance,
  5543. $medical,
  5544. $lta,
  5545. $bonus_allowance,
  5546. $laptop_allowance,
  5547. $gratuity,
  5548. $special_allowance,
  5549. // $professional_tax,
  5550. $esic,
  5551. $pf,
  5552. $total_ctc,
  5553. );
  5554. }
  5555. }
  5556. $cols = array(
  5557. 'Employee Code',
  5558. 'Employee Name',
  5559. 'Joining Date',
  5560. 'Gender',
  5561. 'Date Of Birth',
  5562. 'Quit Date',
  5563. 'Designation',
  5564. 'Department',
  5565. 'Business Unit',
  5566. 'Location',
  5567. 'Saving Account Number',
  5568. 'Bank Name',
  5569. 'PAN Number',
  5570. 'PF Number',
  5571. 'ESIC Number',
  5572. 'Office Email',
  5573. 'ESIC Y N',
  5574. 'Emp Fathers Name',
  5575. 'Basic',
  5576. 'House Rent Allowances',
  5577. 'Conveyance Allowances',
  5578. 'Medical',
  5579. 'LTA',
  5580. 'Bonus Allowance',
  5581. 'Laptop Allowance',
  5582. 'Gratuity',
  5583. 'Special Allowances',
  5584. //'Professional Tax',
  5585. 'Statutory ESIC',
  5586. 'Statutory PF',
  5587. 'Total Ctc',
  5588. );
  5589.  
  5590.  
  5591.  
  5592. $roster_type = "payroll-Master-Ctc-Report".$for_date;
  5593. $filenameexport = $roster_type;
  5594. $final_output = array('output' => $output,
  5595. 'cols' => $cols,
  5596. 'filenameexport' => $filenameexport);
  5597. return $final_output;
  5598. }
  5599.  
  5600. public static function getHeadCountMonth($post_data, $tenant_id, $from, $to) {
  5601. //$for_date = date('Y-m', strtotime($from));
  5602. $for_month = date('m', strtotime($from));
  5603. $end_month = date('m', strtotime($to));
  5604. $for_year = date('Y', strtotime($from));
  5605. $end_year = date('Y', strtotime($to));
  5606. $for_month_previous = $for_month - "01";
  5607. if ($for_month_previous == 0) {
  5608. $for_month_previous = $for_month_previous + "12";
  5609. }
  5610. $end_month_previous = $end_month - "01";
  5611. if ($end_month_previous == 0) {
  5612. $end_month_previous = $end_month_previous + "12";
  5613. }
  5614. if ($for_month_previous > 9 && $end_month_previous > 9) {
  5615. $final_previous_date_for = "01-" . $for_month_previous . "-" . $for_year;
  5616. $final_previous_date_end = "31-" . $end_month_previous . "-" . $end_year;
  5617. } else {
  5618. $final_previous_date_for = "01-0" . $for_month_previous . "-" . $for_year;
  5619. $final_previous_date_end = "31-0" . $end_month_previous . "-" . $end_year;
  5620. }
  5621. $return = array();
  5622. $output = array();
  5623. $current_month = date("m");
  5624. $filter = $post_data['filter_id'];
  5625. $total_hc = 0;
  5626. $total_seprated = 0;
  5627. $total_added = 0;
  5628. $previous_hc = 0;
  5629. $total_seprated_previous_month = 0;
  5630. $users_all = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  5631. $users_all_inactive = UserMongo::model()->getUsersByFilter($filter, $tenant_id, 10); //passing 10 as a parameter to get all active and inactive employee
  5632. if (isset($users_all) && !empty($users_all)) {
  5633. foreach ($users_all as $users) {
  5634. if (isset($users->created->sec) && $users->created->sec >= strtotime($from) && $users->created->sec <= strtotime($to)) {
  5635. $total_added = $total_added + 1;
  5636. }
  5637. if (isset($users->created->sec) && $users->created->sec < strtotime($from)) {
  5638. $previous_hc = $previous_hc + 1;
  5639. }
  5640. }
  5641. }
  5642. if (isset($users_all_inactive) && !empty($users_all_inactive)) {
  5643. foreach ($users_all_inactive as $users_inactive) {
  5644. if (isset($users_inactive->deactivate_date->sec) && $users_inactive->deactivate_date->sec >= strtotime($from) && $users_inactive->deactivate_date->sec <= strtotime($to)) {
  5645. $total_seprated = $total_seprated + 1;
  5646. }
  5647.  
  5648. if (isset($users->created->sec) && $users->created->sec <= strtotime($from)) {
  5649. $previous_hc = $previous_hc + 1;
  5650. }
  5651. if (isset($users_inactive->deactivate_date->sec) && $users_inactive->deactivate_date->sec <= strtotime($final_previous_date_end)) {
  5652. $total_seprated_previous_month = $total_seprated_previous_month + 1;
  5653. }
  5654. }
  5655. }
  5656. $total_hc = (($previous_hc - $total_seprated_previous_month) + $total_added) - $total_seprated;
  5657. $output[] = array(
  5658. ($previous_hc - $total_seprated_previous_month),
  5659. $total_added,
  5660. $total_seprated,
  5661. $total_hc,
  5662. );
  5663. $cols = array(
  5664. 'Opening Head Count',
  5665. 'Addition',
  5666. 'Sepration',
  5667. 'Closing Head Count',
  5668. );
  5669.  
  5670.  
  5671.  
  5672. $roster_type = "payroll-Monthly-Head-Count-Annual";
  5673. $filenameexport = $roster_type;
  5674. $final_output = array('output' => $output,
  5675. 'cols' => $cols,
  5676. 'filenameexport' => $filenameexport);
  5677. return $final_output;
  5678. }
  5679.  
  5680. public static function getLeavesEncashmentBalance($post_data, $tenant_id = null, $from = null, $to = null) {
  5681. //$tenat_leave = Leaves::model()->tenant($tenant_id)->findAll();
  5682. //echo "<pre>"; print_r($tenat_leave); exit("\n exited in " . __FILE__ . " @ " . __LINE__. "</pre>");
  5683. $return = array();
  5684. //$sr_no=1;
  5685. $filter = $post_data['filter_id'];
  5686. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  5687. $output = array();
  5688. $leaves = Leaves::model()->getTenantLeaveList($tenant_id);
  5689.  
  5690. $index = 0;
  5691. foreach ($users as $key => $user) {
  5692. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  5693. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  5694. $user_post = $user->getCurrentPosition($tenant_id);
  5695. $job_title = $user_post['designation'];
  5696. $department = $user_post['department'];
  5697. $business_unit = $user_post['business_unit'];
  5698. // $action_checkbox = "<input type=\"checkbox\" name=\"roster_action\" value=\"\">";
  5699. $leaves_user_allowed = Leaves::model()->getLeaveList($tenant_id, $user->user_id);
  5700. unset($userleaves);
  5701. foreach ($leaves as $leave_id => $leave) {
  5702. if (array_key_exists($leave_id, $leaves_user_allowed)) {
  5703. $userleaves[] = LeavesHelper::individualEncashmentBalance($user->id, $tenant_id, $leave_id);
  5704. } else {
  5705. $userleaves[] = "N.A.";
  5706. }
  5707. }
  5708. $output[] = array(
  5709. // $action_checkbox,
  5710. $employee_number,
  5711. $user_name,
  5712. $job_title,
  5713. $department,
  5714. $business_unit,
  5715. );
  5716. for ($i = 0; $i < count($userleaves); $i++) {
  5717. array_push($output[$index], $userleaves[$i]);
  5718. }
  5719. $index++;
  5720. } // EOF foreach user
  5721.  
  5722. $cols = array(
  5723. // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
  5724. //'Sr No',
  5725. 'Employee ID',
  5726. 'Name',
  5727. 'Job Title',
  5728. 'Department',
  5729. 'Business Unit',
  5730. );
  5731.  
  5732. foreach ($leaves as $leave_id => $leave_name) {
  5733. array_push($cols, $leave_name);
  5734. }
  5735. $roster_type = "Leaves-Encashment";
  5736. $filenameexport = $roster_type;
  5737. $final_output = array('output' => $output,
  5738. 'cols' => $cols,
  5739. 'filenameexport' => $filenameexport);
  5740. return $final_output;
  5741. }
  5742.  
  5743. public static function getReimbursement($post_data, $tenant_id, $from, $to, $type, $name) {
  5744. $output = array();
  5745. $tenant = Tenants::model()->findByPk($tenant_id);
  5746. $subdomain = (isset($tenant->tenant_subdomain) && $tenant->tenant_subdomain != "") ? $tenant->tenant_subdomain : "darwinbox";
  5747. $filter = $post_data['filter_id'];
  5748. $users_all = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  5749. foreach ($users_all as $key_user => $value_user) {
  5750. $users_array[] = $value_user->id;
  5751. }
  5752. $from_date = new MongoDate(strtotime($from));
  5753. $to_date = new MongoDate(strtotime($to));
  5754. if ($type == UserExpenses::STATUS_COMPENSATED) {
  5755. $criteria = new EMongoCriteria();
  5756. $criteria->status('==', UserExpenses::STATUS_APPROVED);
  5757. $criteria->paid('==', UserExpenses::PAID_YES);
  5758. $criteria->tenant_id('==', $tenant_id);
  5759. $criteria->date('<=', $to_date);
  5760. $criteria->date('>=', $from_date);
  5761. $user_expenses = UserExpenses::model()->findAll($criteria);
  5762. } else {
  5763. $criteria = new EMongoCriteria();
  5764. $criteria->status('==', $type);
  5765. $criteria->paid('==', UserExpenses::PAID_NO);
  5766. $criteria->tenant_id('==', $tenant_id);
  5767. $criteria->date('<=', $to_date);
  5768. $criteria->date('>=', $from_date);
  5769. $user_expenses = UserExpenses::model()->findAll($criteria);
  5770. }
  5771. if (isset($user_expenses) && !empty($user_expenses)) {
  5772. foreach ($user_expenses as $key_reimbursment => $value_reimbursment) {
  5773. if (in_array($value_reimbursment->user_id, $users_array)) {
  5774. $user_mongo_each = UserMongo::model()->tenant($tenant_id)->findByPk($value_reimbursment->user_id);
  5775. $user_post = $user_mongo_each->getCurrentPosition($tenant_id);
  5776. $job_title = (isset($user_post['designation'])) ? $user_post['designation'] : "N.A.";
  5777. $department = (isset($user_post['department'])) ? $user_post['department'] : "N.A.";
  5778. $business_unit = (isset($user_post['business_unit'])) ? $user_post['business_unit'] : "N.A.";
  5779. $full_name = $user_mongo_each->getFullname();
  5780. $employee_id = (isset($user_mongo_each->personal->employee_no)) ? $user_mongo_each->personal->employee_no : "N.A.";
  5781. $title = (isset($value_reimbursment->title)) ? $value_reimbursment->title : "N.A.";
  5782. $date = (isset($value_reimbursment->date->sec)) ? date('d F Y', $value_reimbursment->date->sec) : "N.A.";
  5783. $item_total = 0;
  5784. $item_name_price = '';
  5785. foreach ($value_reimbursment->items as $key_items => $value_items) {
  5786. $item_name = $value_items['itemName'];
  5787. $item_price = $value_items['itemPrice'];
  5788. $item_name_price = (empty($item_name_price)) ? $item_name . " (" . $item_price . ")" : $item_name_price . ", " . $item_name . " (" . $item_price . ")";
  5789. $item_total += $item_price;
  5790. }
  5791.  
  5792. if (isset($value_reimbursment->paid_by) && $value_reimbursment->paid_by != "") {
  5793. $performed_by = UserMongo::getFullnameById($value_reimbursment->paid_by);
  5794. } else if (isset($value_reimbursment->approved_or_rejected_by) && $value_reimbursment->approved_or_rejected_by != "") {
  5795. $performed_by = UserMongo::getFullnameById($value_reimbursment->approved_or_rejected_by);
  5796. } else {
  5797. $performed_by = "N.A.";
  5798. }
  5799. $link_created = "https://" . $subdomain . ".darwinbox.in/expenses/expenses/view/id/" . $value_reimbursment->id;
  5800. $link = '<a target = "_blank" href = '.$link_created.'>'.$link_created.' </a>';
  5801. $output[] = array(
  5802. $employee_id,
  5803. $full_name,
  5804. $department,
  5805. $job_title,
  5806. $title,
  5807. $date,
  5808. $item_name_price,
  5809. $item_total,
  5810. $name, //status
  5811. $performed_by,
  5812. $link,
  5813. );
  5814. }
  5815. }
  5816. }
  5817. $cols = array(
  5818. 'Employee ID',
  5819. 'Employee Name',
  5820. 'Department',
  5821. 'Designation',
  5822. 'Title',
  5823. 'Date',
  5824. 'Items(Amount)',
  5825. 'Total Amount',
  5826. 'Status',
  5827. 'Performed By',
  5828. 'Link',
  5829. );
  5830.  
  5831.  
  5832.  
  5833. $roster_type = "Reimbursement-Report";
  5834. $filenameexport = $roster_type;
  5835. $final_output = array('output' => $output,
  5836. 'cols' => $cols,
  5837. 'filenameexport' => $filenameexport);
  5838. return $final_output;
  5839. }
  5840.  
  5841. public static function getAnnualLeaveTracker($post_data, $tenant_id) {
  5842. //$year_requested = date('Y', strtotime($from));
  5843. $todays_date = date('Y-m-d');
  5844. $previous_annual_tracker = AnnualLeavesTracker::isNew($todays_date);
  5845. if ($previous_annual_tracker) {
  5846. $user_mongo_data = UserMongo::model()->tenant()->findByAttributes(array('user_id' => Yii::app()->user->id));
  5847. $annual_tracker = new AnnualLeavesTracker;
  5848. $annual_tracker->user_id = Yii::app()->user->id;
  5849. $annual_tracker->user_name = $user_mongo_data->getFullname();
  5850. $user_email = (isset($user_mongo_data->personal->email)) ? $user_mongo_data->personal->email : UserMongo::getUserEmail($user_mongo_data->user_id);
  5851. $annual_tracker->user_email = array('0' => $user_email);
  5852. $annual_tracker->report_created_time = null;
  5853. $annual_tracker->size = null;
  5854. $annual_tracker->tenant_id = $user_mongo_data->tenant_id;
  5855. $annual_tracker->file_path = null;
  5856. $annual_tracker->save();
  5857. } else {
  5858. $message = "you can request this report only onces a DAY";
  5859. }
  5860. /**/
  5861. $previous_annual_tracker = AnnualLeavesTracker::model()->tenant()->findAll();
  5862. $tenant_profile = TenantProfile::model()->tenant()->find();
  5863. foreach ($previous_annual_tracker as $key_annual => $value_annual) {
  5864. //get employee id
  5865. $users = UserMongo::model()->tenant($tenant_id)->findByAttributes(array('user_id'=>$value_annual->user_id));
  5866. $employee_id = (isset($users->personal->employee_no)) ? $users->personal->employee_no : "N.A.";
  5867. //get employee id
  5868. $status = ($value_annual->status == AnnualLeavesTracker::ANNUALLT_PENDING) ? "Pending" : "Completed";
  5869. $export_requested_time = (isset($value_annual->created_on) && $value_annual->created_on != null) ? date('d F Y @ H:i:s', $value_annual->created_on->sec) : "-";
  5870. $export_completed_time = (isset($value_annual->report_created_time) && $value_annual->report_created_time != null) ? date('d F Y @ H:i:s', $value_annual->report_created_time->sec) : "-";
  5871. if (isset($value_annual->file_path) && $value_annual->file_path != "") {
  5872. $link = "https://" . $tenant_profile->tenant_subdomain . ".darwinbox.in/upload/annualleavesreport/" . $value_annual->file_path;
  5873. $download_link = '<a href = "' . $link . '" target = "_blank"> Click here </a>';
  5874. } else {
  5875. $download_link = "-";
  5876. }
  5877. $output[] = array(
  5878. $employee_id,
  5879. $value_annual->user_name,
  5880. $value_annual->user_email,
  5881. $export_requested_time,
  5882. $export_completed_time,
  5883. $download_link,
  5884. $status,
  5885. );
  5886. }
  5887. $cols = array(
  5888. 'Employee ID',
  5889. 'Export Requested By',
  5890. 'Requested Email',
  5891. 'Export Requested Time',
  5892. 'Export Completed Time',
  5893. 'Download Link',
  5894. 'Status',
  5895. );
  5896.  
  5897.  
  5898.  
  5899. $roster_type = "Annual-Leaves-Requested-Report-List";
  5900. $filenameexport = $roster_type;
  5901. $final_output = array('output' => $output,
  5902. 'cols' => $cols,
  5903. 'filenameexport' => $filenameexport);
  5904. return $final_output;
  5905. /**/
  5906. }
  5907.  
  5908. public static function getcompoffbalance($post_data, $tenant_id, $from, $to) {
  5909. $filter = $post_data['filter_id'];
  5910. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  5911. foreach ($users as $key_user => $user) {
  5912. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  5913. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  5914. $user_post = $user->getCurrentPosition($tenant_id);
  5915. $job_title = $user_post['designation'];
  5916. $department = $user_post['department'];
  5917. $business_unit = $user_post['business_unit'];
  5918. $compoff_available = $user->getCompoffLeavesavailable();
  5919. $output[] = array(
  5920. $employee_number,
  5921. $user_name,
  5922. $job_title,
  5923. $department,
  5924. $business_unit,
  5925. $compoff_available,
  5926. );
  5927. }
  5928.  
  5929. $cols = array(
  5930. 'Employee ID',
  5931. 'Name',
  5932. 'Job Title',
  5933. 'Department',
  5934. 'Business Unit',
  5935. 'Compoff Balance',
  5936. );
  5937.  
  5938.  
  5939.  
  5940. $roster_type = "Compoff-Balance-Report-List";
  5941. $filenameexport = $roster_type;
  5942. $final_output = array('output' => $output,
  5943. 'cols' => $cols,
  5944. 'filenameexport' => $filenameexport);
  5945. return $final_output;
  5946. /**/
  5947. }
  5948.  
  5949. public static function getcompofftakenused($post_data, $tenant_id, $from, $to) {
  5950. $filter = $post_data['filter_id'];
  5951. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  5952. foreach ($users as $key_user => $user) {
  5953. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  5954. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  5955. $user_post = $user->getCurrentPosition($tenant_id);
  5956. $job_title = $user_post['designation'];
  5957. $department = $user_post['department'];
  5958. $business_unit = $user_post['business_unit'];
  5959. $compoff_taken = $user->getCompoffLeavestaken();
  5960. $output[] = array(
  5961. $employee_number,
  5962. $user_name,
  5963. $job_title,
  5964. $department,
  5965. $business_unit,
  5966. $compoff_taken,
  5967. );
  5968. }
  5969.  
  5970. $cols = array(
  5971. 'Employee ID',
  5972. 'Name',
  5973. 'Job Title',
  5974. 'Department',
  5975. 'Business Unit',
  5976. 'Compoff Taken/Used',
  5977. );
  5978.  
  5979.  
  5980.  
  5981. $roster_type = "Compoff-Taken-Report-List";
  5982. $filenameexport = $roster_type;
  5983. $final_output = array('output' => $output,
  5984. 'cols' => $cols,
  5985. 'filenameexport' => $filenameexport);
  5986. return $final_output;
  5987. /**/
  5988. }
  5989.  
  5990. public static function getcompoffcredited($post_data, $tenant_id, $from, $to) {
  5991. $filter = $post_data['filter_id'];
  5992. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  5993. foreach ($users as $key_user => $user) {
  5994. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  5995. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  5996. $user_post = $user->getCurrentPosition($tenant_id);
  5997. $job_title = $user_post['designation'];
  5998. $department = $user_post['department'];
  5999. $business_unit = $user_post['business_unit'];
  6000. $compoff_taken = $user->getCompoffLeavestaken();
  6001. $compoff_available = $user->getCompoffLeavesavailable();
  6002. $compoff_credited = $compoff_taken + $compoff_available;
  6003. $output[] = array(
  6004. $employee_number,
  6005. $user_name,
  6006. $job_title,
  6007. $department,
  6008. $business_unit,
  6009. $compoff_credited,
  6010. );
  6011. }
  6012.  
  6013. $cols = array(
  6014. 'Employee ID',
  6015. 'Name',
  6016. 'Job Title',
  6017. 'Department',
  6018. 'Business Unit',
  6019. 'Compoff credited',
  6020. );
  6021.  
  6022.  
  6023.  
  6024. $roster_type = "Compoff-Credited-Report-List";
  6025. $filenameexport = $roster_type;
  6026. $final_output = array('output' => $output,
  6027. 'cols' => $cols,
  6028. 'filenameexport' => $filenameexport);
  6029. return $final_output;
  6030. /**/
  6031. }
  6032.  
  6033. public static function getcompoffsummary($post_data, $tenant_id, $from, $to) {
  6034. $output = array();
  6035. $filter = $post_data['filter_id'];
  6036. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  6037. foreach ($users as $key_user => $user) {
  6038. $employee_id = $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  6039. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  6040. $user_post = $user->getCurrentPosition($tenant_id);
  6041. $job_title = $user_post['designation'];
  6042. $department = $user_post['department'];
  6043. $business_unit = $user_post['business_unit'];
  6044. $compoff_taken = $user->getCompoffLeavestaken();
  6045. $compoff_available = $user->getCompoffLeavesavailable();
  6046. $compoff_credited = $compoff_taken + $compoff_available;
  6047. $output[] = array(
  6048. $employee_id,
  6049. $user_name,
  6050. $job_title,
  6051. $department,
  6052. $business_unit,
  6053. $compoff_credited,
  6054. $compoff_taken,
  6055. $compoff_available,
  6056. );
  6057. }
  6058.  
  6059. $cols = array(
  6060. 'Employee ID',
  6061. 'Name',
  6062. 'Job Title',
  6063. 'Department',
  6064. 'Business Unit',
  6065. 'Compoff credited',
  6066. 'Compoff taken',
  6067. 'Compoff Balance',
  6068. );
  6069.  
  6070.  
  6071.  
  6072. $roster_type = "Compoff-Summary-Report-List";
  6073. $filenameexport = $roster_type;
  6074. $final_output = array('output' => $output,
  6075. 'cols' => $cols,
  6076. 'filenameexport' => $filenameexport);
  6077. return $final_output;
  6078. /**/
  6079. }
  6080.  
  6081. public static function optionalHolidays($post_data, $tenant_id = null) {
  6082. $return = array();
  6083. $output = array();
  6084. $locations = "";
  6085. $holidays_list = TenantHolidays::model()->tenant()->active()->findAllByAttributes(array('optional' => TenantHolidays::OPTIONAL_TRUE,'date_year' => date('Y')));
  6086. if(isset($holidays_list) && !empty($holidays_list)){
  6087. foreach ($holidays_list as $key_holiday => $value_holiday) {
  6088. $holiday_name = (isset($value_holiday->name)) ? $value_holiday->name : "N.A.";
  6089. if(isset($value_holiday->date,$value_holiday->date_year))
  6090. {
  6091. $date_month = explode('-', $value_holiday->date);
  6092. $date_only = (isset($date_month[1])) ? $date_month[1] : "";
  6093. $month_only = (isset($date_month[0])) ? $date_month[0] : "";
  6094. }
  6095. $holiday_date = (isset($date_only,$month_only) && $month_only != "" && $date_only != "") ? date('d F Y, l',strtotime($date_only."-".$month_only."-".$value_holiday->date_year)) : "N.A.";
  6096. $locations = "";
  6097. if(!empty($value_holiday->for_location)):
  6098. foreach($value_holiday->for_location as $h):
  6099. $tenant_office = TenantOffices::model()->findByPk($h);
  6100. if(!empty($tenant_office)) :
  6101. $locations = (isset($locations) && $locations != "") ? $locations."<br/>".$tenant_office->getLocation() : $tenant_office->getLocation();
  6102. endif;
  6103. endforeach;
  6104. endif;
  6105. $output[] = array(
  6106. $holiday_name,
  6107. $holiday_date,
  6108. $locations,
  6109. );
  6110. } // EOF foreach
  6111. }
  6112. $cols = array(
  6113. 'Holiday Name',
  6114. 'Holiday Date',
  6115. 'Locations',
  6116. );
  6117.  
  6118. $roster_type = "Optional-Holiday-Data";
  6119. $filenameexport = $roster_type;
  6120. $final_output = array('output' => $output,
  6121. 'cols' => $cols,
  6122. 'filenameexport' => $filenameexport);
  6123. return $final_output;
  6124. }
  6125. public static function workanniversary($post_data, $tenant_id = null, $from, $to) {
  6126. $return = array();
  6127. $filter = $post_data['filter_id'];
  6128. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  6129. $output = array();
  6130. $index = 0;
  6131. foreach ($users as $key => $user) {
  6132. if(isset($user->doj->sec) && $user->doj->sec != ""){
  6133. $todaysDate = date('m-d',$user->doj->sec);
  6134. $year_only = date('Y',$user->doj->sec);
  6135. $openDateBegin = date('m-d', strtotime($from));
  6136. $openDateEnd = date('m-d', strtotime($to));
  6137. if (($todaysDate >= $openDateBegin) && ($todaysDate <= $openDateEnd))
  6138. {
  6139. if($year_only != date('Y'))
  6140. {
  6141. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  6142. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  6143. $user_post = $user->getCurrentPosition($tenant_id);
  6144. $job_title = $user_post['designation'];
  6145. $department = $user_post['department'];
  6146. $business_unit = $user_post['business_unit'];
  6147. $doj = date('d F Y, l',$user->doj->sec);
  6148. $annv_date_create = date('Y')."-".$todaysDate;
  6149. $anniversary_date = date('d F Y, l',strtotime($annv_date_create));
  6150. $output[] = array(
  6151. $employee_number,
  6152. $user_name,
  6153. $job_title,
  6154. $department,
  6155. $business_unit,
  6156. $doj,
  6157. $anniversary_date,
  6158. );
  6159. }
  6160. }
  6161. }
  6162. } // EOF foreach user
  6163. $cols = array(
  6164. 'Employee ID',
  6165. 'Name',
  6166. 'Job Title',
  6167. 'Department',
  6168. 'Business Unit',
  6169. 'Date Of Joining',
  6170. 'Work Anniversary Date',
  6171. );
  6172.  
  6173.  
  6174. $roster_type = "Work Anniversary Report";
  6175. $filenameexport = $roster_type;
  6176. $final_output = array('output' => $output,
  6177. 'cols' => $cols,
  6178. 'filenameexport' => $filenameexport);
  6179. return $final_output;
  6180. }
  6181.  
  6182. public static function getAgeReport($post_data, $tenant_id = null, $from, $to) {
  6183. $return = array();
  6184. $filter = $post_data['filter_id'];
  6185. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  6186. $output = array();
  6187. foreach ($users as $key => $user) {
  6188. if(isset($user->personal->dob->sec) && $user->personal->dob->sec != ""){
  6189. $age_total = self::calculate_experience(time(), $user->personal->dob->sec);
  6190. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  6191. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  6192. $user_post = $user->getCurrentPosition($tenant_id);
  6193. $job_title = $user_post['designation'];
  6194. $department = $user_post['department'];
  6195. $business_unit = $user_post['business_unit'];
  6196. $dob = date('d F Y, l', $user->personal->dob->sec);
  6197. $age = $age_total['Years']." y ".$age_total['Months']." m ".$age_total['Days']." d";
  6198. $output[] = array(
  6199. $employee_number,
  6200. $user_name,
  6201. $job_title,
  6202. $department,
  6203. $business_unit,
  6204. $dob,
  6205. $age,
  6206. );
  6207. }
  6208. } // EOF foreach user
  6209. $cols = array(
  6210. 'Name',
  6211. 'Job Title',
  6212. 'Department',
  6213. 'Business Unit',
  6214. 'Date Of Birth',
  6215. 'Age',
  6216. );
  6217.  
  6218.  
  6219. $roster_type = "Age Report";
  6220. $filenameexport = $roster_type;
  6221. $final_output = array('output' => $output,
  6222. 'cols' => $cols,
  6223. 'filenameexport' => $filenameexport);
  6224. return $final_output;
  6225. }
  6226. public static function getHiringReport($post_data, $tenant_id = null, $from, $to) {
  6227. $return = array();
  6228. $filter = $post_data['filter_id'];
  6229. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  6230. $output = array();
  6231. foreach ($users as $key => $user) {
  6232. if(isset($user->doj->sec) && $user->doj->sec != "")
  6233. {
  6234. $todaysDate = date('Y-m-d',$user->doj->sec);
  6235. //$todaysDate=date('Y-m-d', strtotime($todaysDate));
  6236. $openDateBegin = date('Y-m-d', strtotime($from));
  6237. $openDateEnd = date('Y-m-d', strtotime($to));
  6238. if (($todaysDate >= $openDateBegin) && ($todaysDate <= $openDateEnd))
  6239. {
  6240. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  6241. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  6242. $user_post = $user->getCurrentPosition($tenant_id);
  6243. $job_title = $user_post['designation'];
  6244. $department = $user_post['department'];
  6245. $business_unit = $user_post['business_unit'];
  6246. $date_of_joining = date('d F Y, l',$user->doj->sec);
  6247. $output[] = array(
  6248. $employee_number,
  6249. $user_name,
  6250. $job_title,
  6251. $department,
  6252. $business_unit,
  6253. $date_of_joining,
  6254. );
  6255. }
  6256. }
  6257. } // EOF foreach user
  6258. $cols = array(
  6259. 'Employee ID',
  6260. 'Name',
  6261. 'Job Title',
  6262. 'Department',
  6263. 'Business Unit',
  6264. 'Hire Date',
  6265. );
  6266.  
  6267.  
  6268. $roster_type = "Hiring Report";
  6269. $filenameexport = $roster_type;
  6270. $final_output = array('output' => $output,
  6271. 'cols' => $cols,
  6272. 'filenameexport' => $filenameexport);
  6273. return $final_output;
  6274. }
  6275.  
  6276. public static function getTenureReport($post_data, $tenant_id = null) {
  6277. $return = array();
  6278. $filter = $post_data['filter_id'];
  6279. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  6280. $output = array();
  6281.  
  6282. foreach ($users as $key => $user) {
  6283. if(isset($user->doj->sec) && $user->doj->sec != ""){
  6284. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  6285. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  6286. $user_post = $user->getCurrentPosition($tenant_id);
  6287. $job_title = $user_post['designation'];
  6288. $department = $user_post['department'];
  6289. $business_unit = $user_post['business_unit'];
  6290. $diff_cur_work = self::calculate_experience(time(), $user->doj->sec);
  6291. $total_cur_y = $diff_cur_work['Years'];
  6292. $total_cur_m = $diff_cur_work['Months'];
  6293. $cur_work_ex = $total_cur_y . "y " . $total_cur_m . "m";
  6294.  
  6295. $output[] = array(
  6296. $employee_number,
  6297. $user_name,
  6298. $job_title,
  6299. $department,
  6300. $business_unit,
  6301. $cur_work_ex,
  6302. );
  6303. }
  6304. } // EOF foreach
  6305. $cols = array(
  6306. 'Employee ID',
  6307. 'Name',
  6308. 'Job Title',
  6309. 'Department',
  6310. 'Business Unit',
  6311. 'Tenure',
  6312. );
  6313.  
  6314. $roster_type = "Tenure Report";
  6315. $filenameexport = $roster_type;
  6316. $final_output = array('output' => $output,
  6317. 'cols' => $cols,
  6318. 'filenameexport' => $filenameexport);
  6319. return $final_output;
  6320. }
  6321.  
  6322. public static function getPastWorkExp($post_data, $tenant_id = null) {
  6323. $return = array();
  6324. $filter = $post_data['filter_id'];
  6325. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  6326. $output = array();
  6327.  
  6328. foreach ($users as $key => $user) {
  6329. $total_past_y = 0;
  6330. $total_past_m = 0;
  6331. $total_cur_y = 0;
  6332. $total_cur_m = 0;
  6333. $total_ex_m = 0;
  6334. $total_ex_y = 0;
  6335. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  6336. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  6337. $user_post = $user->getCurrentPosition($tenant_id);
  6338. $job_title = $user_post['designation'];
  6339. $department = $user_post['department'];
  6340. $business_unit = $user_post['business_unit'];
  6341. $before_company = "";
  6342. if (isset($user['past_work']) && !empty($user['past_work'])) {
  6343. foreach ($user['past_work'] as $key => $work) {
  6344. $diff_work = self::calculate_experience($work['to_date']->sec, $work['from_date']->sec);
  6345. $total_past_y += intval($diff_work['Years']);
  6346. $total_past_m += intval($diff_work['Months']);
  6347. $company_name = (isset($work->company) && $work->company != "") ? ucfirst($work->company)." - " : "N.A.";
  6348. $exp_company = $diff_work['Years'] . "y " . $diff_work['Months'] . "m";
  6349. if(isset($company_name) && $company_name != "N.A."){
  6350. $before_company = (isset($before_company) && $before_company != "") ? $before_company . "<br/>". $company_name ." ". $exp_company : $company_name . $exp_company;
  6351. }
  6352. }
  6353.  
  6354. if ($total_past_m > 12) {
  6355. $total_past_y += intval($total_past_m / 12);
  6356. $total_past_m = $total_past_m % 12;
  6357. }
  6358. $past_work_ex = $total_past_y . "y " . $total_past_m . "m";
  6359. } else {
  6360. $past_work_ex = "";
  6361. }
  6362.  
  6363. $output[] = array(
  6364. $employee_number,
  6365. $user_name,
  6366. $job_title,
  6367. $department,
  6368. $business_unit,
  6369. $before_company,
  6370. $past_work_ex,
  6371. );
  6372. } // EOF foreach
  6373. $cols = array(
  6374. 'Employee ID',
  6375. 'Name',
  6376. 'Job Title',
  6377. 'Department',
  6378. 'Business Unit',
  6379. 'Comapany Name and Experience',
  6380. 'Total Past Experience',
  6381. );
  6382.  
  6383. $roster_type = "Past Work Experience";
  6384. $filenameexport = $roster_type;
  6385. $final_output = array('output' => $output,
  6386. 'cols' => $cols,
  6387. 'filenameexport' => $filenameexport);
  6388. return $final_output;
  6389. }
  6390. public static function getDependentDetails($post_data, $tenant_id = null) {
  6391. $return = array();
  6392. $filter = $post_data['filter_id'];
  6393. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  6394. $output = array();
  6395.  
  6396. foreach ($users as $key => $user) {
  6397. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  6398. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  6399. $user_post = $user->getCurrentPosition($tenant_id);
  6400. $job_title = $user_post['designation'];
  6401. $department = $user_post['department'];
  6402. $business_unit = $user_post['business_unit'];
  6403. $user_dependent = "";
  6404. if (isset($user['dependents']) && !empty($user['dependents'])) {
  6405. foreach ($user['dependents'] as $key => $dependents) {
  6406. $dep_name = (isset($dependents['first_name'],$dependents['last_name'])) ? ucfirst($dependents['first_name'])." ".$dependents['last_name'] ." - " : "N.A.";
  6407. $dep_relation = (isset($dependents['relation_type'])) ? $dependents['relation_type'] ." - " : "N.A.";
  6408. $get_dep_age = (isset($dependents['dob']->sec)) ? self::calculate_experience(time(), $dependents['dob']->sec) : "N.A.";
  6409. $age_dep = (isset($get_dep_age) && $get_dep_age != "N.A.") ? $get_dep_age['Years']."y ".$get_dep_age['Months']."m" : "N.A.";
  6410. if(isset($dep_name) && $dep_name != "N.A."){
  6411. $user_dependent = (isset($user_dependent) && $user_dependent != "") ? $user_dependent . "<br/>". $dep_name ." ". $dep_relation ." ". $age_dep : $dep_name ." ". $dep_relation ." ". $age_dep;
  6412. }
  6413. }
  6414. } else {
  6415. $user_dependent = "N.A.";
  6416. }
  6417.  
  6418. $output[] = array(
  6419. $employee_number,
  6420. $user_name,
  6421. $job_title,
  6422. $department,
  6423. $business_unit,
  6424. $user_dependent,
  6425. );
  6426. } // EOF foreach
  6427. $cols = array(
  6428. 'Employee ID',
  6429. 'Name',
  6430. 'Job Title',
  6431. 'Department',
  6432. 'Business Unit',
  6433. 'Dependent Detail',
  6434. );
  6435.  
  6436. $roster_type = "Dependent-Data";
  6437. $filenameexport = $roster_type;
  6438. $final_output = array('output' => $output,
  6439. 'cols' => $cols,
  6440. 'filenameexport' => $filenameexport);
  6441. return $final_output;
  6442. }
  6443.  
  6444. public static function getProfileCompletionReport($post_data, $tenant_id = null) {
  6445. $return = array();
  6446. $filter = $post_data['filter_id'];
  6447. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  6448. $output = array();
  6449.  
  6450. foreach ($users as $key => $user) {
  6451. if(isset($user->doj->sec) && $user->doj->sec != ""){
  6452. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  6453. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  6454. $user_post = $user->getCurrentPosition($tenant_id);
  6455. $job_title = $user_post['designation'];
  6456. $department = $user_post['department'];
  6457. $business_unit = $user_post['business_unit'];
  6458. list ($measures, $unfilled) = $user->getCompletionCount();
  6459. $profile_percent = round(100 - (count($unfilled) / count($measures)) * 100) . "%";
  6460.  
  6461. $output[] = array(
  6462. $employee_number,
  6463. $user_name,
  6464. $job_title,
  6465. $department,
  6466. $business_unit,
  6467. $profile_percent,
  6468. );
  6469. }
  6470. } // EOF foreach
  6471. $cols = array(
  6472. 'Employee ID',
  6473. 'Name',
  6474. 'Job Title',
  6475. 'Department',
  6476. 'Business Unit',
  6477. 'Profile Completion %',
  6478. );
  6479.  
  6480. $roster_type = "Profile-Completion-Data";
  6481. $filenameexport = $roster_type;
  6482. $final_output = array('output' => $output,
  6483. 'cols' => $cols,
  6484. 'filenameexport' => $filenameexport);
  6485. return $final_output;
  6486. }
  6487.  
  6488. public static function getReimbBankSheet($post_data, $tenant_id, $from, $to, $type, $name) {
  6489. $output = array();
  6490. $tenant = Tenants::model()->findByPk($tenant_id);
  6491. $subdomain = (isset($tenant->tenant_subdomain) && $tenant->tenant_subdomain != "") ? $tenant->tenant_subdomain : "darwinbox";
  6492. $filter = $post_data['filter_id'];
  6493. $users_all = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  6494. foreach ($users_all as $key_user => $value_user) {
  6495. $users_array[] = $value_user->id;
  6496. }
  6497. $from_date = new MongoDate(strtotime($from));
  6498. $to_date = new MongoDate(strtotime($to));
  6499. if ($type == UserExpenses::STATUS_COMPENSATED) {
  6500. $criteria = new EMongoCriteria();
  6501. $criteria->status('==', UserExpenses::STATUS_APPROVED);
  6502. $criteria->paid('==', UserExpenses::PAID_YES);
  6503. $criteria->tenant_id('==', $tenant_id);
  6504. $criteria->date('<=', $to_date);
  6505. $criteria->date('>=', $from_date);
  6506. $user_expenses = UserExpenses::model()->findAll($criteria);
  6507. } else {
  6508. $criteria = new EMongoCriteria();
  6509. $criteria->status('==', $type);
  6510. $criteria->paid('==', UserExpenses::PAID_NO);
  6511. $criteria->tenant_id('==', $tenant_id);
  6512. $criteria->date('<=', $to_date);
  6513. $criteria->date('>=', $from_date);
  6514. $user_expenses = UserExpenses::model()->findAll($criteria);
  6515. }
  6516. if (isset($user_expenses) && !empty($user_expenses)) {
  6517. foreach ($user_expenses as $key_reimbursment => $value_reimbursment) {
  6518. if (in_array($value_reimbursment->user_id, $users_array)) {
  6519. $user_mongo_each = UserMongo::model()->tenant($tenant_id)->findByPk($value_reimbursment->user_id);
  6520. $user_post = $user_mongo_each->getCurrentPosition($tenant_id);
  6521. $job_title = (isset($user_post['designation'])) ? $user_post['designation'] : "N.A.";
  6522. $department = (isset($user_post['department'])) ? $user_post['department'] : "N.A.";
  6523. $business_unit = (isset($user_post['business_unit'])) ? $user_post['business_unit'] : "N.A.";
  6524. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  6525. $full_name = $user_mongo_each->getFullname();
  6526. $title = (isset($value_reimbursment->title)) ? $value_reimbursment->title : "N.A.";
  6527. $date = (isset($value_reimbursment->date->sec)) ? date('d F Y', $value_reimbursment->date->sec) : "N.A.";
  6528. $item_total = 0;
  6529. $item_name_price = '';
  6530. foreach ($value_reimbursment->items as $key_items => $value_items) {
  6531. $item_name = $value_items['itemName'];
  6532. $item_price = $value_items['itemPrice'];
  6533. $item_name_price = (empty($item_name_price)) ? $item_name . " (" . $item_price . ")" : $item_name_price . ", " . $item_name . " (" . $item_price . ")";
  6534. $item_total += $item_price;
  6535. }
  6536.  
  6537. if (isset($value_reimbursment->paid_by) && $value_reimbursment->paid_by != "") {
  6538. $performed_by = UserMongo::getFullnameById($value_reimbursment->paid_by);
  6539. } else if (isset($value_reimbursment->approved_or_rejected_by) && $value_reimbursment->approved_or_rejected_by != "") {
  6540. $performed_by = UserMongo::getFullnameById($value_reimbursment->approved_or_rejected_by);
  6541. } else {
  6542. $performed_by = "N.A.";
  6543. }
  6544. $link_created = "https://" . $subdomain . ".darwinbox.in/expenses/expenses/view/id/" . $value_reimbursment->id;
  6545. $link = '<a target = "_blank" href = '.$link_created.'>'.$link_created.' </a>';
  6546. // bank details
  6547. if (isset($user_mongo_each->banking) && isset($user_mongo_each->banking->bank_name) && $user_mongo_each->banking->bank_name != "" && isset($user_mongo_each->banking->bank_account) && $user_mongo_each->banking->bank_account != "") {
  6548. $account_number = $user_mongo_each->banking->bank_account;
  6549. $account_bank_name = $user_mongo_each->banking->bank_name;
  6550. $account_ifsc = $user_mongo_each->banking->bank_ifsc;
  6551. $account_bank_branch = $user_mongo_each->banking->bank_branch;
  6552. $pan_number = (isset($user_mongo_each->banking->bank_pan_num) && $user_mongo_each->banking->bank_pan_num != "") ? $user_mongo_each->banking->bank_pan_num : "N.A.";
  6553. } else {
  6554. $account_number = "N.A.";
  6555. $account_bank_name = "N.A.";
  6556. $account_ifsc = "N.A.";
  6557. $account_bank_branch = "N.A.";
  6558. $pan_number = "N.A.";
  6559. }
  6560. $output[] = array(
  6561. $employee_number,
  6562. $full_name,
  6563. $department,
  6564. $job_title,
  6565. $title,
  6566. $date,
  6567. $account_bank_name,
  6568. $account_bank_branch,
  6569. $account_number,
  6570. $account_ifsc,
  6571. $pan_number,
  6572. $item_total,
  6573. );
  6574. }
  6575. }
  6576. }
  6577. $cols = array(
  6578. 'Employee ID',
  6579. 'Employee Name',
  6580. 'Department',
  6581. 'Designation',
  6582. 'Reimb Title',
  6583. 'Date',
  6584. 'Bank Name',
  6585. 'Branch Name',
  6586. 'Account Number',
  6587. 'Account IFSC',
  6588. 'PAN Number',
  6589. 'Total Amount',
  6590. );
  6591. $roster_type = "Reimbursement-Bank-Sheet";
  6592. $filenameexport = $roster_type;
  6593. $final_output = array('output' => $output,
  6594. 'cols' => $cols,
  6595. 'filenameexport' => $filenameexport);
  6596. return $final_output;
  6597. }
  6598.  
  6599. public static function getPfReportMonthly($post_data, $tenant_id, $from, $to) {
  6600. $for_date = date('Y-m', strtotime($from));
  6601. $return = array();
  6602. $output = array();
  6603.  
  6604. $current_month = date("m");
  6605. $filter = $post_data['filter_id'];
  6606. $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
  6607. $tenantProfile = TenantProfile::model()->tenant($tenant_id)->find();
  6608. if(!empty($tenantProfile))
  6609. {
  6610. if(isset($tenantProfile->pf_edli) && $tenantProfile->pf_edli == TenantProfile::ACTIVE)
  6611. {
  6612. $edli_value = 6500;
  6613. }
  6614. else{
  6615. if(strtotime($for_date) > strtotime('2014-10'))
  6616. {
  6617. $edli_value = 15000;
  6618. }
  6619. else{
  6620. $edli_value = 6500;
  6621. }
  6622. }
  6623. }
  6624. foreach ($userSalarySlip as $salaryslip) {
  6625. $employees_contribution = 0;
  6626. $edli = 0;
  6627. $employees_contribution_pf = 0;
  6628. $total_pension = 0;
  6629. $voluntary_pf = 0;
  6630. $total_pf = 0;
  6631. $administartive_amount = 0;
  6632. $insurance_fund = 0;
  6633. $inspection_charges = 0;
  6634. $final_amount = 0;
  6635. //$users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  6636. if($post_data['active_inactive'] == 1)
  6637. {
  6638. $users = UserMongo::model()->tenant($tenant_id)->active()->findByPk($salaryslip->user_id);
  6639. }
  6640. else if($post_data['active_inactive'] == 2)
  6641. {
  6642. $users = UserMongo::model()->tenant($tenant_id)->disabled()->findByPk($salaryslip->user_id);
  6643. }
  6644. else
  6645. {
  6646. $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  6647. }
  6648. if (isset($users) && !empty($users)) {
  6649. $full_name = $users->getFullname();
  6650. $doj = (isset($users->doj->sec))? date('Y-m-d', $users->doj->sec) : 'N.A.';
  6651. $dob = (isset($users->personal->dob->sec) && $users->personal->dob->sec != "") ? date('Y-m-d', $users->personal->dob->sec) : "N.A.";
  6652. $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
  6653. // Calculate Age from Date of Birth
  6654. if($dob != '')
  6655. {
  6656. $from = new DateTime($dob);
  6657. $to = new DateTime('today');
  6658. $age = $from->diff($to)->y;
  6659. }
  6660. else
  6661. {
  6662. $age = 'N.A.';
  6663. }
  6664.  
  6665. // Get employee father name.
  6666. $emp_father_name = '';
  6667. if (isset($users->dependents) && count($users->dependents) > 0)
  6668. {
  6669. foreach ($users->dependents as $key => $value_dependent)
  6670. {
  6671. if ($value_dependent->relation_type == "Father")
  6672. {
  6673. $emp_father_first_name = (isset($value_dependent->first_name))? $value_dependent->first_name : '';
  6674. $emp_father_last_name = (isset($value_dependent->last_name))? $value_dependent->last_name : '';
  6675. $emp_father_name = $emp_father_first_name." ".$emp_father_last_name;
  6676. }
  6677. }
  6678. }
  6679. $emp_father_name = (isset($emp_father_name) && $emp_father_name != "") ? $emp_father_name : "N.A.";
  6680.  
  6681. $office_location = TenantOffices::model()->tenant($tenant_id)->findByAttributes(array('id' => $users->personal->office_location));
  6682. if (isset($office_location) && !empty($office_location) && isset($office_location->city) && $office_location->city != "") {
  6683. $city_name = City::model()->findByPk($office_location->city);
  6684. if (isset($city_name) && !empty($city_name)) {
  6685. $office_location_name = $city_name->name;
  6686. } else {
  6687. $office_location_name = "N.A";
  6688. }
  6689. } else {
  6690. $office_location_name = "N.A";
  6691. }
  6692. foreach ($salaryslip->items as $item) {
  6693. if ($item->variable_name == "basic") {
  6694. if(isset($tenantProfile->is_pf_restricted) && $tenantProfile->is_pf_restricted == TenantProfile::ACTIVE){
  6695. $basic = $item->max_value_month;
  6696. $basic = ($basic > 15000) ? 15000 : $basic;
  6697. }else{
  6698. $basic = $item->max_value_month;
  6699. }
  6700. }
  6701.  
  6702. if ($item->variable_name == "provident_fund") {
  6703. $employees_contribution = $item->max_value_month;
  6704. $employee_pf = (12 * $basic) / 100;
  6705. /*$epf = (float) (($employee_pf / 12) * 3.67);
  6706. $eps = (float) (($employee_pf / 12) * 8.33);*/
  6707. $epf = ($employees_contribution/12) * 3.67;
  6708. $epf = PayrollHelper::roundingValues(Items::ROUND_TO_NEAREST_INTEGER,$epf);
  6709. $eps = PayrollHelper::roundingValues(Items::ROUND_TO_NEAREST_INTEGER,($employees_contribution/12) * 8.33);
  6710. $lop_edli = 0;
  6711. if ($salaryslip->lop > 0) {
  6712. $lop_edli = ($edli_value / $salaryslip->total_working_days) * $salaryslip->lop;
  6713. } else {
  6714. $lop_edli = ($edli_value / $salaryslip->total_working_days) * ($salaryslip->total_working_days - $salaryslip->effective_working_days);
  6715. }
  6716.  
  6717. // Show E. D. L. I. is equal to BASIC if basic < 6500 - KT 9th March 2015
  6718. if($basic < $edli_value )
  6719. {
  6720. $edli = $basic;
  6721. }
  6722. else
  6723. {
  6724. $edli = ($edli_value - $lop_edli);
  6725. }
  6726.  
  6727. $total_pension = ($edli * 8.33) / 100;
  6728. $employees_contribution_pf = ($employees_contribution - $total_pension);
  6729. $voluntary_pf = 0;
  6730. if(strtotime($for_date) >= strtotime('2015-01'))
  6731. {
  6732. $administartive_amount = ($basic * 0.85) / 100;
  6733. }
  6734. else{
  6735. $administartive_amount = ($basic * 1.1) / 100;
  6736. }
  6737. $insurance_fund = ($edli * 0.5) / 100;
  6738. $inspection_charges = ($edli * 0.01) / 100;
  6739. $total_pf = $employees_contribution + $employees_contribution_pf + $total_pension + $voluntary_pf;
  6740. $final_amount = $total_pf + $administartive_amount + $insurance_fund + $inspection_charges;
  6741. }
  6742. }
  6743. $fpf = 0;
  6744. $vpf = 0;
  6745. $edli_charges = 0;
  6746. $employee_total = $employees_contribution + $vpf;
  6747. $employeers_total = $eps +$epf;
  6748. if($employees_contribution > 0)
  6749. {
  6750. $pf_account_number = (isset($users->pf_number) && $users->pf_number != null) ? $users->pf_number : "N.A.";
  6751. $output[] = array(
  6752. $pf_account_number,
  6753. $employee_code,
  6754. $full_name,
  6755. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $basic),
  6756. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $employees_contribution),
  6757. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $vpf),
  6758. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $employee_total),
  6759. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $epf),
  6760. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $eps),
  6761. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $employeers_total),
  6762. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $administartive_amount),
  6763. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $edli),
  6764. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $insurance_fund),
  6765. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $inspection_charges),
  6766. );
  6767. }
  6768. }
  6769. }
  6770. $cols = array(
  6771. 'Provident Fund Account No',
  6772. 'Employee Code',
  6773. 'Employee Name',
  6774. 'PF Wages',
  6775. 'Employees EPF',
  6776. 'Employees VPF',
  6777. 'Employees Total',
  6778. 'Employeers EPF',
  6779. 'Employeers EPS',
  6780. 'Employeers Total',
  6781. 'PF Admin Charges',
  6782. 'EDLI Wages',
  6783. 'EDLI Charges',
  6784. 'EDLI Admin Charges',
  6785. );
  6786.  
  6787.  
  6788.  
  6789. $roster_type = "Statutory-PF-Monthly-month".$for_date;
  6790. $filenameexport = $roster_type;
  6791. $final_output = array('output' => $output,
  6792. 'cols' => $cols,
  6793. 'filenameexport' => $filenameexport);
  6794. return $final_output;
  6795. }
  6796. public static function getPfFormSixA($post_data, $tenant_id, $from, $to) {
  6797. $for_date = date('Y-m', strtotime($from));
  6798. $return = array();
  6799. $output = array();
  6800.  
  6801. $current_month = date("m");
  6802. $filter = $post_data['filter_id'];
  6803. $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
  6804. $tenantProfile = TenantProfile::model()->tenant($tenant_id)->find();
  6805. if(!empty($tenantProfile))
  6806. {
  6807. if(isset($tenantProfile->pf_edli) && $tenantProfile->pf_edli == TenantProfile::ACTIVE)
  6808. {
  6809. $edli_value = 6500;
  6810. }
  6811. else{
  6812. if(strtotime($for_date) > strtotime('2014-10'))
  6813. {
  6814. $edli_value = 15000;
  6815. }
  6816. else{
  6817. $edli_value = 6500;
  6818. }
  6819. }
  6820. }
  6821. foreach ($userSalarySlip as $salaryslip) {
  6822. $employees_contribution = 0;
  6823. $edli = 0;
  6824. $employees_contribution_pf = 0;
  6825. $total_pension = 0;
  6826. $voluntary_pf = 0;
  6827. $total_pf = 0;
  6828. $administartive_amount = 0;
  6829. $insurance_fund = 0;
  6830. $inspection_charges = 0;
  6831. $final_amount = 0;
  6832. //$users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  6833. if($post_data['active_inactive'] == 1)
  6834. {
  6835. $users = UserMongo::model()->tenant($tenant_id)->active()->findByPk($salaryslip->user_id);
  6836. }
  6837. else if($post_data['active_inactive'] == 2)
  6838. {
  6839. $users = UserMongo::model()->tenant($tenant_id)->disabled()->findByPk($salaryslip->user_id);
  6840. }
  6841. else
  6842. {
  6843. $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  6844. }
  6845. if (isset($users) && !empty($users)) {
  6846. $full_name = $users->getFullname();
  6847. $doj = (isset($users->doj->sec))? date('Y-m-d', $users->doj->sec) : 'N.A.';
  6848. $dob = (isset($users->personal->dob->sec) && $users->personal->dob->sec != "") ? date('Y-m-d', $users->personal->dob->sec) : "N.A.";
  6849. $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
  6850. // Calculate Age from Date of Birth
  6851. if($dob != '')
  6852. {
  6853. $from = new DateTime($dob);
  6854. $to = new DateTime('today');
  6855. $age = $from->diff($to)->y;
  6856. }
  6857. else
  6858. {
  6859. $age = 'N.A.';
  6860. }
  6861.  
  6862. // Get employee father name.
  6863. $emp_father_name = '';
  6864. if (isset($users->dependents) && count($users->dependents) > 0)
  6865. {
  6866. foreach ($users->dependents as $key => $value_dependent)
  6867. {
  6868. if ($value_dependent->relation_type == "Father")
  6869. {
  6870. $emp_father_first_name = (isset($value_dependent->first_name))? $value_dependent->first_name : '';
  6871. $emp_father_last_name = (isset($value_dependent->last_name))? $value_dependent->last_name : '';
  6872. $emp_father_name = $emp_father_first_name." ".$emp_father_last_name;
  6873. }
  6874. }
  6875. }
  6876. $emp_father_name = (isset($emp_father_name) && $emp_father_name != "") ? $emp_father_name : "N.A.";
  6877.  
  6878. $office_location = TenantOffices::model()->tenant($tenant_id)->findByAttributes(array('id' => $users->personal->office_location));
  6879. if (isset($office_location) && !empty($office_location) && isset($office_location->city) && $office_location->city != "") {
  6880. $city_name = City::model()->findByPk($office_location->city);
  6881. if (isset($city_name) && !empty($city_name)) {
  6882. $office_location_name = $city_name->name;
  6883. } else {
  6884. $office_location_name = "N.A";
  6885. }
  6886. } else {
  6887. $office_location_name = "N.A";
  6888. }
  6889. foreach ($salaryslip->items as $item) {
  6890. if ($item->variable_name == "basic") {
  6891. $basic = $item->max_value_month;
  6892. }
  6893.  
  6894. if ($item->variable_name == "provident_fund") {
  6895. $employees_contribution = $item->max_value_month;
  6896. $employee_pf = (12 * $basic) / 100;
  6897. /*$epf = (float) (($employee_pf / 12) * 3.67);
  6898. $eps = (float) (($employee_pf / 12) * 8.33);*/
  6899. $epf = ($employees_contribution/12) * 3.67;
  6900. $eps = ($employees_contribution/12) * 8.33;
  6901. $lop_edli = 0;
  6902. if ($salaryslip->lop > 0) {
  6903. $lop_edli = ($edli_value / $salaryslip->total_working_days) * $salaryslip->lop;
  6904. } else {
  6905. $lop_edli = ($edli_value / $salaryslip->total_working_days) * ($salaryslip->total_working_days - $salaryslip->effective_working_days);
  6906. }
  6907.  
  6908. // Show E. D. L. I. is equal to BASIC if basic < 6500 - KT 9th March 2015
  6909. if($basic < $edli_value )
  6910. {
  6911. $edli = $basic;
  6912. }
  6913. else
  6914. {
  6915. $edli = ($edli_value - $lop_edli);
  6916. }
  6917.  
  6918. $total_pension = ($edli * 8.33) / 100;
  6919. $employees_contribution_pf = ($employees_contribution - $total_pension);
  6920. $voluntary_pf = 0;
  6921. if(strtotime($for_date) >= strtotime('2015-01'))
  6922. {
  6923. $administartive_amount = ($basic * 0.85) / 100;
  6924. }
  6925. else{
  6926. $administartive_amount = ($basic * 1.1) / 100;
  6927. }
  6928. $insurance_fund = ($edli * 0.5) / 100;
  6929. $inspection_charges = ($edli * 0.01) / 100;
  6930. $total_pf = $employees_contribution + $employees_contribution_pf + $total_pension + $voluntary_pf;
  6931. $final_amount = $total_pf + $administartive_amount + $insurance_fund + $inspection_charges;
  6932. }
  6933. }
  6934. $fpf = 0;
  6935. $vpf = 0;
  6936. $edli_charges = 0;
  6937. $employee_total = $epf + $fpf + $vpf;
  6938. $employeers_total = $eps +$epf;
  6939. $refund_of_advance = 0;
  6940. $rate_of_higher = 0;
  6941. if($employees_contribution > 0)
  6942. {
  6943. $pf_account_number = (isset($users->pf_number) && $users->pf_number != null) ? $users->pf_number : "N.A.";
  6944. $output[] = array(
  6945. $pf_account_number,
  6946. $employee_code,
  6947. $full_name,
  6948. $basic,
  6949. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $employees_contribution),
  6950. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $epf),
  6951. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $eps),
  6952. $refund_of_advance,
  6953. $rate_of_higher,
  6954. );
  6955. }
  6956. }
  6957. }
  6958. $cols = array(
  6959. 'Provident Fund Account No',
  6960. 'Employee Code',
  6961. 'Employee Name',
  6962. 'Wages retaining allowance (if any ) and D.A. including cash value of food concession paid during the currency period',
  6963. 'Workers Contribution',
  6964. 'Employeers EPF',
  6965. 'Employeers EPS',
  6966. 'Refund of Advances',
  6967. 'Rate of Higher voluntarily contribution if any',
  6968. );
  6969.  
  6970.  
  6971.  
  6972. $roster_type = "Statutory-PF-Form-6A".$for_date;
  6973. $filenameexport = $roster_type;
  6974. $final_output = array('output' => $output,
  6975. 'cols' => $cols,
  6976. 'filenameexport' => $filenameexport);
  6977. return $final_output;
  6978. }
  6979. public static function getPfFormThreeA($post_data, $tenant_id, $from, $to) {
  6980. $for_date = date('Y-m', strtotime($from));
  6981. $return = array();
  6982. $output = array();
  6983.  
  6984. $current_month = date("m");
  6985. $filter = $post_data['filter_id'];
  6986. $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
  6987. $tenantProfile = TenantProfile::model()->tenant($tenant_id)->find();
  6988. $year_to_pass = date('Y') -1;
  6989. $month_list = $tenantProfile->getMonthList('Y-m','M', $year_to_pass);
  6990. if(!empty($tenantProfile))
  6991. {
  6992. if(isset($tenantProfile->pf_edli) && $tenantProfile->pf_edli == TenantProfile::ACTIVE)
  6993. {
  6994. $edli_value = 6500;
  6995. }
  6996. else{
  6997. if(strtotime($for_date) > strtotime('2014-10'))
  6998. {
  6999. $edli_value = 15000;
  7000. }
  7001. else{
  7002. $edli_value = 6500;
  7003. }
  7004. }
  7005. }
  7006. foreach ($month_list as $key => $value)
  7007. {
  7008. $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $key));
  7009. $for_month = $key;
  7010. $employees_contribution_total = 0.00;
  7011. $epf_total = 0.00;
  7012. $eps_total = 0.00;
  7013. $pension_fund = 0.00;
  7014. $basic = 0;
  7015. if(isset($userSalarySlip) && !empty($userSalarySlip))
  7016. {
  7017. foreach ($userSalarySlip as $salaryslip) {
  7018. $employees_contribution = 0;
  7019. $edli = 0;
  7020. $employees_contribution_pf = 0;
  7021. $total_pension = 0;
  7022. $voluntary_pf = 0;
  7023. $total_pf = 0;
  7024. $administartive_amount = 0;
  7025. $insurance_fund = 0;
  7026. $inspection_charges = 0;
  7027. $final_amount = 0;
  7028. //$users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  7029. if($post_data['active_inactive'] == 1)
  7030. {
  7031. $users = UserMongo::model()->tenant($tenant_id)->active()->findByPk($salaryslip->user_id);
  7032. }
  7033. else if($post_data['active_inactive'] == 2)
  7034. {
  7035. $users = UserMongo::model()->tenant($tenant_id)->disabled()->findByPk($salaryslip->user_id);
  7036. }
  7037. else
  7038. {
  7039. $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  7040. }
  7041. if (isset($users) && !empty($users)) {
  7042. $full_name = $users->getFullname();
  7043. $doj = (isset($users->doj->sec))? date('Y-m-d', $users->doj->sec) : 'N.A.';
  7044. $dob = (isset($users->personal->dob->sec) && $users->personal->dob->sec != "") ? date('Y-m-d', $users->personal->dob->sec) : "N.A.";
  7045. $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
  7046. // Calculate Age from Date of Birth
  7047. if($dob != '')
  7048. {
  7049. $from = new DateTime($dob);
  7050. $to = new DateTime('today');
  7051. $age = $from->diff($to)->y;
  7052. }
  7053. else
  7054. {
  7055. $age = 'N.A.';
  7056. }
  7057.  
  7058. // Get employee father name.
  7059. $emp_father_name = '';
  7060. if (isset($users->dependents) && count($users->dependents) > 0)
  7061. {
  7062. foreach ($users->dependents as $key => $value_dependent)
  7063. {
  7064. if ($value_dependent->relation_type == "Father")
  7065. {
  7066. $emp_father_first_name = (isset($value_dependent->first_name))? $value_dependent->first_name : '';
  7067. $emp_father_last_name = (isset($value_dependent->last_name))? $value_dependent->last_name : '';
  7068. $emp_father_name = $emp_father_first_name." ".$emp_father_last_name;
  7069. }
  7070. }
  7071. }
  7072. $emp_father_name = (isset($emp_father_name) && $emp_father_name != "") ? $emp_father_name : "N.A.";
  7073.  
  7074. $office_location = TenantOffices::model()->tenant($tenant_id)->findByAttributes(array('id' => $users->personal->office_location));
  7075. if (isset($office_location) && !empty($office_location) && isset($office_location->city) && $office_location->city != "") {
  7076. $city_name = City::model()->findByPk($office_location->city);
  7077. if (isset($city_name) && !empty($city_name)) {
  7078. $office_location_name = $city_name->name;
  7079. } else {
  7080. $office_location_name = "N.A";
  7081. }
  7082. } else {
  7083. $office_location_name = "N.A";
  7084. }
  7085.  
  7086. foreach ($salaryslip->items as $item) {
  7087. if ($item->variable_name == "basic") {
  7088. $basic += $item->max_value_month;
  7089. }
  7090.  
  7091. if ($item->variable_name == "provident_fund") {
  7092. $employees_contribution = $item->max_value_month;
  7093. $employee_pf = (12 * $basic) / 100;
  7094. /*$epf = (float) (($employee_pf / 12) * 3.67);
  7095. $eps = (float) (($employee_pf / 12) * 8.33);*/
  7096. $epf = ($employees_contribution/12) * 3.67;
  7097. $eps = ($employees_contribution/12) * 8.33;
  7098. $lop_edli = 0;
  7099. if ($salaryslip->lop > 0) {
  7100. $lop_edli = ($edli_value / $salaryslip->total_working_days) * $salaryslip->lop;
  7101. } else {
  7102. $lop_edli = ($edli_value / $salaryslip->total_working_days) * ($salaryslip->total_working_days - $salaryslip->effective_working_days);
  7103. }
  7104.  
  7105. if($basic < $edli_value )
  7106. {
  7107. $edli = $basic;
  7108. }
  7109. else
  7110. {
  7111. $edli = ($edli_value - $lop_edli);
  7112. }
  7113.  
  7114. $total_pension = ($edli * 8.33) / 100;
  7115. $employees_contribution_pf = ($employees_contribution - $total_pension);
  7116. $voluntary_pf = 0;
  7117. if(strtotime($for_date) >= strtotime('2015-01'))
  7118. {
  7119. $administartive_amount = ($basic * 0.85) / 100;
  7120. }
  7121. else{
  7122. $administartive_amount = ($basic * 1.1) / 100;
  7123. }
  7124. $insurance_fund = ($edli * 0.5) / 100;
  7125. $inspection_charges = ($edli * 0.01) / 100;
  7126. $total_pf = $employees_contribution + $employees_contribution_pf + $total_pension + $voluntary_pf;
  7127. $final_amount = $total_pf + $administartive_amount + $insurance_fund + $inspection_charges;
  7128. }
  7129. }
  7130. $fpf = 0;
  7131. $vpf = 0;
  7132. $edli_charges = 0;
  7133. $employee_total = $epf + $fpf + $vpf;
  7134. $employeers_total = $eps +$epf;
  7135. $refund_of_advance = 0;
  7136. $rate_of_higher = 0;
  7137. if($employees_contribution > 0)
  7138. {
  7139. $employees_contribution_total += $employees_contribution;
  7140. $epf_total += $epf;
  7141. $eps_total += $eps;
  7142. }
  7143. }
  7144. }
  7145. }
  7146. $pension_fund = ($epf_total > 0) ? "541.00" : "0.00";
  7147. $output[] = array(
  7148. date('M-Y',strtotime($for_month)),
  7149. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS,$basic),
  7150. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS,$employees_contribution_total),
  7151. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS,$epf_total),
  7152. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS,$eps_total),
  7153. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS,$pension_fund),
  7154. "",
  7155. 0.00,
  7156. "",
  7157. "",
  7158. );
  7159.  
  7160. }
  7161.  
  7162. $cols = array(
  7163. 'Month',
  7164. 'Amount of Wages',
  7165. 'Workers Share EPF.',
  7166. 'Employeers E.P.F. difference between 12% & 8.1/3% (if any)',
  7167. 'Employeers Pension Fund Contribution 8.1/3 %',
  7168. 'Refund of Advances',
  7169. 'No. of days / period of non contributing service (if any)',
  7170. 'Date of Leaving Services (if any)',
  7171. 'Reason for Leaving Services (if any)',
  7172. );
  7173.  
  7174.  
  7175.  
  7176. $roster_type = "Statutory-PF-Form-3A".$for_date;
  7177. $filenameexport = $roster_type;
  7178. $final_output = array('output' => $output,
  7179. 'cols' => $cols,
  7180. 'filenameexport' => $filenameexport);
  7181. return $final_output;
  7182. }
  7183. public static function getAssests($post_data, $tenant_id = null) {
  7184. $return = array();
  7185. $filter = $post_data['filter_id'];
  7186. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  7187. $output = array();
  7188. foreach ($users as $key => $user) {
  7189. $users_filtered[] = $user->id;
  7190. }
  7191. $assests = AssestManagement::model()->tenant()->findAll();
  7192. foreach($assests as $key_ass => $value_ass)
  7193. {
  7194. $user_details = UserMongo::model()->tenant()->findByAttributes(array('id' => $value_ass->user));
  7195. if(isset($user_details) && in_array($user_details->id, $users_filtered)){
  7196. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  7197. $user_name = $user_details['personal']['firstname'] . " " . $user_details['personal']['lastname'];
  7198. $user_post = $user_details->getCurrentPosition($tenant_id);
  7199. $job_title = $user_post['designation'];
  7200. $department = $user_post['department'];
  7201. $business_unit = $user_post['business_unit'];
  7202. $asset_type = (isset($value_ass->asset_type) && $value_ass->asset_type != "") ? $value_ass->asset_type : "N.A.";
  7203. $serial_number = (isset($value_ass->serial_number) && $value_ass->serial_number != "") ? $value_ass->serial_number : "N.A.";
  7204. $model_number = (isset($value_ass->model_number) && $value_ass->model_number != "") ? $value_ass->model_number : "N.A.";
  7205. $issue_date = (isset($value_ass->issue_date) && $value_ass->issue_date != "") ? date('d-m-Y',strtotime($value_ass->issue_date)) : "N.A.";
  7206. $output[] = array(
  7207. $employee_number,
  7208. $user_name,
  7209. $job_title,
  7210. $department,
  7211. $business_unit,
  7212. $asset_type,
  7213. $serial_number,
  7214. $model_number,
  7215. $issue_date,
  7216. );
  7217. }
  7218. } // EOF foreach
  7219. $cols = array(
  7220. 'Employee ID',
  7221. 'Name',
  7222. 'Job Title',
  7223. 'Department',
  7224. 'Business Unit',
  7225. 'Assest type',
  7226. 'Serial number',
  7227. 'Model number/Type',
  7228. 'Issued date',
  7229. );
  7230.  
  7231. $filenameexport = "Asset Roster";
  7232. $final_output = array('output' => $output,
  7233. 'cols' => $cols,
  7234. 'filenameexport' => $filenameexport);
  7235. return $final_output;
  7236. }
  7237. public static function loadFiltersOthers() {
  7238. $filters = array();
  7239. $userMongo = UserMongo::model()->tenant()->findByAttributes(array('user_id' => Yii::app()->user->id));
  7240. if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")) && Yii::app()->session['menu_owner'])
  7241. {
  7242. $filters['ALL'] = array('ALL_0' => 'All Employees');
  7243. $filters['Designations'] = UserDepartments::getAllDepartmentsWithDesignationsNew();
  7244. $filters['Departments'] = UserDepartments::getAllDepartments();
  7245. $filters['Locations'] = TenantOffices::getTenantOfficeLocation();
  7246. $filters['Employee Type'] = TenantUserTypes::getTenantTypes();
  7247. }
  7248. /* if(isset($userMongo) && !empty($userMongo))
  7249. {*/
  7250. elseif($userMongo->checkManager())
  7251. {
  7252. $filters['ALL'] = array('ALL_0' => 'All Reportees');
  7253. $filters['Reportees'] = $userMongo->getManagedUsersForRosters();
  7254. }
  7255. // }
  7256. // $filters['Shift'] = TenantShift::getTenantShiftArray();
  7257. return $filters;
  7258. }
  7259. public static function getESICReport($post_data, $tenant_id, $from, $to)
  7260. {
  7261. $tenant_profile = TenantProfile::model()->tenant()->find();
  7262. $cal_esic_on_gross = (isset($tenant_profile->cal_esic_on_gross))? $tenant_profile->cal_esic_on_gross : 0;
  7263.  
  7264. $for_date = date('Y-m', strtotime($from));
  7265. $return = array();
  7266. $output = array();
  7267. $employees_contribution = "N.A.";
  7268. $employeers_contribution = "N.A.";
  7269. $total = "N.A.";
  7270. $total_no_days = "N.A.";
  7271. $current_month = date("m");
  7272. $filter = $post_data['filter_id'];
  7273. $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
  7274. foreach ($userSalarySlip as $salaryslip) {
  7275. $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  7276. // Getting user gross salary
  7277. $gross_salary = $salaryslip->total_gross;
  7278.  
  7279. $total_transactions = (isset($salaryslip->total_transactions))? $salaryslip->total_transactions : 0;
  7280. $user_transaction_esic = UserTransaction::getTotalTransactionsOtEsic($salaryslip->user_id, $salaryslip->for_month, $salaryslip->tenant_id);
  7281. // Minus Extra payment from gross salary if any
  7282. if($total_transactions > 0){
  7283. $gross_salary = $gross_salary - $total_transactions;
  7284. $gross_salary = $gross_salary + $user_transaction_esic; //esic gross has only OT no other extra payments are affecting gross
  7285. }
  7286.  
  7287. if (isset($users) && !empty($users)) {
  7288. $cal_esic = false;
  7289. foreach ($salaryslip->items as $item) {
  7290. /* if ($item->type == Items::ITEM_TYPE_INCOME) {
  7291. $all_items_total += $item->max_value_month;
  7292. } */
  7293. if ($item->variable_name == "esic") {
  7294. $cal_esic = true;
  7295. $employees_contribution_sal = $item->max_value_month;
  7296. }
  7297. if ($item->variable_name == "basic") {
  7298. $basic = $item->max_value_month;
  7299. }
  7300. if($item->variable_name == 'provident_fund')
  7301. {
  7302. $pf = $item->max_value_month;
  7303. }
  7304. }
  7305. if ($cal_esic) {
  7306. $all_items_total = 0;
  7307. $full_name = $users->getFullname();
  7308. $employee_id = (isset($users->personal->employee_no)) ? $users->personal->employee_no : "N.A.";
  7309. $doj = date('Y-m-d', $users->doj->sec);
  7310. $employees_contribution = $employees_contribution_sal;
  7311. $original_esic = $employees_contribution / 0.0175;
  7312. $employeers_contribution = number_format($original_esic * 0.0475);
  7313. $total = number_format($employees_contribution + $employeers_contribution);
  7314.  
  7315. // Calculate "GROSS + PF (Employeer) + EMPLOYEERS ESIC"
  7316. // If checkbox in Payroll setting is checked for "Calculate ESIC on Gross"
  7317. // if($cal_esic_on_gross == TenantProfile::ACTIVE)
  7318. // {
  7319. // $gross_salary = $gross_salary + $pf + $employeers_contribution;
  7320. // }
  7321.  
  7322. $esic_account_number = (isset($users->esic_number) && $users->esic_number != null) ? $users->esic_number : "N.A.";
  7323. $total_no_days = (isset($salaryslip->effective_working_days)) ? $salaryslip->effective_working_days : "N.A.";
  7324. $output[] = array(
  7325. $employee_id,
  7326. $esic_account_number,
  7327. $full_name,
  7328. $total_no_days,
  7329. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $gross_salary),
  7330. "",
  7331. "",
  7332. );
  7333. }
  7334. }
  7335. }
  7336. $cols = array(
  7337. 'Employee ID',
  7338. 'IP Number(10Digits)',
  7339. 'IP Name(Only alphabets and space)',
  7340. 'No of Days for which wages paid/payable during the month',
  7341. 'Total Monthly Wages',
  7342. 'Reason Code for Zero workings days(numeric only; provide 0 for all other reasons- Click on the link for reference)',
  7343. 'Last Working Day( Format DD/MM/YYYY or DD-MM-YYYY)',
  7344. );
  7345.  
  7346.  
  7347.  
  7348. $roster_type = "Payroll-ESIC-Report-month".$for_date;
  7349. $filenameexport = $roster_type;
  7350. $final_output = array('output' => $output,
  7351. 'cols' => $cols,
  7352. 'filenameexport' => $filenameexport);
  7353. return $final_output;
  7354. }
  7355.  
  7356. public static function getEsicStatement($post_data, $tenant_id, $from, $to){
  7357. $tenant_profile = TenantProfile::model()->tenant()->find();
  7358. $cal_esic_on_gross = (isset($tenant_profile->cal_esic_on_gross))? $tenant_profile->cal_esic_on_gross : 0;
  7359. $count_i = 1;
  7360. $for_date = date('Y-m', strtotime($from));
  7361. $return = array();
  7362. $output = array();
  7363. $employees_contribution = "N.A.";
  7364. $employeers_contribution = "N.A.";
  7365. $total = "N.A.";
  7366. $total_no_days = "N.A.";
  7367. $current_month = date("m");
  7368. $filter = $post_data['filter_id'];
  7369. $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
  7370. foreach ($userSalarySlip as $salaryslip) {
  7371. //$users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  7372. // if($post_data['active_inactive'] == 1){
  7373. // $users = UserMongo::model()->tenant($tenant_id)->active()->findByPk($salaryslip->user_id);
  7374. // }
  7375. // else if($post_data['active_inactive'] == 2){
  7376. // $users = UserMongo::model()->tenant($tenant_id)->disabled()->findByPk($salaryslip->user_id);
  7377. // }
  7378. // else{
  7379. $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  7380. //}
  7381. // Getting user gross salary
  7382. $gross_salary = $salaryslip->total_gross;
  7383. $total_transactions = (isset($salaryslip->total_transactions))? $salaryslip->total_transactions : 0;
  7384. $user_transaction_esic = UserTransaction::getTotalTransactionsOtEsic($salaryslip->user_id, $salaryslip->for_month, $salaryslip->tenant_id);
  7385. // Minus Extra payment from gross salary if any
  7386. if($total_transactions > 0){
  7387. $gross_salary = $gross_salary - $total_transactions;
  7388. $gross_salary = $gross_salary + $user_transaction_esic; //esic gross has only OT no other extra payments are affecting gross
  7389. }
  7390. if (isset($users) && !empty($users)) {
  7391. $cal_esic = false;
  7392. foreach ($salaryslip->items as $item) {
  7393. /* if ($item->type == Items::ITEM_TYPE_INCOME) {
  7394. $all_items_total += $item->max_value_month;
  7395. } */
  7396. if ($item->variable_name == "esic") {
  7397. $cal_esic = true;
  7398. $employees_contribution_sal = $item->max_value_month;
  7399. }
  7400. if ($item->variable_name == "basic") {
  7401. $basic = $item->max_value_month;
  7402. }
  7403. if($item->variable_name == 'provident_fund')
  7404. {
  7405. $pf = $item->max_value_month;
  7406. }
  7407. }
  7408. if ($cal_esic) {
  7409. $all_items_total = 0;
  7410. $full_name = $users->getFullname();
  7411. $doj = date('Y-m-d', $users->doj->sec);
  7412. $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
  7413. $employees_contribution = $employees_contribution_sal;
  7414. $original_esic = $employees_contribution / 0.0175;
  7415. $employeers_contribution = number_format($original_esic * 0.0475);
  7416. $total = number_format($employees_contribution + $employeers_contribution);
  7417. // Calculate "GROSS + PF (Employeer) + EMPLOYEERS ESIC"
  7418. // If checkbox in Payroll setting is checked for "Calculate ESIC on Gross"
  7419. //if($cal_esic_on_gross == TenantProfile::ACTIVE){
  7420. //$gross_salary = $gross_salary + $pf + $employeers_contribution;
  7421. //}
  7422.  
  7423. $esic_account_number = (isset($users->esic_number) && $users->esic_number != null) ? $users->esic_number : "N.A.";
  7424. $total_no_days = (isset($salaryslip->effective_working_days)) ? $salaryslip->effective_working_days : "N.A.";
  7425. $output[] = array(
  7426. $count_i,
  7427. $employee_code,
  7428. $esic_account_number,
  7429. $full_name,
  7430. $total_no_days,
  7431. PayrollHelper::roundingValues(Items::ROUND_TO_NEAREST_INTEGER, $gross_salary),
  7432. PayrollHelper::roundingValues(Items::ROUND_TO_HIGEST_INTEGER, $employees_contribution),
  7433. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $employeers_contribution),
  7434. );
  7435. $count_i++;
  7436. }
  7437. }
  7438. }
  7439. $cols = array(
  7440. 'SI No',
  7441. 'Employee No',
  7442. 'Insurance No',
  7443. 'Name Of Insured Person',
  7444. 'Days Worked',
  7445. 'ESI Gross',
  7446. 'Employees Contribution',
  7447. 'Employeers Contribution',
  7448. );
  7449.  
  7450.  
  7451.  
  7452. $roster_type = "Payroll-ESIC-Report-month".$for_date;
  7453. $filenameexport = $roster_type;
  7454. $final_output = array('output' => $output,
  7455. 'cols' => $cols,
  7456. 'filenameexport' => $filenameexport);
  7457. return $final_output;
  7458. }
  7459. public static function getPFReportMonthNew($post_data, $tenant_id, $from, $to) {
  7460. $for_date = date('Y-m', strtotime($from));
  7461. $return = array();
  7462. $output = array();
  7463.  
  7464. $current_month = date("m");
  7465. $filter = $post_data['filter_id'];
  7466. $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
  7467. $tenantProfile = TenantProfile::model()->tenant($tenant_id)->find();
  7468. if(!empty($tenantProfile))
  7469. {
  7470. if(isset($tenantProfile->pf_edli) && $tenantProfile->pf_edli == TenantProfile::ACTIVE){
  7471. $edli_value = 6500;
  7472. }
  7473. else{
  7474. if(strtotime($for_date) > strtotime('2014-10')){
  7475. $edli_value = 15000;
  7476. }
  7477. else{
  7478. $edli_value = 6500;
  7479. }
  7480. }
  7481. }
  7482. foreach ($userSalarySlip as $salaryslip) {
  7483. $employees_contribution = 0;
  7484. $edli = 0;
  7485. $employees_contribution_pf = 0;
  7486. $total_pension = 0;
  7487. $voluntary_pf = 0;
  7488. $total_pf = 0;
  7489. $administartive_amount = 0;
  7490. $insurance_fund = 0;
  7491. $inspection_charges = 0;
  7492. $final_amount = 0;
  7493. $basic_eps = 0;
  7494. $accountnooneepf = 0;
  7495. $accountnotenepf = 0;
  7496. $accountnotwo = 0;
  7497. $accountnotwentyone = 0;
  7498. $accountnotwentytwo = 0;
  7499. //$users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  7500. if(isset($post_data['active_inactive']) && $post_data['active_inactive'] == 1)
  7501. {
  7502. $users = UserMongo::model()->tenant($tenant_id)->active()->findByPk($salaryslip->user_id);
  7503. }
  7504. else if(isset($post_data['active_inactive']) && $post_data['active_inactive'] == 2)
  7505. {
  7506. $users = UserMongo::model()->tenant($tenant_id)->disabled()->findByPk($salaryslip->user_id);
  7507. }
  7508. else
  7509. {
  7510. $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
  7511. }
  7512. if (isset($users) && !empty($users)) {
  7513. $full_name = $users->getFullname();
  7514. $doj = (isset($users->doj->sec))? date('d/m/Y', $users->doj->sec) : 'N.A.';
  7515. $date_of_exit = (isset($users->deactivate_date->sec))? date('d/m/Y', $users->deactivate_date->sec) : 'N.A.';
  7516. $date_of_exit_month = (isset($users->deactivate_date->sec))? date('Y-m', $users->deactivate_date->sec) : 'N.A.';
  7517. $dob = (isset($users->personal->dob->sec) && $users->personal->dob->sec != "") ? date('d/m/Y', $users->personal->dob->sec) : "N.A.";
  7518. $doj = (isset($users->doj->sec) && $users->doj->sec != "") ? date('d/m/Y', $users->doj->sec) : "N.A.";
  7519. $doj_month = (isset($users->doj->sec) && $users->doj->sec != "") ? date('Y-m', $users->doj->sec) : "N.A.";
  7520. $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
  7521. $gender = (isset($users->personal->gender) && $users->personal->gender == UserPersonal::GENDER_MALE) ? "M" : "F";
  7522. // Calculate Age from Date of Birth
  7523. // if($dob != '')
  7524. // {
  7525. // $from = new DateTime($dob);
  7526. // $to = new DateTime('today');
  7527. // $age = $from->diff($to)->y;
  7528. // }
  7529. // else
  7530. // {
  7531. // $age = 'N.A.';
  7532. // }
  7533.  
  7534. // Get employee father name.
  7535. $emp_father_name = '';
  7536. $emp_husband_name = '';
  7537. $display_realation_name = '';
  7538.  
  7539. if (isset($users->dependents) && count($users->dependents) > 0)
  7540. {
  7541. foreach ($users->dependents as $key => $value_dependent)
  7542. {
  7543. if ($value_dependent->relation_type == "Father")
  7544. {
  7545. $emp_father_first_name = (isset($value_dependent->first_name))? $value_dependent->first_name : '';
  7546. $emp_father_last_name = (isset($value_dependent->last_name))? $value_dependent->last_name : '';
  7547. $emp_father_name = $emp_father_first_name." ".$emp_father_last_name;
  7548. }
  7549. if ($value_dependent->relation_type == "Husband")
  7550. {
  7551. $emp_husband_first_name = (isset($value_dependent->first_name))? $value_dependent->first_name : '';
  7552. $emp_husband_last_name = (isset($value_dependent->last_name))? $value_dependent->last_name : '';
  7553. $emp_husband_name = $emp_father_first_name." ".$emp_father_last_name;
  7554. }
  7555. }
  7556. }
  7557. if(isset($emp_husband_name) && $emp_husband_name != ""){
  7558. $display_realation_name = (isset($emp_husband_name) && $emp_husband_name != "") ? $emp_husband_name : "N.A.";
  7559. $relation_type = 'S';
  7560. }else{
  7561. $display_realation_name = (isset($emp_father_name) && $emp_father_name != "") ? $emp_father_name : "N.A.";
  7562. $relation_type = (isset($emp_father_name) && $emp_father_name != "") ? 'F' : "N.A.";
  7563. }
  7564.  
  7565. $office_location = TenantOffices::model()->tenant($tenant_id)->findByAttributes(array('id' => $users->personal->office_location));
  7566. if (isset($office_location) && !empty($office_location) && isset($office_location->city) && $office_location->city != "") {
  7567. $city_name = City::model()->findByPk($office_location->city);
  7568. if (isset($city_name) && !empty($city_name)) {
  7569. $office_location_name = $city_name->name;
  7570. } else {
  7571. $office_location_name = "N.A";
  7572. }
  7573. } else {
  7574. $office_location_name = "N.A";
  7575. }
  7576. foreach ($salaryslip->items as $item) {
  7577. if ($item->variable_name == "basic") {
  7578. if(isset($tenantProfile->is_pf_restricted) && $tenantProfile->is_pf_restricted == TenantProfile::ACTIVE){
  7579. $basic = $item->max_value_month;
  7580. $basic = ($basic > 15000) ? 15000 : $basic;
  7581. }else{
  7582. $basic = $item->max_value_month;
  7583. }
  7584. }
  7585.  
  7586. if ($item->variable_name == "provident_fund") {
  7587. // basic basic_eps 3 conditions
  7588. // if age is greater than 58 years then 0 else basic
  7589. // if not existing PF member and basic > 15000 then basic_eps = 0
  7590. // if basic > 15000 then basic_eps = 15000 as max limit is 15000
  7591. $age = RandomHelper::CalculateAge(date('Y-m-d',$users->personal->dob->sec));
  7592. $basic_eps = $basic;
  7593. if($age > 58){
  7594. $basic_eps = 0;
  7595. }
  7596. if(isset($user->existing_pf_member) && $user->existing_pf_member == 0 && $basic > 15000){
  7597. $basic_eps = 0;
  7598. }
  7599. if($basic > 15000){
  7600. $basic_eps = 15000;
  7601. }
  7602. // basic basic_eps 3 conditions
  7603.  
  7604. $employees_contribution = $item->max_value_month;
  7605.  
  7606. $eps_contribution = ($basic_eps > 0) ? ($basic_eps * 8.33)/100 : 0;
  7607. $eps_contribution = PayrollHelper::roundingValues(Items::ROUND_TO_HIGEST_INTEGER,$eps_contribution);
  7608.  
  7609. $diff_epf_eps = $employees_contribution - $eps_contribution;
  7610.  
  7611. $lop_days = $salaryslip->lop;
  7612.  
  7613. $arrear_basic = 0; //differnece of basic after salary increment
  7614.  
  7615. $arrears_epf_wages = 0;
  7616.  
  7617. $arrears_epf_ee_wages = 0;
  7618.  
  7619. $arrears_epf_er_wages = 0;
  7620.  
  7621. $arrears_eps = 0;
  7622.  
  7623. if(strtotime($for_date) != strtotime($doj_month)){
  7624. $display_realation_name = "";
  7625. $relation_type = "";
  7626. $dob = "";
  7627. $gender = "";
  7628. $doj = "";
  7629. }
  7630. if(isset($date_of_exit) && strtotime($for_date) == strtotime($date_of_exit_month)){
  7631. $reason_of_exit = "C";
  7632. }else{
  7633. $date_of_exit = "";
  7634. $reason_of_exit = "";
  7635. }
  7636. // $employee_pf = (12 * $basic) / 100;
  7637. // $epf = ($employees_contribution/12) * 3.67;
  7638. // $eps = ($employees_contribution/12) * 8.33;
  7639. $lop_edli = 0;
  7640. if ($salaryslip->lop > 0) {
  7641. $lop_edli = ($edli_value / $salaryslip->total_working_days) * $salaryslip->lop;
  7642. } else {
  7643. $lop_edli = ($edli_value / $salaryslip->total_working_days) * ($salaryslip->total_working_days - $salaryslip->effective_working_days);
  7644. }
  7645.  
  7646. // Show E. D. L. I. is equal to BASIC if basic < 6500 - KT 9th March 2015
  7647. if($basic < $edli_value){
  7648. $edli = $basic;
  7649. }
  7650. else{
  7651. $edli = ($edli_value - $lop_edli);
  7652. }
  7653.  
  7654. // $total_pension = ($edli * 8.33) / 100;
  7655. // $employees_contribution_pf = ($employees_contribution - $total_pension);
  7656. // $voluntary_pf = 0;
  7657. // if(strtotime($for_date) >= strtotime('2015-01'))
  7658. // {
  7659. // $administartive_amount = ($basic * 0.85) / 100;
  7660. // }
  7661. // else{
  7662. // $administartive_amount = ($basic * 1.1) / 100;
  7663. // }
  7664. // $insurance_fund = ($edli * 0.5) / 100;
  7665. // $inspection_charges = ($edli * 0.01) / 100;
  7666. // $total_pf = $employees_contribution + $employees_contribution_pf + $total_pension + $voluntary_pf;
  7667. // $final_amount = $total_pf + $administartive_amount + $insurance_fund + $inspection_charges;
  7668. }
  7669. }
  7670.  
  7671. // Do not show the row if $employees_contribution is ZERO
  7672. if($employees_contribution > 0)
  7673. {
  7674.  
  7675. // Account no1 EPF(employee total pf + employeers diff btw epf and eps)
  7676. $accountnooneepf += ($employees_contribution + $diff_epf_eps);
  7677. // Account no1 EPF(employee total pf + employeers diff btw epf and eps)
  7678. //Account number 10 = sum of all emp EPS
  7679. $accountnotenepf += $eps_contribution;
  7680. //Account number 10 = sum of all emp EPS
  7681. //Account number 2 = PF admin charges
  7682. $accountnotwo += ($basic * 0.85) / 100;
  7683. //Account number 2 = PF admin charges
  7684. //Account number 21 = 0.5% on edli wages
  7685. $accountnotwentyone += ($edli * 0.5) / 100;
  7686. //Account number 21 = 0.5% on edli wages
  7687. //Account number 22 = 0.01% on edli wages
  7688. $accountnotwentytwo += ($edli * 0.01) / 100;
  7689. //Account number 22 = 0.01% on edli wages
  7690.  
  7691. $pf_account_number = (isset($users->pf_number) && $users->pf_number != null) ? $users->pf_number : "N.A.";
  7692. $employee_code_pf_exp = explode('/', $pf_account_number);
  7693. $employee_code_pf = (isset($employee_code_pf_exp[4]) && $employee_code_pf_exp[4] != "") ? $employee_code_pf_exp[4] : "";
  7694. $total_pension = ($edli * 8.33) / 100;
  7695. $employees_contribution_pf = ($employees_contribution - $total_pension);
  7696. $voluntary_pf = 0;
  7697. if(strtotime($for_date) >= strtotime('2015-01'))
  7698. {
  7699. $administartive_amount = ($basic * 0.85) / 100;
  7700. }
  7701. else{
  7702. $administartive_amount = ($basic * 1.1) / 100;
  7703. }
  7704. $insurance_fund = ($edli * 0.5) / 100;
  7705. $inspection_charges = ($edli * 0.01) / 100;
  7706. $total_pf = $employees_contribution + $employees_contribution_pf + $total_pension + $voluntary_pf;
  7707. $final_amount = $total_pf + $administartive_amount + $insurance_fund + $inspection_charges;
  7708. $output[] = array(
  7709. $employee_code_pf,
  7710. $full_name,
  7711. $basic,
  7712. $basic_eps,
  7713. $employees_contribution,
  7714. $eps_contribution,
  7715. $diff_epf_eps,
  7716. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $edli),
  7717. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $administartive_amount),
  7718. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $insurance_fund),
  7719. PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $inspection_charges),
  7720. );
  7721. }
  7722. }
  7723. }
  7724. $cols = array(
  7725. 'Employee Code',
  7726. 'Employee Name',
  7727. 'EPF Wages', //that month earned basic
  7728. 'EPS Wages', // basic amount 3 conditions
  7729. 'EPF Contribution (EE Share)',
  7730. 'EPS Contribution due',
  7731. 'Diff EPF and EPS contribution (ER share)',
  7732. 'EDLI Wages',
  7733. 'PF Admin Charges',
  7734. 'EDLI Charges',
  7735. 'EDLI Admin Charges',
  7736. );
  7737.  
  7738.  
  7739.  
  7740. $roster_type = "payroll-PF-Report-month".$for_date;
  7741. $filenameexport = $roster_type;
  7742. $final_output = array('output' => $output,
  7743. 'cols' => $cols,
  7744. 'filenameexport' => $filenameexport);
  7745. return $final_output;
  7746. }
  7747. public static function flexiPayroll($post_data, $tenant_id = null,$from,$to,$status) {
  7748. $return = array();
  7749. $filter = $post_data['filter_id'];
  7750. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  7751. $output = array();
  7752. $user_array = array();
  7753. foreach ($users as $key => $user) {
  7754. $user_array[] = $user->user_id;
  7755. }
  7756. $final_cycle_start = new MongoDate(strtotime($from));
  7757. $final_cycle_end = new MongoDate(strtotime($to));
  7758. $criteria = new EMongoCriteria();
  7759. $criteria->updated_on('>=', $final_cycle_start);
  7760. $criteria->updated_on('<=', $final_cycle_end);
  7761. $criteria->status('==', $status);
  7762. $criteria->income_flexi('==', OtherClaims::FLEXI);
  7763. $criteria->tenant_id('==', Yii::app()->user->getTenantId());
  7764. $claims = OtherClaims::model()->findAll($criteria);
  7765. if(isset($claims) && !empty($claims)){
  7766. foreach ($claims as $key_claims => $value_claims) {
  7767. if(in_array($value_claims->user_id, $user_array)){
  7768. $user = $users[$value_claims->user_id];
  7769. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  7770. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  7771. $user_post = $user->getCurrentPosition($tenant_id);
  7772. $job_title = $user_post['designation'];
  7773. $department = $user_post['department'];
  7774. $business_unit = $user_post['business_unit'];
  7775. $output[] = array(
  7776. $employee_number,
  7777. $user_name,
  7778. $job_title,
  7779. $department,
  7780. $business_unit,
  7781. str_replace("_", " ",$value_claims->type),
  7782. $value_claims->bill_amount,
  7783. date('d-m-Y',$value_claims->created->sec),
  7784. date('d-m-Y',$value_claims->updated_on->sec),
  7785. );
  7786. }
  7787. } // EOF foreach
  7788. }
  7789. $cols = array(
  7790. 'Employee ID',
  7791. 'Name',
  7792. 'Job Title',
  7793. 'Department',
  7794. 'Business Unit',
  7795. 'Flexi Component',
  7796. 'Bill Amount',
  7797. 'Claim Date',
  7798. 'Approved Date',
  7799. );
  7800.  
  7801. $roster_type = "Experience Report";
  7802. $filenameexport = $roster_type;
  7803. $final_output = array('output' => $output,
  7804. 'cols' => $cols,
  7805. 'filenameexport' => $filenameexport);
  7806. return $final_output;
  7807. }
  7808. public static function pulsereports($post_data, $tenant_id = null,$from,$to) {
  7809. if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")) && Yii::app()->session['menu_owner']) {
  7810. $return = array();
  7811. $filter = $post_data['filter_id'];
  7812. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  7813. $output = array();
  7814. $user_array = array();
  7815. foreach ($users as $key => $user) {
  7816. $user_array[] = $user->id;
  7817. }
  7818. $from_start = new MongoDate(strtotime($from));
  7819. $to_end = new MongoDate(strtotime($to));
  7820. $criteria = new EMongoCriteria();
  7821. $criteria->created('>=', $from_start);
  7822. $criteria->created('<=', $to_end);
  7823. $criteria->tenant_id('==', Yii::app()->user->getTenantId());
  7824. $pulse = PulsePosts::model()->findAll($criteria);
  7825. if(isset($pulse) && !empty($pulse)){
  7826. foreach ($pulse as $key_pulse => $value_pulse) {
  7827. if(in_array($value_pulse->user_id, $user_array)){
  7828. if(isset($value_pulse->is_anonymous) && $value_pulse->is_anonymous == PulsePosts::SHOW){
  7829. $user = UserMongo::model()->tenant()->findByPk($value_pulse->user_id);
  7830. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  7831. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  7832. $user_post = $user->getCurrentPosition($tenant_id);
  7833. $job_title = $user_post['designation'];
  7834. $department = $user_post['department'];
  7835. $business_unit = $user_post['business_unit'];
  7836. }else{
  7837. $employee_number = "Anonymous";
  7838. $user_name = "Anonymous";
  7839. $job_title = "Anonymous";
  7840. $department = "Anonymous";
  7841. $business_unit = "Anonymous";
  7842. }
  7843. $output[] = array(
  7844. $employee_number,
  7845. $user_name,
  7846. $job_title,
  7847. $department,
  7848. $business_unit,
  7849. $value_pulse->pulse_smile,
  7850. $value_pulse->reason,
  7851. date('d-m-Y',$value_pulse->created->sec),
  7852. );
  7853. }
  7854. } // EOF foreach
  7855. }
  7856. $cols = array(
  7857. 'Employee ID',
  7858. 'Name',
  7859. 'Job Title',
  7860. 'Department',
  7861. 'Business Unit',
  7862. 'Pulse',
  7863. 'Comment',
  7864. 'Post Date',
  7865. );
  7866.  
  7867. $roster_type = "Pulse Report";
  7868. $filenameexport = $roster_type;
  7869. $final_output = array('output' => $output,
  7870. 'cols' => $cols,
  7871. 'filenameexport' => $filenameexport);
  7872. return $final_output;
  7873. }
  7874. }
  7875. public static function DepartmentStructure($post_data, $tenant_id = null, $user_id = null) {
  7876. $return = array();
  7877. $filter = $post_data['filter_id'];
  7878. $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
  7879. $output = array();
  7880. $leaves = Leaves::model()->getTenantLeaveListWithoutCompoff($tenant_id);
  7881. $l4_true = $l5_true = $l6_true = $l7_true = $l8_true = $l9_true = false;
  7882. $index = 0;
  7883. foreach ($users as $key => $user) {
  7884. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  7885. $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
  7886. $location = TenantOffices::getTenantOfficeLocationsNameWithCountryById($user->personal->office_location,$user->tenant_id);
  7887. $user_post = $user->getCurrentPosition($tenant_id);
  7888. $job_title = $user_post['designation'];
  7889. $department = $user_post['department'];
  7890. $business_unit = $user_post['business_unit'];
  7891. $department_id = $user_post['department_id'];
  7892. $l1 = $l2 = $l3 = $l4 = $l5 = $l6 = $l7 = $l8 = $l9 = "";
  7893. $department_details = UserDepartments::model()->tenant()->findByPk($department_id);
  7894. if(isset($department_details->parent_department) && !empty($department_details->parent_department)){
  7895. $l1_dept = UserDepartments::model()->tenant()->findByPk($department_details->parent_department);
  7896. $l1 = $l1_dept->department_name;
  7897. if(isset($l1_dept->parent_department) && !empty($l1_dept->parent_department)){
  7898. $l2_dept = UserDepartments::model()->tenant()->findByPk($l1_dept->parent_department);
  7899. $l2 = $l2_dept->department_name;
  7900. if(isset($l2_dept->parent_department) && !empty($l2_dept->parent_department)){
  7901. $l3_dept = UserDepartments::model()->tenant()->findByPk($l2_dept->parent_department);
  7902. $l3 = $l3_dept->department_name;
  7903. if(isset($l3_dept->parent_department) && !empty($l3_dept->parent_department)){
  7904. $l4_true = true;
  7905. $l4_dept = UserDepartments::model()->tenant()->findByPk($l3_dept->parent_department);
  7906. $l4 = $l4_dept->department_name;
  7907. if(isset($l4_dept->parent_department) && !empty($l4_dept->parent_department)){
  7908. $l5_true = true;
  7909. $l5_dept = UserDepartments::model()->tenant()->findByPk($l4_dept->parent_department);
  7910. $l5 = $l5_dept->department_name;
  7911. if(isset($l5_dept->parent_department) && !empty($l5_dept->parent_department)){
  7912. $l6_true = true;
  7913. $l6_dept = UserDepartments::model()->tenant()->findByPk($l5_dept->parent_department);
  7914. $l6 = $l6_dept->department_name;
  7915. if(isset($l6_dept->parent_department) && !empty($l6_dept->parent_department)){
  7916. $l7_true = true;
  7917. $l7_dept = UserDepartments::model()->tenant()->findByPk($l6_dept->parent_department);
  7918. $l7 = $l7_dept->department_name;
  7919. if(isset($l7_dept->parent_department) && !empty($l7_dept->parent_department)){
  7920. $l8_true = true;
  7921. $l8_dept = UserDepartments::model()->tenant()->findByPk($l7_dept->parent_department);
  7922. $l8 = $l8_dept->department_name;
  7923. if(isset($l8_dept->parent_department) && !empty($l8_dept->parent_department)){
  7924. $l9_true = true;
  7925. $l9_dept = UserDepartments::model()->tenant()->findByPk($l8_dept->parent_department);
  7926. $l9 = $l9_dept->department_name;
  7927. }
  7928. }
  7929. }
  7930. }
  7931. }
  7932. }
  7933. }
  7934. }
  7935. }
  7936. $output[] = array(
  7937. // $action_checkbox,
  7938. $employee_number,
  7939. $user_name,
  7940. $job_title,
  7941. $business_unit,
  7942. $location,
  7943. $department,
  7944. $l1,
  7945. $l2,
  7946. $l3,
  7947. );
  7948. if(isset($l4_true) && $l4_true) {
  7949. array_push($output[$index], $l4);
  7950. }
  7951. if(isset($l5_true) && $l5_true) {
  7952. array_push($output[$index], $l5);
  7953. }
  7954. if(isset($l6_true) && $l6_true) {
  7955. array_push($output[$index], $l6);
  7956. }
  7957. if(isset($l7_true) && $l7_true) {
  7958. array_push($output[$index], $l7);
  7959. }
  7960. if(isset($l8_true) && $l8_true) {
  7961. array_push($output[$index], $l8);
  7962. }
  7963. if(isset($l9_true) && $l9_true) {
  7964. array_push($output[$index], $l9);
  7965. }
  7966.  
  7967. $index++;
  7968. } // EOF foreach user
  7969.  
  7970. $cols = array(
  7971. 'Employee ID',
  7972. 'Name',
  7973. 'Job Title',
  7974. 'Business Unit',
  7975. 'Office Location',
  7976. 'Department',
  7977. 'Level 1',
  7978. 'Level 2',
  7979. 'Level 3',
  7980. );
  7981.  
  7982. if(isset($l4_true) && $l4_true) {
  7983. array_push($cols, 'Level 4');
  7984. }
  7985. if(isset($l5_true) && $l5_true) {
  7986. array_push($cols, 'Level 5');
  7987. }
  7988. if(isset($l6_true) && $l6_true) {
  7989. array_push($cols, 'Level 6');
  7990. }
  7991. if(isset($l7_true) && $l7_true) {
  7992. array_push($cols, 'Level 7');
  7993. }
  7994. if(isset($l8_true) && $l8_true) {
  7995. array_push($cols, 'Level 8');
  7996. }
  7997. if(isset($l9_true) && $l9_true) {
  7998. array_push($cols, 'Level 9');
  7999. }
  8000. $roster_type = "Leaves-Credited";
  8001. $filenameexport = $roster_type;
  8002. $final_output = array('output' => $output,
  8003. 'cols' => $cols,
  8004. 'filenameexport' => $filenameexport);
  8005. return $final_output;
  8006. }
  8007. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement