| | |
| | | // 排班信息(功能缺失) |
| | | // 打卡信息(通过人员关联) |
| | | attendances, err := models.NewAttendanceManageSearch().SetDate(date).FindNotTotal() |
| | | if err != nil { |
| | | return err |
| | | } |
| | | if len(attendances) == 0 { |
| | | return errors.New(date + ":打卡信息为空") |
| | | } |
| | | |
| | | // 车台信息(通过人员关联) |
| | | workerPositions, err := models.NewWorkerPositionSearch().SetOverlappingDate(date, date).FindAll() |
| | | if err != nil { |
| | | return err |
| | | } |
| | | |
| | | list := make([]*models.PayrollWorkingHours, 0) |
| | | for _, worker := range workers { |
| | |
| | | } |
| | | |
| | | err = models.WithTransaction(func(db *gorm.DB) error { |
| | | if len(list) == 0 { |
| | | return nil |
| | | } |
| | | if err := models.NewPayrollWorkingHoursSearch().SetOrm(db).SetCycle(date).Delete(); err != nil { |
| | | return err |
| | | } |
| | |
| | | if err != nil { |
| | | return err |
| | | } |
| | | if len(yieldRegisters) == 0 { |
| | | return errors.New(date + ":产量登记为空") |
| | | } |
| | | |
| | | finenesss, err := models.NewFinenessRegisterSearch().SetFinishDate(date).FindAll() // 纤度登记 |
| | | if err != nil { |
| | | return err |
| | | } |
| | | if len(finenesss) == 0 { |
| | | return errors.New(date + ":纤度登记为空") |
| | | } |
| | | |
| | | finenessIds := make([]uint, len(finenesss)) |
| | | for i, fineness := range finenesss { |
| | | finenessIds[i] = fineness.ID |
| | |
| | | return err |
| | | } |
| | | |
| | | priceStandards, _ := models.NewRawSilkPriceStandardSearch().FindNotTotal() // 生丝定价 |
| | | priceStandardMap := make(map[string]decimal.Decimal) // map[庄口\标号]定价 |
| | | priceStandards, err := models.NewRawSilkPriceStandardSearch().FindNotTotal() // 生丝定价 |
| | | if err != nil { |
| | | return err |
| | | } |
| | | if len(priceStandards) == 0 { |
| | | return errors.New(date + ":生丝定价为空") |
| | | } |
| | | |
| | | priceStandardMap := make(map[string]decimal.Decimal) // map[庄口\标号]定价 |
| | | for _, price := range priceStandards { |
| | | key := fmt.Sprintf("%d%s", price.MarketNumber, price.RawSilkGrade) |
| | | priceStandardMap[key] = price.PayStandard |
| | |
| | | workingHours, err := models.NewPayrollWorkingHoursSearch().SetWorkTypeCode(constvar.JobTypeWeavers).SetCycle(date).FindNotTotal() // 员工的工时统计 |
| | | if err != nil { |
| | | return err |
| | | } |
| | | if len(workingHours) == 0 { |
| | | return errors.New(date + ":挡车工打卡信息为空") |
| | | } |
| | | |
| | | // 车台挡车工重复人员标记 |
| | |
| | | } |
| | | for _, workingHour := range workingHourArr { |
| | | key := fmt.Sprintf("%v%v%v", workingHour.WorkshopNumber, workingHour.GroupNumber, workingHour.StartCarNumber) |
| | | carEmployeeMap[key][workingHour.WorkerID] = true |
| | | if temp, ok := carEmployeeMap[key]; ok { |
| | | temp[workingHour.WorkerID] = true |
| | | carEmployeeMap[key] = temp |
| | | } else { |
| | | carEmployeeMap[key] = map[string]bool{workingHour.WorkerID: true} |
| | | } |
| | | |
| | | } |
| | | |
| | | // 方案2 根据纤度登记来查人数 |
| | |
| | | |
| | | } |
| | | err = models.WithTransaction(func(db *gorm.DB) error { |
| | | if len(productionCar) == 0 { |
| | | return nil |
| | | } |
| | | if err := models.NewPayrollProductionCarSearch().SetOrm(db).SetCycle(date).Delete(); err != nil { |
| | | return err |
| | | } |
| | |
| | | if err != nil { |
| | | return err |
| | | } |
| | | if len(productionCars) == 0 { |
| | | errors.New(date + ":车台每天的产量统计为空") |
| | | } |
| | | |
| | | workingHours, err := models.NewPayrollWorkingHoursSearch().SetWorkTypeCode(constvar.JobTypeWeavers).SetCycle(date).FindNotTotal() // 员工的工时统计 |
| | | if err != nil { |
| | | return err |
| | | } |
| | | if len(workingHours) == 0 { |
| | | return errors.New(date + ":挡车工打卡信息为空") |
| | | } |
| | | |
| | | groupWorkingHourMap := make(map[string]map[string]bool) |
| | | for _, workingHour := range workingHours { |
| | | key := fmt.Sprintf("%v%v", workingHour.WorkshopNumber, workingHour.GroupNumber) |
| | | groupWorkingHourMap[key][workingHour.WorkerID] = true |
| | | if temp, ok := groupWorkingHourMap[key]; ok { |
| | | temp[workingHour.WorkerID] = true |
| | | groupWorkingHourMap[key] = temp |
| | | } else { |
| | | groupWorkingHourMap[key] = map[string]bool{workingHour.WorkerID: true} |
| | | } |
| | | } |
| | | |
| | | productionGroupList := make([]*models.PayrollProductionGroup, 0) |
| | |
| | | } |
| | | |
| | | err = models.WithTransaction(func(db *gorm.DB) error { |
| | | err := models.NewPayrollProductionGroupSearch().SetOrm(db).SetCycle(date).Delete() |
| | | if err != nil { |
| | | if len(productionGroupList) == 0 { |
| | | return nil |
| | | } |
| | | if err := models.NewPayrollProductionGroupSearch().SetOrm(db).SetCycle(date).Delete(); err != nil { |
| | | return err |
| | | } |
| | | err = models.NewPayrollProductionGroupSearch().SetOrm(db).CreateBatch(productionGroupList) |
| | | if err != nil { |
| | | if err = models.NewPayrollProductionGroupSearch().SetOrm(db).CreateBatch(productionGroupList); err != nil { |
| | | return err |
| | | } |
| | | return nil |
| | |
| | | if err != nil { |
| | | return err |
| | | } |
| | | if len(workingHours) == 0 { |
| | | return errors.New(date + ":挡车工打卡信息为空") |
| | | } |
| | | |
| | | productionCars, err := models.NewPayrollProductionCarSearch().SetCycle(date).FindNotTotal() |
| | | if err != nil { |
| | | return err |
| | | } |
| | | if len(productionCars) == 0 { |
| | | return errors.New(date + ":车台每天产量统计为空") |
| | | } |
| | | |
| | | productionEmployee := make([]*models.PayrollProductionWeavers, 0) |
| | |
| | | info.FinishTotalAmount = info.FinishTotalAmount.Add(car.FinishTotalAvgAmount) |
| | | } |
| | | } |
| | | if info.SilkQuantity.IsZero() { |
| | | continue |
| | | } |
| | | productionEmployee = append(productionEmployee, &info) |
| | | } |
| | | |
| | | err = models.WithTransaction(func(db *gorm.DB) error { |
| | | if len(productionEmployee) == 0 { |
| | | return nil |
| | | } |
| | | if err := models.NewPayrollProductionWeaversSearch().SetOrm(db).SetCycle(date).Delete(); err != nil { |
| | | return err |
| | | } |
| | |
| | | if err != nil { |
| | | return err |
| | | } |
| | | if len(hours) == 0 { |
| | | return errors.New(date + ":员工打卡信息为空") |
| | | } |
| | | |
| | | jobQuantityMap := make(map[string]int) // 员工出勤统计 |
| | | for _, hour := range hours { |
| | | jobQuantityMap[hour.WorkerID] += 1 |
| | |
| | | } |
| | | |
| | | // 挡车工工资 |
| | | weaversAmountArr, _ := models.NewPayrollProductionWeaversSearch().SetMonthly(date).FindNotTotal() |
| | | weaversAmountArr, err := models.NewPayrollProductionWeaversSearch().SetMonthly(date).FindNotTotal() |
| | | if err != nil { |
| | | return err |
| | | } |
| | | |
| | | weaversAmountMap := make(map[string]*models.PayrollProductionWeavers, len(weaversAmountArr)) |
| | | for _, weaver := range weaversAmountArr { |
| | | key := fmt.Sprintf("%v%v", weaver.Cycle, weaver.WorkerID) |
| | |
| | | |
| | | // 工种工资方案 map[工种]方案 |
| | | salaryPlans, _ := models.NewWorkTypeManageSearch().FindNotTotal() |
| | | if len(salaryPlans) == 0 { |
| | | return errors.New(date + ":工资方案为空") |
| | | } |
| | | |
| | | salaryPlansMap := make(map[uint]*models.WorkTypeManage, len(salaryPlans)) |
| | | for _, salaryPlan := range salaryPlans { |
| | | salaryPlansMap[salaryPlan.ID] = salaryPlan |
| | | } |
| | | |
| | | groups, err := models.NewPayrollProductionGroupSearch().SetMonthly(date).FindNotTotal() |
| | | if err != nil { |
| | | return err |
| | | } |
| | | if len(groups) == 0 { |
| | | return errors.New(date + ":小组每天的产量为空") |
| | | } |
| | | |
| | | groupMap := make(map[string]*models.PayrollProductionGroup, len(groups)) |
| | | groupByMonthMap := make(map[string]*models.PayrollProductionGroup, len(groups)) |
| | | for _, group := range groups { |
| | |
| | | |
| | | // 按天算:日产丝量、生丝单价、桶数、野纤数量、野纤单价 |
| | | groupKey := fmt.Sprintf("%v%v%v", hour.Cycle, hour.WorkshopNumber, hour.GroupNumber) |
| | | group := groupMap[groupKey] |
| | | weaversKey := fmt.Sprintf("%v%v", hour.Cycle, hour.WorkerID) |
| | | weavers := weaversAmountMap[weaversKey] |
| | | parameter := SalaryParameter{ |
| | | SilkQuantity: group.SilkQuantity, |
| | | SilkUnitAmount: decimal.NewFromInt32(1), |
| | | SilkTotalAmount: weavers.FinishTotalAmount, |
| | | FallingSilkBucket: group.FallingSilkBucket, |
| | | BadSilkQuantity: group.BadSilkQuantity, |
| | | BadSilkUnitAmount: decimal.NewFromInt32(1), |
| | | BadSilkTotalAmount: weavers.BadSilkTotalAmount, |
| | | } |
| | | if workType, ok := salaryPlansMap[hour.WorkTypeID]; ok { |
| | | for _, salaryPlan := range workType.SalaryPlans { |
| | | if matched, _ := regexp.MatchString("(日产丝量)|(生丝单价)|(桶数)|(野纤数量)|(野纤单价)", salaryPlan.SalaryFormula); matched { |
| | | temp := production |
| | | formula, s := salaryCalculate(¶meter, salaryPlan) |
| | | if group, ok := groupMap[groupKey]; ok { |
| | | weaversKey := fmt.Sprintf("%v%v", hour.Cycle, hour.WorkerID) |
| | | finishTotalAmount := decimal.NewFromInt32(0) |
| | | badSilkTotalAmount := decimal.NewFromInt32(0) |
| | | if weavers, ok := weaversAmountMap[weaversKey]; ok { |
| | | finishTotalAmount = weavers.FinishTotalAmount |
| | | badSilkTotalAmount = weavers.BadSilkTotalAmount |
| | | } |
| | | |
| | | temp.SalaryFormula = formula |
| | | temp.SalaryPlanId = salaryPlan.ID |
| | | temp.Amount = temp.Amount.Add(s) |
| | | productionByDay = append(productionByDay, &temp) // 每个人的所有方案 |
| | | parameter := SalaryParameter{ |
| | | SilkQuantity: group.SilkQuantity, |
| | | SilkUnitAmount: decimal.NewFromInt32(1), |
| | | SilkTotalAmount: finishTotalAmount, |
| | | FallingSilkBucket: group.FallingSilkBucket, |
| | | BadSilkQuantity: group.BadSilkQuantity, |
| | | BadSilkUnitAmount: decimal.NewFromInt32(1), |
| | | BadSilkTotalAmount: badSilkTotalAmount, |
| | | } |
| | | if workType, ok := salaryPlansMap[hour.WorkTypeID]; ok { |
| | | for _, salaryPlan := range workType.SalaryPlans { |
| | | if matched, _ := regexp.MatchString("(日产丝量)|(生丝单价)|(桶数)|(野纤数量)|(野纤单价)", salaryPlan.SalaryFormula); matched { |
| | | temp := production |
| | | formula, s := salaryCalculate(¶meter, salaryPlan) |
| | | |
| | | temp.SalaryFormula = formula |
| | | temp.SalaryPlanId = salaryPlan.ID |
| | | temp.Amount = temp.Amount.Add(s) |
| | | productionByDay = append(productionByDay, &temp) // 每个人的所有方案 |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | err = models.WithTransaction(func(db *gorm.DB) error { |
| | | if len(productionByDay) == 0 { |
| | | return nil |
| | | } |
| | | if err := models.NewPayrollOtherSubsidiesSearch().SetOrm(db).SetMonthly(date).Delete(); err != nil { |
| | | return err |
| | | } |
| | |
| | | } |
| | | |
| | | monthKey := fmt.Sprintf("%v%v", worker.ShopNumber, worker.GroupNumber) |
| | | group := groupByMonthMap[monthKey] |
| | | fallingSilkBucket := decimal.NewFromInt(0) |
| | | finishTotalAvgAmount := decimal.NewFromInt(0) |
| | | if group, ok := groupByMonthMap[monthKey]; ok { |
| | | fallingSilkBucket = group.FallingSilkBucket |
| | | finishTotalAvgAmount = group.FinishTotalAvgAmount |
| | | } |
| | | parameter := SalaryParameter{ |
| | | FallingSilkBucket: group.FallingSilkBucket, |
| | | GroupWeaversAvgAmount: group.FinishTotalAvgAmount, |
| | | GroupCarHeadAvgAmount: group.FinishTotalAvgAmount.Div(ready70), |
| | | FallingSilkBucket: fallingSilkBucket, |
| | | GroupWeaversAvgAmount: finishTotalAvgAmount, |
| | | GroupCarHeadAvgAmount: finishTotalAvgAmount.Div(ready70), |
| | | JobDays: decimal.NewFromInt32(int32(dayCount)), |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | err = models.WithTransaction(func(db *gorm.DB) error { |
| | | if len(constituteByMonth) == 0 { |
| | | return nil |
| | | } |
| | | if err := models.NewPayrollConstituteSearch().SetOrm(db).SetCycle(date).SetCreatedBy("auto").Delete(); err != nil { |
| | | return err |
| | | } |