Browse Source

Merge branch '20211122' of http://git.shengws.com/csx/XT_New into 20211122

csx 3 years ago
parent
commit
2c841d1fc4

+ 4 - 2
controllers/dialysis_api_controller.go View File

1267
 	assessment.Fallrisk = data.Fallrisk
1267
 	assessment.Fallrisk = data.Fallrisk
1268
 	assessment.MachineRun = data.MachineRun
1268
 	assessment.MachineRun = data.MachineRun
1269
 	assessment.AfterUrea = data.AfterUrea
1269
 	assessment.AfterUrea = data.AfterUrea
1270
+	assessment.PipCoagulation = data.PipCoagulation
1270
 	appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
1271
 	appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
1271
 
1272
 
1272
 	if assessment.ID > 0 {
1273
 	if assessment.ID > 0 {
1423
 	estimated_food_intake := c.GetString("estimated_food_intake")
1424
 	estimated_food_intake := c.GetString("estimated_food_intake")
1424
 	blood_pressure_during_dialysis := c.GetString("blood_pressure_during_dialysis")
1425
 	blood_pressure_during_dialysis := c.GetString("blood_pressure_during_dialysis")
1425
 	urea_befor := c.GetString("urea_befor")
1426
 	urea_befor := c.GetString("urea_befor")
1427
+	suction := c.GetString("suction")
1426
 	assessmentBeforeDislysis := models.PredialysisEvaluation{
1428
 	assessmentBeforeDislysis := models.PredialysisEvaluation{
1427
 		DialysisCount:                  dialysis_count,
1429
 		DialysisCount:                  dialysis_count,
1428
 		EmergencyTreatment:             emergency_treatment,
1430
 		EmergencyTreatment:             emergency_treatment,
1490
 		EstimatedFoodIntake:            estimated_food_intake,
1492
 		EstimatedFoodIntake:            estimated_food_intake,
1491
 		BloodPressureDuringDialysis:    blood_pressure_during_dialysis,
1493
 		BloodPressureDuringDialysis:    blood_pressure_during_dialysis,
1492
 		UreaBefor:                      urea_befor,
1494
 		UreaBefor:                      urea_befor,
1495
+		Suction:                        suction,
1493
 	}
1496
 	}
1494
 
1497
 
1495
 	appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
1498
 	appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
1602
 				mode_id = 0
1605
 				mode_id = 0
1603
 			}
1606
 			}
1604
 		}
1607
 		}
1605
-		fmt.Println("dialysisPrescribe------------------------------------", dialysisPrescribe)
1606
-		fmt.Println("dialysisSolution------------------------------------", dialysisSolution)
1608
+
1607
 		// 插入透析处方
1609
 		// 插入透析处方
1608
 		if dialysisPrescribe == nil && dialysisSolution != nil {
1610
 		if dialysisPrescribe == nil && dialysisSolution != nil {
1609
 			var newprescribe models.DialysisPrescription
1611
 			var newprescribe models.DialysisPrescription

+ 6 - 0
controllers/dialysis_record_api_controller.go View File

533
 	UreaMonitoring              float64 `gorm:"column:urea_monitoring" json:"urea_monitoring" form:"urea_monitoring"`
533
 	UreaMonitoring              float64 `gorm:"column:urea_monitoring" json:"urea_monitoring" form:"urea_monitoring"`
534
 	BloodThickness              float64 `gorm:"column:blood_thickness" json:"blood_thickness" form:"blood_thickness"`
534
 	BloodThickness              float64 `gorm:"column:blood_thickness" json:"blood_thickness" form:"blood_thickness"`
535
 	BloodMonitor                float64 `gorm:"column:blood_monitor" json:"blood_monitor" form:"blood_monitor"`
535
 	BloodMonitor                float64 `gorm:"column:blood_monitor" json:"blood_monitor" form:"blood_monitor"`
536
+	HeparinAmount               float64 `gorm:"column:heparin_amount" json:"heparin_amount" form:"heparin_amount"`
537
+	Dehydration                 float64 `gorm:"column:dehydration" json:"dehydration" form:"dehydration"`
536
 }
538
 }
537
 
539
 
538
 // /api/dislysis/monitor/edit [post]
540
 // /api/dislysis/monitor/edit [post]
652
 			UreaMonitoring:              monitorParam.UreaMonitoring,
654
 			UreaMonitoring:              monitorParam.UreaMonitoring,
653
 			BloodThickness:              monitorParam.BloodThickness,
655
 			BloodThickness:              monitorParam.BloodThickness,
654
 			BloodMonitor:                monitorParam.BloodMonitor,
656
 			BloodMonitor:                monitorParam.BloodMonitor,
657
+			HeparinAmount:               monitorParam.HeparinAmount,
658
+			Dehydration:                 monitorParam.Dehydration,
655
 		}
659
 		}
656
 		createErr := service.CreateMonitor(&monitor)
660
 		createErr := service.CreateMonitor(&monitor)
657
 		key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":monitor_records"
661
 		key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":monitor_records"
734
 		monitor.UreaMonitoring = monitorParam.UreaMonitoring
738
 		monitor.UreaMonitoring = monitorParam.UreaMonitoring
735
 		monitor.BloodThickness = monitorParam.BloodThickness
739
 		monitor.BloodThickness = monitorParam.BloodThickness
736
 		monitor.BloodMonitor = monitorParam.BloodMonitor
740
 		monitor.BloodMonitor = monitorParam.BloodMonitor
741
+		monitor.HeparinAmount = monitorParam.HeparinAmount
742
+		monitor.Dehydration = monitorParam.Dehydration
737
 		updateErr := service.UpdateMonitor(monitor)
743
 		updateErr := service.UpdateMonitor(monitor)
738
 		key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":monitor_records"
744
 		key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":monitor_records"
739
 		redis := service.RedisClient()
745
 		redis := service.RedisClient()

+ 1 - 1
controllers/gobal_config_api_controller.go View File

1061
 		id := int64(idsInter.(float64))
1061
 		id := int64(idsInter.(float64))
1062
 		ids = append(ids, id)
1062
 		ids = append(ids, id)
1063
 	}
1063
 	}
1064
-	getPrint, err := service.GetPrint(ids, OrgID)
1064
+	getPrint, err := service.GetPrint(ids, OrgID, advice_type, stop_type)
1065
 	c.ServeSuccessJSON(map[string]interface{}{
1065
 	c.ServeSuccessJSON(map[string]interface{}{
1066
 		"doctoradvice": getPrint,
1066
 		"doctoradvice": getPrint,
1067
 	})
1067
 	})

+ 4 - 0
controllers/manager_center_api_controller.go View File

1497
 	default_count_unit := c.GetString("default_count_unit")
1497
 	default_count_unit := c.GetString("default_count_unit")
1498
 	is_user, _ := c.GetInt64("is_user")
1498
 	is_user, _ := c.GetInt64("is_user")
1499
 	number := c.GetString("number")
1499
 	number := c.GetString("number")
1500
+	is_warehouse, _ := c.GetInt64("is_warehouse")
1500
 	adminUserInfo := c.GetAdminUserInfo()
1501
 	adminUserInfo := c.GetAdminUserInfo()
1501
 
1502
 
1502
 	totals := service.FindGoodInfoByNameTwo(specification_name, adminUserInfo.CurrentOrgId, good_id, good_name)
1503
 	totals := service.FindGoodInfoByNameTwo(specification_name, adminUserInfo.CurrentOrgId, good_id, good_name)
1559
 		ProvincesCode:               provinces_code,
1560
 		ProvincesCode:               provinces_code,
1560
 		IsUser:                      is_user,
1561
 		IsUser:                      is_user,
1561
 		Number:                      number,
1562
 		Number:                      number,
1563
+		IsWarehouse:                 is_warehouse,
1562
 	}
1564
 	}
1563
 	err, goodInfos := service.AddSigleGoodInfo(&goodInfo)
1565
 	err, goodInfos := service.AddSigleGoodInfo(&goodInfo)
1564
 	if err == nil {
1566
 	if err == nil {
1626
 	register_number := c.GetString("register_number")
1628
 	register_number := c.GetString("register_number")
1627
 	is_user, _ := c.GetInt64("is_user")
1629
 	is_user, _ := c.GetInt64("is_user")
1628
 	number := c.GetString("number")
1630
 	number := c.GetString("number")
1631
+	is_warehouse, _ := c.GetInt64("is_warehouse")
1629
 	adminUserInfo := c.GetAdminUserInfo()
1632
 	adminUserInfo := c.GetAdminUserInfo()
1630
 
1633
 
1631
 	goodInfo := models.GoodInfo{
1634
 	goodInfo := models.GoodInfo{
1680
 		RegisterNumber:              register_number,
1683
 		RegisterNumber:              register_number,
1681
 		IsUser:                      is_user,
1684
 		IsUser:                      is_user,
1682
 		Number:                      number,
1685
 		Number:                      number,
1686
+		IsWarehouse:                 is_warehouse,
1683
 	}
1687
 	}
1684
 
1688
 
1685
 	totals := service.FindGoodInfoByNameOne(specification_name, adminUserInfo.CurrentOrgId, good_id, id, good_name)
1689
 	totals := service.FindGoodInfoByNameOne(specification_name, adminUserInfo.CurrentOrgId, good_id, id, good_name)

+ 5 - 0
controllers/mobile_api_controllers/dialysis_api_controller.go View File

832
 		err := service.AddSigleDoubleCheck(&doubleCheck)
832
 		err := service.AddSigleDoubleCheck(&doubleCheck)
833
 		key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
833
 		key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
834
 		redis := service.RedisClient()
834
 		redis := service.RedisClient()
835
+
835
 		defer redis.Close()
836
 		defer redis.Close()
836
 		//清空key 值
837
 		//清空key 值
837
 		redis.Set(key, "", time.Second)
838
 		redis.Set(key, "", time.Second)
850
 		doubleCheck.ID = check.ID
851
 		doubleCheck.ID = check.ID
851
 		err := service.UpdateDoubleCheck(&doubleCheck)
852
 		err := service.UpdateDoubleCheck(&doubleCheck)
852
 		key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
853
 		key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
854
+		fmt.Println("key233232232323232323", key)
853
 		redis := service.RedisClient()
855
 		redis := service.RedisClient()
854
 		defer redis.Close()
856
 		defer redis.Close()
855
 		//清空key 值
857
 		//清空key 值
1066
 	fallrisk, _ := c.GetInt64("fallrisk")
1068
 	fallrisk, _ := c.GetInt64("fallrisk")
1067
 	machine_run := c.GetString("machine_run")
1069
 	machine_run := c.GetString("machine_run")
1068
 	after_urea := c.GetString("after_urea")
1070
 	after_urea := c.GetString("after_urea")
1071
+	pip_coagulation := c.GetString("pip_coagulation")
1069
 	if id <= 0 {
1072
 	if id <= 0 {
1070
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1073
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1071
 		return
1074
 		return
1168
 		Fallrisk:                     fallrisk,
1171
 		Fallrisk:                     fallrisk,
1169
 		MachineRun:                   machine_run,
1172
 		MachineRun:                   machine_run,
1170
 		AfterUrea:                    after_urea,
1173
 		AfterUrea:                    after_urea,
1174
+		PipCoagulation:               pip_coagulation,
1171
 	}
1175
 	}
1172
 
1176
 
1173
 	appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
1177
 	appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
4752
 			})
4756
 			})
4753
 			return
4757
 			return
4754
 		}
4758
 		}
4759
+
4755
 	}
4760
 	}
4756
 
4761
 
4757
 	//出库逻辑
4762
 	//出库逻辑

+ 9 - 0
controllers/mobile_api_controllers/dialysis_api_controller_extend.go View File

95
 	blood_sugar, _ := this.GetFloat("blood_sugar")
95
 	blood_sugar, _ := this.GetFloat("blood_sugar")
96
 	monitor_anticoagulant, _ := this.GetInt64("monitor_anticoagulant")
96
 	monitor_anticoagulant, _ := this.GetInt64("monitor_anticoagulant")
97
 	monitor_anticoagulant_value := this.GetString("monitor_anticoagulant_value")
97
 	monitor_anticoagulant_value := this.GetString("monitor_anticoagulant_value")
98
+	heparin_amount, _ := this.GetFloat("heparin_amount")
98
 	blood_pressure_monitoring_site, _ := this.GetInt64("blood_pressure_monitoring_site")
99
 	blood_pressure_monitoring_site, _ := this.GetInt64("blood_pressure_monitoring_site")
99
 	complication, _ := this.GetInt64("complication")
100
 	complication, _ := this.GetInt64("complication")
100
 	accumulated_blood_volume, _ := this.GetFloat("accumulated_blood_volume")
101
 	accumulated_blood_volume, _ := this.GetFloat("accumulated_blood_volume")
102
 	urea_monitoring, _ := this.GetFloat("urea_monitoring")
103
 	urea_monitoring, _ := this.GetFloat("urea_monitoring")
103
 	blood_thickness, _ := this.GetFloat("blood_thickness")
104
 	blood_thickness, _ := this.GetFloat("blood_thickness")
104
 	blood_monitor, _ := this.GetFloat("blood_monitor")
105
 	blood_monitor, _ := this.GetFloat("blood_monitor")
106
+	dehydration, _ := this.GetFloat("dehydration")
105
 	adminInfo := this.GetMobileAdminUserInfo()
107
 	adminInfo := this.GetMobileAdminUserInfo()
106
 	patient, getPatientErr := service.MobileGetPatientById(adminInfo.Org.Id, patientID)
108
 	patient, getPatientErr := service.MobileGetPatientById(adminInfo.Org.Id, patientID)
107
 	if getPatientErr != nil {
109
 	if getPatientErr != nil {
165
 		UreaMonitoring:              urea_monitoring,
167
 		UreaMonitoring:              urea_monitoring,
166
 		BloodThickness:              blood_thickness,
168
 		BloodThickness:              blood_thickness,
167
 		BloodMonitor:                blood_monitor,
169
 		BloodMonitor:                blood_monitor,
170
+		HeparinAmount:               heparin_amount,
171
+		Dehydration:                 dehydration,
168
 	}
172
 	}
169
 
173
 
170
 	err := service.CreateMonitor(&record)
174
 	err := service.CreateMonitor(&record)
275
 	urea_monitoring, _ := this.GetFloat("urea_monitoring")
279
 	urea_monitoring, _ := this.GetFloat("urea_monitoring")
276
 	blood_thickness, _ := this.GetFloat("blood_thickness")
280
 	blood_thickness, _ := this.GetFloat("blood_thickness")
277
 	blood_monitor, _ := this.GetFloat("blood_monitor")
281
 	blood_monitor, _ := this.GetFloat("blood_monitor")
282
+	heparin_amount, _ := this.GetFloat("heparin_amount")
283
+	dehydration, _ := this.GetFloat("dehydration")
284
+	fmt.Println("id232323233232233223232332233223", id)
278
 	monitor, err := service.GetMonitor(adminInfo.Org.Id, patientID, id)
285
 	monitor, err := service.GetMonitor(adminInfo.Org.Id, patientID, id)
279
 	if err != nil {
286
 	if err != nil {
280
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
287
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
331
 	monitor.UreaMonitoring = urea_monitoring
338
 	monitor.UreaMonitoring = urea_monitoring
332
 	monitor.BloodThickness = blood_thickness
339
 	monitor.BloodThickness = blood_thickness
333
 	monitor.BloodTemperature = blood_temperature
340
 	monitor.BloodTemperature = blood_temperature
341
+	monitor.HeparinAmount = heparin_amount
342
+	monitor.Dehydration = dehydration
334
 	err = service.UpdateMonitor(monitor)
343
 	err = service.UpdateMonitor(monitor)
335
 	key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(date, 10) + ":monitor_records"
344
 	key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(date, 10) + ":monitor_records"
336
 	redis := service.RedisClient()
345
 	redis := service.RedisClient()

+ 6 - 0
controllers/mobile_api_controllers/patient_api_controller.go View File

2629
 		urea_befor := dataBody["urea_befor"].(string)
2629
 		urea_befor := dataBody["urea_befor"].(string)
2630
 		evaluation.UreaBefor = urea_befor
2630
 		evaluation.UreaBefor = urea_befor
2631
 	}
2631
 	}
2632
+
2633
+	if dataBody["suction"] != nil && reflect.TypeOf(dataBody["suction"]).String() == "string" {
2634
+		suction := dataBody["suction"].(string)
2635
+
2636
+		evaluation.Suction = suction
2637
+	}
2632
 	return
2638
 	return
2633
 }
2639
 }
2634
 
2640
 

+ 9 - 0
controllers/secondary_order_api_contorller.go View File

1
+package controllers
2
+
3
+type SecondaryOrderApiController struct {
4
+	BaseAuthAPIController
5
+}
6
+
7
+func SecondaryOrderApiRegistRouters() {
8
+
9
+}

+ 317 - 79
controllers/supply_order_api_contorller.go View File

103
 	beego.Router("/api/supply/deletereturnorderbyid", &SupplyOrderApiController{}, "Get:DeleteReturnOrderById")
103
 	beego.Router("/api/supply/deletereturnorderbyid", &SupplyOrderApiController{}, "Get:DeleteReturnOrderById")
104
 	//反审核退货单
104
 	//反审核退货单
105
 	beego.Router("/api/supply/modefyreturnorder", &SupplyOrderApiController{}, "Get:ModefyReturnOrder")
105
 	beego.Router("/api/supply/modefyreturnorder", &SupplyOrderApiController{}, "Get:ModefyReturnOrder")
106
+
107
+	//获取采购数据
108
+	beego.Router("/api/supply/getgoodorderdetaillist", &SupplyOrderApiController{}, "Get:GetGoodOrderDetailList")
106
 }
109
 }
107
 
110
 
108
 //判断前端参数是否为空
111
 //判断前端参数是否为空
305
 							Number:       number,
308
 							Number:       number,
306
 							Bank:         bank,
309
 							Bank:         bank,
307
 							BankAccount:  bankAccount,
310
 							BankAccount:  bankAccount,
311
+							UserOrgId:    orgId,
308
 							Status:       1,
312
 							Status:       1,
309
 							Mtime:        time.Now().Unix(),
313
 							Mtime:        time.Now().Unix(),
310
 							Modify:       tmodify,
314
 							Modify:       tmodify,
962
 	limit, _ := this.GetInt64("limit")
966
 	limit, _ := this.GetInt64("limit")
963
 	orgId := this.GetAdminUserInfo().CurrentOrgId
967
 	orgId := this.GetAdminUserInfo().CurrentOrgId
964
 	list, total, err := service.GetAllPurchaseOrderList(check_id, startTime, endTime, keyword, page, limit, orgId)
968
 	list, total, err := service.GetAllPurchaseOrderList(check_id, startTime, endTime, keyword, page, limit, orgId)
969
+
965
 	if err == nil {
970
 	if err == nil {
966
 		this.ServeSuccessJSON(map[string]interface{}{
971
 		this.ServeSuccessJSON(map[string]interface{}{
967
 			"list":  list,
972
 			"list":  list,
1213
 			}
1218
 			}
1214
 
1219
 
1215
 		}
1220
 		}
1221
+		//查询
1222
+		orderInfo, _ := service.GetSupplyWarehousingOrderInfo(warehousing_id)
1216
 		this.ServeSuccessJSON(map[string]interface{}{
1223
 		this.ServeSuccessJSON(map[string]interface{}{
1217
 			"warehousingInfo": warehousingInfo,
1224
 			"warehousingInfo": warehousingInfo,
1225
+			"orderInfo":       orderInfo,
1218
 		})
1226
 		})
1219
 
1227
 
1220
 	}
1228
 	}
1257
 	baseList, _ := service.GetSupplyDrugList(orgId)
1265
 	baseList, _ := service.GetSupplyDrugList(orgId)
1258
 
1266
 
1259
 	goodList, _ := service.GetSupplyGoodList(orgId)
1267
 	goodList, _ := service.GetSupplyGoodList(orgId)
1268
+
1260
 	if err == nil {
1269
 	if err == nil {
1261
 		this.ServeSuccessJSON(map[string]interface{}{
1270
 		this.ServeSuccessJSON(map[string]interface{}{
1262
 			"info":       info,
1271
 			"info":       info,
1542
 					GoodNumber:              warehouseOut.GoodNumber,
1551
 					GoodNumber:              warehouseOut.GoodNumber,
1543
 					SupplyManufacturer:      supply_manufacturer,
1552
 					SupplyManufacturer:      supply_manufacturer,
1544
 					MinPrice:                min_price_float,
1553
 					MinPrice:                min_price_float,
1554
+					IsWarehosue:             2,
1545
 				}
1555
 				}
1546
 				warehousingOut = append(warehousingOut, &order)
1556
 				warehousingOut = append(warehousingOut, &order)
1547
 			}
1557
 			}
1552
 		//如果是手动新增的,type 等于2
1562
 		//如果是手动新增的,type 等于2
1553
 		if item.WarehouseInfoId == 0 {
1563
 		if item.WarehouseInfoId == 0 {
1554
 			item.Type = 2
1564
 			item.Type = 2
1565
+			service.CreateSupplyWarehousOutOrder(item)
1555
 		}
1566
 		}
1556
-		//查询该商品是否来源于采购订单,如果存在则关联, 如果不存在则取消关联
1557
-		_, errcode := service.GetGoodIsSource(warehousing_id, item.ProjectId, orgId)
1558
-		if errcode == gorm.ErrRecordNotFound {
1559
-			item.WarehousingId = 0
1560
-			item.WarehouseInfoId = 0
1561
-			item.OrderNumber = ""
1562
-			item.Type = 2
1563
-			err = service.CreateSupplyWarehousOutOrder(item)
1564
-			//更新采购单
1565
-			service.ModfySupplyWarehouseOut(warehousing_id, orgId)
1566
-		}
1567
-		if errcode == nil {
1568
-			err = service.CreateSupplyWarehousOutOrder(item)
1567
+
1568
+		if item.WarehouseInfoId > 0 {
1569
+			//查询该商品是否来源于采购订单,如果存在则关联, 如果不存在则取消关联
1570
+			_, errcode := service.GetGoodIsSource(warehousing_id, item.ProjectId, orgId)
1571
+
1572
+			if errcode == gorm.ErrRecordNotFound {
1573
+				item.WarehousingId = 0
1574
+				item.WarehouseInfoId = 0
1575
+				item.OrderNumber = ""
1576
+				item.Type = 2
1577
+				err = service.CreateSupplyWarehousOutOrder(item)
1578
+				//更新采购单
1579
+				service.ModfySupplyWarehouseOut(warehousing_id, orgId)
1580
+			}
1581
+			if errcode == nil {
1582
+				err = service.CreateSupplyWarehousOutOrder(item)
1583
+			}
1569
 		}
1584
 		}
1570
 
1585
 
1571
 	}
1586
 	}
1630
 	id, _ := this.GetInt64("id")
1645
 	id, _ := this.GetInt64("id")
1631
 	ids := this.GetString("ids")
1646
 	ids := this.GetString("ids")
1632
 	orgId := this.GetAdminUserInfo().CurrentOrgId
1647
 	orgId := this.GetAdminUserInfo().CurrentOrgId
1648
+
1633
 	if len(ids) == 0 {
1649
 	if len(ids) == 0 {
1634
 		out, err := service.GetGoodOrderDetail(id, orgId)
1650
 		out, err := service.GetGoodOrderDetail(id, orgId)
1635
 		list, _ := service.GetSupplyWarehouseOutById(id, orgId)
1651
 		list, _ := service.GetSupplyWarehouseOutById(id, orgId)
1652
+		for _, item := range list {
1653
+
1654
+			if item.IsSource == 1 {
1655
+				waresingList, _ := service.GetAllDrugWaresingList(item.ProjectId, orgId)
1656
+				medical, _ := service.GetBaseDrugMedical(item.ProjectId)
1657
+				item.DrugWarehouseInfo = waresingList
1658
+				item.SpBaseDrug = medical
1659
+			}
1660
+			if item.IsSource == 2 {
1661
+				waresingList, _ := service.GetAllGoodWaresingList(item.ProjectId, orgId)
1662
+
1663
+				item.GoodWarehouseInfo = waresingList
1664
+			}
1665
+		}
1636
 		drugList, _ := service.GetSupplyDrugList(orgId)
1666
 		drugList, _ := service.GetSupplyDrugList(orgId)
1637
 		goodList, _ := service.GetSupplyGoodList(orgId)
1667
 		goodList, _ := service.GetSupplyGoodList(orgId)
1668
+		supplyList, _ := service.GetSupplierList(orgId)
1638
 		if err == nil {
1669
 		if err == nil {
1639
 			this.ServeSuccessJSON(map[string]interface{}{
1670
 			this.ServeSuccessJSON(map[string]interface{}{
1640
-				"out":      out,
1641
-				"list":     list,
1642
-				"goodList": goodList,
1643
-				"drugList": drugList,
1671
+				"out":        out,
1672
+				"list":       list,
1673
+				"goodList":   goodList,
1674
+				"drugList":   drugList,
1675
+				"supplyList": supplyList,
1644
 			})
1676
 			})
1645
 		} else {
1677
 		} else {
1646
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1678
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1650
 		idArray := strings.Split(ids, ",")
1682
 		idArray := strings.Split(ids, ",")
1651
 		out, err := service.GetGoodOrderDetail(id, orgId)
1683
 		out, err := service.GetGoodOrderDetail(id, orgId)
1652
 		list, _ := service.GetSupplyWarehouseOutByIdOne(id, orgId, idArray)
1684
 		list, _ := service.GetSupplyWarehouseOutByIdOne(id, orgId, idArray)
1685
+		for _, item := range list {
1686
+			if item.IsSource == 1 {
1687
+				waresingList, _ := service.GetAllDrugWaresingList(item.ProjectId, orgId)
1688
+				medical, _ := service.GetBaseDrugMedical(item.ProjectId)
1689
+				item.DrugWarehouseInfo = waresingList
1690
+				item.SpBaseDrug = medical
1691
+			}
1692
+			if item.IsSource == 2 {
1693
+				waresingList, _ := service.GetAllGoodWaresingList(item.ProjectId, orgId)
1694
+
1695
+				item.GoodWarehouseInfo = waresingList
1696
+			}
1697
+		}
1653
 		drugList, _ := service.GetSupplyDrugList(orgId)
1698
 		drugList, _ := service.GetSupplyDrugList(orgId)
1654
 		goodList, _ := service.GetSupplyGoodList(orgId)
1699
 		goodList, _ := service.GetSupplyGoodList(orgId)
1700
+		supplyList, _ := service.GetSupplierList(orgId)
1655
 		if err == nil {
1701
 		if err == nil {
1656
 			this.ServeSuccessJSON(map[string]interface{}{
1702
 			this.ServeSuccessJSON(map[string]interface{}{
1657
-				"out":      out,
1658
-				"list":     list,
1659
-				"goodList": goodList,
1660
-				"drugList": drugList,
1703
+				"out":        out,
1704
+				"list":       list,
1705
+				"goodList":   goodList,
1706
+				"drugList":   drugList,
1707
+				"supplyList": supplyList,
1661
 			})
1708
 			})
1662
 		} else {
1709
 		} else {
1663
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1710
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1954
 						GoodNumber:              good_number,
2001
 						GoodNumber:              good_number,
1955
 						SupplyManufacturer:      supply_manufacturer,
2002
 						SupplyManufacturer:      supply_manufacturer,
1956
 						MinPrice:                min_price_float,
2003
 						MinPrice:                min_price_float,
2004
+						IsWarehosue:             2,
1957
 					}
2005
 					}
1958
 					warehousingOut = append(warehousingOut, &order)
2006
 					warehousingOut = append(warehousingOut, &order)
1959
 				}
2007
 				}
1981
 		}
2029
 		}
1982
 		err = service.CreateSupplyWarehousOutOrder(item)
2030
 		err = service.CreateSupplyWarehousOutOrder(item)
1983
 	}
2031
 	}
2032
+
1984
 	for _, item := range updateWarehout {
2033
 	for _, item := range updateWarehout {
1985
-		//查询该商品是否来源于采购订单,如果存在则关联, 如果不存在则取消关联
1986
-		_, errcode := service.GetGoodIsSource(item.WarehousingId, item.ProjectId, orgId)
1987
-		if errcode == gorm.ErrRecordNotFound {
1988
-			item.WarehousingId = 0
1989
-			item.WarehouseInfoId = 0
1990
-			item.Type = 2
1991
-			item.OrderNumber = ""
1992
-			service.UpdateGoodWarehouseOutOrder(item)
1993
-			//更新采购单
1994
-			service.ModfySupplyWarehouseOut(item.WarehousingId, orgId)
1995
-		}
1996
-	}
2034
+		service.UpdateGoodWarehouseOutOrder(item)
2035
+	}
2036
+	//for _, item := range updateWarehout {
2037
+	//	service.UpdateGoodWarehouseOutOrder(item)
2038
+	//	//查询该商品是否来源于采购订单,如果存在则关联, 如果不存在则取消关联
2039
+	//	_, errcode := service.GetGoodIsSource(item.WarehousingId, item.ProjectId, orgId)
2040
+	//	if errcode == gorm.ErrRecordNotFound {
2041
+	//		item.WarehousingId = 0
2042
+	//		item.WarehouseInfoId = 0
2043
+	//		item.Type = 2
2044
+	//		item.OrderNumber = ""
2045
+	//
2046
+	//		//更新采购单
2047
+	//		service.ModfySupplyWarehouseOut(item.WarehousingId, orgId)
2048
+	//	}
2049
+	//}
2050
+	list, _ := service.GetSupplyWarehouseOutById(warehose_out_id, orgId)
1997
 	if err == nil {
2051
 	if err == nil {
1998
 		this.ServeSuccessJSON(map[string]interface{}{
2052
 		this.ServeSuccessJSON(map[string]interface{}{
1999
-			"out": out,
2053
+			"out":  out,
2054
+			"list": list,
2000
 		})
2055
 		})
2001
 	} else {
2056
 	} else {
2002
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
2057
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
2026
 	//获取购货订单的数据
2081
 	//获取购货订单的数据
2027
 	purcaseOrder, _ := service.GetAllPurcaseOrderById(id, orgId)
2082
 	purcaseOrder, _ := service.GetAllPurcaseOrderById(id, orgId)
2028
 	//获取购货单的数据
2083
 	//获取购货单的数据
2029
-	goodOrder, err := service.GetAllGoodOrderById(id, orgId)
2084
+	goodOrder, err := service.GetAllGoodOrderByIdSix(id, orgId)
2085
+	fmt.Println("2323232332232323232332", goodOrder)
2030
 	drugList, err := service.GetSupplyDrugList(orgId)
2086
 	drugList, err := service.GetSupplyDrugList(orgId)
2087
+
2031
 	if err == nil {
2088
 	if err == nil {
2032
 		this.ServeSuccessJSON(map[string]interface{}{
2089
 		this.ServeSuccessJSON(map[string]interface{}{
2033
 			"purcaseOrder": purcaseOrder,
2090
 			"purcaseOrder": purcaseOrder,
2136
 	//获取购货订单的数据
2193
 	//获取购货订单的数据
2137
 	purcaseOrder, _ := service.GetAllPurcaseOrderById(warehousing_id, orgId)
2194
 	purcaseOrder, _ := service.GetAllPurcaseOrderById(warehousing_id, orgId)
2138
 	//获取购货单的数据
2195
 	//获取购货单的数据
2139
-	goodOrder, _ := service.GetAllGoodOrderByIdTwo(warehousing_id, orgId)
2196
+	goodOrder, _ := service.GetAllGoodOrderByIdTwo(id, orgId)
2140
 
2197
 
2141
 	//查询该购货单是否审核成功
2198
 	//查询该购货单是否审核成功
2142
 	detail, _ := service.GetGoodOrderDetail(id, orgId)
2199
 	detail, _ := service.GetGoodOrderDetail(id, orgId)
2340
 	}
2397
 	}
2341
 	//创建入库单
2398
 	//创建入库单
2342
 	errs := service.CreateDrugWarehousingInfoSix(warehouseInfoDetail)
2399
 	errs := service.CreateDrugWarehousingInfoSix(warehouseInfoDetail)
2400
+
2401
+	//改变入库状态
2402
+
2343
 	fmt.Println(errs)
2403
 	fmt.Println(errs)
2344
 	for _, items := range drugFlow {
2404
 	for _, items := range drugFlow {
2345
 		drugWarehouseInfo, _ := service.GetLastDrugWarehouseInfo(items.DrugId)
2405
 		drugWarehouseInfo, _ := service.GetLastDrugWarehouseInfo(items.DrugId)
2349
 	service.CreateDrugFlowSix(drugFlow)
2409
 	service.CreateDrugFlowSix(drugFlow)
2350
 
2410
 
2351
 	drugList, _ := service.GetSupplyDrugList(orgId)
2411
 	drugList, _ := service.GetSupplyDrugList(orgId)
2412
+
2413
+	for _, items := range goodOrder {
2414
+		service.UpdateWarehouseingById(items.ID)
2415
+	}
2352
 	if err == nil {
2416
 	if err == nil {
2353
 		this.ServeSuccessJSON(map[string]interface{}{
2417
 		this.ServeSuccessJSON(map[string]interface{}{
2354
 			"purcaseOrder": purcaseOrder,
2418
 			"purcaseOrder": purcaseOrder,
2456
 				}
2520
 				}
2457
 				supply_count := int64(items["supply_count"].(float64))
2521
 				supply_count := int64(items["supply_count"].(float64))
2458
 
2522
 
2459
-				if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
2523
+				if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
2460
 					utils.ErrorLog("count")
2524
 					utils.ErrorLog("count")
2461
 					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2525
 					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2462
 					return
2526
 					return
2463
 				}
2527
 				}
2464
-				count := int64(items["count"].(float64))
2528
+				count := items["count"].(string)
2465
 
2529
 
2466
 				if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
2530
 				if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
2467
 					utils.ErrorLog("manufacturer_id")
2531
 					utils.ErrorLog("manufacturer_id")
2604
 					return
2668
 					return
2605
 				}
2669
 				}
2606
 				id := int64(items["id"].(float64))
2670
 				id := int64(items["id"].(float64))
2671
+
2672
+				deposit_rate := items["deposit_rate"].(string)
2673
+
2674
+				deposit_rate_float, _ := strconv.ParseFloat(deposit_rate, 64)
2607
 				cancelOrder := &models.SpSupplierWarehousingCancelOrder{
2675
 				cancelOrder := &models.SpSupplierWarehousingCancelOrder{
2608
 					ManufacturerId:            manufacturer_id,
2676
 					ManufacturerId:            manufacturer_id,
2609
 					OrderNumber:               order_number,
2677
 					OrderNumber:               order_number,
2610
 					ProjectId:                 project_id,
2678
 					ProjectId:                 project_id,
2611
 					GoodNumber:                good_number,
2679
 					GoodNumber:                good_number,
2612
 					IsSource:                  is_source,
2680
 					IsSource:                  is_source,
2613
-					Count:                     supply_count,
2681
+					Count:                     count,
2614
 					Price:                     price_float,
2682
 					Price:                     price_float,
2615
 					Remark:                    supply_remake,
2683
 					Remark:                    supply_remake,
2616
 					RateOfConcession:          rate_of_concession_float,
2684
 					RateOfConcession:          rate_of_concession_float,
2637
 					WarehousingId:             warehousing_id,
2705
 					WarehousingId:             warehousing_id,
2638
 					SourceCount:               count,
2706
 					SourceCount:               count,
2639
 					SupplyWarehouseDetailInfo: id,
2707
 					SupplyWarehouseDetailInfo: id,
2708
+					SupplyCount:               supply_count,
2709
+					DepositRate:               deposit_rate_float,
2640
 				}
2710
 				}
2641
 				warehouseCancel = append(warehouseCancel, cancelOrder)
2711
 				warehouseCancel = append(warehouseCancel, cancelOrder)
2642
 			}
2712
 			}
2644
 	}
2714
 	}
2645
 
2715
 
2646
 	for _, item := range warehouseCancel {
2716
 	for _, item := range warehouseCancel {
2717
+		if item.SupplyWarehouseDetailInfo > 0 {
2718
+			item.Type = 1
2719
+		} else {
2720
+			item.Type = 2
2721
+		}
2647
 		service.CreateCancelReturnOrder(item)
2722
 		service.CreateCancelReturnOrder(item)
2648
 		//查询该商品在退库单中是否存在
2723
 		//查询该商品在退库单中是否存在
2649
 		_, errcodes := service.GetSupplyWarehouseOutIsExsit(item.WarehouseOutId, item.ProjectId, orgId)
2724
 		_, errcodes := service.GetSupplyWarehouseOutIsExsit(item.WarehouseOutId, item.ProjectId, orgId)
2650
 		//如果不存在则情况退库单的关联信息
2725
 		//如果不存在则情况退库单的关联信息
2651
 		if errcodes == gorm.ErrRecordNotFound {
2726
 		if errcodes == gorm.ErrRecordNotFound {
2652
-			service.ModfySupplyCancel(item.WarehouseCancelId, orgId)
2727
+			service.ModfySupplyCancel(item.WarehouseCancelId, orgId, item.ProjectId)
2653
 
2728
 
2654
 		}
2729
 		}
2655
 
2730
 
2720
 	baseList, _ := service.GetSupplyDrugList(orgId)
2795
 	baseList, _ := service.GetSupplyDrugList(orgId)
2721
 
2796
 
2722
 	goodList, _ := service.GetSupplyGoodList(orgId)
2797
 	goodList, _ := service.GetSupplyGoodList(orgId)
2798
+	supplyList, _ := service.GetSupplierList(orgId)
2723
 	if err == nil {
2799
 	if err == nil {
2724
 		this.ServeSuccessJSON(map[string]interface{}{
2800
 		this.ServeSuccessJSON(map[string]interface{}{
2725
 			"cancelDetail":      detail,
2801
 			"cancelDetail":      detail,
2726
 			"orderCancelDetail": orderDetail,
2802
 			"orderCancelDetail": orderDetail,
2727
 			"drugList":          baseList,
2803
 			"drugList":          baseList,
2728
 			"goodList":          goodList,
2804
 			"goodList":          goodList,
2805
+			"supplyList":        supplyList,
2729
 		})
2806
 		})
2730
 	} else {
2807
 	} else {
2731
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
2808
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
2903
 				}
2980
 				}
2904
 				supply_manufacturer := items["supply_manufacturer"].(string)
2981
 				supply_manufacturer := items["supply_manufacturer"].(string)
2905
 
2982
 
2983
+				if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
2984
+					utils.ErrorLog("count")
2985
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2986
+					return
2987
+				}
2988
+				count := items["count"].(string)
2989
+
2990
+				if items["deposit_rate"] == nil || reflect.TypeOf(items["deposit_rate"]).String() != "string" {
2991
+					utils.ErrorLog("deposit_rate")
2992
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2993
+					return
2994
+				}
2995
+				deposit_rate := items["deposit_rate"].(string)
2996
+				deposit_rate_float, _ := strconv.ParseFloat(deposit_rate, 64)
2906
 				if id > 0 {
2997
 				if id > 0 {
2907
 					cancelOrder := &models.SpSupplierWarehousingCancelOrder{
2998
 					cancelOrder := &models.SpSupplierWarehousingCancelOrder{
2908
 						ID:                      id,
2999
 						ID:                      id,
2911
 						ProjectId:               project_id,
3002
 						ProjectId:               project_id,
2912
 						GoodNumber:              good_number,
3003
 						GoodNumber:              good_number,
2913
 						IsSource:                is_source,
3004
 						IsSource:                is_source,
2914
-						Count:                   supply_count,
3005
+						Count:                   count,
2915
 						Price:                   price_float,
3006
 						Price:                   price_float,
2916
 						Remark:                  supply_remake,
3007
 						Remark:                  supply_remake,
2917
 						RateOfConcession:        rate_of_concession_float,
3008
 						RateOfConcession:        rate_of_concession_float,
2931
 						Name:                    name,
3022
 						Name:                    name,
2932
 						SupplyUnit:              supply_unit,
3023
 						SupplyUnit:              supply_unit,
2933
 						SupplyLicenseNumber:     supply_license_number,
3024
 						SupplyLicenseNumber:     supply_license_number,
3025
+						SupplyCount:             supply_count,
3026
+						DepositRate:             deposit_rate_float,
2934
 					}
3027
 					}
2935
 					updateWarehouseCancel = append(updateWarehouseCancel, cancelOrder)
3028
 					updateWarehouseCancel = append(updateWarehouseCancel, cancelOrder)
2936
 				}
3029
 				}
2942
 						ProjectId:               project_id,
3035
 						ProjectId:               project_id,
2943
 						GoodNumber:              good_number,
3036
 						GoodNumber:              good_number,
2944
 						IsSource:                is_source,
3037
 						IsSource:                is_source,
2945
-						Count:                   supply_count,
3038
+						Count:                   count,
2946
 						Price:                   price_float,
3039
 						Price:                   price_float,
2947
 						Remark:                  supply_remake,
3040
 						Remark:                  supply_remake,
2948
 						RateOfConcession:        rate_of_concession_float,
3041
 						RateOfConcession:        rate_of_concession_float,
2952
 						Status:                  1,
3045
 						Status:                  1,
2953
 						Mtime:                   0,
3046
 						Mtime:                   0,
2954
 						WarehouseCancelId:       warehouse_out_id,
3047
 						WarehouseCancelId:       warehouse_out_id,
2955
-						Type:                    1,
3048
+						Type:                    2,
2956
 						ReturnNumber:            return_number,
3049
 						ReturnNumber:            return_number,
2957
 						WarehouseOutId:          warehouse_out_id,
3050
 						WarehouseOutId:          warehouse_out_id,
2958
 						SupplySpecificationName: supply_specification_name,
3051
 						SupplySpecificationName: supply_specification_name,
2962
 						Name:                    name,
3055
 						Name:                    name,
2963
 						SupplyUnit:              supply_unit,
3056
 						SupplyUnit:              supply_unit,
2964
 						SupplyLicenseNumber:     supply_license_number,
3057
 						SupplyLicenseNumber:     supply_license_number,
3058
+						SupplyCount:             supply_count,
3059
+						DepositRate:             deposit_rate_float,
2965
 					}
3060
 					}
2966
 					warehouseCancel = append(warehouseCancel, cancelOrder)
3061
 					warehouseCancel = append(warehouseCancel, cancelOrder)
2967
 				}
3062
 				}
2970
 
3065
 
2971
 		if len(updateWarehouseCancel) > 0 {
3066
 		if len(updateWarehouseCancel) > 0 {
2972
 			for _, item := range updateWarehouseCancel {
3067
 			for _, item := range updateWarehouseCancel {
3068
+
2973
 				service.UpdateWarehouseCancelOrder(item)
3069
 				service.UpdateWarehouseCancelOrder(item)
2974
 			}
3070
 			}
2975
 		}
3071
 		}
2976
 		if len(warehouseCancel) > 0 {
3072
 		if len(warehouseCancel) > 0 {
2977
 			for _, item := range warehouseCancel {
3073
 			for _, item := range warehouseCancel {
3074
+
2978
 				service.CreateCancelReturnOrder(item)
3075
 				service.CreateCancelReturnOrder(item)
2979
 			}
3076
 			}
2980
 		}
3077
 		}
2992
 func (this *SupplyOrderApiController) ModefyGoodOrder() {
3089
 func (this *SupplyOrderApiController) ModefyGoodOrder() {
2993
 
3090
 
2994
 	id, _ := this.GetInt64("id")
3091
 	id, _ := this.GetInt64("id")
3092
+	warehousing_id, _ := this.GetInt64("warehousing_id")
2995
 	orgId := this.GetAdminUserInfo().CurrentOrgId
3093
 	orgId := this.GetAdminUserInfo().CurrentOrgId
2996
 
3094
 
2997
-	//获取购货订单的数据
2998
-	purcaseOrder, _ := service.GetAllPurcaseOrderById(id, orgId)
2999
 	//获取购货单的数据
3095
 	//获取购货单的数据
3000
 	goodOrder, _ := service.GetAllGoodOrderById(id, orgId)
3096
 	goodOrder, _ := service.GetAllGoodOrderById(id, orgId)
3097
+
3098
+	//判断该订单是否有出库记录
3099
+	for _, it := range goodOrder {
3100
+
3101
+		if it.IsSource == 1 {
3102
+			out, _ := service.GetDrugWarehosueInfoByWarehousingId(it.ProjectId, id, orgId)
3103
+
3104
+			if out.ID > 0 {
3105
+				this.ServeSuccessJSON(map[string]interface{}{
3106
+					"cancelList":   "",
3107
+					"purcaseOrder": "",
3108
+					"goodOrder":    "",
3109
+					"drugList":     "",
3110
+					"msg":          3,
3111
+				})
3112
+				return
3113
+			}
3114
+		}
3115
+		if it.IsSource == 2 {
3116
+			fmt.Println("hh23323233232232332232323232332", it.WarehouseOutId)
3117
+			out, _ := service.GetGoodWarehouseInfoByWarehousingId(it.ProjectId, id, orgId)
3118
+			if out.ID > 0 {
3119
+				this.ServeSuccessJSON(map[string]interface{}{
3120
+					"cancelList":   "",
3121
+					"purcaseOrder": "",
3122
+					"goodOrder":    "",
3123
+					"drugList":     "",
3124
+					"msg":          3,
3125
+				})
3126
+				return
3127
+			}
3128
+		}
3129
+	}
3130
+
3131
+	//获取购货订单的数据
3132
+	purcaseOrder, _ := service.GetAllPurcaseOrderById(warehousing_id, orgId)
3133
+
3001
 	drugList, _ := service.GetSupplyDrugList(orgId)
3134
 	drugList, _ := service.GetSupplyDrugList(orgId)
3135
+
3002
 	//获取已有关联的退货单
3136
 	//获取已有关联的退货单
3003
 	cancelList, _ := service.GetSupplyCancelWarehouse(id, orgId)
3137
 	cancelList, _ := service.GetSupplyCancelWarehouse(id, orgId)
3004
 	//查询是否存在退货单
3138
 	//查询是否存在退货单
3013
 		}
3147
 		}
3014
 		err := service.UpdateSupplyGoodOrder(id, out)
3148
 		err := service.UpdateSupplyGoodOrder(id, out)
3015
 
3149
 
3150
+		for _, its := range goodOrder {
3151
+			//改变采购单状态
3152
+			service.UpdateSupplyOrderListById(its.ID)
3153
+		}
3154
+
3016
 		//查询该订单不是采购入库的数据
3155
 		//查询该订单不是采购入库的数据
3017
 		list, _ := service.GetDrugSupplyWarehousingById(id, orgId)
3156
 		list, _ := service.GetDrugSupplyWarehousingById(id, orgId)
3018
 		if len(list) == 0 {
3157
 		if len(list) == 0 {
3151
 	//获取退库单详情
3290
 	//获取退库单详情
3152
 	list, _ := service.GetSupplyCancelOrderDetail(id, orgId)
3291
 	list, _ := service.GetSupplyCancelOrderDetail(id, orgId)
3153
 	for _, item := range list {
3292
 	for _, item := range list {
3154
-
3293
+		fmt.Println("itme.233232323232323232323232323232232332", item.Type)
3155
 		var total_count int64
3294
 		var total_count int64
3156
 		var prescribing_number_total int64
3295
 		var prescribing_number_total int64
3157
 		//药品
3296
 		//药品
3158
 		if item.IsSource == 1 {
3297
 		if item.IsSource == 1 {
3159
 
3298
 
3160
 			//获取药品库存
3299
 			//获取药品库存
3161
-			info, _ := service.GetDrugTotalCountTwenTy(item.ProjectId, item.SupplyWarehouseDetailInfo)
3300
+			info, _ := service.GetDrugTotalCountTwenTy(item.ProjectId, item.SupplyWarehouseDetailInfo, item.Type)
3162
 
3301
 
3163
 			for _, it := range info {
3302
 			for _, it := range info {
3164
-				total_count += it.StockMaxNumber*it.MinNumber + it.StockMinNumber
3303
+
3304
+				if it.MaxUnit == it.CountUnit {
3305
+					it.StockMaxNumber = it.StockMaxNumber * it.MinNumber
3306
+
3307
+				}
3308
+				total_count += (it.StockMaxNumber + it.StockMinNumber)
3165
 			}
3309
 			}
3310
+
3166
 			//查询改药品信息
3311
 			//查询改药品信息
3167
 			medical, _ := service.GetBaseDrugMedical(item.ProjectId)
3312
 			medical, _ := service.GetBaseDrugMedical(item.ProjectId)
3168
 
3313
 
3169
 			//判断单位是否相等
3314
 			//判断单位是否相等
3170
 			if medical.MaxUnit == item.SupplyUnit {
3315
 			if medical.MaxUnit == item.SupplyUnit {
3171
 				//转化为最小单位
3316
 				//转化为最小单位
3172
-				prescribing_number_total = item.Count * medical.MinNumber
3317
+				prescribing_number_total = item.SupplyCount * medical.MinNumber
3173
 			}
3318
 			}
3174
 			if medical.MinUnit == item.SupplyUnit {
3319
 			if medical.MinUnit == item.SupplyUnit {
3175
-				prescribing_number_total = item.Count
3320
+				prescribing_number_total = item.SupplyCount
3176
 			}
3321
 			}
3177
 
3322
 
3323
+			fmt.Println("hhhhhadf dafsdfsdfddddfdf", prescribing_number_total)
3178
 			//判断单位
3324
 			//判断单位
3179
 			if total_count == 0 {
3325
 			if total_count == 0 {
3180
 				goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
3326
 				goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
3215
 			number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
3361
 			number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
3216
 			number = number + total
3362
 			number = number + total
3217
 			warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
3363
 			warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
3218
-			operation_time := time.Now().Unix()
3364
+			//operation_time := time.Now().Unix()
3219
 			creater := this.GetAdminUserInfo().AdminUser.Id
3365
 			creater := this.GetAdminUserInfo().AdminUser.Id
3220
 			recordDateStr := time.Now().Format("2006-01-02")
3366
 			recordDateStr := time.Now().Format("2006-01-02")
3221
 			recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
3367
 			recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
3223
 			record_date := recordDate.Unix()
3369
 			record_date := recordDate.Unix()
3224
 			warehouseOut := models.DrugWarehouseOut{
3370
 			warehouseOut := models.DrugWarehouseOut{
3225
 				WarehouseOutOrderNumber: warehousing_out_order,
3371
 				WarehouseOutOrderNumber: warehousing_out_order,
3226
-				OperationTime:           operation_time,
3372
+				OperationTime:           record_date,
3227
 				OrgId:                   orgId,
3373
 				OrgId:                   orgId,
3228
 				Creater:                 creater,
3374
 				Creater:                 creater,
3229
 				Ctime:                   ctime,
3375
 				Ctime:                   ctime,
3247
 				WarehouseOutOrderNumber: lastDrug.WarehouseOutOrderNumber,
3393
 				WarehouseOutOrderNumber: lastDrug.WarehouseOutOrderNumber,
3248
 				WarehouseOutId:          lastDrug.ID,
3394
 				WarehouseOutId:          lastDrug.ID,
3249
 				DrugId:                  item.ProjectId,
3395
 				DrugId:                  item.ProjectId,
3250
-				Count:                   item.Count,
3396
+				Count:                   item.SupplyCount,
3251
 				Price:                   item.Price,
3397
 				Price:                   item.Price,
3252
 				Status:                  1,
3398
 				Status:                  1,
3253
 				Ctime:                   ctime,
3399
 				Ctime:                   ctime,
3265
 				WarehouseInfoId:         0,
3411
 				WarehouseInfoId:         0,
3266
 				SupplyCancelOutId:       id,
3412
 				SupplyCancelOutId:       id,
3267
 				SupplyWarehouseId:       warehouse_out_id,
3413
 				SupplyWarehouseId:       warehouse_out_id,
3414
+				SysRecordTime:           record_date,
3415
+				IsSource:                item.Type,
3268
 			}
3416
 			}
3269
 
3417
 
3270
 			drup, _ := service.FindBaseDrugLibRecord(orgId, item.ProjectId)
3418
 			drup, _ := service.FindBaseDrugLibRecord(orgId, item.ProjectId)
3271
 			if drup.ID > 0 {
3419
 			if drup.ID > 0 {
3272
-				prescribingNumber := item.Count
3273
-				service.AutoDrugDeliverInfoNight(orgId, prescribingNumber, &warehouseOut, &drup, warehouseOutInfo)
3420
+				prescribingNumber := item.SupplyCount
3421
+				service.AutoDrugDeliverInfoNight(orgId, prescribingNumber, &warehouseOut, &drup, warehouseOutInfo, warehouse_out_id, id)
3274
 			}
3422
 			}
3275
 
3423
 
3276
 			//修改原数据
3424
 			//修改原数据
3277
-			orderInfo := models.SpSupplierWarehousingCancelOrder{
3278
-				SourceCount: item.Count - item.SourceCount,
3279
-			}
3280
-			service.UpdateSupplyCancelById(item.ID, orderInfo)
3425
+			/*	orderInfo := models.SpSupplierWarehousingCancelOrder{
3426
+					SourceCount: item.SupplyCount - item.SourceCount,
3427
+				}
3428
+				service.UpdateSupplyCancelById(item.ID, orderInfo)*/
3281
 		}
3429
 		}
3282
 
3430
 
3283
 		//耗材
3431
 		//耗材
3284
 		if item.IsSource == 2 {
3432
 		if item.IsSource == 2 {
3285
 			// 查询该耗材是否有库存
3433
 			// 查询该耗材是否有库存
3286
-			warehouseOne, _ := service.FindWarehousingInfoTwenTy(item.ProjectId, item.SupplyWarehouseDetailInfo)
3434
+			warehouseOne, _ := service.FindWarehousingInfoTwenTy(item.ProjectId, item.SupplyWarehouseDetailInfo, item.Type)
3287
 
3435
 
3288
 			// 如果出库数量大于该批次剩余库存数量
3436
 			// 如果出库数量大于该批次剩余库存数量
3289
-			if item.Count > warehouseOne.StockCount {
3437
+			if item.SupplyCount > warehouseOne.StockCount {
3290
 
3438
 
3291
 				goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
3439
 				goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
3292
 				this.ServeSuccessJSON(map[string]interface{}{
3440
 				this.ServeSuccessJSON(map[string]interface{}{
3308
 			number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
3456
 			number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
3309
 			number = number + total
3457
 			number = number + total
3310
 			warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
3458
 			warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
3311
-			operation_time := time.Now().Unix()
3459
+			//operation_time := time.Now().Unix()
3312
 			creater := this.GetAdminUserInfo().AdminUser.Id
3460
 			creater := this.GetAdminUserInfo().AdminUser.Id
3313
 			recordDateStr := time.Now().Format("2006-01-02")
3461
 			recordDateStr := time.Now().Format("2006-01-02")
3314
 			recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
3462
 			recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
3316
 			record_date := recordDate.Unix()
3464
 			record_date := recordDate.Unix()
3317
 			warehouseOut := models.WarehouseOut{
3465
 			warehouseOut := models.WarehouseOut{
3318
 				WarehouseOutOrderNumber: warehousing_out_order,
3466
 				WarehouseOutOrderNumber: warehousing_out_order,
3319
-				OperationTime:           operation_time,
3467
+				OperationTime:           record_date,
3320
 				OrgId:                   orgId,
3468
 				OrgId:                   orgId,
3321
 				Creater:                 creater,
3469
 				Creater:                 creater,
3322
 				Ctime:                   ctime,
3470
 				Ctime:                   ctime,
3328
 				IsSys:                   0,
3476
 				IsSys:                   0,
3329
 			}
3477
 			}
3330
 			//查询是否生成出库单
3478
 			//查询是否生成出库单
3331
-			_, errcodes := service.FindStockOutByIsSys(orgId, 0, operation_time)
3479
+			_, errcodes := service.FindStockOutByIsSys(orgId, 0, record_date)
3332
 			if errcodes == gorm.ErrRecordNotFound {
3480
 			if errcodes == gorm.ErrRecordNotFound {
3333
 				service.AddSigleWarehouseOut(&warehouseOut)
3481
 				service.AddSigleWarehouseOut(&warehouseOut)
3334
 			}
3482
 			}
3335
 			outWarehouse, _ := service.GetlastWarehouseOutById(orgId, record_date)
3483
 			outWarehouse, _ := service.GetlastWarehouseOutById(orgId, record_date)
3484
+			fmt.Println("232332322332232323", outWarehouse)
3336
 			goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
3485
 			goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
3337
 			info := &models.WarehouseOutInfo{
3486
 			info := &models.WarehouseOutInfo{
3338
 				WarehouseOutOrderNumber: outWarehouse.WarehouseOutOrderNumber,
3487
 				WarehouseOutOrderNumber: outWarehouse.WarehouseOutOrderNumber,
3340
 				WarehouseInfotId:        0,
3489
 				WarehouseInfotId:        0,
3341
 				GoodId:                  item.ProjectId,
3490
 				GoodId:                  item.ProjectId,
3342
 				GoodTypeId:              goodObj.GoodTypeId,
3491
 				GoodTypeId:              goodObj.GoodTypeId,
3343
-				Count:                   item.Count,
3492
+				Count:                   item.SupplyCount,
3344
 				Price:                   item.Price,
3493
 				Price:                   item.Price,
3345
 				TotalPrice:              0,
3494
 				TotalPrice:              0,
3346
 				ProductDate:             item.SupplyProductDate,
3495
 				ProductDate:             item.SupplyProductDate,
3356
 				SupplyCancelOutId:       id,
3505
 				SupplyCancelOutId:       id,
3357
 				OrgId:                   orgId,
3506
 				OrgId:                   orgId,
3358
 				SupplyWarehouseId:       warehouse_out_id,
3507
 				SupplyWarehouseId:       warehouse_out_id,
3508
+				IsSource:                item.Type,
3359
 			}
3509
 			}
3360
 			//出库逻辑
3510
 			//出库逻辑
3361
-			parseDateErr := service.ConsumablesDeliveryNight(orgId, record_date, info, &warehouseOut, item.Count, creater, warehouse_out_id, id)
3511
+			parseDateErr := service.ConsumablesDeliveryNight(orgId, record_date, info, &warehouseOut, item.SupplyCount, creater, warehouse_out_id, id)
3362
 
3512
 
3363
 			if parseDateErr != nil {
3513
 			if parseDateErr != nil {
3364
 				utils.ErrorLog(parseDateErr.Error())
3514
 				utils.ErrorLog(parseDateErr.Error())
3365
 				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
3515
 				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
3366
 				return
3516
 				return
3367
 			}
3517
 			}
3368
-			//更改原退库数据
3369
-			order := models.SpSupplierWarehousingCancelOrder{
3370
-				SourceCount: item.SourceCount - item.Count,
3371
-			}
3372
-			service.UpdateSupplyCancelById(item.ID, order)
3373
 		}
3518
 		}
3374
 	}
3519
 	}
3375
 	cancel := models.SpSupplierWarehouseCancel{
3520
 	cancel := models.SpSupplierWarehouseCancel{
3378
 		CheckTime: record_date,
3523
 		CheckTime: record_date,
3379
 	}
3524
 	}
3380
 	err := service.CheckReturnOrder(id, orgId, cancel)
3525
 	err := service.CheckReturnOrder(id, orgId, cancel)
3381
-
3526
+	fmt.Println("3232233232322332232323232323322332232323232323")
3382
 	if err == nil {
3527
 	if err == nil {
3383
 		this.ServeSuccessJSON(map[string]interface{}{
3528
 		this.ServeSuccessJSON(map[string]interface{}{
3384
 			"msg":        "1",
3529
 			"msg":        "1",
3452
 func (this *SupplyOrderApiController) ModefyReturnOrder() {
3597
 func (this *SupplyOrderApiController) ModefyReturnOrder() {
3453
 	id, _ := this.GetInt64("id")
3598
 	id, _ := this.GetInt64("id")
3454
 	err := service.ModefyReturnOrder(id)
3599
 	err := service.ModefyReturnOrder(id)
3600
+
3601
+	//获取退库单据日期
3602
+	cancel, _ := service.GetReturnOrderById(id)
3455
 	orgId := this.GetAdminUserInfo().CurrentOrgId
3603
 	orgId := this.GetAdminUserInfo().CurrentOrgId
3456
 	if err == nil {
3604
 	if err == nil {
3457
 		//获取退库单详情
3605
 		//获取退库单详情
3465
 				if item.SupplyUnit == base.MaxUnit {
3613
 				if item.SupplyUnit == base.MaxUnit {
3466
 					//退库
3614
 					//退库
3467
 					drugInfo := models.DrugWarehouseInfo{
3615
 					drugInfo := models.DrugWarehouseInfo{
3468
-						StockMaxNumber: item.Count,
3616
+						StockMaxNumber: item.SupplyCount,
3469
 					}
3617
 					}
3470
 					service.UpdateDrugWasehousring(item.ProjectId, item.SupplyWarehouseDetailInfo, drugInfo)
3618
 					service.UpdateDrugWasehousring(item.ProjectId, item.SupplyWarehouseDetailInfo, drugInfo)
3471
 				}
3619
 				}
3472
-				if item.SupplyType == base.MinUnit {
3620
+
3621
+				if item.SupplyType == base.MinUnit && base.MaxUnit != base.MinUnit {
3473
 					drugInfo := models.DrugWarehouseInfo{
3622
 					drugInfo := models.DrugWarehouseInfo{
3474
-						StockMinNumber: item.Count,
3623
+						StockMinNumber: item.SupplyCount,
3475
 					}
3624
 					}
3476
 					service.UpdateDrugWasehousringOne(item.ProjectId, item.SupplyWarehouseDetailInfo, drugInfo)
3625
 					service.UpdateDrugWasehousringOne(item.ProjectId, item.SupplyWarehouseDetailInfo, drugInfo)
3477
 				}
3626
 				}
3627
+
3478
 				//删除流水
3628
 				//删除流水
3479
 				service.DeleteDrugWarehouseOutNight(item.ProjectId, item.WarehouseCancelId)
3629
 				service.DeleteDrugWarehouseOutNight(item.ProjectId, item.WarehouseCancelId)
3630
+				//查询出库订单
3631
+				drugOut, _ := service.GetDrugWarehouseByDate(cancel.RecordDate, orgId)
3632
+
3633
+				drugOutList, _ := service.GetDrugWarehouseByIdList(drugOut.ID, orgId)
3634
+				if len(drugOutList) == 0 {
3635
+					service.UpdateDrugWarehouseById(drugOut.ID)
3636
+				}
3480
 			}
3637
 			}
3481
 			//耗材
3638
 			//耗材
3482
 			if item.IsSource == 2 {
3639
 			if item.IsSource == 2 {
3483
-
3640
+				fmt.Println("item2332322323232332", item.SupplyCount)
3484
 				//退库
3641
 				//退库
3485
 				info := models.WarehousingInfo{
3642
 				info := models.WarehousingInfo{
3486
-					StockCount: item.Count,
3643
+					StockCount: item.SupplyCount,
3487
 				}
3644
 				}
3645
+
3488
 				//更改库存
3646
 				//更改库存
3489
 				err := service.UpdateWarehousingInfoById(item.ProjectId, item.SupplyWarehouseDetailInfo, info)
3647
 				err := service.UpdateWarehousingInfoById(item.ProjectId, item.SupplyWarehouseDetailInfo, info)
3490
-				//删除出库记录
3491
-				service.DeleteGoodWarehouseOut(item.ProjectId, item.WarehouseCancelId)
3492
 				fmt.Println(err)
3648
 				fmt.Println(err)
3649
+				//删除出库记录
3650
+				service.DeleteGoodWarehouseOut(item.ProjectId, item.WarehouseCancelId, orgId)
3651
+
3652
+				//查询今日的出库单是
3653
+				out, _ := service.GetWarehouseOutByDate(cancel.RecordDate, orgId)
3654
+				warehouseOutList, _ := service.GetWarehouseOutById(out.ID, orgId)
3655
+				if len(warehouseOutList) == 0 {
3656
+					//删除出库单
3657
+					service.DeleteWarehouseOutById(out.ID)
3658
+				}
3659
+
3493
 			}
3660
 			}
3494
 		}
3661
 		}
3495
 	} else {
3662
 	} else {
3505
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
3672
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
3506
 	}
3673
 	}
3507
 }
3674
 }
3675
+
3676
+func (this *SupplyOrderApiController) GetGoodOrderDetailList() {
3677
+	id, _ := this.GetInt64("id")
3678
+	ids := this.GetString("ids")
3679
+	orgId := this.GetAdminUserInfo().CurrentOrgId
3680
+
3681
+	if len(ids) == 0 {
3682
+		out, err := service.GetGoodOrderDetail(id, orgId)
3683
+		list, _ := service.GetSupplyWarehouseOutById(id, orgId)
3684
+		for _, item := range list {
3685
+
3686
+			if item.IsSource == 1 {
3687
+				waresingList, _ := service.GetAllDrugWaresingList(item.ProjectId, orgId)
3688
+				medical, _ := service.GetBaseDrugMedical(item.ProjectId)
3689
+				item.DrugWarehouseInfo = waresingList
3690
+				item.SpBaseDrug = medical
3691
+			}
3692
+			if item.IsSource == 2 {
3693
+				waresingList, _ := service.GetAllGoodWaresingList(item.ProjectId, orgId)
3694
+
3695
+				item.GoodWarehouseInfo = waresingList
3696
+			}
3697
+		}
3698
+		drugList, _ := service.GetSupplyDrugList(orgId)
3699
+		goodList, _ := service.GetSupplyGoodList(orgId)
3700
+		supplyList, _ := service.GetSupplierList(orgId)
3701
+		if err == nil {
3702
+			this.ServeSuccessJSON(map[string]interface{}{
3703
+				"out":        out,
3704
+				"list":       list,
3705
+				"goodList":   goodList,
3706
+				"drugList":   drugList,
3707
+				"supplyList": supplyList,
3708
+			})
3709
+		} else {
3710
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
3711
+		}
3712
+	}
3713
+	if len(ids) > 0 {
3714
+		idArray := strings.Split(ids, ",")
3715
+		out, err := service.GetGoodOrderDetail(id, orgId)
3716
+		list, _ := service.GetSupplyWarehouseOutByIdOne(id, orgId, idArray)
3717
+		for _, item := range list {
3718
+			if item.IsSource == 1 {
3719
+				waresingList, _ := service.GetAllDrugWaresingList(item.ProjectId, orgId)
3720
+				medical, _ := service.GetBaseDrugMedical(item.ProjectId)
3721
+				item.DrugWarehouseInfo = waresingList
3722
+				item.SpBaseDrug = medical
3723
+			}
3724
+			if item.IsSource == 2 {
3725
+				waresingList, _ := service.GetAllGoodWaresingList(item.ProjectId, orgId)
3726
+
3727
+				item.GoodWarehouseInfo = waresingList
3728
+			}
3729
+		}
3730
+		drugList, _ := service.GetSupplyDrugList(orgId)
3731
+		goodList, _ := service.GetSupplyGoodList(orgId)
3732
+		supplyList, _ := service.GetSupplierList(orgId)
3733
+		if err == nil {
3734
+			this.ServeSuccessJSON(map[string]interface{}{
3735
+				"out":        out,
3736
+				"list":       list,
3737
+				"goodList":   goodList,
3738
+				"drugList":   drugList,
3739
+				"supplyList": supplyList,
3740
+			})
3741
+		} else {
3742
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
3743
+		}
3744
+	}
3745
+}

+ 4 - 0
models/dialysis.go View File

319
 	EstimatedFoodIntake            string  `gorm:"column:estimated_food_intake" json:"estimated_food_intake" form:"estimated_food_intake"`
319
 	EstimatedFoodIntake            string  `gorm:"column:estimated_food_intake" json:"estimated_food_intake" form:"estimated_food_intake"`
320
 	BloodPressureDuringDialysis    string  `gorm:"column:blood_pressure_during_dialysis" json:"blood_pressure_during_dialysis" form:"blood_pressure_during_dialysis"`
320
 	BloodPressureDuringDialysis    string  `gorm:"column:blood_pressure_during_dialysis" json:"blood_pressure_during_dialysis" form:"blood_pressure_during_dialysis"`
321
 	UreaBefor                      string  `gorm:"column:urea_befor" json:"urea_befor" form:"urea_befor"`
321
 	UreaBefor                      string  `gorm:"column:urea_befor" json:"urea_befor" form:"urea_befor"`
322
+	Suction                        string  `gorm:"column:suction" json:"suction" form:"suction"`
322
 }
323
 }
323
 
324
 
324
 func (PredialysisEvaluation) TableName() string {
325
 func (PredialysisEvaluation) TableName() string {
634
 	Fallrisk                        int64   `gorm:"column:fallrisk" json:"fallrisk" form:"fallrisk"`
635
 	Fallrisk                        int64   `gorm:"column:fallrisk" json:"fallrisk" form:"fallrisk"`
635
 	MachineRun                      string  `gorm:"column:machine_run" json:"machine_run" form:"machine_run"`
636
 	MachineRun                      string  `gorm:"column:machine_run" json:"machine_run" form:"machine_run"`
636
 	AfterUrea                       string  `gorm:"column:after_urea" json:"after_urea" form:"after_urea"`
637
 	AfterUrea                       string  `gorm:"column:after_urea" json:"after_urea" form:"after_urea"`
638
+	PipCoagulation                  string  `gorm:"column:pip_coagulation" json:"pip_coagulation" form:"pip_coagulation"`
637
 }
639
 }
638
 
640
 
639
 func (AssessmentAfterDislysis) TableName() string {
641
 func (AssessmentAfterDislysis) TableName() string {
743
 	UreaMonitoring              float64 `gorm:"column:urea_monitoring" json:"urea_monitoring" form:"urea_monitoring"`
745
 	UreaMonitoring              float64 `gorm:"column:urea_monitoring" json:"urea_monitoring" form:"urea_monitoring"`
744
 	BloodThickness              float64 `gorm:"column:blood_thickness" json:"blood_thickness" form:"blood_thickness"`
746
 	BloodThickness              float64 `gorm:"column:blood_thickness" json:"blood_thickness" form:"blood_thickness"`
745
 	BloodMonitor                float64 `gorm:"column:blood_monitor" json:"blood_monitor" form:"blood_monitor"`
747
 	BloodMonitor                float64 `gorm:"column:blood_monitor" json:"blood_monitor" form:"blood_monitor"`
748
+	HeparinAmount               float64 `gorm:"column:heparin_amount" json:"heparin_amount" form:"heparin_amount"`
749
+	Dehydration                 float64 `gorm:"column:dehydration" json:"dehydration" form:"dehydration"`
746
 }
750
 }
747
 
751
 
748
 func (MonitoringRecord) TableName() string {
752
 func (MonitoringRecord) TableName() string {

+ 1 - 0
models/drug_stock.go View File

154
 	AdviceId                int64   `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
154
 	AdviceId                int64   `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
155
 	SupplyCancelOutId       int64   `gorm:"column:supply_cancel_out_id" json:"supply_cancel_out_id" form:"supply_cancel_out_id"`
155
 	SupplyCancelOutId       int64   `gorm:"column:supply_cancel_out_id" json:"supply_cancel_out_id" form:"supply_cancel_out_id"`
156
 	SupplyWarehouseId       int64   `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
156
 	SupplyWarehouseId       int64   `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
157
+	IsSource                int64   `gorm:"column:is_source" json:"is_source" form:"is_source"`
157
 }
158
 }
158
 
159
 
159
 func (DrugWarehouseOutInfo) TableName() string {
160
 func (DrugWarehouseOutInfo) TableName() string {

+ 1 - 0
models/good_models.go View File

85
 	GoodSotckInfo               []*GoodSotckInfo     `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_stock_in"`
85
 	GoodSotckInfo               []*GoodSotckInfo     `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_stock_in"`
86
 	IsUser                      int64                `gorm:"column:is_user" json:"is_user" form:"is_user"`
86
 	IsUser                      int64                `gorm:"column:is_user" json:"is_user" form:"is_user"`
87
 	Number                      string               `gorm:"column:number" json:"number" form:"number"`
87
 	Number                      string               `gorm:"column:number" json:"number" form:"number"`
88
+	IsWarehouse                 int64                `gorm:"column:is_warehouse" json:"is_warehouse" form:"is_warehouse"`
88
 }
89
 }
89
 
90
 
90
 func (GoodInfo) TableName() string {
91
 func (GoodInfo) TableName() string {

+ 5 - 0
models/secondary_models.go View File

1
+package models
2
+
3
+func main() {
4
+
5
+}

+ 30 - 28
models/self_drug_models.go View File

384
 }
384
 }
385
 
385
 
386
 type XtDrugWarehouseInfo struct {
386
 type XtDrugWarehouseInfo struct {
387
-	ID                int64      `gorm:"column:id" json:"id" form:"id"`
388
-	WarehousingId     int64      `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
389
-	DrugId            int64      `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
390
-	Number            string     `gorm:"column:number" json:"number" form:"number"`
391
-	ProductDate       int64      `gorm:"column:product_date" json:"product_date" form:"product_date"`
392
-	ExpiryDate        int64      `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
393
-	WarehousingCount  int64      `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
394
-	Price             float64    `gorm:"column:price" json:"price" form:"price"`
395
-	TotalPrice        float64    `gorm:"column:total_price" json:"total_price" form:"total_price"`
396
-	Dealer            int64      `gorm:"column:dealer" json:"dealer" form:"dealer"`
397
-	Manufacturer      int64      `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
398
-	Remark            string     `gorm:"column:remark" json:"remark" form:"remark"`
399
-	Ctime             int64      `gorm:"column:ctime" json:"ctime" form:"ctime"`
400
-	Mtime             int64      `gorm:"column:mtime" json:"mtime" form:"mtime"`
401
-	Status            int64      `gorm:"column:status" json:"status" form:"status"`
402
-	OrgId             int64      `gorm:"column:org_id" json:"org_id" form:"org_id"`
403
-	IsReturn          int64      `gorm:"column:is_return" json:"is_return" form:"is_return"`
404
-	WarehousingOrder  string     `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
405
-	Type              int64      `gorm:"column:type" json:"type" form:"type"`
406
-	RetailPrice       float64    `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
407
-	RetailTotalPrice  float64    `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
408
-	StockMaxNumber    int64      `gorm:"column:stock_max_number" json:"stock_max_number"`
409
-	StockMinNumber    int64      `gorm:"column:stock_min_number" json:"stock_min_number"`
410
-	BatchNumber       string     `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
411
-	MinUnit           string     `gorm:"column:min_unit" json:"max_unit" form:"min_unit"`
412
-	MaxUnit           string     `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
413
-	WarehousingInfoId int64      `gorm:"column:warehousing_info_id" json:"warehousing_info_id" form:"warehousing_info_id"`
414
-	XtBaseDrug        XtBaseDrug `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" `
387
+	ID                        int64      `gorm:"column:id" json:"id" form:"id"`
388
+	WarehousingId             int64      `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
389
+	DrugId                    int64      `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
390
+	Number                    string     `gorm:"column:number" json:"number" form:"number"`
391
+	ProductDate               int64      `gorm:"column:product_date" json:"product_date" form:"product_date"`
392
+	ExpiryDate                int64      `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
393
+	WarehousingCount          int64      `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
394
+	Price                     float64    `gorm:"column:price" json:"price" form:"price"`
395
+	TotalPrice                float64    `gorm:"column:total_price" json:"total_price" form:"total_price"`
396
+	Dealer                    int64      `gorm:"column:dealer" json:"dealer" form:"dealer"`
397
+	Manufacturer              int64      `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
398
+	Remark                    string     `gorm:"column:remark" json:"remark" form:"remark"`
399
+	Ctime                     int64      `gorm:"column:ctime" json:"ctime" form:"ctime"`
400
+	Mtime                     int64      `gorm:"column:mtime" json:"mtime" form:"mtime"`
401
+	Status                    int64      `gorm:"column:status" json:"status" form:"status"`
402
+	OrgId                     int64      `gorm:"column:org_id" json:"org_id" form:"org_id"`
403
+	IsReturn                  int64      `gorm:"column:is_return" json:"is_return" form:"is_return"`
404
+	WarehousingOrder          string     `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
405
+	Type                      int64      `gorm:"column:type" json:"type" form:"type"`
406
+	RetailPrice               float64    `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
407
+	RetailTotalPrice          float64    `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
408
+	StockMaxNumber            int64      `gorm:"column:stock_max_number" json:"stock_max_number"`
409
+	StockMinNumber            int64      `gorm:"column:stock_min_number" json:"stock_min_number"`
410
+	BatchNumber               string     `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
411
+	MinUnit                   string     `gorm:"column:min_unit" json:"max_unit" form:"min_unit"`
412
+	MaxUnit                   string     `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
413
+	WarehousingInfoId         int64      `gorm:"column:warehousing_info_id" json:"warehousing_info_id" form:"warehousing_info_id"`
414
+	XtBaseDrug                XtBaseDrug `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" `
415
+	SupplyWarehouseId         int64      `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
416
+	SupplyWarehouseDetailInfo int64      `gorm:"column:supply_warehouse_detail_info" json:"supply_warehouse_detail_info" form:"supply_warehouse_detail_info"`
415
 }
417
 }
416
 
418
 
417
 func (XtDrugWarehouseInfo) TableName() string {
419
 func (XtDrugWarehouseInfo) TableName() string {

+ 3 - 0
models/stock_models.go View File

242
 	ProjectId               int64        `gorm:"column:project_id" json:"project_id" form:"project_id"`
242
 	ProjectId               int64        `gorm:"column:project_id" json:"project_id" form:"project_id"`
243
 	SupplyCancelOutId       int64        `gorm:"column:supply_cancel_out_id" json:"supply_cancel_out_id" form:"supply_cancel_out_id"`
243
 	SupplyCancelOutId       int64        `gorm:"column:supply_cancel_out_id" json:"supply_cancel_out_id" form:"supply_cancel_out_id"`
244
 	SupplyWarehouseId       int64        `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
244
 	SupplyWarehouseId       int64        `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
245
+	IsSource                int64        `gorm:"column:is_source" json:"is_source" form:"is_source"`
245
 }
246
 }
246
 
247
 
247
 func (WarehouseOutInfo) TableName() string {
248
 func (WarehouseOutInfo) TableName() string {
484
 	PackingUnit                 string  `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
485
 	PackingUnit                 string  `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
485
 	LicenseNumber               string  `gorm:"column:license_number" json:"license_number" form:"license_number"`
486
 	LicenseNumber               string  `gorm:"column:license_number" json:"license_number" form:"license_number"`
486
 	SocialSecurityDirectoryCode string  `gorm:"column:social_security_directory_code" json:"social_security_directory_code" form:"social_security_directory_code"`
487
 	SocialSecurityDirectoryCode string  `gorm:"column:social_security_directory_code" json:"social_security_directory_code" form:"social_security_directory_code"`
488
+	SupplyCancelOutId           int64   `gorm:"column:supply_cancel_out_id" json:"supply_cancel_out_id" form:"supply_cancel_out_id"`
489
+	SupplyWarehouseId           int64   `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
487
 }
490
 }
488
 
491
 
489
 type WarehouseOutInfoTwo struct {
492
 type WarehouseOutInfoTwo struct {

+ 92 - 77
models/supply.models.go View File

65
 }
65
 }
66
 
66
 
67
 type SpWarehouseInfo struct {
67
 type SpWarehouseInfo struct {
68
-	ID         int64 `gorm:"column:id" json:"id" form:"id"`
69
-	GoodId     int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
70
-	StockCount int64 `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
71
-	Status     int64 `gorm:"column:status" json:"status" form:"status"`
72
-	OrgId      int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
68
+	ID                        int64 `gorm:"column:id" json:"id" form:"id"`
69
+	GoodId                    int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
70
+	StockCount                int64 `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
71
+	Status                    int64 `gorm:"column:status" json:"status" form:"status"`
72
+	OrgId                     int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
73
+	SupplyWarehouseDetailInfo int64 `gorm:"column:supply_warehouse_detail_info" json:"supply_warehouse_detail_info" form:"supply_warehouse_detail_info"`
74
+	SupplyWarehouseId         int64 `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
73
 }
75
 }
74
 
76
 
75
 func (SpWarehouseInfo) TableName() string {
77
 func (SpWarehouseInfo) TableName() string {
77
 }
79
 }
78
 
80
 
79
 type SpDrugWarehouseInfo struct {
81
 type SpDrugWarehouseInfo struct {
80
-	ID             int64  `gorm:"column:id" json:"id" form:"id"`
81
-	DrugId         int64  `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
82
-	MaxUnit        string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
83
-	MinUnit        string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
84
-	StockMaxNumber int64  `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
85
-	StockMinNumber int64  `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
86
-	BatchNumber    string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
87
-	Status         int64  `gorm:"column:status" json:"status" form:"status"`
88
-	OrgId          int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
82
+	ID                        int64  `gorm:"column:id" json:"id" form:"id"`
83
+	DrugId                    int64  `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
84
+	MaxUnit                   string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
85
+	MinUnit                   string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
86
+	StockMaxNumber            int64  `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
87
+	StockMinNumber            int64  `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
88
+	BatchNumber               string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
89
+	Status                    int64  `gorm:"column:status" json:"status" form:"status"`
90
+	OrgId                     int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
91
+	SupplyWarehouseDetailInfo int64  `gorm:"column:supply_warehouse_detail_info" json:"supply_warehouse_detail_info" form:"supply_warehouse_detail_info"`
92
+	SupplyWarehouseId         int64  `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
89
 }
93
 }
90
 
94
 
91
 func (SpDrugWarehouseInfo) TableName() string {
95
 func (SpDrugWarehouseInfo) TableName() string {
194
 }
198
 }
195
 
199
 
196
 type SpSupplierWarehousingOutOrder struct {
200
 type SpSupplierWarehousingOutOrder struct {
197
-	ID                      int64   `gorm:"column:id" json:"id" form:"id"`
198
-	OrderNumber             string  `gorm:"column:order_number" json:"order_number" form:"order_number"`
199
-	ProjectId               int64   `gorm:"column:project_id" json:"project_id" form:"project_id"`
200
-	IsSource                int64   `gorm:"column:is_source" json:"is_source" form:"is_source"`
201
-	Count                   int64   `gorm:"column:count" json:"count" form:"count"`
202
-	Price                   float64 `gorm:"column:price" json:"price" form:"price"`
203
-	Amount                  float64 `gorm:"column:amount" json:"amount" form:"amount"`
204
-	Remark                  string  `gorm:"column:remark" json:"remark" form:"remark"`
205
-	IsCheck                 int64   `gorm:"column:is_check" json:"is_check" form:"is_check"`
206
-	UserOrgId               int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
207
-	Status                  int64   `gorm:"column:status" json:"status" form:"status"`
208
-	Ctime                   int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
209
-	Mtime                   int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
210
-	WarehouseOutId          int64   `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
211
-	Type                    int64   `gorm:"column:type" json:"type" form:"type"`
212
-	SupplyBatchNumber       string  `gorm:"column:supply_batch_number" json:"supply_batch_number" form:"supply_batch_number"`
213
-	SupplyProductDate       int64   `gorm:"column:supply_product_date" json:"supply_product_date" form:"supply_product_date"`
214
-	SupplyExpiryDate        int64   `gorm:"column:supply_expiry_date" json:"supply_expiry_date" form:"supply_expiry_date"`
215
-	WarehousingId           int64   `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
216
-	WarehouseInfoId         int64   `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
217
-	SupplyType              string  `gorm:"column:supply_type" json:"supply_type" form:"supply_type"`
218
-	SupplySpecificationName string  `gorm:"column:supply_specification_name" json:"supply_specification_name" form:"supply_specification_name"`
219
-	SupplyTotal             string  `gorm:"column:supply_total" json:"supply_total" form:"supply_total"`
220
-	SupplyManufacturer      string  `gorm:"column:supply_manufacturer" json:"supply_manufacturer" form:"supply_manufacturer"`
221
-	Name                    string  `gorm:"column:name" json:"name" form:"name"`
222
-	SupplyUnit              string  `gorm:"column:supply_unit" json:"supply_unit" form:"supply_unit"`
223
-	ManufacturerId          int64   `gorm:"column:manufacturer_id" json:"manufacturer_id" form:"manufacturer_id"`
224
-	SupplyLicenseNumber     string  `gorm:"column:supply_license_number" json:"supply_license_number" form:"supply_license_number"`
225
-	GoodNumber              string  `gorm:"column:good_number" json:"good_number" form:"good_number"`
226
-	MinPrice                float64 `gorm:"column:min_price" json:"min_price" form:"min_price"`
201
+	ID                      int64                  `gorm:"column:id" json:"id" form:"id"`
202
+	OrderNumber             string                 `gorm:"column:order_number" json:"order_number" form:"order_number"`
203
+	ProjectId               int64                  `gorm:"column:project_id" json:"project_id" form:"project_id"`
204
+	IsSource                int64                  `gorm:"column:is_source" json:"is_source" form:"is_source"`
205
+	Count                   int64                  `gorm:"column:count" json:"count" form:"count"`
206
+	Price                   float64                `gorm:"column:price" json:"price" form:"price"`
207
+	Amount                  float64                `gorm:"column:amount" json:"amount" form:"amount"`
208
+	Remark                  string                 `gorm:"column:remark" json:"remark" form:"remark"`
209
+	IsCheck                 int64                  `gorm:"column:is_check" json:"is_check" form:"is_check"`
210
+	UserOrgId               int64                  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
211
+	Status                  int64                  `gorm:"column:status" json:"status" form:"status"`
212
+	Ctime                   int64                  `gorm:"column:ctime" json:"ctime" form:"ctime"`
213
+	Mtime                   int64                  `gorm:"column:mtime" json:"mtime" form:"mtime"`
214
+	WarehouseOutId          int64                  `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
215
+	Type                    int64                  `gorm:"column:type" json:"type" form:"type"`
216
+	SupplyBatchNumber       string                 `gorm:"column:supply_batch_number" json:"supply_batch_number" form:"supply_batch_number"`
217
+	SupplyProductDate       int64                  `gorm:"column:supply_product_date" json:"supply_product_date" form:"supply_product_date"`
218
+	SupplyExpiryDate        int64                  `gorm:"column:supply_expiry_date" json:"supply_expiry_date" form:"supply_expiry_date"`
219
+	WarehousingId           int64                  `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
220
+	WarehouseInfoId         int64                  `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
221
+	SupplyType              string                 `gorm:"column:supply_type" json:"supply_type" form:"supply_type"`
222
+	SupplySpecificationName string                 `gorm:"column:supply_specification_name" json:"supply_specification_name" form:"supply_specification_name"`
223
+	SupplyTotal             string                 `gorm:"column:supply_total" json:"supply_total" form:"supply_total"`
224
+	SupplyManufacturer      string                 `gorm:"column:supply_manufacturer" json:"supply_manufacturer" form:"supply_manufacturer"`
225
+	Name                    string                 `gorm:"column:name" json:"name" form:"name"`
226
+	SupplyUnit              string                 `gorm:"column:supply_unit" json:"supply_unit" form:"supply_unit"`
227
+	ManufacturerId          int64                  `gorm:"column:manufacturer_id" json:"manufacturer_id" form:"manufacturer_id"`
228
+	SupplyLicenseNumber     string                 `gorm:"column:supply_license_number" json:"supply_license_number" form:"supply_license_number"`
229
+	GoodNumber              string                 `gorm:"column:good_number" json:"good_number" form:"good_number"`
230
+	MinPrice                float64                `gorm:"column:min_price" json:"min_price" form:"min_price"`
231
+	IsWarehosue             int64                  `gorm:"column:is_warehouse" json:"is_warehouse" form:"is_warehouse"`
232
+	GoodWarehouseInfo       []*SpWarehouseInfo     `gorm:"ForeignKey:ProjectId;AssociationForeignKey:GoodId" json:"good_warehouse_info"`
233
+	DrugWarehouseInfo       []*SpDrugWarehouseInfo `gorm:"ForeignKey:ProjectId;AssociationForeignKey:DrugId" json:"drug_warehouse_info"`
234
+	SpBaseDrug              XtBaseDrug             `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"drug"`
227
 }
235
 }
228
 
236
 
229
 func (SpSupplierWarehousingOutOrder) TableName() string {
237
 func (SpSupplierWarehousingOutOrder) TableName() string {
231
 }
239
 }
232
 
240
 
233
 type SpSupplierWarehouseOut struct {
241
 type SpSupplierWarehouseOut struct {
234
-	ID               int64   `gorm:"column:id" json:"id" form:"id"`
235
-	Number           string  `gorm:"column:number" json:"number" form:"number"`
236
-	UserOrgId        int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
237
-	Creater          int64   `gorm:"column:creater" json:"creater" form:"creater"`
238
-	Ctime            int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
239
-	Mtime            int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
240
-	Status           int64   `gorm:"column:status" json:"status" form:"status"`
241
-	RecordDate       int64   `gorm:"column:record_date" json:"record_date" form:"record_date"`
242
-	IsCheck          int64   `gorm:"column:is_check" json:"is_check" form:"is_check"`
243
-	WarehousingId    int64   `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
244
-	GoodNumber       string  `gorm:"column:good_number" json:"good_number" form:"good_number"`
245
-	Arrearage        float64 `gorm:"column:arrearage" json:"arrearage" form:"arrearage"`
246
-	Payment          float64 `gorm:"column:payment" json:"payment" form:"payment"`
247
-	RateOfConcession float64 `gorm:"column:rate_of_concession" json:"rate_of_concession" form:"rate_of_concession"`
248
-	DiscountAmount   float64 `gorm:"column:discount_amount" json:"discount_amount" form:"discount_amount"`
249
-	DocumentDate     int64   `gorm:"column:document_date" json:"document_date" form:"document_date"`
250
-	SupplierId       int64   `gorm:"column:supplier_id" json:"supplier_id" form:"supplier_id"`
251
-	Checker          int64   `gorm:"column:checker" json:"checker" form:"checker"`
252
-	CheckTime        int64   `gorm:"column:check_time" json:"check_time" form:"check_time"`
253
-	ReturnRemake     string  `gorm:"column:return_remake" json:"return_remake" form:"return_remake"`
242
+	ID                            int64                            `gorm:"column:id" json:"id" form:"id"`
243
+	Number                        string                           `gorm:"column:number" json:"number" form:"number"`
244
+	UserOrgId                     int64                            `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
245
+	Creater                       int64                            `gorm:"column:creater" json:"creater" form:"creater"`
246
+	Ctime                         int64                            `gorm:"column:ctime" json:"ctime" form:"ctime"`
247
+	Mtime                         int64                            `gorm:"column:mtime" json:"mtime" form:"mtime"`
248
+	Status                        int64                            `gorm:"column:status" json:"status" form:"status"`
249
+	RecordDate                    int64                            `gorm:"column:record_date" json:"record_date" form:"record_date"`
250
+	IsCheck                       int64                            `gorm:"column:is_check" json:"is_check" form:"is_check"`
251
+	WarehousingId                 int64                            `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
252
+	GoodNumber                    string                           `gorm:"column:good_number" json:"good_number" form:"good_number"`
253
+	Arrearage                     float64                          `gorm:"column:arrearage" json:"arrearage" form:"arrearage"`
254
+	Payment                       float64                          `gorm:"column:payment" json:"payment" form:"payment"`
255
+	RateOfConcession              float64                          `gorm:"column:rate_of_concession" json:"rate_of_concession" form:"rate_of_concession"`
256
+	DiscountAmount                float64                          `gorm:"column:discount_amount" json:"discount_amount" form:"discount_amount"`
257
+	DocumentDate                  int64                            `gorm:"column:document_date" json:"document_date" form:"document_date"`
258
+	SupplierId                    int64                            `gorm:"column:supplier_id" json:"supplier_id" form:"supplier_id"`
259
+	Checker                       int64                            `gorm:"column:checker" json:"checker" form:"checker"`
260
+	CheckTime                     int64                            `gorm:"column:check_time" json:"check_time" form:"check_time"`
261
+	ReturnRemake                  string                           `gorm:"column:return_remake" json:"return_remake" form:"return_remake"`
262
+	SpSupplierWarehousingOutOrder []*SpSupplierWarehousingOutOrder `gorm:"ForeignKey:warehouse_out_id;AssociationForeignKey:ID" json:"order"`
254
 }
263
 }
255
 
264
 
256
 func (SpSupplierWarehouseOut) TableName() string {
265
 func (SpSupplierWarehouseOut) TableName() string {
286
 }
295
 }
287
 
296
 
288
 type VSpSupplierWarehousingOutOrder struct {
297
 type VSpSupplierWarehousingOutOrder struct {
289
-	ID          int64  `gorm:"column:id" json:"id" form:"id"`
290
-	OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
291
-	ProjectId   int64  `gorm:"column:project_id" json:"project_id" form:"project_id"`
292
-	Count       int64  `gorm:"column:count" json:"count" form:"count"`
293
-	Status      int64  `gorm:"column:status" json:"status" form:"status"`
294
-	SupplyUnit  string `gorm:"column:supply_unit" json:"supply_unit" form:"supply_unit"`
295
-	IsSource    int64  `gorm:"column:is_source" json:"is_source" form:"is_source"`
298
+	ID             int64  `gorm:"column:id" json:"id" form:"id"`
299
+	OrderNumber    string `gorm:"column:order_number" json:"order_number" form:"order_number"`
300
+	ProjectId      int64  `gorm:"column:project_id" json:"project_id" form:"project_id"`
301
+	Count          int64  `gorm:"column:count" json:"count" form:"count"`
302
+	Status         int64  `gorm:"column:status" json:"status" form:"status"`
303
+	SupplyUnit     string `gorm:"column:supply_unit" json:"supply_unit" form:"supply_unit"`
304
+	IsSource       int64  `gorm:"column:is_source" json:"is_source" form:"is_source"`
305
+	WarehousingId  int64  `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
306
+	IsWarehosue    int64  `gorm:"column:is_warehosue" json:"is_warehosue" form:"is_warehosue"`
307
+	WarehouseOutId int64  `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
296
 }
308
 }
297
 
309
 
298
 func (VSpSupplierWarehousingOutOrder) TableName() string {
310
 func (VSpSupplierWarehousingOutOrder) TableName() string {
343
 	ProjectId                 int64   `gorm:"column:project_id" json:"project_id" form:"project_id"`
355
 	ProjectId                 int64   `gorm:"column:project_id" json:"project_id" form:"project_id"`
344
 	GoodNumber                string  `gorm:"column:good_number" json:"good_number" form:"good_number"`
356
 	GoodNumber                string  `gorm:"column:good_number" json:"good_number" form:"good_number"`
345
 	IsSource                  int64   `gorm:"column:is_source" json:"is_source" form:"is_source"`
357
 	IsSource                  int64   `gorm:"column:is_source" json:"is_source" form:"is_source"`
346
-	Count                     int64   `gorm:"column:count" json:"count" form:"count"`
358
+	Count                     string  `gorm:"column:count" json:"count" form:"count"`
347
 	Price                     float64 `gorm:"column:price" json:"price" form:"price"`
359
 	Price                     float64 `gorm:"column:price" json:"price" form:"price"`
348
 	Remark                    string  `gorm:"column:remark" json:"remark" form:"remark"`
360
 	Remark                    string  `gorm:"column:remark" json:"remark" form:"remark"`
349
 	RateOfConcession          float64 `gorm:"column:rate_of_concession" json:"rate_of_concession" form:"rate_of_concession"`
361
 	RateOfConcession          float64 `gorm:"column:rate_of_concession" json:"rate_of_concession" form:"rate_of_concession"`
368
 	SupplyExpiryDate          int64   `gorm:"column:supply_expiry_date" json:"supply_expiry_date" form:"supply_expiry_date"`
380
 	SupplyExpiryDate          int64   `gorm:"column:supply_expiry_date" json:"supply_expiry_date" form:"supply_expiry_date"`
369
 	WarehousingId             int64   `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
381
 	WarehousingId             int64   `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
370
 	WarehouseInfoId           int64   `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
382
 	WarehouseInfoId           int64   `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
371
-	SourceCount               int64   `gorm:"column:source_count" json:"source_count" form:"source_count"`
383
+	SourceCount               string  `gorm:"column:source_count" json:"source_count" form:"source_count"`
372
 	SupplyWarehouseDetailInfo int64   `gorm:"column:supply_warehouse_detail_info" json:"supply_warehouse_detail_info" form:"supply_warehouse_detail_info"`
384
 	SupplyWarehouseDetailInfo int64   `gorm:"column:supply_warehouse_detail_info" json:"supply_warehouse_detail_info" form:"supply_warehouse_detail_info"`
385
+	SupplyCount               int64   `gorm:"column:supply_count" json:"supply_count" form:"supply_count"`
386
+	DepositRate               float64 `gorm:"column:deposit_rate" json:"deposit_rate" form:"deposit_rate"`
373
 }
387
 }
374
 
388
 
375
 func (SpSupplierWarehousingCancelOrder) TableName() string {
389
 func (SpSupplierWarehousingCancelOrder) TableName() string {
416
 }
430
 }
417
 
431
 
418
 type VmSpSupplierWarehousingCancelOrder struct {
432
 type VmSpSupplierWarehousingCancelOrder struct {
419
-	ProjectId  int64  `gorm:"column:project_id" json:"project_id" form:"project_id"`
420
-	IsSource   int64  `gorm:"column:is_source" json:"is_source" form:"is_source"`
421
-	Count      int64  `gorm:"column:count" json:"count" form:"count"`
422
-	SupplyUnit string `gorm:"column:supply_unit" json:"supply_unit" form:"supply_unit"`
433
+	ProjectId   int64  `gorm:"column:project_id" json:"project_id" form:"project_id"`
434
+	IsSource    int64  `gorm:"column:is_source" json:"is_source" form:"is_source"`
435
+	Count       string `gorm:"column:count" json:"count" form:"count"`
436
+	SupplyUnit  string `gorm:"column:supply_unit" json:"supply_unit" form:"supply_unit"`
437
+	SupplyCount int64  `gorm:"column:supply_count" json:"supply_count" form:"supply_count"`
423
 }
438
 }
424
 
439
 
425
 func (VmSpSupplierWarehousingCancelOrder) TableName() string {
440
 func (VmSpSupplierWarehousingCancelOrder) TableName() string {

+ 1 - 0
routers/router.go View File

78
 	controllers.GdybRegistRouters()
78
 	controllers.GdybRegistRouters()
79
 
79
 
80
 	controllers.SupplyOrderApiRegistRouters()
80
 	controllers.SupplyOrderApiRegistRouters()
81
+	controllers.SecondaryOrderApiRegistRouters()
81
 }
82
 }

+ 25 - 5
service/gobal_config_service.go View File

163
 	return
163
 	return
164
 }
164
 }
165
 
165
 
166
-func GetPrint(ids []int64, orgid int64) (doctor []*models.DoctorAdvice, err error) {
167
-
166
+func GetPrint(ids []int64, orgid int64, advicetype int64, stoptype int64) (doctor []*models.DoctorAdvice, err error) {
167
+	db := XTReadDB().Model(&doctor).Where("status =1")
168
 	if len(ids) == 1 {
168
 	if len(ids) == 1 {
169
-		err = XTReadDB().Model(&doctor).Where("groupno = ? and user_org_id = ? and status = 1", ids[0], orgid).Find(&doctor).Error
169
+
170
+		if orgid > 0 {
171
+			db = db.Where("user_org_id = ?", orgid)
172
+		}
173
+		if advicetype > 0 {
174
+			db = db.Where("advice_type = ?", advicetype)
175
+		}
176
+		if stoptype > 0 {
177
+			db = db.Where("stop_state = ?", stoptype)
178
+		}
179
+
180
+		err = db.Where("groupno = ?", ids[0]).Find(&doctor).Error
170
 	} else {
181
 	} else {
171
-		err = XTReadDB().Model(&doctor).Where("groupno IN(?) and user_org_id = ? and status = 1", ids, orgid).Find(&doctor).Error
182
+		if orgid > 0 {
183
+			db = db.Where("user_org_id = ?", orgid)
184
+		}
185
+		if advicetype > 0 {
186
+			db = db.Where("advice_type = ?", advicetype)
187
+		}
188
+		if stoptype > 0 {
189
+			db = db.Where("stop_state = ?", stoptype)
190
+		}
191
+		err = db.Where("groupno IN(?)", ids).Find(&doctor).Error
172
 	}
192
 	}
173
 
193
 
174
 	return doctor, err
194
 	return doctor, err
695
 
715
 
696
 func GetBatchOrderDetail(drugid int64, orgid int64, page int64, limit int64) (drug []*models.DrugWarehouseInfo, total int64, err error) {
716
 func GetBatchOrderDetail(drugid int64, orgid int64, page int64, limit int64) (drug []*models.DrugWarehouseInfo, total int64, err error) {
697
 	offset := (page - 1) * limit
717
 	offset := (page - 1) * limit
698
-	err = XTReadDB().Model(&drug).Where("drug_id = ? and org_id = ?", drugid, orgid).Count(&total).Offset(offset).Limit(limit).Find(&drug).Error
718
+	err = XTReadDB().Model(&drug).Where("drug_id = ? and org_id = ? and status = 1", drugid, orgid).Count(&total).Offset(offset).Limit(limit).Find(&drug).Error
699
 	return drug, total, err
719
 	return drug, total, err
700
 }
720
 }
701
 
721
 

+ 1 - 1
service/mobile_dialysis_service.go View File

3433
 
3433
 
3434
 func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
3434
 func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
3435
 	err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
3435
 	err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
3436
-		return db.Preload("GoodsType", "status = 1").Where("status = 1 and is_user = 2")
3436
+		return db.Preload("GoodsType", "status = 1").Where("status = 1 and is_warehouse = 1")
3437
 	}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND type = 3", org_id, record_date, patient_id).Find(&project).Error
3437
 	}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND type = 3", org_id, record_date, patient_id).Find(&project).Error
3438
 
3438
 
3439
 	return
3439
 	return

+ 5 - 0
service/secondary_service.go View File

1
+package service
2
+
3
+func main() {
4
+
5
+}

+ 16 - 3
service/stock_service.go View File

196
 }
196
 }
197
 
197
 
198
 func AddSigleGoodInfo(goodInfo *models.GoodInfo) (error, *models.GoodInfo) {
198
 func AddSigleGoodInfo(goodInfo *models.GoodInfo) (error, *models.GoodInfo) {
199
-	fmt.Println("goodino232323232323232323", goodInfo.IsUse)
200
 	err := writeDb.Create(&goodInfo).Error
199
 	err := writeDb.Create(&goodInfo).Error
201
 	return err, goodInfo
200
 	return err, goodInfo
202
 
201
 
251
 		"provinces_code":                 goodInfo.ProvincesCode,
250
 		"provinces_code":                 goodInfo.ProvincesCode,
252
 		"is_user":                        goodInfo.IsUser,
251
 		"is_user":                        goodInfo.IsUser,
253
 		"number":                         goodInfo.Number,
252
 		"number":                         goodInfo.Number,
253
+		"is_warehouse":                   goodInfo.IsWarehouse,
254
 	}).Error
254
 	}).Error
255
 
255
 
256
 	writeDb.Model(&models.WarehousingInfo{}).Where("good_id = ? AND org_id = ?", goodInfo.ID, goodInfo.OrgId).Updates(map[string]interface{}{"good_type_id": goodInfo.GoodTypeId})
256
 	writeDb.Model(&models.WarehousingInfo{}).Where("good_id = ? AND org_id = ?", goodInfo.ID, goodInfo.OrgId).Updates(map[string]interface{}{"good_type_id": goodInfo.GoodTypeId})
364
 }
364
 }
365
 
365
 
366
 func FindAllGoodInfo(org_id int64) (goodInfo []*models.GoodInfo, err error) {
366
 func FindAllGoodInfo(org_id int64) (goodInfo []*models.GoodInfo, err error) {
367
-	err = XTReadDB().Model(&models.GoodInfo{}).Where("org_id = ? AND status = 1 and is_user = 2", org_id).Find(&goodInfo).Error
367
+	err = XTReadDB().Model(&models.GoodInfo{}).Where("org_id = ? AND status = 1 and is_warehouse = 1", org_id).Find(&goodInfo).Error
368
 	return goodInfo, err
368
 	return goodInfo, err
369
 }
369
 }
370
 
370
 
772
 	return info, err
772
 	return info, err
773
 }
773
 }
774
 
774
 
775
+func FindLastDrugWarehousingInfoByIDSix(drug_id int64, warehouse_out_id int64, is_source int64) (info models.XtDrugWarehouseInfo, err error) {
776
+	if is_source == 1 {
777
+		err = readDb.Model(&models.XtDrugWarehouseInfo{}).Where("drug_id = ? AND status = 1 AND (stock_max_number > 0 or stock_min_number > 0) and supply_warehouse_id = ? ", drug_id, warehouse_out_id).Order("ctime").First(&info).Error
778
+	}
779
+
780
+	if is_source == 2 || is_source == 0 {
781
+		err = readDb.Model(&models.XtDrugWarehouseInfo{}).Where("drug_id = ? AND status = 1 AND (stock_max_number > 0 or stock_min_number > 0)", drug_id).Order("ctime").First(&info).Error
782
+	}
783
+	return info, err
784
+}
785
+
775
 // 出库时先进先出,找出最先入库的批次
786
 // 出库时先进先出,找出最先入库的批次
776
 func FindLastWarehousingInfoByID(drug_id int64) (info models.WarehousingInfo, err error) {
787
 func FindLastWarehousingInfoByID(drug_id int64) (info models.WarehousingInfo, err error) {
777
 	err = readDb.Model(&models.WarehousingInfo{}).Where("drup_id = ? AND status = 1 AND (stock_max_number > 0 or stock_min_number > 0) ", drug_id).Order("ctime").First(&info).Error
788
 	err = readDb.Model(&models.WarehousingInfo{}).Where("drup_id = ? AND status = 1 AND (stock_max_number > 0 or stock_min_number > 0) ", drug_id).Order("ctime").First(&info).Error
1595
 	BatchNumber             string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
1606
 	BatchNumber             string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
1596
 	Drug                    *Drug   `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
1607
 	Drug                    *Drug   `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
1597
 	WarehouseInfoId         int64   `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
1608
 	WarehouseInfoId         int64   `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
1609
+	SupplyCancelOutId       int64   `gorm:"column:supply_cancel_out_id" json:"supply_cancel_out_id" form:"supply_cancel_out_id"`
1610
+	SupplyWarehouseId       int64   `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
1598
 }
1611
 }
1599
 
1612
 
1600
 func (DrugWarehouseOutInfo) TableName() string {
1613
 func (DrugWarehouseOutInfo) TableName() string {
3877
 	if orgid > 0 {
3890
 	if orgid > 0 {
3878
 		db = db.Where("x.org_id = ?", orgid)
3891
 		db = db.Where("x.org_id = ?", orgid)
3879
 	}
3892
 	}
3880
-	err = db.Select("x.id,x.warehouse_out_id,x.warehouse_info_id,x.good_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.number,x.remark,x.license_number,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.min_unit").Joins("left join xt_good_information as t on t.id=x.good_id").Group("x.good_id,x.warehouse_info_id").Order("x.ctime desc").Scan(&out).Error
3893
+	err = db.Select("x.id,x.warehouse_out_id,x.warehouse_info_id,x.good_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.number,x.remark,x.license_number,x.supply_cancel_out_id,x.supply_warehouse_id,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.min_unit").Joins("left join xt_good_information as t on t.id=x.good_id").Group("x.good_id,x.warehouse_info_id").Order("x.ctime desc").Scan(&out).Error
3881
 	return out, err
3894
 	return out, err
3882
 }
3895
 }
3883
 
3896
 

+ 171 - 30
service/supply_service.go View File

412
 	if orgid > 0 {
412
 	if orgid > 0 {
413
 		db = db.Where("sgj_xt.xt_supplier_warehouse_info.user_org_id = ?", orgid)
413
 		db = db.Where("sgj_xt.xt_supplier_warehouse_info.user_org_id = ?", orgid)
414
 	}
414
 	}
415
-	err = db.Count(&total).Offset(offset).Limit(limit).Preload("SupplierWarehousingInfoOrder", "status= 1 and user_org_id = ?", orgid).Preload("SpSupplierWarehouseOut", "status = 1 and user_org_id =?", orgid).Order("ctime desc").Find(&info).Error
415
+	err = db.Count(&total).Offset(offset).Limit(limit).Preload("SupplierWarehousingInfoOrder", "status= 1 and user_org_id = ?", orgid).Preload("SpSupplierWarehouseOut", func(db *gorm.DB) *gorm.DB {
416
+		return db.Where("status = 1").Preload("SpSupplierWarehousingOutOrder", "status= 1 and user_org_id = ?", orgid)
417
+	}).Order("ctime desc").Find(&info).Error
416
 	return info, total, err
418
 	return info, total, err
417
 }
419
 }
418
 
420
 
545
 }
547
 }
546
 
548
 
547
 func GetAllGoodOrderById(id int64, orgid int64) (order []*models.VSpSupplierWarehousingOutOrder, err error) {
549
 func GetAllGoodOrderById(id int64, orgid int64) (order []*models.VSpSupplierWarehousingOutOrder, err error) {
550
+	db := XTReadDB().Table("xt_supplier_warehousing_out_order as o").Where("o.status = 1")
551
+	if id > 0 {
552
+		db = db.Where("o.warehouse_out_id = ?", id)
553
+	}
554
+	if orgid > 0 {
555
+		db = db.Where("o.user_org_id =? and o.is_warehouse= 1", orgid)
556
+	}
557
+	err = db.Select("o.id,o.order_number,o.project_id,o.count as count,o.supply_unit,o.is_source,o.warehousing_id,o.warehouse_out_id").Find(&order).Error
558
+	return order, err
559
+}
560
+
561
+func GetAllGoodOrderByIdSix(id int64, orgid int64) (order []*models.VSpSupplierWarehousingOutOrder, err error) {
548
 	db := XTReadDB().Table("xt_supplier_warehousing_out_order as o").Where("o.status = 1")
562
 	db := XTReadDB().Table("xt_supplier_warehousing_out_order as o").Where("o.status = 1")
549
 	if id > 0 {
563
 	if id > 0 {
550
 		db = db.Where("o.warehousing_id = ?", id)
564
 		db = db.Where("o.warehousing_id = ?", id)
551
 	}
565
 	}
552
 	if orgid > 0 {
566
 	if orgid > 0 {
553
-		db = db.Where("o.user_org_id =?", orgid)
567
+		db = db.Where("o.user_org_id =? and o.is_warehouse= 1", orgid)
554
 	}
568
 	}
555
 	err = db.Select("o.id,o.order_number,o.project_id,o.count as count,o.supply_unit,o.is_source").Find(&order).Error
569
 	err = db.Select("o.id,o.order_number,o.project_id,o.count as count,o.supply_unit,o.is_source").Find(&order).Error
556
 	return order, err
570
 	return order, err
558
 
572
 
559
 func GetAllGoodOrderByIdTwo(id int64, orgid int64) (order []*models.SpSupplierWarehousingOutOrder, err error) {
573
 func GetAllGoodOrderByIdTwo(id int64, orgid int64) (order []*models.SpSupplierWarehousingOutOrder, err error) {
560
 
574
 
561
-	err = XTReadDB().Where("warehousing_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&order).Error
575
+	err = XTReadDB().Where("warehouse_out_id = ? and user_org_id = ? and status = 1 and is_warehouse = 2", id, orgid).Find(&order).Error
562
 	return order, err
576
 	return order, err
563
 }
577
 }
564
 
578
 
655
 	return cancel, err
669
 	return cancel, err
656
 }
670
 }
657
 
671
 
658
-func GetReturnCancelOrderList(id int64, orgid int64) (order models.SpSupplierWarehousingCancelOrder, err error) {
672
+func GetReturnCancelOrderList(id int64, orgid int64) (order []*models.SpSupplierWarehousingCancelOrder, err error) {
659
 
673
 
660
 	err = XTReadDB().Where("warehouse_cancel_id = ? and user_org_id =? and status = 1", id, orgid).Find(&order).Error
674
 	err = XTReadDB().Where("warehouse_cancel_id = ? and user_org_id =? and status = 1", id, orgid).Find(&order).Error
661
 	return order, err
675
 	return order, err
715
 
729
 
716
 func UpdateWarehouseCancelOrder(order *models.SpSupplierWarehousingCancelOrder) error {
730
 func UpdateWarehouseCancelOrder(order *models.SpSupplierWarehousingCancelOrder) error {
717
 
731
 
718
-	err = XTWriteDB().Model(&order).Where("id = ? and status = 1", order.ID).Updates(map[string]interface{}{"manufacturer_id": order.ManufacturerId, "order_number": order.OrderNumber, "project_id": order.ProjectId, "is_source": order.IsSource, "count": order.Count, "price": order.Price, "remark": order.Remark, "rate_of_concession": order.RateOfConcession, "discount_amount": order.DiscountAmount, "type": order.Type, "supply_specification_name": order.SupplySpecificationName, "supply_type": order.SupplyType, "supply_total": order.SupplyTotal, "supply_manufacturer": order.SupplyManufacturer, "name": order.Name, "supply_unit": order.SupplyUnit, "supply_license_number": order.SupplyLicenseNumber}).Error
732
+	err = XTWriteDB().Model(&order).Where("id = ? and status = 1", order.ID).Updates(map[string]interface{}{"manufacturer_id": order.ManufacturerId, "order_number": order.OrderNumber, "project_id": order.ProjectId, "is_source": order.IsSource, "count": order.Count, "price": order.Price, "remark": order.Remark, "rate_of_concession": order.RateOfConcession, "discount_amount": order.DiscountAmount, "supply_specification_name": order.SupplySpecificationName, "supply_type": order.SupplyType, "supply_total": order.SupplyTotal, "supply_manufacturer": order.SupplyManufacturer, "name": order.Name, "supply_unit": order.SupplyUnit, "supply_license_number": order.SupplyLicenseNumber, "supply_count": order.SupplyCount, "deposit_rate": order.DepositRate}).Error
719
 	return err
733
 	return err
720
 }
734
 }
721
 
735
 
765
 func UpdateGoodSupplyFlow(id int64, orgid int64) error {
779
 func UpdateGoodSupplyFlow(id int64, orgid int64) error {
766
 
780
 
767
 	err := XTWriteDB().Model(&models.WarehousingInfo{}).Where("supply_warehouse_id = ? and org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0}).Error
781
 	err := XTWriteDB().Model(&models.WarehousingInfo{}).Where("supply_warehouse_id = ? and org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0}).Error
782
+	err = XTWriteDB().Model(&models.VmStockFlow{}).Where("supply_warehouse_id =? and user_org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0}).Error
768
 	return err
783
 	return err
769
 }
784
 }
770
 
785
 
906
 func GetlastWarehouseOutById(user_org_id int64, record_date int64) (models.WarehouseOut, error) {
921
 func GetlastWarehouseOutById(user_org_id int64, record_date int64) (models.WarehouseOut, error) {
907
 
922
 
908
 	out := models.WarehouseOut{}
923
 	out := models.WarehouseOut{}
909
-	err := XTReadDB().Where("org_id = ? and warehouse_out_time = ? and status = 1", user_org_id, record_date).Find(&out).Error
924
+	err := XTReadDB().Where("org_id = ? and warehouse_out_time = ? and is_sys = 0 and status = 1", user_org_id, record_date).Find(&out).Error
910
 	return out, err
925
 	return out, err
911
 }
926
 }
912
 
927
 
914
 
929
 
915
 	out := models.DrugWarehouseOut{}
930
 	out := models.DrugWarehouseOut{}
916
 	var err error
931
 	var err error
917
-	err = XTReadDB().Where("org_id = ? and warehouse_out_time = ?", orgid, record_date).Find(&out).Error
932
+	err = XTReadDB().Where("org_id = ? and warehouse_out_time = ? and status =1 and is_sys = 0", orgid, record_date).Find(&out).Error
918
 	if err == gorm.ErrRecordNotFound {
933
 	if err == gorm.ErrRecordNotFound {
919
 		return nil, err
934
 		return nil, err
920
 	}
935
 	}
927
 func GetLastDrugWarehouseById(orgid int64, record_date int64) (models.DrugWarehouseOut, error) {
942
 func GetLastDrugWarehouseById(orgid int64, record_date int64) (models.DrugWarehouseOut, error) {
928
 
943
 
929
 	out := models.DrugWarehouseOut{}
944
 	out := models.DrugWarehouseOut{}
930
-	err := XTReadDB().Where("org_id = ? and warehouse_out_time =? and status = 1", orgid, record_date).Find(&out).Error
945
+	err := XTReadDB().Where("org_id = ? and warehouse_out_time =? and status = 1 and is_sys =0 ", orgid, record_date).Last(&out).Error
931
 	return out, err
946
 	return out, err
932
 }
947
 }
933
 
948
 
958
 
973
 
959
 func UpdateWarehousingInfoById(goodid int64, supply_warehouse_id int64, info models.WarehousingInfo) error {
974
 func UpdateWarehousingInfoById(goodid int64, supply_warehouse_id int64, info models.WarehousingInfo) error {
960
 
975
 
961
-	err := XTWriteDB().Model(&info).Where("good_id = ? and supply_warehouse_detail_info = ? and status = 1", goodid, supply_warehouse_id).UpdateColumn("stock_count", gorm.Expr("stock_count - ?", info.StockCount)).Error
976
+	err := XTWriteDB().Model(&info).Where("good_id = ? and supply_warehouse_detail_info = ? and status = 1", goodid, supply_warehouse_id).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", info.StockCount)).Error
962
 	return err
977
 	return err
963
 }
978
 }
964
 
979
 
965
-func DeleteGoodWarehouseOut(goodid int64, supply_warehouse_id int64) error {
980
+func DeleteGoodWarehouseOut(goodid int64, supply_warehouse_id int64, orgid int64) error {
966
 
981
 
967
-	err := XTWriteDB().Model(&models.WarehouseOutInfo{}).Where("good_id = ? and supply_cancel_out_id = ? and status = 1", goodid, supply_warehouse_id).Updates(map[string]interface{}{"status": 0}).Error
982
+	err := XTWriteDB().Model(&models.WarehouseOutInfo{}).Where("good_id = ? and supply_cancel_out_id = ? and status = 1 and org_id = ?", goodid, supply_warehouse_id, orgid).Updates(map[string]interface{}{"status": 0}).Error
968
 
983
 
969
-	err = XTWriteDB().Model(&models.VmStockFlow{}).Where("good_id = ? and supply_cancel_out_id = ? and status = 1", goodid, supply_warehouse_id).Updates(map[string]interface{}{"status": 0}).Error
984
+	err = XTWriteDB().Model(&models.VmStockFlow{}).Where("good_id = ? and supply_cancel_out_id = ? and status = 1 and user_org_id =?", goodid, supply_warehouse_id, orgid).Updates(map[string]interface{}{"status": 0}).Error
970
 
985
 
971
 	return err
986
 	return err
972
 }
987
 }
973
 func UpdateDrugWasehousring(goodid int64, supply_warehouse_id int64, info models.DrugWarehouseInfo) error {
988
 func UpdateDrugWasehousring(goodid int64, supply_warehouse_id int64, info models.DrugWarehouseInfo) error {
974
 
989
 
975
-	err := XTWriteDB().Model(&info).Where("good_id = ? and supply_cancel_out_id = ? and status = 1", goodid, supply_warehouse_id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number - ?", info.StockMaxNumber)).Error
990
+	err := XTWriteDB().Model(&info).Where("drug_id = ? and supply_warehouse_detail_info = ? and status = 1", goodid, supply_warehouse_id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", info.StockMaxNumber)).Error
976
 	return err
991
 	return err
977
 }
992
 }
978
 
993
 
979
 func UpdateDrugWasehousringOne(goodid int64, supply_warehouse_id int64, info models.DrugWarehouseInfo) error {
994
 func UpdateDrugWasehousringOne(goodid int64, supply_warehouse_id int64, info models.DrugWarehouseInfo) error {
980
 
995
 
981
-	err := XTWriteDB().Model(&info).Where("good_id = ? and supply_cancel_out_id = ? and status = 1", goodid, supply_warehouse_id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number - ?", info.StockMinNumber)).Error
996
+	err := XTWriteDB().Model(&info).Where("drug_id = ? and supply_warehouse_detail_info = ? and status = 1", goodid, supply_warehouse_id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", info.StockMinNumber)).Error
982
 	return err
997
 	return err
983
 }
998
 }
984
 
999
 
985
 func DeleteDrugWarehouseOutNight(goodid int64, supply_warehouse_id int64) error {
1000
 func DeleteDrugWarehouseOutNight(goodid int64, supply_warehouse_id int64) error {
986
 
1001
 
987
-	err := XTWriteDB().Model(&models.DrugWarehouseOutInfo{}).Where("good_id = ? and supply_cancel_out_id = ? and status = 1", goodid, supply_warehouse_id).Updates(map[string]interface{}{"status": 0}).Error
1002
+	err := XTWriteDB().Model(&models.DrugWarehouseOutInfo{}).Where("drug_id = ? and supply_cancel_out_id = ? and status = 1", goodid, supply_warehouse_id).Updates(map[string]interface{}{"status": 0}).Error
988
 
1003
 
989
-	err = XTWriteDB().Model(&models.DrugFlow{}).Where("good_id = ? and supply_cancel_out_id = ? and status = 1", goodid, supply_warehouse_id).Updates(map[string]interface{}{"status": 0}).Error
1004
+	err = XTWriteDB().Model(&models.DrugFlow{}).Where("drug_id = ? and supply_cancel_out_id = ? and status = 1", goodid, supply_warehouse_id).Updates(map[string]interface{}{"status": 0}).Error
990
 
1005
 
991
 	return err
1006
 	return err
992
 }
1007
 }
1011
 	return err
1026
 	return err
1012
 }
1027
 }
1013
 
1028
 
1014
-func FindWarehousingInfoTwenTy(goodId int64, supply_warehouse_detail_info int64) (models.WarehousingInfo, error) {
1029
+func FindWarehousingInfoTwenTy(goodId int64, supply_warehouse_detail_info int64, source int64) (models.WarehousingInfo, error) {
1030
+	fmt.Println("source232232332232323232323", source)
1015
 	info := models.WarehousingInfo{}
1031
 	info := models.WarehousingInfo{}
1016
-	err := XTReadDB().Select(" good_id,sum(stock_count) as stock_count").Where("good_id = ? and status = 1 and supply_warehouse_detail_info =?", goodId, supply_warehouse_detail_info).Find(&info).Error
1032
+	var err error
1033
+	if source == 1 {
1034
+		err = XTReadDB().Select(" good_id,sum(stock_count) as stock_count").Where("good_id = ? and status = 1 and supply_warehouse_detail_info =?", goodId, supply_warehouse_detail_info).Find(&info).Error
1035
+
1036
+	}
1037
+	if source == 2 {
1038
+		err = XTReadDB().Select(" good_id,sum(stock_count) as stock_count").Where("good_id = ? and status = 1", goodId).Find(&info).Error
1039
+
1040
+	}
1017
 	return info, err
1041
 	return info, err
1018
 }
1042
 }
1019
 
1043
 
1020
-func GetDrugTotalCountTwenTy(drugid int64, supply_warehouse_detail_info int64) (list []*models.VmDrugWarehouseInfo, err error) {
1044
+func GetDrugTotalCountTwenTy(drugid int64, supply_warehouse_detail_info int64, source int64) (list []*models.VmDrugWarehouseInfo, err error) {
1021
 
1045
 
1022
-	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
1023
-	table := XTReadDB().Table("xt_base_drug as d").Where("d.status = 1")
1024
-	fmt.Println(table)
1025
-	if drugid > 0 {
1026
-		db = db.Where("x.drug_id = ?", drugid)
1027
-	}
1028
-	if supply_warehouse_detail_info > 0 {
1029
-		db = db.Where("x.supply_warehouse_detail_info = ?", supply_warehouse_detail_info)
1046
+	if source == 1 {
1047
+		db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
1048
+		table := XTReadDB().Table("xt_base_drug as d").Where("d.status = 1")
1049
+		fmt.Println(table)
1050
+		if drugid > 0 {
1051
+			db = db.Where("x.drug_id = ?", drugid)
1052
+		}
1053
+		if supply_warehouse_detail_info > 0 {
1054
+			db = db.Where("x.supply_warehouse_detail_info = ?", supply_warehouse_detail_info)
1055
+		}
1056
+		err = db.Select("x.drug_id,x.stock_max_number,x.stock_min_number,d.min_number,d.max_unit,d.min_unit,x.max_unit as count_unit,x.supply_warehouse_detail_info").Joins("left join xt_base_drug as d on d.id = x.drug_id").Scan(&list).Error
1030
 	}
1057
 	}
1031
-	err = db.Select("x.drug_id,x.stock_max_number,x.stock_min_number,d.min_number").Joins("left join xt_base_drug as d on d.id = x.drug_id").Scan(&list).Error
1032
 
1058
 
1059
+	if source == 2 {
1060
+		db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
1061
+		table := XTReadDB().Table("xt_base_drug as d").Where("d.status = 1")
1062
+		fmt.Println(table)
1063
+		if drugid > 0 {
1064
+			db = db.Where("x.drug_id = ?", drugid)
1065
+		}
1066
+		err = db.Select("x.drug_id,x.stock_max_number,x.stock_min_number,d.min_number,d.max_unit,d.min_unit,x.max_unit as count_unit,x.supply_warehouse_detail_info").Joins("left join xt_base_drug as d on d.id = x.drug_id").Scan(&list).Error
1067
+
1068
+	}
1033
 	return list, err
1069
 	return list, err
1034
 }
1070
 }
1035
 
1071
 
1047
 	return &out, nil
1083
 	return &out, nil
1048
 }
1084
 }
1049
 
1085
 
1050
-func ModfySupplyCancel(id int64, orgid int64) error {
1086
+func ModfySupplyCancel(id int64, orgid int64, project_id int64) error {
1051
 
1087
 
1052
 	err := XTWriteDB().Model(models.SpSupplierWarehouseCancel{}).Where("id = ? and user_org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"warehouse_out_id": 0}).Error
1088
 	err := XTWriteDB().Model(models.SpSupplierWarehouseCancel{}).Where("id = ? and user_org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"warehouse_out_id": 0}).Error
1053
 
1089
 
1054
-	err = XTWriteDB().Model(models.SpSupplierWarehousingCancelOrder{}).Where("warehouse_cancel_id = ? and user_org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"warehouse_info_id": 0, "warehouse_out_id": 0, "warehousing_id": 0, "good_number": "", "order_number": ""}).Error
1090
+	err = XTWriteDB().Model(models.SpSupplierWarehousingCancelOrder{}).Where("warehouse_cancel_id = ? and user_org_id = ? and status = 1 and project_id = ?", id, orgid, project_id).Updates(map[string]interface{}{"warehouse_info_id": 0, "warehouse_out_id": 0, "warehousing_id": 0, "good_number": "", "order_number": ""}).Error
1091
+	return err
1092
+}
1093
+
1094
+func UpdateSupplyWarehouseInfo(id int64) error {
1095
+
1096
+	err = XTWriteDB().Model(&models.SupplierWarehouseInfo{}).Where("id = ? and status= 1").Updates(map[string]interface{}{"is_warehouse": 2}).Error
1097
+	return err
1098
+}
1099
+
1100
+func GetDrugWarehosueInfoByWarehousingId(drug_id int64, supply_warehouse_id int64, orgid int64) (models.DrugWarehouseOutInfo, error) {
1101
+
1102
+	info := models.DrugWarehouseOutInfo{}
1103
+	err := XTReadDB().Where("drug_id = ? and supply_warehouse_id = ? and org_id = ? and status = 1", drug_id, supply_warehouse_id, orgid).Last(&info).Error
1104
+	return info, err
1105
+}
1106
+
1107
+func GetGoodWarehouseInfoByWarehousingId(good_id int64, supply_warehouse_id int64, orgid int64) (models.WarehouseOutInfo, error) {
1108
+
1109
+	info := models.WarehouseOutInfo{}
1110
+	err := XTReadDB().Where("good_id = ? and supply_warehouse_id = ? and org_id = ? and status = 1", good_id, supply_warehouse_id, orgid).Last(&info).Error
1111
+	return info, err
1112
+}
1113
+
1114
+func GetAllDrugWaresingList(drug_id int64, org_id int64) (info []*models.SpDrugWarehouseInfo, err error) {
1115
+
1116
+	err = XTReadDB().Where("drug_id = ? and org_id = ? and status = 1 and (stock_max_number>0 or stock_min_number > 0)", drug_id, org_id).Find(&info).Error
1117
+	return info, err
1118
+}
1119
+
1120
+func GetAllGoodWaresingList(good_id int64, org_id int64) (info []*models.SpWarehouseInfo, err error) {
1121
+
1122
+	err = XTReadDB().Where("good_id = ? and org_id =? and status = 1 and stock_count>0", good_id, org_id).Find(&info).Error
1123
+	return info, err
1124
+}
1125
+
1126
+func GetReturnOrderById(id int64) (models.SpSupplierWarehouseCancel, error) {
1127
+
1128
+	order := models.SpSupplierWarehouseCancel{}
1129
+	err := XTReadDB().Where("id = ? and status = 1", id).Find(&order).Error
1130
+	return order, err
1131
+}
1132
+
1133
+func GetWarehouseOutByDate(operation_time int64, orgid int64) (models.WarehouseOut, error) {
1134
+	out := models.WarehouseOut{}
1135
+	err := XTReadDB().Where("warehouse_out_time = ? and org_id = ? and status = 1 and is_sys= 0", operation_time, orgid).Find(&out).Error
1136
+	return out, err
1137
+}
1138
+
1139
+func GetWarehouseOutById(id int64, orgid int64) (out []*models.WarehouseOutInfo, err error) {
1140
+
1141
+	err = XTReadDB().Where("warehouse_out_id = ? and status= 1 and org_id = ?", id, orgid).Find(&out).Error
1142
+	return out, err
1143
+}
1144
+
1145
+func DeleteWarehouseOutById(id int64) error {
1146
+
1147
+	err := XTWriteDB().Model(&models.WarehouseOut{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
1055
 	return err
1148
 	return err
1056
 }
1149
 }
1150
+
1151
+func GetDrugWarehouseByDate(operation_time int64, orgid int64) (models.DrugWarehouseOut, error) {
1152
+
1153
+	out := models.DrugWarehouseOut{}
1154
+	err := XTReadDB().Where("warehouse_out_time = ? and org_id = ? and status =1 and is_sys =0 ", operation_time, orgid).Find(&out).Error
1155
+	return out, err
1156
+}
1157
+
1158
+func GetDrugWarehouseByIdList(id int64, orgid int64) (info []*models.DrugWarehouseOutInfo, err error) {
1159
+
1160
+	err = XTReadDB().Where("warehouse_out_id = ? and status = 1 and org_id = ?", id, orgid).Find(&info).Error
1161
+	return info, err
1162
+}
1163
+
1164
+func UpdateDrugWarehouseById(id int64) error {
1165
+
1166
+	err := XTWriteDB().Model(&models.DrugWarehouseOut{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
1167
+	return err
1168
+}
1169
+
1170
+func UpdateWarehouseingById(id int64) error {
1171
+
1172
+	err := XTWriteDB().Model(&models.SpSupplierWarehousingOutOrder{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"is_warehouse": 1}).Error
1173
+	return err
1174
+}
1175
+
1176
+func UpdateSupplyOrderListById(id int64) error {
1177
+
1178
+	err := XTWriteDB().Model(models.SpSupplierWarehousingOutOrder{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"is_warehouse": 2}).Error
1179
+	return err
1180
+}
1181
+
1182
+func GetAllDrugWarehouseInfo(orgid int64) (info []*models.DrugWarehouseInfo, err error) {
1183
+
1184
+	err = XTReadDB().Where("org_id = ? and status = 1 and supply_warehouse_id>0", orgid).Find(&info).Error
1185
+	return info, err
1186
+}
1187
+
1188
+func GetAllGoodWarehouseInfo(orgid int64) (info []*models.WarehousingInfo, err error) {
1189
+	err = XTReadDB().Where("org_id = ? and status = 1 and supply_warehouse_id>0", orgid).Find(&info).Error
1190
+	return info, err
1191
+}
1192
+
1193
+func GetLastDrugWarehosueInfoByWarehouseOutId(orgid int64, warehouse_out_id int64) (models.XtDrugWarehouseInfo, error) {
1194
+	info := models.XtDrugWarehouseInfo{}
1195
+	err := XTReadDB().Model(&info).Where("user_org_id = ? and status = 1 and supply_warehouse_id = ?", orgid, warehouse_out_id).Find(&info).Error
1196
+	return info, err
1197
+}

+ 78 - 17
service/warhouse_service.go View File

154
 			PatientId:               advice.PatientId,
154
 			PatientId:               advice.PatientId,
155
 			Count:                   deliver_number, //出最小单位
155
 			Count:                   deliver_number, //出最小单位
156
 			WarehouseInfoId:         warehouse.ID,
156
 			WarehouseInfoId:         warehouse.ID,
157
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
157
 		}
158
 		}
158
 
159
 
159
 		drugflow := models.DrugFlow{
160
 		drugflow := models.DrugFlow{
179
 			PatientId:               advice.PatientId,
180
 			PatientId:               advice.PatientId,
180
 			SystemTime:              advice.AdviceDate,
181
 			SystemTime:              advice.AdviceDate,
181
 			WarehousingDetailId:     warehouse.ID,
182
 			WarehousingDetailId:     warehouse.ID,
183
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
182
 		}
184
 		}
183
 
185
 
184
 		CreateDrugFlowOne(drugflow)
186
 		CreateDrugFlowOne(drugflow)
286
 			PatientId:               advice.PatientId,
288
 			PatientId:               advice.PatientId,
287
 			Count:                   deliver_number,
289
 			Count:                   deliver_number,
288
 			WarehouseInfoId:         warehouse.ID,
290
 			WarehouseInfoId:         warehouse.ID,
291
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
289
 		}
292
 		}
290
 		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
293
 		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
291
 		if errOne != nil {
294
 		if errOne != nil {
338
 			BatchNumber:       warehouse.BatchNumber,
341
 			BatchNumber:       warehouse.BatchNumber,
339
 			MaxUnit:           warehouse.MaxUnit,
342
 			MaxUnit:           warehouse.MaxUnit,
340
 			WarehousingInfoId: warehouse.WarehousingInfoId,
343
 			WarehousingInfoId: warehouse.WarehousingInfoId,
344
+			SupplyWarehouseId: warehouse.SupplyWarehouseId,
341
 		}
345
 		}
342
 		//扣减库存
346
 		//扣减库存
343
 		errThree := UpDateDrugWarehouseInfoByStock(&info)
347
 		errThree := UpDateDrugWarehouseInfoByStock(&info)
369
 			IsSys:                   1,
373
 			IsSys:                   1,
370
 			PatientId:               advice.PatientId,
374
 			PatientId:               advice.PatientId,
371
 			WarehousingDetailId:     warehouse.ID,
375
 			WarehousingDetailId:     warehouse.ID,
376
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
372
 		}
377
 		}
373
 
378
 
374
 		CreateDrugFlowOne(drugflow)
379
 		CreateDrugFlowOne(drugflow)
801
 
806
 
802
 	fmt.Println("库存1", stock_number)
807
 	fmt.Println("库存1", stock_number)
803
 	fmt.Println("c出库数量", deliver_number)
808
 	fmt.Println("c出库数量", deliver_number)
809
+
804
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
810
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
805
 	if stock_number >= deliver_number {
811
 	if stock_number >= deliver_number {
806
 
812
 
827
 			WarehouseInfoId:         warehouse.ID,
833
 			WarehouseInfoId:         warehouse.ID,
828
 			CountUnit:               drup.MinUnit,
834
 			CountUnit:               drup.MinUnit,
829
 			AdviceId:                advice.ID,
835
 			AdviceId:                advice.ID,
836
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
830
 		}
837
 		}
831
 
838
 
832
 		warehouseOutInfo.Count = prescribingNumber
839
 		warehouseOutInfo.Count = prescribingNumber
860
 			IsSys:                   0,
867
 			IsSys:                   0,
861
 			WarehouseOutDetailId:    drugWareInfo.ID,
868
 			WarehouseOutDetailId:    drugWareInfo.ID,
862
 			AdviceId:                advice.ID,
869
 			AdviceId:                advice.ID,
870
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
863
 		}
871
 		}
864
 
872
 
865
 		CreateDrugFlowOne(drugflow)
873
 		CreateDrugFlowOne(drugflow)
870
 		if advice.CountUnit == drup.MinUnit {
878
 		if advice.CountUnit == drup.MinUnit {
871
 			maxNumber = prescribingNumber / drup.MinNumber
879
 			maxNumber = prescribingNumber / drup.MinNumber
872
 			minNumber = prescribingNumber % drup.MinNumber
880
 			minNumber = prescribingNumber % drup.MinNumber
881
+			if warehouse.StockMaxNumber == 0 && drup.MaxUnit == drup.MinUnit {
882
+				minNumber = maxNumber
883
+			}
873
 		} else {
884
 		} else {
874
 			maxNumber = prescribingNumber
885
 			maxNumber = prescribingNumber
875
 		}
886
 		}
888
 		} else {
899
 		} else {
889
 			warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
900
 			warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
890
 		}
901
 		}
902
+		fmt.Println("ware233232322332323232", warehouse.StockMaxNumber)
903
+		fmt.Println("ware233232322332323232", warehouse.StockMinNumber)
904
+		if warehouse.StockMaxNumber == 1 && warehouse.StockMinNumber == 1 && drup.MaxUnit == drup.MinUnit {
905
+			warehouse.StockMinNumber = 0
906
+		}
891
 
907
 
892
 		if warehouse.StockMaxNumber < 0 {
908
 		if warehouse.StockMaxNumber < 0 {
893
 			return errors.New("库存数量不足")
909
 			return errors.New("库存数量不足")
924
 			WarehouseInfoId:         warehouse.ID,
940
 			WarehouseInfoId:         warehouse.ID,
925
 			CountUnit:               drup.MinUnit,
941
 			CountUnit:               drup.MinUnit,
926
 			AdviceId:                advice.ID,
942
 			AdviceId:                advice.ID,
943
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
927
 		}
944
 		}
928
 		warehouseOutInfo.Count = stock_number
945
 		warehouseOutInfo.Count = stock_number
929
 
946
 
956
 			IsSys:                   0,
973
 			IsSys:                   0,
957
 			WarehouseOutDetailId:    drugWareInfo.ID,
974
 			WarehouseOutDetailId:    drugWareInfo.ID,
958
 			AdviceId:                advice.ID,
975
 			AdviceId:                advice.ID,
976
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
959
 		}
977
 		}
960
 		CreateDrugFlowOne(drugflow)
978
 		CreateDrugFlowOne(drugflow)
961
 		// 出库完成后,要将该批次库存清零
979
 		// 出库完成后,要将该批次库存清零
1130
 			ExpiryDate:              warehouse.ExpiryDate,
1148
 			ExpiryDate:              warehouse.ExpiryDate,
1131
 			ProductDate:             warehouse.ProductDate,
1149
 			ProductDate:             warehouse.ProductDate,
1132
 			ProjectId:               goods.ProjectId,
1150
 			ProjectId:               goods.ProjectId,
1151
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
1133
 		}
1152
 		}
1134
 		warehouseOutInfo.Count = count
1153
 		warehouseOutInfo.Count = count
1135
 
1154
 
1190
 				IsSys:                   1,
1209
 				IsSys:                   1,
1191
 				PatientId:               patient_id,
1210
 				PatientId:               patient_id,
1192
 				ProjectId:               goods.ProjectId,
1211
 				ProjectId:               goods.ProjectId,
1212
+				SupplyWarehouseId:       warehouse.SupplyWarehouseId,
1193
 			}
1213
 			}
1194
 			//查询流水是否存在
1214
 			//查询流水是否存在
1195
 			exsit, errflow := GetStockFlowIsExsit(warehouse.ID, patient_id, record_time, goods.GoodId)
1215
 			exsit, errflow := GetStockFlowIsExsit(warehouse.ID, patient_id, record_time, goods.GoodId)
1259
 				IsSys:                   1,
1279
 				IsSys:                   1,
1260
 				PatientId:               patient_id,
1280
 				PatientId:               patient_id,
1261
 				ProjectId:               goods.ProjectId,
1281
 				ProjectId:               goods.ProjectId,
1282
+				SupplyWarehouseId:       warehouse.SupplyWarehouseId,
1262
 			}
1283
 			}
1263
 			//查询流水是否存在
1284
 			//查询流水是否存在
1264
 			exsit, errflow := GetStockFlowIsExsit(warehouse.ID, patient_id, record_time, goods.GoodId)
1285
 			exsit, errflow := GetStockFlowIsExsit(warehouse.ID, patient_id, record_time, goods.GoodId)
1294
 					PatientId:               patient_id,
1315
 					PatientId:               patient_id,
1295
 					ReturnCount:             exsit.Count + (exsit.Count + deliver_number),
1316
 					ReturnCount:             exsit.Count + (exsit.Count + deliver_number),
1296
 					ProjectId:               goods.ProjectId,
1317
 					ProjectId:               goods.ProjectId,
1318
+					SupplyWarehouseId:       warehouse.SupplyWarehouseId,
1297
 				}
1319
 				}
1298
 				//UpdatedStockFlow(flow)
1320
 				//UpdatedStockFlow(flow)
1299
 				UpdatedStockFlowOne(flow, warehouse.ID, patient_id, record_time, goods.GoodId)
1321
 				UpdatedStockFlowOne(flow, warehouse.ID, patient_id, record_time, goods.GoodId)
1347
 			ExpiryDate:              warehouse.ExpiryDate,
1369
 			ExpiryDate:              warehouse.ExpiryDate,
1348
 			ProductDate:             warehouse.ProductDate,
1370
 			ProductDate:             warehouse.ProductDate,
1349
 			ProjectId:               goods.ProjectId,
1371
 			ProjectId:               goods.ProjectId,
1372
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
1350
 		}
1373
 		}
1351
 		warehouseOutInfo.Count = stock_number
1374
 		warehouseOutInfo.Count = stock_number
1352
 
1375
 
1383
 				IsSys:                   1,
1406
 				IsSys:                   1,
1384
 				PatientId:               patient_id,
1407
 				PatientId:               patient_id,
1385
 				ProjectId:               goods.ProjectId,
1408
 				ProjectId:               goods.ProjectId,
1409
+				SupplyWarehouseId:       warehouse.SupplyWarehouseId,
1386
 			}
1410
 			}
1387
 			//查询流水是否存在
1411
 			//查询流水是否存在
1388
 			exsit, errflows := GetStockFlowIsExsit(warehouse.ID, patient_id, record_time, goods.GoodId)
1412
 			exsit, errflows := GetStockFlowIsExsit(warehouse.ID, patient_id, record_time, goods.GoodId)
1416
 					PatientId:               patient_id,
1440
 					PatientId:               patient_id,
1417
 					ReturnCount:             exsit.Count + (exsit.Count + deliver_number),
1441
 					ReturnCount:             exsit.Count + (exsit.Count + deliver_number),
1418
 					ProjectId:               goods.ProjectId,
1442
 					ProjectId:               goods.ProjectId,
1443
+					SupplyWarehouseId:       warehouse.SupplyWarehouseId,
1419
 				}
1444
 				}
1420
 				//UpdatedStockFlow(flow)
1445
 				//UpdatedStockFlow(flow)
1421
 				UpdatedStockFlowOne(flow, warehouse.ID, patient_id, record_time, goods.GoodId)
1446
 				UpdatedStockFlowOne(flow, warehouse.ID, patient_id, record_time, goods.GoodId)
1452
 				IsSys:                   1,
1477
 				IsSys:                   1,
1453
 				PatientId:               patient_id,
1478
 				PatientId:               patient_id,
1454
 				ProjectId:               goods.ProjectId,
1479
 				ProjectId:               goods.ProjectId,
1480
+				SupplyWarehouseId:       warehouse.SupplyWarehouseId,
1455
 			}
1481
 			}
1456
 			//查询流水是否存在
1482
 			//查询流水是否存在
1457
 			exsit, errflows := GetStockFlowIsExsit(warehouse.ID, patient_id, record_time, goods.GoodId)
1483
 			exsit, errflows := GetStockFlowIsExsit(warehouse.ID, patient_id, record_time, goods.GoodId)
1484
 					IsSys:                   1,
1510
 					IsSys:                   1,
1485
 					PatientId:               patient_id,
1511
 					PatientId:               patient_id,
1486
 					ProjectId:               goods.ProjectId,
1512
 					ProjectId:               goods.ProjectId,
1513
+					SupplyWarehouseId:       warehouse.SupplyWarehouseId,
1487
 				}
1514
 				}
1488
 				//UpdatedStockFlow(flow)
1515
 				//UpdatedStockFlow(flow)
1489
 				UpdatedStockFlowOne(flow, warehouse.ID, patient_id, record_time, goods.GoodId)
1516
 				UpdatedStockFlowOne(flow, warehouse.ID, patient_id, record_time, goods.GoodId)
1664
 			Number:                  warehouse.Number,
1691
 			Number:                  warehouse.Number,
1665
 			Price:                   goods.Price,
1692
 			Price:                   goods.Price,
1666
 			LicenseNumber:           goods.LicenseNumber,
1693
 			LicenseNumber:           goods.LicenseNumber,
1694
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
1667
 		}
1695
 		}
1668
 		warehouseOutInfo.Count = goods.Count
1696
 		warehouseOutInfo.Count = goods.Count
1669
 		//添加出库单详情
1697
 		//添加出库单详情
1702
 			CancelOutDetailId:       0,
1730
 			CancelOutDetailId:       0,
1703
 			ProductDate:             goods.ProductDate,
1731
 			ProductDate:             goods.ProductDate,
1704
 			ExpireDate:              goods.ExpiryDate,
1732
 			ExpireDate:              goods.ExpiryDate,
1733
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
1705
 		}
1734
 		}
1706
 
1735
 
1707
 		//创建出库流水
1736
 		//创建出库流水
1746
 			Number:                  warehouse.Number,
1775
 			Number:                  warehouse.Number,
1747
 			Price:                   warehouse.PackingPrice,
1776
 			Price:                   warehouse.PackingPrice,
1748
 			LicenseNumber:           goods.LicenseNumber,
1777
 			LicenseNumber:           goods.LicenseNumber,
1778
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
1749
 		}
1779
 		}
1750
 		warehouseOutInfo.Count = stock_number
1780
 		warehouseOutInfo.Count = stock_number
1751
 
1781
 
1793
 			CancelOutDetailId:       0,
1823
 			CancelOutDetailId:       0,
1794
 			ProductDate:             goods.ProductDate,
1824
 			ProductDate:             goods.ProductDate,
1795
 			ExpireDate:              goods.ExpiryDate,
1825
 			ExpireDate:              goods.ExpiryDate,
1826
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
1796
 		}
1827
 		}
1797
 
1828
 
1798
 		//创建出库明细
1829
 		//创建出库明细
2001
 			Count:                   deliver_number, //出最小单位
2032
 			Count:                   deliver_number, //出最小单位
2002
 			WarehouseInfoId:         warehouse.ID,
2033
 			WarehouseInfoId:         warehouse.ID,
2003
 			AdviceId:                advice.ID,
2034
 			AdviceId:                advice.ID,
2035
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
2004
 		}
2036
 		}
2005
 
2037
 
2006
 		drugflow := models.DrugFlow{
2038
 		drugflow := models.DrugFlow{
2026
 			PatientId:               advice.PatientId,
2058
 			PatientId:               advice.PatientId,
2027
 			WarehousingDetailId:     warehouse.ID,
2059
 			WarehousingDetailId:     warehouse.ID,
2028
 			AdviceId:                advice.ID,
2060
 			AdviceId:                advice.ID,
2061
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
2029
 		}
2062
 		}
2030
 
2063
 
2031
 		CreateDrugFlowOne(drugflow)
2064
 		CreateDrugFlowOne(drugflow)
2193
 			BatchNumber:       warehouse.BatchNumber,
2226
 			BatchNumber:       warehouse.BatchNumber,
2194
 			MaxUnit:           warehouse.MaxUnit,
2227
 			MaxUnit:           warehouse.MaxUnit,
2195
 			WarehousingInfoId: warehouse.WarehousingInfoId,
2228
 			WarehousingInfoId: warehouse.WarehousingInfoId,
2229
+			SupplyWarehouseId: warehouse.SupplyWarehouseId,
2196
 		}
2230
 		}
2197
 		//扣减库存
2231
 		//扣减库存
2198
 		errThree := UpDateDrugWarehouseInfoByStock(&info)
2232
 		errThree := UpDateDrugWarehouseInfoByStock(&info)
2224
 			PatientId:               advice.PatientId,
2258
 			PatientId:               advice.PatientId,
2225
 			WarehousingDetailId:     warehouse.ID,
2259
 			WarehousingDetailId:     warehouse.ID,
2226
 			AdviceId:                advice.ID,
2260
 			AdviceId:                advice.ID,
2261
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
2227
 		}
2262
 		}
2228
 
2263
 
2229
 		CreateDrugFlowOne(drugflow)
2264
 		CreateDrugFlowOne(drugflow)
2380
 		}
2415
 		}
2381
 
2416
 
2382
 		warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
2417
 		warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
2418
+		if warehouse.StockMaxNumber < 0 {
2419
+			warehouse.StockMaxNumber = 0
2420
+		}
2383
 		warehouse.Mtime = time.Now().Unix()
2421
 		warehouse.Mtime = time.Now().Unix()
2384
 
2422
 
2385
 		if warehouse.StockMinNumber < minNumber {
2423
 		if warehouse.StockMinNumber < minNumber {
2424
+			fmt.Println("233323232233223")
2386
 			warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
2425
 			warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
2387
 			warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
2426
 			warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
2388
 		} else {
2427
 		} else {
2756
 	// 根据先进先出原则,查询最先入库的批次,进行出库
2795
 	// 根据先进先出原则,查询最先入库的批次,进行出库
2757
 
2796
 
2758
 	// 如果没有对应的库存,则报错
2797
 	// 如果没有对应的库存,则报错
2759
-	warehouse, err := FindFirstWarehousingInfoByStockNight(goods.GoodId, goods.GoodTypeId, warehouse_out_id)
2798
+	warehouse, err := FindFirstWarehousingInfoByStockNight(goods.GoodId, goods.GoodTypeId, warehouse_out_id, goods.IsSource)
2760
 	if err != nil {
2799
 	if err != nil {
2761
 
2800
 
2762
 		return err
2801
 		return err
2769
 
2808
 
2770
 		warehouseOutInfo := &models.WarehouseOutInfo{
2809
 		warehouseOutInfo := &models.WarehouseOutInfo{
2771
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
2810
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
2772
-			WarehouseOutId:          warehouseOut.ID,
2811
+			WarehouseOutId:          goods.WarehouseOutId,
2773
 			WarehouseInfotId:        warehouse.ID,
2812
 			WarehouseInfotId:        warehouse.ID,
2774
 			Status:                  1,
2813
 			Status:                  1,
2775
 			Ctime:                   time.Now().Unix(),
2814
 			Ctime:                   time.Now().Unix(),
2808
 			ConsumableType:          2,
2847
 			ConsumableType:          2,
2809
 			IsSys:                   goods.IsSys,
2848
 			IsSys:                   goods.IsSys,
2810
 			WarehousingOrder:        "",
2849
 			WarehousingOrder:        "",
2811
-			WarehouseOutId:          warehouseOut.ID,
2850
+			WarehouseOutId:          goods.WarehouseOutId,
2812
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
2851
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
2813
 			IsEdit:                  1,
2852
 			IsEdit:                  1,
2814
 			CancelStockId:           0,
2853
 			CancelStockId:           0,
2854
 		// 当该批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
2893
 		// 当该批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
2855
 		warehouseOutInfo := &models.WarehouseOutInfo{
2894
 		warehouseOutInfo := &models.WarehouseOutInfo{
2856
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
2895
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
2857
-			WarehouseOutId:          warehouseOut.ID,
2896
+			WarehouseOutId:          goods.WarehouseOutId,
2858
 			WarehouseInfotId:        warehouse.ID,
2897
 			WarehouseInfotId:        warehouse.ID,
2859
 			Status:                  1,
2898
 			Status:                  1,
2860
 			Ctime:                   time.Now().Unix(),
2899
 			Ctime:                   time.Now().Unix(),
2902
 			ConsumableType:          2,
2941
 			ConsumableType:          2,
2903
 			IsSys:                   0,
2942
 			IsSys:                   0,
2904
 			WarehousingOrder:        "",
2943
 			WarehousingOrder:        "",
2905
-			WarehouseOutId:          warehouseOut.ID,
2944
+			WarehouseOutId:          goods.WarehouseOutId,
2906
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
2945
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
2907
 			IsEdit:                  1,
2946
 			IsEdit:                  1,
2908
 			CancelStockId:           0,
2947
 			CancelStockId:           0,
2944
 	return nil
2983
 	return nil
2945
 }
2984
 }
2946
 
2985
 
2947
-func FindFirstWarehousingInfoByStockNight(good_id int64, good_type_id int64, warehouse_out_id int64) (info models.WarehousingInfo, err error) {
2948
-	err = readDb.Model(&models.WarehousingInfo{}).Where("good_id = ? AND good_type_id = ? AND status = 1 and stock_count > 0 and supply_warehouse_id = ?", good_id, good_type_id, warehouse_out_id).Order("ctime").First(&info).Error
2986
+func FindFirstWarehousingInfoByStockNight(good_id int64, good_type_id int64, warehouse_out_id int64, is_source int64) (info models.WarehousingInfo, err error) {
2987
+
2988
+	fmt.Println("is_source2233232233232323232232323", is_source)
2989
+	if is_source == 1 {
2990
+		err = readDb.Model(&models.WarehousingInfo{}).Where("good_id = ? AND good_type_id = ? AND status = 1 and stock_count > 0 and supply_warehouse_id = ?", good_id, good_type_id, warehouse_out_id).Order("ctime").First(&info).Error
2991
+
2992
+	}
2993
+	if is_source == 2 || is_source == 0 {
2994
+		err = readDb.Model(&models.WarehousingInfo{}).Where("good_id = ? AND good_type_id = ? AND status = 1 and stock_count > 0", good_id, good_type_id).Order("ctime").First(&info).Error
2995
+	}
2949
 	return info, err
2996
 	return info, err
2950
 }
2997
 }
2951
 
2998
 
2952
 // 药品出库 递归方式
2999
 // 药品出库 递归方式
2953
-func AutoDrugDeliverInfoNight(orgID int64, prescribingNumber int64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.DrugWarehouseOutInfo) (err error) {
3000
+func AutoDrugDeliverInfoNight(orgID int64, prescribingNumber int64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.DrugWarehouseOutInfo, warehouse_out_id int64, cancel_out_id int64) (err error) {
2954
 
3001
 
2955
 	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
3002
 	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
2956
 	var deliver_number int64 = 0
3003
 	var deliver_number int64 = 0
2966
 	// 如果没有对应的库存,则报错
3013
 	// 如果没有对应的库存,则报错
2967
 	//开启事物
3014
 	//开启事物
2968
 
3015
 
2969
-	warehouse, err := FindLastDrugWarehousingInfoByID(advice.DrugId)
3016
+	warehouse, err := FindLastDrugWarehousingInfoByIDSix(advice.DrugId, warehouse_out_id, advice.IsSource)
2970
 
3017
 
2971
 	if err != nil {
3018
 	if err != nil {
2972
 
3019
 
2982
 
3029
 
2983
 		warehouseOutInfo := &models.DrugWarehouseOutInfo{
3030
 		warehouseOutInfo := &models.DrugWarehouseOutInfo{
2984
 			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
3031
 			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
2985
-			WarehouseOutId:          warehouseout.ID,
3032
+			WarehouseOutId:          advice.WarehouseOutId,
2986
 			Status:                  1,
3033
 			Status:                  1,
2987
 			Ctime:                   time.Now().Unix(),
3034
 			Ctime:                   time.Now().Unix(),
2988
 			Remark:                  advice.Remark,
3035
 			Remark:                  advice.Remark,
2991
 			Manufacturer:            advice.Manufacturer,
3038
 			Manufacturer:            advice.Manufacturer,
2992
 			Dealer:                  warehouse.Dealer,
3039
 			Dealer:                  warehouse.Dealer,
2993
 			IsSys:                   0,
3040
 			IsSys:                   0,
2994
-			SysRecordTime:           advice.Ctime,
3041
+			SysRecordTime:           advice.SysRecordTime,
2995
 			DrugId:                  advice.DrugId,
3042
 			DrugId:                  advice.DrugId,
2996
 			ExpiryDate:              advice.ExpiryDate,
3043
 			ExpiryDate:              advice.ExpiryDate,
2997
 			ProductDate:             advice.ProductDate,
3044
 			ProductDate:             advice.ProductDate,
3017
 
3064
 
3018
 		drugWareInfo, _ := GetLastWarehouseOutInfoById(advice.DrugId)
3065
 		drugWareInfo, _ := GetLastWarehouseOutInfoById(advice.DrugId)
3019
 		drugflow := models.DrugFlow{
3066
 		drugflow := models.DrugFlow{
3020
-			WarehouseOutId:          warehouseout.ID,
3067
+			WarehouseOutId:          advice.WarehouseOutId,
3021
 			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
3068
 			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
3022
 			DrugId:                  advice.DrugId,
3069
 			DrugId:                  advice.DrugId,
3023
 			Number:                  warehouse.Number,
3070
 			Number:                  warehouse.Number,
3040
 			AdviceId:                advice.ID,
3087
 			AdviceId:                advice.ID,
3041
 			SupplyCancelOutId:       warehouseout.SupplyCancelOutId,
3088
 			SupplyCancelOutId:       warehouseout.SupplyCancelOutId,
3042
 			SupplyWarehouseId:       warehouseout.SupplyWarehouseId,
3089
 			SupplyWarehouseId:       warehouseout.SupplyWarehouseId,
3090
+			SystemTime:              advice.SysRecordTime,
3043
 		}
3091
 		}
3044
 
3092
 
3045
 		CreateDrugFlowOne(drugflow)
3093
 		CreateDrugFlowOne(drugflow)
3050
 		if advice.CountUnit == drup.MinUnit {
3098
 		if advice.CountUnit == drup.MinUnit {
3051
 			maxNumber = prescribingNumber / drup.MinNumber
3099
 			maxNumber = prescribingNumber / drup.MinNumber
3052
 			minNumber = prescribingNumber % drup.MinNumber
3100
 			minNumber = prescribingNumber % drup.MinNumber
3101
+			if warehouse.StockMaxNumber == 0 && drup.MaxUnit == drup.MinUnit {
3102
+				minNumber = maxNumber
3103
+			}
3053
 		} else {
3104
 		} else {
3054
 			maxNumber = prescribingNumber
3105
 			maxNumber = prescribingNumber
3055
 		}
3106
 		}
3056
-
3107
+		fmt.Println("maxNUMBER23323232323323322323", maxNumber)
3108
+		fmt.Println("MIN_NUMBWEEEWEWEWWEEWEWEWWE", minNumber)
3109
+		fmt.Println("编辑55555555555555")
3057
 		if warehouse.StockMaxNumber < maxNumber {
3110
 		if warehouse.StockMaxNumber < maxNumber {
3058
 
3111
 
3059
 			return errors.New("库存数量不足")
3112
 			return errors.New("库存数量不足")
3060
 		}
3113
 		}
3061
 
3114
 
3062
 		warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
3115
 		warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
3116
+		if warehouse.StockMaxNumber < 0 {
3117
+			warehouse.StockMaxNumber = 0
3118
+		}
3119
+
3063
 		warehouse.Mtime = time.Now().Unix()
3120
 		warehouse.Mtime = time.Now().Unix()
3064
 
3121
 
3065
 		if warehouse.StockMinNumber < minNumber {
3122
 		if warehouse.StockMinNumber < minNumber {
3072
 		if warehouse.StockMaxNumber < 0 {
3129
 		if warehouse.StockMaxNumber < 0 {
3073
 			return errors.New("库存数量不足")
3130
 			return errors.New("库存数量不足")
3074
 		}
3131
 		}
3132
+		if warehouse.StockMaxNumber == 1 && warehouse.StockMinNumber == 1 && drup.MaxUnit == drup.MinUnit {
3133
+			warehouse.StockMinNumber = 0
3134
+		}
3075
 
3135
 
3076
 		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
3136
 		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
3077
 		if errThree != nil {
3137
 		if errThree != nil {
3083
 		// 当该批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
3143
 		// 当该批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
3084
 		warehouseOutInfo := &models.DrugWarehouseOutInfo{
3144
 		warehouseOutInfo := &models.DrugWarehouseOutInfo{
3085
 			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
3145
 			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
3086
-			WarehouseOutId:          warehouseout.ID,
3146
+			WarehouseOutId:          advice.WarehouseOutId,
3087
 			Status:                  1,
3147
 			Status:                  1,
3088
 			Ctime:                   time.Now().Unix(),
3148
 			Ctime:                   time.Now().Unix(),
3089
 			Remark:                  advice.Remark,
3149
 			Remark:                  advice.Remark,
3092
 			Manufacturer:            advice.Manufacturer,
3152
 			Manufacturer:            advice.Manufacturer,
3093
 			Dealer:                  warehouse.Dealer,
3153
 			Dealer:                  warehouse.Dealer,
3094
 			IsSys:                   0,
3154
 			IsSys:                   0,
3095
-			SysRecordTime:           advice.Ctime,
3155
+			SysRecordTime:           advice.SysRecordTime,
3096
 			DrugId:                  advice.DrugId,
3156
 			DrugId:                  advice.DrugId,
3097
 			ExpiryDate:              warehouse.ExpiryDate,
3157
 			ExpiryDate:              warehouse.ExpiryDate,
3098
 			ProductDate:             warehouse.ProductDate,
3158
 			ProductDate:             warehouse.ProductDate,
3117
 		}
3177
 		}
3118
 		drugWareInfo, _ := GetLastWarehouseOutInfoById(advice.DrugId)
3178
 		drugWareInfo, _ := GetLastWarehouseOutInfoById(advice.DrugId)
3119
 		drugflow := models.DrugFlow{
3179
 		drugflow := models.DrugFlow{
3120
-			WarehouseOutId:          warehouseout.ID,
3180
+			WarehouseOutId:          advice.WarehouseOutId,
3121
 			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
3181
 			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
3122
 			DrugId:                  advice.DrugId,
3182
 			DrugId:                  advice.DrugId,
3123
 			Number:                  warehouse.Number,
3183
 			Number:                  warehouse.Number,
3140
 			AdviceId:                advice.ID,
3200
 			AdviceId:                advice.ID,
3141
 			SupplyCancelOutId:       warehouseout.SupplyCancelOutId,
3201
 			SupplyCancelOutId:       warehouseout.SupplyCancelOutId,
3142
 			SupplyWarehouseId:       warehouseout.SupplyWarehouseId,
3202
 			SupplyWarehouseId:       warehouseout.SupplyWarehouseId,
3203
+			SystemTime:              advice.SysRecordTime,
3143
 		}
3204
 		}
3144
 		CreateDrugFlowOne(drugflow)
3205
 		CreateDrugFlowOne(drugflow)
3145
 		// 出库完成后,要将该批次库存清零
3206
 		// 出库完成后,要将该批次库存清零
3154
 		prescribingNumber_two_temp := deliver_number - stock_number
3215
 		prescribingNumber_two_temp := deliver_number - stock_number
3155
 		advice.CountUnit = drup.MinUnit
3216
 		advice.CountUnit = drup.MinUnit
3156
 
3217
 
3157
-		AutoDrugDeliverInfoNight(orgID, prescribingNumber_two_temp, warehouseout, drup, advice)
3218
+		AutoDrugDeliverInfoNight(orgID, prescribingNumber_two_temp, warehouseout, drup, advice, warehouse_out_id, cancel_out_id)
3158
 	}
3219
 	}
3159
 
3220
 
3160
 	return
3221
 	return