浏览代码

11月8日库存管理

XMLWAN 3 年前
父节点
当前提交
5740c83e1b
共有 4 个文件被更改,包括 71 次插入25 次删除
  1. 14 3
      controllers/schedule_api_controller.go
  2. 34 17
      controllers/stock_in_api_controller.go
  3. 5 5
      service/schedule_service.go
  4. 18 0
      service/stock_service.go

+ 14 - 3
controllers/schedule_api_controller.go 查看文件

@@ -2033,12 +2033,24 @@ func (this *ScheduleApiController) GetNextWeekDaySchedule() {
2033 2033
 	week_time, _ := this.GetInt64("week_time")
2034 2034
 	start_time, _ := this.GetInt64("start_time")
2035 2035
 	end_time, _ := this.GetInt64("end_time")
2036
-	//zone, _ := this.GetInt64("zone")
2036
+	record_date := this.GetString("record_date")
2037
+
2037 2038
 	zons := this.GetString("zone")
2038 2039
 	zone := strings.Split(zons, ",")
2039 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 2054
 	if err != nil {
2043 2055
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2044 2056
 		return
@@ -2354,7 +2366,6 @@ func (this *ScheduleApiController) GetBloodScheduleList() {
2354 2366
 
2355 2367
 	week_type, _ := this.GetInt64("week_type", -1)
2356 2368
 	week_time, _ := this.GetInt64("week_time")
2357
-	//zone, _ := this.GetInt64("zone")
2358 2369
 	zones := this.GetString("zone")
2359 2370
 	zone := strings.Split(zones, ",")
2360 2371
 	thisTime := time.Now()

+ 34 - 17
controllers/stock_in_api_controller.go 查看文件

@@ -2493,8 +2493,7 @@ func (c *StockManagerApiController) EditCancelStock() {
2493 2493
 		}
2494 2494
 	}
2495 2495
 	var errs error
2496
-	fmt.Println("出库22322333223", cancelStockInfos)
2497
-	fmt.Println("更新23232323232323233", upDateCancelStockInfos)
2496
+
2498 2497
 	if len(cancelStockInfos) > 0 {
2499 2498
 
2500 2499
 		for _, item := range cancelStockInfos {
@@ -2519,9 +2518,7 @@ func (c *StockManagerApiController) EditCancelStock() {
2519 2518
 			if item.Count <= infolist.WarehousingCount {
2520 2519
 
2521 2520
 				errs := service.CreateCancelStockInfo(cancelStockInfos)
2522
-				if len(stockFlow) > 0 {
2523
-					service.CreateStockFlow(stockFlow)
2524
-				}
2521
+
2525 2522
 				if errs != nil {
2526 2523
 					utils.ErrorLog(errs.Error())
2527 2524
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
@@ -2535,6 +2532,23 @@ func (c *StockManagerApiController) EditCancelStock() {
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 2554
 	if len(upDateCancelStockInfos) > 0 {
@@ -2542,14 +2556,13 @@ func (c *StockManagerApiController) EditCancelStock() {
2542 2556
 
2543 2557
 			//获取该批次最后一套出库记录
2544 2558
 			info, _ := service.GetLastCancelInfo(item.WarehouseInfoId, item.GoodId)
2545
-			fmt.Println("info232332322332233223", info.Count, item.Count)
2559
+
2546 2560
 			//比较出库数量和最后一次出库数据大小
2547 2561
 			//退库(加)
2548 2562
 			if item.Count < info.Count {
2549 2563
 				var total = info.Count - item.Count
2550 2564
 				errs = service.UpDateCancelStockInfo(item)
2551 2565
 
2552
-				service.CreateStockFlow(stockFlow)
2553 2566
 				warehouseinfo, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
2554 2567
 				if (warehouseinfo.StockCount + total) > warehouseinfo.StockCount {
2555 2568
 					c.ServeSuccessJSON(map[string]interface{}{
@@ -2566,9 +2579,7 @@ func (c *StockManagerApiController) EditCancelStock() {
2566 2579
 			}
2567 2580
 			//(减)
2568 2581
 			if item.Count > info.Count {
2569
-
2570 2582
 				errs = service.UpDateCancelStockInfo(item)
2571
-				service.CreateStockFlow(stockFlow)
2572 2583
 				//查询该批次入库的值
2573 2584
 				infolist, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
2574 2585
 				if item.Count > infolist.WarehousingCount {
@@ -2592,15 +2603,21 @@ func (c *StockManagerApiController) EditCancelStock() {
2592 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 2623
 	if errs != nil {

+ 5 - 5
service/schedule_service.go 查看文件

@@ -626,7 +626,7 @@ func GetWeekDayScheduleByIdThee(orgid int64, scheduleDate int64, scheduleType in
626 626
 
627 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 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 630
 		return db.Where("status =1").Order("id asc")
631 631
 	}).Preload("LastAfterWeight", func(db *gorm.DB) *gorm.DB {
632 632
 		return db.Where("user_org_id = ? and status = 1 and assessment_date < ?", orgid, scheduleDate)
@@ -814,7 +814,7 @@ func UpdateNewScheduleTemplateStatus(id int64, org_id int64) (err error) {
814 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 819
 	db := readDb.Table("xt_schedule as s ").Where("s.status =1")
820 820
 	if orgID > 0 {
@@ -838,14 +838,14 @@ func GetNextWeekDaySchedule(weektype int64, weektime int64, startime int64, endt
838 838
 	err = db.
839 839
 		Preload("DeviceZone", "status = 1 ").
840 840
 		Preload("DeviceNumber", "status = 1 ").
841
-		Preload("XtAssessmentBeforeDislysis", "status = 1").
841
+		Preload("XtAssessmentBeforeDislysis", "status = 1 and assessment_date = ?", record_date).
842 842
 		Preload("DialysisPrescription", func(db *gorm.DB) *gorm.DB {
843 843
 			return db.Where("status = 1").Order("id asc")
844 844
 		}).Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
845 845
 		return db.Where("status = 1").Order("id asc")
846 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 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 850
 		Order("s.partition_id desc").
851 851
 		Find(&schedules).Error

+ 18 - 0
service/stock_service.go 查看文件

@@ -5128,3 +5128,21 @@ func UpdateDrugCancelStockInfo(info *models.DrugCancelStockInfo) error {
5128 5128
 	err := XTWriteDB().Save(&info).Error
5129 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
+}