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 ) ; } } } } } ?>