Skip to main content

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:

  1. Office Status:

    • Determines if the user is present in the office (CheckIsInOffice).
  2. Scan Point Candidates:

    • Processes scan logs to identify potential scan points (GetScanPointCandidateFromScanLogs).
  3. Set Summary from Candidates or Rules:

    • Updates the summary based on scan points or applicable rules (SetSummaryFromScanPointCandidateOrRule).

3. Process Summary Data

  • If the summary has scans, the following operations are performed:
    1. Calculate Breaks:
      • Computes break durations and adds them to the summary (CalculateBreaks).
    2. Early/Late Calculations:
      • Evaluates early and late attendance (calculateEarlyLateHeader).
    3. Presence Penalties:
      • Calculates presence penalties (CalculatePrecense).
    4. Overtime Calculations:
      • Computes overtime durations (CalculateOvertime).
    5. Duration Metrics:
      • Finalizes attendance durations, excluding breaks (calculateDurationHeader).
    6. Scores:
      • Assigns scores based on computed data (CalculateScore).

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.

6. Apply Overwrites

  • If an overwrite is detected (summary.OverwriteApplied), applies precomputed values:
    • Retrieves and merges overwrite data using findSummaryOverwriteBySummaryID and CopyNonZeroFieldsExclude.

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.ExtractDateFromString
  • ScanLogsHasDate
  • CheckIsInOffice
  • GetScanPointCandidateFromScanLogs
  • SetSummaryFromScanPointCandidateOrRule
  • CalculateBreaks
  • calculateEarlyLateHeader
  • CalculatePrecense
  • CalculateOvertime
  • calculateDurationHeader
  • CalculateScore
  • checkLeave
  • CopyNonZeroFieldsExclude