Skip to main content

Attendance Summary Query Documentation

This code provides functions for querying and manipulating attendance summary data in the database. It uses the PocketBase DAO for database interactions and includes functions for retrieving, inserting, and updating attendance summary records.

Functions

GetAttendanceSummaries

func GetAttendanceSummaries(dao *daos.Dao, companyID string, startDate, endDate time.Time) ([]*entity.AttendanceSummariesTable, error)

Retrieves attendance summaries for a company within a specified date range.

  • dao: The PocketBase DAO.
  • companyID: The ID of the company.
  • startDate: The start date of the range.
  • endDate: The end date of the range.
  • Returns: A slice of pointers to AttendanceSummariesTable structs containing the attendance summary data, or an error if the operation fails.

GetUserAttendanceSummaries

func GetUserAttendanceSummaries(dao *daos.Dao, userProfileID string, startDate, endDate time.Time) ([]*entity.AttendanceSummaryTable, error)

Retrieves attendance summaries for a specific user within a specified date range.

  • dao: The PocketBase DAO.
  • userProfileID: The ID of the user profile.
  • startDate: The start date of the range.
  • endDate: The end date of the range.
  • Returns: A slice of pointers to AttendanceSummaryTable structs containing the attendance summary data, or an error if the operation fails.

GetUserAttendanceSummariesWithRelations

func GetUserAttendanceSummariesWithRelations(dao *daos.Dao, userProfileID string, startDate, endDate time.Time) ([]*entity.AttendanceSummaryTable, error)

Retrieves attendance summaries for a specific user within a specified date range, including related data such as attendance logs, shifts, and breaks.

  • dao: The PocketBase DAO.
  • userProfileID: The ID of the user profile.
  • startDate: The start date of the range.
  • endDate: The end date of the range.
  • Returns: A slice of pointers to AttendanceSummaryTable structs containing the attendance summary data with related data, or an error if the operation fails.

GetBulkUserAttendanceSummaries

func GetBulkUserAttendanceSummaries(dao *daos.Dao, userProfileIDs []string, startDate, endDate time.Time) (map[string][]entity.AttendanceSummaryTable, error)

Retrieves attendance summaries for multiple users within a specified date range.

  • dao: The PocketBase DAO.
  • userProfileIDs: A slice of user profile IDs.
  • startDate: The start date of the range.
  • endDate: The end date of the range.
  • Returns: A map where the keys are user profile IDs and the values are slices of AttendanceSummaryTable structs containing the attendance summary data, or an error if the operation fails.

GetBulkUserAttendanceSummariesByUserProfiles

func GetBulkUserAttendanceSummariesByUserProfiles(dao *daos.Dao, userProfiles []*entity.UserProfileTable, startDate, endDate time.Time) (map[string][]entity.AttendanceSummaryTable, error)

Retrieves attendance summaries for multiple users within a specified date range, using user profile structs.

  • dao: The PocketBase DAO.
  • userProfiles: A slice of pointers to UserProfileTable structs.
  • startDate: The start date of the range.
  • endDate: The end date of the range.
  • Returns: A map where the keys are user profile IDs and the values are slices of AttendanceSummaryTable structs containing the attendance summary data, or an error if the operation fails.

SyncAttendanceSummary

func SyncAttendanceSummary(dao *daos.Dao, userProfileID string, startDate, endDate time.Time, data []*entity.AttendanceSummaryTable) error

Synchronizes attendance summaries for a specific user within a specified date range by deleting existing records and inserting new ones.

  • dao: The PocketBase DAO.
  • userProfileID: The ID of the user profile.
  • startDate: The start date of the range.
  • endDate: The end date of the range.
  • data: A slice of pointers to AttendanceSummaryTable structs containing the new attendance summary data.
  • Returns: An error if the operation fails.

InsertAttendanceSummary

func InsertAttendanceSummary(dao *daos.Dao, data *entity.AttendanceSummaryTable) error

Inserts a new attendance summary record into the database.

  • dao: The PocketBase DAO.
  • data: A pointer to an AttendanceSummaryTable struct containing the attendance summary data to be inserted.
  • Returns: An error if the operation fails.

Example Usage

Initializing the DAO

Before using the functions, you need to initialize the PocketBase DAO.

package main

import (
"fio-backend/queries"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/daos"
)

func main() {
// Initialize PocketBase
pb := pocketbase.New()

// Initialize the DAO
dao := daos.New(pb.DB())
}

Retrieving Attendance Summaries for a Company

package main

import (
"fio-backend/queries"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/daos"
"fmt"
"time"
)

func main() {
// Initialize PocketBase
pb := pocketbase.New()

// Initialize the DAO
dao := daos.New(pb.DB())

// Retrieve attendance summaries for a company
companyID := "company123"
startDate := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
endDate := time.Date(2023, 1, 31, 23, 59, 59, 0, time.UTC)
summaries, err := queries.GetAttendanceSummaries(dao, companyID, startDate, endDate)
if err != nil {
fmt.Println("Error:", err)
return
}

fmt.Println("Attendance Summaries:", summaries)
}

Retrieving Attendance Summaries for a User

package main

import (
"fio-backend/queries"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/daos"
"fmt"
"time"
)

func main() {
// Initialize PocketBase
pb := pocketbase.New()

// Initialize the DAO
dao := daos.New(pb.DB())

// Retrieve attendance summaries for a user
userProfileID := "user123"
startDate := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
endDate := time.Date(2023, 1, 31, 23, 59, 59, 0, time.UTC)
summaries, err := queries.GetUserAttendanceSummaries(dao, userProfileID, startDate, endDate)
if err != nil {
fmt.Println("Error:", err)
return
}

fmt.Println("User Attendance Summaries:", summaries)
}

Synchronizing Attendance Summaries

package main

import (
"fio-backend/entity"
"fio-backend/queries"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/daos"
"fmt"
"time"
)

func main() {
// Initialize PocketBase
pb := pocketbase.New()

// Initialize the DAO
dao := daos.New(pb.DB())

// Create new attendance summary data
newData := []*entity.AttendanceSummaryTable{
{
UserProfileID: "user123",
Date: "2023-01-01",
PresenceRule: 1,
DurationCiLateRule: 0,
DurationOtCiEarlyRule: 0,
DurationOtCoLateRule: 0,
},
{
UserProfileID: "user123",
Date: "2023-01-02",
PresenceRule: 1,
DurationCiLateRule: 0,
DurationOtCiEarlyRule: 0,
DurationOtCoLateRule: 0,
},
}

// Synchronize attendance summaries for a user
userProfileID := "user123"
startDate := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
endDate := time.Date(2023, 1, 31, 23, 59, 59, 0, time.UTC)
err := queries.SyncAttendanceSummary(dao, userProfileID, startDate, endDate, newData)
if err != nil {
fmt.Println("Error:", err)
return
}

fmt.Println("Attendance summaries synchronized successfully")
}

This documentation provides an overview of the attendance summary query functions, their parameters, and example usage. By following the examples, you can retrieve, insert, and update attendance summary records in the database.