Skip to main content

createSummaryFromCalendarDetail Function

Overview

The createSummaryFromCalendarDetail function is responsible for creating a summary placeholder header and details from a CalendarSchedule. It is typically used for generating new attendance summaries.

Function Signature

func createSummaryFromCalendarDetail(calSched *entity.CalendarScheduleTable, idx int, cache *caching.AllCacheStruct) AttendanceSummariesCompute

Parameters

ParameterTypeDescription
calSched*entity.CalendarScheduleTableThe calendar schedule containing data to populate the attendance summary.
idxintThe index of the specific detail within the calendar schedule's details to use.
cache*caching.AllCacheStructA cache structure containing preloaded shift and rule data for use in the summary generation.

Returns

  • AttendanceSummariesCompute: A struct containing the generated attendance summary and related metadata.

Function Details

  1. Initialize Temporary Structures:

    • Creates a temporary AttendanceSummariesCompute object (tmp) and initializes its properties using the data from the provided CalendarScheduleTable and AllCacheStruct.
  2. Populate Summary Fields:

    • Sets key fields in the tmp struct using values from calSched:
      • UserProfileID
      • CompanyID
      • TheDate
      • ScheduleID
      • CalendarScheduleID, etc.
    • Populates shift-specific details like ShiftID, OrderNum, and CalendarHolidayID from the details indexed by idx.
  3. Set Flags and Indicators:

    • Configures flags for overtime, work type, holiday behavior, and other operational modes (e.g., IsOvertime, IsFlexible, IsIgnoreHoliday, etc.).
  4. Set Shift from Cache:

    • Retrieves shift details from the provided cache structure based on ShiftID.
  5. Generate Break Details:

    • Calls the createBreakDetails function to generate break-related information for the summary.
  6. Return the Generated Summary:

    • Returns the fully populated AttendanceSummariesCompute struct.

Key Notes

  • Header Type: The function initializes the summary as a placeholder header with SummaryType set to SUMMARY_HEADER.
  • Integration with Cache: Leverages the cache for shift information to ensure efficiency and reduce database calls.
  • Customizable Flags: Handles various schedule attributes such as overtime rules and flexible schedules.
  • Break Details: Delegates break-related logic to the createBreakDetails function for modularity.

Example Usage

calSched := &entity.CalendarScheduleTable{
UserProfileID: "user123",
CompanyID: "companyXYZ",
TheDate: "2024-12-01",
// other fields...
}

cache := &caching.AllCacheStruct{
Shifts: preloadedShifts,
}

summary := createSummaryFromCalendarDetail(calSched, 0, cache)

// Use `summary` as needed...

Dependencies

  • Entities:
    • entity.CalendarScheduleTable
    • entity.AttendanceSummariesTable
  • Cache:
    • caching.AllCacheStruct
  • createBreakDetails:
    • Used to handle break-related details within the generated summary.