This commit is contained in:
jiangyong27 2024-11-04 23:30:31 +08:00
parent bbc9c78499
commit b039d1fcf8
6 changed files with 65 additions and 6 deletions

View File

@ -66,12 +66,16 @@ func (d *StaffSalaryDao) GetBy(username, month string) (*model.StaffSalary, erro
return &u, nil
}
func (d *StaffSalaryDao) Query(month string) ([]*model.StaffSalary, error) {
func (d *StaffSalaryDao) Query(month, username string) ([]*model.StaffSalary, error) {
var u []*model.StaffSalary
tx := GetDB().Table(d.TableName())
if month != "" {
tx = tx.Where("month = ?", month)
}
if username != "" {
tx.Where("username = ?", username)
}
tx.Order("month DESC")
res := tx.Find(&u)
if res.Error == gorm.ErrRecordNotFound {

View File

@ -51,7 +51,7 @@
{{range $i, $arr := .data}}
<tr>
{{range $j, $v := $arr}}
<td>{{ $v }}</td>
<td>{{ $v }}</td>
{{end}}
</tr>
{{end}}

View File

@ -34,6 +34,10 @@ func (s *Staff) Salary(ctx *gin.Context) {
}
}
func (s *Staff) SalaryHistory(ctx *gin.Context) {
new(service.StaffSalary).History(ctx)
}
func (s *Staff) SyncStaffInfo(ctx *gin.Context) {
go new(worker.Staff).SyncStaffInfo()
ctx.JSON(http.StatusOK, session.NewRspOk())

View File

@ -18,6 +18,7 @@ func initRoutge(engine *gin.Engine) {
apiGroup.Any("/qyweixin/pay", qyweixin.Pay)
group.GET("/staff/salary", staff.Salary)
group.GET("/staff/salary/history", staff.SalaryHistory)
group.GET("/staff/sync/salary", staff.SyncStaffSalary)
group.GET("/staff/sync/info", staff.SyncStaffInfo)

View File

@ -27,9 +27,57 @@ var (
type StaffSalary struct {
}
func (s *StaffSalary) History(ctx *gin.Context) {
username := ctx.Query("username")
staffSalarys, err := dao.NewStaffSalaryDao().Query("", username)
if err != nil {
panic(config.ErrDb.New().Append(err))
}
header := []string{"月份", "基本工资", "绩效工资", "出勤工资", "奖金", "社保扣除", "公积金扣除", "个税扣除", "应出勤天数", "实际出勤天数", "补卡天数", "请假天数", "实发工资"}
datas := make([][]string, 0)
for _, staff := range staffSalarys {
baseInfo, err := dao.NewStaffInfoDao().GetByUsername(staff.Username)
if err != nil {
log.Errorf("db error :%s", err.Error())
continue
}
if baseInfo == nil {
continue
}
extra := make(map[string]interface{})
json.Unmarshal([]byte(staff.Extra), &extra)
item := make([]string, 0)
item = append(item, cast.ToString(staff.Month))
item = append(item, cast.ToString(staff.BaseSalary))
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.AwardSalary)))
item = append(item, cast.ToString(staff.SocialInsurence))
item = append(item, cast.ToString(staff.HouseFund))
item = append(item, cast.ToString(staff.PersonalTax))
item = append(item, cast.ToString(staff.TotalDay))
item = append(item, cast.ToString(staff.RealDay))
item = append(item, cast.ToString(extra["approvalCheckinDay"]))
item = append(item, cast.ToString(staff.Holiday))
item = append(item, cast.ToString(staff.GetRealSalary()))
datas = append(datas, item)
}
ctx.HTML(http.StatusOK, "salary.html", gin.H{
"title": username + "工资汇总",
"header": header,
"data": datas,
})
}
func (s *StaffSalary) Agent(month string, ctx *gin.Context) {
xls := ctx.Query("xls")
staffSalarys, err := dao.NewStaffSalaryDao().Query(month)
staffSalarys, err := dao.NewStaffSalaryDao().Query(month, "")
if err != nil {
panic(config.ErrDb.New().Append(err))
}
@ -49,6 +97,7 @@ func (s *StaffSalary) Agent(month string, ctx *gin.Context) {
continue
}
item := make([]string, 0)
item = append(item, baseInfo.Realname)
item = append(item, cast.ToString(baseInfo.Idno))
item = append(item, cast.ToString(baseInfo.Phone))
@ -90,7 +139,7 @@ func (s *StaffSalary) Agent(month string, ctx *gin.Context) {
func (s *StaffSalary) Bank(month string, ctx *gin.Context) {
xls := ctx.Query("xls")
staffSalarys, err := dao.NewStaffSalaryDao().Query(month)
staffSalarys, err := dao.NewStaffSalaryDao().Query(month, "")
if err != nil {
panic(config.ErrDb.New().Append(err))
}
@ -148,7 +197,7 @@ func (s *StaffSalary) Bank(month string, ctx *gin.Context) {
func (s *StaffSalary) Summary(month string, ctx *gin.Context) {
xls := ctx.Query("xls")
staffSalarys, err := dao.NewStaffSalaryDao().Query(month)
staffSalarys, err := dao.NewStaffSalaryDao().Query(month, "")
if err != nil {
panic(config.ErrDb.New().Append(err))
}
@ -191,6 +240,7 @@ func (s *StaffSalary) Summary(month string, ctx *gin.Context) {
} else {
item = append(item, "")
}
//item = append(item, fmt.Sprintf("https://e.batiao8.com/staff/salary/history?username=%s", baseInfo.Username))
datas = append(datas, item)
summary.BaseSalary += staff.BaseSalary

View File

@ -55,7 +55,7 @@ func (s *Staff) MontorWorkAge() {
}
func (s *Staff) SendStaffSalaryBill(month string) {
staffSalarys, err := dao.NewStaffSalaryDao().Query(month)
staffSalarys, err := dao.NewStaffSalaryDao().Query(month, "")
if err != nil {
log.Errorf("db error :%s", err.Error())
return