CreateSummaryFixed Function
This documentation provides an overview of the CreateSummaryFixed function in Go, its purpose, functionality, and the sequence of operations.
Function Overview
func CreateSummaryFixed(summary *AttendanceSummariesCompute, scanLogs []*entity.AttendanceLogTable)
The CreateSummaryFixed function processes attendance data and generates a comprehensive attendance summary based on scan logs, schedules, and rules. The function incorporates existing summaries, applies various business rules, and calculates key metrics such as early/late attendance, breaks, overtime, and final scores.
Parameters
summary *AttendanceSummariesCompute
- Description: Represents the attendance summary being computed. Contains fields for attendance details, such as shift information, scan points, and computed metrics.
- Type: Pointer to
AttendanceSummariesCompute.
scanLogs []*entity.AttendanceLogTable
- Description: A list of attendance scan logs, which provide raw attendance data (e.g., check-in/out times).
- Type: Slice of
AttendanceLogTable.
Process Flow
1. Prepare Schedules
- Prepares schedules and shifts from cached data.
- Initializes or uses an existing summary structure, populating it with initial data.
2. Check and Process Scan Logs
- Extracts the relevant date from the summary using
timedate.ExtractDateFromString. - Checks if scan logs exist for the computed date using
ScanLogsHasDate.
If Scan Logs Exist:
-
Office Status:
- Determines if the user is present in the office (
CheckIsInOffice).
- Determines if the user is present in the office (
-
Scan Point Candidates:
- Processes scan logs to identify potential scan points (
GetScanPointCandidateFromScanLogs).
- Processes scan logs to identify potential scan points (
-
Set Summary from Candidates or Rules:
- Updates the summary based on scan points or applicable rules (
SetSummaryFromScanPointCandidateOrRule).
- Updates the summary based on scan points or applicable rules (
3. Process Summary Data
- If the summary has scans, the following operations are performed:
- Calculate Breaks:
- Computes break durations and adds them to the summary (
CalculateBreaks).
- Computes break durations and adds them to the summary (
- Early/Late Calculations:
- Evaluates early and late attendance (
calculateEarlyLateHeader).
- Evaluates early and late attendance (
- Presence Penalties:
- Calculates presence penalties (
CalculatePrecense).
- Calculates presence penalties (
- Overtime Calculations:
- Computes overtime durations (
CalculateOvertime).
- Computes overtime durations (
- Duration Metrics:
- Finalizes attendance durations, excluding breaks (
calculateDurationHeader).
- Finalizes attendance durations, excluding breaks (
- Scores:
- Assigns scores based on computed data (
CalculateScore).
- Assigns scores based on computed data (
- Calculate Breaks:
4. Flag Handling
- Adjusts flags based on conditions:
- Overtime on holidays or non-working days.
- Attendance requests (
summary.checkScanAttendanceRequest).
5. Handle Missing Scans
- If no scans exist:
- Checks off-days (e.g., weekends, holidays, leave) using
checkLeave. - Ensures no unnecessary calculations are performed.
- Checks off-days (e.g., weekends, holidays, leave) using
6. Apply Overwrites
- If an overwrite is detected (
summary.OverwriteApplied), applies precomputed values:- Retrieves and merges overwrite data using
findSummaryOverwriteBySummaryIDandCopyNonZeroFieldsExclude.
- Retrieves and merges overwrite data using
Notes
- Business Rules:
- The function enforces various attendance policies, including handling holidays, overtime, and leave.
- Performance:
- Leverages caching and conditional checks to optimize processing.
Example Usage
summary := &AttendanceSummariesCompute{TheDate: "2024-12-08"}
scanLogs := []*entity.AttendanceLogTable{
// Populate with attendance log data
}
CreateSummaryFixed(summary, scanLogs)
// Access computed summary details
fmt.Println(summary)
Key Functions Referenced
timedate.ExtractDateFromStringScanLogsHasDateCheckIsInOfficeGetScanPointCandidateFromScanLogsSetSummaryFromScanPointCandidateOrRuleCalculateBreakscalculateEarlyLateHeaderCalculatePrecenseCalculateOvertimecalculateDurationHeaderCalculateScorecheckLeaveCopyNonZeroFieldsExclude