Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Short description for file
- *
- * Long description (if any) ...
- *
- * PHP version 5
- *
- * The license text...
- *
- * @category PHP
- * @package Roster
- * @author vineet singh
- * @license a
- * @version CVS: $Id:$
- * @link http://pear.php.net/package/Roster
- * @see References to other sections (if any)...
- */
- /**
- * Short description for class
- *
- * Long description (if any) ...
- *
- * @category PHP
- * @package Roster
- * @author vineet singh
- * @license a
- * @version Release: @package_version@
- * @link http://pear.php.net/package/Roster
- * @see References to other sections (if any)...
- */
- class Reports extends CFormModel {
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param string $className Parameter description (if any) ...
- * @return string Return description (if any) ...
- * @access public
- * @static
- */
- public static function model($className = __CLASS__) {
- return parent::model($className);
- }
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @return string Return description (if any) ...
- * @access public
- */
- public function primaryKey() {
- return 'id';
- }
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @return string Return description (if any) ...
- * @access public
- */
- public function getCollectionName() {
- return 'users';
- }
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param date $to_date Parameter description (if any) ...
- * @param date $from_date Parameter description (if any) ...
- * @return mixed Return description (if any) ...
- * @access public
- * @static
- */
- public static function calculate_experience($to_date, $from_date) {
- $interval = date_diff(date_create(date('Y-m-d', $to_date)), date_create(date('Y-m-d', $from_date)));
- $diff = $interval->format("Years:%Y,Months:%M,Days:%d");
- $a_out = array();
- array_walk(explode(',', $diff), function($val, $key) use(&$a_out) {
- $v = explode(':', $val);
- $a_out[$v[0]] = $v[1];
- });
- return $a_out;
- }
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param array $post_data Parameter description (if any) ...
- * @param unknown $tenant_id Parameter description (if any) ...
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- public static function getExperienceRoster($post_data, $tenant_id = null) {
- $return = array();
- //$sr_no=1;
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- foreach ($users as $key => $user) {
- $total_past_y = 0;
- $total_past_m = 0;
- $total_cur_y = 0;
- $total_cur_m = 0;
- $total_ex_m = 0;
- $total_ex_y = 0;
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- if (isset($user['past_work']) && !empty($user['past_work'])) {
- foreach ($user['past_work'] as $key => $work) {
- $diff_work = self::calculate_experience($work['to_date']->sec, $work['from_date']->sec);
- $total_past_y += intval($diff_work['Years']);
- $total_past_m += intval($diff_work['Months']);
- }
- if ($total_past_m > 12) {
- $total_past_y += intval($total_past_m / 12);
- $total_past_m = $total_past_m % 12;
- }
- $past_work_ex = $total_past_y . "y " . $total_past_m . "m";
- } else {
- $past_work_ex = "";
- }
- if (isset($user->doj->sec) && $user->doj->sec != "") {
- $diff_cur_work = self::calculate_experience(time(), $user->doj->sec);
- $total_cur_y = $diff_cur_work['Years'];
- $total_cur_m = $diff_cur_work['Months'];
- $cur_work_ex = $total_cur_y . "y " . $total_cur_m . "m";
- } else {
- $cur_work_ex = "";
- }
- if (!empty($user['past_work'])) {
- $total_ex_m = intval($total_past_m) + intval($total_cur_m);
- $total_ex_y = intval($total_past_y) + intval($total_cur_y);
- if ($total_ex_m > 12) {
- $total_ex_y += intval($total_ex_m / 12);
- $total_ex_m = $total_ex_m % 12;
- }
- $total_ex = $total_ex_y . "y " . $total_ex_m . "m";
- } elseif (!empty($user['designation'])) {
- $total_ex = $total_cur_y . "y " . $total_cur_m . "m";
- } else {
- $total_ex = "";
- }
- // $action_checkbox = "<input type=\"checkbox\" name=\"roster_action\" value=\"\">";
- $output[] = array(
- // $action_checkbox,
- $employee_number,
- $user_name,
- $job_title,
- $department,
- $business_unit,
- $past_work_ex,
- $cur_work_ex,
- $total_ex
- );
- } // EOF foreach
- // echo "<pre>"; print_r($output); exit("</pre> \n exited here ");
- $cols = array(
- // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
- //'Sr No',
- 'Employee ID',
- 'Name',
- 'Job Title',
- 'Department',
- 'Business Unit',
- 'Past Experience',
- 'Current Experience',
- 'Total Experience'
- );
- $roster_type = "Experience Report";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- // EOF function
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param array $post_data Parameter description (if any) ...
- * @param unknown $tenant_id Parameter description (if any) ...
- * @param unknown $user_id Parameter description (if any) ...
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- public static function getLeavesCredited($post_data, $tenant_id = null, $user_id = null) {
- $return = array();
- //$sr_no=1;
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- $leaves = Leaves::model()->getTenantLeaveListWithoutCompoff($tenant_id);
- $index = 0;
- foreach ($users as $key => $user) {
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- // $action_checkbox = "<input type=\"checkbox\" name=\"roster_action\" value=\"\">";
- $leaves_user_allowed = Leaves::model()->getLeaveListWithoutCompOff($tenant_id, $user->user_id);
- unset($userleaves);
- foreach ($leaves as $leave_id => $leave) {
- if (array_key_exists($leave_id, $leaves_user_allowed)) {
- $userleaves[] = LeavesHelper::individualLeaveBalance($user->user_id, $tenant_id, $leave_id);
- } else {
- $userleaves[] = array(
- 'leave_name' => 'NA',
- 'balance' => 'NA',
- 'total' => 'NA',
- 'prevBalance' => 'NA'
- );
- }
- }
- $output[] = array(
- // $action_checkbox,
- $employee_number,
- $user_name,
- $job_title,
- $department,
- $business_unit,
- );
- for ($i = 0; $i < count($userleaves); $i++) {
- array_push($output[$index], $userleaves[$i]['total']);
- }
- $index++;
- } // EOF foreach user
- $cols = array(
- // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
- //'Sr No',
- 'Employee ID',
- 'Name',
- 'Job Title',
- 'Department',
- 'Business Unit',
- );
- foreach ($leaves as $leave_id => $leave_name) {
- array_push($cols, $leave_name);
- }
- $roster_type = "Leaves-Credited";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- // EOF function
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param array $post_data Parameter description (if any) ...
- * @param unknown $tenant_id Parameter description (if any) ...
- * @param unknown $user_id Parameter description (if any) ...
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- public static function getLeavesNew($post_data, $tenant_id = null, $user_id = null, $from, $to) {
- $return = array();
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- // $leaves = TenantLeaves::model()->findAllByAttributes(array('tenant_id'=>$tenant_id));
- // $leaves = Leaves::getLeaveList(null,null,true);
- $leavesModel = Leaves::model()->tenant($tenant_id)->findAll();
- foreach ($leavesModel as $key => $value) {
- $leaves[$value->id] = $value->name;
- }
- $index = 0;
- $begin = new DateTime($from);
- $end = new DateTime($to);
- $end = $end->modify('+1 day');
- $interval = new DateInterval('P1D');
- $daterange = new DatePeriod($begin, $interval, $end);
- $from = strtotime($from);
- $to = strtotime($to);
- $criteria = new EMongoCriteria();
- foreach ($users as $key => $user) {
- $totalDays = 0;
- $workingDays = 0;
- $workingDaysCount = 0;
- $appliedOn = "";
- $leaveType = "";
- $fromDate = "";
- $toDate = "";
- $totalDays = "";
- $workingDays = "";
- $isHalfDay = "";
- $isUnpaid = "";
- $approvedBy = "";
- $approvalDate = "";
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $criteria->from_date('>=', new MongoDate($from));
- $criteria->from_date('<=', new MongoDate($to));
- $criteria->user_id = $user->id;
- $userLeaves = UserLeaves::model()->tenant($tenant_id)->findAll($criteria);
- if (!empty($userLeaves)) {
- foreach ($userLeaves as $userLeave) {
- $leaveMessage = $userLeave->message();
- if ($userLeave->status == UserLeaves::STATUS_APPROVED) {
- $approvedBy = $leaveMessage->getLeaveApprover();
- if (isset($leaveMessage->last_modified->sec)) {
- $approvalDate = date("Y-m-d", $leaveMessage->last_modified->sec);
- }
- $appliedOn = date("d-m-Y", $userLeave->created->sec);
- $leaveType = ($userLeave->leave_id == "unpaid") ? "Unpaid Leave" : $leaves[$userLeave->leave_id];
- $fromDate = date("Y-m-d", $userLeave->from_date->sec);
- $toDate = date("Y-m-d", $userLeave->to_date->sec);
- $totalDays = count($leaveMessage->attachments["items"]["total_days"]);
- $isUnpaid = ($userLeave->isUnpaid == UserLeaves::LEAVE_PAID ) ? "Paid" : "Unpaid";
- $workingDays = RandomHelper::getWorkingDays($userLeave->from_date->sec, $userLeave->to_date->sec, $user->id, $tenant_id);
- $workingDaysCount = $totalDays;
- if($userLeave->is_half_day == UserLeaves::HALF_DAY_YES)
- {
- $isHalfDay = "Half Day";
- $totalDays = "0.5";
- $workingDaysCount = "0.5";
- }
- else{
- $isHalfDay = "Full Day";
- }
- $output[] = array(
- $employee_number,
- $user_name,
- $job_title,
- $department,
- $appliedOn,
- $leaveType,
- $fromDate,
- $toDate,
- $totalDays,
- $workingDaysCount,
- $isHalfDay,
- $isUnpaid,
- $approvedBy,
- $approvalDate
- );
- }
- }
- }
- $index++;
- } // EOF foreach user
- $cols = array(
- // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
- //'Sr No',
- 'Employee ID',
- 'Name',
- 'Job Title',
- 'Department',
- 'Applied on||date on which leave application request was created/made',
- 'Leave Type||this is the type of leave applied',
- 'From||date from which leave duration begins',
- 'To||date on which leave duration ends',
- 'Total Days||total days covered during leave period including holidays, weekly offs and working days',
- 'Working Days||total working days covered in leave period',
- 'Is it Half-day||this column says whether this is a half-day leave or not',
- 'Paid/Unpaid||here you\'ll see if it\'s been counted as a paid or an unpaid leave',
- 'Approved by||leave was approved by the person mentioned in this column',
- 'Approval date||leave was approved on the date mentioned here',
- );
- $roster_type = "New Leave Report";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- // EOF function
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param array $post_data Parameter description (if any) ...
- * @param unknown $tenant_id Parameter description (if any) ...
- * @param unknown $user_id Parameter description (if any) ...
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- public static function getLeavesTaken($post_data, $tenant_id, $from, $to) {
- $return = array();
- if(date('Y-m',strtotime($to)) == date('Y-m'))
- {
- $to = date('Y-m')."-".date('t', strtotime($from));
- }
- //$for_month = "2015-08";
- //$sr_no=1;
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- // $leaves = Leaves::model()->getLeaveList($tenant_id, $user_id);
- $leaves = Leaves::model()->getTenantLeaveListWithoutCompoff($tenant_id);
- $index = 0;
- foreach ($users as $key => $user) {
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $action_checkbox = "<input type=\"checkbox\" name=\"roster_action\" value=\"\">";
- $leaves_user_allowed = Leaves::model()->getLeaveListWithoutCompOff($tenant_id, $user->user_id);
- unset($userleaves);
- foreach ($leaves as $leave_id => $leave) {
- //$userleaves[] = LeavesHelper::individualLeaveBalance($user->user_id, $tenant_id, $leave_id);
- /*if (array_key_exists($leave_id, $leaves_user_allowed)) {
- $userleaves[] = LeavesHelper::individualLeaveBalance($user->user_id, $tenant_id, $leave_id, $from, $to);
- } else {
- $userleaves[] = array(
- 'leave_name' => 'NA',
- 'balance' => 'NA',
- 'total' => 'NA',
- 'prevBalance' => 'NA'
- );
- }*/
- $leaves_approved = UserLeaves::model()->user_approved_leave($user->id, $leave_id)->forMonth(null, $from, $to)->paid()->findAll();
- //$leaves_approved = UserLeaves::model()->user_approved_leave($user->id, $leave_id)->forMonth($for_month)->paid()->findAll();
- $total_days = 0;
- foreach ($leaves_approved as $le)
- {
- $wekly_off_days = RandomHelper::getWorkingDays($le->from_date->sec, $le->to_date->sec, $le->user_id, $le->tenant_id);
- if (!empty($wekly_off_days))
- {
- if ($le->is_half_day == UserLeaves::HALF_DAY_YES)
- {
- $total_days += 0.5;
- }
- }
- else
- {
- if ($total_days > 0)
- {
- $total_days -= 0.5;
- }
- }
- }
- $counter = 0;
- $total_data_of_leaves = UserLeaves::getCountOfMonths($user->id, $leave_id,null, 1, $from, $to);
- //$total_data_of_leaves = UserLeaves::getCountOfMonths($user->id, $leave_id,$for_month, 1);
- if ($total_data_of_leaves > 0)
- {
- $counter = $total_data_of_leaves - $total_days;
- }
- else
- {
- $counter = $total_data_of_leaves;
- }
- $userleaves[] = $counter;
- }
- $output[] = array(
- // $action_checkbox,
- $employee_number,
- $user_name,
- $job_title,
- $department,
- $business_unit,
- );
- for ($i = 0; $i < count($userleaves); $i++) {
- /* if ($userleaves[$i]['total'] != "NA") {
- $prev_bal_leaves = (isset($userleaves[$i]['prevBalance'])) ? $userleaves[$i]['prevBalance'] : 0;
- $total_leaves_with_prev = $userleaves[$i]['total'] + $userleaves[$i]['prevBalance'];
- $newfinal = $total_leaves_with_prev - $userleaves[$i]['balance'];
- } else {
- $newfinal = "NA";
- }*/
- $newfinal = $userleaves[$i];
- array_push($output[$index], $newfinal);
- }
- $index++;
- } // EOF foreach user
- $cols = array(
- // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
- //'Sr No',
- 'Employee ID',
- 'Name',
- 'Job Title',
- 'Department',
- 'Business Unit',
- );
- foreach ($leaves as $leave_id => $leave_name) {
- array_push($cols, $leave_name);
- }
- $roster_type = "Leaves-Taken-or-Used";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- // EOF function
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param array $post_data Parameter description (if any) ...
- * @param unknown $tenant_id Parameter description (if any) ...
- * @param unknown $user_id Parameter description (if any) ...
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- public static function getLeavesBalance($post_data, $tenant_id, $user_id = null) {
- $return = array();
- //$sr_no=1;
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- //$leaves = Leaves::model()->getLeaveList($tenant_id, $user_id);
- $leaves = Leaves::model()->getTenantLeaveListWithoutCompoff($tenant_id);
- $index = 0;
- foreach ($users as $key => $user) {
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $leaves_user_allowed = Leaves::model()->getLeaveListWithoutCompOff($tenant_id, $user->user_id);
- $action_checkbox = "<input type=\"checkbox\" name=\"roster_action\" value=\"\">";
- unset($userleaves);
- foreach ($leaves as $leave_id => $leave) {
- // echo "<pre>"; print_r($leaves); exit("</pre> \n exited here ");
- //$userleaves[] = LeavesHelper::IndividualLeaveBalance($user->user_id, $tenant_id, $leave_id);
- if (array_key_exists($leave_id, $leaves_user_allowed)) {
- $userleaves[] = LeavesHelper::individualLeaveBalance($user->user_id, $tenant_id, $leave_id);
- } else {
- $userleaves[] = array(
- 'leave_name' => 'NA',
- 'balance' => 'NA',
- 'total' => 'NA',
- 'prevBalance' => 'NA'
- );
- }
- }
- $output[] = array(
- // $action_checkbox,
- $employee_number,
- $user_name,
- $job_title,
- $department,
- $business_unit,
- );
- for ($i = 0; $i < count($userleaves); $i++) {
- array_push($output[$index], $userleaves[$i]['balance']);
- }
- $index++;
- } // EOF foreach user
- // echo "<pre>"; print_r($output); exit("</pre> \n exited here ");
- $leaves = Leaves::model()->getTenantLeaveListWithoutCompoff($tenant_id);
- $cols = array(
- // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
- //'Sr No',
- 'Employee ID',
- 'Name',
- 'Job Title',
- 'Department',
- 'Business Unit',
- );
- foreach ($leaves as $leave_id => $leave_name) {
- array_push($cols, $leave_name);
- }
- $roster_type = "Leaves-Balance";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- // EOF function
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param array $post_data Parameter description (if any) ...
- * @param unknown $tenant_id Parameter description (if any) ...
- * @param unknown $user_id Parameter description (if any) ...
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- public static function getLeavesSummary($post_data, $tenant_id, $user_id = null) {
- /* $name = "leavesSummary_{$tenant_id}_all";
- $cache = Yii::app()->cache->get($name);
- if (isset($cache) && !empty($cache)) {
- return $cache;
- } else { */
- $return = array();
- //$sr_no=1;
- $userleaves = array();
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- //$leaves = Leaves::model()->getLeaveList($tenant_id, $user_id);
- $leaves = Leaves::model()->getTenantLeaveListWithoutCompoff($tenant_id);
- /* removing compoff from the list */
- if (isset($leaves) && !empty($leaves)) {
- foreach ($leaves as $key => $leave) {
- if ($leave != "Compensatory Off") {
- $output_userleaves[$key] = $leave;
- }
- }
- $leaves = $output_userleaves;
- }
- /* removing compoff from the list */
- $index = 0;
- foreach ($users as $key => $user) {
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $leaves_user_allowed = Leaves::model()->getLeaveListWithoutCompOff($tenant_id, $user->user_id);
- $action_checkbox = "<input type=\"checkbox\" name=\"roster_action\" value=\"\">";
- unset($userleaves);
- foreach ($leaves as $leave_id => $leave) {
- //$userleaves[] = LeavesHelper::individualLeaveBalance($user->user_id, $tenant_id, $leave_id);
- if (array_key_exists($leave_id, $leaves_user_allowed)) {
- $userleaves[] = LeavesHelper::individualLeaveBalance($user->user_id, $tenant_id, $leave_id);
- } else {
- $userleaves[] = array(
- 'leave_name' => 'NA',
- 'balance' => 'NA',
- 'total' => 'NA',
- 'prevBalance' => 'NA'
- );
- }
- }
- $output[] = array(
- // $action_checkbox,
- $employee_number,
- $user_name,
- );
- if (isset($userleaves)) {
- for ($i = 0; $i < count($userleaves); $i++) {
- for ($j = 0; $j < 3; $j++) {
- switch ($j) {
- case 0:
- $column = $userleaves[$i]['total'];
- break;
- case 1:
- if ($userleaves[$i]['total'] != "NA") {
- $column = $userleaves[$i]['total'] - $userleaves[$i]['balance'] + $userleaves[$i]['prevBalance'];
- } else {
- $column = "NA";
- }
- break;
- case 2:
- $column = $userleaves[$i]['balance'];
- break;
- }
- array_push($output[$index], $column);
- }
- //array_push($output[$index], $column);
- }
- }
- $index++;
- } // EOF foreach user
- $cols = array(
- // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
- //'Sr No',
- 'Employee ID',
- 'Name',
- );
- foreach ($leaves as $leave_id => $leave_name) {
- for ($i = 0; $i < 3; $i++) {
- switch ($i) {
- case 0:
- $colname = $leave_name . "\\n(Credited)";
- break;
- case 1:
- $colname = $leave_name . "\\n(Taken)";
- break;
- case 2:
- $colname = $leave_name . "\\n(Balance)";
- break;
- }
- array_push($cols, $colname);
- }
- }
- $roster_type = "Leaves-Summary";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- // Yii::app()->cache->set($name, $final_output, 0);
- return $final_output;
- // }
- }
- // EOF function
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param array $post_data Parameter description (if any) ...
- * @param unknown $tenant_id Parameter description (if any) ...
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- public static function getBirthdayRoster($post_data, $tenant_id = null) {
- $return = array();
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- foreach ($users as $key => $user) {
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- if (isset($user['personal']['dob']->sec)) {
- $user_dob = date("Y-m-d", $user['personal']['dob']->sec);
- if (($timestamp = strtotime($user_dob)) !== false) {
- $php_date = getdate($timestamp);
- $dob_year = date("Y", $timestamp);
- $dob_month = date("M", $timestamp);
- $dob_day = date("d", $timestamp);
- $age = date("Y") - date("Y", $timestamp) . " y ";
- $age .= (date("m") > date("m", $timestamp)) ? date("m") - date("m", $timestamp) : date("m") - date("m", $timestamp) + 12;
- $age .= " m";
- $no_days_remain = self::days_till_birthday(date("d", $timestamp) . " " . date("M", $timestamp));
- }
- } else {
- $dob_year = "N.A.";
- $dob_month = "N.A.";
- $dob_day = "N.A.";
- $age = "N.A.";
- $no_days_remain = "N.A.";
- }
- // $action_checkbox = "<input type=\"checkbox\" name=\"roster_action\" value=\"\">";
- $output[] = array(
- // $action_checkbox,
- $employee_number,
- $user_name,
- $job_title,
- $department,
- $business_unit,
- $dob_day,
- $dob_month,
- $dob_year,
- $age,
- $no_days_remain,
- );
- } // EOF foreach
- // echo "<pre>"; print_r($output); exit("</pre> \n exited here ");
- $cols = array(
- // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
- //'SR NO',
- 'Employee ID',
- 'Name',
- 'Job Title',
- 'Department',
- 'Business Unit',
- 'Day',
- 'Month',
- 'Year',
- 'Age',
- 'Days Remain'
- );
- $filenameexport = "Birthday-Data";
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- // EOF function
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param array $post_data Parameter description (if any) ...
- * @param unknown $tenant_id Parameter description (if any) ...
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- /*public static function getCustomRoster($post_data, $tenant_id = null) {
- //echo "<pre>"; print_r($post_data); exit("</pre> \n exited here");
- $fields_arrary = explode("|", $post_data['fields']);
- $return = array();
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- $idx = 0;
- foreach ($users as $key => $user) {
- // echo "<pre>"; print_r($user); exit("</pre> \n exited here ");
- foreach ($fields_arrary as $fields_key => $fields_value) {
- $a = array('');
- $a = explode("->", $fields_value);
- switch ($a[1]) {
- case 'cur_address':
- $cur_add = "";
- $cur_add .= (isset($user[$a[0]]['address'][0]['address'])) ? $user[$a[0]]['address'][0]['address'] : "";
- $cur_add .= (isset($user[$a[0]]['address'][0]['city'])) ? $user[$a[0]]['address'][0]['city'] : "";
- $cur_add .= (isset($user[$a[0]]['address'][0]['state'])) ? $user[$a[0]]['address'][0]['state'] : "";
- $op[$idx][] = $cur_add;
- break;
- case 'additional_contact':
- $add_con = "";
- // echo "<pre>"; print_r($a); echo("</pre>");
- // echo "<pre>"; print_r($user['contact']['additional_contact']); exit("</pre> \n exited here ");
- foreach ($user['contact']['additional_contact'] as $key => $value) {
- if (isset($value)) {
- if ($value['type'] == $a[2]) {
- $add_con .= (isset($value['value'])) ? $value['value'] : "";
- $add_con .= ",";
- }
- }
- }
- $add_con = rtrim($add_con, ",");
- $op[$idx][] = $add_con;
- break;
- case 'per_address':
- $per_add = "";
- $per_add .= (isset($user[$a[0]]['address'][0]['address'])) ? $user[$a[0]]['address'][0]['address'] : "";
- $per_add .= (isset($user[$a[0]]['address'][0]['city'])) ? $user[$a[0]]['address'][0]['city'] : "";
- $per_add .= (isset($user[$a[0]]['address'][0]['state'])) ? $user[$a[0]]['address'][0]['state'] : "";
- $op[$idx][] = $per_add;
- break;
- case 'dob':
- $dob = (isset($user['personal']['dob']->sec)) ? date("d-M-Y", $user['personal']['dob']->sec) : "";
- $op[$idx][] = $dob;
- break;
- case 'gender':
- // echo "<pre>"; print_r($a); exit("</pre> \n exited here ");
- if (isset($user['personal']['gender'])) {
- switch ($user['personal']['gender']) {
- case 1:
- $gender = "Male";
- break;
- case 2:
- $gender = "Female";
- break;
- default:
- $gender = "";
- break;
- }
- } else {
- $gender = "";
- }
- $op[$idx][] = $gender;
- break;
- case 'marital_status':
- // echo "<pre>"; print_r($a); exit("</pre> \n exited here ");
- if (isset($user['personal']['marital_status'])) {
- switch ($user['personal']['marital_status']) {
- case 1:
- $marital_status = "Married";
- break;
- case 2:
- $marital_status = "Single";
- break;
- default:
- $marital_status = "";
- break;
- }
- } else {
- $marital_status = "";
- }
- $op[$idx][] = $marital_status;
- break;
- case 'anniversary_date':
- $anniversary_date = (isset($user['personal']['anniversary_date']->sec)) ? date("d-M-Y", $user['personal']['anniversary_date']->sec) : "";
- $op[$idx][] = $anniversary_date;
- break;
- case 'office_location':
- // echo "<pre>"; print_r($a); exit("</pre> \n exited here ");
- $tentaoffice_obj = TenantOffices::model()->findAllByAttributes(array('id' => $user[$a[0]][$a[1]]));
- if (isset($tentaoffice_obj) && !empty($tentaoffice_obj)) {
- $city = City::model()->findByPk($tentaoffice_obj[0]['city']);
- // echo "<pre>"; print_r($city); exit("</pre> \n exited here ");
- $office_location = (isset($city) && isset($city->name)) ? $city->name : "";
- } else {
- $office_location = "Not Found";
- }
- $op[$idx][] = $office_location;
- break;
- default:
- $op[$idx][] = $user[$a[0]][$a[1]];
- break;
- }
- }
- $idx += 1;
- } // EOF foreach
- // echo "<pre>"; print_r($output); echo("</pre>");
- // echo "<pre>"; print_r($op[11]); exit("</pre> \n exited here ");
- $custom_roster_data = self::loadCustomRosterFilter();
- $cols = array(
- // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
- );
- $fields_arrary = explode("|", $post_data['fields']);
- $idx = 0;
- foreach ($fields_arrary as $fields_key => $fields_value) {
- $a = array('');
- $a = explode("->", $fields_value);
- if (isset($a[2])) {
- $colname = $custom_roster_data[$a[0]][$a[1]][$a[2]];
- } else {
- $colname = $custom_roster_data[$a[0]][$a[1]];
- }
- array_push($cols, $colname);
- }
- $filenameexport = "Custom Roster";
- $final_output = array('output' => $op,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport
- );
- return $final_output;
- }
- // EOF function Name month day list P A WO H L AdjL
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param array $post_data Parameter description (if any) ...
- * @param unknown $tenant_id Parameter description (if any) ...
- * @param unknown $from Parameter description (if any) ...
- * @param unknown $to Parameter description (if any) ...
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- public static function getCustomRoster($post_data, $tenant_id = null) {
- $fields_arrary = explode("|", $post_data['fields']);
- if(in_array("company->inactive", $fields_arrary)){
- $post_data['active_inactive'] = 2;
- if (($key = array_search('company->inactive', $fields_arrary)) !== false) {
- unset($fields_arrary[$key]);
- array_values($fields_arrary);
- }
- }
- $return = array();
- $filter = $post_data['filter_id'];
- $tenant_id = Yii::app()->user->getTenantId();
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- $idx = 0;
- foreach ($users as $key => $user) {
- // echo "<pre>"; print_r($user); exit("</pre> \n exited here ");
- foreach ($fields_arrary as $fields_key => $fields_value) {
- $a = array('');
- $a = explode("->", $fields_value);
- switch ($a[1]) {
- case 'cur_address':
- $current = array();
- $contact_details = $user->contact;
- $current['address'] = (isset($contact_details['address'][0]['address']) && $contact_details['address'][0]['address'] != "") ? $contact_details['address'][0]['address'] : "";
- $current['city'] = (isset($contact_details['address'][0]['city']) && $contact_details['address'][0]['city'] != "") ? City::getCityById($contact_details['address'][0]['city']) : "";
- $current['state'] = (isset($contact_details['address'][0]['state']) && $contact_details['address'][0]['state'] != "") ? State::getStateById($contact_details['address'][0]['state']) : "";
- $current['country'] = (isset($contact_details['address'][0]['country']) && $contact_details['address'][0]['country'] != "") ? Country::getCountryById($contact_details['address'][0]['country']) : "";
- $current['pincode'] = (isset($contact_details['address'][0]['pincode']) && $contact_details['address'][0]['pincode'] != "") ? $contact_details['address'][0]['pincode'] : "";
- $op[$idx][] = implode(", ", $current);
- break;
- case 'additional_contact':
- $add_con = "";
- foreach ($user['contact']['additional_contact'] as $key => $value) {
- if (isset($value)) {
- if ($value['type'] == $a[2]) {
- $add_con .= (isset($value['value'])) ? $value['value'] : "";
- $add_con .= ",";
- }
- }
- }
- $add_con = rtrim($add_con, ",");
- $op[$idx][] = $add_con;
- break;
- case 'per_address':
- $permanent = array();
- $contact_details = $user->contact;
- $permanent['address'] = (isset($contact_details['address'][1]['address']) && $contact_details['address'][1]['address'] != "") ? $contact_details['address'][1]['address'] : "";
- $permanent['city'] = (isset($contact_details['address'][1]['city']) && $contact_details['address'][1]['city'] != "") ? City::getCityById($contact_details['address'][1]['city']) : "";
- $permanent['state'] = (isset($contact_details['address'][1]['state']) && $contact_details['address'][1]['state'] != "") ? State::getStateById($contact_details['address'][1]['state']) : "";
- $permanent['country'] = (isset($contact_details['address'][1]['country']) && $contact_details['address'][1]['country'] != "") ? Country::getCountryById($contact_details['address'][1]['country']) : "";
- $permanent['pincode'] = (isset($contact_details['address'][1]['pincode']) && $contact_details['address'][1]['pincode'] != "") ? $contact_details['address'][1]['pincode'] : "";
- $op[$idx][] = implode(", ", $permanent);
- break;
- case 'custom_fields':
- $cus_field = "";
- if (isset($user->personal->custom_fields[$a[2]]))
- {
- if ($user->personal->custom_fields[$a[2]] == "1")
- {
- $cus_field .= 'Yes';
- }
- else if ($user->personal->custom_fields[$a[2]] == "0" || $user->personal->custom_fields[$a[2]] == "")
- {
- $cus_field .= 'No';
- }
- else
- {
- $cus_field .= (is_array($user->personal->custom_fields[$a[2]])) ? implode(", ", $user->personal->custom_fields[$a[2]]) : $user->personal->custom_fields[$a[2]];
- }
- }
- else
- {
- if (isset($user->payroll_profile->custom_fields[$a[2]]))
- {
- if ($user->payroll_profile->custom_fields[$a[2]] == "1")
- {
- $cus_field .= "Yes";
- } else {
- $cus_field .= "No";
- }
- } else {
- $cus_field .= "No";
- }
- }
- $op[$idx][] = $cus_field;
- break;
- case 'dob':
- $dob = (isset($user['personal']['dob']->sec)) ? date("d-M-Y", $user['personal']['dob']->sec) : "";
- $op[$idx][] = $dob;
- break;
- case 'deactivate_date':
- $deactivate_date = (isset($user['deactivate_date']->sec)) ? date("d-M-Y", $user['deactivate_date']->sec) : "";
- $op[$idx][] = $deactivate_date;
- break;
- case 'manager':
- $direct_manager = (isset($user->manager_id) && $user->manager_id != "") ? UserMongo::getFullnameById($user->manager_id) : "No Direct Manager";
- $op[$idx][] = $direct_manager;
- break;
- case 'dotted_manager':
- $dotted_line_manager = (isset($user->dotted_line_manager) && $user->dotted_line_manager != "") ? UserMongo::getFullnameById($user->dotted_line_manager) : "No Dotted Manager";
- $op[$idx][] = $dotted_line_manager;
- break;
- case 'emp_type':
- $emp_type = (isset($user['personal']['type'])) ? TenantUserTypes::getTypesNameById($user['personal']['type']) : "";
- $op[$idx][] = $emp_type;
- break;
- case 'probation':
- $probation = (isset($user->probation_period)) ? ProbationPeriod::getProbationNameById($user->probation_period) : "";
- $op[$idx][] = $probation;
- break;
- case 'emp_id':
- $emp_id = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "";
- $op[$idx][] = $emp_id;
- break;
- case 'confirmation':
- //Date of confirmation
- if(isset($user->date_of_confirmation) && $user->date_of_confirmation != ""){
- $date_confirmation = (isset($user->date_of_confirmation->sec)) ? date('d-m-Y',$user->date_of_confirmation->sec) : $user->date_of_confirmation;
- } else {
- if(isset($user->doj->sec,$user->probation_period) && $user->probation_period != "")
- {
- $prb = ProbationPeriod::model()->tenant()->findByPk($user->probation_period);
- if(isset($prb) && !empty($prb))
- {
- $number_of_days = $prb->number_of_days + 1;
- $date = strtotime(date("Y-m-d", $user->doj->sec) . " +".$number_of_days ."days");
- $date_confirmation = date('d-m-Y' ,$date);
- }
- }
- else{
- $date_confirmation = (isset($user->doj->sec)) ? date('d-m-Y',$user->doj->sec) : "";
- }
- }
- $op[$idx][] = $date_confirmation;
- break;
- case 'pf_number':
- $pf_number = (isset($user->pf_number)) ? $user->pf_number : "";
- $op[$idx][] = $pf_number;
- break;
- case 'esic_number':
- $esic_number = (isset($user->esic_number)) ? $user->esic_number : "";
- $op[$idx][] = $esic_number;
- break;
- case 'uan_number':
- $uan_number = (isset($user->uan_number)) ? $user->uan_number : "";
- $op[$idx][] = $uan_number;
- break;
- case 'emergency_contact_person':
- $emergency_contact_person = (isset($user->emergency_contact_person)) ? $user->emergency_contact_person : "";
- $op[$idx][] = $emergency_contact_person;
- break;
- case 'emergency_contact_number':
- $emergency_contact_number = (isset($user->emergency_contact_number)) ? $user->emergency_contact_number : "";
- $op[$idx][] = $emergency_contact_number;
- break;
- case 'ctc':
- $ctc_data = Ctc::model()->tenant($user->tenant_id)->user($user->id)->find();
- if(isset($ctc_data) && !empty($ctc_data)){
- $ctc = $ctc_data->getCtc();
- }else{
- $ctc = "N.A.";
- }
- $op[$idx][] = $ctc;
- break;
- case 'email':
- $email = "";
- $user_sql_data = User::model()->tenant()->findByPk($user->user_id);
- if(isset($user_sql_data) && !empty($user_sql_data)){
- $email = (isset($user_sql_data->selfservice) && $user_sql_data->selfservice == User::EMPLOYEE_SELFSERVICE_YES) ? $user_sql_data->email : "";
- }
- $op[$idx][] = $email;
- break;
- case 'gender':
- // echo "<pre>"; print_r($a); exit("</pre> \n exited here ");
- if (isset($user['personal']['gender'])) {
- switch ($user['personal']['gender']) {
- case 1:
- $gender = "Male";
- break;
- case 2:
- $gender = "Female";
- break;
- default:
- $gender = "";
- break;
- }
- } else {
- $gender = "";
- }
- $op[$idx][] = $gender;
- break;
- case 'marital_status':
- // echo "<pre>"; print_r($a); exit("</pre> \n exited here ");
- if (isset($user['personal']['marital_status'])) {
- switch ($user['personal']['marital_status']) {
- case 1:
- $marital_status = "Married";
- break;
- case 2:
- $marital_status = "Single";
- break;
- default:
- $marital_status = "";
- break;
- }
- } else {
- $marital_status = "";
- }
- $op[$idx][] = $marital_status;
- break;
- case 'anniversary_date':
- $anniversary_date = (isset($user['personal']['anniversary_date']->sec)) ? date("d-M-Y", $user['personal']['anniversary_date']->sec) : "";
- $op[$idx][] = $anniversary_date;
- break;
- case 'doj':
- $doj = (isset($user['doj']->sec)) ? date("d-M-Y", $user['doj']->sec) : "";
- $op[$idx][] = $doj;
- break;
- case 'department':
- $user_post = $user->getCurrentPosition($tenant_id);
- $department = (isset($user_post['department']) && $user_post['department'] != "") ? $user_post['department'] : "N.A.";
- $op[$idx][] = $department;
- break;
- case 'designation':
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = (isset($user_post['designation']) && $user_post['designation'] != "") ? $user_post['designation'] : "N.A.";
- $op[$idx][] = $job_title;
- break;
- case 'tenure':
- $diff_cur_work = self::calculate_experience(time(), $user->doj->sec);
- $total_cur_y = $diff_cur_work['Years'];
- $total_cur_m = $diff_cur_work['Months'];
- $cur_work_ex = $total_cur_y . "y " . $total_cur_m . "m";
- $op[$idx][] = $cur_work_ex;
- break;
- case 'dependents':
- if (isset($user['dependents']) && !empty($user['dependents'])) {
- $user_dependent = "";
- foreach ($user['dependents'] as $key => $dependents) {
- $dep_name = (isset($dependents['first_name'],$dependents['last_name'])) ? ucfirst($dependents['first_name'])." ".$dependents['last_name'] ." - " : "N.A.";
- $dep_relation = (isset($dependents['relation_type'])) ? $dependents['relation_type'] ." - " : "N.A.";
- $get_dep_age = (isset($dependents['dob']->sec)) ? self::calculate_experience(time(), $dependents['dob']->sec) : "N.A.";
- $age_dep = (isset($get_dep_age) && $get_dep_age != "N.A.") ? $get_dep_age['Years']."y ".$get_dep_age['Months']."m" : "N.A.";
- if(isset($dep_name) && $dep_name != "N.A."){
- $user_dependent = (isset($user_dependent) && $user_dependent != "") ? $user_dependent . "<br/>". $dep_name ." ". $dep_relation ." ". $age_dep : $dep_name ." ". $dep_relation ." ". $age_dep;
- }
- }
- } else {
- $user_dependent = "N.A.";
- }
- $op[$idx][] = $user_dependent;
- break;
- case 'band':
- $user_post = $user->getCurrentPosition($tenant_id);
- $band = (isset($user_post['band']) && $user_post['band'] != "") ? $user_post['band'] : "N.A.";
- $op[$idx][] = $band;
- break;
- case 'grade':
- $user_post = $user->getCurrentPosition($tenant_id);
- $grade = (isset($user_post['grade']) && $user_post['grade'] != "") ? $user_post['grade'] : "N.A.";
- $op[$idx][] = $grade;
- break;
- case 'business_unit':
- $user_post = $user->getCurrentPosition($tenant_id);
- $business_unit = (isset($user_post['business_unit']) && $user_post['business_unit'] != "") ? $user_post['business_unit'] : "N.A.";
- $op[$idx][] = $business_unit;
- break;
- case 'parent_company_id':
- $company_name = SubTenantProfile::getGroupCompanyNameId($user->getIsSubCompany());
- $parent_company = (isset($company_name) && $company_name != "") ? $company_name : "N.A.";
- $op[$idx][] = $parent_company;
- break;
- case 'office_location':
- if (isset($user->personal->office_location) && !empty($user->personal->office_location)) {
- $office_location = TenantOffices::getTenantOfficeLocationsNameWithCountryById($user->personal->office_location);
- } else {
- $office_location = "NA";
- }
- $op[$idx][] = $office_location;
- break;
- case 'office_area':
- if (isset($user->personal->office_location) && !empty($user->personal->office_location)) {
- $office_location_area = TenantOffices::getTenantOfficeLocationsArea($user->personal->office_location);
- } else {
- $office_location_area = "NA";
- }
- $op[$idx][] = $office_location_area;
- break;
- case 'office_city':
- if (isset($user->personal->office_location) && !empty($user->personal->office_location)) {
- $office_location_city = TenantOffices::getTenantOfficeLocationsCity($user->personal->office_location);
- } else {
- $office_location_city = "NA";
- }
- $op[$idx][] = $office_location_city;
- break;
- case 'office_state':
- if (isset($user->personal->office_location) && !empty($user->personal->office_location)) {
- $office_location_state = TenantOffices::getTenantOfficeLocationsState($user->personal->office_location);
- } else {
- $office_location_state = "NA";
- }
- $op[$idx][] = $office_location_state;
- break;
- case 'office_country':
- if (isset($user->personal->office_location) && !empty($user->personal->office_location)) {
- $office_location_country = TenantOffices::getTenantOfficeLocationsCountry($user->personal->office_location);
- } else {
- $office_location_country = "NA";
- }
- $op[$idx][] = $office_location_country;
- break;
- case 'shift':
- $shift_name = "";
- $timestamp = time();
- $user_shift_planner = UserShiftPlanner::getUserShift($user->id, $timestamp, null, 1);
- if(isset($user_shift_planner) && !empty($user_shift_planner)){
- $tenant_shift = TenantShift::getTenantShift($user_shift_planner['shift_id'],$user->tenant_id);
- if(isset($tenant_shift) && !empty($tenant_shift)){
- $shift_name = $tenant_shift->shift_name . " (". AttendanceHelper::getFormatedTime($tenant_shift->begin_time) ."-". AttendanceHelper::getFormatedTime($tenant_shift->end_time).")";
- }
- }
- $op[$idx][] = $shift_name;
- break;
- case 'policy':
- $policy_name = "";
- $timestamp = time();
- $user_shift_planner = UserShiftPlanner::getUserShift($user->id, $timestamp, null, 1);
- if(isset($user_shift_planner) && !empty($user_shift_planner)){
- $attendance_policy = AttendancePolicy::getAttendancePolicy($user_shift_planner['policy_id'],$user->tenant_id);
- if(isset($attendance_policy) && !empty($attendance_policy)){
- $policy_name = $attendance_policy->policy_name;
- }
- }
- $op[$idx][] = $policy_name;
- break;
- case 'weeklyoff':
- $weeklyoff = "";
- $timestamp = time();
- $user_shift_planner = UserShiftPlanner::getUserShift($user->id, $timestamp, null, 1);
- if(isset($user_shift_planner) && !empty($user_shift_planner)){
- $user_weekly_off = WeeklyOff::getWeeklyOff($user_shift_planner['weekly_off_id'],$user->tenant_id);
- if(isset($user_weekly_off) && !empty($user_weekly_off)){
- $non_working_days = $user_weekly_off->getNonWorkingDays();
- $weeklyoff = $user_weekly_off->weekly_off_name . " (". $non_working_days.")";
- }
- }
- $op[$idx][] = $weeklyoff;
- break;
- case 'location_type':
- $tentaoffice_obj_typ = TenantOffices::model()->findByAttributes(array('id' => $user->personal->office_location));
- if (isset($tentaoffice_obj_typ) && !empty($tentaoffice_obj_typ)) {
- $type_loc = (isset($tentaoffice_obj_typ->location_type) && $tentaoffice_obj_typ->location_type != "") ? '('. TenantLocationTypes::getTypesNameById($tentaoffice_obj_typ->location_type).')' :"";
- $office_location_type = $type_loc;
- } else {
- $office_location_type = "";
- }
- $op[$idx][] = $office_location_type;
- break;
- default:
- $op[$idx][] = $user[$a[0]][$a[1]];
- break;
- }
- }
- $idx += 1;
- } // EOF foreach
- // echo "<pre>"; print_r($output); echo("</pre>");
- // echo "<pre>"; print_r($op[11]); exit("</pre> \n exited here ");
- $custom_roster_data = self::loadCustomRosterFilter();
- $cols = array(
- // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
- );
- $fields_arrary = explode("|", $post_data['fields']);
- if (($key = array_search('company->inactive', $fields_arrary)) !== false) {
- unset($fields_arrary[$key]);
- array_values($fields_arrary);
- }
- $idx = 0;
- foreach ($fields_arrary as $fields_key => $fields_value) {
- $a = array('');
- $a = explode("->", $fields_value);
- if (isset($a[2])) {
- $colname = $custom_roster_data[$a[0]][$a[1]][$a[2]];
- } else {
- $colname = $custom_roster_data[$a[0]][$a[1]];
- }
- array_push($cols, $colname);
- }
- $filenameexport = "Custom Roster";
- $final_output = array('output' => $op,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport
- );
- // echo '<pre>';
- // print_r($final_output); exit;
- return $final_output;
- }
- // EOF function Name month day list P A WO H L AdjL
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param array $post_data Parameter description (if any) ...
- * @param unknown $tenant_id Parameter description (if any) ...
- * @param unknown $from Parameter description (if any) ...
- * @param unknown $to Parameter description (if any) ...
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- public static function getAttendanceSummaryRoster($post_data, $tenant_id = null, $from = null, $to = null) {
- $return = array();
- $index = 0;
- $output = array();
- $finaldata = array();
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $begin = new DateTime($from);
- $end = new DateTime($to);
- $end = $end->modify('+1 day');
- $interval = new DateInterval('P1D');
- $daterange = new DatePeriod($begin, $interval, $end);
- $from = strtotime($from);
- $to = strtotime($to);
- $criteria = new EMongoCriteria();
- $criteria->shift_date('>=', new MongoDate($from));
- $criteria->shift_date('<=', new MongoDate($to));
- foreach ($users as $key => $user) {
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $criteria->user_id = $user->id;
- $userAttendanceLogsold = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
- if(isset($userAttendanceLogsold) && !empty($userAttendanceLogsold)){
- foreach ($userAttendanceLogsold as $key_each => $value_each) {
- if(isset($value_each->shift_date->sec)){
- $date_each = date("d", $value_each->shift_date->sec);
- $userAttendanceLogs[$date_each] = $value_each;
- }
- }
- }
- // echo "<pre>"; print_r($userAttendanceLogs); exit("</pre> \n exited here \n");
- $present = 0;
- $absent = 0;
- $weeklyoff_count = 0;
- $holiday_count = 0;
- $leave_count = 0;
- $unpaidleave_count = 0;
- $return = array();
- $output[] = array(
- $employee_number,
- $user_name,
- );
- $jindex = 0;
- foreach ($daterange as $date) {
- $yindex = $date->format("d");
- $unpaidFlag = false;
- if (isset($userAttendanceLogs[$yindex])) {
- if ($date->format("d") == date("d", $userAttendanceLogs[$yindex]->shift_date->sec)) {
- $date = date("d", $userAttendanceLogs[$yindex]->shift_date->sec);
- if (isset($userAttendanceLogs[$yindex]->attendance_status)) {
- $status = $userAttendanceLogs[$yindex]->attendance_status;
- if ($status == UserAttendance::ATTENDANCE_STATUS_ABSENT)
- {
- $checkBothClockInClockOut = false;
- $checkOnlyClockIn = false;
- // Get policy_id to check policy for markin / markout / markboth
- $shift_planner_id = $userAttendanceLogs[$yindex]->shift_planner;
- // Get shift planner
- $useShiftPlanner = UserShiftPlanner::model()->user($user->id)->findByPk($shift_planner_id);
- if (!empty($useShiftPlanner))
- {
- $policy_id = $useShiftPlanner->policy_id;
- }
- else
- {
- $policy_id = "";
- }
- // Get user policy using policy Id.
- $attendancePolicy = AttendancePolicy::getAttendancePolicy($policy_id, $tenant_id);
- if (!empty($attendancePolicy))
- {
- if ($attendancePolicy->markin_policy->status == MarkinPolicy::MARKIN_BOTH)
- {
- $checkBothClockInClockOut = true;
- $checkOnlyClockIn = false;
- }
- else if ($attendancePolicy->markin_policy->status == MarkinPolicy::MARKIN_IN)
- {
- $checkBothClockInClockOut = false;
- $checkOnlyClockIn = true;
- }
- }
- if ($checkBothClockInClockOut)
- {
- if(($userAttendanceLogs[$yindex]->punchin_time != '') && ($userAttendanceLogs[$yindex]->punchout_time != ''))
- {
- $status = UserAttendanceLog::ATTENDANCE_STATUS_PRESENT;
- }
- else
- {
- $status = UserAttendanceLog::ATTENDANCE_STATUS_ABSENT;
- }
- }
- else if ($checkOnlyClockIn)
- {
- if(($userAttendanceLogs[$yindex]->punchin_time != ''))
- {
- $status = UserAttendanceLog::ATTENDANCE_STATUS_PRESENT;
- }
- else
- {
- $status = UserAttendanceLog::ATTENDANCE_STATUS_ABSENT;
- }
- }
- else
- {
- $status = UserAttendanceLog::ATTENDANCE_STATUS_ABSENT;
- }
- }
- elseif ($status == UserAttendance::ATTENDANCE_STATUS_PRESENT)
- {
- $status = UserAttendanceLog::ATTENDANCE_STATUS_PRESENT;
- }
- // ***************************** <END> *****************************
- /*
- // OLD CODE Commented
- if ($status == UserAttendance::ATTENDANCE_STATUS_ABSENT) {
- $status = UserAttendanceLog::ATTENDANCE_STATUS_ABSENT;
- } elseif ($status == UserAttendance::ATTENDANCE_STATUS_PRESENT) {
- $status = UserAttendanceLog::ATTENDANCE_STATUS_PRESENT;
- }
- */
- $weeklyoff = $userAttendanceLogs[$yindex]->is_weekly_off->status;
- $holiday = $userAttendanceLogs[$yindex]->is_holiday->status;
- $leave = $userAttendanceLogs[$yindex]->in_leave->status;
- $leave_revoked = false;
- if (isset($userAttendanceLogs[$yindex]->in_leave->leave_id)) {
- $unpaidLeave = UserLeaves::model()->findByPk($userAttendanceLogs[$yindex]->in_leave->leave_id);
- if ($unpaidLeave->isUnpaid == UserLeaves::LEAVE_UNPAID) {
- $unpaidleave_count++;
- $unpaidFlag = true;
- } else {
- $unpaidFlag = false;
- }
- if ($unpaidLeave->status == UserLeaves::STATUS_REVOKED || $unpaidLeave->status == UserLeaves::STATUS_REJECTED)
- {
- $leave_revoked = true;
- }
- } else {
- $unpaidFlag = false;
- }
- if (isset($weeklyoff) && $weeklyoff == "1") {
- $status = "W";
- $weeklyoff_count++;
- } elseif (isset($holiday) && $holiday == "1") {
- $status = "H";
- $holiday_count++;
- } elseif ((isset($leave)) && ($leave == "1") && ($leave_revoked == false)) {
- $status = "<font color = #0033FF><b>L</b></font>";
- $leave_count++;
- } elseif ($status == UserAttendanceLog::ATTENDANCE_STATUS_PRESENT || $status == UserAttendanceLog::ATTENDANCE_STATUS_PENDING) {
- $status = "<font color = #009900><b>P</b></font>";
- $present++;
- } /* elseif ($status == UserAttendanceLog::ATTENDANCE_STATUS_PENDING) {
- $status = "n";
- } */ elseif ($status == UserAttendanceLog::ATTENDANCE_STATUS_ABSENT || $status == UserAttendance::ATTENDANCE_STATUS_ABSENT) {
- $status = "<font color = #FF0000><b>A</b></font>";
- $absent++;
- } else {
- $status = "";
- }
- } else {
- $status = "";
- }
- $jindex++;
- } else {
- $status = "-";
- }
- } else {
- $status = "-";
- }
- if ($unpaidFlag) {
- $status = "U";
- }
- array_push($output[$index], $status);
- } // my good loop
- array_push($output[$index], $present);
- array_push($output[$index], $absent);
- array_push($output[$index], $weeklyoff_count);
- array_push($output[$index], $leave_count);
- array_push($output[$index], $unpaidleave_count);
- $index++;
- } // EOF foreach all user
- $flag = true;
- $cols = array(
- // 'Name||Column displays the Name of the employees.'
- 'Employee ID',
- 'Name||Column displays the Name of the employees.'
- );
- foreach ($daterange as $date) {
- $finaldatacols = $date->format("d") . "<br>" . substr((String) $date->format("D"), 0, 2);
- array_push($cols, $finaldatacols);
- }
- array_push($cols, 'P||Column displays the total number days when an employee was Present in the specified duration.');
- array_push($cols, 'A||Column displays the total number of days when an employee was Absent in the specified duration.');
- array_push($cols, 'W||Column displays the total number of Weekly Offs assigned to an employee in the specified duration.');
- array_push($cols, 'L||Column displays the total number of days when an employee was on a Leave in the specified duration.');
- array_push($cols, 'U||Column displays the total number of days when an employee was on a Unpaid Leave in the specified duration.');
- $roster_type = "Attendance-Summary";
- $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
- $filenameexport = $roster_type . "_" . $date;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- // EOF function
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param array $post_data Parameter description (if any) ...
- * @param unknown $tenant_id Parameter description (if any) ...
- * @param unknown $from Parameter description (if any) ...
- * @param unknown $to Parameter description (if any) ...
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- public static function getAbsenteesSummaryRoster($post_data, $tenant_id = null, $from = null, $to = null) {
- $return = array();
- $index = 0;
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- $finaldata = array();
- $begin = new DateTime($from);
- $end = new DateTime($to);
- $end = $end->modify('+1 day');
- $interval = new DateInterval('P1D');
- $daterange = new DatePeriod($begin, $interval, $end);
- $from = strtotime($from);
- $to = strtotime($to);
- $criteria = new EMongoCriteria();
- $criteria->shift_date('>=', new MongoDate($from));
- $criteria->shift_date('<=', new MongoDate($to));
- foreach ($users as $key => $user) {
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $criteria->user_id = $user->id;
- $userAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
- $present = 0;
- $absent = 0;
- $weeklyoff_count = 0;
- $holiday_count = 0;
- $leave_count = 0;
- $counter_var = 0;
- $present_count = 0;
- $return = array();
- $output[] = array(
- $employee_number,
- $user_name,
- $job_title,
- $department,
- );
- foreach ($userAttendanceLogs as $key => $userAttendance) {
- if (!empty($userAttendance)) {
- $status = $userAttendance->attendance_status;
- if ($status == UserAttendance::ATTENDANCE_STATUS_ABSENT) {
- $status = UserAttendanceLog::ATTENDANCE_STATUS_ABSENT;
- } elseif ($status == UserAttendance::ATTENDANCE_STATUS_PRESENT) {
- $status = UserAttendanceLog::ATTENDANCE_STATUS_PRESENT;
- }
- if ($status == UserAttendanceLog::ATTENDANCE_STATUS_ABSENT) {
- $weeklyoff = $userAttendance->is_weekly_off->status;
- $leave = $userAttendance->in_leave->status;
- $holiday = $userAttendance->is_holiday->status;
- if (is_null($weeklyoff) || $weeklyoff == IsWeeklyOff::WEEKLYOFF_YES) {
- continue;
- } elseif (is_null($leave) || $leave == InLeave::INLEAVE_YES) {
- continue;
- } elseif (is_null($holiday) || $holiday == IsHoliday::HOLIDAY_YES) {
- continue;
- } else {
- $absent++;
- }
- } // EOF abset status if
- } // EOF !empty if
- } // EOF userattendance foreach
- array_push($output[$index++], $absent);
- } // EOF foreach all user
- $flag = true;
- $cols = array(
- 'Employee ID',
- 'Name||Column displays the Name of the employees.',
- 'Job Title||Column displays the Job Tittle of the particular employee.',
- 'Department||Column displays the Department to which the employee belongs.',
- 'Absent Count||Column displays the total number of days when an employee was Absent in the specified duration.',
- );
- $roster_type = "Absentees-Summary";
- $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
- $filenameexport = $roster_type . "_" . $date;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- // EOF function
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param array $post_data Parameter description (if any) ...
- * @param unknown $tenant_id Parameter description (if any) ...
- * @param unknown $from Parameter description (if any) ...
- * @param unknown $to Parameter description (if any) ...
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- public static function getAttendanceLocationSummaryRoster($post_data, $tenant_id = null, $from = null, $to = null) {
- $return = array();
- $index = 0;
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- $finaldata = array();
- $begin = new DateTime($from);
- $end = new DateTime($to);
- $end = $end->modify('+1 day');
- $interval = new DateInterval('P1D');
- $daterange = new DatePeriod($begin, $interval, $end);
- $from = strtotime($from);
- $to = strtotime($to);
- $criteria = new EMongoCriteria();
- $criteria->shift_date('>=', new MongoDate($from));
- $criteria->shift_date('<=', new MongoDate($to));
- foreach ($users as $key => $user) {
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $criteria->user_id = $user->id;
- $UserAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
- $office = 0;
- $home = 0;
- $out = 0;
- $return = array();
- $output[] = array(
- $employee_number,
- $user_name,
- $job_title,
- $department,
- );
- $jindex = 0;
- foreach ($daterange as $date) {
- if (isset($UserAttendanceLogs[$jindex])) {
- $date = date("d", $UserAttendanceLogs[$jindex]->shift_date->sec);
- if (isset($UserAttendanceLogs[$jindex]->shift_planner)) {
- $timestamp = $UserAttendanceLogs[$jindex]->shift_date->sec;
- $data = UserShiftPlanner::getUserShift($user->id, $timestamp, $tenant_id);
- $shift_obj = TenantShift::getTenantShift($data['shift_id'], $tenant_id);
- $request = Request::getAttendanceRequestnew($UserAttendanceLogs[$jindex]->user_id, $shift_obj->is_next_day, $UserAttendanceLogs[$jindex]->shift_date->sec);
- if (!empty($request)) {
- //$request_location_array = AttendanceRequestForm::loadLocation();
- //$request_location = $request_location_array[$request->attendance->request_from];
- if ($request->attendance->request_from == UserAttendance::WORK_FROM_OFFICE) {
- $office++;
- }
- if ($request->attendance->request_from == UserAttendance::WORK_FROM_HOME) {
- $home++;
- }
- if ($request->attendance->request_from == UserAttendance::WORK_OUT_DUTY) {
- $out++;
- }
- }
- } else {
- $office++;
- }
- }
- /* array_push($output[$index], $status); */
- $jindex++;
- } // my good loop
- array_push($output[$index], $office);
- array_push($output[$index], $out);
- array_push($output[$index], $home);
- $index++;
- } // EOF foreach all user
- $flag = true;
- $cols = array(
- 'Employee ID',
- 'Name||Column displays the Name of the employees.',
- 'Job Title||Column displays the Job Tittle of the particular employee.',
- 'Department||Column displays the Department to which the employee belongs.',
- 'Office Days||Column displays the total number of days where attendance location is Office in the specified duration.',
- 'Field Duty Days||Column displays the total number of days where attendance location is Out - Duty in the specified duration.',
- 'Home Days||Column displays the total number of days where attendance location is Home in the specified duration.',
- );
- $roster_type = "Attendance-Location-Summary";
- $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
- $filenameexport = $roster_type . "_" . $date;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- // EOF function
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param array $post_data Parameter description (if any) ...
- * @param unknown $tenant_id Parameter description (if any) ...
- * @param unknown $from Parameter description (if any) ...
- * @param unknown $to Parameter description (if any) ...
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- public static function getOverTimeSummaryRoster($post_data, $tenant_id = null, $from = null, $to = null) {
- $return = array();
- $index = 0;
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- $finaldata = array();
- $begin = new DateTime($from);
- $end = new DateTime($to);
- $end = $end->modify('+1 day');
- $interval = new DateInterval('P1D');
- $daterange = new DatePeriod($begin, $interval, $end);
- $from = strtotime($from);
- $to = strtotime($to);
- $criteria = new EMongoCriteria();
- $criteria->shift_date('>=', new MongoDate($from));
- $criteria->shift_date('<=', new MongoDate($to));
- foreach ($users as $key => $user) {
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $criteria->user_id = $user->id;
- $userAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
- $overtime = 0;
- $overtimesum = 0;
- $return = array();
- $output[] = array(
- $employee_number,
- $user_name,
- $job_title,
- $department,
- );
- $jindex = 0;
- foreach ($daterange as $date) {
- if (isset($userAttendanceLogs[$jindex])) {
- if (isset($userAttendanceLogs[$jindex]->over_time) && $userAttendanceLogs[$jindex]->over_time != '0') {
- $shift_date = $userAttendanceLogs[$jindex]->shift_date->sec;
- $user_id = $user->id;
- $logCalc = AttendanceHelper::logCalculator($user_id, $shift_date, $tenant_id);
- $overtimesum = $logCalc['rosterOverTimeSec'];
- // $overtimesum += strtotime($overtimedata);
- $overtime++;
- }
- }
- /* array_push($output[$index], $status); */
- $jindex++;
- } // my good loop
- if ($overtime != 0) {
- // $avgtime = $overtimesum / $overtime;
- $finalavg = RandomHelper::sec2hms($overtimesum);
- } else {
- $avgtime = '0';
- $finalavg = "0:00";
- }
- array_push($output[$index], $overtime);
- array_push($output[$index], $finalavg);
- $index++;
- } // EOF foreach all user
- $flag = true;
- $cols = array(
- 'Employee ID',
- 'Name||Column displays the Name of the employees.',
- 'Job Title||Column displays the Job Tittle of the particular employee.',
- 'Department||Column displays the Department to which the employee belongs.',
- '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.',
- 'Average Over Time||Column dsiplays the average amount of time by which an employee is working over time in the specified duration.'
- );
- $roster_type = "Overtime-Summary";
- $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
- $filenameexport = $roster_type . "_" . $date;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- // EOF function
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param array $post_data Parameter description (if any) ...
- * @param unknown $tenant_id Parameter description (if any) ...
- * @param unknown $from Parameter description (if any) ...
- * @param unknown $to Parameter description (if any) ...
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- public static function getWorkDurationSummaryRoster($post_data, $tenant_id = null, $from = null, $to = null) {
- $return = array();
- $output = array();
- $finaldata = array();
- $index = 0;
- $totalDays = 0;
- $filter = $post_data['filter_id'];
- $begin = new DateTime($from);
- $end = new DateTime($to);
- $end = $end->modify('+1 day');
- $interval = new DateInterval('P1D');
- $daterange = new DatePeriod($begin, $interval, $end);
- $from = strtotime($from);
- $to = strtotime($to);
- $criteria = new EMongoCriteria();
- $criteria->shift_date('>=', new MongoDate($from));
- $criteria->shift_date('<=', new MongoDate($to));
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- foreach ($users as $key => $user) {
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $criteria->user_id = $user->id;
- $userAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
- // echo "<pre>"; print_r($userAttendanceLogs); exit("</pre> \n exited here ");
- $total = 0;
- $totaltime = 0;
- $isholiday = 0;
- $isweeklyoff = 0;
- $jindex = 0;
- $return = array();
- $totalWorkDuration = 0;
- $totalDays = 0;
- $totalWorkedDays = 0;
- $workingDaysCount = 0;
- $totalWorkDurationSc = 0;
- $totalWorkDurationTimeStamp = 0;
- $output[] = array(
- $employee_number,
- $user_name,
- $job_title,
- $department,
- );
- foreach ($daterange as $date) {
- if (isset($userAttendanceLogs[$jindex])) {
- $status = $userAttendanceLogs[$jindex]->attendance_status;
- if ($status == UserAttendance::ATTENDANCE_STATUS_ABSENT) {
- $status = UserAttendanceLog::ATTENDANCE_STATUS_ABSENT;
- } elseif ($status == UserAttendance::ATTENDANCE_STATUS_PRESENT) {
- $status = UserAttendanceLog::ATTENDANCE_STATUS_PRESENT;
- }
- if ($status == UserAttendanceLog::ATTENDANCE_STATUS_PRESENT || $status == UserAttendanceLog::ATTENDANCE_STATUS_PENDING) {
- if (isset($userAttendanceLogs[$jindex]->total_duration) && $userAttendanceLogs[$jindex]->total_duration != 0) {
- $totalWorkDurationTimeStamp += $userAttendanceLogs[$jindex]->total_duration;
- $workingDaysCount++;
- $totalWorkedDays++;
- }
- }
- }
- $jindex++;
- $totalDays++;
- } // my good loop
- if (isset($totalWorkDurationTimeStamp) && $workingDaysCount != 0) {
- $totalWorkedHr = RandomHelper::sec2hms($totalWorkDurationTimeStamp);
- $week = $totalDays / 7;
- $weeklyAverageNo = $totalWorkDurationTimeStamp / $week;
- $weeklyAverage = RandomHelper::sec2hms($weeklyAverageNo);
- // echo "<pre>"; print_r($weeklyAverage); exit("</pre> \n exited here ");
- $daillyAverage = $totalWorkDurationTimeStamp / $workingDaysCount;
- $daillyAverage = RandomHelper::sec2hms($daillyAverage);
- } else {
- $totalWorkedHr = 0;
- $weeklyAverage = 0;
- $daillyAverage = 0;
- }
- array_push($output[$index], $totalWorkedHr);
- array_push($output[$index], $weeklyAverage);
- array_push($output[$index], $daillyAverage);
- $index++;
- // break;
- } // EOF foreach all user
- $cols = array(
- 'Employee ID',
- 'Name||Column displays the Name of the employees.',
- 'Job Title||Column displays the Job Tittle of the particular employee.',
- 'Department||Column displays the Department to which the employee belongs.',
- 'Total worked hours||Column displays the total worked hours for the specified duration.',
- 'Weekly Average||Column displays the weekly average work hours duration of the employee in the specified duration.',
- 'Daily Average||Column displays the daily average work hours duration of the employee in the specified duration.'
- );
- $roster_type = "Work-Duration-Summary";
- $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
- $filenameexport = $roster_type . "_" . $date;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- // EOF function
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param array $post_data Parameter description (if any) ...
- * @param unknown $tenant_id Parameter description (if any) ...
- * @param unknown $from Parameter description (if any) ...
- * @param unknown $to Parameter description (if any) ...
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- public static function getLatemarkDateWiseRoster($post_data, $tenant_id = null, $from = null, $to = null) {
- $return = array();
- $index = 0;
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- $finaldata = array();
- $begin = new DateTime($from);
- $end = new DateTime($to);
- $end = $end->modify('+1 day');
- $interval = new DateInterval('P1D');
- $daterange = new DatePeriod($begin, $interval, $end);
- $from = strtotime($from);
- $to = strtotime($to);
- $criteria = new EMongoCriteria();
- foreach ($daterange as $date) {
- $todaydate = strtotime($date->format("d-m-Y"));
- $criteria->shift_date('==', new MongoDate($todaydate));
- $criteria->coming_late_by('!=', null);
- $UserAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
- foreach ($UserAttendanceLogs as $logs) {
- $userid = $logs->user_id;
- $usermodel = UserMongo::model()->tenant($tenant_id)->findByPk($userid);
- if (array_key_exists($usermodel->user_id, $users)) {
- $user_name = $usermodel->getFullname();
- $employee_number = (isset($usermodel['personal']['employee_no'])) ? $usermodel['personal']['employee_no'] : "N.A.";
- $user_post = $usermodel->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $present = 0;
- $absent = 0;
- $weeklyoff_count = 0;
- $holiday_count = 0;
- $leave_count = 0;
- $return = array();
- $jindex = 0;
- if (isset($logs) && $logs != null) {
- if (isset($logs->coming_late_by) && $logs->coming_late_by != null) {
- if (isset($logs->punchin_timestamp->sec) && $logs->punchin_timestamp->sec != null) {
- $punchin_timestamp = (isset($logs->punchin_timestamp->sec) && $logs->punchin_timestamp->sec != null) ? date("H:i", $logs->punchin_timestamp->sec) : "-";
- } else {
- $punchin_timestamp = (isset($logs->punchin_timestamp) && $logs->punchin_timestamp != null) ? date("H:i", $logs->punchin_timestamp) : "-";
- }
- if (isset($logs->punchout_timestamp->sec) && $logs->punchout_timestamp->sec != null) {
- $punchout_timestamp = (isset($logs->punchout_timestamp->sec) && $logs->punchout_timestamp->sec != null) ? date("H:i", $logs->punchout_timestamp->sec) : "-";
- } else {
- if (!is_object($logs->punchout_timestamp)) {
- $punchout_timestamp = (isset($logs->punchout_timestamp) && $logs->punchout_timestamp != null) ? date("H:i", $logs->punchout_timestamp) : "-";
- }
- }
- $coming_late_bydata = (isset($logs->coming_late_by) && $logs->coming_late_by != null) ? $logs->coming_late_by : "-";
- $coming_late_by = str_replace('.', ':', $coming_late_bydata);
- $new_come_late = explode(":", $coming_late_by);
- if(isset($new_come_late[0],$new_come_late[1]) && ($new_come_late[0] < 10 || $new_come_late[1] < 10))
- {
- $new_come_late_hrs = ($new_come_late[0] < 10) ? "0".$new_come_late[0] : $new_come_late[0];
- $new_come_late_mins = ($new_come_late[1] < 10) ? "0".$new_come_late[1] : $new_come_late[1];
- $coming_late_by = $new_come_late_hrs . ":".$new_come_late_mins;
- }
- // $date = date("d", $logs->shift_date->sec);
- } else {
- $punchin_timestamp = "-";
- $punchout_timestamp = "-";
- $coming_late_by = "-";
- }
- $attdate = date("d-M-Y", $logs->shift_date->sec);
- $attdateday = date("l", $logs->shift_date->sec);
- /* $attdate = $attdateonly.','. $attdateday; */
- $output[] = array($attdate);
- // array_push($output[$index], $attdate);
- array_push($output[$index], $attdateday);
- array_push($output[$index], $employee_number);
- array_push($output[$index], $user_name);
- array_push($output[$index], $job_title);
- array_push($output[$index], $department);
- array_push($output[$index], $punchin_timestamp);
- array_push($output[$index], $punchout_timestamp);
- array_push($output[$index], $coming_late_by);
- }
- $index++;
- }//check users if
- } // EOF foreach for all logs
- } // EOF foreach all date
- $flag = true;
- $cols = array(
- 'Date||Column displays all the Dates selected in the specified duration.',
- 'Day||Column displays the Particular Day corresponding to the date.',
- 'Employee ID',
- 'Name||Column displays the Name of the employees.',
- 'Job Title||Column displays the Job Tittle of the particular employee.',
- 'Department||Column displays the Department to which the employee belongs.',
- 'Punch In Time||Column displays the Time when the employee is suppose to start his Shift.',
- 'Punch Out Time||Column displays the Time at which the particular employee started his Shift.',
- 'Coming Late By||Column displays the Time by which the employee was late by on the particular date.'
- );
- $roster_type = "LateMark-Datewise";
- $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
- $filenameexport = $roster_type . "_" . $date;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- // EOF function
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param array $post_data Parameter description (if any) ...
- * @param unknown $tenant_id Parameter description (if any) ...
- * @param unknown $from Parameter description (if any) ...
- * @param unknown $to Parameter description (if any) ...
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- public static function getAbsenteesDatewiseRoster($post_data, $tenant_id = null, $from = null, $to = null) {
- $return = array();
- $index = 0;
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- $finaldata = array();
- $begin = new DateTime($from);
- $end = new DateTime($to);
- $end = $end->modify('+1 day');
- $interval = new DateInterval('P1D');
- $daterange = new DatePeriod($begin, $interval, $end);
- $from = strtotime($from);
- $to = strtotime($to);
- $criteria = new EMongoCriteria();
- foreach ($daterange as $date) {
- $todaydate = strtotime($date->format("d-m-Y"));
- $criteria->shift_date('==', new MongoDate($todaydate));
- $userAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
- foreach ($userAttendanceLogs as $logs) {
- $status = $logs->attendance_status;
- if ($status == UserAttendanceLog::ATTENDANCE_STATUS_ABSENT && $status == UserAttendance::ATTENDANCE_STATUS_ABSENT) { // echo "<pre>"; print_r($status);
- $weeklyoff = $logs->is_weekly_off->status;
- $leave = $logs->in_leave->status;
- $holiday = $logs->is_holiday->status;
- if (is_null($weeklyoff) || $weeklyoff == IsWeeklyOff::WEEKLYOFF_YES) {
- continue;
- } elseif (is_null($leave) || $leave == InLeave::INLEAVE_YES) {
- continue;
- } elseif (is_null($holiday) || $holiday == IsHoliday::HOLIDAY_YES) {
- continue;
- } else {
- $userid = $logs->user_id;
- $usermodel = UserMongo::model()->tenant($tenant_id)->findByPk($userid);
- if (array_key_exists($usermodel->user_id, $users)) {
- $employee_id = $usermodel->personal->employee_no;
- $user_name = $usermodel->getFullname();
- $user_post = $usermodel->getCurrentPosition($tenant_id);
- $job_title = (isset($user_post['designation']) && $user_post['designation'] != null) ? $user_post['designation'] : "-";
- $department = (isset($user_post['department']) && $user_post['department'] != null) ? $user_post['department'] : "-";
- $business_unit = (isset($user_post['business_unit']) && $user_post['business_unit'] != null) ? $user_post['business_unit'] : "-";
- $present = 0;
- $absent = 0;
- $weeklyoff_count = 0;
- $holiday_count = 0;
- $leave_count = 0;
- $return = array();
- $jindex = 0;
- $attdate = date("d-M-Y", $logs->shift_date->sec);
- $attdateday = date("l", $logs->shift_date->sec);
- /* $attdate = $attdateonly.','. $attdateday; */
- $output[] = array($attdate);
- array_push($output[$index], $attdateday);
- array_push($output[$index], $employee_id);
- array_push($output[$index], $user_name);
- array_push($output[$index], $job_title);
- array_push($output[$index], $department);
- $index++;
- }
- }
- } // EOF user if
- } // EOF foreach logs
- } // EOF foreach all date
- $flag = true;
- $cols = array(
- 'Date||Column displays all the Dates selected in the specified duration.',
- 'Day||Column displays the Particular Day corresponding to the date.',
- 'Employee ID||Employee id',
- 'Name||Column displays the Name of the employees.',
- 'Job Title||Column displays the Job Tittle of the particular employee.',
- 'Department||Column displays the Department to which the employee belongs.'
- );
- $roster_type = "Absentees-Datewise-Summary";
- $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
- $filenameexport = $roster_type . "_" . $date;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- // EOF function
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param array $post_data Parameter description (if any) ...
- * @param unknown $tenant_id Parameter description (if any) ...
- * @param unknown $from Parameter description (if any) ...
- * @param unknown $to Parameter description (if any) ...
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- public static function getLateMarksSummaryRoster($post_data, $tenant_id = null, $from = null, $to = null) {
- $return = array();
- $index = 0;
- $output = array();
- $finaldata = array();
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $begin = new DateTime($from);
- $end = new DateTime($to);
- $end = $end->modify('+1 day');
- $interval = new DateInterval('P1D');
- $daterange = new DatePeriod($begin, $interval, $end);
- $from = strtotime($from);
- $to = strtotime($to);
- $criteria = new EMongoCriteria();
- $criteria->shift_date('>=', new MongoDate($from));
- $criteria->shift_date('<=', new MongoDate($to));
- foreach ($users as $key => $user) {
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $criteria->user_id = $user->id;
- $userAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
- $present = 0;
- $absent = 0;
- $comingLateCounter = 0;
- $weeklyoff_count = 0;
- $holiday_count = 0;
- $leave_count = 0;
- $cominglatetotal = 0;
- $punchintimetotal = 0;
- $punchInCounter = 0;
- $jindex = 0;
- $timeInTotalSec = 0;
- $punchInTimeStamp = 0;
- $avgLateBy = 0;
- $comingLateBy = 0;
- $return = array();
- $output[] = array(
- $employee_number,
- $user_name,
- $job_title,
- $department,
- );
- foreach ($daterange as $date) {
- if (isset($userAttendanceLogs[$jindex])) {
- if (isset($userAttendanceLogs[$jindex]->punchin_timestamp->sec) && $userAttendanceLogs[$jindex]->punchin_timestamp->sec != null) {
- $shift_date = $userAttendanceLogs[$jindex]->shift_date->sec;
- $user_id = $user->id;
- $logCalc = AttendanceHelper::logCalculator($user_id, $shift_date, $tenant_id);
- // $comingLateBy += $logCalc["rosterLateBySec"];
- // echo "<pre>"; print_r($logCalc); exit("</pre> \n exited here \n");
- $punchInTimeStamp += $logCalc["rosterClockInSec"];
- // echo "<pre>"; print_r($punchInTimeStamp); exit("</pre> \n exited here ");
- $punchInCounter++;
- }
- if (isset($userAttendanceLogs[$jindex]->coming_late_by) && $userAttendanceLogs[$jindex]->coming_late_by != null) {
- /* $shift_date = $userAttendanceLogs[$jindex]->shift_date->sec;
- $user_id = $user->id;
- $logCalc = AttendanceHelper::logCalculator($user_id,$shift_date,$tenant_id); */
- if (isset($logCalc["rosterLateBySec"])) {
- $comingLateBy += $logCalc["rosterLateBySec"];
- $comingLateCounter++;
- }
- // echo "<pre>"; print_r($logCalc); exit("</pre> \n exited here \n");
- }
- }
- $jindex++;
- } // my good loop
- if (isset($comingLateBy) && $comingLateCounter != 0) {
- $avgLateBy = $comingLateBy / $comingLateCounter;
- $avgLateBy = RandomHelper::sec2hms($avgLateBy);
- } else {
- $avgLateBy = "00:00";
- }
- if (isset($punchInTimeStamp) && $punchInCounter != 0) {
- $avgPunchInTimeSec = $punchInTimeStamp / $punchInCounter;
- $avgPunchInTime = RandomHelper::sec2hms($avgPunchInTimeSec);
- } else {
- $avgpunchintime = 0;
- $avgPunchInTime = '00:00';
- }
- array_push($output[$index], $comingLateCounter);
- array_push($output[$index], $avgLateBy);
- array_push($output[$index], $avgPunchInTime);
- $index++;
- // break;
- } // EOF foreach all user
- $flag = true;
- $cols = array(
- 'Employee ID ||Column to display employee id',
- 'Name||Column displays the Name of the employees.',
- 'Job Title||Column displays the Job Tittle of the particular employee.',
- 'Department||Column displays the Department to which the employee belongs.',
- '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.',
- 'Average Late By||Column displays what is the average duration by which an employee is late by in the specified duration.',
- 'Average Clock In Time||Column displays the average clock-in time of the employee for the specified duration.'
- );
- $roster_type = "Latemark-Summary";
- $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
- $filenameexport = $roster_type . "_" . $date;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- //EOF function
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param array $post_data Parameter description (if any) ...
- * @param unknown $tenant_id Parameter description (if any) ...
- * @param unknown $from Parameter description (if any) ...
- * @param unknown $to Parameter description (if any) ...
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- public static function getEarlyClockOutSummaryRoster($post_data, $tenant_id = null, $from = null, $to = null) {
- $return = array();
- $index = 0;
- $output = array();
- $finaldata = array();
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $begin = new DateTime($from);
- $end = new DateTime($to);
- $end = $end->modify('+1 day');
- $interval = new DateInterval('P1D');
- $daterange = new DatePeriod($begin, $interval, $end);
- $from = strtotime($from);
- $to = strtotime($to);
- $criteria = new EMongoCriteria();
- $criteria->shift_date('>=', new MongoDate($from));
- $criteria->shift_date('<=', new MongoDate($to));
- foreach ($users as $key => $user) {
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $criteria->user_id = $user->id;
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $userAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
- $present = 0;
- $absent = 0;
- $goingearly = 0;
- $weeklyoff_count = 0;
- $holiday_count = 0;
- $leave_count = 0;
- $goingearlytotal = 0;
- $totalpunchout = 0;
- $punchouttimetotal = 0;
- $return = array();
- $output[] = array(
- $employee_number,
- $user_name,
- $job_title,
- $department,
- );
- foreach ($userAttendanceLogs as $userAttendanceLog) {
- if (isset($userAttendanceLog)) {
- if (isset($userAttendanceLog->shift_date->sec)) {
- $shift_date = $userAttendanceLog->shift_date->sec;
- $user_id = $user->id;
- $logCalc = AttendanceHelper::logCalculator($user_id, $shift_date, $tenant_id);
- // echo "<pre>"; print_r($logCalc); exit("</pre> \n exited here ");
- if (isset($userAttendanceLog->punchout_time) && $userAttendanceLog->punchout_time != null) {
- $punchouttimetotal += $logCalc["rosterClockOutSec"];
- $totalpunchout++;
- }
- if (!empty($logCalc["total_duration"])) {
- if ($logCalc["total_duration"] < $logCalc["rosterShiftSeconds"]) {
- $goingearlytotal += $logCalc["rosterShiftSeconds"] - $logCalc["total_duration"];
- $goingearly++;
- }
- }
- }
- }
- } // my good loop
- if (isset($goingearlytotal) && $goingearlytotal != 0) {
- $avgtime = $goingearlytotal / $goingearly;
- $finalavg = RandomHelper::sec2hms($avgtime);
- //echo "<pre>"; print_r($avgtime); exit("</pre> \n exited here");
- } else {
- $avgtime = 0;
- $finalavg = '00:00';
- }
- if (isset($punchouttimetotal) && $punchouttimetotal != 0) {
- // $totalpunchoutdur = date('H.i', $punchouttimetotal);
- $avgpunchouttime = $punchouttimetotal / $totalpunchout;
- $finalavgpunchout = RandomHelper::sec2hms($avgpunchouttime);
- // echo "<pre>"; print_r($finalavgpunchin); exit("</pre> \n exited here");
- } else {
- $finalavgpunchout = '00:00';
- }
- array_push($output[$index], $goingearly);
- array_push($output[$index], $finalavg);
- array_push($output[$index], $finalavgpunchout);
- $index++;
- // break;
- } // EOF foreach all user
- $flag = true;
- $cols = array(
- 'Employee ID||Column to display Employee id',
- 'Name||Column displays the Name of the employees.',
- 'Job Title||Column displays the Job Tittle of the particular employee.',
- 'Department||Column displays the Department to which the employee belongs.',
- 'No Of Early Clock Out Days||Column displays the Number of days the employee has clocked out early.',
- 'Average Of Early Clock Out||Column displays the average by which an employee clocks out early in the specified duration.',
- 'Average Of Clock Out Time||Column displays a simple average of the clock-out times recorded for the specified duration.'
- );
- $roster_type = "Early-Clockout-Summary";
- $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
- $filenameexport = $roster_type . "_" . $date;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- //EOF function
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param array $post_data Parameter description (if any) ...
- * @param unknown $tenant_id Parameter description (if any) ...
- * @param unknown $from Parameter description (if any) ...
- * @param unknown $to Parameter description (if any) ...
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- public static function getEarlyClockOutDatewiseRoster($post_data, $tenant_id = null, $from = null, $to = null) {
- $return = array();
- $output = array();
- $finaldata = array();
- $index = 0;
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- //echo "<pre>"; print_r($users); exit("</pre> \n exited here");
- $begin = new DateTime($from);
- $end = new DateTime($to);
- $end = $end->modify('+1 day');
- $interval = new DateInterval('P1D');
- $daterange = new DatePeriod($begin, $interval, $end);
- $from = strtotime($from);
- $to = strtotime($to);
- $criteria = new EMongoCriteria();
- foreach ($daterange as $date) {
- $todaydate = strtotime($date->format("d-m-Y"));
- $criteria->shift_date('==', new MongoDate($todaydate));
- // $criteria->going_early_by('!=', null);
- $UserAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
- foreach ($UserAttendanceLogs as $logs) {
- $userid = $logs->user_id;
- $usermodel = UserMongo::model()->tenant($tenant_id)->findByPk($userid);
- if (array_key_exists($usermodel->user_id, $users)) {
- $user_name = $usermodel->getFullname();
- $user_post = $usermodel->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $present = 0;
- $absent = 0;
- $weeklyoff_count = 0;
- $holiday_count = 0;
- $leave_count = 0;
- $jindex = 0;
- $return = array();
- $shift_date = $logs->shift_date->sec;
- $user_id = $usermodel->id;
- $logCalc = AttendanceHelper::logCalculator($user_id, $shift_date, $tenant_id);
- if (!empty($logCalc["total_duration"])) {
- if ($logCalc["total_duration"] < $logCalc["rosterShiftSeconds"]) {
- if (isset($logs->shift_planner)) {
- $begin_time = date("H:i", $logCalc["rosterShiftBegin"]);
- $end_time = date("H:i", $logCalc["rosterShiftEnd"]);
- $going_early_by = $logCalc["rosterShiftSeconds"] - $logCalc["total_duration"];
- $going_early_by = RandomHelper::sec2hms($going_early_by);
- } else {
- $begin_time = "-";
- $end_time = "-";
- }
- // $going_early_bydata = (isset($logs->going_early_by) && $logs->going_early_by != null) ? $logs->going_early_by : "-";
- // $going_early_by = str_replace('.', ':', $going_early_bydata);
- $attdate = date("d-M-Y", $logs->shift_date->sec);
- $attdateday = date("l", $logs->shift_date->sec);
- $output[] = array($attdate);
- array_push($output[$index], $employee_number);
- array_push($output[$index], $attdateday);
- array_push($output[$index], $user_name);
- array_push($output[$index], $job_title);
- array_push($output[$index], $department);
- array_push($output[$index], $begin_time);
- array_push($output[$index], $end_time);
- array_push($output[$index], $going_early_by);
- $index++;
- }
- }
- } // EOF foreach for all logs
- }
- } // EOF foreach all date
- $flag = true;
- $cols = array(
- 'Employee ID ||Column to display Employee id ',
- 'Date||Column displays all the Dates selected in the specified duration.',
- 'Day||Column displays the Particular Day corresponding to the date.',
- 'Name||Column displays the Name of the employees.',
- 'Job Title||Column displays the Job Tittle of the particular employee.',
- 'Department||Column displays the Department to which the employee belongs.',
- 'Shift Begin Time||Column displays the Time when the employee shift starts.',
- 'Shift End Time||Column displays the Time when the employee shift ',
- 'Going Early By||Column displays the Time by which the employee is leaving early than the stipulated time.'
- );
- $roster_type = "Early-Clockout-Datewise-Summary";
- $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
- $filenameexport = $roster_type . "_" . $date;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- // EOF function
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param array $post_data Parameter description (if any) ...
- * @param unknown $tenant_id Parameter description (if any) ...
- * @param unknown $from Parameter description (if any) ...
- * @param unknown $to Parameter description (if any) ...
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- public static function getOverTimeDatewiseRoster($post_data, $tenant_id = null, $from = null, $to = null) {
- $return = array();
- $index = 0;
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- $finaldata = array();
- $begin = new DateTime($from);
- $end = new DateTime($to);
- $end = $end->modify('+1 day');
- $interval = new DateInterval('P1D');
- $daterange = new DatePeriod($begin, $interval, $end);
- $from = strtotime($from);
- $to = strtotime($to);
- $criteria = new EMongoCriteria();
- foreach ($daterange as $date) {
- $todaydate = strtotime($date->format("d-m-Y"));
- $criteria->shift_date('==', new MongoDate($todaydate));
- $criteria->over_time('!=', 0);
- $UserAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
- foreach ($UserAttendanceLogs as $logs) {
- $userid = $logs->user_id;
- $usermodel = UserMongo::model()->tenant($tenant_id)->findByPk($userid);
- if (array_key_exists($usermodel->user_id, $users)) {
- $user_name = $usermodel->getFullname();
- $user_post = $usermodel->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $present = 0;
- $absent = 0;
- $weeklyoff_count = 0;
- $holiday_count = 0;
- $leave_count = 0;
- $return = array();
- $jindex = 0;
- if (isset($logs)) {
- if (isset($logs->shift_planner)) {
- $timestamp = $logs->shift_date->sec;
- $logs->shift_date->sec;
- $data = UserShiftPlanner::getUserShift($usermodel->id, $timestamp, $tenant_id);
- $shift_obj = TenantShift::getTenantShift($data['shift_id'], $tenant_id);
- $begin_time = (isset($shift_obj->begin_time) && $shift_obj->begin_time != null) ? $shift_obj->begin_time : null;
- $new_come_begin_time = explode(":", $begin_time);
- if(isset($new_come_begin_time[0],$new_come_begin_time[1]) && ($new_come_begin_time[0] < 10 || $new_come_begin_time[1] < 10))
- {
- $new_come_begin_time_hrs = ($new_come_begin_time[0] < 10) ? "0".$new_come_begin_time[0] : $new_come_begin_time[0];
- $new_come_begin_time_mins = ($new_come_begin_time[1] < 10) ? "0".$new_come_begin_time[1] : $new_come_begin_time[1];
- $begin_time = $new_come_begin_time_hrs . ":".$new_come_begin_time_mins;
- }
- $end_time = (isset($shift_obj->end_time) && $shift_obj->end_time != null) ? $shift_obj->end_time : null;
- $new_come_end_time = explode(":", $end_time);
- if(isset($new_come_end_time[0],$new_come_end_time[1]) && ($new_come_end_time[0] < 10 || $new_come_end_time[1] < 10))
- {
- $new_come_end_time_hrs = ($new_come_end_time[0] < 10) ? "0".$new_come_end_time[0] : $new_come_end_time[0];
- $new_come_end_time_mins = ($new_come_end_time[1] < 10) ? "0".$new_come_end_time[1] : $new_come_end_time[1];
- $end_time = $new_come_end_time_hrs . ":".$new_come_end_time_mins;
- }
- } else {
- $begin_time = "-";
- $end_time = "-";
- }
- $over_time = (isset($logs->over_time) && $logs->over_time != null) ? $logs->over_time : "-";
- $attdate = date("d-M-Y", $logs->shift_date->sec);
- $attdateday = date("l", $logs->shift_date->sec);
- /* $attdate = $attdateonly.','. $attdateday; */
- $output[] = array($attdate);
- // array_push($output[$index], $attdate);
- array_push($output[$index], $employee_number);
- array_push($output[$index], $attdateday);
- array_push($output[$index], $user_name);
- array_push($output[$index], $job_title);
- array_push($output[$index], $department);
- array_push($output[$index], $begin_time);
- array_push($output[$index], $end_time);
- array_push($output[$index], $over_time);
- }
- $index++;
- } //EOF user IF
- } // EOF foreach for all logs
- } // EOF foreach all date
- $flag = true;
- $cols = array(
- 'Employee ID ||Column to display employee ',
- 'Date||Column displays all the Dates selected in the specified duration.',
- 'Day||Column displays the Particular Day corresponding to the date.',
- 'Name||Column displays the Name of the employees.',
- 'Job Title||Column displays the Job Tittle of the particular employee.',
- 'Department||Column displays the Department to which the employee belongs.',
- 'Shift Begin Time||Column displays the Time when the employee shift starts.',
- 'Shift End Time||Column displays the Time when the employee shift ',
- 'Over Time Duration||Column displays the Time by which the employee is doing overtime on that particular day.'
- );
- $roster_type = "Overtime-Datewise-Summary";
- $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
- $filenameexport = $roster_type . "_" . $date;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- // EOF function
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param array $post_data Parameter description (if any) ...
- * @param unknown $tenant_id Parameter description (if any) ...
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- public static function getAttendanceRoster($post_data, $tenant_id = null) {
- $return = array();
- //$sr_no=1;
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- // echo "<pre>"; print_r($users); exit("</pre> \n exited here ");
- $output = array();
- foreach ($users as $key => $user) {
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $date = strtotime(date('Y-m-d'));
- $employee_number = $user['personal']['employee_no'];
- $userShift = UserShift::getUserShift($user->id, $user->tenant_id);
- if (!empty($userShift)) {
- if ($userShift['type'] == UserShift::ROTATING_SHIFT) {
- $userShift = UserShiftPlanner::getUserShift($user->id, $date, $user->tenant_id);
- $weekly_obj = WeeklyOff::getWeeklyOff($userShift['weekly_off_id'], $user->tenant_id);
- } else {
- $get_weekly_obj = UserWeeklyOff::getUserWeeklyOffByUserId($user->id, $user->tenant_id);
- if (isset($get_weekly_obj->weekly_off_id)) {
- $weekly_obj = WeeklyOff::getWeeklyOff($get_weekly_obj->weekly_off_id, $user->tenant_id);
- } else {
- $weekly_obj = "";
- }
- }
- // echo "<pre>"; print_r($weekly_obj); echo("</pre>"); exit();
- $weekly_name = (isset($weekly_obj->weekly_off_name)) ? $weekly_obj->weekly_off_name : "";
- $shift_obj = TenantShift::getTenantShift($userShift['shift_id'], $user->tenant_id);
- $shift_name = (isset($shift_obj->shift_name)) ? $shift_obj->shift_name : "";
- $policy_obj = AttendancePolicy::getAttendancePolicy($userShift['policy_id'], $user->tenant_id);
- $policy_name = (isset($policy_obj->policy_name)) ? $policy_obj->policy_name : "";
- if (isset($userShift['clocking_priority']['clocking_priority'])) {
- switch ($userShift['clocking_priority']['clocking_priority']) {
- case 0:
- $clocking_priority = "Web";
- break;
- case 1:
- $clocking_priority = "Hardware";
- break;
- default:
- $clocking_priority = "Web";
- break;
- }
- }
- /**/
- if(isset($userShift->controls['clocking_warning']) && $userShift->controls['clocking_warning'] == 1)
- {
- $clocking_warning_check = "ON";
- }
- else{
- $clocking_warning_check = "OFF";
- }
- if(isset($userShift->controls['absent_warning']) && $userShift->controls['absent_warning'] == 1)
- {
- $absent_warning_check = "ON";
- }
- else{
- $absent_warning_check = "OFF";
- }
- if ($userShift->clocking_priority->clocking_priority == 0 && !empty($userShift->ip_restriction)) {
- $all_names = "";
- if (!is_array($userShift->ip_restriction)) {
- $userShift->ip_restriction = array($userShift->ip_restriction);
- }
- foreach ($userShift->ip_restriction as $key => $restriction) {
- $ip_name = AttendanceIp::getNameById($restriction);
- $ip_only_name = $ip_name['name'];
- $new_array[$restriction]['name'] = $ip_name['name'];
- $new_array[$restriction]['ip_from'] = $ip_name['ip_from'];
- $new_array[$restriction]['ip_to'] = (isset($ip_name['ip_to']) && $ip_name['ip_to'] != "") ? $ip_name['ip_to'] : "N.A.";
- $all_names = $all_names . $ip_only_name . ", ";
- }
- $all_names = substr_replace($all_names, "", -2);
- }
- else{
- $all_names = "N.A.";
- }
- /**/
- } // EOF empty if check
- else {
- $get_weekly_obj = UserWeeklyOff::getUserWeeklyOffByUserId($user->id, $user->tenant_id);
- if (isset($get_weekly_obj->weekly_off_id)) {
- $weekly_obj = WeeklyOff::getWeeklyOff($get_weekly_obj->weekly_off_id, $user->tenant_id);
- $weekly_name = (isset($weekly_obj->weekly_off_name)) ? $weekly_obj->weekly_off_name : "";
- } else {
- $weekly_obj = "";
- $weekly_name = "";
- }
- $shift_name = "";
- $policy_name = "";
- // $weekly_name = "";
- $clocking_priority = "";
- $clocking_warning_check = "";
- $absent_warning_check = "";
- $all_names = "N.A.";
- // $action_checkbox = "<input type=\"checkbox\" name=\"roster_action\" value=\"\">";
- }
- $output[] = array(
- // $action_checkbox,
- $employee_number,
- $user_name,
- $job_title,
- $department,
- $business_unit,
- $clocking_priority,
- $shift_name,
- $policy_name,
- $weekly_name,
- $all_names,
- $clocking_warning_check,
- $absent_warning_check,
- );
- } // EOF foreach
- //echo "<pre>"; print_r($output); exit("</pre> \n exited here ");
- $cols = array(
- // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
- //'Sr No',
- 'Employee ID ||Column displays employee id',
- 'Name||Column displays the Name of the employees.',
- 'Job Title||Column displays the Job Tittle of the particular employee.',
- 'Department||Column displays the Department to which the employee belongs.',
- 'Business Unit||Column displays the Business Unit to which the employee belongs.',
- 'Clocking Priority||Column displays the details of employees Clocking Source.',
- 'Shift Name||Column displays the details of the Shift assigned to the employee.',
- 'Policy Name||Column displays the details of the Policy assigned to the employee.',
- 'Weekly Off Name||Column displays the details of Weekly off type assigned to the employee.',
- 'IP restriction Name||Column displays the details of IP restriction assigned to the employee.',
- 'Clock-in reminder||Column displays whether clock-in reminder will be sent or not.',
- 'Absent reminder||Column displays whether Absent reminder will be sent or not.',
- );
- $roster_type = "Attendance-Assignments";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- // EOF function
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param array $post_data Parameter description (if any) ...
- * @param unknown $tenant_id Parameter description (if any) ...
- * @param unknown $from Parameter description (if any) ...
- * @param unknown $to Parameter description (if any) ...
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- public static function getDailyAttendanceRoster($post_data, $tenant_id = null, $from = null, $to = null) {
- $from = $from." 00:00:00";
- $to = $to." 23:59:59";
- $return = array();
- $output = array();
- $finaldata = array();
- $index = 0;
- $status_msg = "";
- $todays_day = date("d");
- $filter = $post_data['filter_id'];
- $criteria = new EMongoCriteria();
- $criteria->shift_date('>=', new MongoDate(strtotime($from)));
- $criteria->shift_date('<=', new MongoDate(strtotime($to)));
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $begin = new DateTime($from);
- $end = new DateTime($to);
- $end = $end->modify('+1 day');
- $interval = new DateInterval('P1D');
- $daterange = new DatePeriod($begin, $interval, $end);
- $from = strtotime($from);
- $to = strtotime($to);
- $clockInSec = 0;
- $clockOutSec = 0;
- foreach ($users as $user)
- {
- // Getting users details...
- $usermodel = UserMongo::model()->tenant($tenant_id)->findByPk($user->id);
- $user_name = "";
- $job_title_department = "";
- $user_name = $usermodel->getFullname();
- $employee_no = (isset($usermodel->personal->employee_no) && !empty($usermodel->personal->employee_no)) ? $usermodel->personal->employee_no : "N.A.";
- $user_post = $usermodel->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $job_title_department = $job_title . "({$department})";
- $criteria->user_id('==', $user->id);
- $userAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
- $user_shift_id = '';
- $user_policy_id = '';
- foreach ($userAttendanceLogs as $key => $userAttendanceLog)
- {
- if (isset($userAttendanceLog))
- {
- $unpaidFlag = false;
- $userid = $userAttendanceLog->user_id;
- $shift_date = $userAttendanceLog->shift_date->sec;
- $user_shift_planner = UserShiftPlanner::model()->findByPk($userAttendanceLog->shift_planner);
- if ($user_shift_planner->shift_id != $user_shift_id)
- {
- $tenant_shift = TenantShift::model()->findByPk($user_shift_planner->shift_id);
- }
- $user_shift_id = $user_shift_planner->shift_id;
- if ($user_shift_planner->policy_id != $user_policy_id)
- {
- $attendance_policy = AttendancePolicy::model()->findByPk($user_shift_planner->policy_id);
- }
- $user_policy_id = $user_shift_planner->policy_id;
- /**/
- //$shift_name = $logCalc["rosterShiftName"];
- $shift_name = (isset($tenant_shift->shift_name) && $tenant_shift->shift_name != "") ? $tenant_shift->shift_name : "N.A.";
- //$policy_name = $logCalc["rosterPolicyName"];
- $policy_name = (isset($attendance_policy->policy_name) && $attendance_policy->policy_name != "") ? $attendance_policy->policy_name : "N.A.";
- /*$clockInSec = (isset($logCalc["punchin_time"])) ? AttendanceHelper::getFormatedTime($logCalc["punchin_time"]) : "N.A.";
- ;
- $clockOutSec = (isset($logCalc["punchout_time"])) ? AttendanceHelper::getFormatedTime($logCalc["punchout_time"]) : "N.A.";
- ;*/
- $clockInSec = (isset($userAttendanceLog["punchin_time"]) && $userAttendanceLog["punchin_time"] != null) ? AttendanceHelper::getFormatedTime($userAttendanceLog["punchin_time"]) : "N.A.";
- ;
- $clockOutSec = (isset($userAttendanceLog["punchout_time"]) && $userAttendanceLog["punchout_time"] != null) ? AttendanceHelper::getFormatedTime($userAttendanceLog["punchout_time"]) : "N.A.";
- ;
- /*if (isset($logCalc["rosterOverTimeSec"])) {
- if ($logCalc["rosterOverTimeSec"] > 0) {
- $overTimeSec = RandomHelper::sec2hms($logCalc["rosterOverTimeSec"]);
- } else {
- $overTimeSec = "0:00";
- }
- } else {
- $overTimeSec = "0:00";
- }*/
- $total_duration = (isset($userAttendanceLog["total_work_duration"]) && $userAttendanceLog["total_work_duration"] != null) ? AttendanceHelper::getFormatedTimeNewHrs($userAttendanceLog["total_work_duration"]) : "0:00";
- //$lateBySec = (isset($logCalc["rosterLateBySec"])) ? RandomHelper::sec2hms($logCalc["rosterLateBySec"]) : "0:00";
- $lateBySec = (isset($userAttendanceLog["coming_late_by"]) && $userAttendanceLog["coming_late_by"] != null) ? AttendanceHelper::getFormatedTimeNewHrs($userAttendanceLog["coming_late_by"]) : "0:00";
- $overTimeSec = (isset($userAttendanceLog["over_time"]) && $userAttendanceLog["over_time"] != null) ? AttendanceHelper::getFormatedTimeNewHrs($userAttendanceLog["over_time"]) : "0:00";
- ;
- ////// status
- $date = date("d", $shift_date);
- if (isset($userAttendanceLog->attendance_status))
- {
- $status = $userAttendanceLog->attendance_status;
- if ($status == UserAttendance::ATTENDANCE_STATUS_ABSENT) {
- $status = UserAttendanceLog::ATTENDANCE_STATUS_ABSENT;
- } elseif ($status == UserAttendance::ATTENDANCE_STATUS_PRESENT) {
- $status = UserAttendanceLog::ATTENDANCE_STATUS_PRESENT;
- }
- $weeklyoff = $userAttendanceLog->is_weekly_off->status;
- $holiday = $userAttendanceLog->is_holiday->status;
- $leave = $userAttendanceLog->in_leave->status;
- if (isset($userAttendanceLog->in_leave->leave_id))
- {
- $unpaidLeave = UserLeaves::model()->findByPk($userAttendanceLog->in_leave->leave_id);
- if (isset($unpaidLeave->isUnpaid) && $unpaidLeave->isUnpaid == UserLeaves::LEAVE_UNPAID) {
- $unpaidFlag = true;
- } else {
- $unpaidFlag = false;
- }
- } else {
- $unpaidFlag = false;
- }
- $present_or_not = '';
- if (isset($weeklyoff) && $weeklyoff == "1")
- {
- $status = "W";
- }
- elseif (isset($holiday) && $holiday == "1")
- {
- $status = "H";
- }
- elseif (isset($leave) && $leave == "1")
- {
- if ($status == UserAttendanceLog::ATTENDANCE_STATUS_PRESENT || $status == UserAttendanceLog::ATTENDANCE_STATUS_PENDING)
- {
- $present_or_not = 'Present ';
- }
- $status = "L";
- }
- elseif ($status == UserAttendanceLog::ATTENDANCE_STATUS_PRESENT || $status == UserAttendanceLog::ATTENDANCE_STATUS_PENDING)
- {
- $status = "P";
- } /* elseif ($status == UserAttendanceLog::ATTENDANCE_STATUS_PENDING) {
- $status = "n";
- } */
- elseif ($status == UserAttendanceLog::ATTENDANCE_STATUS_ABSENT || $status == UserAttendance::ATTENDANCE_STATUS_ABSENT)
- {
- $status = "A";
- }
- else
- {
- $status = "";
- }
- }
- else
- {
- $status = "";
- }
- if ($unpaidFlag)
- {
- $status = "U";
- }
- switch ($status)
- {
- case 'P':
- $status_msg = "Present";
- break;
- case 'A':
- $status_msg = "Absent";
- break;
- case 'W':
- $status_msg = "Weekly Off";
- break;
- case 'H':
- $status_msg = "Holiday" . '(' . $userAttendanceLog->is_holiday->holiday_name . ')';
- break;
- case 'L':
- case 'U':
- //in leave
- $leave_id = $userAttendanceLog->in_leave->leave_id;
- $userLeaves = UserLeaves::model()->tenant()->findByPk($leave_id);
- if (!empty($userLeaves))
- {
- $tenantLeave = $userLeaves->leaveType();
- $leave_type = (isset($tenantLeave->name))? $tenantLeave->name : 'Unpaid Leave';
- if ($userLeaves->is_half_day == UserLeaves::HALF_DAY_NO) {
- $wired_msg = $present_or_not."On Leave" . ' (' . $leave_type . ')';
- } else {
- $wired_msg = $present_or_not."HalfDay Leave" . ' (' . $leave_type . ')';
- }
- }
- $status_msg = $wired_msg;
- break;
- default:
- $status_msg = "-";
- break;
- }
- ////// status
- $attdate = date("d-M-Y", $shift_date);
- $attdateday = date("l", $shift_date);
- $attdate_day = $attdate . "(" . substr($attdateday, 0, 3) . ")";
- $output[] = array($attdate_day);
- array_push($output[$index], $employee_no, $user_name, $job_title_department, $shift_name, $policy_name, $clockInSec, $clockOutSec, $total_duration, $lateBySec, $overTimeSec, $status_msg);
- /*
- array_push($output[$index], $user_name);
- array_push($output[$index], $job_title_department);
- array_push($output[$index], $shift_name);
- array_push($output[$index], $policy_name);
- array_push($output[$index], $clockInSec);
- array_push($output[$index], $clockOutSec);
- array_push($output[$index], $total_duration);
- array_push($output[$index], $lateBySec);
- array_push($output[$index], $overTimeSec);
- array_push($output[$index], $status_msg);
- */
- $index++;
- }
- } // EOF foreach all date
- // break;
- } // EOF foreach for users count...
- $flag = true;
- $cols = array(
- 'Date||Column displays Date.',
- 'Employee ID||Column displays Employee Number.',
- 'Name||Column displays Name.',
- 'Job Title||Column displays Job Title.',
- 'Shift Name||Column displays Shift Name.',
- 'Policy Name||Column displays Policy Name.',
- 'Clock In||Column displays Clock In.',
- 'Clock Out||Column displays Clock Out.',
- 'Work Duration||Column displays Work Duration.',
- 'Late by||Column displays Late By.',
- 'Overtime||Column displays Overtime.',
- 'Status||Column displays Status.'
- );
- $roster_type = "Daily-Attendance-Report";
- $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
- $filenameexport = $roster_type . "_" . $date;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- // EOF function
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param array $post_data Parameter description (if any) ...
- * @param unknown $tenant_id Parameter description (if any) ...
- * @param unknown $from Parameter description (if any) ...
- * @param unknown $to Parameter description (if any) ...
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- public static function getCompleteAttendanceSummaryRoster($post_data, $tenant_id = null, $from = null, $to = null) {
- $return = array();
- $output = array();
- $finaldata = array();
- $index = 0;
- $status_msg = "";
- $todays_day = date("d");
- $filter = $post_data['filter_id'];
- $criteria = new EMongoCriteria();
- $criteria->shift_date('>=', new MongoDate(strtotime($from)));
- $criteria->shift_date('<=', new MongoDate(strtotime($to)));
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $begin = new DateTime($from);
- $end = new DateTime($to);
- $end = $end->modify('+1 day');
- $interval = new DateInterval('P1D');
- $daterange = new DatePeriod($begin, $interval, $end);
- $from = strtotime($from);
- $to = strtotime($to);
- foreach ($users as $user) {
- $employee_id = $user->personal->employee_no;
- $jindex = 0;
- $present_count = 0;
- $absent_count = 0;
- $leave_count = 0;
- $unpaid_leaves_count = 0;
- $weeklyoff_count = 0;
- $holiday_count = 0;
- $totalWorkDurationTimeStamp = 0;
- $workingDaysCount = 0;
- $comingLateBy = 0;
- $comingLateCounter = 0;
- $goingearly = 0;
- $goingearlytotal = 0;
- $overTimeSecCounter = 0;
- $overTimeSec = 0;
- $unpaidleave_count = 0;
- $shift_name = "";
- $policy_name = "";
- $weeklyOffName = "";
- $clockingPriority = "";
- $criteria->user_id('==', $user->id);
- $userAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
- $unpaidFlag = false;
- $user_name = "";
- $job_title_department = "";
- $userid = $user->id;
- $usermodel = UserMongo::model()->tenant($tenant_id)->findByPk($userid);
- $user_name = $usermodel->getFullname();
- $user_post = $usermodel->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $job_title_department = $job_title . "({$department})";
- $user_id = $usermodel->id;
- // echo "<pre>"; print_r($userAttendanceLogs); //exit("</pre> \n exited here ");
- foreach ($daterange as $date) {
- if (isset($userAttendanceLogs[$jindex])) {
- $shift_date = $userAttendanceLogs[$jindex]->shift_date->sec;
- $logCalc = AttendanceHelper::logCalculator($user_id, $shift_date, $tenant_id, true);
- // echo "<pre>"; print_r($logCalc); //exit("</pre> \n exited here \n");
- $shift_name = (isset($logCalc["rosterShiftName"])) ? $logCalc["rosterShiftName"] : "";
- $policy_name = $logCalc["rosterPolicyName"];
- $weeklyOffName = (isset($logCalc["rosterWeeklyOffName"])) ? $logCalc["rosterWeeklyOffName"] : "";
- $clockingPriority = (isset($logCalc["rosterClockingPriority"])) ? $logCalc["rosterClockingPriority"] : "";
- ////// status
- if (isset($userAttendanceLogs[$jindex]->attendance_status)) {
- $status = $userAttendanceLogs[$jindex]->attendance_status;
- if ($status == UserAttendance::ATTENDANCE_STATUS_ABSENT) {
- $status = UserAttendanceLog::ATTENDANCE_STATUS_ABSENT;
- } elseif ($status == UserAttendance::ATTENDANCE_STATUS_PRESENT) {
- $status = UserAttendanceLog::ATTENDANCE_STATUS_PRESENT;
- }
- $weeklyoff = $userAttendanceLogs[$jindex]->is_weekly_off->status;
- $holiday = $userAttendanceLogs[$jindex]->is_holiday->status;
- $leave = $userAttendanceLogs[$jindex]->in_leave->status;
- if (isset($userAttendanceLogs[$jindex]->in_leave->leave_id)) {
- $unpaidLeave = UserLeaves::model()->findByPk($userAttendanceLogs[$jindex]->in_leave->leave_id);
- if ($unpaidLeave->isUnpaid == UserLeaves::LEAVE_UNPAID) {
- $unpaidleave_count++;
- }
- }
- if (isset($weeklyoff) && $weeklyoff == "1") {
- $weeklyoff_count++;
- } elseif (isset($holiday) && $holiday == "1") {
- $holiday_count++;
- } elseif (isset($leave) && $leave == "1") {
- $leave_count++;
- } elseif ($status == UserAttendanceLog::ATTENDANCE_STATUS_PRESENT || $status == UserAttendanceLog::ATTENDANCE_STATUS_PENDING) {
- $present_count++;
- } /* elseif ($status == UserAttendanceLog::ATTENDANCE_STATUS_PENDING) {
- $status = "n";
- } */ elseif ($status == UserAttendanceLog::ATTENDANCE_STATUS_ABSENT || $status == UserAttendance::ATTENDANCE_STATUS_ABSENT) {
- $absent_count++;
- }
- }
- ////// status
- /// attendance
- if ($status == UserAttendanceLog::ATTENDANCE_STATUS_PRESENT || $status == UserAttendanceLog::ATTENDANCE_STATUS_PENDING) {
- if (isset($userAttendanceLogs[$jindex]->total_duration) && $userAttendanceLogs[$jindex]->total_duration != 0) {
- $totalWorkDurationTimeStamp += $userAttendanceLogs[$jindex]->total_duration;
- $workingDaysCount++;
- }
- }
- if (isset($userAttendanceLogs[$jindex]->coming_late_by) && $userAttendanceLogs[$jindex]->coming_late_by != null) {
- if (isset($logCalc["rosterLateBySec"])) {
- // echo $userAttendanceLogs[$jindex]->coming_late_by . "<br>";
- // echo $logCalc["rosterLateBySec"] . "<br>";
- $comingLateBy += $logCalc["rosterLateBySec"];
- $comingLateCounter++;
- }
- }
- if (isset($userAttendanceLogs[$jindex]->over_time) && $userAttendanceLogs[$jindex]->over_time != '0') {
- $overTimeSec += $logCalc['rosterOverTimeSec'];
- $overTimeSecCounter++;
- }
- if (!empty($logCalc["total_duration"])) {
- if ($logCalc["total_duration"] < $logCalc["rosterShiftSeconds"]) {
- $goingearlytotal += $logCalc["rosterShiftSeconds"] - $logCalc["total_duration"];
- $goingearly++;
- }
- }
- $attdate = date("d-M-Y", $shift_date);
- $attdateday = date("l", $shift_date);
- $attdate_day = $attdate . "(" . substr($attdateday, 0, 3) . ")";
- /// attendance
- $jindex++;
- } // EOF if isset
- } // EOF foreach all date
- if (isset($totalWorkDurationTimeStamp)) {
- $totalWorkedHr = RandomHelper::sec2hms($totalWorkDurationTimeStamp);
- if ($workingDaysCount > 0) {
- $daillyAverage = $totalWorkDurationTimeStamp / $workingDaysCount;
- $daillyAverage = RandomHelper::sec2hms($daillyAverage);
- } else {
- $daillyAverage = 0;
- $daillyAverage = "0:00";
- }
- } else {
- $totalWorkedHr = 0;
- $weeklyAverage = 0;
- $daillyAverage = 0;
- }
- if (isset($comingLateBy) && $comingLateCounter != 0) {
- $avgLateBy = $comingLateBy / $comingLateCounter;
- $avgLateBy = RandomHelper::sec2hms($avgLateBy);
- } else {
- $avgLateBy = "00:00";
- }
- if (isset($goingearlytotal) && $goingearlytotal != 0) {
- $avgtime = $goingearlytotal / $goingearly;
- $finalavg = RandomHelper::sec2hms($avgtime);
- } else {
- $avgtime = 0;
- $finalavg = '00:00';
- }
- if ($overTimeSec != 0) {
- $overTimeSec = $overTimeSec / $overTimeSecCounter;
- $overTimeSec = RandomHelper::sec2hms($overTimeSec);
- } else {
- $overTimeSec = "0";
- }
- $output[] = array($employee_id);
- array_push($output[$index], $user_name);
- array_push($output[$index], $job_title_department);
- array_push($output[$index], $shift_name);
- array_push($output[$index], $policy_name);
- array_push($output[$index], $weeklyOffName);
- array_push($output[$index], $clockingPriority);
- array_push($output[$index], $present_count);
- array_push($output[$index], $absent_count);
- array_push($output[$index], $leave_count);
- array_push($output[$index], $unpaid_leaves_count);
- // array_push($output[$index], $overTimeSec);
- array_push($output[$index], $totalWorkedHr);
- array_push($output[$index], $daillyAverage);
- array_push($output[$index], $comingLateCounter);
- array_push($output[$index], $avgLateBy);
- array_push($output[$index], $goingearly);
- array_push($output[$index], $finalavg);
- array_push($output[$index], $overTimeSecCounter);
- array_push($output[$index], $overTimeSec);
- $index++;
- // break;
- } // EOF user foreach
- $flag = true;
- $cols = array(
- 'Employee ID||Employee id',
- 'Name||Name',
- 'Job Title||Job Title',
- 'Shift||Shift Assinged',
- 'Policy||Policy Name',
- 'Weekly Off||Weekly off Name',
- 'Mode||The method by which employee clocks in and out, either Web/Online or Biometric/Hardware.',
- 'Present||Total days when employee was marked Present.',
- 'Absent||Total days when employee was marked Absent.',
- 'Leaves||Total leaves taken by employee during this period.',
- 'Unpaid||Unpaid leaves taken during this period.',
- 'Total Worked Hours||Total number of hours employee has worked during this period.',
- 'Daily Avg. Work Duration||An average of daily work duration for this period.',
- 'Late Marks||Total number of days when employee was marked late to work.',
- 'Avg. Late By||Average number of hours by which employee was on late marked days during this period.',
- 'Early Clock Outs||Number of days when employee clocked out before completing shift duration.',
- 'Avg. Early Clock Out by||Average number of hours by which employee clocked out on days marked as Early clock out.',
- 'Over Time Days||Number of days when employee clocked over time hours during this period.',
- 'Avg. Over Time||Average number of hours by which employee worked over time during this period.'
- );
- $roster_type = "Complete-Attendance-Summary";
- $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
- $filenameexport = $roster_type . "_" . $date;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- // EOF function
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param string $birth_day_month Parameter description (if any) ...
- * @return number Return description (if any) ...
- * @access public
- * @static
- */
- public static function days_till_birthday($birth_day_month) {
- $bts = strtotime($birth_day_month . " " . date("y"));
- $ts = time();
- if ($bts < $ts) {
- $bts = strtotime($birth_day_month . " " . date("y", strtotime("+1 year")));
- }
- return round(($bts - $ts) / 86400);
- }
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- public static function loadFilters() {
- $filters = array();
- $userMongo = UserMongo::model()->tenant()->findByAttributes(array('user_id' => Yii::app()->user->id));
- if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")) && Yii::app()->session['menu_owner'])
- {
- //$filters['ALL'] = array('ALL_0' => 'All Employees');
- // $filters['Designations'] = self::getAllDesignations();
- // $filters['Departments'] = UserDepartments::getAllDepartments();
- // $filters['Locations'] = TenantOffices::getTenantOfficeLocation();
- // $filters['Employee Type'] = TenantUserTypes::getTenantTypes();
- }
- /* if(isset($userMongo) && !empty($userMongo))
- {*/
- elseif($userMongo->checkManager())
- {
- $filters['ALL'] = array('ALL_0' => 'All Reportees');
- $filters['Reportees'] = $userMongo->getManagedUsersForRosters();
- }
- // }
- // $filters['Shift'] = TenantShift::getTenantShiftArray();
- return $filters;
- }
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- public static function loadCustomRosterFilter() {
- $roster_attribute_labels = array();
- $usermongo_obj = new UserMongo;
- $roster_attribute_labels = $usermongo_obj::model()->rosterAttributeLabels();
- // echo "<pre>"; print_r($roster_attribute_labels); exit("</pre> \n exited here ");
- return $roster_attribute_labels;
- /* //remove later
- $embedded_documents = $usermongo_obj::model()->embeddedDocuments();
- foreach ($embedded_documents as $model_name => $model) {
- $m = new $model;
- $filters[$model_name] = $m->attributes;
- // echo "<pre>"; print_r($filters); exit("</pre> \n exited here ");
- } */
- }
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- public static function getAllDesignations() {
- $desigs = UserDesignations::model()->tenant()->findAll();
- $collection = array();
- foreach ($desigs as $desig) {
- $collection['DESG_' . $desig->id] = $desig->designation_name;
- }
- return $collection;
- }
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param unknown $tenant_id Parameter description (if any) ...
- * @return object Return description (if any) ...
- * @access public
- */
- public function tenant($tenant_id = null) {
- $this->getDbCriteria()->mergeWith(array(
- 'conditions' => array(
- 'tenant_id' => array('==' => ($tenant_id == null) ? Yii::app()->user->getTenantId() : $tenant_id),
- ),
- 'sort' => array(
- 'unit_name' => EMongoCriteria::SORT_ASC,
- ),
- ));
- return $this;
- }
- public static function getLeavesCarriedForwardBalance($post_data, $tenant_id = null, $from = null, $to = null) {
- //$tenat_leave = Leaves::model()->tenant($tenant_id)->findAll();
- //echo "<pre>"; print_r($tenat_leave); exit("\n exited in " . __FILE__ . " @ " . __LINE__. "</pre>");
- $return = array();
- //$sr_no=1;
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- $leaves = Leaves::model()->getTenantLeaveList($tenant_id);
- $index = 0;
- foreach ($users as $key => $user) {
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- // $action_checkbox = "<input type=\"checkbox\" name=\"roster_action\" value=\"\">";
- $leaves_user_allowed = Leaves::model()->getLeaveList($tenant_id, $user->user_id);
- unset($userleaves);
- foreach ($leaves as $leave_id => $leave) {
- if (array_key_exists($leave_id, $leaves_user_allowed)) {
- $userleaves[] = LeavesHelper::individualLeaveBalance($user->user_id, $tenant_id, $leave_id);
- } else {
- $userleaves[] = array(
- 'leave_name' => 'NA',
- 'balance' => 'NA',
- 'total' => 'NA',
- 'prevBalance' => 'NA'
- );
- }
- }
- $output[] = array(
- // $action_checkbox,
- $employee_number,
- $user_name,
- $job_title,
- $department,
- $business_unit,
- );
- for ($i = 0; $i < count($userleaves); $i++) {
- array_push($output[$index], $userleaves[$i]['prevBalance']);
- }
- $index++;
- } // EOF foreach user
- $cols = array(
- // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
- //'Sr No',
- 'Employee ID',
- 'Name',
- 'Job Title',
- 'Department',
- 'Business Unit',
- );
- foreach ($leaves as $leave_id => $leave_name) {
- array_push($cols, $leave_name);
- }
- $roster_type = "Leaves-Credited";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getEmployeeExitReport($post_data, $tenant_id = null,$from, $to) {
- $return = array();
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, 3);
- $output = array();
- foreach ($users as $key => $user) {
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- if (isset($user->deactivate_date) && $user->deactivate_date->sec != null) {
- // checking whether it is in range
- $deactivateDate = date('Y-m-d',$user->deactivate_date->sec);
- $deactivation_Begin = date('Y-m-d', strtotime($from));
- $deactivation_End = date('Y-m-d', strtotime($to));
- if (($deactivateDate > $deactivation_Begin) && ($deactivateDate < $deactivation_End))
- {
- // checking whether it is in range
- if (isset($user->doj) && isset($user->deactivate_date)) {
- $doj = new DateTime(date("Y-m-d", $user->doj->sec)); // or your date as well
- $deactivate_date = new DateTime(date("Y-m-d", $user->deactivate_date->sec));
- $interval = $doj->diff($deactivate_date);
- $final_exp = $interval->format('%y years %m months and %d days');
- $job_experience = $final_exp;
- } else {
- $job_experience = "NA";
- }
- if (isset($user->deactivate_reason)) {
- $deactivateReason = UserDeactivate::model()->tenant()->findByPk($user->deactivate_reason);
- $exit_type = (isset($deactivateReason->type) && $deactivateReason->type == UserDeactivate::USER_DEACTIVATE_TERMINATED) ? "Terminated" : "Resigned";
- $exit_reason = (isset($deactivateReason->value) && $deactivateReason->value != null) ? $deactivateReason->value : "NA";
- } else {
- $exit_type = "NA";
- $exit_reason = "NA";
- }
- $doj = (isset($user->doj) && $user->doj != null) ? date('d/m/Y', $user->doj->sec) : "NA";
- $exit_date = (isset($user->deactivate_date) && $user->deactivate_date != null) ? date('d/m/Y', $user->deactivate_date->sec) : "NA";
- $deactivate_by = (isset($user->deactivate_by) && $user->deactivate_by != null) ? UserMongo::getFullnameById($user->deactivate_by) : "NA";
- $deactivate_on = (isset($user->deactivate_created_on) && $user->deactivate_created_on != null) ? date('d/m/Y', $user->deactivate_created_on->sec) : "NA";
- // } else {
- // $dob_year = "N.A.";
- // $dob_month = "N.A.";
- // $dob_day = "N.A.";
- // $age = "N.A.";
- // $no_days_remain = "N.A.";
- // }
- // $action_checkbox = "<input type=\"checkbox\" name=\"roster_action\" value=\"\">";
- $output[] = array(
- $employee_number,
- $user_name,
- $job_title,
- $department,
- $business_unit,
- $doj,
- $job_experience,
- $exit_date,
- $exit_type,
- $exit_reason,
- $deactivate_by,
- $deactivate_on,
- );
- }
- }
- } // EOF foreach
- // echo "<pre>"; print_r($output); exit("</pre> \n exited here ");
- $cols = array(
- // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
- //'SR NO',
- 'Employee ID',
- 'Name',
- 'Job Title',
- 'Department',
- 'Business Unit',
- 'Joining Date',
- 'Job experience',
- 'Exit Date',
- 'Exit Type',
- 'Exit Reason',
- 'Deactivated by',
- 'Deactivated on'
- );
- $filenameexport = "Employee-Deactivated-Data";
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- /**
- * Short description for function
- *
- * Long description (if any) ...
- *
- * @param array $post_data Parameter description (if any) ...
- * @param unknown $tenant_id Parameter description (if any) ...
- * @param unknown $user_id Parameter description (if any) ...
- * @return array Return description (if any) ...
- * @access public
- * @static
- */
- public static function getUnpaidLeavesTaken($post_data, $tenant_id, $from, $to) {
- $return = array();
- //$sr_no=1;
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- $leave_settings = TenantLeavesSettings::model()->findByAttributes(array('tenant_id' => $tenant_id));
- // $leaves = Leaves::model()->getLeaveList($tenant_id, $user_id);
- if(isset($leave_settings->unpaid_refresh) && $leave_settings->unpaid_refresh == TenantLeavesSettings::FINANCIAL_UNPAID_REFRESH){
- $tenantProfile = TenantProfile::model()->tenant($tenant_id)->find();
- $year_to_pass = date('Y');
- $month_list = $tenantProfile->getMonthList('Y-m','M', $year_to_pass);
- }
- else{
- $tenantProfile = TenantProfile::model()->tenant($tenant_id)->find();
- $month_list = $tenantProfile->getMonthListCalendar('Y-m','M');
- }
- //$leaves = Leaves::model()->getTenantLeaveList($tenant_id);
- $index = 0;
- foreach ($users as $key => $user) {
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- // $action_checkbox = "<input type=\"checkbox\" name=\"roster_action\" value=\"\">";
- // $leaves_user_allowed = Leaves::model()->getLeaveList($tenant_id, $user->user_id);
- // unset($userleaves);
- $check_total = 0;
- foreach ($month_list as $for_month => $month){
- $leaves_approved = UserLeaves::model()->user_approved_leave($user->id)->forMonth($for_month)->unpaid()->findAll();
- $total_days = 0;
- foreach ($leaves_approved as $le){
- $wekly_off_days = RandomHelper::getWorkingDays($le->from_date->sec, $le->to_date->sec, $le->user_id, $le->tenant_id);
- if (!empty($wekly_off_days)){
- if ($le->is_half_day == UserLeaves::HALF_DAY_YES){
- $total_days += 0.5;
- }
- }
- else{
- if ($total_days > 0){
- $total_days -= 0.5;
- }
- }
- }
- /**/
- $counter = 0;
- $counter_new = 0;
- $counter = UserLeaves::getCountOfMonthsUnpaid($user->id, $for_month);
- if ($counter > 0)
- {
- $counter = $counter - $total_days;
- }
- else
- {
- $counter = $counter;
- }
- $check_total += $counter;
- }
- //
- $output[] = array(
- // $action_checkbox,
- $employee_number,
- $user_name,
- $job_title,
- $department,
- $business_unit,
- $check_total,
- );
- // for ($i = 0; $i < count($userleaves); $i++) {
- // $newfinal = $userleaves[$i];
- // array_push($output[$index], $newfinal);
- // }
- $index++;
- } // EOF foreach user
- $cols = array(
- // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
- //'Sr No',
- 'Employee ID',
- 'Name',
- 'Job Title',
- 'Department',
- 'Business Unit',
- 'Unpaid Leaves'
- );
- // foreach ($leaves as $leave_id => $leave_name) {
- // array_push($cols, $leave_name);
- // }
- $roster_type = "Leaves-Taken-or-Used";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- // EOF function
- public static function getSummaryMonth($post_data, $tenant_id, $from, $to) {
- $for_date = date('Y-m', strtotime($from));
- $return = array();
- $deactivated_user = 0;
- $bank_details_user = 0;
- $no_bank_details_user = 0;
- $fandfamount = 0;
- $bankamount = 0;
- $nobankamount = 0;
- $current_month = date("m");
- //$sr_no=1;
- $filter = $post_data['filter_id'];
- $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
- foreach ($userSalarySlip as $salaryslip) {
- //$users = UserMongo::model()->getUsersByFilter($filter, $tenant_id,$post_data['active_inactive']);
- $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- if (isset($users) && !empty($users)) {
- $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
- /*if (isset($users->deactivate_date) && $users->deactivate_date != null && date('m', $users->deactivate_date->sec) == $current_month) {
- $deactivated_user++;
- $fandfamount += $salaryslip->total_net;
- } */if (isset($users->banking) && isset($users->banking->bank_name) && isset($users->banking->bank_account)) {
- $bank_details_user++;
- $bankamount += $salaryslip->total_net;
- } elseif (empty($users->banking) && !isset($users->banking->bank_name) && !isset($users->banking->bank_account)) {
- $no_bank_details_user++;
- $nobankamount += $salaryslip->total_net;
- }
- }
- }
- $output = array();
- $index = 0;
- $particulars_name = array("Bank List", "No Bank List");
- foreach ($particulars_name as $key => $particular) {
- if ($particular == "Bank List") {
- $employee_count = $bank_details_user;
- $amount = $bankamount;
- } elseif ($particular == "No Bank List") {
- $employee_count = $no_bank_details_user;
- $amount = $nobankamount;
- } /*else {
- $employee_count = $deactivated_user;
- $amount = $fandfamount;
- }*/
- $output[] = array(
- $particular,
- $employee_count,
- $amount,
- );
- }
- $cols = array(
- 'Particulars',
- 'Employees Count',
- 'Amount',
- );
- $roster_type = "payroll-summary-month".$for_date;
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getBankListMonth($post_data, $tenant_id, $from, $to) {
- $for_date = date('Y-m', strtotime($from));
- $return = array();
- $output = array();
- $current_month = date("m");
- $filter = $post_data['filter_id'];
- $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
- foreach ($userSalarySlip as $salaryslip) {
- //$users = UserMongo::model()->getUsersByFilter($filter, $tenant_id,$post_data['active_inactive']);
- //$users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- if($post_data['active_inactive'] == 1)
- {
- $users = UserMongo::model()->tenant($tenant_id)->active()->findByPk($salaryslip->user_id);
- }
- else if($post_data['active_inactive'] == 2)
- {
- $users = UserMongo::model()->tenant($tenant_id)->disabled()->findByPk($salaryslip->user_id);
- }
- else
- {
- $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- }
- if (isset($users) && !empty($users)) {
- $office_location = TenantOffices::model()->tenant($tenant_id)->findByAttributes(array('id' => $users->personal->office_location));
- $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
- if (isset($office_location) && !empty($office_location) && isset($office_location->city) && $office_location->city != "") {
- $city_name = City::model()->findByPk($office_location->city);
- if (isset($city_name) && !empty($city_name)) {
- $office_location_name = $city_name->name;
- } else {
- $office_location_name = "N.A";
- }
- } else {
- $office_location_name = "N.A";
- }
- if (isset($users->banking) && isset($users->banking->bank_name) && $users->banking->bank_name != "" && isset($users->banking->bank_account) && $users->banking->bank_account != "") {
- $account_number = $users->banking->bank_account;
- $account_bank_name = $users->banking->bank_name;
- $account_branch_name = (isset($users->banking->bank_branch) && $users->banking->bank_branch != "") ? $users->banking->bank_branch : "N.A.";
- //$account_bank_branch = (isset($users->banking->bank_branch) && $users->banking->bank_branch != "") ? $users->banking->bank_branch : "N.A.";
- $ifsc_code = (isset($users->banking->bank_ifsc) && $users->banking->bank_ifsc != "") ? $users->banking->bank_ifsc : "N.A.";
- $net_salary = $salaryslip->total_net;
- $full_name = $users->getFullname();
- $output[] = array(
- $employee_code,
- $full_name,
- $office_location_name,
- $account_number,
- $account_bank_name,
- $account_branch_name,
- $ifsc_code,
- $net_salary,
- );
- }
- }
- }
- $cols = array(
- 'Employee Code',
- 'Employee Name',
- 'Location',
- 'Account Number',
- 'Bank Name',
- 'Bank Branch',
- 'IFSC Code',
- 'Net Salary',
- );
- $roster_type = "payroll-Bank-List-month".$for_date;
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getNoBankListMonth($post_data, $tenant_id, $from, $to) {
- $for_date = date('Y-m', strtotime($from));
- $return = array();
- $output = array();
- $current_month = date("m");
- $filter = $post_data['filter_id'];
- $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
- foreach ($userSalarySlip as $salaryslip) {
- //$users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- if($post_data['active_inactive'] == 1)
- {
- $users = UserMongo::model()->tenant($tenant_id)->active()->findByPk($salaryslip->user_id);
- }
- else if($post_data['active_inactive'] == 2)
- {
- $users = UserMongo::model()->tenant($tenant_id)->disabled()->findByPk($salaryslip->user_id);
- }
- else
- {
- $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- }
- if (isset($users) && !empty($users)) {
- $office_location = TenantOffices::model()->tenant($tenant_id)->findByAttributes(array('id' => $users->personal->office_location));
- $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
- if (isset($office_location) && !empty($office_location) && isset($office_location->city) && $office_location->city != "") {
- $city_name = City::model()->findByPk($office_location->city);
- if (isset($city_name) && !empty($city_name)) {
- $office_location_name = $city_name->name;
- } else {
- $office_location_name = "N.A";
- }
- } else {
- $office_location_name = "N.A";
- }
- 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 == "") {
- $account_number = $users->banking->bank_account;
- $account_bank_name = "Cheque Payment";
- $account_branch_name = (isset($users->banking->bank_branch) && $users->banking->bank_branch != "") ? $users->banking->bank_branch : "N.A.";
- $net_salary = $salaryslip->total_net;
- $full_name = $users->getFullname();
- $output[] = array(
- $employee_code,
- $full_name,
- $office_location_name,
- $account_number,
- $account_bank_name,
- $net_salary,
- );
- }
- }
- }
- $cols = array(
- 'Employee Code',
- 'Employee Name',
- 'Location',
- 'Account Number',
- 'Bank Name',
- 'Net Salary',
- );
- $roster_type = "payroll-No-Bank-List-month".$for_date;
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getFandFListMonth($post_data, $tenant_id, $from, $to) {
- $for_date = date('Y-m', strtotime($from));
- $return = array();
- $output = array();
- $current_month = date("m");
- $filter = $post_data['filter_id'];
- $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
- foreach ($userSalarySlip as $salaryslip) {
- //$users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- if($post_data['active_inactive'] == 1)
- {
- $users = UserMongo::model()->tenant($tenant_id)->active()->findByPk($salaryslip->user_id);
- }
- else if($post_data['active_inactive'] == 2)
- {
- $users = UserMongo::model()->tenant($tenant_id)->disabled()->findByPk($salaryslip->user_id);
- }
- else
- {
- $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- }
- if (isset($users) && !empty($users)) {
- $office_location = TenantOffices::model()->tenant($tenant_id)->findByAttributes(array('id' => $users->personal->office_location));
- if (isset($office_location) && !empty($office_location) && isset($office_location->city) && $office_location->city != "") {
- $city_name = City::model()->findByPk($office_location->city);
- if (isset($city_name) && !empty($city_name)) {
- $office_location_name = $city_name->name;
- } else {
- $office_location_name = "N.A";
- }
- } else {
- $office_location_name = "N.A";
- }
- if (isset($users->deactivate_date) && $users->deactivate_date != null && date('m', $users->deactivate_date->sec) == $current_month) {
- $net_salary = $salaryslip->total_net;
- $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
- $full_name = $users->getFullname();
- $output[] = array(
- $employee_code,
- $full_name,
- $office_location_name,
- $net_salary,
- );
- }
- }
- }
- $cols = array(
- 'Employee Code',
- 'Employee Name',
- 'Location',
- 'Net Salary',
- );
- $roster_type = "payroll-FandF-List-month".$for_date;
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getTDSReportMonth($post_data, $tenant_id, $from, $to) {
- $for_date = date('Y-m', strtotime($from));
- $return = array();
- $output = array();
- $current_month = date("m");
- $filter = $post_data['filter_id'];
- $active_inactive = (!empty($post_data['active_inactive'])) ? $post_data['active_inactive'] : '';
- $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
- foreach ($userSalarySlip as $salaryslip) {
- //$users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- if($active_inactive == 1)
- {
- $users = UserMongo::model()->tenant($tenant_id)->active()->findByPk($salaryslip->user_id);
- }
- else if($active_inactive == 2)
- {
- $users = UserMongo::model()->tenant($tenant_id)->disabled()->findByPk($salaryslip->user_id);
- }
- else
- {
- $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- }
- $gross_salary = (isset($salaryslip->total_gross)) ? $salaryslip->total_gross : 0;
- if (isset($users) && !empty($users)) {
- $full_name = $users->getFullname();
- $office_location = TenantOffices::model()->tenant($tenant_id)->findByAttributes(array('id' => $users->personal->office_location));
- $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
- if (isset($office_location) && !empty($office_location) && isset($office_location->city) && $office_location->city != "") {
- $city_name = City::model()->findByPk($office_location->city);
- if (isset($city_name) && !empty($city_name)) {
- $office_location_name = $city_name->name;
- } else {
- $office_location_name = "N.A";
- }
- } else {
- $office_location_name = "N.A";
- }
- $pan_number = (isset($users->banking->bank_pan_num) && $users->banking->bank_pan_num != "") ? $users->banking->bank_pan_num : "N.A.";
- //$total_tds = (isset($salaryslip->tds) && $salaryslip->tds != "") ? $salaryslip->tds : "N.A.";
- $total_tds = $salaryslip->tds;
- $education_cess_cal = $total_tds * 0.03;
- $education_cess = PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $education_cess_cal);
- $income_tax = $total_tds - $education_cess;
- $surcharges =0;
- if($income_tax > 0)
- {
- $output[] = array(
- $employee_code,
- $full_name,
- $office_location_name,
- $pan_number,
- $gross_salary,
- $income_tax,
- $education_cess,
- $surcharges,
- $total_tds,
- );
- }
- }
- }
- $cols = array(
- 'Employee Code',
- 'Employee Name',
- 'Location',
- 'PAN Number',
- 'Gross',
- 'Income Tax',
- 'Education Cess',
- 'Surcharge',
- 'Total Income Tax',
- );
- $roster_type = "payroll-TDS-Report-List-month".$for_date;
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getPTReportMonth($post_data, $tenant_id, $from, $to) {
- $for_date = date('Y-m', strtotime($from));
- $month = date('m', strtotime($from));
- $return = array();
- $output = array();
- $current_month = date("m");
- $filter = $post_data['filter_id'];
- $active_inactive = (!empty($post_data['active_inactive'])) ? $post_data['active_inactive'] : '';
- $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
- foreach ($userSalarySlip as $salaryslip) {
- //$users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- if($active_inactive == 1)
- {
- $users = UserMongo::model()->tenant($tenant_id)->active()->findByPk($salaryslip->user_id);
- }
- else if($active_inactive == 2)
- {
- $users = UserMongo::model()->tenant($tenant_id)->disabled()->findByPk($salaryslip->user_id);
- }
- else
- {
- $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- }
- if (isset($users) && !empty($users)) {
- $full_name = $users->getFullname();
- $office_location = TenantOffices::model()->tenant($tenant_id)->findByAttributes(array('id' => $users->personal->office_location));
- $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
- if (isset($office_location) && !empty($office_location) && isset($office_location->city) && $office_location->city != "") {
- $city_name = City::model()->findByPk($office_location->city);
- if (isset($city_name) && !empty($city_name)) {
- $office_location_name = $city_name->name;
- } else {
- $office_location_name = "N.A";
- }
- } else {
- $office_location_name = "N.A";
- }
- foreach ($salaryslip->items as $item) {
- if ($item->variable_name == "professional_tax") {
- //print_r($item);
- //$d = new DateTime($this->for_month);
- $professional_tax = $item->max_value_month;
- if ($office_location->state == "1927" && $month == "02")
- {
- $professional_tax = (isset($professional_tax) && $professional_tax > 0 && $professional_tax == 200) ? $professional_tax + 100 : $professional_tax;
- }
- } else {
- $professional_tax = "N.A.";
- }
- }
- // Do not show the employees in the report whose PT is ZERO - KT - 9th March 2015
- if($professional_tax > 0)
- {
- $output[] = array(
- $employee_code,
- $full_name,
- $office_location_name,
- $professional_tax,
- );
- }
- }
- }
- $cols = array(
- 'Employee Code',
- 'Employee Name',
- 'Location',
- 'Professional Tax',
- );
- $roster_type = "payroll-PT-Report-month".$for_date;
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getPFReportMonth($post_data, $tenant_id, $from, $to) {
- $for_date = date('Y-m', strtotime($from));
- $return = array();
- $output = array();
- $current_month = date("m");
- $filter = $post_data['filter_id'];
- $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
- $tenantProfile = TenantProfile::model()->tenant($tenant_id)->find();
- if(!empty($tenantProfile))
- {
- if(isset($tenantProfile->pf_edli) && $tenantProfile->pf_edli == TenantProfile::ACTIVE){
- $edli_value = 6500;
- }
- else{
- if(strtotime($for_date) > strtotime('2014-10')){
- $edli_value = 15000;
- }
- else{
- $edli_value = 6500;
- }
- }
- }
- foreach ($userSalarySlip as $salaryslip) {
- $employees_contribution = 0;
- $edli = 0;
- $employees_contribution_pf = 0;
- $total_pension = 0;
- $voluntary_pf = 0;
- $total_pf = 0;
- $administartive_amount = 0;
- $insurance_fund = 0;
- $inspection_charges = 0;
- $final_amount = 0;
- $basic_eps = 0;
- $accountnooneepf = 0;
- $accountnotenepf = 0;
- $accountnotwo = 0;
- $accountnotwentyone = 0;
- $accountnotwentytwo = 0;
- //$users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- if($post_data['active_inactive'] == 1)
- {
- $users = UserMongo::model()->tenant($tenant_id)->active()->findByPk($salaryslip->user_id);
- }
- else if($post_data['active_inactive'] == 2)
- {
- $users = UserMongo::model()->tenant($tenant_id)->disabled()->findByPk($salaryslip->user_id);
- }
- else
- {
- $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- }
- if (isset($users) && !empty($users)) {
- $full_name = $users->getFullname();
- $employee_id = $users->personal->employee_no;
- $doj = (isset($users->doj->sec))? date('d/m/Y', $users->doj->sec) : 'N.A.';
- $date_of_exit = (isset($users->deactivate_date->sec))? date('d/m/Y', $users->deactivate_date->sec) : 'N.A.';
- $date_of_exit_month = (isset($users->deactivate_date->sec))? date('Y-m', $users->deactivate_date->sec) : 'N.A.';
- $dob = (isset($users->personal->dob->sec) && $users->personal->dob->sec != "") ? date('d/m/Y', $users->personal->dob->sec) : "N.A.";
- $doj = (isset($users->doj->sec) && $users->doj->sec != "") ? date('d/m/Y', $users->doj->sec) : "N.A.";
- $doj_month = (isset($users->doj->sec) && $users->doj->sec != "") ? date('Y-m', $users->doj->sec) : "N.A.";
- $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
- $gender = (isset($users->personal->gender) && $users->personal->gender == UserPersonal::GENDER_MALE) ? "M" : "F";
- // Calculate Age from Date of Birth
- // if($dob != '')
- // {
- // $from = new DateTime($dob);
- // $to = new DateTime('today');
- // $age = $from->diff($to)->y;
- // }
- // else
- // {
- // $age = 'N.A.';
- // }
- // Get employee father name.
- $emp_father_name = '';
- $emp_husband_name = '';
- $display_realation_name = '';
- if (isset($users->dependents) && count($users->dependents) > 0)
- {
- foreach ($users->dependents as $key => $value_dependent)
- {
- if ($value_dependent->relation_type == "Father")
- {
- $emp_father_first_name = (isset($value_dependent->first_name))? $value_dependent->first_name : '';
- $emp_father_last_name = (isset($value_dependent->last_name))? $value_dependent->last_name : '';
- $emp_father_name = $emp_father_first_name." ".$emp_father_last_name;
- }
- if ($value_dependent->relation_type == "Husband")
- {
- $emp_husband_first_name = (isset($value_dependent->first_name))? $value_dependent->first_name : '';
- $emp_husband_last_name = (isset($value_dependent->last_name))? $value_dependent->last_name : '';
- $emp_husband_name = $emp_father_first_name." ".$emp_father_last_name;
- }
- }
- }
- if(isset($emp_husband_name) && $emp_husband_name != ""){
- $display_realation_name = (isset($emp_husband_name) && $emp_husband_name != "") ? $emp_husband_name : "N.A.";
- $relation_type = 'S';
- }else{
- $display_realation_name = (isset($emp_father_name) && $emp_father_name != "") ? $emp_father_name : "N.A.";
- $relation_type = (isset($emp_father_name) && $emp_father_name != "") ? 'F' : "N.A.";
- }
- $office_location = TenantOffices::model()->tenant($tenant_id)->findByAttributes(array('id' => $users->personal->office_location));
- if (isset($office_location) && !empty($office_location) && isset($office_location->city) && $office_location->city != "") {
- $city_name = City::model()->findByPk($office_location->city);
- if (isset($city_name) && !empty($city_name)) {
- $office_location_name = $city_name->name;
- } else {
- $office_location_name = "N.A";
- }
- } else {
- $office_location_name = "N.A";
- }
- foreach ($salaryslip->items as $item) {
- if ($item->variable_name == "basic") {
- if(isset($tenantProfile->is_pf_restricted) && $tenantProfile->is_pf_restricted == TenantProfile::ACTIVE){
- $basic = $item->max_value_month;
- $basic = ($basic > 15000) ? 15000 : $basic;
- }else{
- $basic = $item->max_value_month;
- }
- }
- if ($item->variable_name == "provident_fund") {
- // basic basic_eps 3 conditions
- // if age is greater than 58 years then 0 else basic
- // if not existing PF member and basic > 15000 then basic_eps = 0
- // if basic > 15000 then basic_eps = 15000 as max limit is 15000
- $age = RandomHelper::CalculateAge(date('Y-m-d',$users->personal->dob->sec));
- $basic_eps = $basic;
- if($age > 58){
- $basic_eps = 0;
- }
- if(isset($user->existing_pf_member) && $user->existing_pf_member == 0 && $basic > 15000){
- $basic_eps = 0;
- }
- if($basic > 15000){
- $basic_eps = 15000;
- }
- // basic basic_eps 3 conditions
- $employees_contribution = $item->max_value_month;
- $eps_contribution = ($basic_eps > 0) ? ($basic_eps * 8.33)/100 : 0;
- $eps_contribution = PayrollHelper::roundingValues(Items::ROUND_TO_HIGEST_INTEGER,$eps_contribution);
- $diff_epf_eps = $employees_contribution - $eps_contribution;
- $lop_days = $salaryslip->lop;
- $arrear_basic = 0; //differnece of basic after salary increment
- $arrears_epf_wages = 0;
- $arrears_epf_ee_wages = 0;
- $arrears_epf_er_wages = 0;
- $arrears_eps = 0;
- if(strtotime($for_date) != strtotime($doj_month)){
- $display_realation_name = "";
- $relation_type = "";
- $dob = "";
- $gender = "";
- $doj = "";
- }
- if(isset($date_of_exit) && strtotime($for_date) == strtotime($date_of_exit_month)){
- $reason_of_exit = "C";
- }else{
- $date_of_exit = "";
- $reason_of_exit = "";
- }
- // $employee_pf = (12 * $basic) / 100;
- // $epf = ($employees_contribution/12) * 3.67;
- // $eps = ($employees_contribution/12) * 8.33;
- $lop_edli = 0;
- if ($salaryslip->lop > 0) {
- $lop_edli = ($edli_value / $salaryslip->total_working_days) * $salaryslip->lop;
- } else {
- $lop_edli = ($edli_value / $salaryslip->total_working_days) * ($salaryslip->total_working_days - $salaryslip->effective_working_days);
- }
- // Show E. D. L. I. is equal to BASIC if basic < 6500 - KT 9th March 2015
- if($basic < $edli_value){
- $edli = $basic;
- }
- else{
- $edli = ($edli_value - $lop_edli);
- }
- // $total_pension = ($edli * 8.33) / 100;
- // $employees_contribution_pf = ($employees_contribution - $total_pension);
- // $voluntary_pf = 0;
- // if(strtotime($for_date) >= strtotime('2015-01'))
- // {
- // $administartive_amount = ($basic * 0.85) / 100;
- // }
- // else{
- // $administartive_amount = ($basic * 1.1) / 100;
- // }
- // $insurance_fund = ($edli * 0.5) / 100;
- // $inspection_charges = ($edli * 0.01) / 100;
- // $total_pf = $employees_contribution + $employees_contribution_pf + $total_pension + $voluntary_pf;
- // $final_amount = $total_pf + $administartive_amount + $insurance_fund + $inspection_charges;
- }
- }
- // Do not show the row if $employees_contribution is ZERO
- if($employees_contribution > 0)
- {
- // Account no1 EPF(employee total pf + employeers diff btw epf and eps)
- $accountnooneepf += ($employees_contribution + $diff_epf_eps);
- // Account no1 EPF(employee total pf + employeers diff btw epf and eps)
- //Account number 10 = sum of all emp EPS
- $accountnotenepf += $eps_contribution;
- //Account number 10 = sum of all emp EPS
- //Account number 2 = PF admin charges
- $accountnotwo += ($basic * 0.85) / 100;
- //Account number 2 = PF admin charges
- //Account number 21 = 0.5% on edli wages
- $accountnotwentyone += ($edli * 0.5) / 100;
- //Account number 21 = 0.5% on edli wages
- //Account number 22 = 0.01% on edli wages
- $accountnotwentytwo += ($edli * 0.01) / 100;
- //Account number 22 = 0.01% on edli wages
- $pf_account_number = (isset($users->pf_number) && $users->pf_number != null) ? $users->pf_number : "N.A.";
- $employee_code_pf_exp = explode('/', $pf_account_number);
- $employee_code_pf = (isset($employee_code_pf_exp[4]) && $employee_code_pf_exp[4] != "") ? $employee_code_pf_exp[4] : "";
- $output[] = array(
- $employee_id,
- $employee_code_pf,
- $full_name,
- $basic,
- $basic_eps,
- $employees_contribution,
- $employees_contribution,
- $eps_contribution,
- $eps_contribution,
- $diff_epf_eps,
- $diff_epf_eps,
- $lop_days,
- 0,
- $arrears_epf_wages,
- $arrears_epf_ee_wages,
- $arrears_epf_er_wages,
- $arrears_eps,
- $display_realation_name,
- $relation_type,
- $dob,
- $gender,
- $doj,
- $doj,
- $date_of_exit,
- $date_of_exit,
- $reason_of_exit,
- );
- }
- }
- }
- $cols = array(
- 'Employee ID',
- 'Employee Code',
- 'Employee Name',
- 'EPF Wages', //that month earned basic
- 'EPS Wages', // basic amount 3 conditions
- 'EPF Contribution (EE Share) due',
- 'EPF Contribution (EE Share) being remitted',
- 'EPS Contribution due',
- 'EPS Contribution being remitted',
- 'Diff EPF and EPS contribution (ER share) due',
- 'Diff EPF and EPS contribution (ER share) being remitted',
- 'NCP Days',
- 'Refund Of Advances',
- 'Arrear EPF Wages',
- 'Arrear EPF EE share',
- 'Arrear EPF ER share',
- 'Arrear EPS',
- 'Fathers/Husbands Name',
- 'Relationship with the Member',
- 'Date of Birth',
- 'Gender',
- 'Date of Joining EPF',
- 'Date of Joining EPS',
- 'Date of Exit EPF',
- 'Date of Exit EPS',
- 'Reason For Leaving',
- );
- $roster_type = "payroll-PF-Report-month".$for_date;
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getSalaryRegisterMonth($post_data, $tenant_id, $from, $to) {
- $for_date = date('Y-m', strtotime($from));
- $return = array();
- $output = array();
- $index = 0;
- $current_month = date("m");
- $filter = $post_data['filter_id'];
- $active_inactive = (!empty($post_data['active_inactive'])) ? $post_data['active_inactive'] : '';
- /*get filter users*/
- $filter_users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $active_inactive);
- $filtered_users =array();
- foreach ($filter_users as $key_filter_user => $value_filter_user) {
- $filtered_users[] = $value_filter_user->id;
- }
- /*get filter users*/
- /**/
- $tenant_salary_structure = SalaryStructure::model()->tenant($tenant_id)->findAll();
- foreach ($tenant_salary_structure as $salstructure) {
- foreach ($salstructure->items as $key => $i) {
- if($i->type == Items::ITEM_TYPE_INCOME){
- $claims_to_be_made[] = array(
- "id" => $i->id,
- "label" => $i->label,
- "variable_name" => $i->variable_name,
- "declared_value" => 0.0,
- "map_to" => $i->map_to,
- );
- }
- }
- }
- foreach ($tenant_salary_structure as $salstructure) {
- foreach ($salstructure->items as $key => $i) {
- if($i->type == Items::ITEM_TYPE_BALANCING_INCOME){
- $claims_to_be_made[] = array(
- "id" => $i->id,
- "label" => $i->label,
- "variable_name" => $i->variable_name,
- "declared_value" => 0.0,
- "map_to" => $i->map_to,
- );
- }
- }
- }
- $claims_to_be_made = array_map("unserialize", array_unique(array_map("serialize", $claims_to_be_made)));
- $taken = array();
- foreach ($claims_to_be_made as $key => $item) {
- if (isset($item['variable_name']) && $item['variable_name'] != null) {
- if (!in_array($item['variable_name'], $taken)) {
- $taken[] = $item['variable_name'];
- } else {
- unset($claims_to_be_made[$key]);
- }
- }
- }
- /**/
- $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
- foreach ($userSalarySlip as $salaryslip) {
- if(in_array($salaryslip->user_id, $filtered_users)){
- //$users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- if($active_inactive == 1)
- {
- $users = UserMongo::model()->tenant($tenant_id)->active()->findByPk($salaryslip->user_id);
- }
- else if($active_inactive == 2)
- {
- $users = UserMongo::model()->tenant($tenant_id)->disabled()->findByPk($salaryslip->user_id);
- }
- else
- {
- $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- }
- if (isset($users) && !empty($users)) {
- $user_post = $users->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $full_name = $users->getFullname();
- $date_of_joining = date('Y-m-d', $users->doj->sec);
- $quit_date = (isset($users->deactivate_date->sec) && $users->deactivate_date->sec != "") ? date('Y-m-d', $users->deactivate_date->sec) : "N.A.";
- $office_location = TenantOffices::model()->tenant($tenant_id)->findByAttributes(array('id' => $users->personal->office_location));
- $state_value = (isset($office_location->state) && $office_location->state != "") ? $office_location->state : null;
- $bank_account_number = (isset($users->banking->bank_account) && $users->banking->bank_account != "") ? $users->banking->bank_account : "N.A.";
- $bank_name = (isset($users->banking->bank_name) && $users->banking->bank_name != "") ? $users->banking->bank_name : "N.A.";
- $pan_number = (isset($users->banking->bank_pan_num) && $users->banking->bank_pan_num != "") ? $users->banking->bank_pan_num : "N.A.";
- $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
- if (isset($office_location) && !empty($office_location) && isset($office_location->city) && $office_location->city != "") {
- $city_name = City::model()->findByPk($office_location->city);
- if (isset($city_name) && !empty($city_name)) {
- $office_location_name = $city_name->name;
- } else {
- $office_location_name = "N.A";
- }
- } else {
- $office_location_name = "N.A";
- }
- $esic = 0;
- $professional_tax = 0;
- $hra = 0;
- $conveyance = 0;
- $special_allowance = 0;
- $lta = 0;
- $medical = 0;
- $pf = 0;
- $check_month = date('m',strtotime($salaryslip->for_month));
- $get_final_value = array();
- /**/
- foreach ($salaryslip->items as $item) {
- if ($item->variable_name == "professional_tax") {
- //$professional_tax = $item->actual_value_month;
- if($check_month == "02" && $state_value == "1927")
- {
- $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;
- }
- else{
- $professional_tax =$item->actual_value_month;
- }
- }
- if ($item->variable_name == "provident_fund") {
- $pf =$item->actual_value_month;
- }
- if ($item->variable_name == "esic") {
- $esic =$item->actual_value_month;
- }
- }
- /**/
- foreach ($claims_to_be_made as $key => $value) {
- foreach ($salaryslip->items as $item) {
- if($value['variable_name'] == $item->variable_name)
- {
- $get_final_value[$item->variable_name] = $item->actual_value_month;
- }
- }
- }
- $lwf = 0;
- /*foreach ($claims_to_be_made as $key => $value) {
- if($value['variable_name'] == "lwf"){
- if (isset($salaryslip->lwf) && $salaryslip->lwf != null) {
- $get_final_value['lwf'] = $salaryslip->lwf;
- }
- else{
- $lwf = "N.A.";
- }
- }
- }*/
- $present_days = $salaryslip->effective_working_days;
- $loan = (isset($salaryslip->loan_deduction)) ? $salaryslip->loan_deduction : 0;
- if (isset($salaryslip->loan) && !empty($salaryslip->loan)) {
- $loan = "";
- foreach ($salaryslip->loan as $key => $value) {
- $loan_name = UserLoan::model()->tenant()->findByPk($value['id']);
- if(isset($loan_name) && !empty($loan_name)){
- $amount = PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS,$value['loan_deduction']);
- $loan = $loan .$loan_name->loan_name ." (" . $amount ."),";
- }
- }
- $loan = rtrim($loan, ",");
- }
- $advance = (isset($salaryslip->advance_deduction)) ? $salaryslip->advance_deduction : 0;
- /**/
- if(isset($salaryslip->advance_deduction) && !empty($salaryslip->advance_deduction))
- {
- $advance = 0;
- foreach ($salaryslip->advance_deduction as $key => $value) {
- $advance_name = UserAdvances::model()->tenant()->findByPk($value['id']);
- if(isset($advance_name) && !empty($advance_name)){
- $amount = PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS,$value['amount']);
- $advance = $advance .$advance_name->advance_name ." (" . $amount ."),";
- }
- }
- if($advance != 0){
- $advance = rtrim($advance, ",");
- }
- }
- else{
- $advance = 0;
- }
- /**/
- //$total_days = $salaryslip->total_working_days;
- //$present_days = $salaryslip->total_working_days;
- // $base_salary = $salaryslip->total_gross;
- // $bonus = $salaryslip->total_transactions;
- // $gross_salary = $base_salary;
- $base_salary = ($salaryslip->total_gross - $salaryslip->total_transactions);
- if($salaryslip->total_working_days != $salaryslip->effective_working_days){
- $base_salary = PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS,($base_salary/$salaryslip->effective_working_days) * $salaryslip->total_working_days);
- }
- $bonus = $salaryslip->total_transactions;
- $gross_salary = $salaryslip->total_gross;
- $incometax = $salaryslip->tds;
- $total_deductions = $salaryslip->total_deductions + $incometax;
- $net_salary = $gross_salary - $total_deductions;
- $arrears_days = 0;
- $output[] = array(
- $employee_code,
- $full_name,
- $date_of_joining,
- $quit_date,
- $present_days,
- $arrears_days,
- $job_title,
- $department,
- $business_unit,
- $office_location_name,
- $bank_account_number,
- $bank_name,
- $base_salary,
- $pan_number,
- /*$basic,
- $hra,
- $conveyance,
- $lta,
- $medical,
- $special_allowance,*/
- /* $lta_taxable,
- $lta_non_taxable,
- $medical_taxable,
- $medical_non_taxable, */
- );
- /*echo "<pre>"; print_r($get_final_value); exit("\n exited in " . __FILE__ . " @ " . __LINE__. "</pre>");
- $matching_records = array();
- foreach ($claims_to_be_made as $key_claims => $value_claims)
- {
- foreach ($get_final_value as $key_final_value => $value_final_value) {
- if($key_final_value == $value_claims['variable_name']){
- $matching_records[$value_claims['variable_name']] = $value_final_value;
- }
- }
- }*/
- $count_of_claims = count($claims_to_be_made);
- $claims_key_value_array = array();
- $diff_in_two_arrays = array();
- $tempArray = array();
- foreach ($claims_to_be_made as $key_make_new => $value_make_new) {
- $claims_key_value_array[$value_make_new['variable_name']] = $value_make_new['variable_name'];
- }
- $diff_in_two_arrays = array_diff_key($claims_key_value_array, $get_final_value);
- if(isset($diff_in_two_arrays) && !empty($diff_in_two_arrays))
- {
- foreach ($diff_in_two_arrays as $key => $value) {
- $get_final_value[$key] = 0;
- }
- }
- foreach ($get_final_value as $key_fv => $value) {
- foreach(array_keys($claims_key_value_array) as $key)
- {
- $tempArray[$key] = $get_final_value[$key];
- }
- $get_final_value = $tempArray;
- }
- /*foreach ($sal_str_deduction as $key_income => $value_income) {
- $abc = count($value_income);
- if($abc != 12)
- {
- $i = 1;
- foreach ($month_list as $key => $value) {
- if($i <= (12 - $abc)){
- $sal_str_deduction[$key_income][$key] = 0.00;
- $i++;
- }
- }
- }
- foreach(array_keys($month_list) as $key)
- {
- $tempArray[$key] = $sal_str_deduction[$key_income][$key];
- }
- $sal_str_deduction[$key_income] = $tempArray;
- }*/
- foreach ($get_final_value as $key_matching => $value_matching) {
- array_push($output[$index], (isset($value_matching)) ? $value_matching : 0);
- }
- //array_push($output[$index],$base_salary);
- array_push($output[$index],$bonus);
- array_push($output[$index],$gross_salary);
- array_push($output[$index],$incometax);
- array_push($output[$index],$professional_tax);
- array_push($output[$index],$esic);
- array_push($output[$index],$pf);
- array_push($output[$index],$lwf);
- array_push($output[$index],$loan);
- array_push($output[$index],$advance);
- array_push($output[$index],$total_deductions);
- array_push($output[$index],$net_salary);
- $index++;
- //echo "<pre>"; print_r($output); exit("\n exited in " . __FILE__ . " @ " . __LINE__. "</pre>");
- }
- }
- }
- $cols = array(
- 'Employee Code',
- 'Employee Name',
- 'Joining Date',
- 'Quit Date',
- 'Present Days',
- 'Arrears Days',
- 'Designation',
- 'Department',
- 'Business Unit',
- 'Location',
- 'Saving Account Number',
- 'Bank Name',
- 'Base Salary',
- 'PAN Number',
- /*'Basic Salary',
- 'House Rent Allowances',
- 'Conveyance Allowances',
- 'LTA',
- 'Medical',
- 'Special Allowances',*/
- /* 'LT Expenses Taxable',
- 'LT Expenses Allowance',
- 'Medical Taxable',
- 'Medical Non Taxable', */
- );
- foreach ($claims_to_be_made as $value) {
- $finaldatacols = $value['label'];
- array_push($cols, $finaldatacols);
- }
- //array_push($cols,'Base Salary');
- array_push($cols,'Bonus');
- array_push($cols,'Gross Salary');
- array_push($cols,'Income Tax');
- array_push($cols,'Professional Tax');
- array_push($cols,'Statutory ESIC');
- array_push($cols,'Statutory PF');
- array_push($cols,'LWF');
- array_push($cols,'Loan');
- array_push($cols,'Advance');
- array_push($cols,'Total Deduction');
- array_push($cols,'Net Salary');
- $roster_type = "payroll-Salary-Register-month-" .$for_date;
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getESICReportMonth($post_data, $tenant_id, $from, $to)
- {
- $tenant_profile = TenantProfile::model()->tenant()->find();
- $cal_esic_on_gross = (isset($tenant_profile->cal_esic_on_gross))? $tenant_profile->cal_esic_on_gross : 0;
- $for_date = date('Y-m', strtotime($from));
- $return = array();
- $output = array();
- $employees_contribution = "N.A.";
- $employeers_contribution = "N.A.";
- $total = "N.A.";
- $total_no_days = "N.A.";
- $current_month = date("m");
- $filter = $post_data['filter_id'];
- $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
- foreach ($userSalarySlip as $salaryslip) {
- //$users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- if($post_data['active_inactive'] == 1)
- {
- $users = UserMongo::model()->tenant($tenant_id)->active()->findByPk($salaryslip->user_id);
- }
- else if($post_data['active_inactive'] == 2)
- {
- $users = UserMongo::model()->tenant($tenant_id)->disabled()->findByPk($salaryslip->user_id);
- }
- else
- {
- $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- }
- // Getting user gross salary - 9th March 2015
- $gross_salary = $salaryslip->total_gross;
- $total_transactions = (isset($salaryslip->total_transactions))? $salaryslip->total_transactions : 0;
- // Minus Extra payment from gross salary if any
- if($total_transactions > 0)
- {
- $gross_salary = $gross_salary - $total_transactions;
- }
- if (isset($users) && !empty($users)) {
- $cal_esic = false;
- foreach ($salaryslip->items as $item) {
- /* if ($item->type == Items::ITEM_TYPE_INCOME) {
- $all_items_total += $item->actual_value_month;
- } */
- if ($item->variable_name == "esic") {
- $cal_esic = true;
- $employees_contribution_sal = $item->actual_value_month;
- }
- if ($item->variable_name == "basic") {
- $basic = $item->actual_value_month;
- }
- if($item->variable_name == 'provident_fund')
- {
- $pf = $item->actual_value_month;
- }
- }
- if ($cal_esic) {
- $all_items_total = 0;
- $full_name = $users->getFullname();
- $doj = date('Y-m-d', $users->doj->sec);
- $office_location = TenantOffices::model()->tenant($tenant_id)->findByAttributes(array('id' => $users->personal->office_location));
- $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
- if (isset($office_location) && !empty($office_location) && isset($office_location->city) && $office_location->city != "") {
- $city_name = City::model()->findByPk($office_location->city);
- if (isset($city_name) && !empty($city_name)) {
- $office_location_name = $city_name->name;
- } else {
- $office_location_name = "N.A";
- }
- } else {
- $office_location_name = "N.A";
- }
- $employees_contribution = $employees_contribution_sal;
- $original_esic = $employees_contribution / 0.0175;
- $employeers_contribution = number_format($original_esic * 0.0475);
- $total = number_format($employees_contribution + $employeers_contribution);
- // Calculate "GROSS + PF (Employeer) + EMPLOYEERS ESIC"
- // If checkbox in Payroll setting is checked for "Calculate ESIC on Gross" - KT - 9th March 2015
- if($cal_esic_on_gross == TenantProfile::ACTIVE)
- {
- $gross_salary = $gross_salary + $pf + $employeers_contribution;
- }
- $esic_account_number = (isset($users->esic_number) && $users->esic_number != null) ? $users->esic_number : "N.A.";
- $total_no_days = (isset($salaryslip->effective_working_days)) ? $salaryslip->effective_working_days : "N.A.";
- $output[] = array(
- $employee_code,
- $full_name,
- $doj,
- $office_location_name,
- $esic_account_number,
- $total_no_days,
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $gross_salary),
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $employees_contribution),
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $employeers_contribution),
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $total),
- );
- }
- }
- }
- $cols = array(
- 'Employee Code',
- 'Employee Name',
- 'Date Of Joining',
- 'Location',
- 'ESIC Account No',
- 'Number Of Working Days',
- 'Gross',
- 'Employees Contribution',
- 'Employeers Contribution',
- 'Total',
- );
- $roster_type = "Payroll-ESIC-Report-month".$for_date;
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getAttendanceSummaryRosterPayroll($post_data, $tenant_id = null, $from = null, $to = null) {
- $return = array();
- $index = 0;
- $output = array();
- $finaldata = array();
- $final_output = array();
- $filter = $post_data['filter_id'];
- $users = RunPayroll::getWithoutFNFUsers($filter, $tenant_id, $post_data['month_year']);
- $begin = new DateTime($from);
- $end = new DateTime($to);
- $end = $end->modify('+1 day');
- $interval = new DateInterval('P1D');
- $daterange = new DatePeriod($begin, $interval, $end);
- $from = strtotime($from);
- $to = strtotime($to);
- $criteria = new EMongoCriteria();
- $criteria->shift_date('>=', new MongoDate($from));
- $criteria->shift_date('<=', new MongoDate($to));
- foreach ($users as $key => $user) {
- 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)) {
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $criteria->user_id = $user->id;
- $userAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
- //echo "<pre>"; print_r($userAttendanceLogs); exit("</pre> \n exited here \n");
- $present = 0;
- $absent = 0;
- $weeklyoff_count = 0;
- $holiday_count = 0;
- $leave_count = 0;
- $unpaidleave_count = 0;
- $return = array();
- $output[] = array(
- $user_name,
- );
- $jindex = 0;
- foreach ($daterange as $date) {
- $unpaidFlag = false;
- if (isset($userAttendanceLogs[$jindex])) {
- if ($date->format("d") == date("d", $userAttendanceLogs[$jindex]->shift_date->sec)) {
- $date = date("d", $userAttendanceLogs[$jindex]->shift_date->sec);
- if (isset($userAttendanceLogs[$jindex]->attendance_status)) {
- $status = $userAttendanceLogs[$jindex]->attendance_status;
- if ($status == UserAttendance::ATTENDANCE_STATUS_ABSENT) {
- $status = UserAttendanceLog::ATTENDANCE_STATUS_ABSENT;
- } elseif ($status == UserAttendance::ATTENDANCE_STATUS_PRESENT) {
- $status = UserAttendanceLog::ATTENDANCE_STATUS_PRESENT;
- }
- $weeklyoff = $userAttendanceLogs[$jindex]->is_weekly_off->status;
- $holiday = $userAttendanceLogs[$jindex]->is_holiday->status;
- $leave = $userAttendanceLogs[$jindex]->in_leave->status;
- if (isset($userAttendanceLogs[$jindex]->in_leave->leave_id)) {
- $unpaidLeave = UserLeaves::model()->findByPk($userAttendanceLogs[$jindex]->in_leave->leave_id);
- if (isset($unpaidLeave) && $unpaidLeave != null) {
- if ($unpaidLeave->isUnpaid == UserLeaves::LEAVE_UNPAID) {
- $unpaidleave_count++;
- $unpaidFlag = true;
- } else {
- $unpaidFlag = false;
- }
- }
- } else {
- $unpaidFlag = false;
- }
- if (isset($weeklyoff) && $weeklyoff == "1") {
- $status = "W";
- $weeklyoff_count++;
- } elseif (isset($holiday) && $holiday == "1") {
- $status = "H";
- $holiday_count++;
- } elseif (isset($leave) && $leave == "1") {
- $status = "L";
- $leave_count++;
- } elseif ($status == UserAttendanceLog::ATTENDANCE_STATUS_PRESENT || $status == UserAttendanceLog::ATTENDANCE_STATUS_PENDING) {
- $status = "P";
- $present++;
- } /* elseif ($status == UserAttendanceLog::ATTENDANCE_STATUS_PENDING) {
- $status = "n";
- } */ elseif ($status == UserAttendanceLog::ATTENDANCE_STATUS_ABSENT || $status == UserAttendance::ATTENDANCE_STATUS_ABSENT) {
- $status = "A";
- $absent++;
- } else {
- $status = "";
- }
- } else {
- $status = "";
- }
- $jindex++;
- } else {
- $status = "-";
- }
- } else {
- $status = "-";
- }
- if ($unpaidFlag) {
- $status = "U";
- }
- array_push($output[$index], $status);
- } // my good loop
- array_push($output[$index], $present);
- array_push($output[$index], $absent);
- array_push($output[$index], $weeklyoff_count);
- array_push($output[$index], $leave_count);
- array_push($output[$index], $unpaidleave_count);
- $index++;
- } // EOF foreach all user
- $flag = true;
- $cols = array(
- // 'Name||Column displays the Name of the employees.'
- 'Name||Column displays the Name of the employees.'
- );
- foreach ($daterange as $date) {
- $finaldatacols = $date->format("d") . "<br>" . substr((String) $date->format("D"), 0, 2);
- array_push($cols, $finaldatacols);
- }
- array_push($cols, 'P||Column displays the total number days when an employee was Present in the specified duration.');
- array_push($cols, 'A||Column displays the total number of days when an employee was Absent in the specified duration.');
- array_push($cols, 'W||Column displays the total number of Weekly Offs assigned to an employee in the specified duration.');
- array_push($cols, 'L||Column displays the total number of days when an employee was on a Leave in the specified duration.');
- array_push($cols, 'U||Column displays the total number of days when an employee was on a Unpaid Leave in the specified duration.');
- $roster_type = "Attendance-Summary";
- $date = date('d-m-Y', $from) . "-to-" . date('d-m-Y', $to);
- $filenameexport = $roster_type . "_" . $date;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- }
- return $final_output;
- }
- public static function getMasterCtcReport($post_data, $tenant_id, $from, $to) {
- $for_date = date('Y-m', strtotime($from));
- $return = array();
- $output = array();
- $current_month = date("m");
- $filter = $post_data['filter_id'];
- $gratuity_show = false;
- /**/
- $tenant_salary_structure = SalaryStructure::model()->tenant($tenant_id)->findAll();
- foreach ($tenant_salary_structure as $salstructure) {
- foreach ($salstructure->items as $key => $i) {
- if($i->variable_name == "gratuity")
- {
- $gratuity_show = true;
- }
- $claims_to_be_made[] = array(
- "id" => $i->id,
- "label" => $i->label,
- "variable_name" => $i->variable_name,
- "declared_value" => 0.0,
- "map_to" => $i->map_to
- );
- }
- }
- $claims_to_be_made = array_map("unserialize", array_unique(array_map("serialize", $claims_to_be_made)));
- /**/
- //$users_all = UserMongo::model()->tenant($tenant_id)->findAll();
- $users_all = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- foreach ($users_all as $users) {
- if (isset($users) && !empty($users)) {
- $user_sql = UserMongoView::model()->tenant($tenant_id)->findByAttributes(array('user_id'=>$users->user_id));
- if (isset($user_sql) && !empty($user_sql)) {
- $email_id_sql = (isset($user_sql->email) && $user_sql->email != "") ? $user_sql->email : "N.A.";
- } else {
- $email_id_sql = "N.A.";
- }
- $user_post = $users->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- if (isset($users->personal->gender) && $users->personal->gender != "") {
- $gender = ($users->personal->gender == "1") ? "Male" : "Female";
- } else {
- $gender = "N.A.";
- }
- $dob = (isset($users->personal->dob->sec) && $users->personal->dob->sec != "") ? date('Y-m-d', $users->personal->dob->sec) : "N.A.";
- if (isset($users->dependents) && count($users->dependents) > 0) {
- foreach ($users->dependents as $key => $value_dependent) {
- if ($value_dependent->relation_type == "Father") {
- $emp_father_name = $value_dependent->first_name;
- }
- }
- }
- $emp_father_name = (isset($emp_father_name) && $emp_father_name != "") ? $emp_father_name : "N.A.";
- $full_name = $users->getFullname();
- $date_of_joining = date('Y-m-d', $users->doj->sec);
- $quit_date = (isset($users->deactivate_date->sec) && $users->deactivate_date->sec != "") ? date('Y-m-d', $users->deactivate_date->sec) : "N.A.";
- $office_location = TenantOffices::model()->tenant($tenant_id)->findByAttributes(array('id' => $users->personal->office_location));
- $bank_account_number = (isset($users->banking->bank_account) && $users->banking->bank_account != "") ? $users->banking->bank_account : "N.A.";
- $bank_name = (isset($users->banking->bank_name) && $users->banking->bank_name != "") ? $users->banking->bank_name : "N.A.";
- $pan_number = (isset($users->banking->bank_pan_num) && $users->banking->bank_pan_num != "") ? $users->banking->bank_pan_num : "N.A.";
- $pf_number = (isset($users->pf_number) && $users->pf_number != "") ? $users->pf_number : "N.A.";
- $esic_number = (isset($users->esic_number) && $users->esic_number != "") ? $users->esic_number : "N.A.";
- $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
- if (isset($office_location) && !empty($office_location) && isset($office_location->city) && $office_location->city != "") {
- $city_name = City::model()->findByPk($office_location->city);
- if (isset($city_name) && !empty($city_name)) {
- $office_location_name = $city_name->name;
- } else {
- $office_location_name = "N.A";
- }
- } else {
- $office_location_name = "N.A";
- }
- /**/
- $for_month = date('Y-m');
- $year = date('Y');
- $month = ($year + 1) . "-03";
- $where = "1";
- $taxCalculator = new TaxCalculator($users->id, $tenant_id, $year, $month, 0.0, $where);
- $professional_tax = 0;
- $deduction_total = $taxCalculator->getItemsTotal(Items::ITEM_TYPE_DEDUCTIONS);
- foreach ($deduction_total as $key => $value) {
- $professional_tax += $value['professional_tax'];
- foreach ($value as $keys => $value_name) {
- if ($keys == "professional_tax") {
- $office_location = TenantOffices::model()->findByPk($users->personal->office_location);
- if ($office_location->state == "1927" && date('m', strtotime($key)) == "02") {
- $professional_tax = (isset($professional_tax) && $professional_tax > 0) ? $professional_tax + 100 : 0;
- } elseif ($office_location->state == "1926" && date('m', strtotime($key)) == "03") {
- $professional_tax = (isset($professional_tax) && $professional_tax > 0) ? $professional_tax + 4 : 0;
- }
- }
- }
- }
- $salaryCalculator = new SalCalculator($users->id, $tenant_id, $for_month, '', '', '', 1);
- $ctc_proration = $salaryCalculator->userSalarySlip;
- if (isset($ctc_proration) && !empty($ctc_proration)) {
- $basic = 0;
- $hra = 0;
- $conveyance = 0;
- $medical = 0;
- $lta = 0;
- $special_allowance = 0;
- $base_salary = 0;
- $bonus = 0;
- $gross_salary = 0;
- $incometax = 0;
- //$professional_tax = 0;
- $esic = 0;
- $pf = 0;
- $total_deductions = 0;
- $net_salary = 0;
- $esic_is_yes_no = 'No';
- $bonus_allowance = 0;
- $laptop_allowance = 0;
- foreach ($ctc_proration->items as $item) {
- /* if ($item->variable_name == "professional_tax") {
- $professional_tax = $item->max_value_month;
- } */
- if ($item->variable_name == "basic") {
- $basic = $item->max_value_year;
- }
- if ($item->variable_name == "hra") {
- $hra = $item->max_value_year;
- }
- if ($item->variable_name == "conveyance") {
- $conveyance = $item->max_value_year;
- }
- if ($item->variable_name == "special_allowance") {
- $special_allowance = $item->max_value_year;
- }
- if ($item->variable_name == "lta") {
- $lta = $item->max_value_year;
- }
- if ($item->variable_name == "medical") {
- $medical = $item->max_value_year;
- }
- if ($item->variable_name == "provident_fund") {
- $pf = $item->max_value_year;
- }
- if ($item->variable_name == "esic") {
- $esic_is_yes_no = 'Yes';
- $esic = $item->max_value_year;
- }
- if ($item->variable_name == "bonus_allowance") {
- $bonus_allowance = $item->max_value_year;
- }
- if ($item->variable_name == "laptop_allowance") {
- $laptop_allowance = $item->max_value_year;
- }
- }
- } else {
- $esic_is_yes_no = 'No';
- $basic = "N.A.";
- $hra = "N.A.";
- $conveyance = "N.A.";
- $medical = "N.A.";
- $lta = "N.A.";
- $special_allowance = "N.A.";
- $base_salary = "N.A.";
- $bonus = "N.A.";
- $gross_salary = "N.A.";
- $incometax = "N.A.";
- $professional_tax = "N.A.";
- $esic = "N.A.";
- $pf = "N.A.";
- $total_deductions = "N.A.";
- $net_salary = "N.A.";
- $bonus_allowance = "N.A.";
- $laptop_allowance = "N.A.";
- }
- if($gratuity_show && $basic > 0)
- {
- $gratuity = $basic * 0.0481;
- }
- else{
- $gratuity = "N.A.";
- }
- /**/
- $basic = (isset($basic)) ? $basic : "N.A.";
- $hra = (isset($hra)) ? $hra : "N.A.";
- $conveyance = (isset($conveyance)) ? $conveyance : "N.A.";
- $special_allowance = (isset($special_allowance)) ? $special_allowance : "N.A.";
- $lta = (isset($lta)) ? $lta : "N.A.";
- $medical = (isset($medical)) ? $medical : "N.A.";
- $pf = (isset($pf)) ? $pf : "N.A.";
- $base_salary = $salaryslip->total_gross;
- $gross_salary = $base_salary + $bonus;
- $incometax = $salaryslip->tds;
- $esic = (isset($esic) && $esic != "") ? $esic : 0;
- $bonus_allowance = (isset($bonus_allowance) && $bonus_allowance != "") ? $bonus_allowance : 0;
- $laptop_allowance = (isset($laptop_allowance) && $laptop_allowance != "") ? $laptop_allowance : 0;
- $total_ctc = $ctc_proration->ctc;
- $output[] = array(
- $employee_code,
- $full_name,
- $date_of_joining,
- $gender,
- $dob,
- $quit_date,
- $job_title,
- $department,
- $business_unit,
- $office_location_name,
- $bank_account_number,
- $bank_name,
- $pan_number,
- $pf_number,
- $esic_number,
- $email_id_sql,
- $esic_is_yes_no,
- $emp_father_name,
- $basic,
- $hra,
- $conveyance,
- $medical,
- $lta,
- $bonus_allowance,
- $laptop_allowance,
- $gratuity,
- $special_allowance,
- // $professional_tax,
- $esic,
- $pf,
- $total_ctc,
- );
- }
- }
- $cols = array(
- 'Employee Code',
- 'Employee Name',
- 'Joining Date',
- 'Gender',
- 'Date Of Birth',
- 'Quit Date',
- 'Designation',
- 'Department',
- 'Business Unit',
- 'Location',
- 'Saving Account Number',
- 'Bank Name',
- 'PAN Number',
- 'PF Number',
- 'ESIC Number',
- 'Office Email',
- 'ESIC Y N',
- 'Emp Fathers Name',
- 'Basic',
- 'House Rent Allowances',
- 'Conveyance Allowances',
- 'Medical',
- 'LTA',
- 'Bonus Allowance',
- 'Laptop Allowance',
- 'Gratuity',
- 'Special Allowances',
- //'Professional Tax',
- 'Statutory ESIC',
- 'Statutory PF',
- 'Total Ctc',
- );
- $roster_type = "payroll-Master-Ctc-Report".$for_date;
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getHeadCountMonth($post_data, $tenant_id, $from, $to) {
- //$for_date = date('Y-m', strtotime($from));
- $for_month = date('m', strtotime($from));
- $end_month = date('m', strtotime($to));
- $for_year = date('Y', strtotime($from));
- $end_year = date('Y', strtotime($to));
- $for_month_previous = $for_month - "01";
- if ($for_month_previous == 0) {
- $for_month_previous = $for_month_previous + "12";
- }
- $end_month_previous = $end_month - "01";
- if ($end_month_previous == 0) {
- $end_month_previous = $end_month_previous + "12";
- }
- if ($for_month_previous > 9 && $end_month_previous > 9) {
- $final_previous_date_for = "01-" . $for_month_previous . "-" . $for_year;
- $final_previous_date_end = "31-" . $end_month_previous . "-" . $end_year;
- } else {
- $final_previous_date_for = "01-0" . $for_month_previous . "-" . $for_year;
- $final_previous_date_end = "31-0" . $end_month_previous . "-" . $end_year;
- }
- $return = array();
- $output = array();
- $current_month = date("m");
- $filter = $post_data['filter_id'];
- $total_hc = 0;
- $total_seprated = 0;
- $total_added = 0;
- $previous_hc = 0;
- $total_seprated_previous_month = 0;
- $users_all = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $users_all_inactive = UserMongo::model()->getUsersByFilter($filter, $tenant_id, 10); //passing 10 as a parameter to get all active and inactive employee
- if (isset($users_all) && !empty($users_all)) {
- foreach ($users_all as $users) {
- if (isset($users->created->sec) && $users->created->sec >= strtotime($from) && $users->created->sec <= strtotime($to)) {
- $total_added = $total_added + 1;
- }
- if (isset($users->created->sec) && $users->created->sec < strtotime($from)) {
- $previous_hc = $previous_hc + 1;
- }
- }
- }
- if (isset($users_all_inactive) && !empty($users_all_inactive)) {
- foreach ($users_all_inactive as $users_inactive) {
- if (isset($users_inactive->deactivate_date->sec) && $users_inactive->deactivate_date->sec >= strtotime($from) && $users_inactive->deactivate_date->sec <= strtotime($to)) {
- $total_seprated = $total_seprated + 1;
- }
- if (isset($users->created->sec) && $users->created->sec <= strtotime($from)) {
- $previous_hc = $previous_hc + 1;
- }
- if (isset($users_inactive->deactivate_date->sec) && $users_inactive->deactivate_date->sec <= strtotime($final_previous_date_end)) {
- $total_seprated_previous_month = $total_seprated_previous_month + 1;
- }
- }
- }
- $total_hc = (($previous_hc - $total_seprated_previous_month) + $total_added) - $total_seprated;
- $output[] = array(
- ($previous_hc - $total_seprated_previous_month),
- $total_added,
- $total_seprated,
- $total_hc,
- );
- $cols = array(
- 'Opening Head Count',
- 'Addition',
- 'Sepration',
- 'Closing Head Count',
- );
- $roster_type = "payroll-Monthly-Head-Count-Annual";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getLeavesEncashmentBalance($post_data, $tenant_id = null, $from = null, $to = null) {
- //$tenat_leave = Leaves::model()->tenant($tenant_id)->findAll();
- //echo "<pre>"; print_r($tenat_leave); exit("\n exited in " . __FILE__ . " @ " . __LINE__. "</pre>");
- $return = array();
- //$sr_no=1;
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- $leaves = Leaves::model()->getTenantLeaveList($tenant_id);
- $index = 0;
- foreach ($users as $key => $user) {
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- // $action_checkbox = "<input type=\"checkbox\" name=\"roster_action\" value=\"\">";
- $leaves_user_allowed = Leaves::model()->getLeaveList($tenant_id, $user->user_id);
- unset($userleaves);
- foreach ($leaves as $leave_id => $leave) {
- if (array_key_exists($leave_id, $leaves_user_allowed)) {
- $userleaves[] = LeavesHelper::individualEncashmentBalance($user->id, $tenant_id, $leave_id);
- } else {
- $userleaves[] = "N.A.";
- }
- }
- $output[] = array(
- // $action_checkbox,
- $employee_number,
- $user_name,
- $job_title,
- $department,
- $business_unit,
- );
- for ($i = 0; $i < count($userleaves); $i++) {
- array_push($output[$index], $userleaves[$i]);
- }
- $index++;
- } // EOF foreach user
- $cols = array(
- // "<input type=\\\"checkbox\\\" name=\\\"roster_action\\\" value=\\\"\\\">",
- //'Sr No',
- 'Employee ID',
- 'Name',
- 'Job Title',
- 'Department',
- 'Business Unit',
- );
- foreach ($leaves as $leave_id => $leave_name) {
- array_push($cols, $leave_name);
- }
- $roster_type = "Leaves-Encashment";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getReimbursement($post_data, $tenant_id, $from, $to, $type, $name) {
- $output = array();
- $tenant = Tenants::model()->findByPk($tenant_id);
- $subdomain = (isset($tenant->tenant_subdomain) && $tenant->tenant_subdomain != "") ? $tenant->tenant_subdomain : "darwinbox";
- $filter = $post_data['filter_id'];
- $users_all = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- foreach ($users_all as $key_user => $value_user) {
- $users_array[] = $value_user->id;
- }
- $from_date = new MongoDate(strtotime($from));
- $to_date = new MongoDate(strtotime($to));
- if ($type == UserExpenses::STATUS_COMPENSATED) {
- $criteria = new EMongoCriteria();
- $criteria->status('==', UserExpenses::STATUS_APPROVED);
- $criteria->paid('==', UserExpenses::PAID_YES);
- $criteria->tenant_id('==', $tenant_id);
- $criteria->date('<=', $to_date);
- $criteria->date('>=', $from_date);
- $user_expenses = UserExpenses::model()->findAll($criteria);
- } else {
- $criteria = new EMongoCriteria();
- $criteria->status('==', $type);
- $criteria->paid('==', UserExpenses::PAID_NO);
- $criteria->tenant_id('==', $tenant_id);
- $criteria->date('<=', $to_date);
- $criteria->date('>=', $from_date);
- $user_expenses = UserExpenses::model()->findAll($criteria);
- }
- if (isset($user_expenses) && !empty($user_expenses)) {
- foreach ($user_expenses as $key_reimbursment => $value_reimbursment) {
- if (in_array($value_reimbursment->user_id, $users_array)) {
- $user_mongo_each = UserMongo::model()->tenant($tenant_id)->findByPk($value_reimbursment->user_id);
- $user_post = $user_mongo_each->getCurrentPosition($tenant_id);
- $job_title = (isset($user_post['designation'])) ? $user_post['designation'] : "N.A.";
- $department = (isset($user_post['department'])) ? $user_post['department'] : "N.A.";
- $business_unit = (isset($user_post['business_unit'])) ? $user_post['business_unit'] : "N.A.";
- $full_name = $user_mongo_each->getFullname();
- $employee_id = $user_mongo_each->personal->employee_no;
- $title = (isset($value_reimbursment->title)) ? $value_reimbursment->title : "N.A.";
- $date = (isset($value_reimbursment->date->sec)) ? date('d F Y', $value_reimbursment->date->sec) : "N.A.";
- $item_total = 0;
- $item_name_price = '';
- foreach ($value_reimbursment->items as $key_items => $value_items) {
- $item_name = $value_items['itemName'];
- $item_price = $value_items['itemPrice'];
- $item_name_price = (empty($item_name_price)) ? $item_name . " (" . $item_price . ")" : $item_name_price . ", " . $item_name . " (" . $item_price . ")";
- $item_total += $item_price;
- }
- if (isset($value_reimbursment->paid_by) && $value_reimbursment->paid_by != "") {
- $performed_by = UserMongo::getFullnameById($value_reimbursment->paid_by);
- } else if (isset($value_reimbursment->approved_or_rejected_by) && $value_reimbursment->approved_or_rejected_by != "") {
- $performed_by = UserMongo::getFullnameById($value_reimbursment->approved_or_rejected_by);
- } else {
- $performed_by = "N.A.";
- }
- $link_created = "https://" . $subdomain . ".darwinbox.in/expenses/expenses/view/id/" . $value_reimbursment->id;
- $link = '<a target = "_blank" href = '.$link_created.'>'.$link_created.' </a>';
- $output[] = array(
- $employee_id,
- $full_name,
- $department,
- $job_title,
- $title,
- $date,
- $item_name_price,
- $item_total,
- $name, //status
- $performed_by,
- $link,
- );
- }
- }
- }
- $cols = array(
- 'Employee ID',
- 'Employee Name',
- 'Department',
- 'Designation',
- 'Title',
- 'Date',
- 'Items(Amount)',
- 'Total Amount',
- 'Status',
- 'Performed By',
- 'Link',
- );
- $roster_type = "Reimbursement-Report";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getAnnualLeaveTracker($post_data, $tenant_id) {
- //$year_requested = date('Y', strtotime($from));
- $todays_date = date('Y-m-d');
- $previous_annual_tracker = AnnualLeavesTracker::isNew($todays_date);
- if ($previous_annual_tracker) {
- $user_mongo_data = UserMongo::model()->tenant()->findByAttributes(array('user_id' => Yii::app()->user->id));
- $annual_tracker = new AnnualLeavesTracker;
- $annual_tracker->user_id = Yii::app()->user->id;
- $annual_tracker->user_name = $user_mongo_data->getFullname();
- $user_email = (isset($user_mongo_data->personal->email)) ? $user_mongo_data->personal->email : UserMongo::getUserEmail($user_mongo_data->user_id);
- $annual_tracker->user_email = array('0' => $user_email);
- $annual_tracker->report_created_time = null;
- $annual_tracker->size = null;
- $annual_tracker->tenant_id = $user_mongo_data->tenant_id;
- $annual_tracker->file_path = null;
- $annual_tracker->save();
- } else {
- $message = "you can request this report only onces a DAY";
- }
- /**/
- $previous_annual_tracker = AnnualLeavesTracker::model()->tenant()->findAll();
- $tenant_profile = TenantProfile::model()->tenant()->find();
- foreach ($previous_annual_tracker as $key_annual => $value_annual) {
- //get employee id
- $users = UserMongo::model()->tenant($tenant_id)->findByAttributes(array('user_id'=>$value_annual->user_id));
- $employee_id = $users->personal->employee_no;
- //get employee id
- $status = ($value_annual->status == AnnualLeavesTracker::ANNUALLT_PENDING) ? "Pending" : "Completed";
- $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) : "-";
- $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) : "-";
- if (isset($value_annual->file_path) && $value_annual->file_path != "") {
- $link = "https://" . $tenant_profile->tenant_subdomain . ".darwinbox.in/upload/annualleavesreport/" . $value_annual->file_path;
- $download_link = '<a href = "' . $link . '" target = "_blank"> Click here </a>';
- } else {
- $download_link = "-";
- }
- $output[] = array(
- $employee_id,
- $value_annual->user_name,
- $value_annual->user_email,
- $export_requested_time,
- $export_completed_time,
- $download_link,
- $status,
- );
- }
- $cols = array(
- 'Employee ID',
- 'Export Requested By',
- 'Requested Email',
- 'Export Requested Time',
- 'Export Completed Time',
- 'Download Link',
- 'Status',
- );
- $roster_type = "Annual-Leaves-Requested-Report-List";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- /**/
- }
- public static function getcompoffbalance($post_data, $tenant_id, $from, $to) {
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- foreach ($users as $key_user => $user) {
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $compoff_available = $user->getCompoffLeavesavailable();
- $output[] = array(
- $employee_number,
- $user_name,
- $job_title,
- $department,
- $business_unit,
- $compoff_available,
- );
- }
- $cols = array(
- 'Employee ID',
- 'Name',
- 'Job Title',
- 'Department',
- 'Business Unit',
- 'Compoff Balance',
- );
- $roster_type = "Compoff-Balance-Report-List";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- /**/
- }
- public static function getcompofftakenused($post_data, $tenant_id, $from, $to) {
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- foreach ($users as $key_user => $user) {
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $compoff_taken = $user->getCompoffLeavestaken();
- $output[] = array(
- $employee_number,
- $user_name,
- $job_title,
- $department,
- $business_unit,
- $compoff_taken,
- );
- }
- $cols = array(
- 'Employee ID',
- 'Name',
- 'Job Title',
- 'Department',
- 'Business Unit',
- 'Compoff Taken/Used',
- );
- $roster_type = "Compoff-Taken-Report-List";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- /**/
- }
- public static function getcompoffcredited($post_data, $tenant_id, $from, $to) {
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- foreach ($users as $key_user => $user) {
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $compoff_taken = $user->getCompoffLeavestaken();
- $compoff_available = $user->getCompoffLeavesavailable();
- $compoff_credited = $compoff_taken + $compoff_available;
- $output[] = array(
- $employee_number,
- $user_name,
- $job_title,
- $department,
- $business_unit,
- $compoff_credited,
- );
- }
- $cols = array(
- 'Employee ID',
- 'Name',
- 'Job Title',
- 'Department',
- 'Business Unit',
- 'Compoff credited',
- );
- $roster_type = "Compoff-Credited-Report-List";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- /**/
- }
- public static function getcompoffsummary($post_data, $tenant_id, $from, $to) {
- $output = array();
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- foreach ($users as $key_user => $user) {
- $employee_id = $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $compoff_taken = $user->getCompoffLeavestaken();
- $compoff_available = $user->getCompoffLeavesavailable();
- $compoff_credited = $compoff_taken + $compoff_available;
- $output[] = array(
- $employee_id,
- $user_name,
- $job_title,
- $department,
- $business_unit,
- $compoff_credited,
- $compoff_taken,
- $compoff_available,
- );
- }
- $cols = array(
- 'Employee ID',
- 'Name',
- 'Job Title',
- 'Department',
- 'Business Unit',
- 'Compoff credited',
- 'Compoff taken',
- 'Compoff Balance',
- );
- $roster_type = "Compoff-Summary-Report-List";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- /**/
- }
- public static function optionalHolidays($post_data, $tenant_id = null) {
- $return = array();
- $output = array();
- $locations = "";
- $holidays_list = TenantHolidays::model()->tenant()->active()->findAllByAttributes(array('optional' => TenantHolidays::OPTIONAL_TRUE,'date_year' => date('Y')));
- if(isset($holidays_list) && !empty($holidays_list)){
- foreach ($holidays_list as $key_holiday => $value_holiday) {
- $holiday_name = (isset($value_holiday->name)) ? $value_holiday->name : "N.A.";
- if(isset($value_holiday->date,$value_holiday->date_year))
- {
- $date_month = explode('-', $value_holiday->date);
- $date_only = (isset($date_month[1])) ? $date_month[1] : "";
- $month_only = (isset($date_month[0])) ? $date_month[0] : "";
- }
- $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.";
- $locations = "";
- if(!empty($value_holiday->for_location)):
- foreach($value_holiday->for_location as $h):
- $tenant_office = TenantOffices::model()->findByPk($h);
- if(!empty($tenant_office)) :
- $locations = (isset($locations) && $locations != "") ? $locations."<br/>".$tenant_office->getLocation() : $tenant_office->getLocation();
- endif;
- endforeach;
- endif;
- $output[] = array(
- $holiday_name,
- $holiday_date,
- $locations,
- );
- } // EOF foreach
- }
- $cols = array(
- 'Holiday Name',
- 'Holiday Date',
- 'Locations',
- );
- $roster_type = "Optional-Holiday-Data";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function workanniversary($post_data, $tenant_id = null, $from, $to) {
- $return = array();
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- $index = 0;
- foreach ($users as $key => $user) {
- if(isset($user->doj->sec) && $user->doj->sec != ""){
- $todaysDate = date('m-d',$user->doj->sec);
- $year_only = date('Y',$user->doj->sec);
- $openDateBegin = date('m-d', strtotime($from));
- $openDateEnd = date('m-d', strtotime($to));
- if (($todaysDate >= $openDateBegin) && ($todaysDate <= $openDateEnd))
- {
- if($year_only != date('Y'))
- {
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $doj = date('d F Y, l',$user->doj->sec);
- $annv_date_create = date('Y')."-".$todaysDate;
- $anniversary_date = date('d F Y, l',strtotime($annv_date_create));
- $output[] = array(
- $employee_number,
- $user_name,
- $job_title,
- $department,
- $business_unit,
- $doj,
- $anniversary_date,
- );
- }
- }
- }
- } // EOF foreach user
- $cols = array(
- 'Employee ID',
- 'Name',
- 'Job Title',
- 'Department',
- 'Business Unit',
- 'Date Of Joining',
- 'Work Anniversary Date',
- );
- $roster_type = "Work Anniversary Report";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getAgeReport($post_data, $tenant_id = null, $from, $to) {
- $return = array();
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- foreach ($users as $key => $user) {
- if(isset($user->personal->dob->sec) && $user->personal->dob->sec != ""){
- $age_total = self::calculate_experience(time(), $user->personal->dob->sec);
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $dob = date('d F Y, l', $user->personal->dob->sec);
- $age = $age_total['Years']." y ".$age_total['Months']." m ".$age_total['Days']." d";
- $output[] = array(
- $employee_number,
- $user_name,
- $job_title,
- $department,
- $business_unit,
- $dob,
- $age,
- );
- }
- } // EOF foreach user
- $cols = array(
- 'Name',
- 'Job Title',
- 'Department',
- 'Business Unit',
- 'Date Of Birth',
- 'Age',
- );
- $roster_type = "Age Report";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getHiringReport($post_data, $tenant_id = null, $from, $to) {
- $return = array();
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- foreach ($users as $key => $user) {
- if(isset($user->doj->sec) && $user->doj->sec != "")
- {
- $todaysDate = date('Y-m-d',$user->doj->sec);
- //$todaysDate=date('Y-m-d', strtotime($todaysDate));
- $openDateBegin = date('Y-m-d', strtotime($from));
- $openDateEnd = date('Y-m-d', strtotime($to));
- if (($todaysDate >= $openDateBegin) && ($todaysDate <= $openDateEnd))
- {
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $date_of_joining = date('d F Y, l',$user->doj->sec);
- $output[] = array(
- $employee_number,
- $user_name,
- $job_title,
- $department,
- $business_unit,
- $date_of_joining,
- );
- }
- }
- } // EOF foreach user
- $cols = array(
- 'Employee ID',
- 'Name',
- 'Job Title',
- 'Department',
- 'Business Unit',
- 'Hire Date',
- );
- $roster_type = "Hiring Report";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getTenureReport($post_data, $tenant_id = null) {
- $return = array();
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- foreach ($users as $key => $user) {
- if(isset($user->doj->sec) && $user->doj->sec != ""){
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $diff_cur_work = self::calculate_experience(time(), $user->doj->sec);
- $total_cur_y = $diff_cur_work['Years'];
- $total_cur_m = $diff_cur_work['Months'];
- $cur_work_ex = $total_cur_y . "y " . $total_cur_m . "m";
- $output[] = array(
- $employee_number,
- $user_name,
- $job_title,
- $department,
- $business_unit,
- $cur_work_ex,
- );
- }
- } // EOF foreach
- $cols = array(
- 'Employee ID',
- 'Name',
- 'Job Title',
- 'Department',
- 'Business Unit',
- 'Tenure',
- );
- $roster_type = "Tenure Report";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getPastWorkExp($post_data, $tenant_id = null) {
- $return = array();
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- foreach ($users as $key => $user) {
- $total_past_y = 0;
- $total_past_m = 0;
- $total_cur_y = 0;
- $total_cur_m = 0;
- $total_ex_m = 0;
- $total_ex_y = 0;
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $before_company = "";
- if (isset($user['past_work']) && !empty($user['past_work'])) {
- foreach ($user['past_work'] as $key => $work) {
- $diff_work = self::calculate_experience($work['to_date']->sec, $work['from_date']->sec);
- $total_past_y += intval($diff_work['Years']);
- $total_past_m += intval($diff_work['Months']);
- $company_name = (isset($work->company) && $work->company != "") ? ucfirst($work->company)." - " : "N.A.";
- $exp_company = $diff_work['Years'] . "y " . $diff_work['Months'] . "m";
- if(isset($company_name) && $company_name != "N.A."){
- $before_company = (isset($before_company) && $before_company != "") ? $before_company . "<br/>". $company_name ." ". $exp_company : $company_name . $exp_company;
- }
- }
- if ($total_past_m > 12) {
- $total_past_y += intval($total_past_m / 12);
- $total_past_m = $total_past_m % 12;
- }
- $past_work_ex = $total_past_y . "y " . $total_past_m . "m";
- } else {
- $past_work_ex = "";
- }
- $output[] = array(
- $employee_number,
- $user_name,
- $job_title,
- $department,
- $business_unit,
- $before_company,
- $past_work_ex,
- );
- } // EOF foreach
- $cols = array(
- 'Employee ID',
- 'Name',
- 'Job Title',
- 'Department',
- 'Business Unit',
- 'Comapany Name and Experience',
- 'Total Past Experience',
- );
- $roster_type = "Past Work Experience";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getDependentDetails($post_data, $tenant_id = null) {
- $return = array();
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- foreach ($users as $key => $user) {
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $user_dependent = "";
- if (isset($user['dependents']) && !empty($user['dependents'])) {
- foreach ($user['dependents'] as $key => $dependents) {
- $dep_name = (isset($dependents['first_name'],$dependents['last_name'])) ? ucfirst($dependents['first_name'])." ".$dependents['last_name'] ." - " : "N.A.";
- $dep_relation = (isset($dependents['relation_type'])) ? $dependents['relation_type'] ." - " : "N.A.";
- $get_dep_age = (isset($dependents['dob']->sec)) ? self::calculate_experience(time(), $dependents['dob']->sec) : "N.A.";
- $age_dep = (isset($get_dep_age) && $get_dep_age != "N.A.") ? $get_dep_age['Years']."y ".$get_dep_age['Months']."m" : "N.A.";
- if(isset($dep_name) && $dep_name != "N.A."){
- $user_dependent = (isset($user_dependent) && $user_dependent != "") ? $user_dependent . "<br/>". $dep_name ." ". $dep_relation ." ". $age_dep : $dep_name ." ". $dep_relation ." ". $age_dep;
- }
- }
- } else {
- $user_dependent = "N.A.";
- }
- $output[] = array(
- $employee_number,
- $user_name,
- $job_title,
- $department,
- $business_unit,
- $user_dependent,
- );
- } // EOF foreach
- $cols = array(
- 'Employee ID',
- 'Name',
- 'Job Title',
- 'Department',
- 'Business Unit',
- 'Dependent Detail',
- );
- $roster_type = "Dependent-Data";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getProfileCompletionReport($post_data, $tenant_id = null) {
- $return = array();
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- foreach ($users as $key => $user) {
- if(isset($user->doj->sec) && $user->doj->sec != ""){
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- list ($measures, $unfilled) = $user->getCompletionCount();
- $profile_percent = round(100 - (count($unfilled) / count($measures)) * 100) . "%";
- $output[] = array(
- $employee_number,
- $user_name,
- $job_title,
- $department,
- $business_unit,
- $profile_percent,
- );
- }
- } // EOF foreach
- $cols = array(
- 'Employee ID',
- 'Name',
- 'Job Title',
- 'Department',
- 'Business Unit',
- 'Profile Completion %',
- );
- $roster_type = "Profile-Completion-Data";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getReimbBankSheet($post_data, $tenant_id, $from, $to, $type, $name) {
- $output = array();
- $tenant = Tenants::model()->findByPk($tenant_id);
- $subdomain = (isset($tenant->tenant_subdomain) && $tenant->tenant_subdomain != "") ? $tenant->tenant_subdomain : "darwinbox";
- $filter = $post_data['filter_id'];
- $users_all = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- foreach ($users_all as $key_user => $value_user) {
- $users_array[] = $value_user->id;
- }
- $from_date = new MongoDate(strtotime($from));
- $to_date = new MongoDate(strtotime($to));
- if ($type == UserExpenses::STATUS_COMPENSATED) {
- $criteria = new EMongoCriteria();
- $criteria->status('==', UserExpenses::STATUS_APPROVED);
- $criteria->paid('==', UserExpenses::PAID_YES);
- $criteria->tenant_id('==', $tenant_id);
- $criteria->date('<=', $to_date);
- $criteria->date('>=', $from_date);
- $user_expenses = UserExpenses::model()->findAll($criteria);
- } else {
- $criteria = new EMongoCriteria();
- $criteria->status('==', $type);
- $criteria->paid('==', UserExpenses::PAID_NO);
- $criteria->tenant_id('==', $tenant_id);
- $criteria->date('<=', $to_date);
- $criteria->date('>=', $from_date);
- $user_expenses = UserExpenses::model()->findAll($criteria);
- }
- if (isset($user_expenses) && !empty($user_expenses)) {
- foreach ($user_expenses as $key_reimbursment => $value_reimbursment) {
- if (in_array($value_reimbursment->user_id, $users_array)) {
- $user_mongo_each = UserMongo::model()->tenant($tenant_id)->findByPk($value_reimbursment->user_id);
- $user_post = $user_mongo_each->getCurrentPosition($tenant_id);
- $job_title = (isset($user_post['designation'])) ? $user_post['designation'] : "N.A.";
- $department = (isset($user_post['department'])) ? $user_post['department'] : "N.A.";
- $business_unit = (isset($user_post['business_unit'])) ? $user_post['business_unit'] : "N.A.";
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $full_name = $user_mongo_each->getFullname();
- $title = (isset($value_reimbursment->title)) ? $value_reimbursment->title : "N.A.";
- $date = (isset($value_reimbursment->date->sec)) ? date('d F Y', $value_reimbursment->date->sec) : "N.A.";
- $item_total = 0;
- $item_name_price = '';
- foreach ($value_reimbursment->items as $key_items => $value_items) {
- $item_name = $value_items['itemName'];
- $item_price = $value_items['itemPrice'];
- $item_name_price = (empty($item_name_price)) ? $item_name . " (" . $item_price . ")" : $item_name_price . ", " . $item_name . " (" . $item_price . ")";
- $item_total += $item_price;
- }
- if (isset($value_reimbursment->paid_by) && $value_reimbursment->paid_by != "") {
- $performed_by = UserMongo::getFullnameById($value_reimbursment->paid_by);
- } else if (isset($value_reimbursment->approved_or_rejected_by) && $value_reimbursment->approved_or_rejected_by != "") {
- $performed_by = UserMongo::getFullnameById($value_reimbursment->approved_or_rejected_by);
- } else {
- $performed_by = "N.A.";
- }
- $link_created = "https://" . $subdomain . ".darwinbox.in/expenses/expenses/view/id/" . $value_reimbursment->id;
- $link = '<a target = "_blank" href = '.$link_created.'>'.$link_created.' </a>';
- // bank details
- 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 != "") {
- $account_number = $user_mongo_each->banking->bank_account;
- $account_bank_name = $user_mongo_each->banking->bank_name;
- $account_ifsc = $user_mongo_each->banking->bank_ifsc;
- $account_bank_branch = $user_mongo_each->banking->bank_branch;
- $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.";
- } else {
- $account_number = "N.A.";
- $account_bank_name = "N.A.";
- $account_ifsc = "N.A.";
- $account_bank_branch = "N.A.";
- $pan_number = "N.A.";
- }
- $output[] = array(
- $employee_number,
- $full_name,
- $department,
- $job_title,
- $title,
- $date,
- $account_bank_name,
- $account_bank_branch,
- $account_number,
- $account_ifsc,
- $pan_number,
- $item_total,
- );
- }
- }
- }
- $cols = array(
- 'Employee ID',
- 'Employee Name',
- 'Department',
- 'Designation',
- 'Reimb Title',
- 'Date',
- 'Bank Name',
- 'Branch Name',
- 'Account Number',
- 'Account IFSC',
- 'PAN Number',
- 'Total Amount',
- );
- $roster_type = "Reimbursement-Bank-Sheet";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getPfReportMonthly($post_data, $tenant_id, $from, $to) {
- $for_date = date('Y-m', strtotime($from));
- $return = array();
- $output = array();
- $current_month = date("m");
- $filter = $post_data['filter_id'];
- $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
- $tenantProfile = TenantProfile::model()->tenant($tenant_id)->find();
- if(!empty($tenantProfile))
- {
- if(isset($tenantProfile->pf_edli) && $tenantProfile->pf_edli == TenantProfile::ACTIVE)
- {
- $edli_value = 6500;
- }
- else{
- if(strtotime($for_date) > strtotime('2014-10'))
- {
- $edli_value = 15000;
- }
- else{
- $edli_value = 6500;
- }
- }
- }
- foreach ($userSalarySlip as $salaryslip) {
- $employees_contribution = 0;
- $edli = 0;
- $employees_contribution_pf = 0;
- $total_pension = 0;
- $voluntary_pf = 0;
- $total_pf = 0;
- $administartive_amount = 0;
- $insurance_fund = 0;
- $inspection_charges = 0;
- $final_amount = 0;
- //$users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- if($post_data['active_inactive'] == 1)
- {
- $users = UserMongo::model()->tenant($tenant_id)->active()->findByPk($salaryslip->user_id);
- }
- else if($post_data['active_inactive'] == 2)
- {
- $users = UserMongo::model()->tenant($tenant_id)->disabled()->findByPk($salaryslip->user_id);
- }
- else
- {
- $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- }
- if (isset($users) && !empty($users)) {
- $full_name = $users->getFullname();
- $doj = (isset($users->doj->sec))? date('Y-m-d', $users->doj->sec) : 'N.A.';
- $dob = (isset($users->personal->dob->sec) && $users->personal->dob->sec != "") ? date('Y-m-d', $users->personal->dob->sec) : "N.A.";
- $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
- // Calculate Age from Date of Birth
- if($dob != '')
- {
- $from = new DateTime($dob);
- $to = new DateTime('today');
- $age = $from->diff($to)->y;
- }
- else
- {
- $age = 'N.A.';
- }
- // Get employee father name.
- $emp_father_name = '';
- if (isset($users->dependents) && count($users->dependents) > 0)
- {
- foreach ($users->dependents as $key => $value_dependent)
- {
- if ($value_dependent->relation_type == "Father")
- {
- $emp_father_first_name = (isset($value_dependent->first_name))? $value_dependent->first_name : '';
- $emp_father_last_name = (isset($value_dependent->last_name))? $value_dependent->last_name : '';
- $emp_father_name = $emp_father_first_name." ".$emp_father_last_name;
- }
- }
- }
- $emp_father_name = (isset($emp_father_name) && $emp_father_name != "") ? $emp_father_name : "N.A.";
- $office_location = TenantOffices::model()->tenant($tenant_id)->findByAttributes(array('id' => $users->personal->office_location));
- if (isset($office_location) && !empty($office_location) && isset($office_location->city) && $office_location->city != "") {
- $city_name = City::model()->findByPk($office_location->city);
- if (isset($city_name) && !empty($city_name)) {
- $office_location_name = $city_name->name;
- } else {
- $office_location_name = "N.A";
- }
- } else {
- $office_location_name = "N.A";
- }
- foreach ($salaryslip->items as $item) {
- if ($item->variable_name == "basic") {
- if(isset($tenantProfile->is_pf_restricted) && $tenantProfile->is_pf_restricted == TenantProfile::ACTIVE){
- $basic = $item->max_value_month;
- $basic = ($basic > 15000) ? 15000 : $basic;
- }else{
- $basic = $item->max_value_month;
- }
- }
- if ($item->variable_name == "provident_fund") {
- $employees_contribution = $item->max_value_month;
- $employee_pf = (12 * $basic) / 100;
- /*$epf = (float) (($employee_pf / 12) * 3.67);
- $eps = (float) (($employee_pf / 12) * 8.33);*/
- $epf = ($employees_contribution/12) * 3.67;
- $epf = PayrollHelper::roundingValues(Items::ROUND_TO_NEAREST_INTEGER,$epf);
- $eps = PayrollHelper::roundingValues(Items::ROUND_TO_NEAREST_INTEGER,($employees_contribution/12) * 8.33);
- $lop_edli = 0;
- if ($salaryslip->lop > 0) {
- $lop_edli = ($edli_value / $salaryslip->total_working_days) * $salaryslip->lop;
- } else {
- $lop_edli = ($edli_value / $salaryslip->total_working_days) * ($salaryslip->total_working_days - $salaryslip->effective_working_days);
- }
- // Show E. D. L. I. is equal to BASIC if basic < 6500 - KT 9th March 2015
- if($basic < $edli_value )
- {
- $edli = $basic;
- }
- else
- {
- $edli = ($edli_value - $lop_edli);
- }
- $total_pension = ($edli * 8.33) / 100;
- $employees_contribution_pf = ($employees_contribution - $total_pension);
- $voluntary_pf = 0;
- if(strtotime($for_date) >= strtotime('2015-01'))
- {
- $administartive_amount = ($basic * 0.85) / 100;
- }
- else{
- $administartive_amount = ($basic * 1.1) / 100;
- }
- $insurance_fund = ($edli * 0.5) / 100;
- $inspection_charges = ($edli * 0.01) / 100;
- $total_pf = $employees_contribution + $employees_contribution_pf + $total_pension + $voluntary_pf;
- $final_amount = $total_pf + $administartive_amount + $insurance_fund + $inspection_charges;
- }
- }
- $fpf = 0;
- $vpf = 0;
- $edli_charges = 0;
- $employee_total = $employees_contribution + $vpf;
- $employeers_total = $eps +$epf;
- if($employees_contribution > 0)
- {
- $pf_account_number = (isset($users->pf_number) && $users->pf_number != null) ? $users->pf_number : "N.A.";
- $output[] = array(
- $pf_account_number,
- $employee_code,
- $full_name,
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $basic),
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $employees_contribution),
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $vpf),
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $employee_total),
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $epf),
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $eps),
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $employeers_total),
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $administartive_amount),
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $edli),
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $insurance_fund),
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $inspection_charges),
- );
- }
- }
- }
- $cols = array(
- 'Provident Fund Account No',
- 'Employee Code',
- 'Employee Name',
- 'PF Wages',
- 'Employees EPF',
- 'Employees VPF',
- 'Employees Total',
- 'Employeers EPF',
- 'Employeers EPS',
- 'Employeers Total',
- 'PF Admin Charges',
- 'EDLI Wages',
- 'EDLI Charges',
- 'EDLI Admin Charges',
- );
- $roster_type = "Statutory-PF-Monthly-month".$for_date;
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getPfFormSixA($post_data, $tenant_id, $from, $to) {
- $for_date = date('Y-m', strtotime($from));
- $return = array();
- $output = array();
- $current_month = date("m");
- $filter = $post_data['filter_id'];
- $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
- $tenantProfile = TenantProfile::model()->tenant($tenant_id)->find();
- if(!empty($tenantProfile))
- {
- if(isset($tenantProfile->pf_edli) && $tenantProfile->pf_edli == TenantProfile::ACTIVE)
- {
- $edli_value = 6500;
- }
- else{
- if(strtotime($for_date) > strtotime('2014-10'))
- {
- $edli_value = 15000;
- }
- else{
- $edli_value = 6500;
- }
- }
- }
- foreach ($userSalarySlip as $salaryslip) {
- $employees_contribution = 0;
- $edli = 0;
- $employees_contribution_pf = 0;
- $total_pension = 0;
- $voluntary_pf = 0;
- $total_pf = 0;
- $administartive_amount = 0;
- $insurance_fund = 0;
- $inspection_charges = 0;
- $final_amount = 0;
- //$users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- if($post_data['active_inactive'] == 1)
- {
- $users = UserMongo::model()->tenant($tenant_id)->active()->findByPk($salaryslip->user_id);
- }
- else if($post_data['active_inactive'] == 2)
- {
- $users = UserMongo::model()->tenant($tenant_id)->disabled()->findByPk($salaryslip->user_id);
- }
- else
- {
- $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- }
- if (isset($users) && !empty($users)) {
- $full_name = $users->getFullname();
- $doj = (isset($users->doj->sec))? date('Y-m-d', $users->doj->sec) : 'N.A.';
- $dob = (isset($users->personal->dob->sec) && $users->personal->dob->sec != "") ? date('Y-m-d', $users->personal->dob->sec) : "N.A.";
- $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
- // Calculate Age from Date of Birth
- if($dob != '')
- {
- $from = new DateTime($dob);
- $to = new DateTime('today');
- $age = $from->diff($to)->y;
- }
- else
- {
- $age = 'N.A.';
- }
- // Get employee father name.
- $emp_father_name = '';
- if (isset($users->dependents) && count($users->dependents) > 0)
- {
- foreach ($users->dependents as $key => $value_dependent)
- {
- if ($value_dependent->relation_type == "Father")
- {
- $emp_father_first_name = (isset($value_dependent->first_name))? $value_dependent->first_name : '';
- $emp_father_last_name = (isset($value_dependent->last_name))? $value_dependent->last_name : '';
- $emp_father_name = $emp_father_first_name." ".$emp_father_last_name;
- }
- }
- }
- $emp_father_name = (isset($emp_father_name) && $emp_father_name != "") ? $emp_father_name : "N.A.";
- $office_location = TenantOffices::model()->tenant($tenant_id)->findByAttributes(array('id' => $users->personal->office_location));
- if (isset($office_location) && !empty($office_location) && isset($office_location->city) && $office_location->city != "") {
- $city_name = City::model()->findByPk($office_location->city);
- if (isset($city_name) && !empty($city_name)) {
- $office_location_name = $city_name->name;
- } else {
- $office_location_name = "N.A";
- }
- } else {
- $office_location_name = "N.A";
- }
- foreach ($salaryslip->items as $item) {
- if ($item->variable_name == "basic") {
- $basic = $item->max_value_month;
- }
- if ($item->variable_name == "provident_fund") {
- $employees_contribution = $item->max_value_month;
- $employee_pf = (12 * $basic) / 100;
- /*$epf = (float) (($employee_pf / 12) * 3.67);
- $eps = (float) (($employee_pf / 12) * 8.33);*/
- $epf = ($employees_contribution/12) * 3.67;
- $eps = ($employees_contribution/12) * 8.33;
- $lop_edli = 0;
- if ($salaryslip->lop > 0) {
- $lop_edli = ($edli_value / $salaryslip->total_working_days) * $salaryslip->lop;
- } else {
- $lop_edli = ($edli_value / $salaryslip->total_working_days) * ($salaryslip->total_working_days - $salaryslip->effective_working_days);
- }
- // Show E. D. L. I. is equal to BASIC if basic < 6500 - KT 9th March 2015
- if($basic < $edli_value )
- {
- $edli = $basic;
- }
- else
- {
- $edli = ($edli_value - $lop_edli);
- }
- $total_pension = ($edli * 8.33) / 100;
- $employees_contribution_pf = ($employees_contribution - $total_pension);
- $voluntary_pf = 0;
- if(strtotime($for_date) >= strtotime('2015-01'))
- {
- $administartive_amount = ($basic * 0.85) / 100;
- }
- else{
- $administartive_amount = ($basic * 1.1) / 100;
- }
- $insurance_fund = ($edli * 0.5) / 100;
- $inspection_charges = ($edli * 0.01) / 100;
- $total_pf = $employees_contribution + $employees_contribution_pf + $total_pension + $voluntary_pf;
- $final_amount = $total_pf + $administartive_amount + $insurance_fund + $inspection_charges;
- }
- }
- $fpf = 0;
- $vpf = 0;
- $edli_charges = 0;
- $employee_total = $epf + $fpf + $vpf;
- $employeers_total = $eps +$epf;
- $refund_of_advance = 0;
- $rate_of_higher = 0;
- if($employees_contribution > 0)
- {
- $pf_account_number = (isset($users->pf_number) && $users->pf_number != null) ? $users->pf_number : "N.A.";
- $output[] = array(
- $pf_account_number,
- $employee_code,
- $full_name,
- $basic,
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $employees_contribution),
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $epf),
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $eps),
- $refund_of_advance,
- $rate_of_higher,
- );
- }
- }
- }
- $cols = array(
- 'Provident Fund Account No',
- 'Employee Code',
- 'Employee Name',
- 'Wages retaining allowance (if any ) and D.A. including cash value of food concession paid during the currency period',
- 'Workers Contribution',
- 'Employeers EPF',
- 'Employeers EPS',
- 'Refund of Advances',
- 'Rate of Higher voluntarily contribution if any',
- );
- $roster_type = "Statutory-PF-Form-6A".$for_date;
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getPfFormThreeA($post_data, $tenant_id, $from, $to) {
- $for_date = date('Y-m', strtotime($from));
- $return = array();
- $output = array();
- $current_month = date("m");
- $filter = $post_data['filter_id'];
- $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
- $tenantProfile = TenantProfile::model()->tenant($tenant_id)->find();
- $year_to_pass = date('Y') -1;
- $month_list = $tenantProfile->getMonthList('Y-m','M', $year_to_pass);
- if(!empty($tenantProfile))
- {
- if(isset($tenantProfile->pf_edli) && $tenantProfile->pf_edli == TenantProfile::ACTIVE)
- {
- $edli_value = 6500;
- }
- else{
- if(strtotime($for_date) > strtotime('2014-10'))
- {
- $edli_value = 15000;
- }
- else{
- $edli_value = 6500;
- }
- }
- }
- foreach ($month_list as $key => $value)
- {
- $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $key));
- $for_month = $key;
- $employees_contribution_total = 0.00;
- $epf_total = 0.00;
- $eps_total = 0.00;
- $pension_fund = 0.00;
- $basic = 0;
- if(isset($userSalarySlip) && !empty($userSalarySlip))
- {
- foreach ($userSalarySlip as $salaryslip) {
- $employees_contribution = 0;
- $edli = 0;
- $employees_contribution_pf = 0;
- $total_pension = 0;
- $voluntary_pf = 0;
- $total_pf = 0;
- $administartive_amount = 0;
- $insurance_fund = 0;
- $inspection_charges = 0;
- $final_amount = 0;
- //$users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- if($post_data['active_inactive'] == 1)
- {
- $users = UserMongo::model()->tenant($tenant_id)->active()->findByPk($salaryslip->user_id);
- }
- else if($post_data['active_inactive'] == 2)
- {
- $users = UserMongo::model()->tenant($tenant_id)->disabled()->findByPk($salaryslip->user_id);
- }
- else
- {
- $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- }
- if (isset($users) && !empty($users)) {
- $full_name = $users->getFullname();
- $doj = (isset($users->doj->sec))? date('Y-m-d', $users->doj->sec) : 'N.A.';
- $dob = (isset($users->personal->dob->sec) && $users->personal->dob->sec != "") ? date('Y-m-d', $users->personal->dob->sec) : "N.A.";
- $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
- // Calculate Age from Date of Birth
- if($dob != '')
- {
- $from = new DateTime($dob);
- $to = new DateTime('today');
- $age = $from->diff($to)->y;
- }
- else
- {
- $age = 'N.A.';
- }
- // Get employee father name.
- $emp_father_name = '';
- if (isset($users->dependents) && count($users->dependents) > 0)
- {
- foreach ($users->dependents as $key => $value_dependent)
- {
- if ($value_dependent->relation_type == "Father")
- {
- $emp_father_first_name = (isset($value_dependent->first_name))? $value_dependent->first_name : '';
- $emp_father_last_name = (isset($value_dependent->last_name))? $value_dependent->last_name : '';
- $emp_father_name = $emp_father_first_name." ".$emp_father_last_name;
- }
- }
- }
- $emp_father_name = (isset($emp_father_name) && $emp_father_name != "") ? $emp_father_name : "N.A.";
- $office_location = TenantOffices::model()->tenant($tenant_id)->findByAttributes(array('id' => $users->personal->office_location));
- if (isset($office_location) && !empty($office_location) && isset($office_location->city) && $office_location->city != "") {
- $city_name = City::model()->findByPk($office_location->city);
- if (isset($city_name) && !empty($city_name)) {
- $office_location_name = $city_name->name;
- } else {
- $office_location_name = "N.A";
- }
- } else {
- $office_location_name = "N.A";
- }
- foreach ($salaryslip->items as $item) {
- if ($item->variable_name == "basic") {
- $basic += $item->max_value_month;
- }
- if ($item->variable_name == "provident_fund") {
- $employees_contribution = $item->max_value_month;
- $employee_pf = (12 * $basic) / 100;
- /*$epf = (float) (($employee_pf / 12) * 3.67);
- $eps = (float) (($employee_pf / 12) * 8.33);*/
- $epf = ($employees_contribution/12) * 3.67;
- $eps = ($employees_contribution/12) * 8.33;
- $lop_edli = 0;
- if ($salaryslip->lop > 0) {
- $lop_edli = ($edli_value / $salaryslip->total_working_days) * $salaryslip->lop;
- } else {
- $lop_edli = ($edli_value / $salaryslip->total_working_days) * ($salaryslip->total_working_days - $salaryslip->effective_working_days);
- }
- if($basic < $edli_value )
- {
- $edli = $basic;
- }
- else
- {
- $edli = ($edli_value - $lop_edli);
- }
- $total_pension = ($edli * 8.33) / 100;
- $employees_contribution_pf = ($employees_contribution - $total_pension);
- $voluntary_pf = 0;
- if(strtotime($for_date) >= strtotime('2015-01'))
- {
- $administartive_amount = ($basic * 0.85) / 100;
- }
- else{
- $administartive_amount = ($basic * 1.1) / 100;
- }
- $insurance_fund = ($edli * 0.5) / 100;
- $inspection_charges = ($edli * 0.01) / 100;
- $total_pf = $employees_contribution + $employees_contribution_pf + $total_pension + $voluntary_pf;
- $final_amount = $total_pf + $administartive_amount + $insurance_fund + $inspection_charges;
- }
- }
- $fpf = 0;
- $vpf = 0;
- $edli_charges = 0;
- $employee_total = $epf + $fpf + $vpf;
- $employeers_total = $eps +$epf;
- $refund_of_advance = 0;
- $rate_of_higher = 0;
- if($employees_contribution > 0)
- {
- $employees_contribution_total += $employees_contribution;
- $epf_total += $epf;
- $eps_total += $eps;
- }
- }
- }
- }
- $pension_fund = ($epf_total > 0) ? "541.00" : "0.00";
- $output[] = array(
- date('M-Y',strtotime($for_month)),
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS,$basic),
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS,$employees_contribution_total),
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS,$epf_total),
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS,$eps_total),
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS,$pension_fund),
- "",
- 0.00,
- "",
- "",
- );
- }
- $cols = array(
- 'Month',
- 'Amount of Wages',
- 'Workers Share EPF.',
- 'Employeers E.P.F. difference between 12% & 8.1/3% (if any)',
- 'Employeers Pension Fund Contribution 8.1/3 %',
- 'Refund of Advances',
- 'No. of days / period of non contributing service (if any)',
- 'Date of Leaving Services (if any)',
- 'Reason for Leaving Services (if any)',
- );
- $roster_type = "Statutory-PF-Form-3A".$for_date;
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getAssests($post_data, $tenant_id = null) {
- $return = array();
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- foreach ($users as $key => $user) {
- $users_filtered[] = $user->id;
- }
- $assests = AssestManagement::model()->tenant()->findAll();
- foreach($assests as $key_ass => $value_ass)
- {
- $user_details = UserMongo::model()->tenant()->findByAttributes(array('id' => $value_ass->user));
- if(isset($user_details) && in_array($user_details->id, $users_filtered)){
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $user_name = $user_details['personal']['firstname'] . " " . $user_details['personal']['lastname'];
- $user_post = $user_details->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $asset_type = (isset($value_ass->asset_type) && $value_ass->asset_type != "") ? $value_ass->asset_type : "N.A.";
- $serial_number = (isset($value_ass->serial_number) && $value_ass->serial_number != "") ? $value_ass->serial_number : "N.A.";
- $model_number = (isset($value_ass->model_number) && $value_ass->model_number != "") ? $value_ass->model_number : "N.A.";
- $issue_date = (isset($value_ass->issue_date) && $value_ass->issue_date != "") ? date('d-m-Y',strtotime($value_ass->issue_date)) : "N.A.";
- $output[] = array(
- $employee_number,
- $user_name,
- $job_title,
- $department,
- $business_unit,
- $asset_type,
- $serial_number,
- $model_number,
- $issue_date,
- );
- }
- } // EOF foreach
- $cols = array(
- 'Employee ID',
- 'Name',
- 'Job Title',
- 'Department',
- 'Business Unit',
- 'Assest type',
- 'Serial number',
- 'Model number/Type',
- 'Issued date',
- );
- $filenameexport = "Asset Roster";
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function loadFiltersOthers() {
- $filters = array();
- $userMongo = UserMongo::model()->tenant()->findByAttributes(array('user_id' => Yii::app()->user->id));
- if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")) && Yii::app()->session['menu_owner'])
- {
- $filters['ALL'] = array('ALL_0' => 'All Employees');
- $filters['Designations'] = UserDepartments::getAllDepartmentsWithDesignationsNew();
- $filters['Departments'] = UserDepartments::getAllDepartments();
- $filters['Locations'] = TenantOffices::getTenantOfficeLocation();
- $filters['Employee Type'] = TenantUserTypes::getTenantTypes();
- }
- /* if(isset($userMongo) && !empty($userMongo))
- {*/
- elseif($userMongo->checkManager())
- {
- $filters['ALL'] = array('ALL_0' => 'All Reportees');
- $filters['Reportees'] = $userMongo->getManagedUsersForRosters();
- }
- // }
- // $filters['Shift'] = TenantShift::getTenantShiftArray();
- return $filters;
- }
- public static function getESICReport($post_data, $tenant_id, $from, $to)
- {
- $tenant_profile = TenantProfile::model()->tenant()->find();
- $cal_esic_on_gross = (isset($tenant_profile->cal_esic_on_gross))? $tenant_profile->cal_esic_on_gross : 0;
- $for_date = date('Y-m', strtotime($from));
- $return = array();
- $output = array();
- $employees_contribution = "N.A.";
- $employeers_contribution = "N.A.";
- $total = "N.A.";
- $total_no_days = "N.A.";
- $current_month = date("m");
- $filter = $post_data['filter_id'];
- $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
- foreach ($userSalarySlip as $salaryslip) {
- $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- // Getting user gross salary
- $gross_salary = $salaryslip->total_gross;
- $total_transactions = (isset($salaryslip->total_transactions))? $salaryslip->total_transactions : 0;
- $user_transaction_esic = UserTransaction::getTotalTransactionsOtEsic($salaryslip->user_id, $salaryslip->for_month, $salaryslip->tenant_id);
- // Minus Extra payment from gross salary if any
- if($total_transactions > 0){
- $gross_salary = $gross_salary - $total_transactions;
- $gross_salary = $gross_salary + $user_transaction_esic; //esic gross has only OT no other extra payments are affecting gross
- }
- if (isset($users) && !empty($users)) {
- $cal_esic = false;
- foreach ($salaryslip->items as $item) {
- /* if ($item->type == Items::ITEM_TYPE_INCOME) {
- $all_items_total += $item->max_value_month;
- } */
- if ($item->variable_name == "esic") {
- $cal_esic = true;
- $employees_contribution_sal = $item->max_value_month;
- }
- if ($item->variable_name == "basic") {
- $basic = $item->max_value_month;
- }
- if($item->variable_name == 'provident_fund')
- {
- $pf = $item->max_value_month;
- }
- }
- if ($cal_esic) {
- $all_items_total = 0;
- $full_name = $users->getFullname();
- $employee_id = $users->personal->employee_no;
- $doj = date('Y-m-d', $users->doj->sec);
- $employees_contribution = $employees_contribution_sal;
- $original_esic = $employees_contribution / 0.0175;
- $employeers_contribution = number_format($original_esic * 0.0475);
- $total = number_format($employees_contribution + $employeers_contribution);
- // Calculate "GROSS + PF (Employeer) + EMPLOYEERS ESIC"
- // If checkbox in Payroll setting is checked for "Calculate ESIC on Gross"
- // if($cal_esic_on_gross == TenantProfile::ACTIVE)
- // {
- // $gross_salary = $gross_salary + $pf + $employeers_contribution;
- // }
- $esic_account_number = (isset($users->esic_number) && $users->esic_number != null) ? $users->esic_number : "N.A.";
- $total_no_days = (isset($salaryslip->effective_working_days)) ? $salaryslip->effective_working_days : "N.A.";
- $output[] = array(
- $employee_id,
- $esic_account_number,
- $full_name,
- $total_no_days,
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $gross_salary),
- "",
- "",
- );
- }
- }
- }
- $cols = array(
- 'Employee ID',
- 'IP Number(10Digits)',
- 'IP Name(Only alphabets and space)',
- 'No of Days for which wages paid/payable during the month',
- 'Total Monthly Wages',
- 'Reason Code for Zero workings days(numeric only; provide 0 for all other reasons- Click on the link for reference)',
- 'Last Working Day( Format DD/MM/YYYY or DD-MM-YYYY)',
- );
- $roster_type = "Payroll-ESIC-Report-month".$for_date;
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getEsicStatement($post_data, $tenant_id, $from, $to){
- $tenant_profile = TenantProfile::model()->tenant()->find();
- $cal_esic_on_gross = (isset($tenant_profile->cal_esic_on_gross))? $tenant_profile->cal_esic_on_gross : 0;
- $count_i = 1;
- $for_date = date('Y-m', strtotime($from));
- $return = array();
- $output = array();
- $employees_contribution = "N.A.";
- $employeers_contribution = "N.A.";
- $total = "N.A.";
- $total_no_days = "N.A.";
- $current_month = date("m");
- $filter = $post_data['filter_id'];
- $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
- foreach ($userSalarySlip as $salaryslip) {
- //$users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- // if($post_data['active_inactive'] == 1){
- // $users = UserMongo::model()->tenant($tenant_id)->active()->findByPk($salaryslip->user_id);
- // }
- // else if($post_data['active_inactive'] == 2){
- // $users = UserMongo::model()->tenant($tenant_id)->disabled()->findByPk($salaryslip->user_id);
- // }
- // else{
- $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- //}
- // Getting user gross salary
- $gross_salary = $salaryslip->total_gross;
- $total_transactions = (isset($salaryslip->total_transactions))? $salaryslip->total_transactions : 0;
- $user_transaction_esic = UserTransaction::getTotalTransactionsOtEsic($salaryslip->user_id, $salaryslip->for_month, $salaryslip->tenant_id);
- // Minus Extra payment from gross salary if any
- if($total_transactions > 0){
- $gross_salary = $gross_salary - $total_transactions;
- $gross_salary = $gross_salary + $user_transaction_esic; //esic gross has only OT no other extra payments are affecting gross
- }
- if (isset($users) && !empty($users)) {
- $cal_esic = false;
- foreach ($salaryslip->items as $item) {
- /* if ($item->type == Items::ITEM_TYPE_INCOME) {
- $all_items_total += $item->max_value_month;
- } */
- if ($item->variable_name == "esic") {
- $cal_esic = true;
- $employees_contribution_sal = $item->max_value_month;
- }
- if ($item->variable_name == "basic") {
- $basic = $item->max_value_month;
- }
- if($item->variable_name == 'provident_fund')
- {
- $pf = $item->max_value_month;
- }
- }
- if ($cal_esic) {
- $all_items_total = 0;
- $full_name = $users->getFullname();
- $doj = date('Y-m-d', $users->doj->sec);
- $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
- $employees_contribution = $employees_contribution_sal;
- $original_esic = $employees_contribution / 0.0175;
- $employeers_contribution = number_format($original_esic * 0.0475);
- $total = number_format($employees_contribution + $employeers_contribution);
- // Calculate "GROSS + PF (Employeer) + EMPLOYEERS ESIC"
- // If checkbox in Payroll setting is checked for "Calculate ESIC on Gross"
- //if($cal_esic_on_gross == TenantProfile::ACTIVE){
- //$gross_salary = $gross_salary + $pf + $employeers_contribution;
- //}
- $esic_account_number = (isset($users->esic_number) && $users->esic_number != null) ? $users->esic_number : "N.A.";
- $total_no_days = (isset($salaryslip->effective_working_days)) ? $salaryslip->effective_working_days : "N.A.";
- $output[] = array(
- $count_i,
- $employee_code,
- $esic_account_number,
- $full_name,
- $total_no_days,
- PayrollHelper::roundingValues(Items::ROUND_TO_NEAREST_INTEGER, $gross_salary),
- PayrollHelper::roundingValues(Items::ROUND_TO_HIGEST_INTEGER, $employees_contribution),
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $employeers_contribution),
- );
- $count_i++;
- }
- }
- }
- $cols = array(
- 'SI No',
- 'Employee No',
- 'Insurance No',
- 'Name Of Insured Person',
- 'Days Worked',
- 'ESI Gross',
- 'Employees Contribution',
- 'Employeers Contribution',
- );
- $roster_type = "Payroll-ESIC-Report-month".$for_date;
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function getPFReportMonthNew($post_data, $tenant_id, $from, $to) {
- $for_date = date('Y-m', strtotime($from));
- $return = array();
- $output = array();
- $current_month = date("m");
- $filter = $post_data['filter_id'];
- $userSalarySlip = UserSalarySlip::model()->tenant($tenant_id)->findAllByAttributes(array('for_month' => $for_date));
- $tenantProfile = TenantProfile::model()->tenant($tenant_id)->find();
- if(!empty($tenantProfile))
- {
- if(isset($tenantProfile->pf_edli) && $tenantProfile->pf_edli == TenantProfile::ACTIVE){
- $edli_value = 6500;
- }
- else{
- if(strtotime($for_date) > strtotime('2014-10')){
- $edli_value = 15000;
- }
- else{
- $edli_value = 6500;
- }
- }
- }
- foreach ($userSalarySlip as $salaryslip) {
- $employees_contribution = 0;
- $edli = 0;
- $employees_contribution_pf = 0;
- $total_pension = 0;
- $voluntary_pf = 0;
- $total_pf = 0;
- $administartive_amount = 0;
- $insurance_fund = 0;
- $inspection_charges = 0;
- $final_amount = 0;
- $basic_eps = 0;
- $accountnooneepf = 0;
- $accountnotenepf = 0;
- $accountnotwo = 0;
- $accountnotwentyone = 0;
- $accountnotwentytwo = 0;
- //$users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- if(isset($post_data['active_inactive']) && $post_data['active_inactive'] == 1)
- {
- $users = UserMongo::model()->tenant($tenant_id)->active()->findByPk($salaryslip->user_id);
- }
- else if(isset($post_data['active_inactive']) && $post_data['active_inactive'] == 2)
- {
- $users = UserMongo::model()->tenant($tenant_id)->disabled()->findByPk($salaryslip->user_id);
- }
- else
- {
- $users = UserMongo::model()->tenant($tenant_id)->findByPk($salaryslip->user_id);
- }
- if (isset($users) && !empty($users)) {
- $full_name = $users->getFullname();
- $doj = (isset($users->doj->sec))? date('d/m/Y', $users->doj->sec) : 'N.A.';
- $date_of_exit = (isset($users->deactivate_date->sec))? date('d/m/Y', $users->deactivate_date->sec) : 'N.A.';
- $date_of_exit_month = (isset($users->deactivate_date->sec))? date('Y-m', $users->deactivate_date->sec) : 'N.A.';
- $dob = (isset($users->personal->dob->sec) && $users->personal->dob->sec != "") ? date('d/m/Y', $users->personal->dob->sec) : "N.A.";
- $doj = (isset($users->doj->sec) && $users->doj->sec != "") ? date('d/m/Y', $users->doj->sec) : "N.A.";
- $doj_month = (isset($users->doj->sec) && $users->doj->sec != "") ? date('Y-m', $users->doj->sec) : "N.A.";
- $employee_code = (isset($users->personal->employee_no) && $users->personal->employee_no != "") ? $users->personal->employee_no : "N.A.";
- $gender = (isset($users->personal->gender) && $users->personal->gender == UserPersonal::GENDER_MALE) ? "M" : "F";
- // Calculate Age from Date of Birth
- // if($dob != '')
- // {
- // $from = new DateTime($dob);
- // $to = new DateTime('today');
- // $age = $from->diff($to)->y;
- // }
- // else
- // {
- // $age = 'N.A.';
- // }
- // Get employee father name.
- $emp_father_name = '';
- $emp_husband_name = '';
- $display_realation_name = '';
- if (isset($users->dependents) && count($users->dependents) > 0)
- {
- foreach ($users->dependents as $key => $value_dependent)
- {
- if ($value_dependent->relation_type == "Father")
- {
- $emp_father_first_name = (isset($value_dependent->first_name))? $value_dependent->first_name : '';
- $emp_father_last_name = (isset($value_dependent->last_name))? $value_dependent->last_name : '';
- $emp_father_name = $emp_father_first_name." ".$emp_father_last_name;
- }
- if ($value_dependent->relation_type == "Husband")
- {
- $emp_husband_first_name = (isset($value_dependent->first_name))? $value_dependent->first_name : '';
- $emp_husband_last_name = (isset($value_dependent->last_name))? $value_dependent->last_name : '';
- $emp_husband_name = $emp_father_first_name." ".$emp_father_last_name;
- }
- }
- }
- if(isset($emp_husband_name) && $emp_husband_name != ""){
- $display_realation_name = (isset($emp_husband_name) && $emp_husband_name != "") ? $emp_husband_name : "N.A.";
- $relation_type = 'S';
- }else{
- $display_realation_name = (isset($emp_father_name) && $emp_father_name != "") ? $emp_father_name : "N.A.";
- $relation_type = (isset($emp_father_name) && $emp_father_name != "") ? 'F' : "N.A.";
- }
- $office_location = TenantOffices::model()->tenant($tenant_id)->findByAttributes(array('id' => $users->personal->office_location));
- if (isset($office_location) && !empty($office_location) && isset($office_location->city) && $office_location->city != "") {
- $city_name = City::model()->findByPk($office_location->city);
- if (isset($city_name) && !empty($city_name)) {
- $office_location_name = $city_name->name;
- } else {
- $office_location_name = "N.A";
- }
- } else {
- $office_location_name = "N.A";
- }
- foreach ($salaryslip->items as $item) {
- if ($item->variable_name == "basic") {
- if(isset($tenantProfile->is_pf_restricted) && $tenantProfile->is_pf_restricted == TenantProfile::ACTIVE){
- $basic = $item->max_value_month;
- $basic = ($basic > 15000) ? 15000 : $basic;
- }else{
- $basic = $item->max_value_month;
- }
- }
- if ($item->variable_name == "provident_fund") {
- // basic basic_eps 3 conditions
- // if age is greater than 58 years then 0 else basic
- // if not existing PF member and basic > 15000 then basic_eps = 0
- // if basic > 15000 then basic_eps = 15000 as max limit is 15000
- $age = RandomHelper::CalculateAge(date('Y-m-d',$users->personal->dob->sec));
- $basic_eps = $basic;
- if($age > 58){
- $basic_eps = 0;
- }
- if(isset($user->existing_pf_member) && $user->existing_pf_member == 0 && $basic > 15000){
- $basic_eps = 0;
- }
- if($basic > 15000){
- $basic_eps = 15000;
- }
- // basic basic_eps 3 conditions
- $employees_contribution = $item->max_value_month;
- $eps_contribution = ($basic_eps > 0) ? ($basic_eps * 8.33)/100 : 0;
- $eps_contribution = PayrollHelper::roundingValues(Items::ROUND_TO_HIGEST_INTEGER,$eps_contribution);
- $diff_epf_eps = $employees_contribution - $eps_contribution;
- $lop_days = $salaryslip->lop;
- $arrear_basic = 0; //differnece of basic after salary increment
- $arrears_epf_wages = 0;
- $arrears_epf_ee_wages = 0;
- $arrears_epf_er_wages = 0;
- $arrears_eps = 0;
- if(strtotime($for_date) != strtotime($doj_month)){
- $display_realation_name = "";
- $relation_type = "";
- $dob = "";
- $gender = "";
- $doj = "";
- }
- if(isset($date_of_exit) && strtotime($for_date) == strtotime($date_of_exit_month)){
- $reason_of_exit = "C";
- }else{
- $date_of_exit = "";
- $reason_of_exit = "";
- }
- // $employee_pf = (12 * $basic) / 100;
- // $epf = ($employees_contribution/12) * 3.67;
- // $eps = ($employees_contribution/12) * 8.33;
- $lop_edli = 0;
- if ($salaryslip->lop > 0) {
- $lop_edli = ($edli_value / $salaryslip->total_working_days) * $salaryslip->lop;
- } else {
- $lop_edli = ($edli_value / $salaryslip->total_working_days) * ($salaryslip->total_working_days - $salaryslip->effective_working_days);
- }
- // Show E. D. L. I. is equal to BASIC if basic < 6500 - KT 9th March 2015
- if($basic < $edli_value){
- $edli = $basic;
- }
- else{
- $edli = ($edli_value - $lop_edli);
- }
- // $total_pension = ($edli * 8.33) / 100;
- // $employees_contribution_pf = ($employees_contribution - $total_pension);
- // $voluntary_pf = 0;
- // if(strtotime($for_date) >= strtotime('2015-01'))
- // {
- // $administartive_amount = ($basic * 0.85) / 100;
- // }
- // else{
- // $administartive_amount = ($basic * 1.1) / 100;
- // }
- // $insurance_fund = ($edli * 0.5) / 100;
- // $inspection_charges = ($edli * 0.01) / 100;
- // $total_pf = $employees_contribution + $employees_contribution_pf + $total_pension + $voluntary_pf;
- // $final_amount = $total_pf + $administartive_amount + $insurance_fund + $inspection_charges;
- }
- }
- // Do not show the row if $employees_contribution is ZERO
- if($employees_contribution > 0)
- {
- // Account no1 EPF(employee total pf + employeers diff btw epf and eps)
- $accountnooneepf += ($employees_contribution + $diff_epf_eps);
- // Account no1 EPF(employee total pf + employeers diff btw epf and eps)
- //Account number 10 = sum of all emp EPS
- $accountnotenepf += $eps_contribution;
- //Account number 10 = sum of all emp EPS
- //Account number 2 = PF admin charges
- $accountnotwo += ($basic * 0.85) / 100;
- //Account number 2 = PF admin charges
- //Account number 21 = 0.5% on edli wages
- $accountnotwentyone += ($edli * 0.5) / 100;
- //Account number 21 = 0.5% on edli wages
- //Account number 22 = 0.01% on edli wages
- $accountnotwentytwo += ($edli * 0.01) / 100;
- //Account number 22 = 0.01% on edli wages
- $pf_account_number = (isset($users->pf_number) && $users->pf_number != null) ? $users->pf_number : "N.A.";
- $employee_code_pf_exp = explode('/', $pf_account_number);
- $employee_code_pf = (isset($employee_code_pf_exp[4]) && $employee_code_pf_exp[4] != "") ? $employee_code_pf_exp[4] : "";
- $total_pension = ($edli * 8.33) / 100;
- $employees_contribution_pf = ($employees_contribution - $total_pension);
- $voluntary_pf = 0;
- if(strtotime($for_date) >= strtotime('2015-01'))
- {
- $administartive_amount = ($basic * 0.85) / 100;
- }
- else{
- $administartive_amount = ($basic * 1.1) / 100;
- }
- $insurance_fund = ($edli * 0.5) / 100;
- $inspection_charges = ($edli * 0.01) / 100;
- $total_pf = $employees_contribution + $employees_contribution_pf + $total_pension + $voluntary_pf;
- $final_amount = $total_pf + $administartive_amount + $insurance_fund + $inspection_charges;
- $output[] = array(
- $employee_code_pf,
- $full_name,
- $basic,
- $basic_eps,
- $employees_contribution,
- $eps_contribution,
- $diff_epf_eps,
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $edli),
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $administartive_amount),
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $insurance_fund),
- PayrollHelper::roundingValues(Items::ROUND_TO_TWO_DIGITS, $inspection_charges),
- );
- }
- }
- }
- $cols = array(
- 'Employee Code',
- 'Employee Name',
- 'EPF Wages', //that month earned basic
- 'EPS Wages', // basic amount 3 conditions
- 'EPF Contribution (EE Share)',
- 'EPS Contribution due',
- 'Diff EPF and EPS contribution (ER share)',
- 'EDLI Wages',
- 'PF Admin Charges',
- 'EDLI Charges',
- 'EDLI Admin Charges',
- );
- $roster_type = "payroll-PF-Report-month".$for_date;
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function flexiPayroll($post_data, $tenant_id = null,$from,$to,$status) {
- $return = array();
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- $user_array = array();
- foreach ($users as $key => $user) {
- $user_array[] = $user->user_id;
- }
- $final_cycle_start = new MongoDate(strtotime($from));
- $final_cycle_end = new MongoDate(strtotime($to));
- $criteria = new EMongoCriteria();
- $criteria->updated_on('>=', $final_cycle_start);
- $criteria->updated_on('<=', $final_cycle_end);
- $criteria->status('==', $status);
- $criteria->income_flexi('==', OtherClaims::FLEXI);
- $criteria->tenant_id('==', Yii::app()->user->getTenantId());
- $claims = OtherClaims::model()->findAll($criteria);
- if(isset($claims) && !empty($claims)){
- foreach ($claims as $key_claims => $value_claims) {
- if(in_array($value_claims->user_id, $user_array)){
- $user = $users[$value_claims->user_id];
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $employee_number = $user['personal']['employee_no'];
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $output[] = array(
- $employee_number,
- $user_name,
- $job_title,
- $department,
- $business_unit,
- str_replace("_", " ",$value_claims->type),
- $value_claims->bill_amount,
- date('d-m-Y',$value_claims->created->sec),
- date('d-m-Y',$value_claims->updated_on->sec),
- );
- }
- } // EOF foreach
- }
- $cols = array(
- 'Employee ID',
- 'Name',
- 'Job Title',
- 'Department',
- 'Business Unit',
- 'Flexi Component',
- 'Bill Amount',
- 'Claim Date',
- 'Approved Date',
- );
- $roster_type = "Experience Report";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function pulsereports($post_data, $tenant_id = null,$from,$to) {
- if(Yii::app()->cache->executeCommand("hget", array(Yii::app()->user->getTenantId().":".Yii::app()->user->id,"Owner")) && Yii::app()->session['menu_owner']) {
- $return = array();
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- $user_array = array();
- foreach ($users as $key => $user) {
- $user_array[] = $user->id;
- }
- $from_start = new MongoDate(strtotime($from));
- $to_end = new MongoDate(strtotime($to));
- $criteria = new EMongoCriteria();
- $criteria->created('>=', $from_start);
- $criteria->created('<=', $to_end);
- $criteria->tenant_id('==', Yii::app()->user->getTenantId());
- $pulse = PulsePosts::model()->findAll($criteria);
- if(isset($pulse) && !empty($pulse)){
- foreach ($pulse as $key_pulse => $value_pulse) {
- if(in_array($value_pulse->user_id, $user_array)){
- if(isset($value_pulse->is_anonymous) && $value_pulse->is_anonymous == PulsePosts::SHOW){
- $user = UserMongo::model()->tenant()->findByPk($value_pulse->user_id);
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $employee_number = $user['personal']['employee_no'];
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- }else{
- $employee_number = "Anonymous";
- $user_name = "Anonymous";
- $job_title = "Anonymous";
- $department = "Anonymous";
- $business_unit = "Anonymous";
- }
- $output[] = array(
- $employee_number,
- $user_name,
- $job_title,
- $department,
- $business_unit,
- $value_pulse->pulse_smile,
- $value_pulse->reason,
- date('d-m-Y',$value_pulse->created->sec),
- );
- }
- } // EOF foreach
- }
- $cols = array(
- 'Employee ID',
- 'Name',
- 'Job Title',
- 'Department',
- 'Business Unit',
- 'Pulse',
- 'Comment',
- 'Post Date',
- );
- $roster_type = "Pulse Report";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- }
- public static function DepartmentStructure($post_data, $tenant_id = null, $user_id = null) {
- $return = array();
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- $l4_true = $l5_true = $l6_true = $l7_true = $l8_true = $l9_true = false;
- $index = 0;
- foreach ($users as $key => $user) {
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $location = TenantOffices::getTenantOfficeLocationsNameWithCountryById($user->personal->office_location,$user->tenant_id);
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $department_id = $user_post['department_id'];
- $l1 = $l2 = $l3 = $l4 = $l5 = $l6 = $l7 = $l8 = $l9 = "";
- $dep_status = array();
- $department_details = UserDepartments::model()->tenant()->findByPk($department_id);
- if(isset($department_details->parent_department) && !empty($department_details->parent_department)){
- $l1_dept = UserDepartments::model()->tenant()->findByPk($department_details->parent_department);
- $l1 = $l1_dept->department_name;
- $dep_status[] = $l1_dept->department_name;
- if(isset($l1_dept->parent_department) && !empty($l1_dept->parent_department)){
- $l2_dept = UserDepartments::model()->tenant()->findByPk($l1_dept->parent_department);
- $l2 = $l2_dept->department_name;
- $dep_status[] = $l2_dept->department_name;
- if(isset($l2_dept->parent_department) && !empty($l2_dept->parent_department)){
- $l3_dept = UserDepartments::model()->tenant()->findByPk($l2_dept->parent_department);
- $l3 = $l3_dept->department_name;
- $dep_status[] = $l3_dept->department_name;
- if(isset($l3_dept->parent_department) && !empty($l3_dept->parent_department)){
- $l4_true = true;
- $l4_dept = UserDepartments::model()->tenant()->findByPk($l3_dept->parent_department);
- $l4 = $l4_dept->department_name;
- $dep_status[] = $l4_dept->department_name;
- if(isset($l4_dept->parent_department) && !empty($l4_dept->parent_department)){
- $l5_true = true;
- $l5_dept = UserDepartments::model()->tenant()->findByPk($l4_dept->parent_department);
- $l5 = $l5_dept->department_name;
- $dep_status[] = $l5_dept->department_name;
- if(isset($l5_dept->parent_department) && !empty($l5_dept->parent_department)){
- $l6_true = true;
- $l6_dept = UserDepartments::model()->tenant()->findByPk($l5_dept->parent_department);
- $l6 = $l6_dept->department_name;
- $dep_status[] = $l6_dept->department_name;
- if(isset($l6_dept->parent_department) && !empty($l6_dept->parent_department)){
- $l7_true = true;
- $l7_dept = UserDepartments::model()->tenant()->findByPk($l6_dept->parent_department);
- $l7 = $l7_dept->department_name;
- $dep_status[] = $l7_dept->department_name;
- if(isset($l7_dept->parent_department) && !empty($l7_dept->parent_department)){
- $l8_true = true;
- $l8_dept = UserDepartments::model()->tenant()->findByPk($l7_dept->parent_department);
- $l8 = $l8_dept->department_name;
- $dep_status[] = $l8_dept->department_name;
- if(isset($l8_dept->parent_department) && !empty($l8_dept->parent_department)){
- $l9_true = true;
- $l9_dept = UserDepartments::model()->tenant()->findByPk($l8_dept->parent_department);
- $l9 = $l9_dept->department_name;
- $dep_status[] = $l9_dept->department_name;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- $output[] = array(
- // $action_checkbox,
- $employee_number,
- $user_name,
- $job_title,
- $business_unit,
- $location,
- //$department,
- );
- $new=0;
- $dep_status = array_reverse($dep_status);
- if(isset($dep_status) && !empty($dep_status)){
- foreach ($dep_status as $key_each_dep => $value_each_dep) {
- array_push($output[$index], $value_each_dep);
- $new++;
- }
- }
- array_push($output[$index], $department);
- for ($p=($new+1); $p <= 9 ; $p++) {
- array_push($output[$index], "");
- }
- $index++;
- } // EOF foreach user
- $cols = array(
- 'Employee ID',
- 'Name',
- 'Job Title',
- 'Business Unit',
- 'Office Location',
- 'Level 1',
- 'Level 2',
- 'Level 3',
- );
- //if(isset($l4_true) && $l4_true) {
- array_push($cols, 'Level 4');
- //}
- //if(isset($l5_true) && $l5_true) {
- array_push($cols, 'Level 5');
- //}
- //if(isset($l6_true) && $l6_true) {
- array_push($cols, 'Level 6');
- //}
- //if(isset($l7_true) && $l7_true) {
- array_push($cols, 'Level 7');
- //}
- //if(isset($l8_true) && $l8_true) {
- array_push($cols, 'Level 8');
- //}
- //if(isset($l9_true) && $l9_true) {
- array_push($cols, 'Level 9');
- //}
- $roster_type = "Department-Level-Wise-Report";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- public static function ItDeclaration($post_data, $tenant_id = null, $user_id = null) {
- $return = array();
- $filter = $post_data['filter_id'];
- $users = UserMongo::model()->getUsersByFilter($filter, $tenant_id, $post_data['active_inactive']);
- $output = array();
- $header_array = array();
- $index = 0;
- $year = '2016';
- $get_format = UserItDeclaration::model()->tenant(Yii::app()->user->getTenantId())->find();
- foreach ($get_format->items as $key_each_item => $value_each_item) {
- $header_array[$value_each_item->label] = $value_each_item->label;
- }
- if(isset($header_array) && !empty($header_array)){
- foreach ($users as $key => $user) {
- $declaration_user= array();
- $declaration = UserItDeclaration::model()->tenant(Yii::app()->user->getTenantId())->user($user->id)->forYear($year)->find();
- if(isset($declaration) && !empty($declaration)){
- foreach ($declaration->items as $key_each_item_dec => $value_each_item_dec) {
- $declaration_user[$value_each_item_dec->label] = $value_each_item_dec->declared_value;
- }
- $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
- $employee_number = (isset($user['personal']['employee_no'])) ? $user['personal']['employee_no'] : "N.A.";
- $location = TenantOffices::getTenantOfficeLocationsNameWithCountryById($user->personal->office_location,$user->tenant_id);
- $user_post = $user->getCurrentPosition($tenant_id);
- $job_title = $user_post['designation'];
- $department = $user_post['department'];
- $business_unit = $user_post['business_unit'];
- $output[] = array(
- $employee_number,
- $user_name,
- $business_unit,
- $job_title,
- $department,
- $location,
- );
- if(isset($declaration_user) && !empty($declaration_user)){
- foreach ($declaration_user as $key_eu => $value_eu) {
- if($key_eu != "PF"){
- array_push($output[$index], $value_eu);
- }
- }
- }
- $index++;
- } // EOF foreach user
- }
- }
- $cols = array(
- 'Employee ID',
- 'Name',
- 'Business Unit',
- 'Job Title',
- 'Department',
- 'Office Location',
- );
- if(isset($header_array) && !empty($header_array)){
- foreach ($header_array as $key_head => $value_head) {
- if($value_head != "PF"){
- array_push($cols, $value_head);
- }
- }
- }
- $roster_type = "IT Declaration";
- $filenameexport = $roster_type;
- $final_output = array('output' => $output,
- 'cols' => $cols,
- 'filenameexport' => $filenameexport);
- return $final_output;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement