* */ public function day_statistics($branchid = '') { $this->load->model('excel_import_model'); $this->load->model('api_model'); $day = date('d'); $month = date('m'); $year = date('Y'); $monthid = $this->excel_import_model->select_monthid($month, $year); $users = $this->excel_import_model->select_users_condition($branchid); for ($i_users = 0 ; $i_users < count($users) ; $i_users++) { $total_hours = 0; $lack_of_hours = 0; $enough_of_hours = 0; $overtime = 0; $note = 0; $timekeeping = $this->api_model->select_timekeeping_of_day($branchid, $day, $monthid, $users[$i_users]['id']); for ($i_timekeeping = 0 ; $i_timekeeping < count($timekeeping) ; $i_timekeeping++) { if ($timekeeping[$i_timekeeping]['number_hours'] == $timekeeping[$i_timekeeping]['number_hours_ca']) { $enough_of_hours++; $total_hours += $timekeeping[$i_timekeeping]['number_hours']; } elseif ($timekeeping[$i_timekeeping]['number_hours'] < $timekeeping[$i_timekeeping]['number_hours_ca']) { $lack_of_hours++; $total_hours += $timekeeping[$i_timekeeping]['number_hours']; } else { $overtime++; $total_hours += $timekeeping[$i_timekeeping]['number_hours']; } if ($timekeeping[$i_timekeeping]['description'] != '') { $note = $note . '(' . 'Ngày' . $timekeeping[$i_timekeeping]['number_day'] . ': ' . $timekeeping[$i_timekeeping]['description'] . ') '; } } $array_lack_of_hours = array('lack_of_hours' => $lack_of_hours); $array_enough_of_hours = array('enough_of_hours' => $enough_of_hours); $array_overtime = array('overtime' => $overtime); $array_total_hours = array('total_hours' => $total_hours); $description = array('description' => $note); $real_work = array('real_work' => $total_hours / 8); $users[$i_users] = array_merge($users[$i_users], $array_lack_of_hours); $users[$i_users] = array_merge($users[$i_users], $array_enough_of_hours); $users[$i_users] = array_merge($users[$i_users], $array_overtime); $users[$i_users] = array_merge($users[$i_users], $array_total_hours); $users[$i_users] = array_merge($users[$i_users], $real_work); $users[$i_users] = array_merge($users[$i_users], $description); } //echo "
"; //print_r($users);die; echo json_encode($users); } /* * Thống kê số giờ theo tuần * Endpoint http://localhost/miwork-hrm-private/api/human_resource/weekly_statistics/branch/* */ public function weekly_statistics($branchid = '', $start_date = '', $end_date = '') { $this->load->model('excel_import_model'); $this->load->model('api_model'); $date = date('d-m-Y'); $month = date('m'); $year = date('Y'); $numberWeek = $this->getNumberWeekOfYear($date); $week_array = getStartAndEndDate($numberWeek, $year); if ($start_date == '' && $end_date == '') { $start_date = $week_array['start_date']; $end_date = $week_array['end_date']; } $monthid = $this->excel_import_model->select_monthid($month, $year); $users = $this->excel_import_model->select_users_condition($branchid); for ($i_users = 0 ; $i_users < count($users) ; $i_users++) { $total_hours = 0; $lack_of_hours = 0; $enough_of_hours = 0; $overtime = 0; $note = 0; $timekeeping = $this->api_model->select_timekeepingOfWeek($branchid, $start_date, $end_date, $monthid, $users[$i_users]['id']); for ($i_timekeeping = 0 ; $i_timekeeping < count($timekeeping) ; $i_timekeeping++) { if ($timekeeping[$i_timekeeping]['number_hours'] == $timekeeping[$i_timekeeping]['number_hours_ca']) { $enough_of_hours++; $total_hours += $timekeeping[$i_timekeeping]['number_hours']; } elseif ($timekeeping[$i_timekeeping]['number_hours'] < $timekeeping[$i_timekeeping]['number_hours_ca']) { $lack_of_hours++; $total_hours += $timekeeping[$i_timekeeping]['number_hours']; } else { $overtime++; $total_hours += $timekeeping[$i_timekeeping]['number_hours']; } if ($timekeeping[$i_timekeeping]['description'] != '') { $note = $note . '(' . 'Ngày' . $timekeeping[$i_timekeeping]['number_day'] . ': ' . $timekeeping[$i_timekeeping]['description'] . ') '; } } $array_lack_of_hours = array('lack_of_hours' => $lack_of_hours); $array_enough_of_hours = array('enough_of_hours' => $enough_of_hours); $array_overtime = array('overtime' => $overtime); $array_total_hours = array('total_hours' => $total_hours); $description = array('description' => $note); $real_work = array('real_work' => $total_hours / 8); $users[$i_users] = array_merge($users[$i_users], $array_lack_of_hours); $users[$i_users] = array_merge($users[$i_users], $array_enough_of_hours); $users[$i_users] = array_merge($users[$i_users], $array_overtime); $users[$i_users] = array_merge($users[$i_users], $array_total_hours); $users[$i_users] = array_merge($users[$i_users], $real_work); $users[$i_users] = array_merge($users[$i_users], $description); } echo " "; print_r($users); die; // echo json_encode($users); } /* * Thống kê số giờ theo tháng * Endpoint http://localhost/miwork-hrm-private/api/human_resource/monthly_statistics/branch/* */ public function monthly_statistics($branchid = '') { $this->load->model('api_model'); $this->load->model('excel_import_model'); $month = date('m'); $year = date('Y'); $monthid = $this->excel_import_model->select_monthid($month, $year); $users = $this->excel_import_model->select_users_condition($branchid); for ($i_users = 0 ; $i_users < count($users) ; $i_users++) { $total_hours = 0; $lack_of_hours = 0; $enough_of_hours = 0; $overtime = 0; $note = 0; $timekeeping = $this->api_model->select_timekeeping_of_month($branchid, $monthid, $users[$i_users]['id']); for ($i_timekeeping = 0 ; $i_timekeeping < count($timekeeping) ; $i_timekeeping++) { if ($timekeeping[$i_timekeeping]['number_hours'] == $timekeeping[$i_timekeeping]['number_hours_ca']) { $enough_of_hours++; $total_hours += $timekeeping[$i_timekeeping]['number_hours']; } elseif ($timekeeping[$i_timekeeping]['number_hours'] < $timekeeping[$i_timekeeping]['number_hours_ca']) { $lack_of_hours++; $total_hours += $timekeeping[$i_timekeeping]['number_hours']; } else { $overtime++; $total_hours += $timekeeping[$i_timekeeping]['number_hours']; } if ($timekeeping[$i_timekeeping]['description'] != '') { $note = $note . '(' . 'Ngày' . $timekeeping[$i_timekeeping]['number_day'] . ': ' . $timekeeping[$i_timekeeping]['description'] . ') '; } } $array_lack_of_hours = array('lack_of_hours' => $lack_of_hours); $array_enough_of_hours = array('enough_of_hours' => $enough_of_hours); $array_overtime = array('overtime' => $overtime); $array_total_hours = array('total_hours' => $total_hours); $description = array('description' => $note); $real_work = array('real_work' => $total_hours / 8); $users[$i_users] = array_merge($users[$i_users], $array_lack_of_hours); $users[$i_users] = array_merge($users[$i_users], $array_enough_of_hours); $users[$i_users] = array_merge($users[$i_users], $array_overtime); $users[$i_users] = array_merge($users[$i_users], $array_total_hours); $users[$i_users] = array_merge($users[$i_users], $real_work); $users[$i_users] = array_merge($users[$i_users], $description); } //echo " "; //print_r($users);die; echo json_encode($users); } // lấy ngày bắt đầu và kết thúc của tuần theo năm public function getStartAndEndDate($week, $year) { $dto = new DateTime(); $dto->setISODate($year, $week); $ret['week_start'] = $dto->format('d-m-Y'); $dto->modify('+6 days'); $ret['week_end'] = $dto->format('d-m-Y'); return $ret; } // lấy số tuần của năm đó public function getNumberWeekOfYear($ddate) { $date = new DateTime($ddate); $week = $date->format("W"); return $week; } }