diff --git a/common/dao/staff_salary.go b/common/dao/staff_salary.go
index 5eac87c..5e83dbe 100644
--- a/common/dao/staff_salary.go
+++ b/common/dao/staff_salary.go
@@ -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 {
diff --git a/conf/template/salary.html b/conf/template/salary.html
index 50a4100..e7e512a 100644
--- a/conf/template/salary.html
+++ b/conf/template/salary.html
@@ -51,7 +51,7 @@
{{range $i, $arr := .data}}
{{range $j, $v := $arr}}
- {{ $v }} |
+ {{ $v }} |
{{end}}
{{end}}
diff --git a/server/controller/staff.go b/server/controller/staff.go
index a507460..f60c950 100644
--- a/server/controller/staff.go
+++ b/server/controller/staff.go
@@ -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())
diff --git a/server/server.go b/server/server.go
index fe89aee..d3675dc 100644
--- a/server/server.go
+++ b/server/server.go
@@ -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)
diff --git a/server/service/staff_salary.go b/server/service/staff_salary.go
index c0cbab3..be0c248 100644
--- a/server/service/staff_salary.go
+++ b/server/service/staff_salary.go
@@ -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
diff --git a/worker/staff.go b/worker/staff.go
index 51ee105..f602a9f 100644
--- a/worker/staff.go
+++ b/worker/staff.go
@@ -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