Skip to main content

checkScanAttendanceRequest Function

Overview

The checkScanAttendanceRequest function processes attendance requests for a given user and date, modifying the attendance summary based on the type of requests found. It supports various attendance request types, such as late check-ins, early check-outs, and overtime.

This function operates on the AttendanceSummariesCompute struct and interacts with cached scan requests for validation and computation.


Function Definition

func (summary *AttendanceSummariesCompute) checkScanAttendanceRequest()

Parameters

  • summary (*AttendanceSummariesCompute):
    The receiver struct representing the attendance summary for a user on a specific date.

Supported Request Types

Request TypeDescription
REQUEST_TYPE_CHECK_INAdjusts late check-in duration.
REQUEST_TYPE_CHECK_OUTAdjusts early check-out duration.
REQUEST_TYPE_OVERTIMERecords general overtime (duration only).
REQUEST_TYPE_OVERTIME_EARLYHandles early overtime adjustments.
REQUEST_TYPE_OVERTIME_LATEHandles late overtime adjustments.
REQUEST_TYPE_BREAK_INReserved for future implementation (break-in requests).
REQUEST_TYPE_BREAK_OUTReserved for future implementation (break-out requests).

Functionality

  1. Retrieve Scan Requests
    Fetches all attendance scan requests for the user (summary.UserProfileID) on the specified date (summary.TheDate).

  2. Process Each Request
    Iterates over the retrieved requests (scanReqs) and adjusts attendance metrics based on the request type.

  3. Switch Logic
    Processes requests using a switch statement on the request type (v.RequestType):

    • Check-In Requests:
      Compares the check-in time against the defined rule (summary.CiRule) and resets late duration if applicable.
    • Check-Out Requests:
      Compares the check-out time against the defined rule (summary.CoRule) and resets early check-out duration if applicable.
    • Overtime Requests:
      Updates overtime rules (OtCiEarlyRule, OtCoLateRule, etc.) with metadata from the request.
    • Break Requests:
      Placeholder for REQUEST_TYPE_BREAK_IN and REQUEST_TYPE_BREAK_OUT (not implemented).
    • Default:
      Logs an error for unknown request types (currently commented out).
  4. Handle Status and IDs
    Updates the origin of duration changes with the request status and ID, e.g., "scanrequest:<ID>" or "[<STATUS>]scanrequest:<ID>".


Key Considerations

  • Validation:
    The function does not currently check if the request is already approved, leaving room for inconsistent processing.
    TODO: Add validation to ensure only approved requests are considered.

  • Rules Logic:
    The RULE_COUNT_EQUAL flag determines whether to include boundary conditions when comparing times.

  • Unimplemented Features:
    Request types REQUEST_TYPE_BREAK_IN and REQUEST_TYPE_BREAK_OUT are logged but not processed.


Example Usage

Input Data

summary := &AttendanceSummariesCompute{
UserProfileID: "user123",
TheDate: "2024-12-08",
CiRule: "09:00",
CoRule: "17:00",
}

Process Flow

  1. Fetch requests for user123 on 2024-12-08.
  2. Process each request (e.g., REQUEST_TYPE_CHECK_IN).
  3. Update attendance summary (summary.DurationCiLateRule, etc.).

Notes

  • Ensure all request types in the entity package are accounted for and handled appropriately.
  • Future enhancements may include support for additional request types and improved error handling/logging.