109 lines
3.7 KiB
PHP
109 lines
3.7 KiB
PHP
<?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 ) ;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|