Skip to content

Commit

Permalink
Merge pull request #134 from vshn/fix-nil
Browse files Browse the repository at this point in the history
Fix crash when generating an employee report
  • Loading branch information
ccremer authored Nov 8, 2022
2 parents 5956f4e + 54564f8 commit 51c52b1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/web/employeereport/employeereport_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,10 @@ func (c *EmployeeReport) fetchLeaves(ctx context.Context) error {
}

func (c *EmployeeReport) calculateMonthlyReport(_ context.Context) error {
tz := c.getTimeZone()
reporter := timesheet.NewReporter(c.Attendances, c.Leaves, &c.Employee, c.Contracts).
SetRange(c.Start, c.Stop.AddDate(0, 0, 1)).
SetTimeZone(controller.TimezoneOrDefault(c.NextPayslip.TimeZone, controller.DefaultTimeZone))
SetTimeZone(tz)
report, err := reporter.CalculateReport()
c.Result = report
return err
Expand Down Expand Up @@ -194,3 +195,12 @@ func (c *EmployeeReport) ignoreNoContractFound(_ context.Context, err error) err
}
return err
}

func (c *EmployeeReport) getTimeZone() *time.Location {
if c.NextPayslip != nil && !c.NextPayslip.TimeZone.IsEmpty() {
// timezone from payslip has precedence.
return c.NextPayslip.TimeZone.Location()
}
// last resort to default TZ.
return controller.DefaultTimeZone
}

0 comments on commit 51c52b1

Please sign in to comment.