enterprise/server/api/salary.go

102 lines
4.0 KiB
Go

package api
import (
"enterprise/common/model"
"github.com/smbrave/goutil"
"github.com/spf13/cast"
)
type Salary struct {
Id string `json:"id"`
Month string `json:"month"`
Username string `json:"username"`
Realname string `json:"realname"`
BaseSalary string `json:"base_salary"`
TargetSalary string `json:"target_salary"`
RealSalary string `json:"real_salary"`
AttendIncome string `json:"attend_income"`
TargetIncome string `json:"target_income"`
AwardIncome string `json:"award_income"`
OtherIncome string `json:"other_income"`
ShouldDay string `json:"should_day"`
AttendDay string `json:"attend_day"`
HolidayDay string `json:"holiday_day"`
LackDay string `json:"lack_day"`
SocialDeduct string `json:"social_deduct"`
HouseDeduct string `json:"house_deduct"`
PersonalDeduct string `json:"personal_deduct"`
OtherDeduct string `json:"other_deduct"`
CreateTime string `json:"create_time"`
UpdateTime string `json:"update_time"`
Extra string `json:"extra"`
Status string `json:"status"`
}
type CreateSalaryReq struct {
Month string `json:"month"`
Username string `json:"username"`
}
type UpdateSalaryReq struct {
Id string `json:"id"`
OtherIncome string `json:"other_income"`
OtherDeduct string `json:"other_deduct"`
PersonalDeduct string `json:"personal_deduct"`
Status string `json:"status"`
}
type PaySalaryReq struct {
SalaryId string `json:"salary_id"`
PayType string `json:"pay_type"`
}
type ListSalaryReq struct {
BaseRequest
StartMonth string `form:"start_month"`
EndMonth string `form:"end_month"`
StaffId string `form:"staff_id"`
Status string `form:"status"`
}
func (s *Salary) From(m *model.StaffSalary) {
s.Id = cast.ToString(m.Id)
s.Username = m.Username
s.Month = m.Month
s.RealSalary = goutil.FormatFloat(m.GetRealSalary())
s.AttendIncome = goutil.FormatFloat(m.AttendSalary)
s.TargetIncome = goutil.FormatFloat(m.TargetSalary)
s.AwardIncome = goutil.FormatFloat(m.AwardSalary)
s.OtherIncome = goutil.FormatFloat(m.OtherSalary)
s.ShouldDay = cast.ToString(m.ShouldDay)
s.AttendDay = goutil.FormatFloat(m.AttendDay)
s.HolidayDay = goutil.FormatFloat(m.HolidayDay)
s.SocialDeduct = goutil.FormatFloat(m.SocialDeduct)
s.HouseDeduct = goutil.FormatFloat(m.HouseDeduct)
s.PersonalDeduct = goutil.FormatFloat(m.PersonalDeduct)
s.OtherDeduct = goutil.FormatFloat(m.OtherDeduct)
s.CreateTime = goutil.TimeToDateTime(m.CreateTime)
s.UpdateTime = goutil.TimeToDateTime(m.UpdateTime)
s.Extra = m.Extra
s.Status = cast.ToString(m.Status)
s.LackDay = goutil.FormatFloat(float64(m.ShouldDay) - m.AttendDay - m.HolidayDay)
}
func (s *Salary) Add(o *Salary) {
s.TargetSalary = goutil.FormatFloat(cast.ToFloat64(s.TargetSalary) + cast.ToFloat64(o.TargetSalary))
s.BaseSalary = goutil.FormatFloat(cast.ToFloat64(s.BaseSalary) + cast.ToFloat64(o.BaseSalary))
s.RealSalary = goutil.FormatFloat(cast.ToFloat64(s.RealSalary) + cast.ToFloat64(o.RealSalary))
s.AttendIncome = goutil.FormatFloat(cast.ToFloat64(s.AttendIncome) + cast.ToFloat64(o.AttendIncome))
s.TargetIncome = goutil.FormatFloat(cast.ToFloat64(s.TargetIncome) + cast.ToFloat64(o.TargetIncome))
s.AwardIncome = goutil.FormatFloat(cast.ToFloat64(s.AwardIncome) + cast.ToFloat64(o.AwardIncome))
s.OtherIncome = goutil.FormatFloat(cast.ToFloat64(s.OtherIncome) + cast.ToFloat64(o.OtherIncome))
s.ShouldDay = cast.ToString(cast.ToInt(s.ShouldDay) + cast.ToInt(o.ShouldDay))
s.AttendDay = goutil.FormatFloat(cast.ToFloat64(s.AttendDay) + cast.ToFloat64(o.AttendDay))
s.HolidayDay = goutil.FormatFloat(cast.ToFloat64(s.HolidayDay) + cast.ToFloat64(o.HolidayDay))
s.SocialDeduct = goutil.FormatFloat(cast.ToFloat64(s.SocialDeduct) + cast.ToFloat64(o.SocialDeduct))
s.HouseDeduct = goutil.FormatFloat(cast.ToFloat64(s.HouseDeduct) + cast.ToFloat64(o.HouseDeduct))
s.PersonalDeduct = goutil.FormatFloat(cast.ToFloat64(s.PersonalDeduct) + cast.ToFloat64(o.PersonalDeduct))
s.OtherDeduct = goutil.FormatFloat(cast.ToFloat64(s.OtherDeduct) + cast.ToFloat64(o.OtherDeduct))
}