query("SELECT * FROM system_user WHERE user_id = '".$_SESSION['system_id']."' "); if ($mysqli_page->num_rows > 0){ while($row_page=$mysqli_page->fetch_array(MYSQLI_ASSOC)){ if($row_page['user_date_format'] == NULL){ $dateformat = "Y-m-d"; } else{ $dateformat = $row_page['user_date_format']; } $date01 = str_replace("d","01",$dateformat); $date31 = str_replace("d","t",$dateformat); // get all branch $branch = [] ; $get_branch = $mysqli->query("SELECT * FROM branch WHERE deleted_at IS NULL".$user_branch_permission_sql) ; if ( $get_branch->num_rows > 0 ){ while ( $row_branch = $get_branch->fetch_assoc() ){ $branch[$row_branch['branch_id']] = $row_branch['branch_name'] ; } } // mode type | all list | new | edit switch( $page_mode ){ case 'record-all': include 'includes/Record/record-all.php'; break; case 'record-edit': include 'includes/Record/record-edit.php'; break; case 'admend-format-1' : /* $result = 'failed' ; $data = [] ; $staff_id = escapeString($_GET['staff_id']) ; $check_group = escapeString($_GET['check_group']) ; if ( $staff_id != '' && $check_group != '' ){ $attendances_q = $mysqli->query("SELECT * FROM staff_attendance WHERE staff_id = '".$staff_id."'AND check_group = '".$check_group."' AND deleted_at IS NULL ORDER BY created_at ASC") ; if ( $attendances_q->num_rows > 0 ){ $result = 'success' ; while ( $attendance = $attendances_q->fetch_assoc() ){ $data[] = [ 'id' => $attendance['attendance_id'], 'type' => ucwords($attendance['type']), 'date' => date('Y-m-d', strtotime($attendance['created_at'])), 'time' => date('H:i:s', strtotime($attendance['created_at'])) ] ; } $last_inout = '' ; $last_date = '' ; for ( $a = 0 ; $a < 8 ; $a++ ){ if ( !empty($data[$a]) ){ $last_inout = $data[$a]['type'] ; $last_date = $data[$a]['date'] ; }else{ if ( $last_inout == 'In' ){ $last_inout = 'Out' ; }else{ $last_inout = 'In' ; } $data[$a] = [ 'id' => 0, 'type' => $last_inout, 'date' => $last_date, 'time' => '' ] ; } } }else{ $result = 'success' ; $last_inout = '' ; for ( $a = 0 ; $a < 8 ; $a++ ){ if ( $last_inout == 'In' && $last_inout != '' ){ $last_inout = 'Out' ; }else{ $last_inout = 'In' ; } $data[$a] = [ 'id' => 0, 'type' => $last_inout, 'date' => $check_group, 'time' => '' ] ; } } } echo json_encode([ 'result' => $result, 'data' => $data ]) ; exit ; */ break ; case 'admend-format-2' : $result = 'failed' ; $data = [] ; $staff_id = escapeString($_GET['staff_id']) ; $check_group = escapeString($_GET['check_group']) ; if ( $staff_id != '' && $check_group != '' ){ $attendances_q = $mysqli->query("SELECT * FROM staff_attendance WHERE staff_id = '".$staff_id."'AND created_at LIKE '".$check_group."%' AND deleted_at IS NULL ORDER BY created_at ASC") ; if ( $attendances_q->num_rows > 0 ){ $result = 'success' ; while ( $attendance = $attendances_q->fetch_assoc() ){ $data[] = [ 'id' => $attendance['attendance_id'], 'date' => date('Y-m-d', strtotime($attendance['created_at'])), 'time' => date('H:i:s', strtotime($attendance['created_at'])), 'remark' => dataFilter($attendance['remark']) ] ; } for ( $a = 0 ; $a < 8 ; $a++ ){ if ( !empty($data[$a]) ){ $last_date = $data[$a]['date'] ; }else{ $data[$a] = [ 'id' => 0, 'date' => $last_date, 'time' => '', 'remark' => '' ] ; } } }else{ $result = 'success' ; $last_inout = '' ; for ( $a = 0 ; $a < 8 ; $a++ ){ $data[$a] = [ 'id' => 0, 'date' => $check_group, 'time' => '', 'remark' => '' ] ; } } } echo json_encode([ 'result' => $result, 'data' => $data ]) ; exit ; break ; case 'list-limit' : $path = 'attendances/check' ; $platform = 'web' ; $lang = 'en' ; $branch_id = $row_branch['branch_id'] ; $staff_id = '' ; $token = '' ; $time = time() ; $sign = hash('sha256', $path.$platform.$lang.$branch_id.$staff_id.$token.$time.APIKEY) ; $call = call( 'curl', PATH.'api/'.$path.'.php', 'POST', [], [ 'input_type' => 'selfpunch', 'qrcode' => $staff_idno, 'latitude' => '', 'longitude' => '', 'platform' => $platform, 'lang' => $lang, 'branch_id' => $branch_id, 'staff_id' => $staff_id, 'token' => $token, 'time' => $time, 'sign' => $sign ] ) ; echo json_encode( $call ) ; exit ; break ; case 'selfpunch' : $status = '300' ; $message = 'Staff not found.' ; $alert = '' ; $data = [] ; $list = [] ; // staff_idno $staff_idno = escapeString( $_GET['staff_idno'] ) ; if ( $staff_idno != '' ){ $path = 'attendances/punch' ; $platform = 'web' ; $lang = 'en' ; $branch_id = $row_branch['branch_id'] ; $staff_id = '' ; $token = '' ; $time = time() ; $sign = hash('sha256', $path.$platform.$lang.$branch_id.$staff_id.$token.$time.APIKEY) ; $call = call( 'curl', PATH.'api/'.$path.'.php', 'POST', [], [ 'input_type' => 'selfpunch', 'qrcode' => $staff_idno, 'latitude' => '', 'longitude' => '', 'platform' => $platform, 'lang' => $lang, 'branch_id' => $branch_id, 'staff_id' => $staff_id, 'token' => $token, 'time' => $time, 'sign' => $sign ] ) ; $status = $call['status'] ; $message = $call['message'] ; if ( $call['status'] == '200' ){ $alert = 'Scan success ( '.$staff_idno.' ).' ; } } echo json_encode([ 'status' => $status, 'message' => $message, 'alert' => $alert ]) ; exit ; break ; case 'qrcode-check' : $status = '300' ; $message = 'Code not found.' ; $data = [] ; $new_code = '' ; $alert = '' ; $boolean = false ; $type = $_POST['type'] ; $qrcode = $_POST['qrcode'] ; // if code not found, generate one if ( $qrcode != '' ){ $get_code = $mysqli->query("SELECT staff_id, code, status, created_at FROM qrcodes WHERE type = '".$type."' AND code = '".$qrcode."' LIMIT 1") ; if ( $get_code->num_rows > 0 ){ $status = '220' ; $message = 'Code expired.' ; $get = $get_code->fetch_assoc() ; $date_code = $get['created_at'] ; $date_time = TODAYDATE ; $date_time = date('Y-m-d H:i:s', strtotime($date_time . ' -5 minutes')) ; if ( $date_code > $date_time ){ $status = '210' ; $message = 'Code used' ; // check code status if ( $get['status'] == '0' ){ $status = '201' ; // Code used before $message = 'Code can used back.' ; $generate = $get['code'] ; $boolean = true ; }elseif ( $get['status'] == '1' ){ // 1 mean scan success // get staff info if ( $get['staff_id'] > 0 ){ $get_staff = $mysqli->query("SELECT * FROM staff WHERE deleted_at IS NULL AND staff_id = '".$get['staff_id']."' LIMIT 1") ; if ( $get_staff->num_rows > 0 ){ $staff = $get_staff->fetch_assoc() ; $alert = 'Scan success ( '.$staff['staff_idno'].' )' ; } } }elseif ( $get['status'] == '2' ){ // 2 mean scan success, but scan too fast $alert = 'Accept rescan only after 15 minutes.' ; } } } } $generatecode = generateQrcode( '', $new_code, $new_code ) ; $new_code = $generatecode['url'] ; if ( !$boolean ){ $mysqli->query("INSERT INTO qrcodes (type, status, created_at, updated_at) VALUES ('checkin', '0', '".TODAYDATE."', '".TODAYDATE."')") ; // set new code $last_id = $mysqli->insert_id ; $new_code = 'PC|'.str_pad($last_id, 6, '0', STR_PAD_LEFT) ; $mysqli->query("UPDATE qrcodes SET code = '".$new_code."' WHERE qrcode_id = '".$last_id."'") ; $status = '200' ; $message = 'New code generated' ; } $generatecode = generateQrcode( '', $new_code, $new_code ) ; $new_code = $generatecode['url'] ; echo json_encode([ 'status' => $status, 'message' => $message, 'data' => [ 'alert' => $alert, 'code' => $new_code ] ]) ; exit ; break ; case 'qrcode' : // check permission if ( !permissionCheck($row_user, 'attendance-list-qrcode') ){ header('Location: index.php') ; exit ; } // active page $active_main_menu = 'hr' ; $active_sub_menu = 'hr-attendance' ; $active_menu = 'hr-attendance-qrcode' ; // start header here include 'requires/page_header.php' ; include 'requires/page_top.php' ; ?>
| Date | Day | Work day | = ( $a%2 == 0 ? 'In' : 'Out' ) ?> | Work Day | T Day | Work | Rest 1 | Rest Timeout 1 | Rest 2 | Rest Timeout 2 | Early | Late | Early Out | OT | Remark |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| '. $value['list_date'] .' | '. $lang[$date] .' | '.( $value['list_work_day'] > 0 ? ''.$value['list_work_day'].'' : $value['list_work_day'] ).' | ' ; for ( $a = 0 ; $a < 8 ; $a++ ){ $current_time = $attendances_date[$a]['created_at'] ; $current_time = ( $current_time != '' ? date('H:i:s', strtotime($current_time)) : '' ) ; echo '
'. $current_time .'
| ' ;
}
if ( EXCELDETAIL == "YES" ){
echo '
'. ( $value['list_work_day'] != '0.00' ? $value['list_work_day'] : '' ) .' | '. ( $value['list_ot_day'] != '0.00' ? $value['list_ot_day'] : '' ) .' | '; } echo ''. ( $value['list_work'] != '00:00:00' ? $value['list_work'] : '' ) .' | '. ( $value['list_rest'] != '00:00:00' ? $value['list_rest'] : '' ) .' '. ( $value['list_time_off'] != '00:00:00' ? '( '.$value['list_time_off'].' )' : '' ) .' | '. ( $value['list_rest_more'] != '00:00:00' ? $value['list_rest_more'] : '' ) .' | '. ( $value['list_rest2'] != '00:00:00' ? $value['list_rest2'] : '' ) .' '. ( $value['list_time_off2'] != '00:00:00' ? '( '.$value['list_time_off2'].' )' : '' ) .' | '. ( $value['list_rest_more2'] != '00:00:00' ? $value['list_rest_more2'] : '' ) .' | '. ( $value['list_early'] != '00:00:00' ? $value['list_early'] : '' ) .' | '. ( $value['list_late'] != '00:00:00' ? $value['list_late'] : '' ) .' | '. ( $value['list_early_out'] != '00:00:00' ? $value['list_early_out'] : '' ) .' | '. ( $value['list_ot_normal'] != '00:00:00' ? $value['list_ot_normal'] : '' ) .' | '. $value['list_remark'] .' |