leave day

This commit is contained in:
jiangyong27 2024-07-03 13:24:41 +08:00
parent 96e68e9675
commit c8bc563d93
2 changed files with 13 additions and 3 deletions

View File

@ -15,6 +15,7 @@ type StaffInfo struct {
Salary string
EntryDate string
OfficialDate string
LeaveDate string
BirthDate string
BankName string
BankCard string

View File

@ -110,7 +110,7 @@ func (s *Staff) SyncStaffSalary(month string) {
month = time.Now().AddDate(0, -1, 0).Format("2006-01")
}
month = strings.ReplaceAll(month, "-", "")
//totalDays := s.getTotalWorkDay(month)
maxTotalDays := s.getTotalWorkDayMax(month)
monthTime, _ := time.ParseInLocation("200601", month, time.Local)
startDate := cast.ToInt(monthTime.Format("20060102"))
endDate := cast.ToInt(monthTime.AddDate(0, 1, -1).Format("20060102"))
@ -135,8 +135,10 @@ func (s *Staff) SyncStaffSalary(month string) {
entryTime, _ := time.ParseInLocation("2006-01-02", staff.EntryDate, time.Local)
officalTime, _ := time.ParseInLocation("2006-01-02", staff.OfficialDate, time.Local)
leaveTime, _ := time.ParseInLocation("2006-01-02", staff.LeaveDate, time.Local)
isEntryMonth := goutil.If(cast.ToInt(entryTime.Format("200601")) == cast.ToInt(month), true, false)
isOfficialMonth := goutil.If(cast.ToInt(officalTime.Format("200601")) == cast.ToInt(month), true, false)
isLeaveMonth := goutil.If(cast.ToInt(leaveTime.Format("200601")) == cast.ToInt(month), true, false)
config, err := dao.NewUserConfigDao().GetByUsername(staff.Username)
if err != nil {
@ -159,7 +161,8 @@ func (s *Staff) SyncStaffSalary(month string) {
//社保
socialInsurence := cast.ToFloat64(config.Get(model.StaffSalarySocialInsurence))
if isEntryMonth && entryTime.Day() >= 15 {
//if isEntryMonth && entryTime.Day() >= 15 {
if isEntryMonth { //入职月不买社保
socialInsurence = 0
}
@ -191,6 +194,11 @@ func (s *Staff) SyncStaffSalary(month string) {
discount = discount*float64(officialDate-startDate)/totalMonthDay + 1*float64(endDate-officialDate+1)/totalMonthDay
}
// 入职月或离职月以大多数人的出勤天数为准
if isEntryMonth || isLeaveMonth {
totalDays = maxTotalDays
}
realWorkDays = realWorkDays + surplusHoliday
attendSalary := salary.BaseSalary * (realWorkDays / float64(totalDays)) * discount
staffSalaryPerDay := cast.ToFloat64(config.Get(model.StaffSalaryPerDay))
@ -289,7 +297,8 @@ func (s *Staff) getTotalWorkDay(username, month string) int64 {
checkins, _ := dao.NewCheckinDao().Query(username, month, false)
return int64(len(checkins))
}
func (s *Staff) getTotalWorkDay_bak(month string) int64 {
func (s *Staff) getTotalWorkDayMax(month string) int64 {
// 最多人数的应出勤天数 为真正的出勤天数
userCounts, err := dao.NewCheckinDao().CountUsername(month)
if err != nil {