Pārlūkot izejas kodu

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

csx 3 gadus atpakaļ
vecāks
revīzija
2c841d1fc4

+ 4 - 2
controllers/dialysis_api_controller.go Parādīt failu

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

+ 6 - 0
controllers/dialysis_record_api_controller.go Parādīt failu

@@ -533,6 +533,8 @@ type EditMonitorParamObject struct {
533 533
 	UreaMonitoring              float64 `gorm:"column:urea_monitoring" json:"urea_monitoring" form:"urea_monitoring"`
534 534
 	BloodThickness              float64 `gorm:"column:blood_thickness" json:"blood_thickness" form:"blood_thickness"`
535 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 540
 // /api/dislysis/monitor/edit [post]
@@ -652,6 +654,8 @@ func (this *DialysisRecordAPIController) EditMonitor() {
652 654
 			UreaMonitoring:              monitorParam.UreaMonitoring,
653 655
 			BloodThickness:              monitorParam.BloodThickness,
654 656
 			BloodMonitor:                monitorParam.BloodMonitor,
657
+			HeparinAmount:               monitorParam.HeparinAmount,
658
+			Dehydration:                 monitorParam.Dehydration,
655 659
 		}
656 660
 		createErr := service.CreateMonitor(&monitor)
657 661
 		key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":monitor_records"
@@ -734,6 +738,8 @@ func (this *DialysisRecordAPIController) EditMonitor() {
734 738
 		monitor.UreaMonitoring = monitorParam.UreaMonitoring
735 739
 		monitor.BloodThickness = monitorParam.BloodThickness
736 740
 		monitor.BloodMonitor = monitorParam.BloodMonitor
741
+		monitor.HeparinAmount = monitorParam.HeparinAmount
742
+		monitor.Dehydration = monitorParam.Dehydration
737 743
 		updateErr := service.UpdateMonitor(monitor)
738 744
 		key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":monitor_records"
739 745
 		redis := service.RedisClient()

+ 1 - 1
controllers/gobal_config_api_controller.go Parādīt failu

@@ -1061,7 +1061,7 @@ func (c *GobalConfigApiController) GetPrintInfo() {
1061 1061
 		id := int64(idsInter.(float64))
1062 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 1065
 	c.ServeSuccessJSON(map[string]interface{}{
1066 1066
 		"doctoradvice": getPrint,
1067 1067
 	})

+ 4 - 0
controllers/manager_center_api_controller.go Parādīt failu

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

+ 5 - 0
controllers/mobile_api_controllers/dialysis_api_controller.go Parādīt failu

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

+ 9 - 0
controllers/mobile_api_controllers/dialysis_api_controller_extend.go Parādīt failu

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

+ 6 - 0
controllers/mobile_api_controllers/patient_api_controller.go Parādīt failu

@@ -2629,6 +2629,12 @@ func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, dat
2629 2629
 		urea_befor := dataBody["urea_befor"].(string)
2630 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 2638
 	return
2633 2639
 }
2634 2640
 

+ 9 - 0
controllers/secondary_order_api_contorller.go Parādīt failu

@@ -0,0 +1,9 @@
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 Parādīt failu

@@ -103,6 +103,9 @@ func SupplyOrderApiRegistRouters() {
103 103
 	beego.Router("/api/supply/deletereturnorderbyid", &SupplyOrderApiController{}, "Get:DeleteReturnOrderById")
104 104
 	//反审核退货单
105 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,6 +308,7 @@ func (this *SupplyOrderApiController) UpdateSupply() {
305 308
 							Number:       number,
306 309
 							Bank:         bank,
307 310
 							BankAccount:  bankAccount,
311
+							UserOrgId:    orgId,
308 312
 							Status:       1,
309 313
 							Mtime:        time.Now().Unix(),
310 314
 							Modify:       tmodify,
@@ -962,6 +966,7 @@ func (this *SupplyOrderApiController) GetAllPurchaseOrderList() {
962 966
 	limit, _ := this.GetInt64("limit")
963 967
 	orgId := this.GetAdminUserInfo().CurrentOrgId
964 968
 	list, total, err := service.GetAllPurchaseOrderList(check_id, startTime, endTime, keyword, page, limit, orgId)
969
+
965 970
 	if err == nil {
966 971
 		this.ServeSuccessJSON(map[string]interface{}{
967 972
 			"list":  list,
@@ -1213,8 +1218,11 @@ func (this *SupplyOrderApiController) UpdatePurchaseOrder() {
1213 1218
 			}
1214 1219
 
1215 1220
 		}
1221
+		//查询
1222
+		orderInfo, _ := service.GetSupplyWarehousingOrderInfo(warehousing_id)
1216 1223
 		this.ServeSuccessJSON(map[string]interface{}{
1217 1224
 			"warehousingInfo": warehousingInfo,
1225
+			"orderInfo":       orderInfo,
1218 1226
 		})
1219 1227
 
1220 1228
 	}
@@ -1257,6 +1265,7 @@ func (this *SupplyOrderApiController) GetPurchaseOrderDetail() {
1257 1265
 	baseList, _ := service.GetSupplyDrugList(orgId)
1258 1266
 
1259 1267
 	goodList, _ := service.GetSupplyGoodList(orgId)
1268
+
1260 1269
 	if err == nil {
1261 1270
 		this.ServeSuccessJSON(map[string]interface{}{
1262 1271
 			"info":       info,
@@ -1542,6 +1551,7 @@ func (this *SupplyOrderApiController) AddGoodOrder() {
1542 1551
 					GoodNumber:              warehouseOut.GoodNumber,
1543 1552
 					SupplyManufacturer:      supply_manufacturer,
1544 1553
 					MinPrice:                min_price_float,
1554
+					IsWarehosue:             2,
1545 1555
 				}
1546 1556
 				warehousingOut = append(warehousingOut, &order)
1547 1557
 			}
@@ -1552,20 +1562,25 @@ func (this *SupplyOrderApiController) AddGoodOrder() {
1552 1562
 		//如果是手动新增的,type 等于2
1553 1563
 		if item.WarehouseInfoId == 0 {
1554 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,17 +1645,34 @@ func (this *SupplyOrderApiController) GetGoodOrderDetail() {
1630 1645
 	id, _ := this.GetInt64("id")
1631 1646
 	ids := this.GetString("ids")
1632 1647
 	orgId := this.GetAdminUserInfo().CurrentOrgId
1648
+
1633 1649
 	if len(ids) == 0 {
1634 1650
 		out, err := service.GetGoodOrderDetail(id, orgId)
1635 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 1666
 		drugList, _ := service.GetSupplyDrugList(orgId)
1637 1667
 		goodList, _ := service.GetSupplyGoodList(orgId)
1668
+		supplyList, _ := service.GetSupplierList(orgId)
1638 1669
 		if err == nil {
1639 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 1677
 		} else {
1646 1678
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
@@ -1650,14 +1682,29 @@ func (this *SupplyOrderApiController) GetGoodOrderDetail() {
1650 1682
 		idArray := strings.Split(ids, ",")
1651 1683
 		out, err := service.GetGoodOrderDetail(id, orgId)
1652 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 1698
 		drugList, _ := service.GetSupplyDrugList(orgId)
1654 1699
 		goodList, _ := service.GetSupplyGoodList(orgId)
1700
+		supplyList, _ := service.GetSupplierList(orgId)
1655 1701
 		if err == nil {
1656 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 1709
 		} else {
1663 1710
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
@@ -1954,6 +2001,7 @@ func (this *SupplyOrderApiController) UpdateGoodOrder() {
1954 2001
 						GoodNumber:              good_number,
1955 2002
 						SupplyManufacturer:      supply_manufacturer,
1956 2003
 						MinPrice:                min_price_float,
2004
+						IsWarehosue:             2,
1957 2005
 					}
1958 2006
 					warehousingOut = append(warehousingOut, &order)
1959 2007
 				}
@@ -1981,22 +2029,29 @@ func (this *SupplyOrderApiController) UpdateGoodOrder() {
1981 2029
 		}
1982 2030
 		err = service.CreateSupplyWarehousOutOrder(item)
1983 2031
 	}
2032
+
1984 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 2051
 	if err == nil {
1998 2052
 		this.ServeSuccessJSON(map[string]interface{}{
1999
-			"out": out,
2053
+			"out":  out,
2054
+			"list": list,
2000 2055
 		})
2001 2056
 	} else {
2002 2057
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
@@ -2026,8 +2081,10 @@ func (this *SupplyOrderApiController) GetAllOrderCountList() {
2026 2081
 	//获取购货订单的数据
2027 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 2086
 	drugList, err := service.GetSupplyDrugList(orgId)
2087
+
2031 2088
 	if err == nil {
2032 2089
 		this.ServeSuccessJSON(map[string]interface{}{
2033 2090
 			"purcaseOrder": purcaseOrder,
@@ -2136,7 +2193,7 @@ func (this *SupplyOrderApiController) GetGoodOrderCountList() {
2136 2193
 	//获取购货订单的数据
2137 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 2199
 	detail, _ := service.GetGoodOrderDetail(id, orgId)
@@ -2340,6 +2397,9 @@ func (this *SupplyOrderApiController) GetGoodOrderCountList() {
2340 2397
 	}
2341 2398
 	//创建入库单
2342 2399
 	errs := service.CreateDrugWarehousingInfoSix(warehouseInfoDetail)
2400
+
2401
+	//改变入库状态
2402
+
2343 2403
 	fmt.Println(errs)
2344 2404
 	for _, items := range drugFlow {
2345 2405
 		drugWarehouseInfo, _ := service.GetLastDrugWarehouseInfo(items.DrugId)
@@ -2349,6 +2409,10 @@ func (this *SupplyOrderApiController) GetGoodOrderCountList() {
2349 2409
 	service.CreateDrugFlowSix(drugFlow)
2350 2410
 
2351 2411
 	drugList, _ := service.GetSupplyDrugList(orgId)
2412
+
2413
+	for _, items := range goodOrder {
2414
+		service.UpdateWarehouseingById(items.ID)
2415
+	}
2352 2416
 	if err == nil {
2353 2417
 		this.ServeSuccessJSON(map[string]interface{}{
2354 2418
 			"purcaseOrder": purcaseOrder,
@@ -2456,12 +2520,12 @@ func (this *SupplyOrderApiController) SaveGoodReturnOrder() {
2456 2520
 				}
2457 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 2524
 					utils.ErrorLog("count")
2461 2525
 					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2462 2526
 					return
2463 2527
 				}
2464
-				count := int64(items["count"].(float64))
2528
+				count := items["count"].(string)
2465 2529
 
2466 2530
 				if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
2467 2531
 					utils.ErrorLog("manufacturer_id")
@@ -2604,13 +2668,17 @@ func (this *SupplyOrderApiController) SaveGoodReturnOrder() {
2604 2668
 					return
2605 2669
 				}
2606 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 2675
 				cancelOrder := &models.SpSupplierWarehousingCancelOrder{
2608 2676
 					ManufacturerId:            manufacturer_id,
2609 2677
 					OrderNumber:               order_number,
2610 2678
 					ProjectId:                 project_id,
2611 2679
 					GoodNumber:                good_number,
2612 2680
 					IsSource:                  is_source,
2613
-					Count:                     supply_count,
2681
+					Count:                     count,
2614 2682
 					Price:                     price_float,
2615 2683
 					Remark:                    supply_remake,
2616 2684
 					RateOfConcession:          rate_of_concession_float,
@@ -2637,6 +2705,8 @@ func (this *SupplyOrderApiController) SaveGoodReturnOrder() {
2637 2705
 					WarehousingId:             warehousing_id,
2638 2706
 					SourceCount:               count,
2639 2707
 					SupplyWarehouseDetailInfo: id,
2708
+					SupplyCount:               supply_count,
2709
+					DepositRate:               deposit_rate_float,
2640 2710
 				}
2641 2711
 				warehouseCancel = append(warehouseCancel, cancelOrder)
2642 2712
 			}
@@ -2644,12 +2714,17 @@ func (this *SupplyOrderApiController) SaveGoodReturnOrder() {
2644 2714
 	}
2645 2715
 
2646 2716
 	for _, item := range warehouseCancel {
2717
+		if item.SupplyWarehouseDetailInfo > 0 {
2718
+			item.Type = 1
2719
+		} else {
2720
+			item.Type = 2
2721
+		}
2647 2722
 		service.CreateCancelReturnOrder(item)
2648 2723
 		//查询该商品在退库单中是否存在
2649 2724
 		_, errcodes := service.GetSupplyWarehouseOutIsExsit(item.WarehouseOutId, item.ProjectId, orgId)
2650 2725
 		//如果不存在则情况退库单的关联信息
2651 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,12 +2795,14 @@ func (this *SupplyOrderApiController) GetGoodReturnDetail() {
2720 2795
 	baseList, _ := service.GetSupplyDrugList(orgId)
2721 2796
 
2722 2797
 	goodList, _ := service.GetSupplyGoodList(orgId)
2798
+	supplyList, _ := service.GetSupplierList(orgId)
2723 2799
 	if err == nil {
2724 2800
 		this.ServeSuccessJSON(map[string]interface{}{
2725 2801
 			"cancelDetail":      detail,
2726 2802
 			"orderCancelDetail": orderDetail,
2727 2803
 			"drugList":          baseList,
2728 2804
 			"goodList":          goodList,
2805
+			"supplyList":        supplyList,
2729 2806
 		})
2730 2807
 	} else {
2731 2808
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
@@ -2903,6 +2980,20 @@ func (this *SupplyOrderApiController) UpdateGoodReturn() {
2903 2980
 				}
2904 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 2997
 				if id > 0 {
2907 2998
 					cancelOrder := &models.SpSupplierWarehousingCancelOrder{
2908 2999
 						ID:                      id,
@@ -2911,7 +3002,7 @@ func (this *SupplyOrderApiController) UpdateGoodReturn() {
2911 3002
 						ProjectId:               project_id,
2912 3003
 						GoodNumber:              good_number,
2913 3004
 						IsSource:                is_source,
2914
-						Count:                   supply_count,
3005
+						Count:                   count,
2915 3006
 						Price:                   price_float,
2916 3007
 						Remark:                  supply_remake,
2917 3008
 						RateOfConcession:        rate_of_concession_float,
@@ -2931,6 +3022,8 @@ func (this *SupplyOrderApiController) UpdateGoodReturn() {
2931 3022
 						Name:                    name,
2932 3023
 						SupplyUnit:              supply_unit,
2933 3024
 						SupplyLicenseNumber:     supply_license_number,
3025
+						SupplyCount:             supply_count,
3026
+						DepositRate:             deposit_rate_float,
2934 3027
 					}
2935 3028
 					updateWarehouseCancel = append(updateWarehouseCancel, cancelOrder)
2936 3029
 				}
@@ -2942,7 +3035,7 @@ func (this *SupplyOrderApiController) UpdateGoodReturn() {
2942 3035
 						ProjectId:               project_id,
2943 3036
 						GoodNumber:              good_number,
2944 3037
 						IsSource:                is_source,
2945
-						Count:                   supply_count,
3038
+						Count:                   count,
2946 3039
 						Price:                   price_float,
2947 3040
 						Remark:                  supply_remake,
2948 3041
 						RateOfConcession:        rate_of_concession_float,
@@ -2952,7 +3045,7 @@ func (this *SupplyOrderApiController) UpdateGoodReturn() {
2952 3045
 						Status:                  1,
2953 3046
 						Mtime:                   0,
2954 3047
 						WarehouseCancelId:       warehouse_out_id,
2955
-						Type:                    1,
3048
+						Type:                    2,
2956 3049
 						ReturnNumber:            return_number,
2957 3050
 						WarehouseOutId:          warehouse_out_id,
2958 3051
 						SupplySpecificationName: supply_specification_name,
@@ -2962,6 +3055,8 @@ func (this *SupplyOrderApiController) UpdateGoodReturn() {
2962 3055
 						Name:                    name,
2963 3056
 						SupplyUnit:              supply_unit,
2964 3057
 						SupplyLicenseNumber:     supply_license_number,
3058
+						SupplyCount:             supply_count,
3059
+						DepositRate:             deposit_rate_float,
2965 3060
 					}
2966 3061
 					warehouseCancel = append(warehouseCancel, cancelOrder)
2967 3062
 				}
@@ -2970,11 +3065,13 @@ func (this *SupplyOrderApiController) UpdateGoodReturn() {
2970 3065
 
2971 3066
 		if len(updateWarehouseCancel) > 0 {
2972 3067
 			for _, item := range updateWarehouseCancel {
3068
+
2973 3069
 				service.UpdateWarehouseCancelOrder(item)
2974 3070
 			}
2975 3071
 		}
2976 3072
 		if len(warehouseCancel) > 0 {
2977 3073
 			for _, item := range warehouseCancel {
3074
+
2978 3075
 				service.CreateCancelReturnOrder(item)
2979 3076
 			}
2980 3077
 		}
@@ -2992,13 +3089,50 @@ func (this *SupplyOrderApiController) UpdateGoodReturn() {
2992 3089
 func (this *SupplyOrderApiController) ModefyGoodOrder() {
2993 3090
 
2994 3091
 	id, _ := this.GetInt64("id")
3092
+	warehousing_id, _ := this.GetInt64("warehousing_id")
2995 3093
 	orgId := this.GetAdminUserInfo().CurrentOrgId
2996 3094
 
2997
-	//获取购货订单的数据
2998
-	purcaseOrder, _ := service.GetAllPurcaseOrderById(id, orgId)
2999 3095
 	//获取购货单的数据
3000 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 3134
 	drugList, _ := service.GetSupplyDrugList(orgId)
3135
+
3002 3136
 	//获取已有关联的退货单
3003 3137
 	cancelList, _ := service.GetSupplyCancelWarehouse(id, orgId)
3004 3138
 	//查询是否存在退货单
@@ -3013,6 +3147,11 @@ func (this *SupplyOrderApiController) ModefyGoodOrder() {
3013 3147
 		}
3014 3148
 		err := service.UpdateSupplyGoodOrder(id, out)
3015 3149
 
3150
+		for _, its := range goodOrder {
3151
+			//改变采购单状态
3152
+			service.UpdateSupplyOrderListById(its.ID)
3153
+		}
3154
+
3016 3155
 		//查询该订单不是采购入库的数据
3017 3156
 		list, _ := service.GetDrugSupplyWarehousingById(id, orgId)
3018 3157
 		if len(list) == 0 {
@@ -3151,30 +3290,37 @@ func (this *SupplyOrderApiController) CheckReturnOrder() {
3151 3290
 	//获取退库单详情
3152 3291
 	list, _ := service.GetSupplyCancelOrderDetail(id, orgId)
3153 3292
 	for _, item := range list {
3154
-
3293
+		fmt.Println("itme.233232323232323232323232323232232332", item.Type)
3155 3294
 		var total_count int64
3156 3295
 		var prescribing_number_total int64
3157 3296
 		//药品
3158 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 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 3312
 			medical, _ := service.GetBaseDrugMedical(item.ProjectId)
3168 3313
 
3169 3314
 			//判断单位是否相等
3170 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 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 3325
 			if total_count == 0 {
3180 3326
 				goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
@@ -3215,7 +3361,7 @@ func (this *SupplyOrderApiController) CheckReturnOrder() {
3215 3361
 			number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
3216 3362
 			number = number + total
3217 3363
 			warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
3218
-			operation_time := time.Now().Unix()
3364
+			//operation_time := time.Now().Unix()
3219 3365
 			creater := this.GetAdminUserInfo().AdminUser.Id
3220 3366
 			recordDateStr := time.Now().Format("2006-01-02")
3221 3367
 			recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
@@ -3223,7 +3369,7 @@ func (this *SupplyOrderApiController) CheckReturnOrder() {
3223 3369
 			record_date := recordDate.Unix()
3224 3370
 			warehouseOut := models.DrugWarehouseOut{
3225 3371
 				WarehouseOutOrderNumber: warehousing_out_order,
3226
-				OperationTime:           operation_time,
3372
+				OperationTime:           record_date,
3227 3373
 				OrgId:                   orgId,
3228 3374
 				Creater:                 creater,
3229 3375
 				Ctime:                   ctime,
@@ -3247,7 +3393,7 @@ func (this *SupplyOrderApiController) CheckReturnOrder() {
3247 3393
 				WarehouseOutOrderNumber: lastDrug.WarehouseOutOrderNumber,
3248 3394
 				WarehouseOutId:          lastDrug.ID,
3249 3395
 				DrugId:                  item.ProjectId,
3250
-				Count:                   item.Count,
3396
+				Count:                   item.SupplyCount,
3251 3397
 				Price:                   item.Price,
3252 3398
 				Status:                  1,
3253 3399
 				Ctime:                   ctime,
@@ -3265,28 +3411,30 @@ func (this *SupplyOrderApiController) CheckReturnOrder() {
3265 3411
 				WarehouseInfoId:         0,
3266 3412
 				SupplyCancelOutId:       id,
3267 3413
 				SupplyWarehouseId:       warehouse_out_id,
3414
+				SysRecordTime:           record_date,
3415
+				IsSource:                item.Type,
3268 3416
 			}
3269 3417
 
3270 3418
 			drup, _ := service.FindBaseDrugLibRecord(orgId, item.ProjectId)
3271 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 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 3439
 				goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
3292 3440
 				this.ServeSuccessJSON(map[string]interface{}{
@@ -3308,7 +3456,7 @@ func (this *SupplyOrderApiController) CheckReturnOrder() {
3308 3456
 			number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
3309 3457
 			number = number + total
3310 3458
 			warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
3311
-			operation_time := time.Now().Unix()
3459
+			//operation_time := time.Now().Unix()
3312 3460
 			creater := this.GetAdminUserInfo().AdminUser.Id
3313 3461
 			recordDateStr := time.Now().Format("2006-01-02")
3314 3462
 			recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
@@ -3316,7 +3464,7 @@ func (this *SupplyOrderApiController) CheckReturnOrder() {
3316 3464
 			record_date := recordDate.Unix()
3317 3465
 			warehouseOut := models.WarehouseOut{
3318 3466
 				WarehouseOutOrderNumber: warehousing_out_order,
3319
-				OperationTime:           operation_time,
3467
+				OperationTime:           record_date,
3320 3468
 				OrgId:                   orgId,
3321 3469
 				Creater:                 creater,
3322 3470
 				Ctime:                   ctime,
@@ -3328,11 +3476,12 @@ func (this *SupplyOrderApiController) CheckReturnOrder() {
3328 3476
 				IsSys:                   0,
3329 3477
 			}
3330 3478
 			//查询是否生成出库单
3331
-			_, errcodes := service.FindStockOutByIsSys(orgId, 0, operation_time)
3479
+			_, errcodes := service.FindStockOutByIsSys(orgId, 0, record_date)
3332 3480
 			if errcodes == gorm.ErrRecordNotFound {
3333 3481
 				service.AddSigleWarehouseOut(&warehouseOut)
3334 3482
 			}
3335 3483
 			outWarehouse, _ := service.GetlastWarehouseOutById(orgId, record_date)
3484
+			fmt.Println("232332322332232323", outWarehouse)
3336 3485
 			goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
3337 3486
 			info := &models.WarehouseOutInfo{
3338 3487
 				WarehouseOutOrderNumber: outWarehouse.WarehouseOutOrderNumber,
@@ -3340,7 +3489,7 @@ func (this *SupplyOrderApiController) CheckReturnOrder() {
3340 3489
 				WarehouseInfotId:        0,
3341 3490
 				GoodId:                  item.ProjectId,
3342 3491
 				GoodTypeId:              goodObj.GoodTypeId,
3343
-				Count:                   item.Count,
3492
+				Count:                   item.SupplyCount,
3344 3493
 				Price:                   item.Price,
3345 3494
 				TotalPrice:              0,
3346 3495
 				ProductDate:             item.SupplyProductDate,
@@ -3356,20 +3505,16 @@ func (this *SupplyOrderApiController) CheckReturnOrder() {
3356 3505
 				SupplyCancelOutId:       id,
3357 3506
 				OrgId:                   orgId,
3358 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 3513
 			if parseDateErr != nil {
3364 3514
 				utils.ErrorLog(parseDateErr.Error())
3365 3515
 				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
3366 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 3520
 	cancel := models.SpSupplierWarehouseCancel{
@@ -3378,7 +3523,7 @@ func (this *SupplyOrderApiController) CheckReturnOrder() {
3378 3523
 		CheckTime: record_date,
3379 3524
 	}
3380 3525
 	err := service.CheckReturnOrder(id, orgId, cancel)
3381
-
3526
+	fmt.Println("3232233232322332232323232323322332232323232323")
3382 3527
 	if err == nil {
3383 3528
 		this.ServeSuccessJSON(map[string]interface{}{
3384 3529
 			"msg":        "1",
@@ -3452,6 +3597,9 @@ func (this *SupplyOrderApiController) DeleteReturnOrderById() {
3452 3597
 func (this *SupplyOrderApiController) ModefyReturnOrder() {
3453 3598
 	id, _ := this.GetInt64("id")
3454 3599
 	err := service.ModefyReturnOrder(id)
3600
+
3601
+	//获取退库单据日期
3602
+	cancel, _ := service.GetReturnOrderById(id)
3455 3603
 	orgId := this.GetAdminUserInfo().CurrentOrgId
3456 3604
 	if err == nil {
3457 3605
 		//获取退库单详情
@@ -3465,31 +3613,50 @@ func (this *SupplyOrderApiController) ModefyReturnOrder() {
3465 3613
 				if item.SupplyUnit == base.MaxUnit {
3466 3614
 					//退库
3467 3615
 					drugInfo := models.DrugWarehouseInfo{
3468
-						StockMaxNumber: item.Count,
3616
+						StockMaxNumber: item.SupplyCount,
3469 3617
 					}
3470 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 3622
 					drugInfo := models.DrugWarehouseInfo{
3474
-						StockMinNumber: item.Count,
3623
+						StockMinNumber: item.SupplyCount,
3475 3624
 					}
3476 3625
 					service.UpdateDrugWasehousringOne(item.ProjectId, item.SupplyWarehouseDetailInfo, drugInfo)
3477 3626
 				}
3627
+
3478 3628
 				//删除流水
3479 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 3639
 			if item.IsSource == 2 {
3483
-
3640
+				fmt.Println("item2332322323232332", item.SupplyCount)
3484 3641
 				//退库
3485 3642
 				info := models.WarehousingInfo{
3486
-					StockCount: item.Count,
3643
+					StockCount: item.SupplyCount,
3487 3644
 				}
3645
+
3488 3646
 				//更改库存
3489 3647
 				err := service.UpdateWarehousingInfoById(item.ProjectId, item.SupplyWarehouseDetailInfo, info)
3490
-				//删除出库记录
3491
-				service.DeleteGoodWarehouseOut(item.ProjectId, item.WarehouseCancelId)
3492 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 3662
 	} else {
@@ -3505,3 +3672,74 @@ func (this *SupplyOrderApiController) ModefyReturnOrder() {
3505 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 Parādīt failu

@@ -319,6 +319,7 @@ type PredialysisEvaluation struct {
319 319
 	EstimatedFoodIntake            string  `gorm:"column:estimated_food_intake" json:"estimated_food_intake" form:"estimated_food_intake"`
320 320
 	BloodPressureDuringDialysis    string  `gorm:"column:blood_pressure_during_dialysis" json:"blood_pressure_during_dialysis" form:"blood_pressure_during_dialysis"`
321 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 325
 func (PredialysisEvaluation) TableName() string {
@@ -634,6 +635,7 @@ type AssessmentAfterDislysis struct {
634 635
 	Fallrisk                        int64   `gorm:"column:fallrisk" json:"fallrisk" form:"fallrisk"`
635 636
 	MachineRun                      string  `gorm:"column:machine_run" json:"machine_run" form:"machine_run"`
636 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 641
 func (AssessmentAfterDislysis) TableName() string {
@@ -743,6 +745,8 @@ type MonitoringRecord struct {
743 745
 	UreaMonitoring              float64 `gorm:"column:urea_monitoring" json:"urea_monitoring" form:"urea_monitoring"`
744 746
 	BloodThickness              float64 `gorm:"column:blood_thickness" json:"blood_thickness" form:"blood_thickness"`
745 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 752
 func (MonitoringRecord) TableName() string {

+ 1 - 0
models/drug_stock.go Parādīt failu

@@ -154,6 +154,7 @@ type DrugWarehouseOutInfo struct {
154 154
 	AdviceId                int64   `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
155 155
 	SupplyCancelOutId       int64   `gorm:"column:supply_cancel_out_id" json:"supply_cancel_out_id" form:"supply_cancel_out_id"`
156 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 160
 func (DrugWarehouseOutInfo) TableName() string {

+ 1 - 0
models/good_models.go Parādīt failu

@@ -85,6 +85,7 @@ type GoodInfo struct {
85 85
 	GoodSotckInfo               []*GoodSotckInfo     `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_stock_in"`
86 86
 	IsUser                      int64                `gorm:"column:is_user" json:"is_user" form:"is_user"`
87 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 91
 func (GoodInfo) TableName() string {

+ 5 - 0
models/secondary_models.go Parādīt failu

@@ -0,0 +1,5 @@
1
+package models
2
+
3
+func main() {
4
+
5
+}

+ 30 - 28
models/self_drug_models.go Parādīt failu

@@ -384,34 +384,36 @@ func (XtDrugAutomaticReduceDetail) TableName() string {
384 384
 }
385 385
 
386 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 419
 func (XtDrugWarehouseInfo) TableName() string {

+ 3 - 0
models/stock_models.go Parādīt failu

@@ -242,6 +242,7 @@ type WarehouseOutInfo struct {
242 242
 	ProjectId               int64        `gorm:"column:project_id" json:"project_id" form:"project_id"`
243 243
 	SupplyCancelOutId       int64        `gorm:"column:supply_cancel_out_id" json:"supply_cancel_out_id" form:"supply_cancel_out_id"`
244 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 248
 func (WarehouseOutInfo) TableName() string {
@@ -484,6 +485,8 @@ type WarehouseOutInfoOne struct {
484 485
 	PackingUnit                 string  `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
485 486
 	LicenseNumber               string  `gorm:"column:license_number" json:"license_number" form:"license_number"`
486 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 492
 type WarehouseOutInfoTwo struct {

+ 92 - 77
models/supply.models.go Parādīt failu

@@ -65,11 +65,13 @@ func (SpGoodInformation) TableName() string {
65 65
 }
66 66
 
67 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 77
 func (SpWarehouseInfo) TableName() string {
@@ -77,15 +79,17 @@ func (SpWarehouseInfo) TableName() string {
77 79
 }
78 80
 
79 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 95
 func (SpDrugWarehouseInfo) TableName() string {
@@ -194,36 +198,40 @@ func (VmSupplierWarehouseInfo) TableName() string {
194 198
 }
195 199
 
196 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 237
 func (SpSupplierWarehousingOutOrder) TableName() string {
@@ -231,26 +239,27 @@ func (SpSupplierWarehousingOutOrder) TableName() string {
231 239
 }
232 240
 
233 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 265
 func (SpSupplierWarehouseOut) TableName() string {
@@ -286,13 +295,16 @@ func (VmSupplierWarehouseOut) TableName() string {
286 295
 }
287 296
 
288 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 310
 func (VSpSupplierWarehousingOutOrder) TableName() string {
@@ -343,7 +355,7 @@ type SpSupplierWarehousingCancelOrder struct {
343 355
 	ProjectId                 int64   `gorm:"column:project_id" json:"project_id" form:"project_id"`
344 356
 	GoodNumber                string  `gorm:"column:good_number" json:"good_number" form:"good_number"`
345 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 359
 	Price                     float64 `gorm:"column:price" json:"price" form:"price"`
348 360
 	Remark                    string  `gorm:"column:remark" json:"remark" form:"remark"`
349 361
 	RateOfConcession          float64 `gorm:"column:rate_of_concession" json:"rate_of_concession" form:"rate_of_concession"`
@@ -368,8 +380,10 @@ type SpSupplierWarehousingCancelOrder struct {
368 380
 	SupplyExpiryDate          int64   `gorm:"column:supply_expiry_date" json:"supply_expiry_date" form:"supply_expiry_date"`
369 381
 	WarehousingId             int64   `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
370 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 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 389
 func (SpSupplierWarehousingCancelOrder) TableName() string {
@@ -416,10 +430,11 @@ func (VmSpSupplierWarehousingOutOrder) TableName() string {
416 430
 }
417 431
 
418 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 440
 func (VmSpSupplierWarehousingCancelOrder) TableName() string {

+ 1 - 0
routers/router.go Parādīt failu

@@ -78,4 +78,5 @@ func init() {
78 78
 	controllers.GdybRegistRouters()
79 79
 
80 80
 	controllers.SupplyOrderApiRegistRouters()
81
+	controllers.SecondaryOrderApiRegistRouters()
81 82
 }

+ 25 - 5
service/gobal_config_service.go Parādīt failu

@@ -163,12 +163,32 @@ func FindAdviceInitConfig(org_id int64) (adviceInit models.AdviceInit, err error
163 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 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 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 194
 	return doctor, err
@@ -695,7 +715,7 @@ func GetDrugStockOutFlow(drugid int64, startime int64, endtime int64, page int64
695 715
 
696 716
 func GetBatchOrderDetail(drugid int64, orgid int64, page int64, limit int64) (drug []*models.DrugWarehouseInfo, total int64, err error) {
697 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 719
 	return drug, total, err
700 720
 }
701 721
 

+ 1 - 1
service/mobile_dialysis_service.go Parādīt failu

@@ -3433,7 +3433,7 @@ func GetHisProjectConfig(orgid int64) (models.XtHisProjectConfig, error) {
3433 3433
 
3434 3434
 func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
3435 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 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 3439
 	return

+ 5 - 0
service/secondary_service.go Parādīt failu

@@ -0,0 +1,5 @@
1
+package service
2
+
3
+func main() {
4
+
5
+}

+ 16 - 3
service/stock_service.go Parādīt failu

@@ -196,7 +196,6 @@ func FindAllGoodInfoTotal(orgId int64) (total int64) {
196 196
 }
197 197
 
198 198
 func AddSigleGoodInfo(goodInfo *models.GoodInfo) (error, *models.GoodInfo) {
199
-	fmt.Println("goodino232323232323232323", goodInfo.IsUse)
200 199
 	err := writeDb.Create(&goodInfo).Error
201 200
 	return err, goodInfo
202 201
 
@@ -251,6 +250,7 @@ func ModifyGoodInfo(goodInfo *models.GoodInfo) (error, *models.GoodInfo) {
251 250
 		"provinces_code":                 goodInfo.ProvincesCode,
252 251
 		"is_user":                        goodInfo.IsUser,
253 252
 		"number":                         goodInfo.Number,
253
+		"is_warehouse":                   goodInfo.IsWarehouse,
254 254
 	}).Error
255 255
 
256 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,7 +364,7 @@ func FindAllGoodTypeOne(org_id int64) (goodType []*models.GoodsType, err error)
364 364
 }
365 365
 
366 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 368
 	return goodInfo, err
369 369
 }
370 370
 
@@ -772,6 +772,17 @@ func FindLastDrugWarehousingInfoByID(drug_id int64) (info models.XtDrugWarehouse
772 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 787
 func FindLastWarehousingInfoByID(drug_id int64) (info models.WarehousingInfo, err error) {
777 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,6 +1606,8 @@ type DrugWarehouseOutInfo struct {
1595 1606
 	BatchNumber             string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
1596 1607
 	Drug                    *Drug   `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
1597 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 1613
 func (DrugWarehouseOutInfo) TableName() string {
@@ -3877,7 +3890,7 @@ func GetOrderDetialByOrderId(id int64, orgid int64) (out []*models.WarehouseOutI
3877 3890
 	if orgid > 0 {
3878 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 3894
 	return out, err
3882 3895
 }
3883 3896
 

+ 171 - 30
service/supply_service.go Parādīt failu

@@ -412,7 +412,9 @@ func GetAllPurchaseOrderList(check_id int64, startime int64, endtime int64, keyw
412 412
 	if orgid > 0 {
413 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 418
 	return info, total, err
417 419
 }
418 420
 
@@ -545,12 +547,24 @@ func GetAllPurcaseOrderById(id int64, orgid int64) (order []*models.VSupplierWar
545 547
 }
546 548
 
547 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 562
 	db := XTReadDB().Table("xt_supplier_warehousing_out_order as o").Where("o.status = 1")
549 563
 	if id > 0 {
550 564
 		db = db.Where("o.warehousing_id = ?", id)
551 565
 	}
552 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 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 570
 	return order, err
@@ -558,7 +572,7 @@ func GetAllGoodOrderById(id int64, orgid int64) (order []*models.VSpSupplierWare
558 572
 
559 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 576
 	return order, err
563 577
 }
564 578
 
@@ -655,7 +669,7 @@ func GetReturnCancelOrder(id int64, orgid int64) (models.SpSupplierWarehouseCanc
655 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 674
 	err = XTReadDB().Where("warehouse_cancel_id = ? and user_org_id =? and status = 1", id, orgid).Find(&order).Error
661 675
 	return order, err
@@ -715,7 +729,7 @@ func GetGoodReturnOrderDetail(id int64, orgid int64) (order []*models.SpSupplier
715 729
 
716 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 733
 	return err
720 734
 }
721 735
 
@@ -765,6 +779,7 @@ func UpdateGoodSupplyWarehousingInfo(id int64, orgid int64) error {
765 779
 func UpdateGoodSupplyFlow(id int64, orgid int64) error {
766 780
 
767 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 783
 	return err
769 784
 }
770 785
 
@@ -906,7 +921,7 @@ func DeleteGoodOrderById(id int64) error {
906 921
 func GetlastWarehouseOutById(user_org_id int64, record_date int64) (models.WarehouseOut, error) {
907 922
 
908 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 925
 	return out, err
911 926
 }
912 927
 
@@ -914,7 +929,7 @@ func GetDrugWarehouseOutById(orgid int64, record_date int64) (*models.DrugWareho
914 929
 
915 930
 	out := models.DrugWarehouseOut{}
916 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 933
 	if err == gorm.ErrRecordNotFound {
919 934
 		return nil, err
920 935
 	}
@@ -927,7 +942,7 @@ func GetDrugWarehouseOutById(orgid int64, record_date int64) (*models.DrugWareho
927 942
 func GetLastDrugWarehouseById(orgid int64, record_date int64) (models.DrugWarehouseOut, error) {
928 943
 
929 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 946
 	return out, err
932 947
 }
933 948
 
@@ -958,35 +973,35 @@ func ModefyReturnOrder(id int64) error {
958 973
 
959 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 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 986
 	return err
972 987
 }
973 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 991
 	return err
977 992
 }
978 993
 
979 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 997
 	return err
983 998
 }
984 999
 
985 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 1006
 	return err
992 1007
 }
@@ -1011,25 +1026,46 @@ func ModfySupplyWarehouseOut(warehousing_id int64, orgid int64) error {
1011 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 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 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 1069
 	return list, err
1034 1070
 }
1035 1071
 
@@ -1047,10 +1083,115 @@ func GetSupplyWarehouseOutIsExsit(warehouse_out_id int64, project_id int64, orgi
1047 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 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 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 Parādīt failu

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