Skip to main content

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

  1. Retrieve Shift Data

    • Fetches the shift corresponding to summary.ShiftID from the cache.
    • 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).
  2. Calculate Scan Points

    • Extracts the date from summary.TheDate using timedate.ExtractDateFromString.
    • Computes scan points and their order using GetScanPointsFromShift.
  3. Set Summary Attributes

    • Updates the following fields of the summary object:
      • ShiftDuration
      • ShiftStart
      • ShiftEnd
      • ShiftInterval
      • ShiftMinimumDuration
      • ShiftPresence
  4. 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.
  5. Apply Shift Rules

    • Integrates additional shift rules into the summary using addRuleDetailsToRulesHit.

Example Workflow

  1. Input:

    • A valid summary object containing ShiftID and TheDate.
    • A cache object with preloaded shift definitions.
  2. Output:

    • Updated summary object with:
      • Shift timings (start, end, duration).
      • Break details for each scheduled break.
      • Applied shift rules.

Error Handling

  • If no shift is found for the given ShiftID:
    • Logs a warning if IsNoWork == false.
    • Ignores processing if IsNoWork == true.

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.