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 Type | Description |
---|---|
REQUEST_TYPE_CHECK_IN | Adjusts late check-in duration. |
REQUEST_TYPE_CHECK_OUT | Adjusts early check-out duration. |
REQUEST_TYPE_OVERTIME | Records general overtime (duration only). |
REQUEST_TYPE_OVERTIME_EARLY | Handles early overtime adjustments. |
REQUEST_TYPE_OVERTIME_LATE | Handles late overtime adjustments. |
REQUEST_TYPE_BREAK_IN | Reserved for future implementation (break-in requests). |
REQUEST_TYPE_BREAK_OUT | Reserved for future implementation (break-out requests). |
Functionality
-
Retrieve Scan Requests
Fetches all attendance scan requests for the user (summary.UserProfileID
) on the specified date (summary.TheDate
). -
Process Each Request
Iterates over the retrieved requests (scanReqs
) and adjusts attendance metrics based on the request type. -
Switch Logic
Processes requests using aswitch
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 forREQUEST_TYPE_BREAK_IN
andREQUEST_TYPE_BREAK_OUT
(not implemented). - Default:
Logs an error for unknown request types (currently commented out).
- Check-In Requests:
-
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:
TheRULE_COUNT_EQUAL
flag determines whether to include boundary conditions when comparing times. -
Unimplemented Features:
Request typesREQUEST_TYPE_BREAK_IN
andREQUEST_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
- Fetch requests for
user123
on2024-12-08
. - Process each request (e.g.,
REQUEST_TYPE_CHECK_IN
). - 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.