calculateScanPointsAndCreateBreaks
Function
Overview
The calculateScanPointsAndCreateBreaks
function processes attendance summary data by calculating scan points (check-in, check-out, and breaks) based on the assigned shift and its schedule. The function ensures the proper mapping of shift attributes and handles break details for accurate attendance computation.
Function Signature
func calculateScanPointsAndCreateBreaks(summary *AttendanceSummariesCompute, cache *caching.AllCacheStruct)
Parameters
-
summary
Type:*AttendanceSummariesCompute
Description: Pointer to the attendance summary object that will be updated with shift and scan point information. -
cache
Type:*caching.AllCacheStruct
Description: Cache structure that contains preloaded shift data, among other information.
Key Operations
-
Retrieve Shift Data
- Fetches the shift corresponding to
summary.ShiftID
from thecache
. - Handles cases where:
- The shift is not set (
summary.Shift == nil
) but work is required (!summary.IsNoWork
). - The shift is not set but no work is scheduled (
summary.IsNoWork == true
).
- The shift is not set (
- Fetches the shift corresponding to
-
Calculate Scan Points
- Extracts the date from
summary.TheDate
usingtimedate.ExtractDateFromString
. - Computes scan points and their order using
GetScanPointsFromShift
.
- Extracts the date from
-
Set Summary Attributes
- Updates the following fields of the
summary
object:ShiftDuration
ShiftStart
ShiftEnd
ShiftInterval
ShiftMinimumDuration
ShiftPresence
- Updates the following fields of the
-
Handle Breaks
- Iterates through
summary.Shift.ShiftBreaks
to process break data:- Fetches or creates summary details for each break.
- Updates break details (start, end, duration, etc.) based on calculated scan points.
- Iterates through
-
Apply Shift Rules
- Integrates additional shift rules into the summary using
addRuleDetailsToRulesHit
.
- Integrates additional shift rules into the summary using
Example Workflow
-
Input:
- A valid
summary
object containingShiftID
andTheDate
. - A
cache
object with preloaded shift definitions.
- A valid
-
Output:
- Updated
summary
object with:- Shift timings (start, end, duration).
- Break details for each scheduled break.
- Applied shift rules.
- Updated
Error Handling
- If no shift is found for the given
ShiftID
:- Logs a warning if
IsNoWork == false
. - Ignores processing if
IsNoWork == true
.
- Logs a warning if
Dependencies
-
Utilities:
timedate.ExtractDateFromString
timedate.TimeToString
utils.IntToString
-
Shift Calculation:
GetScanPointsFromShift
-
Rule Application:
addRuleDetailsToRulesHit
Notes
- The function relies heavily on the structure and availability of cached shift data.
- It assumes that scan points and breaks are indexed consistently.
- Debugging print statements (commented out) suggest additional monitoring could be implemented during execution.