createBreakDetails
Function
Overview
The createBreakDetails
function generates new attendance summary details for break periods based on the shift information available in the provided AttendanceSummariesCompute
object. This function ensures that each break in the shift is translated into a corresponding detail entry within the attendance summary.
Function Signature
func createBreakDetails(summary *AttendanceSummariesCompute)
Parameters
summary
:
A pointer to anAttendanceSummariesCompute
object that contains information about the shift, user, and company for which attendance summaries are being computed.
Behavior
- Checks if the
Shift
attribute in thesummary
object is notnil
. - Iterates over the
ShiftBreaks
associated with the shift in the summary. - For each break:
- Creates an instance of
AttendanceSummariesDetailTable
and populates its fields with relevant data:SummaryType
: Set toSUMMARY_BREAK
.UserProfileID
,CompanyID
,TheDate
,ScheduleID
,ShiftID
: Taken from thesummary
object.BreakID
: Identifier of the current break.ShiftDuration
: Duration of the break in minutes.BreakCountAsWork
: Boolean indicating whether the break counts as work time.OrderNum
: The order number of the break in the shift sequence.
- Appends the populated detail object to a slice of breaks.
- Creates an instance of
- Assigns the slice of created break details to the
SummaryDetails
attribute of thesummary
object.
Key Features
- Dependency on Shift: The function assumes that the
Shift
is already populated in thesummary
object. If no shift is present, no details are created. - Iterative Creation: Break details are generated for each break in the
ShiftBreaks
list. - Detailed Field Population: Each
AttendanceSummariesDetailTable
is populated with both static data (from thesummary
object) and dynamic data (from each break).
Limitations
- The function does not handle cases where
ShiftBreaks
is empty. It simply does not append any details if no breaks exist. - Some commented-out fields (e.g.,
ShiftStart
,ShiftEnd
) indicate that they might be intended for future implementation or require additional data to be set.
Example
summary := &AttendanceSummariesCompute{
UserProfileID: 123,
CompanyID: 456,
TheDate: time.Now(),
ScheduleID: 789,
ShiftID: 101,
Shift: &Shift{
ShiftBreaks: []ShiftBreak{
{
Break: Break{
Id: 1,
DurationMinutes: 30,
StartTime: "10:00 AM",
EndTime: "10:30 AM",
},
CountAsWork: true,
OrderNum: 1,
},
},
},
}
createBreakDetails(summary)
// Result: summary.SummaryDetails now contains details for the break in the shift.
Return Value
This function does not return any value. It directly modifies the SummaryDetails
attribute of the provided summary
object.
Notes
- Ensure that the
Shift
is populated in theAttendanceSummariesCompute
object before calling this function. - Commented-out lines indicate future enhancements or features that rely on additional data sources.