迟到计算
This commit is contained in:
parent
4bf3fdd053
commit
2f678ed714
|
@ -100,7 +100,7 @@ func (s *Staff) SyncStaffSalary(month string) {
|
||||||
month = time.Now().AddDate(0, -1, 0).Format("2006-01")
|
month = time.Now().AddDate(0, -1, 0).Format("2006-01")
|
||||||
}
|
}
|
||||||
month = strings.ReplaceAll(month, "-", "")
|
month = strings.ReplaceAll(month, "-", "")
|
||||||
totalDays := s.getTotalWordDay(month)
|
totalDays := s.getTotalWorkDay(month)
|
||||||
monthTime, _ := time.ParseInLocation("200601", month, time.Local)
|
monthTime, _ := time.ParseInLocation("200601", month, time.Local)
|
||||||
startDate := cast.ToInt(monthTime.Format("20060102"))
|
startDate := cast.ToInt(monthTime.Format("20060102"))
|
||||||
endDate := cast.ToInt(monthTime.AddDate(0, 1, -1).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)
|
surplusHoliday := float64(0)
|
||||||
for _, vac := range approveVacations {
|
for _, vac := range approveVacations {
|
||||||
holiday += vac.VacationDuration
|
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
|
realWorkDays := s.getRealWorkDay(staff.Username, month)
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extra := make(map[string]interface{})
|
extra := make(map[string]interface{})
|
||||||
salary.BaseSalary = cast.ToFloat64(staff.Salary)
|
salary.BaseSalary = cast.ToFloat64(staff.Salary)
|
||||||
salary.Holiday = holiday
|
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
|
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
|
realSalary := salary.BaseSalary * (realWorkDays / float64(totalDays)) * discount
|
||||||
staffSalaryPerDay := cast.ToFloat64(config.Get(model.StaffSalaryPerDay))
|
staffSalaryPerDay := cast.ToFloat64(config.Get(model.StaffSalaryPerDay))
|
||||||
if staffSalaryPerDay > 0 {
|
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)
|
userCounts, err := dao.NewCheckinDao().CountUsername(month)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue