leavedate

This commit is contained in:
jiangyong27 2024-11-01 16:31:49 +08:00
parent 86f66cf654
commit 73a3e853df
1 changed files with 26 additions and 12 deletions

View File

@ -11,6 +11,7 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/smbrave/goutil" "github.com/smbrave/goutil"
"github.com/spf13/cast" "github.com/spf13/cast"
"math"
"strings" "strings"
"time" "time"
) )
@ -217,22 +218,23 @@ func (s *Staff) SyncStaffSalary(month string) {
holiday := float64(0) holiday := float64(0)
surplusHoliday := float64(0) surplusHoliday := float64(0)
for _, vac := range approveVacations { for _, vac := range approveVacations {
startTime, _ := time.ParseInLocation(vac.VacationStartTime, "2006-01-02 15:04:05", time.Local) startTime, _ := time.ParseInLocation("2006-01-02 15:04:05", vac.VacationStartTime, time.Local)
endTime, _ := time.ParseInLocation(vac.VacationEndTime, "2006-01-02 15:04:05", time.Local) endTime, _ := time.ParseInLocation("2006-01-02 15:04:05", vac.VacationEndTime, time.Local)
//同一天请假时长大于8小时算一天 //同一天请假时长大于8小时算一天
if startTime.Format("2006-01-02") == endTime.Format("2006-01-02") && vac.VacationDuration > 1 { if startTime.Format("2006-01-02") == endTime.Format("2006-01-02") && vac.VacationDuration > 1 {
holiday += 1 holiday += 1
} else { } else {
holiday += vac.VacationDuration holiday += vac.VacationDuration
//不是整天数,把剩余的算上
span := vac.VacationDuration - math.Floor(vac.VacationDuration)
surplusHoliday += goutil.If(math.Abs(span) < 0.000001, 0, 1-span)
} }
surplusHoliday += goutil.If(vac.VacationDuration < 1, 1-vac.VacationDuration, 0)
} }
// 打卡正常天数+补卡天数 为正常出勤天数 // 打卡正常天数+补卡天数 为正常出勤天数
totalDays := s.getTotalWorkDay(staff.Username, month) totalDays := s.getTotalWorkDay(staff.Username, month)
realWorkDays := s.getRealWorkDay(staff.EntryDate, staff.Username, month) realWorkDays := s.getRealWorkDay(staff.EntryDate, staff.LeaveDate, staff.Username, month)
approvalCheckinDay := s.getApprovalCheckinDay(staff.Username, month) approvalCheckinDay := s.getApprovalCheckinDay(staff.Username, month)
extra := make(map[string]interface{}) extra := make(map[string]interface{})
salary.BaseSalary = cast.ToFloat64(staff.Salary) salary.BaseSalary = cast.ToFloat64(staff.Salary)
@ -310,7 +312,7 @@ func (s *Staff) getApprovalCheckinDay(username, month string) int {
return approvalDay return approvalDay
} }
func (s *Staff) getRealWorkDay(entryDate, username, month string) float64 { func (s *Staff) getRealWorkDay(entryDate, leaveDate, username, month string) float64 {
realWorkdays := float64(0) realWorkdays := float64(0)
userCheckins, err := dao.NewCheckinDao().Query(username, month, false) userCheckins, err := dao.NewCheckinDao().Query(username, month, false)
if err != nil { if err != nil {
@ -318,12 +320,30 @@ func (s *Staff) getRealWorkDay(entryDate, username, month string) float64 {
return realWorkdays return realWorkdays
} }
approvalCheckinDay := 0 approvalCheckinDay := 0
//入职当天算工作日
entryTime, _ := time.ParseInLocation("2006-01-02", entryDate, time.Local)
if entryTime.Format("200601") == month {
realWorkdays += 1
}
//离职当天算工作日
leaveTime, _ := time.ParseInLocation("2006-01-02", leaveDate, time.Local)
if leaveTime.Format("200601") == month {
realWorkdays += 1
}
for _, checkin := range userCheckins { for _, checkin := range userCheckins {
if checkin.Exception == "" { if checkin.Exception == "" {
realWorkdays += 1 realWorkdays += 1
continue continue
} }
//入职离职当天已经算过了
if entryTime.Format("2006-01-02") == checkin.Day || leaveTime.Format("2006-01-02") == checkin.Day {
continue
}
//有补卡申请就直接算出勤 //有补卡申请就直接算出勤
approvalCheckin, _ := dao.NewApprovalCheckinDao().GetByUsernameDay(username, checkin.Day) approvalCheckin, _ := dao.NewApprovalCheckinDao().GetByUsernameDay(username, checkin.Day)
if approvalCheckin != nil { if approvalCheckin != nil {
@ -338,12 +358,6 @@ func (s *Staff) getRealWorkDay(entryDate, username, month string) float64 {
continue continue
} }
//入职当天考勤异常忽略
if checkin.Day == entryDate {
realWorkdays += 1
continue
}
// 迟到的按时间折算 // 迟到的按时间折算
if strings.Contains(checkin.Exception, "上班打卡:时间异常") { if strings.Contains(checkin.Exception, "上班打卡:时间异常") {
stTime := time.Unix(checkin.StartTime, 0) stTime := time.Unix(checkin.StartTime, 0)