yinbentan
2024-08-30 cc7c2094568ea8f9d1697da5ed0a2c759ca81abd
models/payroll_constitute.go
@@ -29,8 +29,9 @@
   PayrollConstituteSearch struct {
      PayrollConstitute
      Monthly string
      Keyword string
      Monthly   string
      WorkerIDs []string
      Keyword   string
      Order    string
      PageNum  int
@@ -99,6 +100,11 @@
   return slf
}
func (slf *PayrollConstituteSearch) SetWorkerIDs(workerIds []string) *PayrollConstituteSearch {
   slf.WorkerIDs = workerIds
   return slf
}
func (slf *PayrollConstituteSearch) SetCreatedBy(createdBy string) *PayrollConstituteSearch {
   slf.CreatedBy = createdBy
   return slf
@@ -108,7 +114,7 @@
   var db = slf.Orm.Table(slf.TableName())
   if slf.Preload {
      db = db.Model(&PayrollConstitute{}).Preload("Worker").Preload("WorkType").Preload("WorkType.SalaryPlan")
      db = db.Model(&PayrollConstitute{}).Preload("Worker").Preload("WorkType.SalaryPlan")
   }
   if slf.ID > 0 {
@@ -121,6 +127,10 @@
   if slf.Monthly != "" {
      db = db.Where("cycle like ?", slf.Monthly+"%")
   }
   if len(slf.WorkerIDs) > 0 {
      db = db.Where("Worker_id in ?", slf.WorkerIDs)
   }
   if slf.WorkTypeID > 0 {
@@ -327,31 +337,47 @@
   return records, nil
}
type ConstituteGroup struct {
   Cycle        string           `json:"cycle"`        //月份
   WorkerID     string           `json:"workerId"`     //员工ID
   WorkTypeCode constvar.JobType `json:"workTypeCode"` //工种代码
   SalaryPlanId uint             `json:"salaryPlanId"` //薪资方案ID
}
type (
   ConstituteGroup struct {
      Cycle        string           `json:"cycle"`        //月份
      WorkerID     string           `json:"workerId"`     //员工ID
      WorkTypeCode constvar.JobType `json:"workTypeCode"` //工种代码
      SalaryPlanId uint             `json:"salaryPlanId"` //薪资方案ID
   }
// ConstituteGroup 本月统计了工资的人员
func (slf *PayrollConstituteSearch) ConstituteGroup(cg *ConstituteGroup) ([]*ConstituteGroup, error) {
   ConstituteGroupSearch struct {
      ConstituteGroup
      WorkerIDs []string `json:"workerIds"`
      PageNum   int      `json:"pageNum"`
      PageSize  int      `json:"pageSize"`
   }
)
// ConstituteGroup 每月统计工资的员工
func (slf *PayrollConstituteSearch) ConstituteGroup(cg *ConstituteGroupSearch) ([]*ConstituteGroup, error) {
   var (
      records = make([]*ConstituteGroup, 0)
      db      = slf.Orm.Table(slf.TableName())
   )
   db.Select("cycle,worker_id,work_type_code,salary_plan_id")
   db.Where("cycle = ?", cg.Cycle)
   db = db.Select("cycle,worker_id,work_type_code,salary_plan_id")
   db = db.Where("cycle = ?", cg.Cycle)
   if cg.WorkerID != "" {
      db.Where("worker_id = ?", cg.WorkerID)
      db = db.Where("worker_id = ?", cg.WorkerID)
   }
   if len(cg.WorkerIDs) > 0 {
      db = db.Where("worker_id in ?", cg.WorkerIDs)
   }
   if cg.WorkTypeCode != "" {
      db.Where("work_type_code = ?", cg.WorkTypeCode)
      db = db.Where("work_type_code = ?", cg.WorkTypeCode)
   }
   if cg.SalaryPlanId > 0 {
      db.Where("salary_plan_id = ?", cg.SalaryPlanId)
      db = db.Where("salary_plan_id = ?", cg.SalaryPlanId)
   }
   db.Group("cycle,worker_id,work_type_code,salary_plan_id")
   db = db.Group("cycle,worker_id,work_type_code,salary_plan_id").Order("salary_plan_id,worker_id")
   /*   if cg.PageNum*cg.PageSize > 0 {
      db = db.Offset((cg.PageNum - 1) * cg.PageSize).Limit(cg.PageSize)
   }*/
   return records, db.Find(&records).Error
}
@@ -362,8 +388,8 @@
      db          = slf.Orm.Table(slf.TableName())
      total int64 = 0
   )
   date := "2024-06"
   if err := db.Where("cycle = ?", date).Count(&total).Error; err != nil {
   date := "2024-07"
   if err := db.Where("cycle = ? and salary_plan_id = 5", date).Count(&total).Error; err != nil {
      return err
   }
   if total != 0 {
@@ -379,7 +405,7 @@
         WorkTypeID:   uint(r + 1),
         WorkTypeCode: constvar.JobTypeArr[r],
         WorkTypeName: constvar.JobTypeMap[constvar.JobTypeArr[r]],
         SalaryPlanId: 7,
         SalaryPlanId: 5,
         Amount:       decimal.NewFromInt32(int32(r * 100)),
         CreatedBy:    "auto",
      })