first commit

This commit is contained in:
LAPTOP-V9RRD1TL\Michelle's Computer
2025-07-21 21:38:17 +08:00
commit f8f8fcaf96
2529 changed files with 227800 additions and 0 deletions
+234
View File
@@ -0,0 +1,234 @@
<?php
include '../connect/cms-config.php' ;
include '../requires/function.php' ;
// using this link https://www.devglan.com/online-tools/rsa-encryption-decryption
// RSA Encryption
// -- Enter Plain Text to Encrypt ( 1234567890030188 )
// -- Enter Public/Private key ( MFswDQYJKoZIhvcNAQEBBQADSgAwRwJAY5pTsXQKlatdfq/W4BDSBcOk5lyDfwtK3elJnCKeA6v5mwSVAqk17XLJ8zXRus1tk0dtNULH02WDRXOI6SBcIwIDAQAB )
// -- Select Cipher Type ( RSA )
// will get result ( ASp8qEBeQpu/Y3FfoagKElhJgvi4A1hH0aTwcvIko1jPsHYm2x1rdEW+rqwZ/QY4YpBmmZhgvLiOZrx73yuQoQ== )
// URL : https://malhrmsgateway.azurewebsites.net
// Client ID : dceb24cd-9965-404c-9988-8b8da4f6bd19
// Secret Key : WoXOHQfBAsUR3gTBu91uh5tcWxqR6e
// PGP Key for Encryption : MFswDQYJKoZIhvcNAQEBBQADSgAwRwJAY5pTsXQKlatdfq/W4BDSBcOk5lyDfwtK3elJnCKeA6v5mwSVAqk17XLJ8zXRus1tk0dtNULH02WDRXOI6SBcIwIDAQAB
$companys = [
[
"CompanyID" => 2,
"CompanyCode" => null,
"CompanyName" => "M&R MANUFACTURING SDN BHD"
],
[
"CompanyID" => 4,
"CompanyCode" => null,
"CompanyName" => "M&R MANUFACTURING SDN BHD (ISKANDAR)"
],
[
"CompanyID" => 5,
"CompanyCode" => null,
"CompanyName" => "M&R INTEGRATED SOLUTION SDN BHD"
],
[
"CompanyID" => 6,
"CompanyCode" => null,
"CompanyName" => "ASA MULTIPLATE (M) SDN BHD"
],
[
"CompanyID" => 7,
"CompanyCode" => null,
"CompanyName" => "M & R INTEGRATED SYNERGY SDN BHD"
]
] ;
$infotech_authorization = 'ASp8qEBeQpu/Y3FfoagKElhJgvi4A1hH0aTwcvIko1jPsHYm2x1rdEW+rqwZ/QY4YpBmmZhgvLiOZrx73yuQoQ==' ;
$infotech_api = 'https://malhrmsgateway.azurewebsites.net' ;
$infotech_clientid = 'dceb24cd-9965-404c-9988-8b8da4f6bd19' ;
$infotech_secretkey = 'WoXOHQfBAsUR3gTBu91uh5tcWxqR6e' ;
$infotech_key = '1234567890030188';
$infotech_iv = 'Info-TechGateWay' ;
foreach ( $companys as $kcompany => $vcompany ){
$infotech_companyid = $vcompany['CompanyID'] ;
$call_token = call( 'curl', $infotech_api.'/Authenticate', 'POST', [ "Authorization:".$infotech_clientid.':'.$infotech_secretkey, "customkey:".$infotech_authorization ], [ "Grant_type" => "password" ]
) ;
if ( $call_token['access_token'] != null ){
// get all current staff
$staffs = [] ;
$select_staff = $mysqli->query("SELECT staff_id, staff_idno, group_id FROM staff
WHERE deleted_at IS NULL AND staff_idno != '' ORDER BY group_id") ;
if ( $select_staff->num_rows > 0 ){
while ( $row_staff = $select_staff->fetch_assoc() ){
$staffs[$row_staff['staff_idno']] = $row_staff ;
}
}
// get all working code
$workingids = [] ;
$workingnames = [] ;
$select_working = $mysqli->query("SELECT group_id, group_name FROM setting_working_group
WHERE deleted_at IS NULL ORDER BY group_id") ;
if ( $select_working->num_rows > 0 ){
while ( $row_working = $select_working->fetch_assoc() ){
$workingids[$row_working['group_id']] = $row_working['group_name'] ;
$workingnames[$row_working['group_name']] = $row_working['group_id'] ;
}
}
// get staff details
$call_parameter = [
"CompanyID" => $infotech_companyid,
"IsActive" => "1"
] ;
$plaintext = json_encode( $call_parameter ) ;
$ciphertext = openssl_encrypt( $plaintext, 'aes-128-cbc', $infotech_key, OPENSSL_RAW_DATA, $infotech_iv ) ;
$get_str = base64_encode( $ciphertext ) ;
$call_staff = call( 'curl-json', $infotech_api.'/Api/GetEmployeeDetails', 'GET', [ "Authorization:Bearer ".$call_token['access_token'] ], [ "str" => $get_str ]
) ;
// check staff shiftcode same with system or not
$update_staffs = [] ;
if ( count($call_staff) > 0 ){
foreach ( $call_staff as $k => $v ){
$get_staff = $staffs[$v['EmployeeCode']] ;
$get_group_id = $get_staff['group_id'] ;
if ( $v['ShiftCode'] != '' && $v['ShiftCode'] != $workingids[$get_group_id] ){
$update_staffs[$get_staff['staff_id']] = $workingnames[$v['ShiftCode']] ;
}
}
}
// update all staff latest shift
if ( count($update_staffs) > 0 ){
$staff_ids = [] ;
$case_ids = [] ;
foreach ( $update_staffs as $k => $v ){
$case_ids[] = " WHEN staff_id = '".$k."' THEN '".$v."'" ;
$staff_ids[] = $k ;
}
$update_query = "
UPDATE staff
SET group_id = CASE
".implode( '', $case_ids )."
ELSE group_id
END
WHERE staff_id IN ( ".implode( ', ', $staff_ids )." )
" ;
$mysqli->query( $update_query ) ;
}
// get leave details
$call_parameter = [
"CompanyID" => $infotech_companyid,
"EmpCode" => "",
// "FromDate" => '22/07/2023',
// "ToDate" => '22/07/2023',
"FromDate" => date( "d/m/Y", time() ),
"ToDate" => date( "d/m/Y", time() )
] ;
$plaintext = json_encode( $call_parameter ) ;
$ciphertext = openssl_encrypt( $plaintext, 'aes-128-cbc', $infotech_key, OPENSSL_RAW_DATA, $infotech_iv ) ;
$get_str = base64_encode( $ciphertext ) ;
$call_leave = call( 'curl-json', $infotech_api.'/Api/GetLeaveDetails', 'GET', [ "Authorization:Bearer ".$call_token['access_token'] ], [ "str" => $get_str ]
) ;
$leaves = [] ;
if ( count($call_leave) > 0 ){
foreach ( $call_leave as $k => $v ){
if ( $v['LeaveStatus'] == 'APPROVED' ){
$get_staff = $staffs[$v['EmpCodeC']] ;
$v['staff_id'] = $get_staff['staff_id'] ;
$leaves[] = $v ;
$kkk[$v['LeaveType']] = $v['LeaveType'] ;
}
}
}
foreach ( $leaves as $kleave => $vleave ){
$leave_type_mode = 'working' ;
$leave_date = date( 'Y-m-d', strtotime( $vleave['LvDateD'] ) ) ;
$leave_work_day = '0' ;
$leave_type = 'unpaid' ;
$leave_work_direct = 'yes' ;
switch ( $vleave['LeaveType'] ){
case 'HOURLY LEAVE UNPAID' :
$leave_type = 'unpaid' ;
$leave_work_day = 'hourly' ;
break ;
case 'UNPAID LEAVE' :
$leave_type = 'unpaid' ;
$leave_work_day = 'full' ;
break ;
case 'UNPAID LEAVE FIRST HALF' :
$leave_type = 'unpaid' ;
$leave_work_day = 'firsthalf' ;
break ;
case 'UNPAID LEAVE SECOND HALF' :
$leave_type = 'unpaid' ;
$leave_work_day = 'secondhalf' ;
break ;
case 'ANNUAL LEAVE' :
case 'REPLACEMENT LEAVE' :
case 'MATRIMONIAL LEAVE' :
case 'COMPASSIONATE LEAVE' :
case 'EMERGENCY LEAVE' :
$leave_type = 'annual' ;
$leave_work_day = 'full' ;
break ;
case 'ANNUAL LEAVE FIRST HALF' :
case 'EMERGENCY LEAVE FIRST HALF' :
$leave_type = 'annual' ;
$leave_work_day = 'firsthalf' ;
break ;
case 'ANNUAL LEAVE SECOND HALF' :
case 'EMERGENCY LEAVE SECOND HALF' :
$leave_type = 'annual' ;
$leave_work_day = 'secondhalf' ;
break ;
case 'MEDICAL LEAVE' :
case 'HOSPITALIZATION LEAVE' :
case 'MATERNITY LEAVE' :
case 'PATERNITY LEAVE' :
$leave_type = 'sick' ;
$leave_work_day = 'full' ;
break ;
}
$select_leave = $mysqli->query( "SELECT * FROM staff_leave_date
WHERE deleted_at IS NULL AND staff_id = '".$vleave['staff_id']."' AND leave_type = '".$leave_type."' AND leave_type_mode = '".$leave_type_mode."' AND leave_date = '".$leave_date."'" ) ;
if ( $select_leave->num_rows == 0 ){
$mysqli->query( "INSERT INTO staff_leave_date
( staff_id, leave_type, leave_type_mode, leave_date, leave_work_direct, leave_work_day ) VALUES
( '".$vleave['staff_id']."', '".$leave_type."', '".$leave_type_mode."', '".$leave_date."', '".$leave_work_direct."', '".$leave_work_day."' )" ) ;
}
}
// print_r($leaves) ;
// print_r("<br />") ;
// print_r("<br />") ;
// print_r("<br />") ;
}
}
?>
+70
View File
@@ -0,0 +1,70 @@
<?php
include '../connect/cms-config.php' ;
$current_timestamp = time() ;
$current_year = date( "Y", $current_timestamp ) ;
$current_month = date( "m", $current_timestamp ) ;
$current_day = date( "d", $current_timestamp ) ;
$current_hour = date( "H", $current_timestamp ) ;
$current_minute = date( "i", $current_timestamp ) ;
// run every minutes
if ( $CRONJOBS['rms_pay_bill'] == 'yes' ){ file_get_contents( PATH . 'cron/rms_pay_bill.php' ) ; }
if ( $CRONJOBS['rms_prepaid_check_status'] == 'yes' ){ file_get_contents( PATH . 'cron/rms_prepaid_check_status.php' ) ; }
if ( $CRONJOBS['generate_attendance'] == 'yes' ){ file_get_contents( PATH . 'cron/generate_attendance.php' ) ; }
if ( $CRONJOBS['push_notification'] == 'yes' ){ file_get_contents( PATH . 'cron/push_notification.php' ) ; }
if ( $CRONJOBS['punchs/user'] == 'yes' ){ file_get_contents( PATH . 'apiv3/punchs/user.php' ) ; }
// run every day in 00:00
if ( $current_hour == 0 && $current_minute == 0 ){
if ( $CRONJOBS['generate_leave_day'] == 'yes' ){ file_get_contents( PATH . 'cron/generate_leave_day.php' ) ; }
}
// run every day in 08:00
if ( $current_hour == 8 && $current_minute == 0 ){
if ( $CRONJOBS['push_task_notification'] == 'yes' ){ file_get_contents( PATH . 'cron/push_task_notification.php' ) ; }
if ( $CRONJOBS['push_holiday'] == 'yes' ){ file_get_contents( PATH . 'cron/push_holiday.php' ) ; }
if ( $CRONJOBS['push_passport_permit_leave_advance'] == 'yes' ){ file_get_contents( PATH . 'cron/push_passport_permit_leave_advance.php' ) ; }
if ( $CRONJOBS['push_application_form_reminder'] == 'yes' ){ file_get_contents( PATH . 'cron/push_application_form_reminder.php' ) ; }
}
// run every day in 09:35 & 14:35
if ( ( $current_hour == 9 && $current_minute == 35 ) ||
( $current_hour == 14 && $current_minute == 35 ) ){
if ( $CRONJOBS['generate_attendance_to_text'] == 'yes' ){ file_get_contents( PATH . 'cron/generate_attendance_to_text.php' ) ; }
}
// run every first day of month, because got year end cut off function, the other cronjob need to delay 1 hour
if ( $current_day == 1 && $current_hour == 0 && $current_minute == 0 ){
if ( $CRONJOBS['generate_staff_achievement'] == 'yes' ){ file_get_contents( PATH . 'cron/generate_staff_achievement.php' ) ; }
}
// run every month and give point
if ( $current_day == 1 && $current_hour == 1 && $current_minute == 0 ){
if ( $CRONJOBS['generate_monthly_performance_point'] == 'yes' ){ file_get_contents( PATH . 'cron/generate_monthly_performance_point.php' ) ; }
if ( ( $current_month == 1 || $current_month == 4 || $current_month == 7 || $current_month == 10 ) ){ // runing report by seasonly
if ( $CRONJOBS['generate_seasonly_improvement_point'] == 'yes' ){ file_get_contents( PATH . 'cron/generate_seasonly_improvement_point.php' ) ; }
}
}
// run every 10 days of month, because need count full attendance report
if ( $current_day == 10 && $current_hour == 0 && $current_minute == 0 ){
if ( $CRONJOBS['generate_monthly_attendance_point'] == 'yes' ){ file_get_contents( PATH . 'cron/generate_monthly_attendance_point.php' ) ; }
}
// run every 25 days of month, because generate salary
if ( $current_day == 25 && $current_hour == 9 && $current_minute == 0 ){
if ( $CRONJOBS['push_staff_resignation'] == 'yes' ){ file_get_contents( PATH . 'cron/push_staff_resignation.php' ) ; }
}
// run every 27 days of month, because generate salary
if ( $current_day == 27 && $current_hour == 0 && $current_minute == 0 ){
if ( $CRONJOBS['generate_payment_slip'] == 'yes' ){ file_get_contents( PATH . 'cron/generate_payment_slip.php' ) ; }
}
// run seasonly to summary report
if ( $current_day == 15 && $current_hour == 0 && $current_minute == 0 ){
if ( $CRONJOBS['generate_seasonly_summary_point'] == 'yes' ){ file_get_contents( PATH . 'cron/generate_seasonly_summary_point.php' ) ; }
}
?>
+994
View File
@@ -0,0 +1,994 @@
<?php
// default config setting
$boolean_ssl_lock = true ;
include '../connect/cms-config.php' ;
include '../requires/function.php' ;
// defualt parameter
$get_type = $_GET['get_type'] ;
$get_date = $_GET['get_date'] ;
$get_staff_id = $_GET['get_staff_id'] ;
$status = '500' ;
$message = 'Failed' ;
if ( $get_type == 'custom' ){
// today is generate selected date report
$date_yesterday = $get_date ;
}else{
// today is generate yesterday report
$date_today = TODAYDATE ;
$date_yesterday = date('Y-m-d', strtotime($date_today . ' -1 day')) ;
}
$current_hour = date('H', time()) ;
$date_next = date('Y-m-d', strtotime($date_yesterday . ' +1 day')) ;
$yesterday_day = date('N', strtotime($date_yesterday)) ;
// check if is holiday
$boolean_holiday = false ;
$holiday_name = '' ;
$holiday_q = $mysqli->query("SELECT holiday_name FROM setting_holiday
WHERE deleted_at IS NULL AND holiday_date = '".$date_yesterday."' LIMIT 1") ;
if ( $holiday_q->num_rows ){
$boolean_holiday = true ;
$holiday = $holiday_q->fetch_assoc() ;
$holiday_name = $holiday['holiday_name'] ;
}
// loop all staff
if ( $get_type == 'custom' ){
$staffs_q = $mysqli->query("SELECT staff_id, staff_idno, staff_name, group_id, country_id, staff_settings, work_type_id FROM staff
WHERE deleted_at IS NULL AND staff_id = '".$get_staff_id."' LIMIT 1") ;
}else{
$staffs_q = $mysqli->query("SELECT staff_id, staff_idno, staff_name, group_id, country_id, staff_settings, work_type_id 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 )") ;
}
if ( $staffs_q->num_rows > 0 ){
$status = '210' ;
$message = 'No staff found.' ;
$staffs = [] ;
while ( $row = $staffs_q->fetch_assoc() ){
$staffs[] = $row ;
}
// get all staff deparment
$staff_department = [] ;
$get_department = $mysqli->query("SELECT staff_id, department_id FROM staff_department
WHERE deleted_at IS NULL ORDER BY department_id") ;
if ( $get_department->num_rows > 0 ){
while ( $row_department = $get_department->fetch_assoc() ){
$staff_department[$row_department['staff_id']][] = $row_department['department_id'] ;
}
}
// cut off attendance report
foreach ( $staffs as $key => $staff ){
$status = '201' ;
$message = 'Attendance list report was generated already.' ;
$staff_id = $staff['staff_id'] ;
$list_type = 'normal' ;
$list_type_remark = 'WD' ;
$list_remark = '' ;
$list_work_day = '0' ;
$list_ot_day = '0' ;
$list_work = '00:00:00' ;
$list_rest = '00:00:00' ;
$list_rest_more = '00:00:00' ;
$list_time_off = '00:00:00' ;
$list_rest2 = '00:00:00' ;
$list_rest_more2 = '00:00:00' ;
$list_time_off2 = '00:00:00' ;
$list_early = '00:00:00' ;
$list_early_out = '00:00:00' ;
$list_late = '00:00:00' ;
$list_ot_normal = '00:00:00' ;
$list_leave_day = 0 ;
$wrong_punch = [] ;
$array_abnormal = [] ;
// staff setting
$staff_settings = $staff['staff_settings'] ;
if ( $staff_settings != '' ){
$staff_settings = JsonEncodeDecode('decode', $staff_settings) ;
}else{
$staff_settings = [] ;
}
// check if not exists
$attendance_list_q = $mysqli->query("SELECT list_id FROM staff_attendance_list
WHERE deleted_at IS NULL AND staff_id = '".$staff_id."' AND list_date = '".$date_yesterday."' LIMIT 1") ;
if ( $attendance_list_q->num_rows == 0 ){
$status = '209' ;
$message = 'Selected staff no setting working hours.' ;
// check staff working time, if not exists create
$boolean_setting_working = false ;
$working_q = $mysqli->query("SELECT working_id, working_on, working_next_day, working_if_flexi, working_if_include_rest, working_if_ot, working_direct_day, working_if_fixed_work, working_day_calculation, working_period_from, working_period_to, working_period_before, working_from, working_to, working_to_include_ot, working_total_hours, working_total_rest_hours, working_rest_range_from, working_rest_range_to, working_rest_include_ot, working_rounding_ot, working_if_ot_morning, working_if_offduty, working_count_offduty, working_if_deduct_offduty, working_max_ot,working_total_rest_hours2,working_rest_range_from2,working_rest_range_to2 FROM staff_attendance_working
WHERE deleted_at IS NULL AND staff_id = '".$staff_id."' AND working_date = '".$date_yesterday."' LIMIT 1") ;
if ( $working_q->num_rows == 0 ){
// get staff working hours
$working_q2 = $mysqli->query("SELECT group_id, working_on, working_next_day, working_if_flexi, working_if_include_rest, working_if_ot, working_direct_day, working_if_fixed_work, working_day_calculation, working_morning_start as working_period_from, working_morning_end as working_period_to, working_period_before, working_break_start as working_from, working_break_end as working_to, working_break_end_include_ot as working_to_include_ot, working_total_hours, working_total_rest_hours, working_rest_range_from, working_rest_range_to, working_rest_include_ot, working_rounding_ot, working_if_ot_morning, working_if_offduty, working_count_offduty, working_if_deduct_offduty, working_max_ot,working_total_rest_hours2,working_rest_range_from2,working_rest_range_to2 FROM setting_working
WHERE deleted_at IS NULL AND group_id = '".$staff['group_id']."' AND working_day = '".$yesterday_day."' LIMIT 1") ;
// check if working setting got set
if ( $working_q2->num_rows > 0 ){
$boolean_setting_working = true ;
$working = $working_q2->fetch_assoc() ;
$mysqli->query("INSERT INTO staff_attendance_working
(staff_id, working_group_id, working_date, working_on, working_next_day, working_if_flexi, working_if_include_rest, working_if_ot, working_direct_day, working_if_fixed_work, working_day_calculation, working_period_from, working_period_to, working_period_before, working_from, working_to, working_to_include_ot, working_total_hours, working_total_rest_hours, working_rest_range_from, working_rest_range_to, working_rest_include_ot, working_rounding_ot, working_if_ot_morning, working_if_offduty, working_count_offduty, working_if_deduct_offduty, working_max_ot, created_at, updated_at,working_total_rest_hours2,working_rest_range_from2,working_rest_range_to2) VALUES
('".$staff_id."', '".$working['group_id']."', '".$date_yesterday."', '".$working['working_on']."', '".$working['working_next_day']."', '".$working['working_if_flexi']."', '".$working['working_if_include_rest']."', '".$working['working_if_ot']."', '".$working['working_direct_day']."', '".$working['working_if_fixed_work']."', '".$working['working_day_calculation']."', '".$working['working_period_from']."', '".$working['working_period_to']."', '".$working['working_period_before']."', '".$working['working_from']."', '".$working['working_to']."', '".$working['working_to_include_ot']."', '".$working['working_total_hours']."', '".$working['working_total_rest_hours']."', ".( $working['working_rest_range_from'] != '' ? "'".$working['working_rest_range_from']."'" : "NULL" ).", ".( $working['working_rest_range_to'] != '' ? "'".$working['working_rest_range_to']."'" : "NULL" ).", ".( $working['working_rest_include_ot'] != '' ? "'".$working['working_rest_include_ot']."'" : "NULL" ).", '".$working['working_rounding_ot']."', '".$working['working_if_ot_morning']."', '".$working['working_if_offduty']."', '".$working['working_count_offduty']."', '".$working['working_if_deduct_offduty']."', '".$working['working_max_ot']."', '".TODAYDATE."', '".TODAYDATE."','".$working['working_total_rest_hours2']."',".($working['working_rest_range_from2'] !='' ? "'".$working['working_rest_range_from2']."'" : "NULL" ).",".($working['working_rest_range_to2'] != '' ? "'".$working['working_rest_range_to2']."'": "NULL" ).")") ;
}
}else{
$boolean_setting_working = true ;
$working = $working_q->fetch_assoc() ;
}
if ( $boolean_setting_working ){
$status = '208' ;
$message = 'Selected staff cannot generate attendance report currently.' ;
// default parameter
$total_hours = $working['working_total_hours'] ;
$total_rest_hours = $working['working_total_rest_hours'] ;
$total_rest_hours2 = $working['working_total_rest_hours2'] ;
$boolean_rest_hours2 = ( $total_rest_hours2 != '' && $total_rest_hours2 != '00:00:00' ? 'yes' : 'no' ) ;
$array_atten_ls = [] ;
$array_atten = [] ;
$punchiscorrect = true ;
// check if allow to insert attendances
$check_current_datetime = $date_yesterday.' '.$working['working_period_from'] ;
$check_next_datetime = $date_next.' '.$working['working_period_to'] ;
if ( $working['working_to_include_ot'] > 0 ){
$check_next_datetime = date( 'Y-m-d H:i:s', strtotime('-'.$working['working_to_include_ot'].' hour', strtotime($check_next_datetime)) ) ;
}
// set running schedule time + 1 hours
$check_running_datetime = date( 'Y-m-d H:i:s', strtotime('+1 hour', strtotime($check_next_datetime)) ) ;
$after_rest1 = date( 'Y-m-d', strtotime( $check_current_datetime ) ) . ' ' . $working['working_rest_range_from'] ;
$after_rest2 = date( 'Y-m-d', strtotime( $check_current_datetime ) ) . ' ' . $working['working_rest_range_to'] ;
if ( TODAYDATE > $check_running_datetime ){
// check if today got apply leave
$check_leave_q = $mysqli->query("SELECT a.leave_type, a.leave_work_day, b.leave_reason FROM staff_leave_date a
LEFT JOIN staff_leave b ON ( a.leave_id = b.leave_id )
WHERE a.deleted_at IS NULL AND a.staff_id = '".$staff_id."' AND a.leave_date = '".$date_yesterday."' AND b.deleted_at IS NULL AND b.leave_status = 'confirmed' LIMIT 1") ;
if ( $check_leave_q->num_rows > 0 ){
$check_leave = $check_leave_q->fetch_assoc() ;
$list_type = 'leave' ;
$list_remark = $check_leave['leave_reason'] ;
$list_leave_day = $check_leave['leave_work_day'] ;
switch ( $check_leave['leave_type'] ){
case 'unpaid' :
$list_type_remark = 'UL' ;
break ;
case 'annual' :
$list_type_remark = 'AL' ;
break ;
case 'sick' :
$list_type_remark = 'MC' ;
break ;
}
}
// check today is holiday or weekend
if ( $working['working_on'] == 'no' ){
$list_type = 'weekend' ;
$list_type_remark = 'OD' ;
$list_remark = 'Off Day' ;
$list_work_day = '0' ;
}else{
// if is holiday
if ( $boolean_holiday ){
$list_type = 'holiday' ;
$list_type_remark = 'HL' ;
$list_remark = $holiday_name ;
$list_work_day = '0' ;
}
}
// filter between time period attendance
$attendance_q = $mysqli->query("SELECT attendance_id, created_at FROM staff_attendance
WHERE deleted_at IS NULL AND staff_id = '".$staff_id."' AND list_id = '0' AND created_at >= '".$check_current_datetime."' AND created_at <= '".$check_next_datetime."' ORDER BY created_at ASC") ;
if ( $attendance_q->num_rows > 0 ){
$total_atten = $attendance_q->num_rows ;
$last_atten = '' ;
$working_from = '00:00:00' ;
$first_in_time = '00:00:00' ;
$count_atten = 0 ;
// keep all attendance in array
while ( $attendance = $attendance_q->fetch_assoc() ){
$last_atten = $attendance['created_at'] ;
// check working to
$working_to = date('Y-m-d H:i:s', strtotime( date('Y-m-d', strtotime($last_atten)).' '.$working['working_to'] )) ;
if ( $working['working_if_flexi'] != 'yes' && $working['working_if_fixed_work'] == 'yes' ){
if ( $last_atten >= $working_to ){
$last_atten = $working_to ;
}
}
if ( $count_atten == 0 ){
if ( $working['working_if_flexi'] == 'yes' ){
$working_from = $last_atten ;
}else{
$working_from = date('Y-m-d H:i:s', strtotime( date('Y-m-d', strtotime($last_atten)).' '.$working['working_from'] )) ;
}
$first_in_time = $last_atten ;
if ( $working_from >= $last_atten ){
$last_atten = $working_from ;
}
}
$array_atten_ls[] = $attendance['attendance_id'] ;
$array_atten[] = $last_atten ;
$count_atten++ ;
}
// generate new attendance if attendance is odd
if ( $total_atten%2 == 1 ){
$array_atten[] = $last_atten ;
$punchiscorrect = false ;
}
if ( $array_atten['1'] >= $array_atten['0'] ){
// calculate work and rest and keep in array
$array_hours = [] ;
$array_abnormal = [] ;
$next_hours = '' ;
$rest_1_out = '' ;
$rest_1_in = '' ;
$rest_2_out = '' ;
$rest_2_in = '' ;
$count_rest = 0 ;
foreach ( $array_atten as $k => $v ){
if ( $next_hours != '' ){
$array_hours[] = subtractTime($v, $next_hours) ;
if ( $count_rest == 1 ){
$rest_1_out = $v ;
}
if ( $count_rest == 2 ){
$rest_1_in = $v ;
}
if ( $count_rest == 3 ){
$rest_2_out = $v ;
}
if ( $count_rest == 4 ){
$rest_2_in = $v ;
}
}
$next_hours = $v ;
$count_rest++ ;
}
// get total work & rest
foreach ( $array_hours as $k => $v ){
if ( $k%2 == 1 ){
if ( $k == 1 ){
$list_rest = addTime($list_rest, $v) ;
}else{
if ( $boolean_rest_hours2 == 'yes' ){
$list_rest2 = addTime($list_rest2, $v) ;
}else{
$list_rest = addTime($list_rest, $v) ;
}
}
}else{
$list_work = addTime($list_work, $v) ;
}
$prev_hours = $v ;
}
// check rest in & out if got time, and attendance time more than 2
// if range from and range to setting is empty do nothing
// check if under the range time, if yes do nothing, else checking total time off
$rest_array[] = [
'current_rest' => '1',
'boolean_rest_hours' => 'yes',
'array_atten_ls_1' => 1,
'array_atten_ls_2' => 2,
'total_rest_hours' => $total_rest_hours,
'list_rest' => $list_rest,
'list_rest_more' => $list_rest_more,
'list_time_off' => $list_time_off,
'rest_out' => $rest_1_out,
'rest_in' => $rest_1_in,
'count_rest' => 2,
'working_rest_range_from' => $working['working_rest_range_from'],
'working_rest_range_to' => $working['working_rest_range_to']
] ;
if ( $boolean_rest_hours2 ){
$rest_array[] = [
'current_rest' => '2',
'boolean_rest_hours' => $boolean_rest_hours2,
'array_atten_ls_1' => 3,
'array_atten_ls_2' => 4,
'total_rest_hours' => $total_rest_hours2,
'list_rest' => $list_rest2,
'list_rest_more' => $list_rest_more2,
'list_time_off' => $list_time_off2,
'rest_out' => $rest_2_out,
'rest_in' => $rest_2_in,
'count_rest' => 4,
'working_rest_range_from' => $working['working_rest_range_from2'],
'working_rest_range_to' => $working['working_rest_range_to2']
] ;
}
foreach ( $rest_array as $krest => $vrest ){
$temp_list_time_off = $vrest['list_time_off'] ;
$more_rest = '00:00:00' ;
if ( $vrest['boolean_rest_hours'] == 'yes' ){
if ( $working['working_if_flexi'] == 'no' && $vrest['rest_out'] != '' && $vrest['rest_in'] != '' && $count_rest > $vrest['count_rest'] ){
$rest_range_from = $vrest['working_rest_range_from'] ;
$rest_range_to = $vrest['working_rest_range_to'] ;
if ( ( $rest_range_from != '' && $rest_range_from != '00:00:00' ) &&
( $rest_range_to != '' && $rest_range_to != '00:00:00' ) ){
$rest_range_from = $date_yesterday . ' ' . $rest_range_from ;
$rest_range_to = $date_yesterday . ' ' . $rest_range_to ;
if ( $rest_range_from > $vrest['rest_out'] || $rest_range_to < $vrest['rest_out'] || $rest_range_from > $vrest['rest_in'] || $rest_range_to < $vrest['rest_in'] ){
// if situation 1 - early out
// else - late out
if ( $rest_range_from > $vrest['rest_out'] || $rest_range_to >= $vrest['rest_out'] ){
if ( $rest_range_from > $vrest['rest_in'] ){
$temp_list_time_off = subtractTime($rest_range_from, $vrest['rest_out']) ;
$array_abnormal[] = $array_atten_ls[$vrest['array_atten_ls_1']] ;
$array_abnormal[] = $array_atten_ls[$vrest['array_atten_ls_2']] ;
}else{
if ( $rest_range_from > $vrest['rest_out'] && $rest_range_to < $vrest['rest_in'] ){
$deduct_out = subtractTime($rest_range_from, $vrest['rest_out']) ;
$deduct_in = subtractTime($vrest['rest_in'], $rest_range_to) ;
$temp_list_time_off = addTime($deduct_out, $deduct_in) ;
$array_abnormal[] = $array_atten_ls[$vrest['array_atten_ls_1']] ;
$array_abnormal[] = $array_atten_ls[$vrest['array_atten_ls_2']] ;
}elseif ( $rest_range_from <= $vrest['rest_out'] && $rest_range_to < $vrest['rest_in'] ){
$temp_list_time_off = subtractTime($vrest['rest_in'], $rest_range_to) ;
$array_abnormal[] = $array_atten_ls[$vrest['array_atten_ls_2']] ;
}else{
$temp_list_time_off = subtractTime($rest_range_from, $vrest['rest_out']) ;
$array_abnormal[] = $array_atten_ls[$vrest['array_atten_ls_1']] ;
}
}
}else{
$temp_list_time_off = subtractTime($vrest['rest_in'], $vrest['rest_out']) ;
$array_abnormal[] = $array_atten_ls[$vrest['array_atten_ls_2']] ;
}
}
}
}
$boolean_rest = false ;
if ( $vrest['current_rest'] == '1' ){
$boolean_rest = true ;
}
if ( $vrest['current_rest'] == '2' ){
if ( $vrest['working_rest_range_from'] != '00:00:00' && $vrest['working_rest_range_to'] != '00:00:00' ){
$setting_rest2_time = date( 'Y-m-d', strtotime( $check_current_datetime ) ) . ' ' . $vrest['working_rest_range_to'] ;
}else{
$setting_rest2_time = date( 'Y-m-d', strtotime( $check_current_datetime ) ) . ' ' . $working['working_to'] ;
$setting_rest2_time = date( 'Y-m-d H:i:s', strtotime( $setting_rest2_time . ' +'.convertMinutes($vrest['total_rest_hours']).' minutes' ) ) ;
}
if ( $last_atten >= $working_to && $last_atten >= $setting_rest2_time ){
$check_atten_hours = subtractTime($last_atten, $working_to) ;
$boolean_rest = true ;
}else{
$list_rest2 = '00:00:00' ;
$list_rest_more2 = '00:00:00' ;
$list_time_off2 = '00:00:00' ;
}
}
// calculate rest
if ( $vrest['total_rest_hours'] != '00:00:00' && $vrest['total_rest_hours'] != '' ){
if ( $boolean_rest ){
if ( $vrest['total_rest_hours'] > $vrest['list_rest'] ){
$diff_rest = subtractTime($vrest['total_rest_hours'], $vrest['list_rest']) ;
if ( $list_work > '00:00:00' ){
$list_work = subtractTime($list_work, $diff_rest) ;
}
}
}
if ( $vrest['list_rest'] > $vrest['total_rest_hours'] ){
$more_rest = subtractTime($vrest['list_rest'], $vrest['total_rest_hours']) ;
if ( $boolean_rest ){
$list_work = addTime($list_work, $more_rest) ;
$array_abnormal[] = $array_atten_ls[$vrest['array_atten_ls_2']] ;
}
}
}
// if rest hour more than real rest hours within working hours
if ( $boolean_rest ){
if ( $vrest['total_rest_hours'] == '00:00:00' || $vrest['total_rest_hours'] == '' ){
if ( $temp_list_time_off != '00:00:00' && $temp_list_time_off != '' ){
if ( $temp_list_time_off > $vrest['total_rest_hours'] ){
$list_work = addTime($list_work, $vrest['total_rest_hours']) ;
$temp_list_time_off = subtractTime($temp_list_time_off, $vrest['total_rest_hours']) ;
}else{
$list_work = addTime($list_work, $temp_list_time_off) ;
$temp_list_time_off = '00:00:00' ;
}
}
}
}
// if ( $working['working_direct_day'] == 'no' ){
if ( $list_type_remark != 'OD' && $list_type_remark != 'HL' ){
switch ( $vrest['current_rest'] ){
case '1' :
$list_rest = $vrest['total_rest_hours'] ;
$list_rest_more = $more_rest ;
$list_time_off = $temp_list_time_off ;
break ;
case '2' :
$list_rest2 = $vrest['total_rest_hours'] ;
$list_rest_more2 = $more_rest ;
$list_time_off2 = $temp_list_time_off ;
break ;
}
}
}
}
// get early / late / ot
if ( $working_from > $first_in_time ){
$list_early = subtractTime($working_from, $first_in_time) ;
}
$new_first_in_time = $first_in_time ;
if ( $working['working_rest_range_from'] != '00:00:00' ){
$new_first_in_time = date( 'Y-m-d', strtotime( $first_in_time ) ) . ' ' . $working['working_rest_range_from'] ;
}
if ( $first_in_time >= $working_from && $working_from < $new_first_in_time ){
if ( $new_first_in_time >= $first_in_time ){
$list_late = subtractTime($first_in_time, $working_from) ;
}else{
$list_late = subtractTime($new_first_in_time, $working_from) ;
}
}
// echo $list_late ;
// exit ;
// check if OT is count as total work?
// add the late hours to the total work
$list_work_total = $list_work ;
// if ( $working['working_direct_day'] == 'yes' ){
if ( $list_type_remark == 'OD' || $list_type_remark == 'HL' ){
$total_hours = '00:00:00' ;
}else{
if ( $working['working_if_flexi'] != 'yes' ){
$list_work = addTime($list_work, $list_late) ;
}
}
// check if work enough hours
if ( $list_work >= $total_hours ){
// check if ot
if ( $working['working_if_ot'] == 'yes' ){
if ( $list_work > $total_hours ){
$list_ot_normal = subtractTime($list_work, $total_hours) ;
$list_work = subtractTime($list_work, $list_ot_normal) ;
}
// if off duty is yes
if ( $working['working_if_offduty'] == 'yes' ){
if ( $list_ot_normal >= $working['working_count_offduty'] ){
if ( $working['working_if_deduct_offduty'] == 'no' ){
$list_work = addTime($list_work, $working['working_count_offduty']) ;
$list_ot_normal = subtractTime($list_ot_normal, $working['working_count_offduty']) ;
}
}else{
$list_work = addTime($list_work, $list_ot_normal) ;
$list_ot_normal = '00:00:00' ;
}
}
// if ot rounding is greater than 1
if ( $working['working_rounding_ot'] > 1 ){
$working_rounding_ot = strPad(2, $working['working_rounding_ot']) ;
if ( $working_rounding_ot == '60' ){
$rounding_ot = '01:00:00' ;
}else{
$rounding_ot = '00:'.$working_rounding_ot.':00' ;
}
$reset_list_ot_normal = $list_ot_normal ;
$list_ot_normal = '00:00:00' ;
$boolean_ot = true ;
if ( $rounding_ot <= $reset_list_ot_normal ){
while ( $boolean_ot ){
$reset_list_ot_normal = subtractTime($reset_list_ot_normal, $rounding_ot) ;
$list_ot_normal = addTime($list_ot_normal, $rounding_ot) ;
if ( $rounding_ot > $reset_list_ot_normal ){
$boolean_ot = false ;
}
}
// check if morning is count as ot
if ( $working['working_if_ot_morning'] == 'yes' ){
if ( $list_early != '' && $list_early != '00:00:00' ){
$reset_list_ot_normal = $list_early ;
$boolean_ot = true ;
if ( $rounding_ot <= $reset_list_ot_normal ){
while ( $boolean_ot ){
$reset_list_ot_normal = subtractTime($reset_list_ot_normal, $rounding_ot) ;
$list_ot_normal = addTime($list_ot_normal, $rounding_ot) ;
if ( $rounding_ot > $reset_list_ot_normal ){
$boolean_ot = false ;
}
}
}
}
}
}
}
// check if OT is count as total work?
// delete back the total work hours
if ( $working['working_if_flexi'] != 'yes' ){
$list_work = subtractTime($list_work, $list_late) ;
}
// check max ot hours
$working_max_ot = $working['working_max_ot'] ;
if ( $working_max_ot != '' && $working_max_ot != '00:00:00' ){
if ( $list_ot_normal > $working_max_ot ){
$list_work = addTime( $list_work, subtractTime($working_max_ot, $list_ot_normal) ) ;
$list_ot_normal = $working_max_ot ;
}
}
}
}else{
$list_early_out = subtractTime($total_hours, $list_work_total) ;
if ( $list_late != '00:00:00' ){
$list_early_out = subtractTime($list_early_out, $list_late) ;
}
if ( $after_rest2 > $last_atten ){
// $rest_exclude_early_out = subtractTime($after_rest2, $last_atten) ;
// $list_early_out = subtractTime( $list_early_out, $rest_exclude_early_out ) ;
}
}
}
}else{
if ( $working['working_on'] == 'yes' && $list_type == 'normal' ){
$list_type_remark = 'AS' ;
$list_remark = 'Absent' ;
}
}
// inside into db
// start commit
$error = 0 ;
$mysqli->autocommit( false ) ;
try{
// check if normal working hours
if ( $list_work != '00:00:00' ){
// reset late
$count_total_less = 0 ;
$boolean_less = true ;
$rounding_less = $working['working_day_calculation'] ;
$get_list_early_out = $list_early_out ;
$reset_list_less = addTime($list_late, $get_list_early_out) ;
$reset_list_less = addTime($reset_list_less, $list_time_off) ;
if ( $list_leave_day == '0.5' ){
if ( $list_late > $list_early_out ){
$reset_list_less = subtractTime($reset_list_less, $total_rest_hours) ;
}
}
$reset_work = $working['working_total_hours'] ;
$reset_ot_normal = $list_ot_normal ;
if ( $reset_list_less != '00:00:00' && $reset_list_less > '00:01:00'){
$reset_list_less = subtractTime($reset_list_less, '00:01:00') ;
$rounding_less = ( $rounding_less != '00:00:00' ? $rounding_less : '00:01' ) ;
if ( $rounding_less <= $reset_list_less ){
while ( $boolean_less ){
$reset_list_less = subtractTime($reset_list_less, $rounding_less) ;
if ( $rounding_less > $reset_list_less ){
$boolean_less = false ;
}
$count_total_less++ ;
}
}
if ( $reset_list_less != '00:00:00' ){
$count_total_less++ ;
}
}
// check if local / oversea worker, 1 = local, else oversea
if ( $count_total_less > 0 ){
for ( $a = $count_total_less ; $a > 0 ; $a-- ){
// $deduct_from_day = true ;
// if ( $staff['country_id'] == '1' ){
// }else{
// if ( $working['working_if_ot'] == 'yes' && $reset_ot_normal != '00:00:00' ){
// $deduct_from_day = false ;
// }
// }
// // check if deduct from day or ot
// if ( $deduct_from_day ){
// }else{
// if ( $rounding_less > $reset_ot_normal ){
// $reset_ot_normal = '00:00:00' ;
// }else{
// $reset_ot_normal = subtractTime($reset_ot_normal, $rounding_less) ;
// }
// }
if ( $rounding_less > $reset_work ){
$reset_work = '00:00:00' ;
}else{
$reset_work = subtractTime($reset_work, $rounding_less) ;
}
}
}
// get working & ot day
if ( $reset_work != '00:00:00' ){
$reset_total_work = numberFormat( convertMinutes($working['working_total_hours']), 2 ) ;
$reset_work = numberFormat( convertMinutes($reset_work), 2 ) ;
$list_work_day += numberFormat( ( $reset_work / $reset_total_work ), 2 ) ;
$list_work_day = ( $list_leave_day == 0.5 ? 0.5 : ( $list_work_day > 0.5 ? 1 : ( $list_work_day > 0 ? 0.5 : 0 ) ) ) ;
}
if ( $reset_ot_normal != '00:00:00' ){
$explode_ot_normal = explode(':', $reset_ot_normal) ;
$list_ot_day = numberFormat ( ( $explode_ot_normal[0] . '.' . ( $explode_ot_normal[1] > 0 ? ( $explode_ot_normal[1] / 60 * 100 ) : '' ) ), 2 ) ;
}
}
// over x minutes just count as late
if ( $working['working_period_before'] > 0 ){
$count_late_minutes = convertToTimes($working['working_period_before']) ;
if ( $list_late != '00:00:00' ){
if ( $count_late_minutes > $list_late ){
$list_work = addTime($list_work, $list_late) ;
$list_late = '00:00:00' ;
}else{
$list_work = addTime($list_work, $count_late_minutes) ;
$list_late = subtractTime($list_late, $count_late_minutes) ;
}
}
}
// work_type_id == 3 mean part time job
if ( $list_type_remark == 'WD' && $staff['work_type_id'] == '3' ){
$list_type_remark = 'PT' ;
}
// check if abnormal attendance
if ( $list_late != '00:00:00' ){
$array_abnormal[] = $array_atten_ls[0] ;
}
if ( $list_early_out != '00:00:00' ){
$array_abnormal[] = end($array_atten_ls) ;
}
// if only work half day
$boolean_move_towork = false ;
if ( ( $list_work_day + $list_leave_day ) == '0.5' ){
if ( convertMinutes( $list_late ) > 0 ){
$list_work_day += 0.5 ;
if ( $working['working_rest_range_to'] != '00:00:00' ){
if ( $first_in_time >= $after_rest1 && $after_rest2 > $first_in_time && $list_late != '00:00:00' ){
$late_includerest = subtractTime( $after_rest2, $first_in_time ) ;
$list_late = subtractTime( $list_late, $late_includerest ) ;
}else{
$boolean_move_towork = true ;
}
}else{
$boolean_move_towork = true ;
}
}else{
$boolean_move_towork = true ;
}
}
if ( $boolean_move_towork ){
if ( $list_rest != '00:00:00' ){
$list_work = addTime($list_work, $list_rest) ;
}
$list_rest = '00:00:00' ;
$list_time_off = '00:00:00' ;
}
if ( $list_work_day == 0.5 && $list_leave_day == 0 ){
$list_work_day = 1 ;
}
// combine all working hours as ot
// if ( $working['working_direct_day'] == 'yes' ){
if ( $list_type_remark == 'OD' || $list_type_remark == 'HL' ){
$list_work_day = '0' ;
$list_ot_day = '0' ;
$list_work = '00:00:00' ;
$list_late = '00:00:00' ;
$list_early = '00:00:00' ;
$list_early_out = '00:00:00' ;
}
// if leave half day, then filter out late / early out
if ( $working['working_if_flexi'] == 'no' ){
if ( $list_type_remark == 'AL' || $list_type_remark == 'UL' || $list_type_remark == 'MC' ){
if ( $list_leave_day == '0.5' ){
$half_day_minutes = ( convertMinutes( $total_hours ) / 2 ) ;
$half_day_hours = convertToTimes( $half_day_minutes ) ;
if ( $list_late >= $half_day_hours ){
$list_late = subtractTime( $list_late, $half_day_hours ) ;
if ( $list_late >= $total_rest_hours ){
$list_late = subtractTime( $list_late, $total_rest_hours ) ;
}else{
$list_late = '00:00:00' ;
}
}else{
$list_late = '00:00:00' ;
}
if ( $list_early_out >= $half_day_hours ){
$list_early_out = subtractTime( $list_early_out, $half_day_hours ) ;
if ( $list_early_out >= $total_rest_hours ){
$list_early_out = subtractTime( $list_early_out, $total_rest_hours ) ;
}else{
$list_early_out = '00:00:00' ;
}
}else{
$list_early_out = '00:00:00' ;
}
}
}
}
if ( $working['working_rest_include_ot'] != '00:00:00' ){
if ( $list_rest != '00:00:00' ){
$temp_ot_rest = addTime( $list_ot_normal, $list_rest ) ;
if ( $working['working_rest_include_ot'] >= $temp_ot_rest ){
$list_ot_normal = $temp_ot_rest ;
$list_rest = '00:00:00' ;
}
}
}
if ( !$punchiscorrect ){
$list_work_day = 0 ;
$list_ot_day = 0 ;
$list_work = '00:00:00' ;
$list_rest = '00:00:00' ;
$list_rest_more = '00:00:00' ;
$list_time_off = '00:00:00' ;
$list_rest2 = '00:00:00' ;
$list_rest_more2 = '00:00:00' ;
$list_time_off2 = '00:00:00' ;
$list_early = '00:00:00' ;
$list_early_out = '00:00:00' ;
$list_late = '00:00:00' ;
$list_ot_normal = '00:00:00' ;
$array_abnormal = [] ;
}
// show log
echo 'staff : <br />' ;
foreach ( $staff as $kk => $vv ){
echo $kk . ' -> ' . $vv ;
echo '<br />' ;
}
echo '<br />' ;
echo '<br />' ;
echo 'array_atten : <br />' ;
foreach ( $array_atten as $kk => $vv ){
echo $kk . ' -> ' . $vv ;
echo '<br />' ;
}
echo '<br />' ;
echo '<br />' ;
echo 'array_abnormal : <br />' ;
foreach ( $array_abnormal as $kk => $vv ){
echo $kk . ' -> ' . $vv ;
echo '<br />' ;
}
echo '<br />' ;
echo '<br />' ;
echo 'working : <br />' ;
foreach ( $working as $kk => $vv ){
echo $kk . ' -> ' . $vv ;
echo '<br />' ;
}
echo '<br />' ;
echo '<br />' ;
echo 'staff_id -> ' . $staff_id ;
echo '<br />' ;
echo 'list_type -> ' . $list_type ;
echo '<br />' ;
echo 'list_date -> ' . $date_yesterday ;
echo '<br />' ;
echo 'list_work_day -> ' . $list_work_day ;
echo '<br />' ;
echo 'list_ot_day -> ' . $list_ot_day ;
echo '<br />' ;
echo 'list_leave_day -> ' . $list_leave_day ;
echo '<br />' ;
echo 'list_early -> ' . $list_early ;
echo '<br />' ;
echo 'list_early_out -> ' . $list_early_out ;
echo '<br />' ;
echo 'list_late -> ' . $list_late ;
echo '<br />' ;
echo 'list_rest -> ' . $list_rest ;
echo '<br />' ;
echo 'list_rest_more -> ' . $list_rest_more ;
echo '<br />' ;
echo 'list_time_off -> ' . $list_time_off ;
echo '<br />' ;
echo 'list_rest2 -> ' . $list_rest2 ;
echo '<br />' ;
echo 'list_rest_more2 -> ' . $list_rest_more2 ;
echo '<br />' ;
echo 'list_time_off2 -> ' . $list_time_off2 ;
echo '<br />' ;
echo 'list_type -> ' . $list_type ;
echo '<br />' ;
echo 'list_type_remark -> ' . $list_type_remark ;
echo '<br />' ;
echo 'list_remark -> ' . $list_remark ;
echo '<br />' ;
echo 'list_work -> ' . $list_work ;
echo '<br />' ;
echo 'list_ot_normal -> ' . $list_ot_normal ;
echo '<br />' ;
echo '<br />' ;
echo '<br />' ;
// exit ;
$list_insert = $mysqli->query("INSERT INTO staff_attendance_list
(staff_id, list_date, list_checkinout, created_at, updated_at, list_work_day, list_ot_day, list_leave_day, list_early, list_early_out, list_late, list_rest, list_rest_more, list_time_off, list_rest2, list_rest_more2, list_time_off2, list_type, list_type_remark, list_remark, list_work, list_ot_normal) VALUES
('".$staff_id."', '".$date_yesterday."', '".json_encode($array_atten)."', '".TODAYDATE."', '".TODAYDATE."', '".$list_work_day."', '".$list_ot_day."', '".$list_leave_day."', '".$list_early."', '".$list_early_out."', '".$list_late."', '".$list_rest."', '".$list_rest_more."', '".$list_time_off."', '".$list_rest2."', '".$list_rest_more2."', '".$list_time_off2."', '".$list_type."', '".$list_type_remark."', '".$list_remark."', '".$list_work."', '".$list_ot_normal."')") ;
if ( $mysqli->affected_rows > 0 ){
$last_insert = $mysqli->insert_id ;
if ( count($array_atten_ls) > 0 ){
foreach ( $array_atten_ls as $k_atten => $v_atten ){
$merge_insert = $mysqli->query("UPDATE staff_attendance SET
" . ( in_array($v_atten, $array_abnormal) ? "abnormal = 'yes'," : '' ) . "
list_id = '".$last_insert."',
check_group = '".$date_yesterday."'
WHERE attendance_id = '".$v_atten."' ") ;
if ( $mysqli->affected_rows > 0 ){ }else{
$error++ ;
}
}
}
}else{
$error++ ;
}
}catch( Exception $e ){
$error++;
}
if( $error == 0 ) {
// commit query
$mysqli->commit() ;
$status = '200' ;
$message = 'Success' ;
}else{
$mysqli->rollback() ;
$status = '300' ;
$message = 'Something error, please try again later.' ;
}
}
}
}
}
}
echo json_encode([
'status' => $status,
'message' => $message
]) ;
?>
+69
View File
@@ -0,0 +1,69 @@
<?php
// default config setting
$boolean_ssl_lock = true ;
include '../connect/cms-config.php' ;
include '../requires/function.php' ;
$current_times = date( "H:i:s", time() ) ;
$current_hours = date( "H", time() ) ;
$current_minutes = date( "m", time() ) ;
$day_before_3 = date( "Y-m-d", strtotime( "-3 days" ) ) ;
$day_before_4 = date( "Y-m-d", strtotime( "-4 days" ) ) ;
$today_day = date( "Y-m-d", time() ) ;
$today_datetime = date( "Ymd", time() ) ;
$search_query = "" ;
if ( $current_times > '09:40:00' && $current_times <= '14:40:00' ){
$search_query .= " AND a.created_at BETWEEN '" . $day_before_3 . " 09:30:00' AND '" . $today_day . " 14:29:59'" ;
$today_datetime .= '-1' ;
}else{
$search_query .= " AND a.created_at BETWEEN '" . $day_before_4 . " 14:30:00' AND '" . $today_day . " 09:29:59'" ;
$today_datetime .= '-2' ;
}
$mysqli_attendances = $mysqli->query( "SELECT a.created_at, b.staff_idno FROM staff_attendance a
LEFT JOIN staff b ON ( a.staff_id = b.staff_id )
WHERE a.deleted_at IS NULL AND CHAR_LENGTH(b.staff_idno) > 6 " . $search_query . "
ORDER BY a.created_at" ) ;
$filename = '../txt/' . $today_datetime . '.txt' ;
$file = fopen( $filename, "wb" ) ;
fwrite($fp,$content);
if ( $mysqli_attendances->num_rows > 0 ){
$count = 0 ;
$total = $mysqli_attendances->num_rows ;
while ( $row_attendances = $mysqli_attendances->fetch_assoc() ){
$count++ ;
$content = $row_attendances['staff_idno'] . '|' . date( 'Y-m-d', strtotime($row_attendances['created_at']) ) . '|' . date( 'H:i:s', strtotime($row_attendances['created_at']) ) ;
if ( $count != $total ){
$content .= "\n" ;
}
fwrite( $file, $content ) ;
}
}
fclose( $file ) ;
// header("Content-Description: File Transfer");
// header("Content-Type: application/octet-stream");
// header("Content-Disposition: attachment; filename=\"". basename($filename) ."\"") ;
// readfile ( $filename ) ;
exit ;
?>
@@ -0,0 +1,65 @@
<?php
// default config setting
$boolean_ssl_lock = true ;
include '../connect/cms-config.php' ;
include '../requires/function.php' ;
$current_times = date( "H:i:s", time() ) ;
$current_hours = date( "H", time() ) ;
$current_minutes = date( "m", time() ) ;
// $yesterday_day = ( $_GET['from'] != '' ? $_GET['from'] : date( "Y-m-d", strtotime( "-1 days" ) ) ) ;
$today_day = ( $_GET['from'] != '' ? $_GET['from'] : date( "Y-m-d", time() ) ) ;
$next_day = ( $_GET['to'] != '' ? $_GET['to'] : date( "Y-m-d", time() ) ) ;
$search_query = "" ;
$today_datetime = 'manual-export' ;
$search_query .= " AND a.created_at BETWEEN '" . $today_day . " 00:00:00' AND '" . $next_day . " 23:59:59'" ;
$mysqli_attendances = $mysqli->query( "SELECT a.created_at, b.staff_idno FROM staff_attendance a
LEFT JOIN staff b ON ( a.staff_id = b.staff_id )
WHERE a.deleted_at IS NULL AND CHAR_LENGTH(b.staff_idno) > 6 " . $search_query . "
ORDER BY a.created_at" ) ;
$filename = '../txt/' . $today_datetime . '.txt' ;
$file = fopen( $filename, "wb" ) ;
fwrite($fp,$content);
if ( $mysqli_attendances->num_rows > 0 ){
$count = 0 ;
$total = $mysqli_attendances->num_rows ;
while ( $row_attendances = $mysqli_attendances->fetch_assoc() ){
$count++ ;
$content = $row_attendances['staff_idno'] . '|' . date( 'Y-m-d', strtotime($row_attendances['created_at']) ) . '|' . date( 'H:i:s', strtotime($row_attendances['created_at']) ) ;
if ( $count != $total ){
$content .= "\n" ;
}
fwrite( $file, $content ) ;
}
}
fclose( $file ) ;
// header("Content-Description: File Transfer");
// header("Content-Type: application/octet-stream");
// header("Content-Disposition: attachment; filename=\"". basename($filename) ."\"") ;
// readfile ( $filename ) ;
echo '<a href="'.$filename.'" download>Download</a>' ;
exit ;
?>
+19
View File
@@ -0,0 +1,19 @@
<?php
// default config setting
$boolean_ssl_lock = true ;
include '../connect/cms-config.php' ;
include '../requires/function.php' ;
$staffs = $mysqli->query( "SELECT a.staff_id FROM staff a
WHERE a.deleted_at IS NULL AND ( a.staff_date_resigned >= '".date("Y-m-d",time())."' OR a.staff_date_resigned = '0000-00-00' OR a.staff_date_resigned IS NULL )" ) ;
if ( $staffs->num_rows > 0 ){
while ( $staff = $staffs->fetch_assoc() ){
setStaffLeaveYear( $staff['staff_id'] ) ;
}
}
?>
+157
View File
@@ -0,0 +1,157 @@
<?php
// default config setting
$boolean_ssl_lock = true ;
include '../connect/cms-config.php' ;
include '../requires/function.php' ;
$last_month = date( "Y-m", strtotime( "-1 month" ) ) ;
$last_monthday = $last_month . '-01' ;
$service_module = '' ;
$services = $mysqli->query( "SELECT a.module FROM app_service a
WHERE a.deleted_at IS NULL AND a.type = 'service' AND a.module IN ( 'Hr', 'HrBranch', 'HrManual' ) AND on_off = 'on'
LIMIT 1" ) ;
if ( $services->num_rows > 0 ){
$row_service = $services->fetch_assoc() ;
$service_module = $row_service['module'] ;
}
// get setting point
$array_setting_point = [ 'daily' => 0, 'monthly' => 0 ] ;
$select_setting_point = $mysqli->query( "SELECT point_type, point_value FROM setting_point
WHERE deleted_at IS NULL AND point_from = 'staff_point_monthly_report' AND point_type IN ( 'daily', 'monthly' ) AND difficulty = 'normal' " ) ;
if ( $select_setting_point->num_rows > 0 ){
while ( $row_setting_point = $select_setting_point->fetch_assoc() ){
$array_setting_point[$row_setting_point['point_type']] = $row_setting_point['point_value'] ;
}
}
// check record
$array_record = [] ;
$select_record = $mysqli->query( "SELECT staff_id, type FROM staff_point_monthly_report
WHERE deleted_at IS NULL AND type IN ( 'daily-attendance', 'monthly-attendance' ) AND given_date LIKE '%".$last_month."%'" ) ;
if ( $select_record->num_rows > 0 ){
while ( $row_record = $select_record->fetch_assoc() ){
$array_record[$row_record['staff_id']][$row_record['type']] = $row_record['staff_id'] ;
}
}
switch ( $service_module ){
case 'Hr' :
case 'HrBranch' :
// get working day
$list_workday = [] ;
$select_attendancelist = $mysqli->query("SELECT staff_id, list_type_remark, COUNT( list_type_remark ) as count_list_type_remark, SUM( list_work_day ) as sum_list_work_day, SUM( list_leave_day ) as sum_list_leave_day FROM staff_attendance_list
WHERE deleted_at IS NULL AND list_date LIKE '".$last_month."%'
GROUP BY staff_id, list_type_remark") ;
if ( $select_attendancelist->num_rows > 0 ){
while ( $row_attendancelist = $select_attendancelist->fetch_assoc() ){
$list_workday[$row_attendancelist['staff_id']][$row_attendancelist['list_type_remark']] = $row_attendancelist ;
}
}
foreach ( $list_workday as $kwork => $vwork ){
$staff_id = $kwork ;
$total_realwork = floor( ( $vwork['WD'] != null ? $vwork['WD']['sum_list_work_day'] : 0 ) + 0 ) ;
$total_workday = 0 ;
foreach ( [ 'WD', 'PT', 'AL', 'MC', 'UL', 'AS' ] as $ktype => $vtype ){
if ( $vwork[$vtype] != null ){
$total_workday += $vwork[$vtype]['count_list_type_remark'] ;
}
}
if ( $array_record[$staff_id]['daily-attendance'] == null ){
if ( $total_realwork > 0 ){
$point_value = $array_setting_point['daily'] ;
$point_total = ( $total_realwork * $point_value ) ;
$point_total_minus1day = ( $point_total - $point_value ) ;
$remark = 'System auto given daily attendance point ( '.$total_realwork.' days * '.$point_value.' points = '.$point_total.' points )' ;
$mysqli->query( "INSERT INTO staff_point_monthly_report
( staff_id, type, remark, given_date, times, given_point ) VALUES
( '".$staff_id."', 'daily-attendance', '".$remark."', '".$last_monthday."', '".$total_realwork."', '".$point_value."' )" ) ;
$report_id = $mysqli->insert_id ;
pointMovement( 'staff_point_monthly_report', $report_id, 'daily', 'normal', $staff_id, $point_total_minus1day, $remark ) ;
}
}
if ( $array_record[$staff_id]['monthly-attendance'] == null ){
if ( $total_realwork > 0 && $total_realwork == $total_workday ){
$point_value = $array_setting_point['monthly'] ;
$remark = 'System auto given monthly attendance point ( '.$total_workday.' days, '.$point_value.' points )' ;
$mysqli->query( "INSERT INTO staff_point_monthly_report
( staff_id, type, remark, given_date, times, given_point ) VALUES
( '".$staff_id."', 'monthly-attendance', '".$remark."', '".$last_monthday."', '".$total_workday."', '".$point_value."' )" ) ;
$report_id = $mysqli->insert_id ;
pointMovement( 'staff_point_monthly_report', $report_id, 'monthly', 'normal', $staff_id, 0, $remark ) ;
}
}
}
break ;
case 'HrManual' :
$staff_ids = [] ;
$select_manual = $mysqli->query( "SELECT staff_id FROM staff_attendance_manual
WHERE deleted_at IS NULL AND attendance_date LIKE '%".$last_month."%'" ) ;
if ( $select_manual->num_rows > 0 ){
while ( $row_manual = $select_manual->fetch_assoc() ){
$staff_ids[] = $row_manual['staff_id'] ;
}
}
if ( count($staff_ids) ){
foreach ( $staff_ids as $kstaff => $vstaff ){
$staff_id = $vstaff ;
if ( $array_record[$staff_id]['monthly-attendance'] == null ){
$point_value = $array_setting_point['monthly'] ;
$remark = 'System auto given monthly attendance point ( '.$point_value.' points )' ;
$mysqli->query( "INSERT INTO staff_point_monthly_report
( staff_id, type, remark, given_date, times, given_point ) VALUES
( '".$staff_id."', 'monthly-attendance', '".$remark."', '".$last_monthday."', '1', '".$point_value."' )" ) ;
$report_id = $mysqli->insert_id ;
pointMovement( 'staff_point_monthly_report', $report_id, 'monthly', 'normal', $staff_id, 0, $remark ) ;
}
}
}
break ;
}
?>
+167
View File
@@ -0,0 +1,167 @@
<?php
// default config setting
$boolean_ssl_lock = true ;
include '../connect/cms-config.php' ;
include '../requires/function.php' ;
$last_month = date( "Y-m", strtotime( "-1 month" ) ) ;
$last_monthday = $last_month . '-01' ;
// get setting point
$array_setting_point = [ 'monthly-compliment' => 0, 'monthly-task' => 0 ] ;
$select_setting_point = $mysqli->query( "SELECT point_type, point_value FROM setting_point
WHERE deleted_at IS NULL AND point_from = 'staff_point_monthly_report' AND point_type IN ( 'monthly-compliment', 'monthly-task' ) AND difficulty = 'normal' " ) ;
if ( $select_setting_point->num_rows > 0 ){
while ( $row_setting_point = $select_setting_point->fetch_assoc() ){
$array_setting_point[$row_setting_point['point_type']] = $row_setting_point['point_value'] ;
}
}
// check record
$array_record = [] ;
$select_record = $mysqli->query( "SELECT staff_id, type FROM staff_point_monthly_report
WHERE deleted_at IS NULL AND type IN ( 'monthly-compliment', 'monthly-task' ) AND given_date LIKE '%".$last_month."%'" ) ;
if ( $select_record->num_rows > 0 ){
while ( $row_record = $select_record->fetch_assoc() ){
$array_record[$row_record['staff_id']][$row_record['type']] = $row_record['staff_id'] ;
}
}
// get all staff
$staffs = [] ;
$staffs_q = $mysqli->query("SELECT staff_id, staff_idno, staff_name 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 )") ;
if ( $staffs_q->num_rows > 0 ){
while ( $row_staff = $staffs_q->fetch_assoc() ){
$staffs[] = $row_staff ;
}
}
// - compliment
// ·一个月内被加了最少五次分,并且同时没有被扣过任何的分数,就能拿到额外的30分(每个月30分)
// ·每个月一号计算上个月的数据(auto)
$adjustments = [] ;
$select_adjustment = $mysqli->query( "SELECT a.staff_id, b.adjustment_type, count(b.adjustment_type) as total_adjustment_type FROM staff_adjustment_point a
LEFT JOIN staff_adjustment b ON ( a.adjustment_id = b.adjustment_id )
WHERE a.deleted_at IS NULL AND b.deleted_at IS NULL AND b.created_at LIKE '%".$last_month."%'
GROUP BY a.staff_id, b.adjustment_type" ) ;
if ( $select_adjustment->num_rows > 0 ){
while ( $row_adjustment = $select_adjustment->fetch_assoc() ){
$adjustments[$row_adjustment['staff_id']][$row_adjustment['adjustment_type']] = $row_adjustment['total_adjustment_type'] ;
}
}
// - task
// ·一个月内最少完成三个task(在deadline之前),就能获得50分(每个月50分)
// ·每个月一号计算上个月的数据(auto)
$tasks = [] ;
$select_task = $mysqli->query( "SELECT a.task_id, a.assigned_by, ( SELECT GROUP_CONCAT( DISTINCT(staff_id) ) FROM task_joinstaff WHERE task_id = a.task_id ) as executed_by FROM task a
WHERE a.deleted_at IS NULL AND a.status = 'approved' AND a.is_late = 'no' AND a.updated_at LIKE '%".$last_month."%'" ) ;
if ( $select_task->num_rows > 0 ){
while ( $row_task = $select_task->fetch_assoc() ){
$executed_by = $row_task['executed_by'] ;
$executeds = ( $executed_by != null ? explode( ',', $executed_by ) : [] ) ;
if ( $row_task['assigned_by'] > 0 ){
if ( !in_array( $row_task['assigned_by'], $executeds ) ){
$tasks[$row_task['assigned_by']][] = $row_task['task_id'] ;
}
}
foreach ( $executeds as $kexecuted => $vexecuted ){
$tasks[$vexecuted][] = $row_task['task_id'] ;
}
}
}
// - improvement
// ·给出有用的suggestion就能获得额外的60分(每三个月60分)
// ·每个月一号计算上个月的数据(auto)
// $suggestions = [] ;
// $select_suggestion = $mysqli->query( "SELECT staff_id, count(suggestion_id) as total_suggestion FROM suggestion
// WHERE deleted_at IS NULL AND type = 'improvement-plan' AND status = 'confirmed' AND updated_at LIKE '%".$last_month."%'
// GROUP BY staff_id" ) ;
// if ( $select_suggestion->num_rows > 0 ){
// while ( $row_suggestion = $select_suggestion->fetch_assoc() ){
// $suggestions[$row_suggestion['staff_id']] = $row_suggestion['total_suggestion'] ;
// }
// }
// start running report
foreach ( $staffs as $kstaff => $vstaff ){
$staff_id = $vstaff['staff_id'] ;
// adjustment given (compliment)
if ( $array_record[$staff_id]['monthly-compliment'] == null ){
$get_adjustment = $adjustments[$staff_id] ;
if ( $get_adjustment != null ){
if ( $get_adjustment['minus'] == null && $get_adjustment['plus'] != null ){
if ( $get_adjustment['plus'] >= 5 ){
$point_value = $array_setting_point['monthly-compliment'] ;
$remark = 'System auto given monthly compliment point ( '.$point_value.' points )' ;
$mysqli->query( "INSERT INTO staff_point_monthly_report
( staff_id, type, remark, given_date, times, given_point ) VALUES
( '".$staff_id."', 'monthly-compliment', '".$remark."', '".$last_monthday."', '1', '".$point_value."' )" ) ;
$report_id = $mysqli->insert_id ;
pointMovement( 'staff_point_monthly_report', $report_id, 'monthly-compliment', 'normal', $staff_id, 0, $remark ) ;
}
}
}
}
// task given
if ( $array_record[$staff_id]['monthly-task'] == null ){
$get_task = $tasks[$staff_id] ;
if ( $get_task != null ){
if ( count($get_task) >= 3 ){
$point_value = $array_setting_point['monthly-task'] ;
$remark = 'System auto given monthly task point ( '.$point_value.' points )' ;
$mysqli->query( "INSERT INTO staff_point_monthly_report
( staff_id, type, remark, given_date, times, given_point ) VALUES
( '".$staff_id."', 'monthly-task', '".$remark."', '".$last_monthday."', '1', '".$point_value."' )" ) ;
$report_id = $mysqli->insert_id ;
pointMovement( 'staff_point_monthly_report', $report_id, 'monthly-task', 'normal', $staff_id, 0, $remark ) ;
}
}
}
}
?>
+241
View File
@@ -0,0 +1,241 @@
<?php
// default config setting
$boolean_ssl_lock = true ;
include '../connect/cms-config.php' ;
include '../requires/function.php' ;
$today_date = date('Y-m-d');
// $today_date = '2023-04-01';
//get setting generate slip for current or previous month
$setting_month = 'current';
$query_setting = $mysqli->query("SELECT * FROM setting_salary_tax WHERE tax_type = 'slip_month_setting' LIMIT 1");
if(mysqli_num_rows($query_setting) > 0){
$result_setting = mysqli_fetch_assoc($query_setting);
$setting_month = $result_setting['tax_title'];
}
if($setting_month == 'current'){
$month = date('Y-m-01', strtotime($today_date));
}else if($setting_month == 'previous'){
$temp_month = date('Y-m-01', strtotime($today_date));
$month = date('Y-m-01', strtotime($temp_month. ' - 1 months'));
}
$query_staff = $mysqli->query("SELECT * FROM staff WHERE deleted_at is NULL");
if(mysqli_num_rows($query_staff) > 0){
//get all tax rate and store
$tax_rate = [];
$query_tax_rate = $mysqli->query("SELECT * FROM setting_salary_tax WHERE deleted_at is NULL");
while($row_tax = mysqli_fetch_assoc($query_tax_rate)){
$tax_rate[$row_tax['tax_id']] = $row_tax;
}
while($row = mysqli_fetch_assoc($query_staff)){
$staff_id = $row['staff_id'];
$staff_idno = $row['staff_idno'];
$basic_salary = $row['staff_salary'];
$epf_rate_id = $row['staff_epf_rate_id'];
$socso_rate_id = $row['staff_socso_rate_id'];
$eis_rate_id = $row['staff_eis_rate_id'];
$zakat_rate_id = $row['staff_zakat_rate_id'];
$tax_status_id = $row['tax_status_id']; //pcb category, resident, non-resident, no tax
$staff_epf_rate = $tax_rate[$epf_rate_id]['employee_rate'];
$employer_epf_rate = $tax_rate[$epf_rate_id]['employer_rate'];
$staff_socso_rate = $tax_rate[$socso_rate_id]['employee_rate'];
$employer_socso_rate = $tax_rate[$socso_rate_id]['employer_rate'];
$staff_eis_rate = $tax_rate[$eis_rate_id]['employee_rate'];
$employer_eis_rate = $tax_rate[$eis_rate_id]['employer_rate'];
$staff_zakat_rate = $tax_rate[$zakat_rate_id]['employee_rate'];
$employer_zakat_rate = $tax_rate[$zakat_rate_id]['employer_rate'];
$socso_category_id = $row['socso_category_id'];
$eis_status = $row['staff_eis_status'];
$birthday = $row['staff_birthdate'];
if($birthday == NULL || $birthday == '0000-00-00'){
$age = 0;
}else{
$birthDate = date("Y",strtotime($birthday));
$age = date("Y") - $birthDate;
}
$country_id = $row['country_id'];
$query_country = $mysqli->query("SELECT country_desc FROM master_country WHERE country_id = '$country_id' LIMIT 1");
$country = mysqli_fetch_assoc($query_country)['country_desc'];
if($country == 'MALAYSIA'){
$citizen = 'yes';
}else{
$citizen = 'yes';
}
$staff_settings = $row['staff_settings'] ;
if ( $staff_settings != '' ){
$staff_settings = JsonEncodeDecode('decode', $staff_settings) ;
}else{
$staff_settings = [] ;
}
$marital_status = $staff_settings['marital_status'];
$num_children = $staff_settings['no_children'];
$spouse_working = $staff_settings['spouse_working'];
//for kindlemind
$query_commission_temp = $mysqli->query("SELECT * FROM staff_commission_temp WHERE staff_id='$staff_idno' AND month='$month' LIMIT 1");
if(mysqli_num_rows($query_commission_temp) > 0){
$commission = mysqli_fetch_assoc($query_commission_temp)['commission'];
}else{
$commission = 0;
}
$allowance = $row['staff_allowance_topup'] + $row['staff_allowance_work'] + $row['staff_allowance_food'];
//calculate epf, socso, eis, pcb
$staff_epf = 0;
$staff_socso = 0;
$staff_eis = 0;
$staff_zakat = 0;
$staff_pcb = 0;
$employer_epf = 0;
$employer_socso = 0;
$employer_eis = 0;
$employer_zakat = 0;
$employer_pcb = 0;
$deduction = 0;
$gross_total = $basic_salary + $commission + $allowance;
//calculate pcb tax
$boolean_pcb = true;
if($row['tax_status_id'] == 1){
if($marital_status == 'Single' || $marital_status == 'Divorced' || $marital_status == 'Widow'){
$category = 1;
$category2 = 'B';
}else if($marital_status == 'Married'){
if($num_children == '' || $num_children == 0){
$category2 = 'K';
}else{
$category2 = 'KA'.$num_children;
}
if($spouse_working == 'Yes'){
$category = 3;
}else{
$category = 2;
}
}else{
$boolean_pcb = false;
}
}else{
$boolean_pcb = false;
}
if($boolean_pcb){
$pcb = calculateTax('pcb', $gross_total, $category, $category2);
}else{
$pcb = 0;
}
$staff_pcb = $pcb;
//calculate pcb tax end
//calculate epf tax
if($staff_epf_rate == '11'){
$epf_array = calculateTaxEPF('epf', $gross_total, $age, $citizen);
}else if($staff_epf_rate == '9'){
$epf_array = calculateTaxEPF('epf', $gross_total, $age, $citizen);
}else if($staff_epf_rate == '0' || $staff_epf_rate == ''){
$epf_array = [];
}
if($epf_array['staff_epf']!= ''){
$staff_epf = $epf_array['staff_epf'];
}
if($epf_array['employer_epf']!= ''){
$employer_epf = $epf_array['employer_epf'];
}
//calculate epf tax end
//calculate socso tax
if($socso_category_id == 1){
$socso_array = calculateTaxSOCSO('socso', $gross_total, $socso_category_id);
}else if($socso_category_id == 2){
$socso_array = calculateTaxSOCSO('socso', $gross_total, $socso_category_id);
}else{
$socso_array = [];
}
if($socso_array['staff_socso']!= ''){
$staff_socso = $socso_array['staff_socso'];
}
if($socso_array['employer_socso']!= ''){
$employer_socso = $socso_array['employer_socso'];
}
//calculate socso tax end
//calculate eis tax
if($eis_status == 1){
$eis_array = calculateTaxEIS('eis', $gross_total);
}else{
$eis_array = [];
}
if($eis_array['staff_eis']!= ''){
$staff_eis = $eis_array['staff_eis'];
}
if($eis_array['employer_eis']!= ''){
$employer_eis = $eis_array['employer_eis'];
}
//calculate eis tax end
//calculate zakat fund
if($staff_zakat_rate > 0){
$staff_zakat = calculateTaxZAKAT($gross_total, $staff_zakat_rate);
}
//calculate zakat fund end
$subtotal = $basic_salary + $commission + $allowance ;
$total = $basic_salary + $commission + $allowance - $staff_epf - $staff_socso - $staff_eis - $staff_zakat - $staff_pcb ;
$query_salary_slip = $mysqli->query("SELECT slip_id FROM salary_slip WHERE staff_id = '$staff_id' AND month = '$month' LIMIT 1");
if(mysqli_num_rows($query_salary_slip) <= 0){
$insert = $mysqli->query("INSERT INTO salary_slip ( staff_id, basic_salary, commission, allowance, staff_epf, staff_socso, staff_eis, staff_zakat, staff_pcb, employer_epf, employer_socso, employer_eis, employer_zakat, employer_pcb, deduction, deduction_reason, status, sub_total, total, month ) VALUES ( '$staff_id', '$basic_salary', '$commission', '$allowance', '$staff_epf', '$staff_socso', '$staff_eis', '$staff_zakat', '$staff_pcb', '$employer_epf', '$employer_socso', '$employer_eis', '$employer_zakat', '$employer_pcb', '$deduction', '', 'active', '$subtotal', '$total', '$month' )");
if($insert){
$slip_id = $mysqli->insert_id;
$mysqli->query("INSERT INTO setting_slip_tax( slip_id, staff_epf_rate, employer_epf_rate, age, country_id, staff_socso_rate, employer_socso_rate, socso_category_id, staff_eis_rate, employer_eis_rate, staff_eis_status, staff_zakat_rate, employer_zakat_rate, tax_status_id, marital_status, spouse_working, num_children ) VALUES ( '$slip_id', '$staff_epf_rate', '$employer_epf_rate', '$age', '$country_id', '$staff_socso_rate', '$employer_socso_rate', '$socso_category_id', '$staff_eis_rate', '$employer_eis_rate', '$eis_status', '$staff_zakat_rate', '$employer_zakat_rate', '$tax_status_id', '$marital_status', '$spouse_working', '$num_children')");
}
}
}
}
?>
@@ -0,0 +1,106 @@
<?php
// default config setting
$boolean_ssl_lock = true ;
include '../connect/cms-config.php' ;
include '../requires/function.php' ;
$current_month = date( "m", time() ) ;
$date_from = date( "Y-m-01", strtotime( "-3 months" ) ) ;
$date_to = date( "Y-m-t", strtotime( "-1 months" ) ) ;
$last_month = date( "Y-m", strtotime( $date_to ) ) ;
$last_monthday = $last_month . '-01' ;
// running season report, calculate the report base on month
// 1 ( 10,11,12 )
// 4 ( 1,2,3 )
// 7 ( 4,5,6 )
// 10 ( 7,8,9 )
if ( $current_month == 1 || $current_month == 4 || $current_month == 7 || $current_month == 10 ){
// get setting point
$array_setting_point = [ 'seasonly-improvement' => 0 ] ;
$select_setting_point = $mysqli->query( "SELECT point_type, point_value FROM setting_point
WHERE deleted_at IS NULL AND point_from = 'staff_point_monthly_report' AND point_type IN ( 'seasonly-improvement' ) AND difficulty = 'normal' " ) ;
if ( $select_setting_point->num_rows > 0 ){
while ( $row_setting_point = $select_setting_point->fetch_assoc() ){
$array_setting_point[$row_setting_point['point_type']] = $row_setting_point['point_value'] ;
}
}
// check record
$array_record = [] ;
$select_record = $mysqli->query( "SELECT staff_id, type FROM staff_point_monthly_report
WHERE deleted_at IS NULL AND type IN ( 'seasonly-improvement' ) AND given_date LIKE '%".$last_month."%'" ) ;
if ( $select_record->num_rows > 0 ){
while ( $row_record = $select_record->fetch_assoc() ){
$array_record[$row_record['staff_id']][$row_record['type']] = $row_record['staff_id'] ;
}
}
// get all staff
$staffs = [] ;
$staffs_q = $mysqli->query("SELECT staff_id, staff_idno, staff_name 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 )") ;
if ( $staffs_q->num_rows > 0 ){
while ( $row_staff = $staffs_q->fetch_assoc() ){
$staffs[] = $row_staff ;
}
}
// - improvement
// ·给出有用的suggestion就能获得额外的60分(每三个月60分)
// ·每个月一号计算上个月的数据(auto)
$suggestions = [] ;
$select_suggestion = $mysqli->query( "SELECT staff_id, count(suggestion_id) as total_suggestion FROM suggestion
WHERE deleted_at IS NULL AND type = 'improvement-plan' AND status = 'confirmed' AND updated_at BETWEEN '".$date_from." 00:00:00' AND '".$date_to." 23:59:59'
GROUP BY staff_id" ) ;
if ( $select_suggestion->num_rows > 0 ){
while ( $row_suggestion = $select_suggestion->fetch_assoc() ){
$suggestions[$row_suggestion['staff_id']] = $row_suggestion['total_suggestion'] ;
}
}
// start running report
foreach ( $staffs as $kstaff => $vstaff ){
$staff_id = $vstaff['staff_id'] ;
// adjustment given (compliment)
if ( $array_record[$staff_id]['seasonly-improvement'] == null ){
$get_suggestion = $suggestions[$staff_id] ;
if ( $get_suggestion != null ){
if ( $get_suggestion >= 1 ){
$point_value = $array_setting_point['seasonly-improvement'] ;
$remark = 'System auto given seasonly improvement point ( '.$point_value.' points )' ;
$mysqli->query( "INSERT INTO staff_point_monthly_report
( staff_id, type, remark, given_date, times, given_point ) VALUES
( '".$staff_id."', 'seasonly-improvement', '".$remark."', '".$last_monthday."', '1', '".$point_value."' )" ) ;
$report_id = $mysqli->insert_id ;
pointMovement( 'staff_point_monthly_report', $report_id, 'seasonly-improvement', 'normal', $staff_id, 0, $remark ) ;
}
}
}
}
}
?>
@@ -0,0 +1,130 @@
<?php
// default config setting
$boolean_ssl_lock = true ;
include '../connect/cms-config.php' ;
include '../requires/function.php' ;
$current_month = date( "m", time() ) ;
$date_from = date( "Y-m-01", strtotime( "-3 months" ) ) ;
$date_to = date( "Y-m-t", strtotime( "-1 months" ) ) ;
$last_month = date( "Y-m", strtotime( $date_to ) ) ;
$last_monthday = $last_month . '-01' ;
// running season report, calculate the report base on month
// 1 ( 10,11,12 )
// 4 ( 1,2,3 )
// 7 ( 4,5,6 )
// 10 ( 7,8,9 )
if ( $current_month == 1 || $current_month == 4 || $current_month == 7 || $current_month == 10 || $current_month == 2 ){
// get setting point
$array_setting_point = [ 'seasonly-improvement' => 0, 'seasonly-summary' => 0 ] ;
$select_setting_point = $mysqli->query( "SELECT point_type, point_value FROM setting_point
WHERE deleted_at IS NULL AND point_from = 'staff_point_monthly_report' AND point_type IN ( 'seasonly-improvement', 'seasonly-summary' ) AND difficulty = 'normal' " ) ;
if ( $select_setting_point->num_rows > 0 ){
while ( $row_setting_point = $select_setting_point->fetch_assoc() ){
$array_setting_point[$row_setting_point['point_type']] = $row_setting_point['point_value'] ;
}
}
// check record
$array_record = [] ;
$select_record = $mysqli->query( "SELECT staff_id, type FROM staff_point_monthly_report
WHERE deleted_at IS NULL AND type IN ( 'seasonly-improvement', 'seasonly-summary' ) AND given_date LIKE '%".$last_month."%'" ) ;
if ( $select_record->num_rows > 0 ){
while ( $row_record = $select_record->fetch_assoc() ){
$array_record[$row_record['staff_id']][$row_record['type']] = $row_record['staff_id'] ;
}
}
// get all staff
$staffs = [] ;
$staffs_q = $mysqli->query("SELECT staff_id, staff_idno, staff_name 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 )") ;
if ( $staffs_q->num_rows > 0 ){
while ( $row_staff = $staffs_q->fetch_assoc() ){
$staffs[] = $row_staff ;
}
}
// - improvement
// ·给出有用的suggestion就能获得额外的60分(每三个月60分)
// ·每个月一号计算上个月的数据(auto)
$suggestions = [] ;
$select_suggestion = $mysqli->query( "SELECT staff_id, count(suggestion_id) as total_suggestion FROM suggestion
WHERE deleted_at IS NULL AND type = 'improvement-plan' AND status = 'confirmed' AND updated_at BETWEEN '".$date_from." 00:00:00' AND '".$date_to." 23:59:59'
GROUP BY staff_id" ) ;
if ( $select_suggestion->num_rows > 0 ){
while ( $row_suggestion = $select_suggestion->fetch_assoc() ){
$suggestions[$row_suggestion['staff_id']] = $row_suggestion['total_suggestion'] ;
}
}
// start running report
foreach ( $staffs as $kstaff => $vstaff ){
$staff_id = $vstaff['staff_id'] ;
// adjustment given (compliment)
if ( $array_record[$staff_id]['seasonly-improvement'] == null ){
$get_suggestion = $suggestions[$staff_id] ;
if ( $get_suggestion != null ){
if ( $get_suggestion >= 1 ){
$point_value = $array_setting_point['seasonly-improvement'] ;
$remark = 'System auto given seasonly improvement point ( '.$point_value.' points )' ;
$mysqli->query( "INSERT INTO staff_point_monthly_report
( staff_id, type, remark, given_date, times, given_point ) VALUES
( '".$staff_id."', 'seasonly-improvement', '".$remark."', '".$last_monthday."', '1', '".$point_value."' )" ) ;
$report_id = $mysqli->insert_id ;
pointMovement( 'staff_point_monthly_report', $report_id, 'seasonly-improvement', 'normal', $staff_id, 0, $remark ) ;
}
}
}
// task given
// if ( $array_record[$staff_id]['seasonly-summary'] == null ){
// $get_task = $tasks[$staff_id] ;
// if ( $get_task != null ){
// if ( count($get_task) >= 3 ){
// $point_value = $array_setting_point['monthly-task'] ;
// $remark = 'System auto given monthly task point ( '.$point_value.' points )' ;
// $mysqli->query( "INSERT INTO staff_point_monthly_report
// ( staff_id, type, remark, given_date, times, given_point ) VALUES
// ( '".$staff_id."', 'monthly-task', '".$remark."', '".$last_monthday."', '1', '".$point_value."' )" ) ;
// $report_id = $mysqli->insert_id ;
// pointMovement( 'staff_point_monthly_report', $report_id, 'monthly-task', 'normal', $staff_id, 0, $remark ) ;
// }
// }
// }
}
}
?>
+109
View File
@@ -0,0 +1,109 @@
<?php
// default config setting
$boolean_ssl_lock = true ;
include '../connect/cms-config.php' ;
include '../requires/function.php' ;
$current_month = date( "m", time() ) ;
$date_from = date( "Y-m-01", strtotime( "-3 months" ) ) ;
$date_to = date( "Y-m-t", strtotime( "-1 months" ) ) ;
$last_month = date( "Y-m", strtotime( $date_to ) ) ;
$last_monthday = $last_month . '-01' ;
// running season report, calculate the report base on month
// 1 ( 10,11,12 )
// 4 ( 1,2,3 )
// 7 ( 4,5,6 )
// 10 ( 7,8,9 )
if ( $current_month == 1 || $current_month == 4 || $current_month == 7 || $current_month == 10 ){
// get setting point
$array_setting_point = [ 'seasonly-summary' => 0 ] ;
$select_setting_point = $mysqli->query( "SELECT point_type, point_value FROM setting_point
WHERE deleted_at IS NULL AND point_from = 'staff_point_monthly_report' AND point_type IN ( 'seasonly-summary' ) AND difficulty = 'normal' " ) ;
if ( $select_setting_point->num_rows > 0 ){
while ( $row_setting_point = $select_setting_point->fetch_assoc() ){
$array_setting_point[$row_setting_point['point_type']] = $row_setting_point['point_value'] ;
}
}
// check record
$array_record = [] ;
$select_record = $mysqli->query( "SELECT staff_id, type FROM staff_point_monthly_report
WHERE deleted_at IS NULL AND type IN ( 'seasonly-summary' ) AND given_date LIKE '%".$last_month."%'" ) ;
if ( $select_record->num_rows > 0 ){
while ( $row_record = $select_record->fetch_assoc() ){
$array_record[$row_record['staff_id']][$row_record['type']] = $row_record['staff_id'] ;
}
}
// get all staff
$staffs = [] ;
$staffs_q = $mysqli->query("SELECT staff_id, staff_idno, staff_name 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 )") ;
if ( $staffs_q->num_rows > 0 ){
while ( $row_staff = $staffs_q->fetch_assoc() ){
$staffs[] = $row_staff ;
}
}
// 'monthly-attendance', 'monthly-compliment', 'monthly-task', 'seasonly-improvement'
// the total should be 10 by each staff
$summaries = [] ;
$select_summary = $mysqli->query( "SELECT staff_id, count(report_id) as total_summary FROM staff_point_monthly_report
WHERE deleted_at IS NULL AND type IN ( 'monthly-attendance', 'monthly-compliment', 'monthly-task', 'seasonly-improvement' ) AND given_date BETWEEN '".$date_from." 00:00:00' AND '".$date_to." 23:59:59'
GROUP BY staff_id" ) ;
if ( $select_summary->num_rows > 0 ){
while ( $row_summary = $select_summary->fetch_assoc() ){
$summaries[$row_summary['staff_id']] = $row_summary['total_summary'] ;
}
}
// start running report
foreach ( $staffs as $kstaff => $vstaff ){
$staff_id = $vstaff['staff_id'] ;
// adjustment given (compliment)
if ( $array_record[$staff_id]['seasonly-summary'] == null ){
$get_summary = $summaries[$staff_id] ;
if ( $get_summary != null ){
if ( $get_summary >= 10 ){
$point_value = $array_setting_point['seasonly-summary'] ;
$remark = 'System auto given seasonly summary point ( '.$point_value.' points )' ;
$mysqli->query( "INSERT INTO staff_point_monthly_report
( staff_id, type, remark, given_date, times, given_point ) VALUES
( '".$staff_id."', 'seasonly-summary', '".$remark."', '".$last_monthday."', '1', '".$point_value."' )" ) ;
$report_id = $mysqli->insert_id ;
pointMovement( 'staff_point_monthly_report', $report_id, 'seasonly-summary', 'normal', $staff_id, 0, $remark ) ;
}
}
}
}
}
?>
+46
View File
@@ -0,0 +1,46 @@
<?php
include '../connect/cms-config.php' ;
include '../requires/function.php' ;
$staffs_q = $mysqli->query("SELECT staff_id, staff_star, staff_point_achievement, staff_achievement 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 )") ;
if ( $staffs_q->num_rows > 0 ){
$yesterday_day = date( 'Y-m-d', strtotime( '-1 days' ) ) ;
while ( $staff = $staffs_q->fetch_assoc() ){
$staff_id = $staff['staff_id'] ;
$staff_star = $staff['staff_star'] ;
$staff_point_achievement = $staff['staff_point_achievement'] ;
$staff_achievement = $staff['staff_achievement'] ;
$mysqli->query( "INSERT INTO staff_monthly_achievement
( reported_at, staff_id, staff_point_achievement, staff_star, staff_achievement ) VALUES
( '".$yesterday_day."', '".$staff_id."', '".$staff_point_achievement."', '".$staff_star."', '".$staff_achievement."' )" ) ;
$staff_point_achievement = ( $staff_point_achievement <= 0 ? $staff_point_achievement : 0 ) ;
$mysqli->query( "UPDATE staff SET
staff_star = '0',
staff_point_achievement = '".$staff_point_achievement."'
WHERE staff_id = '".$staff_id."'" ) ;
}
}
?>
@@ -0,0 +1,13 @@
{
"type": "service_account",
"project_id": "hr-system-b0af6",
"private_key_id": "5bcb3596d437019f95b9d43e6a47c5456f9a8638",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCouTmCxNvs14t6\nG0wZCb6lg2jOQG/cVzh1PPK38jDp88ehfljtvaCQx9ZXWrANnAZVqN9ufaL5zBS7\noT3Q6u7hO+9sakyrf70gzqgEgXEFs8Wa7/JHqChMPUmJoaDWhf/CEKGdeMGyBj4P\n9/Qt7TyQqDSpzKndx0raAVdQtybNKUrwNFO9RB7AOjuKU3FhDUKiFCZp4SllmPsJ\ntvUt3Wn/ItPhzRZLdcCR0P5+S71prwwu/5u8Xk/f1+OsC2Zgw5G62ztqbOOj4xUc\neWr6J66D0jNwBKPhf2vTINAdxzGQGiRD9iSOefP3499v+cbsUNx3Bce6lNgSJCt9\nPpz74309AgMBAAECggEABChkWWuee8yn/D9V9bv+vbdqSsLdvtFLa+AvnwbR28IN\nJlalvF4S6d5y0r5CXmN86Hl74A4qiPtVe3YyvsY7UsOWV9aawxMnxvowu8Ow1FIk\nyXemQcvMCmzsNf8Mppywu8iLIwVJyKhMuToEA2m4N1xdx91qRjPWDV9BFpUc2Ktk\nilC8YMobwiZYKyrtHH5m9eJCtdaUs4zRa1Ur0g+LFMpOh2O3g+eC+YDdN7mP6Bky\nErs403DVItMkFC82A8xLvhq5MLDPKcx6YFAlsXe/gNClhJ/lvG7OeX1aqDOqtm+U\ntA71sZXRh0qZ79hbKB5FQjropmNrg8yAIJ0nnNieRQKBgQDkhYvyg575yDGtgvGk\nGl7HTfzQg5YbarAAFgk3fw7pxrldUz70KsaGc2ixj4SXc24q8DMY2HQlGNYXBDZX\n29+pW2EE/HYlO0EY3ANj9ma1zwh/qB7SnC1eCpQ07q1qhadOfc/VhMICjuXAgN51\n63WNFTkKoXuJusEmKnihi05SQwKBgQC9AvIjKbdx9zl8MbCylEWhzVG7pl2seSnR\nPSKzLyUve+CdcN/IeAV6UIX8oZ3VpjAM2SUIQQQ7AAc0RaqLHBA0tpYQeqUh2+3i\nw6CqqX1KaP6X1uQEQooutRRFVv6vZ+zeZBU6gNb+ZA7jGn46k+PPYcXxCyN3XJ2G\nLVHBbGy6fwKBgQCBV+1cOI90xZEIqoLm5V4b5NJhmvkNT5eKlO5mkO3599bXMdUC\nEmwHka8CQT9FEbqbZxUkzO8ASEx0/pdbp0Gy89u4HMUqUZ2I2o64t7Bu213uE1RO\n1MMA5W/5fdZ94mROEvvd2KSPGh6ElOxVRg5k6kw87iWkUSYd2hApL1YHTQKBgDiQ\nkiBd0q2DnCuDv2qiHvieNpCe6De+hvo8fo77U/iS7RSQ/BfFe3YwdPi28UJIGuct\ncPy4YGi7yGwnUTOScXMlFWHXImYwqE+N1h5c3McRBugwAksYEryJqohZ0Zxy0Jt5\nfjTk6/JzxVTHz/D941Zj31YUzEdjay0FkQr+xMdHAoGBAISQ6K+tRnjAXi1Hnu/p\nWdmrem1wJrVZiVbXUJoduu/uBaexSetO+PaMniZrjZeDTYfq6DpjLbhrQB86jcj7\n0jrpy4nmgLjNU+QxKO2STrepnkDDzLhvohWkK8qBBQt95/FFfTXpH458Q97fUcS3\nJiBKfyvwllztWwch/m04964z\n-----END PRIVATE KEY-----\n",
"client_email": "firebase-adminsdk-u5wel@hr-system-b0af6.iam.gserviceaccount.com",
"client_id": "116658927130976853667",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-u5wel%40hr-system-b0af6.iam.gserviceaccount.com",
"universe_domain": "googleapis.com"
}
+84
View File
@@ -0,0 +1,84 @@
<?php
include '../connect/cms-config.php' ;
include '../requires/function.php' ;
include '../extensions/mailer.php' ;
$mysqli_employment = $mysqli->query("SELECT employment_id, employment_branch, employment_position, employment_name, employment_email, employment_interview_date FROM staff_employment WHERE
employment_trash = '0' AND (
( employment_status = 'Interview' AND employment_interview_date LIKE '%".TODAYDAY."%' ) OR
( employment_status = 'Reschedule' AND employment_r_interview_date LIKE '%".TODAYDAY."%' )
)" ) ;
if ( $mysqli_employment->num_rows > 0 ){
$mailer = new Mailer() ;
// get all branch
$array_branch = [] ;
$mysqli_branch = $mysqli->query( "SELECT branch_id, branch_name, branch_hr_email, branch_hr_cc, branch_hr_contact, branch_email_footer FROM branch
WHERE deleted_at IS NULL" ) ;
if ( $mysqli_branch->num_rows > 0 ){
while ( $row_branch = $mysqli_branch->fetch_assoc() ){
$row_branch['branch_hr_cc'] = explodeToArray( $row_branch['branch_hr_cc'] ) ;
$row_branch['branch_email_footer'] = entityDecode( dataFilter( $row_branch['branch_email_footer'] ) ) ;
$array_branch[$row_branch['branch_id']] = $row_branch ;
}
}
// get all position
$array_position = [] ;
$mysqli_position = $mysqli->query( "SELECT a.job_position_id, b.job_position_desc FROM setting_job_position a
LEFT JOIN setting_job_position_translation b ON ( a.job_position_id = b.job_position_id )
WHERE a.deleted_at IS NULL AND b.lang = 'en'" ) ;
if ( $mysqli_position->num_rows > 0 ){
while ( $row_position = $mysqli_position->fetch_assoc() ){
$array_position[$row_position['job_position_id']] = $row_position['job_position_desc'] ;
}
}
while ( $row_employment = $mysqli_employment->fetch_assoc() ){
$title = "Friendly Reminder For Today Interview" ;
$link = PATH.'hr-employment-schedule-interview-date.php?page='.$row_employment['employment_id'].'&branch='.$row_employment['employment_branch'].'&sign='.md5($row_employment['employment_id'].$row_employment['employment_branch'].APIKEY) ;
$link_reschedule = '<a href="'.$link.'">'.$link.'</a>' ;
$link_attach_resume = '<a href="'.PATH.'uploads/Employment_Resume/'.$attach.'">Candidate\'s Resume</a>' ;
$get_branch = $array_branch[$row_employment['employment_branch']] ;
$content = "
<table>
<tr><td>Dear ".strtoupper($row_employment['employment_name']).",</td></tr>
<tr><td style='height:20px;'> </td></tr>
<tr><td>Thank you for your application regarding the position of <span style='border-bottom:1px solid black; font-weight:bold;'>".$array_position[$row_employment['No AAR for react-native-reanimated found. Attempting to build from source.']]."</span> at <span style='border-bottom:1px solid black; font-weight:bold;'>".$get_branch['branch_name']."</span>.</td></tr>
<tr><td style='height:20px;'> </td></tr>
<tr><td>We are impressed with your qualifications and would like to meet with you to have a round of discussion. You are advised to attend for the interview on <span style='border-bottom:1px solid black; font-weight:bold;'>".date('Y-m-d H:i', strtotime($row_employment['employment_interview_date']))."</span> at our office.</td></tr>
<tr><td style='height:20px;'> </td></tr>
<tr><td>If you have any queries, please feel free to contact the office. We look forward to meet you soon at our office.</td></tr>
<tr><td style='height:20px;'> </td></tr>
<tr><td>Please Note That:</td></tr>
<tr><td style='height:20px;'>1) This is an interview call for the job applied and does not guarantee employment with us.</td></tr>
<tr><td style='height:20px;'>2) No TA / DA will be provided to candidates appearing for the interview.</td></tr>
<tr><td style='height:20px;'>3) Bring this letter with you on the above-mentioned date and time of the interview.</td></tr>
<tr><td style='height:20px;'>4) Bring photocopies and originals of your academic & other credentials along with a recent snap.</td></tr>
<tr><td style='height:20px;'> </td></tr>
<tr><td>Reschedule Interview Date (If you are inconvenience with the date provided): </td></tr>
<tr><td>".$link_reschedule."</td></tr>
<tr><td style='height:20px;'> </td></tr>
<tr><td>*Please revert back to this email to confirm for your interview attendance.</td></tr>
</table>" . $get_branch['branch_email_footer'] ;
$mailer->from = $get_branch['branch_hr_email'] ;
$mailer->fromname = COMPANY ;
$mailer->to = [ $row_employment['employment_email'] ] ;
if ( count($get_branch['branch_hr_cc']) > 0 ){
$mailer->cc = $get_branch['branch_hr_cc'] ;
}
$mailer->subject = $title ;
$mailer->body = $content ;
$mailer->send() ;
}
}
?>
+21
View File
@@ -0,0 +1,21 @@
<?php
// update every 12 oclock
include '../connect/cms-config.php' ;
include '../requires/function.php' ;
$select = $mysqli->query( "SELECT * FROM setting_holiday
WHERE deleted_at IS NULL AND holiday_date = '".date('Y-m-d', time())."' LIMIT 1" ) ;
if ( $select->num_rows > 0 ){
$row_select = $select->fetch_assoc() ;
$mysqli_staff = $mysqli->query("SELECT staff_id, staff_name, staff_idno FROM staff
WHERE ( staff_date_resigned IS NULL || staff_date_resigned = '0000-00-00' || staff_date_resigned >= '".TODAYDATE."' ) AND deleted_at IS NULL ") ;
if ( $mysqli_staff->num_rows > 0 ){
while ( $row_staff = $mysqli_staff->fetch_assoc() ){
pushToUserCron( 'holiday', $row_select['holiday_id'], $row_staff['staff_id'], 'Holiday', 'It is public holiday today ( '.$row_select['holiday_name'].' ), kindly enjoy.' ) ;
}
}
}
?>
+140
View File
@@ -0,0 +1,140 @@
<?php
include '../connect/cms-config.php' ;
include '../requires/function.php' ;
include_once( '../vendor/autoload.php' ) ;
use Google\Auth\ApplicationDefaultCredentials;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
$credentialsPath = 'hr-system-b0af6-firebase-adminsdk-u5wel-5bcb3596d4.json' ; // Replace with your actual path
$projectId = '517510861795' ; // Your Firebase project ID or project number
function getAccessToken($credentialsPath) {
$scopes = ['https://www.googleapis.com/auth/firebase.messaging'];
// Get OAuth2 token using service account credentials
$credentials = json_decode(file_get_contents($credentialsPath), true);
$client = new Google_Client();
$client->setAuthConfig($credentials);
$client->setScopes($scopes);
// Get the token
$accessToken = $client->fetchAccessTokenWithAssertion()['access_token'];
return $accessToken;
}
// single send
function sendFCMNotification($projectId, $deviceTokens, $messageTitle, $messageBody, $dataPayload, $credentialsPath) {
$accessToken = getAccessToken($credentialsPath);
$url = 'https://fcm.googleapis.com/v1/projects/' . $projectId . '/messages:send';
$client = new \GuzzleHttp\Client();
foreach ($deviceTokens as $deviceToken) {
$message = [
'message' => [
'token' => $deviceToken,
'notification' => [
'title' => $messageTitle,
'body' => $messageBody
],
'android' => [
'notification' => [
'sound' => 'default' // Use this for Android specific sound settings
]
],
'apns' => [
'payload' => [
'aps' => [
'sound' => 'default' // Use this for iOS specific sound settings
]
]
],
'data' => $dataPayload // Custom data payload
]
];
$headers = [
'Authorization' => 'Bearer ' . $accessToken,
'Content-Type' => 'application/json',
];
print_r($message) ;
print_r($headers) ;
try {
$response = $client->post($url, [
'headers' => $headers,
'json' => $message
]);
echo 'Notification sent to ' . $deviceToken . ': ' . $response->getBody()->getContents() . PHP_EOL;
} catch (RequestException $e) {
if ($e->hasResponse()) {
echo 'Error sending to ' . $deviceToken . ': ' . $e->getResponse()->getBody()->getContents() . PHP_EOL;
} else {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
}
}
}
}
function pushToNotificationUser( $type, $type_id, $staff_id, $title, $message, $cron_id = '', $inbox_id = '' ){
global $mysqli, $projectId, $credentialsPath ;
$push = array() ;
$notifications_query = $mysqli->query( "SELECT notificationid, notification, badge FROM staff_notification
WHERE deleted_at IS NULL AND staff_id = '".$staff_id."' ORDER BY notificationid DESC LIMIT 1") ;
if ( $notifications_query->num_rows > 0 ){
$notification = $notifications_query->fetch_assoc() ;
$token_id = $notification['notificationid'] ;
$badge = ( $notification['badge'] + 1 ) ;
$is_create = true ;
if ( $inbox_id != '' && $inbox_id > 0 ){
$is_create = false ;
}
if ( $is_create ){
$mysqli->query( "INSERT INTO inbox ( staff_id, from_table, from_id, receiver_type, view_format, title, description, created_at ) VALUES ( '/".$staff_id."/', '".$type."', '".$type_id."', '3', 'message', '".$title."', '".$message."', '".TODAYDATE."' )" ) ;
$inbox_id = $mysqli->insert_id ;
$mysqli->query( "INSERT INTO staff_inbox_view ( inbox_id, staff_id, is_read ) VALUES ( '".$inbox_id."', '".$staff_id."', '0' )" ) ;
$mysqli->query( "UPDATE staff_notification_cron SET inbox_id = '".$inbox_id."' WHERE cron_id = '".$cron_id."'" ) ;
}
sendFCMNotification( $projectId, [ $notification['notification'] ], dataFilter( $title ), dataFilter( $message ), [
'go_messageid' => '',
'go_page' => '',
'go_param' => ''
], $credentialsPath ) ;
// update badge
$mysqli->query("UPDATE staff_notification SET badge = '".$badge."' WHERE notificationid = '".$token_id."'") ;
}
}
$select = $mysqli->query( "SELECT * FROM staff_notification_cron
WHERE deleted_at IS NULL AND is_sent = 'no' LIMIT 50" ) ;
if ( $select->num_rows > 0 ){
while ( $row = $select->fetch_assoc() ){
pushToNotificationUser( $row['type'], $row['type_id'], $row['staff_id'], $row['title'], $row['message'], $row['cron_id'], $row['inbox_id'] ) ;
$mysqli->query( "UPDATE staff_notification_cron SET is_sent = 'yes' WHERE cron_id = '".$row['cron_id']."'" ) ;
}
}
?>
+182
View File
@@ -0,0 +1,182 @@
<?php
// default config setting
$boolean_ssl_lock = true ;
include '../connect/cms-config.php' ;
include '../requires/function.php' ;
// defualt parameter
$after_14 = date('Y-m-d', strtotime('+14 days')) ;
$check = [
'passport' => [
'title' => 'Passport',
'no' => 'staff_passportno',
'date' => 'staff_passportexpired'
],
'permit' => [
'title' => 'Permit',
'no' => 'staff_permitno',
'date' => 'staff_permit_end'
]
] ;
// password expired
// permit expired
foreach ( $check as $k => $v ){
// previous date
$staff_q = $mysqli->query("SELECT staff_name, staff_idno, ".$v['no'].", ".$v['date']." FROM staff
WHERE ( staff_date_resigned IS NULL || staff_date_resigned = '0000-00-00' || staff_date_resigned >= '".TODAYDATE."' ) AND deleted_at IS NULL AND ".$v['no']." != '' AND ".$v['date']." != '0000-00-00' AND ".$v['date']." IS NOT NULL AND ".$v['date']." <= '".$after_14."'") ;
if ( $staff_q->num_rows > 0 ){
$html = '' ;
$count = 0 ;
while ( $row = $staff_q->fetch_assoc() ){
$staff_idno = ucwords( dataFilter($row['staff_idno']) ) ;
$count++ ;
$html .= '
<tr>
<td>'.$count.'</td>
<td>'.$staff_idno.'</td>
<td>'.dataFilter($row['staff_name']).'</td>
<td>'.dataFilter($row[$v['no']]).'</td>
<td>'.dataFilter($row[$v['date']]).'</td>
</tr>' ;
}
$html = '
<table border="0" width="800px" style="font-size:13px;">
<thead>
<tr>
<th style="text-align:left;">No.</th>
<th style="text-align:left;">ID No.</th>
<th style="text-align:left;">Staff</th>
<th style="text-align:left;">'.$v['title'].' No.</th>
<th style="text-align:left;">Expired Date</th>
</tr>
</thead>
<tbody>
'.$html.'
</tbody>
</table>' ;
$title = $v['title'] . ' Expired Warning' ;
foreach ( $EMAILCRON as $vv ){
sendEmail( $vv, EMAILNOREPLY, $title, $html ) ;
}
}
}
// leave apply waiting approve
$leave_q = $mysqli->query("SELECT a.leave_type, a.leave_from, a.leave_to, a.leave_day, a.leave_reason, b.staff_name, b.staff_idno FROM staff_leave a
LEFT JOIN staff b ON ( a.staff_id = b.staff_id )
WHERE
a.leave_status = 'pending' AND a.deleted_at IS NULL AND
( b.staff_date_resigned IS NULL || b.staff_date_resigned = '0000-00-00' || b.staff_date_resigned >= '".TODAYDATE."' ) AND b.deleted_at IS NULL
ORDER BY a.leave_from") ;
if ( $leave_q->num_rows > 0 ){
$html = '' ;
$count = 0 ;
while ( $row = $leave_q->fetch_assoc() ){
$staff_idno = ucwords( dataFilter($row['staff_idno']) ) ;
$count++ ;
$html .= '
<tr>
<td>'.$count.'</td>
<td>'.$staff_idno.'</td>
<td>'.dataFilter($row['staff_name']).'</td>
<td>'.ucwords($row['leave_type']).'</td>
<td>'.$row['leave_from'].' ~ '.$row['leave_to'].' ( '.$row['leave_day'].' days )</td>
<td>'.dataFilter($row['leave_reason']).'</td>
</tr>' ;
}
$html = '
<table border="0" width="800px" style="font-size:13px;">
<thead>
<tr>
<th style="text-align:left;">No.</th>
<th style="text-align:left;">ID No.</th>
<th style="text-align:left;">Staff</th>
<th style="text-align:left;">Type</th>
<th style="text-align:left;">From ~ To ( Days )</th>
<th style="text-align:left;">Reason</th>
</tr>
</thead>
<tbody>
'.$html.'
</tbody>
</table>' ;
$title = 'Leave Waiting Approve' ;
foreach ( $EMAILCRON as $vv ){
sendEmail( $vv, EMAILNOREPLY, $title, $html ) ;
}
}
// advance apply waiting approve
$advance_q = $mysqli->query("SELECT a.advance_amount, a.advance_reason, b.staff_name, b.staff_idno FROM staff_advance a
LEFT JOIN staff b ON ( a.staff_id = b.staff_id )
WHERE
a.advance_status = 'pending' AND a.deleted_at IS NULL AND
( b.staff_date_resigned IS NULL || b.staff_date_resigned = '0000-00-00' || b.staff_date_resigned >= '".TODAYDATE."' ) AND b.deleted_at IS NULL
ORDER BY a.created_at") ;
if ( $advance_q->num_rows > 0 ){
$html = '' ;
$count = 0 ;
while ( $row = $advance_q->fetch_assoc() ){
$staff_idno = ucwords( dataFilter($row['staff_idno']) ) ;
$count++ ;
$html .= '
<tr>
<td>'.$count.'</td>
<td>'.$staff_idno.'</td>
<td>'.dataFilter($row['staff_name']).'</td>
<td>'.ucwords($row['advance_amount']).'</td>
<td>'.dataFilter($row['advance_reason']).'</td>
</tr>' ;
}
$html = '
<table border="0" width="800px" style="font-size:13px;">
<thead>
<tr>
<th style="text-align:left;">No.</th>
<th style="text-align:left;">ID No.</th>
<th style="text-align:left;">Staff</th>
<th style="text-align:left;">Amount</th>
<th style="text-align:left;">Reason</th>
</tr>
</thead>
<tbody>
'.$html.'
</tbody>
</table>' ;
$title = 'Advance Waiting Approve' ;
foreach ( $EMAILCRON as $vv ){
sendEmail( $vv, EMAILNOREPLY, $title, $html ) ;
}
}
?>
+105
View File
@@ -0,0 +1,105 @@
<?php
// default config setting
$boolean_ssl_lock = true ;
include '../connect/cms-config.php' ;
include '../requires/function.php' ;
// get all branch
$branch_all = [] ;
$get_branch = $mysqli->query( "SELECT branch_id, branch_name FROM branch
WHERE deleted_at IS NULL " ) ;
if ( $get_branch->num_rows > 0 ){
while ( $row_branch = $get_branch->fetch_assoc() ){
$branch_all[$row_branch['branch_id']] = $row_branch['branch_name'] ;
}
}
$month_3_ago = date( "Y-m", strtotime( '-2 months' ) ) ;
$month_2_ago = date( "Y-m", strtotime( '-1 months' ) ) ;
$month_1_current = date( "Y-m", time() ) ;
$mysqli_staff = $mysqli->query("SELECT staff_id, staff_name, staff_idno, staff_date_resigned, branch_id FROM staff
WHERE deleted_at IS NULL AND staff_idno IS NOT NULL AND ( staff_date_resigned LIKE '%".$month_3_ago."%' OR staff_date_resigned LIKE '%".$month_2_ago."%' OR staff_date_resigned LIKE '%".$month_1_current."%' )
ORDER BY staff_date_resigned ASC") ;
$staff_list = [] ;
if ( $mysqli_staff->num_rows > 0 ){
while ( $row_staff = $mysqli_staff->fetch_assoc() ){
$reset_month = date( 'Y-m', strtotime( $row_staff['staff_date_resigned'] ) ) ;
$staff_list[$row_staff['branch_id']][$reset_month][] = $row_staff ;
}
}
$html = '' ;
if ( count($staff_list) ){
foreach ( $staff_list as $kbranch => $vbranch ){
$html .= '
<div style="font-size:20px;"><b>'.$branch_all[$kbranch].'</b></div>' ;
foreach ( $vbranch as $kdate => $vdate ){
$count = 0 ;
$content = '' ;
$html .= '
<div style="margin-top:10px; margin-bottom:3px;"><b>'.date( 'M Y', strtotime( $kdate.'-01' ) ).'</b></div>' ;
foreach ( $vdate as $kstaff => $vstaff ){
$count++ ;
$staff_idno = ucwords( dataFilter($vstaff['staff_idno']) ) ;
$content .= '
<tr>
<td>'.$count.'</td>
<td>'.dataFilter($vstaff['staff_idno']).'</td>
<td>'.dataFilter($vstaff['staff_name']).'</td>
<td>'.dataFilter($vstaff['staff_date_resigned']).'</td>
</tr>' ;
}
$html .= '
<table border="1" cellpadding="5" cellspacing="0" width="800px" style="font-size:13px;">
<thead>
<tr>
<th width="50" style="text-align:left;">No.</th>
<th width="100" style="text-align:left;">ID No.</th>
<th style="text-align:left;">Staff Name</th>
<th width="100" style="text-align:left;">Resigned Date</th>
</tr>
</thead>
<tbody>
'.$content.'
</tbody>
</table>' ;
}
$html .= '
<br />
<br />
<br />' ;
}
$title = 'Staff Resignation Within 3 Month' ;
foreach ( $EMAILCRON as $vv ){
sendEmail( $vv, EMAILNOREPLY, $title, $html ) ;
}
}
?>
+72
View File
@@ -0,0 +1,72 @@
<?php
include '../connect/cms-config.php' ;
include '../requires/function.php' ;
$select = $mysqli->query( "SELECT task_id, task_so, task_type, created_by, assigned_by, date_start FROM task
WHERE deleted_at IS NULL AND status IN ( 'pending', 'assigned', 'resubmit', 'progress' )" ) ;
if ( $select->num_rows > 0 ){
while ( $row = $select->fetch_assoc() ){
// '1time','daily','weekly','monthly','yearly'
$task_so = $row['task_so'] ;
$title = 'Task Reminder' ;
$message = 'Friendly reminder task ( '.$task_so.' ) haven\'t completed yet' ;
$date_start = strtotime( $row['date_start'] ) ;
$boolean = false ;
switch ( $row['task_type'] ){
case '1time' :
case 'daily' :
$boolean = true ;
break ;
case 'weekly' :
if ( date( 'w', $date_start ) == date( 'w', time() ) ){
$boolean = true ;
}
break ;
case 'monthly' :
if ( date( 'd', $date_start ) >= date( 't', time() ){
$boolean = true ;
}else{
if ( date( 'd', $date_start ) == date( 'd', time() ) ){
$boolean = true ;
}
}
break ;
case 'yearly' :
if ( date( 'm-01', $date_start ) == date( 'm-d', time() ) ){
$boolean = true ;
}
break ;
}
if ( $boolean ){
$staffs = [] ;
$staffs[] = $row['created_by'] ;
$staffs[] = $row['assigned_by'] ;
$select_join = $mysqli->query( "SELECT staff_id FROM task_joinstaff WHERE task_id = '".$row['task_id']."'" ) ;
if ( $select_join->num_rows > 0 ){
while ( $row_join = $select_join->fetch_assoc() ){
$staffs[] = $row_join['staff_id'] ;
}
}
foreach ( $staffs as $k => $staff ){
pushToUserCron( 'task', $row['task_id'], $staff, $title, $message ) ;
}
}
}
}
?>
+77
View File
@@ -0,0 +1,77 @@
<?php
include '../connect/cms-config.php' ;
include '../requires/function.php' ;
// confirm order and check the order within 5 minutes
$from_date = date( 'Y-m-d H:i:s', strtotime( "-5 minutes" ) ) ;
$to_date = date( 'Y-m-d H:i:s', strtotime( "-3 minutes" ) ) ;
// confirm order and check the order within in 1 hour, 2 hours, 3 hours, 4 hours
$hours1 = date( 'Y-m-d H:i', strtotime( "-235 minutes" ) ) ;
$hours2 = date( 'Y-m-d H:i', strtotime( "-175 minutes" ) ) ;
$hours3 = date( 'Y-m-d H:i', strtotime( "-115 minutes" ) ) ;
$hours4 = date( 'Y-m-d H:i', strtotime( "-55 minutes" ) ) ;
$select_order = $mysqli->query( "SELECT order_id, staff_id, biller_code, rms_authorizationtoken, created_at FROM staff_rms_bill_order
WHERE deleted_at IS NULL AND status IN ( 'pending', 'progress' ) AND ( ( created_at BETWEEN '".$from_date."' AND '".$to_date."' ) OR created_at LIKE '%".$hours1."%' OR created_at LIKE '%".$hours2."%' OR created_at LIKE '%".$hours3."%' OR created_at LIKE '%".$hours4."%' )" ) ;
if ( $select_order->num_rows > 0 ){
while ( $row_order = $select_order->fetch_assoc() ){
$rms_content = [
'authorizationToken' => $row_order['rms_authorizationtoken'],
'cashierId' => RMSLOCATION,
'transactionDateTime' => date( 'Y-m-d\TH:i:s', strtotime( $row_order['created_at'] ) ),
'businessDate' => date( 'Y-m-d', strtotime( $row_order['created_at'] ) )
] ;
$rms_call = rmsCall( 'bill/confirm', $rms_content ) ;
saveLog( 'rms-api', 'Confirm Bill Order *Per Minutes*', $rms_content, $rms_call ) ;
if ( $rms_call['respCode'] == '00' ){
if ( $mysqli->query( "UPDATE staff_rms_bill_order SET
rms_order_id = '".$rms_call['orderId']."',
rms_receiptno = '".$rms_call['billerReceiptNo']."',
status = 'confirmed'
WHERE order_id = '".$row_order['order_id']."'" ) ){
$status = '200' ;
}
}else{
if ( $mysqli->query( "UPDATE staff_rms_bill_order SET
status = 'progress'
WHERE order_id = '".$row_order['order_id']."'" ) ){
$status = '202' ;
}
}
}
}
// after transaction over 4 hours, auto cancel order and refund the wallet
$hours1 = date( 'Y-m-d H:i', strtotime( "-300 minutes" ) ) ;
$select_order = $mysqli->query( "SELECT order_id, staff_id, sonumber, reference1, amount FROM staff_rms_bill_order
WHERE deleted_at IS NULL AND status IN ( 'pending', 'progress' ) AND ( created_at LIKE '%".$hours1."%' )" ) ;
if ( $select_order->num_rows > 0 ){
while ( $row_order = $select_order->fetch_assoc() ){
saveLog( 'rms-api', 'Auto Cancel Bill', [], $row_order ) ;
if ( $mysqli->query( "UPDATE staff_rms_bill_order SET
status = 'cancelled'
WHERE order_id = '".$row_order['order_id']."'" ) ){
// refund the wallet
$remark = 'You have been refunded the wallet from bill order '.$row_order['reference1'].' (' . $row_order['sonumber'] . ')' ;
walletMovement( 'staff_rms_bill_order', $row_order['order_id'], 'plus', 'normal', $row_order['staff_id'], $row_order['amount'], $remark ) ;
}
}
}
?>
+64
View File
@@ -0,0 +1,64 @@
<?php
include '../connect/cms-config.php' ;
include '../requires/function.php' ;
// Check the order within 5 minutes
$from_date = date( 'Y-m-d H:i:s', strtotime( "-6 minutes" ) ) ;
$to_date = date( 'Y-m-d H:i:s', strtotime( "-1 minutes" ) ) ;
// Check the order within in 24 hours
$hours1 = date( 'Y-m-d H:i', strtotime( "-24 hours" ) ) ;
$select_order = $mysqli->query( "SELECT order_id, staff_id, sonumber, created_at FROM staff_rms_prepaid_order
WHERE deleted_at IS NULL AND status IN ( 'pending', 'progress' ) AND ( ( created_at BETWEEN '".$from_date."' AND '".$to_date."' ) OR created_at LIKE '%".$hours1."%' )" ) ;
if ( $select_order->num_rows > 0 ){
while ( $row_order = $select_order->fetch_assoc() ){
$rms_content = [
'topUpReferenceId' => $row_order['sonumber']
] ;
$rms_call = rmsCall( 'pinless/checktransactionstatus', $rms_content ) ;
saveLog( 'rms-api', 'Check Prepaid Status', $rms_content, $rms_call ) ;
if ( $rms_call['respCode'] == '00' ){
if ( $mysqli->query( "UPDATE staff_rms_prepaid_order SET
rms_order_id = '".$rms_call['orderId']."',
status = 'confirmed'
WHERE order_id = '".$row_order['order_id']."'" ) ){
$status = '200' ;
}
}else{
if ( $mysqli->query( "UPDATE staff_rms_prepaid_order SET
status = 'progress'
WHERE order_id = '".$row_order['order_id']."'" ) ){
$status = '202' ;
}
}
}
}
// after transaction over 24 hours, auto cancel order and refund the wallet
$hours1 = date( 'Y-m-d H:i', strtotime( "-25 hours" ) ) ;
$select_order = $mysqli->query( "SELECT order_id, staff_id, sonumber, dialcode, mobile, amount FROM staff_rms_prepaid_order
WHERE deleted_at IS NULL AND status IN ( 'pending', 'progress' ) AND ( created_at LIKE '%".$hours1."%' )" ) ;
if ( $select_order->num_rows > 0 ){
while ( $row_order = $select_order->fetch_assoc() ){
saveLog( 'rms-api', 'Auto Cancel Prepaid', [], $row_order ) ;
if ( $mysqli->query( "UPDATE staff_rms_prepaid_order SET
status = 'cancelled'
WHERE order_id = '".$row_order['order_id']."'" ) ){
// refund the wallet
$remark = 'You have been refunded the wallet from prepaid order '.$row_order['dialcode'].'-'.$row_order['mobile'].' (' . $row_order['sonumber'] . ')' ;
walletMovement( 'staff_rms_prepaid_order', $row_order['order_id'], 'plus', 'normal', $row_order['staff_id'], $row_order['amount'], $remark ) ;
}
}
}
?>