slave salary
This commit is contained in:
parent
b039d1fcf8
commit
26fb5fdb6f
|
@ -66,7 +66,7 @@ func (d *StaffSalaryDao) GetBy(username, month string) (*model.StaffSalary, erro
|
||||||
return &u, nil
|
return &u, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *StaffSalaryDao) Query(month, username string) ([]*model.StaffSalary, error) {
|
func (d *StaffSalaryDao) Query(month, username string, master *string) ([]*model.StaffSalary, error) {
|
||||||
var u []*model.StaffSalary
|
var u []*model.StaffSalary
|
||||||
tx := GetDB().Table(d.TableName())
|
tx := GetDB().Table(d.TableName())
|
||||||
if month != "" {
|
if month != "" {
|
||||||
|
@ -75,6 +75,10 @@ func (d *StaffSalaryDao) Query(month, username string) ([]*model.StaffSalary, er
|
||||||
if username != "" {
|
if username != "" {
|
||||||
tx.Where("username = ?", username)
|
tx.Where("username = ?", username)
|
||||||
}
|
}
|
||||||
|
if master != nil {
|
||||||
|
tx.Where("master = ?", *master)
|
||||||
|
}
|
||||||
|
|
||||||
tx.Order("month DESC")
|
tx.Order("month DESC")
|
||||||
|
|
||||||
res := tx.Find(&u)
|
res := tx.Find(&u)
|
||||||
|
|
|
@ -9,6 +9,7 @@ type StaffInfo struct {
|
||||||
Id int64
|
Id int64
|
||||||
Username string
|
Username string
|
||||||
Realname string
|
Realname string
|
||||||
|
Master string
|
||||||
AlipayUid string
|
AlipayUid string
|
||||||
StaffType string
|
StaffType string
|
||||||
Phone string
|
Phone string
|
||||||
|
|
|
@ -15,6 +15,7 @@ var (
|
||||||
type StaffSalary struct {
|
type StaffSalary struct {
|
||||||
Id int64
|
Id int64
|
||||||
Username string
|
Username string
|
||||||
|
Master string
|
||||||
Month string
|
Month string
|
||||||
BaseSalary float64
|
BaseSalary float64
|
||||||
PerfSalary float64
|
PerfSalary float64
|
||||||
|
@ -33,12 +34,19 @@ type StaffSalary struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StaffSalary) GetRealSalary() float64 {
|
func (s *StaffSalary) GetRealSalary() float64 {
|
||||||
|
if s.Master == "" {
|
||||||
return butil.FloatCut(s.AttendSalary + s.PerfSalary + s.AwardSalary - s.SocialInsurence - s.PersonalTax - s.HouseFund)
|
return butil.FloatCut(s.AttendSalary + s.PerfSalary + s.AwardSalary - s.SocialInsurence - s.PersonalTax - s.HouseFund)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return butil.FloatCut(s.BaseSalary)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *StaffSalary) GetShouldSalary() float64 {
|
func (s *StaffSalary) GetShouldSalary() float64 {
|
||||||
|
if s.Master == "" {
|
||||||
return butil.FloatCut(s.AttendSalary + s.PerfSalary + s.AwardSalary)
|
return butil.FloatCut(s.AttendSalary + s.PerfSalary + s.AwardSalary)
|
||||||
}
|
}
|
||||||
|
return butil.FloatCut(s.BaseSalary)
|
||||||
|
}
|
||||||
|
|
||||||
type StaffSalarySort []*StaffSalary
|
type StaffSalarySort []*StaffSalary
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"enterprise/common/config"
|
"enterprise/common/config"
|
||||||
"enterprise/common/dao"
|
"enterprise/common/dao"
|
||||||
"enterprise/common/model"
|
"enterprise/common/model"
|
||||||
|
"enterprise/service"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
@ -29,7 +30,7 @@ type StaffSalary struct {
|
||||||
|
|
||||||
func (s *StaffSalary) History(ctx *gin.Context) {
|
func (s *StaffSalary) History(ctx *gin.Context) {
|
||||||
username := ctx.Query("username")
|
username := ctx.Query("username")
|
||||||
staffSalarys, err := dao.NewStaffSalaryDao().Query("", username)
|
staffSalarys, err := dao.NewStaffSalaryDao().Query("", username, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(config.ErrDb.New().Append(err))
|
panic(config.ErrDb.New().Append(err))
|
||||||
}
|
}
|
||||||
|
@ -77,7 +78,7 @@ func (s *StaffSalary) History(ctx *gin.Context) {
|
||||||
|
|
||||||
func (s *StaffSalary) Agent(month string, ctx *gin.Context) {
|
func (s *StaffSalary) Agent(month string, ctx *gin.Context) {
|
||||||
xls := ctx.Query("xls")
|
xls := ctx.Query("xls")
|
||||||
staffSalarys, err := dao.NewStaffSalaryDao().Query(month, "")
|
staffSalarys, err := dao.NewStaffSalaryDao().Query(month, "", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(config.ErrDb.New().Append(err))
|
panic(config.ErrDb.New().Append(err))
|
||||||
}
|
}
|
||||||
|
@ -139,7 +140,7 @@ func (s *StaffSalary) Agent(month string, ctx *gin.Context) {
|
||||||
|
|
||||||
func (s *StaffSalary) Bank(month string, ctx *gin.Context) {
|
func (s *StaffSalary) Bank(month string, ctx *gin.Context) {
|
||||||
xls := ctx.Query("xls")
|
xls := ctx.Query("xls")
|
||||||
staffSalarys, err := dao.NewStaffSalaryDao().Query(month, "")
|
staffSalarys, err := dao.NewStaffSalaryDao().Query(month, "", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(config.ErrDb.New().Append(err))
|
panic(config.ErrDb.New().Append(err))
|
||||||
}
|
}
|
||||||
|
@ -197,15 +198,18 @@ func (s *StaffSalary) Bank(month string, ctx *gin.Context) {
|
||||||
|
|
||||||
func (s *StaffSalary) Summary(month string, ctx *gin.Context) {
|
func (s *StaffSalary) Summary(month string, ctx *gin.Context) {
|
||||||
xls := ctx.Query("xls")
|
xls := ctx.Query("xls")
|
||||||
staffSalarys, err := dao.NewStaffSalaryDao().Query(month, "")
|
masterBank := ""
|
||||||
|
staffSalarys, err := dao.NewStaffSalaryDao().Query(month, "", &masterBank)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(config.ErrDb.New().Append(err))
|
panic(config.ErrDb.New().Append(err))
|
||||||
}
|
}
|
||||||
sort.Sort(model.StaffSalarySort(staffSalarys))
|
sort.Sort(model.StaffSalarySort(staffSalarys))
|
||||||
|
|
||||||
header := []string{"姓名", "身份证号", "入职日期", "转正日期", "基本工资", "绩效工资", "出勤工资", "奖金", "社保扣除", "公积金扣除", "个税扣除", "应出勤天数", "实际出勤天数", "出勤率", "补卡天数", "请假天数", "实发工资", "状态"}
|
header := []string{"姓名", "身份证号", "入职日期", "转正日期", "基本工资", "绩效工资", "出勤工资", "附属工资", "奖金", "社保扣除", "公积金扣除", "个税扣除", "应出勤天数", "实际出勤天数", "出勤率", "补卡天数", "请假天数", "实发工资", "状态"}
|
||||||
datas := make([][]string, 0)
|
datas := make([][]string, 0)
|
||||||
summary := new(model.StaffSalary)
|
summary := new(model.StaffSalary)
|
||||||
|
totalCount := 0
|
||||||
|
totalSlaveSalary := float64(0)
|
||||||
for _, staff := range staffSalarys {
|
for _, staff := range staffSalarys {
|
||||||
baseInfo, err := dao.NewStaffInfoDao().GetByUsername(staff.Username)
|
baseInfo, err := dao.NewStaffInfoDao().GetByUsername(staff.Username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -225,6 +229,14 @@ func (s *StaffSalary) Summary(month string, ctx *gin.Context) {
|
||||||
item = append(item, cast.ToString(staff.BaseSalary))
|
item = append(item, cast.ToString(staff.BaseSalary))
|
||||||
item = append(item, cast.ToString(butil.FloatCut(staff.PerfSalary)))
|
item = append(item, cast.ToString(butil.FloatCut(staff.PerfSalary)))
|
||||||
item = append(item, cast.ToString(butil.FloatCut(staff.AttendSalary)))
|
item = append(item, cast.ToString(butil.FloatCut(staff.AttendSalary)))
|
||||||
|
|
||||||
|
slaveSalary := float64(0)
|
||||||
|
info, _ := dao.NewStaffInfoDao().GetByUsername(staff.Username)
|
||||||
|
if info != nil {
|
||||||
|
slaveSalary = service.NewStaff(info, nil).GetSlaveSalary(month)
|
||||||
|
}
|
||||||
|
|
||||||
|
item = append(item, cast.ToString(butil.FloatCut(slaveSalary)))
|
||||||
item = append(item, cast.ToString(butil.FloatCut(staff.AwardSalary)))
|
item = append(item, cast.ToString(butil.FloatCut(staff.AwardSalary)))
|
||||||
item = append(item, cast.ToString(staff.SocialInsurence))
|
item = append(item, cast.ToString(staff.SocialInsurence))
|
||||||
item = append(item, cast.ToString(staff.HouseFund))
|
item = append(item, cast.ToString(staff.HouseFund))
|
||||||
|
@ -234,14 +246,15 @@ func (s *StaffSalary) Summary(month string, ctx *gin.Context) {
|
||||||
item = append(item, fmt.Sprintf("%d%%", int(100*staff.RealDay/staff.TotalDay)))
|
item = append(item, fmt.Sprintf("%d%%", int(100*staff.RealDay/staff.TotalDay)))
|
||||||
item = append(item, cast.ToString(extra["approvalCheckinDay"]))
|
item = append(item, cast.ToString(extra["approvalCheckinDay"]))
|
||||||
item = append(item, cast.ToString(staff.Holiday))
|
item = append(item, cast.ToString(staff.Holiday))
|
||||||
item = append(item, cast.ToString(staff.GetRealSalary()))
|
item = append(item, cast.ToString(staff.GetRealSalary()+slaveSalary))
|
||||||
if staff.TotalDay != cast.ToFloat64(staff.RealDay)+cast.ToFloat64(staff.Holiday) {
|
if staff.TotalDay != cast.ToFloat64(staff.RealDay)+cast.ToFloat64(staff.Holiday) {
|
||||||
item = append(item, "【异常】")
|
item = append(item, "【异常】")
|
||||||
} else {
|
} else {
|
||||||
item = append(item, "")
|
item = append(item, "")
|
||||||
}
|
}
|
||||||
//item = append(item, fmt.Sprintf("https://e.batiao8.com/staff/salary/history?username=%s", baseInfo.Username))
|
//item = append(item, fmt.Sprintf("https://e.batiao8.com/staff/salary/history?username=%s", baseInfo.Username))
|
||||||
|
totalCount += 1
|
||||||
|
totalSlaveSalary += slaveSalary
|
||||||
datas = append(datas, item)
|
datas = append(datas, item)
|
||||||
summary.BaseSalary += staff.BaseSalary
|
summary.BaseSalary += staff.BaseSalary
|
||||||
summary.PerfSalary += staff.PerfSalary
|
summary.PerfSalary += staff.PerfSalary
|
||||||
|
@ -260,11 +273,11 @@ func (s *StaffSalary) Summary(month string, ctx *gin.Context) {
|
||||||
summary.SocialInsurence = butil.FloatCut(summary.SocialInsurence)
|
summary.SocialInsurence = butil.FloatCut(summary.SocialInsurence)
|
||||||
summary.HouseFund = butil.FloatCut(summary.HouseFund)
|
summary.HouseFund = butil.FloatCut(summary.HouseFund)
|
||||||
summary.PersonalTax = butil.FloatCut(summary.PersonalTax)
|
summary.PersonalTax = butil.FloatCut(summary.PersonalTax)
|
||||||
datas = append(datas, []string{"合计", "-", "-", "-",
|
datas = append(datas, []string{"合计", cast.ToString(totalCount), "-", "-",
|
||||||
cast.ToString(summary.BaseSalary), cast.ToString(summary.PerfSalary), cast.ToString(summary.AttendSalary), cast.ToString(summary.AwardSalary), cast.ToString(summary.SocialInsurence),
|
cast.ToString(summary.BaseSalary), cast.ToString(summary.PerfSalary), cast.ToString(summary.AttendSalary), cast.ToString(totalSlaveSalary),
|
||||||
cast.ToString(summary.HouseFund),
|
cast.ToString(summary.AwardSalary), cast.ToString(summary.SocialInsurence), cast.ToString(summary.HouseFund),
|
||||||
cast.ToString(summary.PersonalTax), "-", "-", "-", "-", cast.ToString(summary.Holiday),
|
cast.ToString(summary.PersonalTax), "-", "-", "-", "-", cast.ToString(summary.Holiday),
|
||||||
cast.ToString(butil.FloatCut(summary.GetRealSalary())), "-"})
|
cast.ToString(butil.FloatCut(summary.GetRealSalary() + totalSlaveSalary)), "-"})
|
||||||
|
|
||||||
if xls != "" {
|
if xls != "" {
|
||||||
filename := fmt.Sprintf("summary_%s.xlsx", time.Now().Format("20060102_150405"))
|
filename := fmt.Sprintf("summary_%s.xlsx", time.Now().Format("20060102_150405"))
|
||||||
|
|
|
@ -25,6 +25,34 @@ func NewStaff(info *model.StaffInfo, config *model.StaffConfig) *Staff {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Staff) GetSlaveSalary(month string) float64 {
|
||||||
|
slaveSalarys, err := dao.NewStaffSalaryDao().Query(month, "", &s.info.Username)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("db error :%s", err.Error())
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
totalSumSalary := float64(0)
|
||||||
|
if len(slaveSalarys) != 0 {
|
||||||
|
for _, slaveSalary := range slaveSalarys {
|
||||||
|
totalSumSalary += slaveSalary.BaseSalary
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return totalSumSalary
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Staff) CalcSlaveSalary(salary *model.StaffSalary, month string) (*model.StaffSalary, error) {
|
||||||
|
if salary == nil {
|
||||||
|
salary = new(model.StaffSalary)
|
||||||
|
salary.Month = month
|
||||||
|
salary.Username = s.info.Username
|
||||||
|
}
|
||||||
|
salary.BaseSalary = cast.ToFloat64(s.info.BaseSalary)
|
||||||
|
salary.Master = s.info.Master
|
||||||
|
|
||||||
|
return salary, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Staff) CalcSalary(salary *model.StaffSalary, month string) (*model.StaffSalary, error) {
|
func (s *Staff) CalcSalary(salary *model.StaffSalary, month string) (*model.StaffSalary, error) {
|
||||||
staff := s.info
|
staff := s.info
|
||||||
if salary == nil {
|
if salary == nil {
|
||||||
|
|
|
@ -55,7 +55,8 @@ func (s *Staff) MontorWorkAge() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Staff) SendStaffSalaryBill(month string) {
|
func (s *Staff) SendStaffSalaryBill(month string) {
|
||||||
staffSalarys, err := dao.NewStaffSalaryDao().Query(month, "")
|
masterBlank := ""
|
||||||
|
staffSalarys, err := dao.NewStaffSalaryDao().Query(month, "", &masterBlank)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("db error :%s", err.Error())
|
log.Errorf("db error :%s", err.Error())
|
||||||
return
|
return
|
||||||
|
@ -76,9 +77,20 @@ func (s *Staff) SendStaffSalaryBill(month string) {
|
||||||
if staffSalary.AwardSalary >= 0.1 {
|
if staffSalary.AwardSalary >= 0.1 {
|
||||||
message = append(message, fmt.Sprintf("额外工资:%.2f", staffSalary.AwardSalary))
|
message = append(message, fmt.Sprintf("额外工资:%.2f", staffSalary.AwardSalary))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//附属工资
|
||||||
|
var slaveSalary float64 = 0
|
||||||
|
staff, _ := dao.NewStaffInfoDao().GetByUsername(staffSalary.Username)
|
||||||
|
if staff != nil {
|
||||||
|
slaveSalary = service.NewStaff(staff, nil).GetSlaveSalary(month)
|
||||||
|
if slaveSalary > 0.1 {
|
||||||
|
message = append(message, fmt.Sprintf("附属工资:%.2f", slaveSalary))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
message = append(message, fmt.Sprintf("社保扣除:%.2f", staffSalary.SocialInsurence))
|
message = append(message, fmt.Sprintf("社保扣除:%.2f", staffSalary.SocialInsurence))
|
||||||
message = append(message, fmt.Sprintf("个税扣除:%.2f", staffSalary.PersonalTax))
|
message = append(message, fmt.Sprintf("个税扣除:%.2f", staffSalary.PersonalTax))
|
||||||
message = append(message, fmt.Sprintf("实发工资:%.2f", staffSalary.GetRealSalary()))
|
message = append(message, fmt.Sprintf("实发工资:%.2f", staffSalary.GetRealSalary()+slaveSalary))
|
||||||
|
|
||||||
if err := global.SendMessage([]string{"jiangyong"}, strings.Join(message, "\n")); err != nil {
|
if err := global.SendMessage([]string{"jiangyong"}, strings.Join(message, "\n")); err != nil {
|
||||||
log.Errorf("send message error :%s", err.Error())
|
log.Errorf("send message error :%s", err.Error())
|
||||||
|
@ -165,23 +177,29 @@ func (s *Staff) SyncStaffSalary(month string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
config, err := dao.NewUserConfigDao().GetByUsername(staff.Username)
|
|
||||||
if err != nil || config == nil {
|
|
||||||
log.Errorf("username[%s] not config,skip!!", staff.Username)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
salary, err := dao.NewStaffSalaryDao().GetBy(staff.Username, month)
|
salary, err := dao.NewStaffSalaryDao().GetBy(staff.Username, month)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("db error :%s", err.Error())
|
log.Errorf("db error :%s", err.Error())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//附属员工直接生成工资单
|
||||||
|
if staff.Master != "" {
|
||||||
|
staffService := service.NewStaff(staff, nil)
|
||||||
|
salary, err = staffService.CalcSlaveSalary(salary, month)
|
||||||
|
} else {
|
||||||
|
config, err := dao.NewUserConfigDao().GetByUsername(staff.Username)
|
||||||
|
if err != nil || config == nil {
|
||||||
|
log.Errorf("username[%s] not config,skip!!", staff.Username)
|
||||||
|
continue
|
||||||
|
}
|
||||||
staffService := service.NewStaff(staff, config)
|
staffService := service.NewStaff(staff, config)
|
||||||
salary, err = staffService.CalcSalary(salary, month)
|
salary, err = staffService.CalcSalary(salary, month)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("username[%s] staffService.CalcSalary error :%s", staff.Username, err.Error())
|
log.Errorf("username[%s] staffService.CalcSalary error :%s", staff.Username, err.Error())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if salary.Id == 0 {
|
if salary.Id == 0 {
|
||||||
_, err = dao.NewStaffSalaryDao().Create(salary)
|
_, err = dao.NewStaffSalaryDao().Create(salary)
|
||||||
|
|
Loading…
Reference in New Issue