Przeglądaj źródła

11月8日库存管理

XMLWAN 3 lat temu
rodzic
commit
5740c83e1b

+ 14 - 3
controllers/schedule_api_controller.go Wyświetl plik

2033
 	week_time, _ := this.GetInt64("week_time")
2033
 	week_time, _ := this.GetInt64("week_time")
2034
 	start_time, _ := this.GetInt64("start_time")
2034
 	start_time, _ := this.GetInt64("start_time")
2035
 	end_time, _ := this.GetInt64("end_time")
2035
 	end_time, _ := this.GetInt64("end_time")
2036
-	//zone, _ := this.GetInt64("zone")
2036
+	record_date := this.GetString("record_date")
2037
+
2037
 	zons := this.GetString("zone")
2038
 	zons := this.GetString("zone")
2038
 	zone := strings.Split(zons, ",")
2039
 	zone := strings.Split(zons, ",")
2039
 	adminUserInfo := this.GetAdminUserInfo()
2040
 	adminUserInfo := this.GetAdminUserInfo()
2041
+	timeLayout := "2006-01-02"
2042
+	loc, _ := time.LoadLocation("Local")
2043
+
2044
+	var theStartTIme int64
2045
+	if len(record_date) > 0 {
2046
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
2047
+		if err != nil {
2048
+			utils.ErrorLog(err.Error())
2049
+		}
2050
+		theStartTIme = theTime.Unix()
2051
+	}
2040
 
2052
 
2041
-	schedule, err := service.GetNextWeekDaySchedule(week_type, week_time, start_time, end_time, adminUserInfo.CurrentOrgId, zone)
2053
+	schedule, err := service.GetNextWeekDaySchedule(week_type, week_time, start_time, end_time, adminUserInfo.CurrentOrgId, zone, theStartTIme)
2042
 	if err != nil {
2054
 	if err != nil {
2043
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2055
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2044
 		return
2056
 		return
2354
 
2366
 
2355
 	week_type, _ := this.GetInt64("week_type", -1)
2367
 	week_type, _ := this.GetInt64("week_type", -1)
2356
 	week_time, _ := this.GetInt64("week_time")
2368
 	week_time, _ := this.GetInt64("week_time")
2357
-	//zone, _ := this.GetInt64("zone")
2358
 	zones := this.GetString("zone")
2369
 	zones := this.GetString("zone")
2359
 	zone := strings.Split(zones, ",")
2370
 	zone := strings.Split(zones, ",")
2360
 	thisTime := time.Now()
2371
 	thisTime := time.Now()

+ 34 - 17
controllers/stock_in_api_controller.go Wyświetl plik

2493
 		}
2493
 		}
2494
 	}
2494
 	}
2495
 	var errs error
2495
 	var errs error
2496
-	fmt.Println("出库22322333223", cancelStockInfos)
2497
-	fmt.Println("更新23232323232323233", upDateCancelStockInfos)
2496
+
2498
 	if len(cancelStockInfos) > 0 {
2497
 	if len(cancelStockInfos) > 0 {
2499
 
2498
 
2500
 		for _, item := range cancelStockInfos {
2499
 		for _, item := range cancelStockInfos {
2519
 			if item.Count <= infolist.WarehousingCount {
2518
 			if item.Count <= infolist.WarehousingCount {
2520
 
2519
 
2521
 				errs := service.CreateCancelStockInfo(cancelStockInfos)
2520
 				errs := service.CreateCancelStockInfo(cancelStockInfos)
2522
-				if len(stockFlow) > 0 {
2523
-					service.CreateStockFlow(stockFlow)
2524
-				}
2521
+
2525
 				if errs != nil {
2522
 				if errs != nil {
2526
 					utils.ErrorLog(errs.Error())
2523
 					utils.ErrorLog(errs.Error())
2527
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
2524
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
2535
 			}
2532
 			}
2536
 
2533
 
2537
 		}
2534
 		}
2535
+
2536
+		if len(stockFlow) > 0 {
2537
+			for _, itemcancel := range stockFlow {
2538
+
2539
+				//查询是否存在
2540
+				stockInfo, errcode := service.IsExsitStockFlow(itemcancel.GoodId, itemcancel.CancelOrderNumber)
2541
+				if errcode == gorm.ErrRecordNotFound {
2542
+
2543
+				} else {
2544
+					flow := models.VmStockFlow{
2545
+						Count: itemcancel.Count,
2546
+					}
2547
+					service.UpdateStockFlowTwo(stockInfo.ID, flow)
2548
+				}
2549
+			}
2550
+			//service.CreateStockFlow(stockFlow)
2551
+		}
2538
 	}
2552
 	}
2539
 
2553
 
2540
 	if len(upDateCancelStockInfos) > 0 {
2554
 	if len(upDateCancelStockInfos) > 0 {
2542
 
2556
 
2543
 			//获取该批次最后一套出库记录
2557
 			//获取该批次最后一套出库记录
2544
 			info, _ := service.GetLastCancelInfo(item.WarehouseInfoId, item.GoodId)
2558
 			info, _ := service.GetLastCancelInfo(item.WarehouseInfoId, item.GoodId)
2545
-			fmt.Println("info232332322332233223", info.Count, item.Count)
2559
+
2546
 			//比较出库数量和最后一次出库数据大小
2560
 			//比较出库数量和最后一次出库数据大小
2547
 			//退库(加)
2561
 			//退库(加)
2548
 			if item.Count < info.Count {
2562
 			if item.Count < info.Count {
2549
 				var total = info.Count - item.Count
2563
 				var total = info.Count - item.Count
2550
 				errs = service.UpDateCancelStockInfo(item)
2564
 				errs = service.UpDateCancelStockInfo(item)
2551
 
2565
 
2552
-				service.CreateStockFlow(stockFlow)
2553
 				warehouseinfo, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
2566
 				warehouseinfo, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
2554
 				if (warehouseinfo.StockCount + total) > warehouseinfo.StockCount {
2567
 				if (warehouseinfo.StockCount + total) > warehouseinfo.StockCount {
2555
 					c.ServeSuccessJSON(map[string]interface{}{
2568
 					c.ServeSuccessJSON(map[string]interface{}{
2566
 			}
2579
 			}
2567
 			//(减)
2580
 			//(减)
2568
 			if item.Count > info.Count {
2581
 			if item.Count > info.Count {
2569
-
2570
 				errs = service.UpDateCancelStockInfo(item)
2582
 				errs = service.UpDateCancelStockInfo(item)
2571
-				service.CreateStockFlow(stockFlow)
2572
 				//查询该批次入库的值
2583
 				//查询该批次入库的值
2573
 				infolist, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
2584
 				infolist, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
2574
 				if item.Count > infolist.WarehousingCount {
2585
 				if item.Count > infolist.WarehousingCount {
2592
 				errs = service.UpDateCancelStockInfo(item)
2603
 				errs = service.UpDateCancelStockInfo(item)
2593
 			}
2604
 			}
2594
 		}
2605
 		}
2595
-		if errs != nil {
2596
-			utils.ErrorLog(errs.Error())
2597
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
2598
-			return
2599
-		}
2606
+	}
2607
+	if len(stockFlow) > 0 {
2608
+		for _, itemcancel := range stockFlow {
2600
 
2609
 
2601
-		c.ServeSuccessJSON(map[string]interface{}{
2602
-			"msg": "3",
2603
-		})
2610
+			//查询是否存在
2611
+			stockInfo, errcode := service.IsExsitStockFlow(itemcancel.GoodId, itemcancel.CancelOrderNumber)
2612
+			if errcode == gorm.ErrRecordNotFound {
2613
+
2614
+			} else {
2615
+				flow := models.VmStockFlow{
2616
+					Count: itemcancel.Count,
2617
+				}
2618
+				service.UpdateStockFlowTwo(stockInfo.ID, flow)
2619
+			}
2620
+		}
2604
 	}
2621
 	}
2605
 
2622
 
2606
 	if errs != nil {
2623
 	if errs != nil {

+ 5 - 5
service/schedule_service.go Wyświetl plik

626
 
626
 
627
 	err = db.Select("x.id,x.user_org_id,x.partition_id,x.bed_id,x.patient_id,x.schedule_date,x.schedule_type,x.schedule_week,x.mode_id,x.is_export").Preload("XtPatients", "status = 1").Preload("DeviceZone", "status = 1").Preload("DeviceNumber", "status = 1").Preload("DialysisOrder", "status = 1 and dialysis_date = ?", scheduleDate).Preload("XtAssessmentBeforeDislysis", "status = 1 and assessment_date =?", scheduleDate).Preload("DoctorAdvice", func(db *gorm.DB) *gorm.DB {
627
 	err = db.Select("x.id,x.user_org_id,x.partition_id,x.bed_id,x.patient_id,x.schedule_date,x.schedule_type,x.schedule_week,x.mode_id,x.is_export").Preload("XtPatients", "status = 1").Preload("DeviceZone", "status = 1").Preload("DeviceNumber", "status = 1").Preload("DialysisOrder", "status = 1 and dialysis_date = ?", scheduleDate).Preload("XtAssessmentBeforeDislysis", "status = 1 and assessment_date =?", scheduleDate).Preload("DoctorAdvice", func(db *gorm.DB) *gorm.DB {
628
 		return db.Where("status =1 and parent_id = 0 and advice_date = ?", scheduleDate).Preload("ChildDoctorAdvice", "status = 1")
628
 		return db.Where("status =1 and parent_id = 0 and advice_date = ?", scheduleDate).Preload("ChildDoctorAdvice", "status = 1")
629
-	}).Preload("HisDoctorAdviceInfo", "status = 1 and advice_date = ?", scheduleDate).Preload("DialysisPrescription", "status = 1 and record_date =?", scheduleDate).Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
629
+	}).Preload("HisDoctorAdviceInfo", "status = 1 and advice_date = ? and user_org_id = ? ", scheduleDate, orgid).Preload("DialysisPrescription", "status = 1 and record_date =? and user_org_id = ?", scheduleDate, orgid).Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
630
 		return db.Where("status =1").Order("id asc")
630
 		return db.Where("status =1").Order("id asc")
631
 	}).Preload("LastAfterWeight", func(db *gorm.DB) *gorm.DB {
631
 	}).Preload("LastAfterWeight", func(db *gorm.DB) *gorm.DB {
632
 		return db.Where("user_org_id = ? and status = 1 and assessment_date < ?", orgid, scheduleDate)
632
 		return db.Where("user_org_id = ? and status = 1 and assessment_date < ?", orgid, scheduleDate)
814
 	return
814
 	return
815
 }
815
 }
816
 
816
 
817
-func GetNextWeekDaySchedule(weektype int64, weektime int64, startime int64, endtime int64, orgID int64, zone []string) (schedules []*models.WeekScheduleSix, err error) {
817
+func GetNextWeekDaySchedule(weektype int64, weektime int64, startime int64, endtime int64, orgID int64, zone []string, record_date int64) (schedules []*models.WeekScheduleSix, err error) {
818
 
818
 
819
 	db := readDb.Table("xt_schedule as s ").Where("s.status =1")
819
 	db := readDb.Table("xt_schedule as s ").Where("s.status =1")
820
 	if orgID > 0 {
820
 	if orgID > 0 {
838
 	err = db.
838
 	err = db.
839
 		Preload("DeviceZone", "status = 1 ").
839
 		Preload("DeviceZone", "status = 1 ").
840
 		Preload("DeviceNumber", "status = 1 ").
840
 		Preload("DeviceNumber", "status = 1 ").
841
-		Preload("XtAssessmentBeforeDislysis", "status = 1").
841
+		Preload("XtAssessmentBeforeDislysis", "status = 1 and assessment_date = ?", record_date).
842
 		Preload("DialysisPrescription", func(db *gorm.DB) *gorm.DB {
842
 		Preload("DialysisPrescription", func(db *gorm.DB) *gorm.DB {
843
 			return db.Where("status = 1").Order("id asc")
843
 			return db.Where("status = 1").Order("id asc")
844
 		}).Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
844
 		}).Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
845
 		return db.Where("status = 1").Order("id asc")
845
 		return db.Where("status = 1").Order("id asc")
846
 	}).Preload("DoctorAdvice", func(db *gorm.DB) *gorm.DB {
846
 	}).Preload("DoctorAdvice", func(db *gorm.DB) *gorm.DB {
847
-		return db.Where("status =1 and parent_id = 0").Preload("ChildDoctorAdvice", "status = 1")
848
-	}).Preload("HisDoctorAdviceInfo", "status = 1").Joins("JOIN xt_patients as p ON p.id = s.patient_id").
847
+		return db.Where("status =1 and parent_id = 0 and advice_date = ?", record_date).Preload("ChildDoctorAdvice", "status = 1 and advice_date = ?", record_date)
848
+	}).Preload("HisDoctorAdviceInfo", "status = 1 and advice_date = ?", record_date).Joins("JOIN xt_patients as p ON p.id = s.patient_id").
849
 		Select("s.id,s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id, s.status, s.created_time, s.updated_time, p.name as patient").
849
 		Select("s.id,s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id, s.status, s.created_time, s.updated_time, p.name as patient").
850
 		Order("s.partition_id desc").
850
 		Order("s.partition_id desc").
851
 		Find(&schedules).Error
851
 		Find(&schedules).Error

+ 18 - 0
service/stock_service.go Wyświetl plik

5128
 	err := XTWriteDB().Save(&info).Error
5128
 	err := XTWriteDB().Save(&info).Error
5129
 	return err
5129
 	return err
5130
 }
5130
 }
5131
+
5132
+func IsExsitStockFlow(goodid int64, cancel_order_number string) (*models.VmStockFlow, error) {
5133
+	flow := models.VmStockFlow{}
5134
+	err := XTReadDB().Where("good_id = ? and cancel_order_number = ? and status = 1", goodid, cancel_order_number).Find(&flow).Error
5135
+	if err == gorm.ErrRecordNotFound {
5136
+		return nil, err
5137
+	}
5138
+	if err != nil {
5139
+		return nil, err
5140
+	}
5141
+	return &flow, nil
5142
+}
5143
+
5144
+func UpdateStockFlowTwo(id int64, flow models.VmStockFlow) error {
5145
+
5146
+	err := XTWriteDB().Model(&flow).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"count": flow.Count}).Error
5147
+	return err
5148
+}