query("SELECT staff_id, staff_idno, staff_name, group_id, country_id FROM staff WHERE deleted_at IS NULL AND staff_id IN (".implode(',', $rsi).")") ; if ( $staffs_q->num_rows > 0 ){ $result = 'Failed invalid date' ; if ( $reprocessing_date_from != '' && $reprocessing_date_to != '' ){ $get_day = date('N', strtotime($reprocessing_date_from)) ; // get all related staff first $staffs = [] ; $staffs_id = [] ; $group_id = [] ; while ( $row_staff = $staffs_q->fetch_assoc() ){ $staffs[] = $row_staff ; $staffs_id[] = $row_staff['staff_id'] ; $group_id[] = $row_staff['group_id'] ; } // get staff working hours $workings = [] ; $working_q = $mysqli->query("SELECT staff_id, working_period_from, working_period_to, working_period_before FROM staff_attendance_working WHERE deleted_at IS NULL AND staff_id IN (".implode(',', $staffs_id).") AND working_date = '".$reprocessing_date_from."'") ; if ( $working_q->num_rows > 0 ){ while ( $row_working = $working_q->fetch_assoc() ){ $workings[$row_working['staff_id']] = $row_working ; } } // get staff setting working $sworkings = [] ; $working_q = $mysqli->query("SELECT group_id, working_morning_start as working_period_from, working_morning_end as working_period_to, working_period_before FROM setting_working WHERE deleted_at IS NULL AND group_id IN (".implode(',', $group_id).") AND working_day = '".$get_day."'") ; if ( $working_q->num_rows > 0 ){ while ( $row_working = $working_q->fetch_assoc() ){ $sworkings[$row_working['group_id']] = $row_working ; } } // loop all staff foreach ( $staffs as $staff ){ $boolean_working = false ; $staff_id = $staff['staff_id'] ; if ( arrayCheck($workings[$staff_id]) ){ $boolean_working = true ; $working = $workings[$staff_id] ; }else{ if ( arrayCheck($sworkings[$staff['group_id']]) ){ $boolean_working = true ; $working = $sworkings[$staff['group_id']] ; } } if ( $boolean_working ){ $date_from = $reprocessing_date_from . ' ' . $working['working_period_from'] ; $date_to = date('Y-m-d', strtotime($reprocessing_date_to.' +1 days')) . ' ' . $working['working_period_to'] ; // if ( $working['working_period_before'] > 0 ){ // $date_to = date( 'Y-m-d H:i:s', strtotime('-'.$working['working_period_before'].' hour', strtotime($date_to)) ) ; // } // get attendance list $attendance_q = $mysqli->query("SELECT attendance_id, list_id, created_at FROM staff_attendance WHERE deleted_at IS NULL AND staff_id = '".$staff_id."' AND created_at >= '".$date_from."' AND created_at <= '".$date_to."' ORDER BY created_at ASC") ; if ( $attendance_q->num_rows > 0 ){ $result = 'Success update.' ; $list_id = [] ; while ( $row = $attendance_q->fetch_assoc() ){ $list_id[$row['list_id']] = $row['list_id'] ; } $im_list_id = implode(',', $list_id) ; $u_sal = "UPDATE staff_attendance_list SET deleted_at = '".TODAYDATE."' WHERE deleted_at IS NULL AND list_id IN (".$im_list_id.") AND staff_id = '".$staff_id."'" ; $mysqli->query($u_sal) ; if ( $mysqli->error != '' ){ $error++ ; $result = 'Failed update.' ; $_SESSION['system_result'] = $mysqli->error ; exit; } $u_sa = "UPDATE staff_attendance SET list_id = '0' WHERE deleted_at IS NULL AND list_id IN (".$im_list_id.") AND staff_id = '".$staff_id."' AND list_id != '-1'" ; $mysqli->query($u_sa) ; if ( $mysqli->error != '' ){ $error++ ; $result = 'Failed update.' ; $_SESSION['system_result'] = $mysqli->error ; exit; } } $period_date_to = $date_to ; $date_to = date('Y-m-d H:i:s', strtotime($date_to.' -1 days')) ; $u_sal2 = "UPDATE staff_attendance_list SET deleted_at = '".TODAYDATE."' WHERE deleted_at IS NULL AND staff_id = '".$staff_id."' AND list_date >= '".date('Y-m-d', strtotime($date_from))."' AND list_date <= '".date('Y-m-d', strtotime($date_to))."'" ; $mysqli->query($u_sal2) ; if ( $mysqli->error != '' ){ $error++ ; $result = 'Failed update.' ; $_SESSION['system_result'] = $mysqli->error ; exit; } if ( $reprocessing_reset == 'yes' ){ $u_saw = "UPDATE staff_attendance_working SET deleted_at = '".TODAYDATE."' WHERE deleted_at IS NULL AND staff_id = '".$staff_id."' AND working_date >= '".date('Y-m-d', strtotime($date_from))."' AND working_date <= '".date('Y-m-d', strtotime($date_to))."'" ; $mysqli->query($u_saw) ; if ( $mysqli->error != '' ){ $error++ ; $result = 'Failed update.' ; $_SESSION['system_result'] = $mysqli->error ; exit; } } $period = new DatePeriod( new DateTime($date_from), new DateInterval('P1D'), new DateTime($period_date_to) ) ; foreach ( $period as $key => $value ) { $params = [ 'get_type' => 'custom', 'get_date' => $value->format('Y-m-d'), 'get_staff_id' => $staff_id ] ; // callWithoutResponse( PATH, '443', 'GET', '/cron/generate_attendance_2.php', $params ) ; $cronjobHit = cronjobHit( PATH."cron/generate_attendance.php?get_type=custom&get_date=".$value->format('Y-m-d')."&get_staff_id=".$staff_id."" ) ; // $cronjobHit = cronjobHit( PATH."cron/generate_attendance.php?get_type=custom&get_date=".$value->format('Y-m-d')."&get_staff_id=".$staff_id."" ) ; // $de = json_decode($cronjobHit,true); // if($de['status'] != '200'){ // $_SESSION['system_result'] .= $de['message']; // } } $_SESSION['system_result'] = 'success update' ; } } } } header("Location: ".PATH."/hr-attendance-reprocessing.php?sort_by=staff_idno&sort_by_type=ASC") ; exit ; } $boolean_role = false ; $boolean_edit = false ; if ( $_SESSION['system_permission'] == 'admin' ){ $boolean_role = true ; if ( $edit == 'yes' ){ $boolean_edit = true ; } } // active page $active_main_menu = 'hr' ; $active_sub_menu = 'hr-attendance' ; $active_menu = 'hr-attendance-report' ; // start header here include 'requires/page_header.php' ; include 'requires/page_top.php' ; // reset sort by type $sort_by_type = ( $sort_by_type == 'DESC' ? 'ASC' : 'DESC' ) ; ?>
'.$_SESSION['system_result'].'
' ; }else{ echo '
'.$_SESSION['system_result'].'
' ; } unset($_SESSION['system_result']) ; } // get all staff $staff_list = [] ; $mysqli_staff = $mysqli->query( "SELECT staff_id, staff_name, staff_idno FROM staff WHERE deleted_at IS NULL AND ( staff_date_resigned >= '".date("Y-m-d",time())."' OR staff_date_resigned = '0000-00-00' OR staff_date_resigned IS NULL ) ".$user_branch_permission_sql.( $get_user_tier['check'] ? " AND staff_tier IN ( ".implode(', ', $get_user_tier['tiers'])." )" : '' )." ORDER BY staff_idno ASC" ) ; if ( $mysqli_staff->num_rows > 0 ){ while ( $row_staff = $mysqli_staff->fetch_assoc() ){ $staff_list[$row_staff['staff_id']] = dataFilter($row_staff['staff_name']) . ' ( ' . dataFilter($row_staff['staff_idno']) . ' )' ; } } ?>