迟到计算

This commit is contained in:
jiangyong27 2024-02-02 16:19:30 +08:00
parent 4bf3fdd053
commit 2f678ed714
1 changed files with 34 additions and 21 deletions

View File

@ -100,7 +100,7 @@ func (s *Staff) SyncStaffSalary(month string) {
month = time.Now().AddDate(0, -1, 0).Format("2006-01")
}
month = strings.ReplaceAll(month, "-", "")
totalDays := s.getTotalWordDay(month)
totalDays := s.getTotalWorkDay(month)
monthTime, _ := time.ParseInLocation("200601", month, time.Local)
startDate := cast.ToInt(monthTime.Format("20060102"))
endDate := cast.ToInt(monthTime.AddDate(0, 1, -1).Format("20060102"))
@ -159,27 +159,11 @@ func (s *Staff) SyncStaffSalary(month string) {
surplusHoliday := float64(0)
for _, vac := range approveVacations {
holiday += vac.VacationDuration
surplusHoliday += goutil.If(vac.VacationDuration <= 1, 1-vac.VacationDuration, 0)
surplusHoliday += goutil.If(vac.VacationDuration < 1, 1-vac.VacationDuration, 0)
}
// 打卡正常天数+补卡天数 为正常出勤天数
realWorkdays := 0
userCheckins, err := dao.NewCheckinDao().Query(staff.Username, month, false)
if err != nil {
log.Errorf("db error :%s", err.Error())
continue
}
for _, checkin := range userCheckins {
if checkin.Exception == "" {
realWorkdays += 1
continue
}
approvalCheckin, _ := dao.NewApprovalCheckinDao().GetByUsernameDay(staff.Username, checkin.Day)
if approvalCheckin != nil {
realWorkdays += 1
}
}
realWorkDays := s.getRealWorkDay(staff.Username, month)
extra := make(map[string]interface{})
salary.BaseSalary = cast.ToFloat64(staff.Salary)
salary.Holiday = holiday
@ -191,7 +175,7 @@ func (s *Staff) SyncStaffSalary(month string) {
discount = discount*float64(officialDate-startDate)/totalMonthDay + 1*float64(endDate-officialDate+1)/totalMonthDay
}
realWorkDays := float64(realWorkdays) + surplusHoliday
realWorkDays = realWorkDays + surplusHoliday
realSalary := salary.BaseSalary * (realWorkDays / float64(totalDays)) * discount
staffSalaryPerDay := cast.ToFloat64(config.Get(model.StaffSalaryPerDay))
if staffSalaryPerDay > 0 {
@ -231,7 +215,36 @@ func (s *Staff) SyncStaffSalary(month string) {
}
func (s *Staff) getTotalWordDay(month string) int64 {
func (s *Staff) getRealWorkDay(username, month string) float64 {
realWorkdays := float64(0)
userCheckins, err := dao.NewCheckinDao().Query(username, month, false)
if err != nil {
log.Errorf("db error :%s", err.Error())
return realWorkdays
}
for _, checkin := range userCheckins {
if checkin.Exception == "" {
realWorkdays += 1
continue
}
approvalCheckin, _ := dao.NewApprovalCheckinDao().GetByUsernameDay(username, checkin.Day)
if approvalCheckin != nil {
realWorkdays += 1
continue
}
// 迟到的按时间折算
if strings.Contains(checkin.Exception, "上班打卡:时间异常") {
stTime := time.Unix(checkin.StartTime, 0)
later := float64(stTime.Hour() - 8) //迟到小时数从9点算
realWorkdays += (8 - later) / 8
continue
}
}
return realWorkdays
}
func (s *Staff) getTotalWorkDay(month string) int64 {
// 最多人数的应出勤天数 为真正的出勤天数
userCounts, err := dao.NewCheckinDao().CountUsername(month)
if err != nil {