timesheet

package
v1.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2023 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReasonSickLeave          = "Sick / Medical Consultation"
	ReasonOutsideOfficeHours = "Outside office hours"
	ReasonAuthorities        = "Authorities"
	ReasonPublicService      = "Requested Public Service"

	TypePublicHoliday     = "Public Holiday"
	TypeMilitaryService   = "Military Service"
	TypeSpecialOccasions  = "Special Occasions"
	TypeUnpaid            = "Unpaid"
	TypeLegalLeavesPrefix = "Legal Leaves"

	StateApproved  = "validate"
	StateToApprove = "confirm"
	StateDraft     = "draft"
)

Variables

View Source
var DefaultTimeZone *time.Location

DefaultTimeZone is the zone to which apply a last-resort default.

Functions

func AppendValidationError added in v1.6.0

func AppendValidationError(list *ValidationErrorList, err error)

AppendValidationError appends an err to the given list, if err is of type ValidationError.

Types

type AbsenceBlock added in v0.2.0

type AbsenceBlock struct {
	Date   time.Time
	Reason string
}

type AttendanceShift added in v0.7.0

type AttendanceShift struct {
	Start model.Attendance
	End   model.Attendance
}

func (*AttendanceShift) Duration added in v1.3.0

func (s *AttendanceShift) Duration() time.Duration

Duration returns the difference between AttendanceShift.Start and AttendanceShift.End.

func (*AttendanceShift) String added in v1.3.0

func (s *AttendanceShift) String() string

String implements fmt.Stringer.

type BalanceReport added in v1.5.0

type BalanceReport struct {
	Report Report
	// PreviousBalance is the definitive balance from the previous month's payslip, if given.
	PreviousBalance time.Duration
	// CalculatedBalance is the sum of TotalOvertime with the previous month's payslip, if given.
	CalculatedBalance time.Duration
	// DefinitiveBalance contains the value of the current month's payslip, if given.
	DefinitiveBalance *time.Duration
}

type BalanceReportBuilder added in v1.5.0

type BalanceReportBuilder struct {
	// contains filtered or unexported fields
}

func NewBalanceReportBuilder added in v1.5.0

func NewBalanceReportBuilder(report Report, payslips model.PayslipList) *BalanceReportBuilder

func (*BalanceReportBuilder) CalculateBalanceReport added in v1.5.0

func (b *BalanceReportBuilder) CalculateBalanceReport() (BalanceReport, error)

type DailySummary

type DailySummary struct {
	// Date is the localized date of the summary.
	Date     time.Time
	Shifts   []AttendanceShift
	Absences []AbsenceBlock
	FTERatio float64
}

func NewDailySummary

func NewDailySummary(fteRatio float64, date time.Time) *DailySummary

NewDailySummary creates a new instance. The fteRatio is the percentage (input a value between 0..1) of the employee and is used to calculate the daily maximum hours an employee should work. Date is expected to be in a localized timezone.

func (*DailySummary) CalculateAbsenceTime added in v0.7.0

func (s *DailySummary) CalculateAbsenceTime() time.Duration

CalculateAbsenceTime accumulates all absence hours from that day.

func (*DailySummary) CalculateOvertimeSummary added in v1.1.0

func (s *DailySummary) CalculateOvertimeSummary() OvertimeSummary

CalculateOvertimeSummary returns the duration of overtime. If returned duration is positive, then the employee did overtime and undertime if duration is negative.

The overtime is then calculated according to these business rules:

  • Outside office hours are multiplied by 1.5 (as a compensation)
  • Excused hours like sick leave, authorities or public service can be used to "fill up" the daily theoretical maximum if the working hours are less than said maximum. However, there's no overtime possible using excused hours
  • If the working hours exceed the theoretical daily maximum, then the excused hours are basically ignored. Example: it's not possible to work 9 hours, have 1 hour sick leave and expect 2 hours overtime for an 8 hours daily maximum, the overtime here is 1 hour.

func (*DailySummary) HasAbsences added in v0.2.0

func (s *DailySummary) HasAbsences() bool

HasAbsences returns true if there are any absences.

func (*DailySummary) IsHoliday added in v0.7.0

func (s *DailySummary) IsHoliday() bool

IsHoliday returns true if there is a "personalized" leave. Public and unpaid holidays return false. If the holiday falls on a weekend, the day is not counted.

func (*DailySummary) IsWeekend added in v0.2.0

func (s *DailySummary) IsWeekend() bool

IsWeekend returns true if the date falls on a Saturday or Sunday.

func (*DailySummary) ValidateTimesheetEntries added in v1.6.0

func (s *DailySummary) ValidateTimesheetEntries() error

ValidateTimesheetEntries checks if the DailySummary has invalid or incomplete shifts. A shift is invalid in the following conditions:

  • There is no sign_in action before any sign_out
  • There is no sign_out action after any sign_in
  • Start and end of a shift are the same time (duration = 0s)
  • Reasons of start and end of a shift are different
  • Duration of all shifts exceeds 24h (it should be split over multiple days)

type OvertimeSummary added in v1.1.0

type OvertimeSummary struct {
	RegularWorkingTime time.Duration
	SickLeaveTime      time.Duration
	AuthoritiesTime    time.Duration
	OutOfOfficeTime    time.Duration
	DailyMax           time.Duration
	PublicServiceTime  time.Duration
}

func (OvertimeSummary) ExcusedTime added in v1.1.0

func (s OvertimeSummary) ExcusedTime() time.Duration

ExcusedTime returns the sum of AuthoritiesTime, PublicServiceTime and SickLeaveTime, but it can't exceed DailyMax.

func (OvertimeSummary) Overtime added in v1.1.0

func (s OvertimeSummary) Overtime() time.Duration

Overtime returns the total overtime with all business rules respected.

func (OvertimeSummary) WorkingTime added in v1.1.0

func (s OvertimeSummary) WorkingTime() time.Duration

WorkingTime is the sum of OutOfOfficeTime (multiplied with 1.5) and RegularWorkingTime.

type Report

type Report struct {
	DailySummaries []*DailySummary
	Summary        Summary
	Employee       model.Employee
	// From is the first day (inclusive) of the time range.
	From time.Time
	// To is the last day (inclusive) of the time range
	To time.Time
}

type ReportBuilder added in v0.7.0

type ReportBuilder struct {
	// contains filtered or unexported fields
}

func NewReporter added in v0.2.0

func NewReporter(attendances model.AttendanceList, leaves odoo.List[model.Leave], employee model.Employee, contracts model.ContractList) *ReportBuilder

func (*ReportBuilder) CalculateReport added in v1.0.0

func (r *ReportBuilder) CalculateReport(from time.Time, to time.Time) (Report, error)

CalculateReport creates a report with the given information in the builder. For example, to build a monthly report, set `from` to the first day of the month from midnight, and `to` to the first day of the next month at midnight.

func (*ReportBuilder) SkipClampingToNow added in v1.0.0

func (r *ReportBuilder) SkipClampingToNow(skip bool) *ReportBuilder

SkipClampingToNow ignores the current time when preparing the daily summaries within the time range. By default, the reporter doesn't include days that are happening in the future and thus calculate overtime wrongly.

type Summary

type Summary struct {
	TotalOvertime        time.Duration
	TotalExcusedTime     time.Duration
	TotalWorkedTime      time.Duration
	TotalOutOfOfficeTime time.Duration
	// TotalLeave is the amount of paid leave days.
	// This value respects FTE ratio, e.g. in a 50% ratio a public holiday is still counted as '1d'.
	TotalLeave      float64
	AverageWorkload float64
}

type ValidationError added in v1.6.0

type ValidationError struct {
	Date time.Time
	Err  error
}

func NewValidationError added in v1.6.0

func NewValidationError(forDate time.Time, err error) *ValidationError

func (*ValidationError) Error added in v1.6.0

func (e *ValidationError) Error() string

func (*ValidationError) Unwrap added in v1.6.0

func (e *ValidationError) Unwrap() error

type ValidationErrorList added in v1.6.0

type ValidationErrorList struct {
	Errors []*ValidationError
}

func (*ValidationErrorList) Error added in v1.6.0

func (l *ValidationErrorList) Error() string

Error returns a comma-separated list of dates that have a validation error.

type YearlyReport added in v0.7.0

type YearlyReport struct {
	MonthlyReports []BalanceReport
	Employee       model.Employee
	Year           int
	Summary        YearlySummary
}

type YearlyReportBuilder added in v1.0.0

type YearlyReportBuilder struct {
	// contains filtered or unexported fields
}

func NewYearlyReporter added in v1.0.0

func NewYearlyReporter(attendances model.AttendanceList, leaves odoo.List[model.Leave], employee model.Employee, contracts model.ContractList, payslips model.PayslipList) *YearlyReportBuilder

func (*YearlyReportBuilder) CalculateYearlyReport added in v1.0.0

func (r *YearlyReportBuilder) CalculateYearlyReport() (YearlyReport, error)

func (*YearlyReportBuilder) SetYear added in v1.0.0

func (r *YearlyReportBuilder) SetYear(year int) *YearlyReportBuilder

type YearlySummary added in v0.7.0

type YearlySummary struct {
	TotalOvertime time.Duration
	TotalExcused  time.Duration
	TotalWorked   time.Duration
	TotalLeaves   float64
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL