Browse Source

11月9日库存管理

XMLWAN 2 years ago
parent
commit
024bc4492c

+ 9 - 0
controllers/dialysis_api_controller.go View File

@@ -3785,6 +3785,15 @@ func (this *DialysisApiController) GetTodayMonitor() {
3785 3785
 
3786 3786
 	}
3787 3787
 
3788
+	if adminInfo.CurrentOrgId == 10395 {
3789
+
3790
+		if ultrafiltration_rate > 0 {
3791
+			ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate / 1000)
3792
+
3793
+			record.UltrafiltrationVolume = ultrafiltration_volume
3794
+		}
3795
+	}
3796
+
3788 3797
 	if template.TemplateId == 47 || template.TemplateId == 54 {
3789 3798
 		record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
3790 3799
 	}

+ 79 - 88
controllers/drug_stock_api_contorller.go View File

@@ -3563,6 +3563,22 @@ func (c *StockDrugApiController) CheckWarehousingInfo() {
3563 3563
 			}
3564 3564
 
3565 3565
 			Creator := c.GetAdminUserInfo().AdminUser.Id
3566
+
3567
+			//查询默认仓库
3568
+
3569
+			//查询默认仓库剩余多少库存
3570
+			list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
3571
+			var sum_count int64
3572
+			var sum_in_count int64
3573
+			for _, it := range list {
3574
+				baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
3575
+				if it.MaxUnit == baseDrug.MaxUnit {
3576
+					it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
3577
+					it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
3578
+				}
3579
+				sum_count += it.StockMaxNumber + it.StockMinNumber
3580
+				sum_in_count += it.WarehousingCount
3581
+			}
3566 3582
 			flow := &models.DrugFlow{
3567 3583
 				WarehousingId:           0,
3568 3584
 				DrugId:                  item.DrugId,
@@ -3596,24 +3612,10 @@ func (c *StockDrugApiController) CheckWarehousingInfo() {
3596 3612
 				MaxUnit:                 item.MaxUnit,
3597 3613
 				MinUnit:                 item.MinUnit,
3598 3614
 				StorehouseId:            item.StorehouseId,
3615
+				OverCount:               sum_count,
3599 3616
 			}
3600 3617
 			service.CreateDrugFlowTwo(flow)
3601
-
3602
-			//查询默认仓库
3603
-
3604
-			//查询默认仓库剩余多少库存
3605
-			list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
3606
-			var sum_count int64
3607
-			var sum_in_count int64
3608
-			for _, it := range list {
3609
-				baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
3610
-				if it.MaxUnit == baseDrug.MaxUnit {
3611
-					it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
3612
-					it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
3613
-				}
3614
-				sum_count += it.StockMaxNumber + it.StockMinNumber
3615
-				sum_in_count += it.WarehousingCount
3616
-			}
3618
+			//更新基础库剩余库存
3617 3619
 			service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId)
3618 3620
 
3619 3621
 			drugInfolist, _ := service.GetDrugSumCountByStorehouseId(item.StorehouseId, item.OrgId, item.DrugId)
@@ -3630,7 +3632,6 @@ func (c *StockDrugApiController) CheckWarehousingInfo() {
3630 3632
 				total_count += it.WarehousingCount
3631 3633
 				over_count += it.StockMaxNumber + it.StockMinNumber
3632 3634
 			}
3633
-			fmt.Println("over_countwoowoowowow", over_count)
3634 3635
 			//查询该仓库是否有默认数据
3635 3636
 			_, errcode := service.GetDrugStockCount(item.StorehouseId, item.DrugId, item.OrgId)
3636 3637
 			if errcode == gorm.ErrRecordNotFound {
@@ -3772,11 +3773,6 @@ func (c *StockDrugApiController) CheckDrugOut() {
3772 3773
 			total_count += item.StockMaxNumber + item.StockMinNumber
3773 3774
 		}
3774 3775
 
3775
-		//if it.CountUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
3776
-		//	it.Count = it.Count * drup.MinNumber
3777
-		//}
3778
-		//out_count += it.Count
3779
-
3780 3776
 		//出库数量累加
3781 3777
 		if it.CountUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
3782 3778
 			out_count = it.Count * drup.MinNumber
@@ -3820,7 +3816,7 @@ func (c *StockDrugApiController) CheckDrugOut() {
3820 3816
 			}
3821 3817
 			sum_count += its.StockMaxNumber + its.StockMinNumber
3822 3818
 		}
3823
-
3819
+		//更新基础库库存
3824 3820
 		service.UpdateBaseDrugSumTwo(it.DrugId, sum_count, it.OrgId)
3825 3821
 
3826 3822
 		////出库数量累加
@@ -3837,7 +3833,6 @@ func (c *StockDrugApiController) CheckDrugOut() {
3837 3833
 			out_count_one = it.Count
3838 3834
 		}
3839 3835
 
3840
-		fmt.Println("out_count23233232323woede", out_count_one)
3841 3836
 		//增加出库数量
3842 3837
 		service.AddDrugCount(it.DrugId, it.OrgId, storeHouseConfig.DrugStorehouseOut, out_count_one)
3843 3838
 
@@ -3847,18 +3842,19 @@ func (c *StockDrugApiController) CheckDrugOut() {
3847 3842
 		for _, its := range infolist {
3848 3843
 			over_count += its.StockMaxNumber*medical.MinNumber + its.StockMinNumber
3849 3844
 		}
3845
+		//更新剩余库存
3850 3846
 		service.UpdateDrugStockCount(it.DrugId, it.OrgId, storeHouseConfig.DrugStorehouseOut, over_count)
3851 3847
 	}
3852 3848
 
3853 3849
 	out := models.DrugWarehouseOut{
3854 3850
 		IsCheck: 1,
3855 3851
 	}
3856
-
3852
+	//更新审核状态
3857 3853
 	service.UpdateCheckDrugOut(out, warehouse_out_id)
3858
-	info := models.DrugWarehouseOutInfo{
3859
-		IsCheck: 1,
3860
-	}
3861
-	service.UpdateCheckDrugOutInfo(info, warehouse_out_id)
3854
+	//info := models.DrugWarehouseOutInfo{
3855
+	//	IsCheck: 1,
3856
+	//}
3857
+	//service.UpdateCheckDrugOutInfo(info, warehouse_out_id)
3862 3858
 
3863 3859
 	c.ServeSuccessJSON(map[string]interface{}{
3864 3860
 		"warehousingOutInfoList": warehousingOutInfoList,
@@ -4056,77 +4052,20 @@ func (c *StockDrugApiController) CheckCancelDrugStock() {
4056 4052
 			}
4057 4053
 		}
4058 4054
 
4059
-		//查询该批次的退库数量
4060
-		drugFlow := models.DrugFlow{
4061
-			ID:                        0,
4062
-			WarehousingId:             its.BatchNumberId,
4063
-			DrugId:                    its.DrugId,
4064
-			Number:                    its.Number,
4065
-			BatchNumber:               "",
4066
-			Count:                     its.Count,
4067
-			UserOrgId:                 its.OrgId,
4068
-			PatientId:                 0,
4069
-			SystemTime:                cancelDrugStock.ReturnTime,
4070
-			ConsumableType:            4,
4071
-			IsSys:                     0,
4072
-			WarehousingOrder:          "",
4073
-			WarehouseOutId:            0,
4074
-			WarehouseOutOrderNumber:   "",
4075
-			IsEdit:                    0,
4076
-			CancelStockId:             0,
4077
-			CancelOrderNumber:         its.OrderNumber,
4078
-			Manufacturer:              manufacturer_id,
4079
-			Dealer:                    dealer_id,
4080
-			Creator:                   creater,
4081
-			UpdateCreator:             0,
4082
-			Status:                    1,
4083
-			Ctime:                     time.Now().Unix(),
4084
-			Mtime:                     0,
4085
-			Price:                     its.Price,
4086
-			WarehousingDetailId:       its.BatchNumberId,
4087
-			WarehouseOutDetailId:      0,
4088
-			CancelOutDetailId:         its.ID,
4089
-			ExpireDate:                its.ExpiryDate,
4090
-			ProductDate:               its.ProductDate,
4091
-			MaxUnit:                   its.MaxUnit,
4092
-			MinUnit:                   "",
4093
-			StockMaxNumber:            0,
4094
-			StockMinNumber:            0,
4095
-			LastStockMaxNumber:        0,
4096
-			LastStockMinNumber:        0,
4097
-			AdviceId:                  0,
4098
-			SupplyWarehouseId:         0,
4099
-			SupplyCancelOutId:         0,
4100
-			SupplyWarehouseDetailInfo: 0,
4101
-			StorehouseId:              its.StorehouseId,
4102
-			SecondWarehouseInfoId:     0,
4103
-			AdminUserId:               0,
4104
-			LastPrice:                 0,
4105
-			StockCount:                "",
4106
-			PharmacyId:                0,
4107
-		}
4108
-		service.CreateDrugFlowOne(drugFlow)
4109
-
4110 4055
 		medical, _ := service.GetBaseDrugMedical(its.DrugId)
4111 4056
 		if its.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
4112 4057
 			var sum_cancel_count int64
4113 4058
 			sum_cancel_count += its.Count * medical.MinNumber
4114
-			//退库数量增加
4115
-			//service.ModifyAddCancelAddInfomation(its.DrugId,sum_cancel_count,its.OrgId,its.StorehouseId)
4116 4059
 			//出库数量减少
4117 4060
 			service.ModifyAddDrugOutReduceInfomation(its.DrugId, sum_cancel_count, its.OrgId, its.StorehouseId)
4118 4061
 		}
4119 4062
 
4120 4063
 		if its.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
4121
-			//退库数量增加
4122
-			//service.ModifyAddCancelAddInfomation(its.DrugId,its.Count,its.OrgId,its.StorehouseId)
4123 4064
 			//出库数量减少
4124 4065
 			service.ModifyAddDrugOutReduceInfomation(its.DrugId, its.Count, its.OrgId, its.StorehouseId)
4125 4066
 		}
4126 4067
 
4127 4068
 		if its.MaxUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
4128
-			//退库数量增加
4129
-			//service.ModifyAddCancelAddInfomation(its.DrugId,its.Count,its.OrgId,its.StorehouseId)
4130 4069
 			//出库数量减少
4131 4070
 			service.ModifyAddDrugOutReduceInfomation(its.DrugId, its.Count, its.OrgId, its.StorehouseId)
4132 4071
 		}
@@ -4159,7 +4098,7 @@ func (c *StockDrugApiController) CheckCancelDrugStock() {
4159 4098
 			}
4160 4099
 			sum_count += its.StockMaxNumber + its.StockMinNumber
4161 4100
 		}
4162
-
4101
+		//更新剩余库存
4163 4102
 		service.UpdateBaseDrugSumTwo(its.DrugId, sum_count, its.OrgId)
4164 4103
 
4165 4104
 		var cancel_count int64
@@ -4181,8 +4120,60 @@ func (c *StockDrugApiController) CheckCancelDrugStock() {
4181 4120
 			}
4182 4121
 			over_count += its.StockMaxNumber + its.StockMinNumber
4183 4122
 		}
4123
+		//查询该批次的退库数量
4124
+		drugFlow := models.DrugFlow{
4125
+			ID:                        0,
4126
+			WarehousingId:             its.BatchNumberId,
4127
+			DrugId:                    its.DrugId,
4128
+			Number:                    its.Number,
4129
+			BatchNumber:               "",
4130
+			Count:                     its.Count,
4131
+			UserOrgId:                 its.OrgId,
4132
+			PatientId:                 0,
4133
+			SystemTime:                cancelDrugStock.ReturnTime,
4134
+			ConsumableType:            4,
4135
+			IsSys:                     0,
4136
+			WarehousingOrder:          "",
4137
+			WarehouseOutId:            0,
4138
+			WarehouseOutOrderNumber:   "",
4139
+			IsEdit:                    0,
4140
+			CancelStockId:             0,
4141
+			CancelOrderNumber:         its.OrderNumber,
4142
+			Manufacturer:              manufacturer_id,
4143
+			Dealer:                    dealer_id,
4144
+			Creator:                   creater,
4145
+			UpdateCreator:             0,
4146
+			Status:                    1,
4147
+			Ctime:                     time.Now().Unix(),
4148
+			Mtime:                     0,
4149
+			Price:                     its.Price,
4150
+			WarehousingDetailId:       its.BatchNumberId,
4151
+			WarehouseOutDetailId:      0,
4152
+			CancelOutDetailId:         its.ID,
4153
+			ExpireDate:                its.ExpiryDate,
4154
+			ProductDate:               its.ProductDate,
4155
+			MaxUnit:                   its.MaxUnit,
4156
+			MinUnit:                   "",
4157
+			StockMaxNumber:            0,
4158
+			StockMinNumber:            0,
4159
+			LastStockMaxNumber:        0,
4160
+			LastStockMinNumber:        0,
4161
+			AdviceId:                  0,
4162
+			SupplyWarehouseId:         0,
4163
+			SupplyCancelOutId:         0,
4164
+			SupplyWarehouseDetailInfo: 0,
4165
+			StorehouseId:              its.StorehouseId,
4166
+			SecondWarehouseInfoId:     0,
4167
+			AdminUserId:               0,
4168
+			LastPrice:                 0,
4169
+			StockCount:                "",
4170
+			PharmacyId:                0,
4171
+			OverCount:                 over_count,
4172
+		}
4173
+		service.CreateDrugFlowOne(drugFlow)
4174
+		//增加退库数量 更新剩余库存
4184 4175
 		service.AddCancelSumCount(its.StorehouseId, its.DrugId, its.OrgId, cancel_count, over_count)
4185
-
4176
+		//更改审核状态
4186 4177
 		service.ModifyCancelStock(cancelstock_id, cancelStock, orgId)
4187 4178
 	}
4188 4179
 	//新增库存

+ 1 - 8
controllers/his_api_controller.go View File

@@ -1621,10 +1621,6 @@ func (c *HisApiController) CreateHisPrescription() {
1621 1621
 										goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
1622 1622
 
1623 1623
 										for _, item := range goodList {
1624
-											//回退库存
1625
-											//service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
1626
-
1627
-											//service.ModifyReduceGoodSumCount(item.StorehouseId,item.Count,item.OrgId,item.GoodId)
1628 1624
 
1629 1625
 											goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
1630 1626
 											var flush_count int64
@@ -1667,10 +1663,6 @@ func (c *HisApiController) CreateHisPrescription() {
1667 1663
 											goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
1668 1664
 
1669 1665
 											for _, item := range goodList {
1670
-												//回退库存
1671
-												//service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
1672
-												//扣减出库数量
1673
-												//service.ModifyReduceGoodSumCount(item.StorehouseId,item.Count,item.OrgId,item.GoodId)
1674 1666
 
1675 1667
 												goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
1676 1668
 												var flush_count int64
@@ -2168,6 +2160,7 @@ func (c *HisApiController) CreateHisPrescription() {
2168 2160
 						}
2169 2161
 						sum_count += its.StockMaxNumber + its.StockMinNumber
2170 2162
 					}
2163
+					//更新基础库存
2171 2164
 					service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
2172 2165
 					//剩余库存
2173 2166
 					service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)

+ 12 - 10
controllers/mobile_api_controllers/dialysis_api_controller.go View File

@@ -2923,12 +2923,8 @@ func (this *DialysisAPIController) GetLastMonitorRecordTody() {
2923 2923
 			if template.TemplateId == 6 && adminInfo.Org.Id != 9538 {
2924 2924
 				ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
2925 2925
 				record.UltrafiltrationRate = ultrafiltration_rate
2926
+
2926 2927
 			}
2927
-			//if template.TemplateId == 6 && adminInfo.Org.Id ==9671{
2928
-			//  dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
2929
-			//  ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
2930
-			//  record.UltrafiltrationRate = ultrafiltration_rate
2931
-			//}
2932 2928
 
2933 2929
 			if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
2934 2930
 
@@ -2947,10 +2943,9 @@ func (this *DialysisAPIController) GetLastMonitorRecordTody() {
2947 2943
 				ultrafiltration_rate = value
2948 2944
 				record.UltrafiltrationRate = ultrafiltration_rate
2949 2945
 			}
2950
-			fmt.Println("hhh23232323223232323323232323", template.TemplateId)
2946
+
2951 2947
 			if template.TemplateId == 41 || template.TemplateId == 47 {
2952 2948
 				ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
2953
-				fmt.Println("prescritpin2332322323232323223", ultrafiltration_rate)
2954 2949
 				record.UltrafiltrationRate = ultrafiltration_rate
2955 2950
 			}
2956 2951
 
@@ -2989,6 +2984,14 @@ func (this *DialysisAPIController) GetLastMonitorRecordTody() {
2989 2984
 		}
2990 2985
 	}
2991 2986
 
2987
+	if adminInfo.Org.Id == 10395 {
2988
+		if ultrafiltration_rate > 0 {
2989
+			ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate / 1000)
2990
+			record.UltrafiltrationVolume = ultrafiltration_volume
2991
+		}
2992
+
2993
+	}
2994
+
2992 2995
 	if template.TemplateId == 47 || template.TemplateId == 54 {
2993 2996
 		record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
2994 2997
 	}
@@ -6113,7 +6116,6 @@ func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int6
6113 6116
 				StorehouseId: houseConfig.StorehouseOutInfo,
6114 6117
 			}
6115 6118
 
6116
-			fmt.Println("出库数量23333333333333333333333332😯😯😯😯", prepare.Count)
6117 6119
 			service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
6118 6120
 
6119 6121
 			//增加出库数量
@@ -6150,7 +6152,7 @@ func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *mod
6150 6152
 		} else {
6151 6153
 			delete_count = ware.Count
6152 6154
 		}
6153
-		// 在出库记录表里记录退库详情
6155
+
6154 6156
 		warehouseOutInfo := &models.WarehouseOutInfo{
6155 6157
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
6156 6158
 			WarehouseOutId:          warehouseOut.ID,
@@ -6265,7 +6267,7 @@ func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *model
6265 6267
 	//增加退库数量
6266 6268
 	service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
6267 6269
 
6268
-	//扣减出库数量
6270
+	//扣减出库数量
6269 6271
 	service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
6270 6272
 	//查询剩余库存
6271 6273
 	goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID)

+ 8 - 8
controllers/patient_api_controller.go View File

@@ -751,14 +751,14 @@ func (c *PatientApiController) EditLapseto() {
751 751
 
752 752
 	err = service.EditPatientLapseto(&patient, &lapseto)
753 753
 
754
-	if lapseto.LapsetoType == 3 || lapseto.LapsetoType == 2 {
755
-		timeStr := time.Now().Format("2006-01-02")
756
-		timeLayout := "2006-01-02 15:04:05"
757
-		timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
758
-		timenow := timeStringToTime.Unix()
759
-		service.UpdateScheduleByDeathTime(id, timenow)
760
-		service.UpdateScheduleItemByPatientId(id)
761
-	}
754
+	//if lapseto.LapsetoType == 3 || lapseto.LapsetoType == 2 {
755
+	//	timeStr := time.Now().Format("2006-01-02")
756
+	//	timeLayout := "2006-01-02 15:04:05"
757
+	//	timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
758
+	//	timenow := timeStringToTime.Unix()
759
+	//	service.UpdateScheduleByDeathTime(id, timenow)
760
+	//	service.UpdateScheduleItemByPatientId(id)
761
+	//}
762 762
 
763 763
 	if err != nil {
764 764
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeEditLapsetoFail)

+ 353 - 0
controllers/self_drug_api_congtroller.go View File

@@ -106,6 +106,10 @@ func SelfDrugRouters() {
106 106
 	beego.Router("/api/stock/tosendgoodinfomation", &SelfDrugApiController{}, "Get:GetSendGoodInformation")
107 107
 	//药品脚本
108 108
 	beego.Router("/api/drug/getdruginitdatalist", &SelfDrugApiController{}, "Get:GetDrugInitDetailList")
109
+
110
+	//新数据
111
+	beego.Router("/api/stock/getnewpurchasestockquery", &SelfDrugApiController{}, "Get:GetGoodNewPurchaseStockQuery")
112
+	beego.Router("/api/stock/getpurchasenewdrugquery", &SelfDrugApiController{}, "Get:GetPurchaseNewDrugQuery")
109 113
 }
110 114
 
111 115
 func (this *SelfDrugApiController) GetCurrentPatient() {
@@ -2658,6 +2662,7 @@ func (this *SelfDrugApiController) SaveInventoryList() {
2658 2662
 				MaxUnit:                 min_unit,
2659 2663
 				MinUnit:                 min_unit,
2660 2664
 				StorehouseId:            storehouse_id,
2665
+				OverCount:               sum_count,
2661 2666
 			}
2662 2667
 			if ord_total != new_total {
2663 2668
 				service.CreateDrugFlowOne(flow)
@@ -3608,3 +3613,351 @@ func (this *SelfDrugApiController) GetDrugInitDetailList() {
3608 3613
 		"msg": "1",
3609 3614
 	})
3610 3615
 }
3616
+
3617
+func (this *SelfDrugApiController) GetGoodNewPurchaseStockQuery() {
3618
+
3619
+	good_type, _ := this.GetInt64("good_type")
3620
+
3621
+	keyword := this.GetString("keyword")
3622
+
3623
+	page, _ := this.GetInt64("page")
3624
+
3625
+	limit, _ := this.GetInt64("limit")
3626
+
3627
+	start_time := this.GetString("start_time")
3628
+	end_time := this.GetString("end_time")
3629
+	orgId := this.GetAdminUserInfo().CurrentOrgId
3630
+	timeLayout := "2006-01-02"
3631
+	loc, _ := time.LoadLocation("Local")
3632
+	var startTime int64
3633
+
3634
+	if len(start_time) > 0 {
3635
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
3636
+		if err != nil {
3637
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3638
+			return
3639
+		}
3640
+		startTime = theTime.Unix()
3641
+	}
3642
+
3643
+	var endTime int64
3644
+	if len(end_time) > 0 {
3645
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
3646
+		if err != nil {
3647
+			utils.ErrorLog(err.Error())
3648
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3649
+			return
3650
+		}
3651
+		endTime = theTime.Unix()
3652
+	}
3653
+	var ids []int64
3654
+	var goodIds []int64
3655
+	infoList, _ := service.GetGoodWarehouseInfoByOrgIdTwo(orgId)
3656
+	for _, it := range infoList {
3657
+		goodIds = append(goodIds, it.GoodId)
3658
+	}
3659
+
3660
+	manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
3661
+	for _, it := range manufacturers {
3662
+		ids = append(ids, it.ID)
3663
+	}
3664
+	manufacturerList, _ := service.GetAllManufacturerList(orgId)
3665
+	list, total, err := service.GetGoodNewPurchaseStockQuery(good_type, keyword, page, limit, orgId, ids, goodIds)
3666
+
3667
+	for _, item := range list {
3668
+
3669
+		//获取期初结余
3670
+		low, _ := service.GetStartLastFLow(item.ID, orgId, startTime)
3671
+
3672
+		item.GoodStartFlowInfo = low
3673
+
3674
+		//获取期末结余
3675
+		flow, _ := service.GetEndLastFlow(item.ID, orgId, endTime)
3676
+
3677
+		item.GoodEndFlowInfo = flow
3678
+
3679
+		//获取期初结余数量
3680
+		//infoList, _ := service.GetStartGoodWarehouseInfoList(item.ID, orgId, startTime)
3681
+		//for _, it := range infoList {
3682
+		//  item.WarehousingInfoStart = append(item.WarehousingInfoStart, it)
3683
+		//}
3684
+		//
3685
+		////获取期末结余数量
3686
+		//warehouseInfoList, _ := service.GetEndGoodWarehouseInfoList(item.ID, orgId, endTime)
3687
+		//for _, it := range warehouseInfoList {
3688
+		//  item.WarehousingInfoEnd = append(item.WarehousingInfoEnd, it)
3689
+		//}
3690
+
3691
+		//获取期间增加
3692
+		goodWarehouseInfoList, _ := service.GetAddGoodWarehouseInfoList(item.ID, orgId, startTime, endTime)
3693
+		for _, it := range goodWarehouseInfoList {
3694
+			item.WarehousingInfoOne = append(item.WarehousingInfoOne, it)
3695
+		}
3696
+
3697
+		//获取本期增加
3698
+		WarehouseInfoFlowList, _ := service.GetAddStartFlow(item.ID, orgId, startTime, endTime)
3699
+		for _, it := range WarehouseInfoFlowList {
3700
+			item.StartFlowWarehouseInfo = append(item.StartFlowWarehouseInfo, it)
3701
+		}
3702
+		//获取本期减少
3703
+		reduceWarehouseInfoList, _ := service.GetReduceWarehouseInfoList(item.ID, orgId, startTime, endTime)
3704
+		for _, it := range reduceWarehouseInfoList {
3705
+			item.WarehouseOutInfoStart = append(item.WarehouseOutInfoStart, it)
3706
+		}
3707
+
3708
+		//获取期中减少退库
3709
+		lowInfo, _ := service.GetStartEndCancelFLowInfo(item.ID, orgId, startTime, endTime)
3710
+		for _, it := range lowInfo {
3711
+			item.StartEndCancelFLowInfo = append(item.StartEndCancelFLowInfo, it)
3712
+		}
3713
+		//
3714
+		outInfo, _ := service.FindeWarehouseOutInfo(item.ID, orgId, startTime)
3715
+		for _, it := range outInfo {
3716
+			item.WarehouseOutInfoEnd = append(item.WarehouseOutInfoEnd, it)
3717
+		}
3718
+
3719
+		////获取期初结余
3720
+		//info, _ := service.FindeStartFlowInfo(item.ID, orgId, startTime)
3721
+		//for _, it := range info {
3722
+		//  item.StartFlowInfo = append(item.StartFlowInfo, it)
3723
+		//}
3724
+		////获取期初结余
3725
+		//flowOutInfo, _ := service.FindeStartFlowOutInfo(item.ID, orgId, startTime)
3726
+		//for _, it := range flowOutInfo {
3727
+		//  item.StartOutFlowInfo = append(item.StartOutFlowInfo, it)
3728
+		//}
3729
+		//
3730
+		////获取期初退库
3731
+		//cancelInfo, _ := service.FindeStartCancelInfo(item.ID, orgId, startTime)
3732
+		//for _, it := range cancelInfo {
3733
+		//  item.StartCancelFlowInfo = append(item.StartCancelFlowInfo, it)
3734
+		//}
3735
+
3736
+		////获取期末结余
3737
+		//flowInfo, _ := service.FindEndStartFlowInfo(item.ID, orgId, endTime)
3738
+		//for _, it := range flowInfo {
3739
+		//  item.EndFlowInfo = append(item.EndFlowInfo, it)
3740
+		//}
3741
+		//
3742
+		////获取期末出库
3743
+		//lowOutInfo, _ := service.FindeEndFLowOutInfo(item.ID, orgId, endTime)
3744
+		//for _, it := range lowOutInfo {
3745
+		//  item.EndFlowOutInfo = append(item.EndFlowOutInfo, it)
3746
+		//}
3747
+		//
3748
+		////获取期末退库
3749
+		//endCancelInfo, _ := service.FindEndCancelInfo(item.ID, orgId, endTime)
3750
+		//for _, it := range endCancelInfo {
3751
+		//  item.EndCancelFLowInfo = append(item.EndCancelFLowInfo, it)
3752
+		//}
3753
+
3754
+		////期初盘赢
3755
+		//inventory, _ := service.FindeStartStockInventoryProfit(item.ID, orgId, startTime)
3756
+		//for _, it := range inventory {
3757
+		//  item.WareStartStockInventoryProfit = append(item.WareStartStockInventoryProfit, it)
3758
+		//}
3759
+		////期初盘亏
3760
+		//stockInventory, _ := service.FindStartStockInventoryLosses(item.ID, orgId, startTime)
3761
+		//for _, it := range stockInventory {
3762
+		//  item.WareStartStockInventoryLosses = append(item.WareStartStockInventoryLosses, it)
3763
+		//}
3764
+
3765
+		////期末盘盈
3766
+		//inventoryProfit, _ := service.FindeStartStockInventoryProfit(item.ID, orgId, endTime)
3767
+		//for _, it := range inventoryProfit {
3768
+		//  item.WareEndStockInventoryProfit = append(item.WareEndStockInventoryProfit, it)
3769
+		//}
3770
+		////期末盘亏
3771
+		//inventoryLosses, _ := service.FindStartStockInventoryLosses(item.ID, orgId, endTime)
3772
+		//for _, it := range inventoryLosses {
3773
+		//  item.WareEndStockInventoryLosses = append(item.WareEndStockInventoryLosses, it)
3774
+		//}
3775
+
3776
+		//期中盘盈
3777
+		profit, _ := service.FindeEndStokInventoryProfit(item.ID, orgId, startTime, endTime)
3778
+		for _, it := range profit {
3779
+			item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
3780
+		}
3781
+		//期中盘亏
3782
+		losses, _ := service.FindeEndStockInventoryLosses(item.ID, orgId, startTime, endTime)
3783
+		for _, it := range losses {
3784
+			item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
3785
+		}
3786
+	}
3787
+
3788
+	if err != nil {
3789
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
3790
+		return
3791
+	}
3792
+
3793
+	this.ServeSuccessJSON(map[string]interface{}{
3794
+		"list":             list,
3795
+		"manufacturerList": manufacturerList,
3796
+		"total":            total,
3797
+	})
3798
+}
3799
+
3800
+func (this *SelfDrugApiController) GetPurchaseNewDrugQuery() {
3801
+
3802
+	good_type, _ := this.GetInt64("good_type")
3803
+
3804
+	keyword := this.GetString("keyword")
3805
+
3806
+	page, _ := this.GetInt64("page")
3807
+
3808
+	limit, _ := this.GetInt64("limit")
3809
+
3810
+	start_time := this.GetString("start_time")
3811
+	end_time := this.GetString("end_time")
3812
+	orgId := this.GetAdminUserInfo().CurrentOrgId
3813
+	timeLayout := "2006-01-02"
3814
+	loc, _ := time.LoadLocation("Local")
3815
+
3816
+	var startTime int64
3817
+
3818
+	if len(start_time) > 0 {
3819
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
3820
+		if err != nil {
3821
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3822
+			return
3823
+		}
3824
+		startTime = theTime.Unix()
3825
+	}
3826
+
3827
+	var endTime int64
3828
+	if len(end_time) > 0 {
3829
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
3830
+		if err != nil {
3831
+			utils.ErrorLog(err.Error())
3832
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3833
+			return
3834
+		}
3835
+		endTime = theTime.Unix()
3836
+	}
3837
+	var ids []int64
3838
+	var infoIds []int64
3839
+
3840
+	manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
3841
+	for _, it := range manufacturers {
3842
+		ids = append(ids, it.ID)
3843
+	}
3844
+	infoList, _ := service.GetDrugWarehouseInfoByOrgIdTwo(orgId)
3845
+	for _, it := range infoList {
3846
+		infoIds = append(infoIds, it.DrugId)
3847
+	}
3848
+	manufacturerList, _ := service.GetAllManufacturerList(orgId)
3849
+	list, total, err := service.GetDrugNewPurchaseStockQuery(good_type, keyword, page, limit, orgId, startTime, endTime, ids, infoIds)
3850
+
3851
+	for _, item := range list {
3852
+
3853
+		//获取期初结余
3854
+		flow, _ := service.GetDrugStartFlow(item.ID, orgId, startTime)
3855
+
3856
+		item.DrugStatFlow = flow
3857
+
3858
+		//获取期末结余
3859
+		endFlow, _ := service.GetDrugEndFlow(item.ID, orgId, endTime)
3860
+
3861
+		item.DrugEndFlow = endFlow
3862
+		//获取期初结余入库数量
3863
+		//startDrugInfo, _ := service.GetDrugWarehouseInfoStart(item.ID, orgId, startTime)
3864
+		//for _, it := range startDrugInfo {
3865
+		//  item.DrugWarehouseInfoStart = append(item.DrugWarehouseInfoStart, it)
3866
+		//}
3867
+		//
3868
+		////获取期初结余出库数量
3869
+		//flowOutList, _ := service.GetDrugFlowOut(item.ID, orgId, startTime)
3870
+		//for _, it := range flowOutList {
3871
+		//  item.DrugWarehouseOutInfoStart = append(item.DrugWarehouseOutInfoStart, it)
3872
+		//}
3873
+		//
3874
+		////获取期初结余退库数量
3875
+		//cancelInfo, _ := service.GetStartDrugFlowCancelInfo(item.ID, orgId, startTime)
3876
+		//for _, it := range cancelInfo {
3877
+		//  item.WareStartStockCancelInfo = append(item.WareStartStockCancelInfo, it)
3878
+		//}
3879
+		//
3880
+		////获取期末结余入库数量
3881
+		//drugwarehouseinfoend, _ := service.DrugWarehouseInfoEnd(item.ID, orgId, endTime)
3882
+		//for _, it := range drugwarehouseinfoend {
3883
+		//  item.DrugWarehouseInfoEnd = append(item.DrugWarehouseInfoEnd, it)
3884
+		//}
3885
+
3886
+		////获取期末出库结余
3887
+		//endDrugInfo, _ := service.DrugWarehouseOutInfoEnd(item.ID, orgId, endTime)
3888
+		//for _, it := range endDrugInfo {
3889
+		//  item.DrugWarehouseOutInfoEnd = append(item.DrugWarehouseOutInfoEnd, it)
3890
+		//}
3891
+		//
3892
+		////获取期末退库数量
3893
+		//flowCancelInfo, _ := service.GetEndDrugFlowCancelInfo(item.ID, orgId, endTime)
3894
+		//for _, it := range flowCancelInfo {
3895
+		//  item.WareEndStockCancelInfo = append(item.WareEndStockCancelInfo, it)
3896
+		//}
3897
+
3898
+		//期中增加
3899
+		drugWarehouse, _ := service.GetDrugWarehouseStartEnd(item.ID, orgId, startTime, endTime)
3900
+		for _, it := range drugWarehouse {
3901
+			item.DrugWarehouseInfoStartEnd = append(item.DrugWarehouseInfoStartEnd, it)
3902
+		}
3903
+
3904
+		//期中减少
3905
+		outInfo, _ := service.FindeDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
3906
+		for _, it := range outInfo {
3907
+			item.DrugWarehouseOutInfoStartEnd = append(item.DrugWarehouseOutInfoStartEnd, it)
3908
+		}
3909
+
3910
+		//期中退库
3911
+		cancelstartInfo, _ := service.FindStartEndDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
3912
+		for _, it := range cancelstartInfo {
3913
+			item.WareStartEndStockCancelInfo = append(item.WareStartEndStockCancelInfo, it)
3914
+		}
3915
+
3916
+		////获取期初盘盈
3917
+		//startProfit, _ := service.GetDrugFlowStartProfit(item.ID, orgId, startTime)
3918
+		//for _, it := range startProfit {
3919
+		//  item.WareStartStockInventoryProfit = append(item.WareStartStockInventoryProfit, it)
3920
+		//}
3921
+		////获取期初盘亏
3922
+		//startLosses, _ := service.GetDrugFlowStartLosses(item.ID, orgId, startTime)
3923
+		//for _, it := range startLosses {
3924
+		//  item.WareStartStockInventoryLosses = append(item.WareStartStockInventoryLosses, it)
3925
+		//}
3926
+		////获取期末盘盈
3927
+		//endProfit, _ := service.GetDrugFlowEndProfit(item.ID, orgId, endTime)
3928
+		//for _, it := range endProfit {
3929
+		//  item.WareEndStockInventoryProfit = append(item.WareEndStockInventoryProfit, it)
3930
+		//}
3931
+		////获取期末盘亏
3932
+		//losses, _ := service.GetDrugFlowEndLosses(item.ID, orgId, endTime)
3933
+		//for _, it := range losses {
3934
+		//  item.WareEndStockInventoryLosses = append(item.WareEndStockInventoryLosses, it)
3935
+		//}
3936
+
3937
+		//获取期中盘盈
3938
+		profit, _ := service.GetDrugFlowStartEndProfit(item.ID, orgId, startTime, endTime)
3939
+		for _, it := range profit {
3940
+			item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
3941
+		}
3942
+
3943
+		//获取期中盘亏
3944
+		endLosses, _ := service.GetDrugFlowStartEndLosses(item.ID, orgId, startTime, endTime)
3945
+		for _, it := range endLosses {
3946
+			item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
3947
+		}
3948
+	}
3949
+	if err != nil {
3950
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
3951
+		return
3952
+	}
3953
+	var drugType = "药品类型"
3954
+	drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
3955
+	drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
3956
+
3957
+	this.ServeSuccessJSON(map[string]interface{}{
3958
+		"list":             list,
3959
+		"manufacturerList": manufacturerList,
3960
+		"total":            total,
3961
+		"drugTypeList":     drugTypeList,
3962
+	})
3963
+}

+ 60 - 54
controllers/stock_in_api_controller.go View File

@@ -7046,7 +7046,7 @@ func (this *StockManagerApiController) CheckWarehouseOut() {
7046 7046
 		err := service.ConsumablesDeliveryThirty(orgId, item.SysRecordTime, item, &warehouseOut, item.Count, creater)
7047 7047
 		if err != nil {
7048 7048
 			goodErrcode := models.XtGoodErrcode{
7049
-				UserOrgId:      item.OrgId,
7049
+				UserOrgId:      orgId,
7050 7050
 				Errcode:        "调用出库接口报错",
7051 7051
 				GoodId:         item.GoodId,
7052 7052
 				Status:         1,
@@ -7069,7 +7069,7 @@ func (this *StockManagerApiController) CheckWarehouseOut() {
7069 7069
 		errs := service.UpdateSumGood(orgId, item.StorehouseId, item.GoodId, flush_count)
7070 7070
 		if errs != nil {
7071 7071
 			goodErrcode := models.XtGoodErrcode{
7072
-				UserOrgId:      item.OrgId,
7072
+				UserOrgId:      orgId,
7073 7073
 				Errcode:        "手动出库更新剩余出库失败",
7074 7074
 				GoodId:         item.GoodId,
7075 7075
 				Status:         1,
@@ -7096,7 +7096,7 @@ func (this *StockManagerApiController) CheckWarehouseOut() {
7096 7096
 		errsum := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, orgId)
7097 7097
 		if errsum != nil {
7098 7098
 			goodErrcode := models.XtGoodErrcode{
7099
-				UserOrgId:      item.OrgId,
7099
+				UserOrgId:      orgId,
7100 7100
 				Errcode:        "基础库扣减库存报错",
7101 7101
 				GoodId:         item.GoodId,
7102 7102
 				Status:         1,
@@ -7313,15 +7313,35 @@ func (this *StockManagerApiController) CheckWarehouseInfo() {
7313 7313
 
7314 7314
 	warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
7315 7315
 	orgId := this.GetAdminUserInfo().CurrentOrgId
7316
+	Creator := this.GetAdminUserInfo().AdminUser.Id
7316 7317
 	//查询默认仓库
7317 7318
 	storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
7318 7319
 	//更改审核状态
7319 7320
 	err := service.UpdateCheckWarehouseInfo(warehousing_info_id)
7320 7321
 	if err == nil {
7321 7322
 		list, _ := service.GetWarehouseInfoList(warehousing_info_id, orgId)
7322
-		Creator := this.GetAdminUserInfo().AdminUser.Id
7323
+
7323 7324
 		for _, item := range list {
7324 7325
 			service.UpdateWarehouseInfoByIdList(item.WarehousingCount, item.ID)
7326
+
7327
+			//查询该耗材剩余库存库
7328
+			stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId)
7329
+			var total_count int64
7330
+			var sum_in_count int64
7331
+			for _, it := range stockList {
7332
+				total_count += it.StockCount
7333
+				sum_in_count += it.WarehousingCount
7334
+			}
7335
+			//基础库插入数据
7336
+			service.UpdateGoodInfoAddSumCount(item.GoodId, total_count, orgId, sum_in_count)
7337
+
7338
+			//查询该仓库是否有数据
7339
+			_, errcode := service.GetGoodStockCount(orgId, item.StorehouseId, item.GoodId)
7340
+			goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
7341
+			var flush_count int64
7342
+			for _, it := range goodList {
7343
+				flush_count += it.StockCount
7344
+			}
7325 7345
 			stockFlow := models.VmStockFlow{
7326 7346
 				WarehousingId:           item.WarehousingId,
7327 7347
 				GoodId:                  item.GoodId,
@@ -7359,29 +7379,11 @@ func (this *StockManagerApiController) CheckWarehouseInfo() {
7359 7379
 				StockCount:              "",
7360 7380
 				BatchNumberCount:        item.WarehousingCount,
7361 7381
 				IsCheck:                 1,
7382
+				OverCount:               flush_count,
7362 7383
 			}
7363 7384
 			//创建出库流水
7364 7385
 			service.CreateStockFlowOne(stockFlow)
7365 7386
 
7366
-			orgId := this.GetAdminUserInfo().CurrentOrgId
7367
-			//查询该耗材剩余库存库
7368
-			stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId)
7369
-			var total_count int64
7370
-			var sum_in_count int64
7371
-			for _, it := range stockList {
7372
-				total_count += it.StockCount
7373
-				sum_in_count += it.WarehousingCount
7374
-			}
7375
-			//基础库插入数据
7376
-			service.UpdateGoodInfoAddSumCount(item.GoodId, total_count, orgId, sum_in_count)
7377
-
7378
-			//查询该仓库是否有数据
7379
-			_, errcode := service.GetGoodStockCount(orgId, item.StorehouseId, item.GoodId)
7380
-			goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
7381
-			var flush_count int64
7382
-			for _, it := range goodList {
7383
-				flush_count += it.StockCount
7384
-			}
7385 7387
 			if errcode == gorm.ErrRecordNotFound {
7386 7388
 
7387 7389
 				goodCount := models.XtGoodStockCount{
@@ -7480,16 +7482,7 @@ func (this *StockManagerApiController) CheckStockWarehouseInfo() {
7480 7482
 	var out_total_count int64
7481 7483
 	var dealer_id int64
7482 7484
 	for _, item := range list {
7483
-		for _, items := range manufacturerlist {
7484
-			if item.Manufacturer == items.ManufacturerName {
7485
-				manufacturer_id = items.ID
7486
-			}
7487
-		}
7488
-		for _, it := range dealerList {
7489
-			if item.Dealer == it.DealerName {
7490
-				dealer_id = it.ID
7491
-			}
7492
-		}
7485
+
7493 7486
 		//查询该药品该批次的出库数量是否满足退库需求
7494 7487
 		outList, _ := service.GetWarehouseOutList(item.OrgId, item.GoodId, item.WarehouseInfoId)
7495 7488
 		for _, it := range outList {
@@ -7508,6 +7501,37 @@ func (this *StockManagerApiController) CheckStockWarehouseInfo() {
7508 7501
 			})
7509 7502
 			return
7510 7503
 		}
7504
+	}
7505
+
7506
+	cancelStock := models.CancelStock{
7507
+		IsCheck: 1,
7508
+	}
7509
+	service.CheckCancelStock(cancelStock, cancel_stock_id, orgId)
7510
+
7511
+	//回退库存
7512
+	cancellist, _ := service.GetCancelStockInfoById(cancel_stock_id, orgId)
7513
+	for _, item := range cancellist {
7514
+		for _, items := range manufacturerlist {
7515
+			if item.Manufacturer == items.ManufacturerName {
7516
+				manufacturer_id = items.ID
7517
+			}
7518
+		}
7519
+		for _, it := range dealerList {
7520
+			if item.Dealer == it.DealerName {
7521
+				dealer_id = it.ID
7522
+			}
7523
+		}
7524
+		//回退库存
7525
+		service.UpdateCancelStockNumber(item.Count, item.WarehouseInfoId, orgId)
7526
+		//更新基础库库存
7527
+		service.UpdateGoodSumCount(item.Count, item.GoodId, orgId)
7528
+		goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
7529
+		//退库数量增加
7530
+		service.UpdateSumAddCancelCount(orgId, item.GoodId, item.StorehouseId, item.Count)
7531
+		var flush_count int64
7532
+		for _, it := range goodList {
7533
+			flush_count += it.StockCount
7534
+		}
7511 7535
 
7512 7536
 		stockFlow := models.VmStockFlow{
7513 7537
 			ID:                        0,
@@ -7550,29 +7574,11 @@ func (this *StockManagerApiController) CheckStockWarehouseInfo() {
7550 7574
 			AdminUserId:               0,
7551 7575
 			BuyPrice:                  item.Price,
7552 7576
 			StockCount:                "",
7577
+			OverCount:                 flush_count,
7553 7578
 		}
7579
+		//创建流水
7554 7580
 		service.CreateStockFlowOne(stockFlow)
7555
-		service.ModifyAddCancelCount(item.Count, item.GoodId)
7556
-	}
7557
-
7558
-	cancelStock := models.CancelStock{
7559
-		IsCheck: 1,
7560
-	}
7561
-	service.CheckCancelStock(cancelStock, cancel_stock_id, orgId)
7562
-
7563
-	//回退库存
7564
-	cancellist, _ := service.GetCancelStockInfoById(cancel_stock_id, orgId)
7565
-	for _, item := range cancellist {
7566
-		service.UpdateCancelStockNumber(item.Count, item.WarehouseInfoId, orgId)
7567
-
7568
-		service.UpdateGoodSumCount(item.Count, item.GoodId, orgId)
7569
-		goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
7570
-
7571
-		service.UpdateSumAddCancelCount(orgId, item.GoodId, item.StorehouseId, item.Count)
7572
-		var flush_count int64
7573
-		for _, it := range goodList {
7574
-			flush_count += it.StockCount
7575
-		}
7581
+		//更新剩余库存
7576 7582
 		errs := service.UpdateSumGood(orgId, item.StorehouseId, item.GoodId, flush_count)
7577 7583
 
7578 7584
 		//出库数量减少

+ 7 - 0
models/new_stock_models.go View File

@@ -243,6 +243,11 @@ type GoodInfoTwenty struct {
243 243
 
244 244
 	WareStartEndStockInventoryProfit []*VmStockFlowTwenty //期间盘盈
245 245
 	WareStartEndStockInventoryLosses []*VmStockFlowTwenty //期间盘亏
246
+
247
+	//期初结余
248
+	GoodStartFlowInfo VmStockFlowTwenty
249
+	//期末结余
250
+	GoodEndFlowInfo VmStockFlowTwenty
246 251
 }
247 252
 
248 253
 func (GoodInfoTwenty) TableName() string {
@@ -357,6 +362,8 @@ type VmBaseDrugTwenty struct {
357 362
 	WareEndStockCancelInfo           []*DrugFlowTwenty //期末结余退库
358 363
 	WareStartEndStockCancelInfo      []*DrugFlowTwenty //期中减少退库
359 364
 
365
+	DrugStatFlow DrugFlowTwenty
366
+	DrugEndFlow  DrugFlowTwenty
360 367
 }
361 368
 
362 369
 func (VmBaseDrugTwenty) TableName() string {

+ 33 - 4
service/manage_center_service.go View File

@@ -2,7 +2,6 @@ package service
2 2
 
3 3
 import (
4 4
 	"XT_New/models"
5
-	"fmt"
6 5
 	"github.com/jinzhu/gorm"
7 6
 	"strconv"
8 7
 	"strings"
@@ -477,7 +476,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
477 476
 
478 477
 			if (over_count + out_count) <= sum_count {
479 478
 				if its.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
480
-					fmt.Println("进来1", its.Count)
479
+
481 480
 					//退库
482 481
 					warehouseInfo := models.DrugWarehouseInfo{
483 482
 						StockMinNumber: its.Count,
@@ -491,7 +490,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
491 490
 
492 491
 				}
493 492
 				if its.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
494
-					fmt.Println("进来2", its.Count)
493
+
495 494
 					warehouseInfo := models.DrugWarehouseInfo{
496 495
 						StockMaxNumber: its.Count,
497 496
 					}
@@ -504,7 +503,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
504 503
 				}
505 504
 
506 505
 				if its.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
507
-					fmt.Println("进来3", its.Count)
506
+
508 507
 					warehouseInfo := models.DrugWarehouseInfo{
509 508
 						StockMaxNumber: its.Count,
510 509
 					}
@@ -576,6 +575,15 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
576 575
 				IsCheck:          1,
577 576
 			}
578 577
 
578
+			//查询剩余库存
579
+			stockInfo, _ := GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
580
+			var sum_count int64
581
+			for _, its := range stockInfo {
582
+				if its.MaxUnit == drug.MaxUnit {
583
+					its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
584
+				}
585
+				sum_count += its.StockMaxNumber + its.StockMinNumber
586
+			}
579 587
 			flow := models.DrugFlow{
580 588
 				WarehousingId:           info.WarehouseInfoId,
581 589
 				DrugId:                  info.DrugId,
@@ -610,6 +618,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
610 618
 				MinUnit:                 "",
611 619
 				AdviceId:                info.AdviceId,
612 620
 				StorehouseId:            storeHouseConfig.DrugStorehouseOut,
621
+				OverCount:               sum_count,
613 622
 			}
614 623
 			CreatedCancelStock(cancelStockInfo)
615 624
 			CreateDrugFlowOne(flow)
@@ -675,6 +684,15 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
675 684
 				StorehouseId:     houseConfig.DrugStorehouseOut,
676 685
 				IsCheck:          1,
677 686
 			}
687
+			//查询剩余库存
688
+			stockInfo, _ := GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
689
+			var sum_count int64
690
+			for _, its := range stockInfo {
691
+				if its.MaxUnit == drug.MaxUnit {
692
+					its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
693
+				}
694
+				sum_count += its.StockMaxNumber + its.StockMinNumber
695
+			}
678 696
 
679 697
 			flow := models.DrugFlow{
680 698
 				WarehousingId:           info.WarehouseInfoId,
@@ -710,6 +728,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
710 728
 				MinUnit:                 "",
711 729
 				AdviceId:                info.AdviceId,
712 730
 				StorehouseId:            houseConfig.DrugStorehouseOut,
731
+				OverCount:               sum_count,
713 732
 			}
714 733
 			CreatedCancelStock(cancelStockInfo)
715 734
 			CreateDrugFlowOne(flow)
@@ -775,6 +794,15 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
775 794
 				StorehouseId:     houseConfig.DrugStorehouseOut,
776 795
 				IsCheck:          1,
777 796
 			}
797
+			//查询剩余库存
798
+			stockInfo, _ := GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
799
+			var sum_count int64
800
+			for _, its := range stockInfo {
801
+				if its.MaxUnit == drug.MaxUnit {
802
+					its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
803
+				}
804
+				sum_count += its.StockMaxNumber + its.StockMinNumber
805
+			}
778 806
 
779 807
 			flow := models.DrugFlow{
780 808
 				WarehousingId:           info.WarehouseInfoId,
@@ -810,6 +838,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
810 838
 				MinUnit:                 "",
811 839
 				AdviceId:                info.AdviceId,
812 840
 				StorehouseId:            houseConfig.DrugStorehouseOut,
841
+				OverCount:               sum_count,
813 842
 			}
814 843
 			CreatedCancelStock(cancelStockInfo)
815 844
 			CreateDrugFlowOne(flow)

+ 4 - 0
service/new_warehouse_service.go View File

@@ -269,6 +269,7 @@ func ConsumablesGoodDelivery(orgID int64, patient_id int64, record_time int64, g
269 269
 				StorehouseId:            goods.StorehouseId,
270 270
 				BuyPrice:                warehouse.Price,
271 271
 				ProjectId:               goods.ProjectId,
272
+				OverCount:               sum_count,
272 273
 			}
273 274
 			if orgID == 9671 || orgID == 10265 {
274 275
 				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
@@ -521,6 +522,7 @@ func ConsumablesGoodDelivery(orgID int64, patient_id int64, record_time int64, g
521 522
 				StorehouseId:            goods.StorehouseId,
522 523
 				BuyPrice:                warehouse.Price,
523 524
 				ProjectId:               goods.ProjectId,
525
+				OverCount:               sum_count,
524 526
 			}
525 527
 			if orgID == 9671 || orgID == 10265 {
526 528
 				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
@@ -1588,6 +1590,7 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1588 1590
 				AdviceId:                advice.ID,
1589 1591
 				StorehouseId:            storeConfig.DrugStorehouseOut,
1590 1592
 				LastPrice:               warehouse.Price,
1593
+				OverCount:               sum_count,
1591 1594
 			}
1592 1595
 			CreateDrugFlowOne(flow)
1593 1596
 			AddCancelSumCountOne(storeConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, flow.Count)
@@ -1897,6 +1900,7 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1897 1900
 				AdviceId:                advice.ID,
1898 1901
 				StorehouseId:            storeConfig.DrugStorehouseOut,
1899 1902
 				LastPrice:               warehouse.Price,
1903
+				OverCount:               sum_count,
1900 1904
 			}
1901 1905
 			CreateDrugFlowOne(flow)
1902 1906
 

+ 1 - 1
service/patient_service.go View File

@@ -730,7 +730,7 @@ func EditPatientLapseto(patient *models.Patients, lapseto *models.PatientLapseto
730 730
 		return
731 731
 	}
732 732
 	// 删除排班和排班模板信息
733
-	if lapseto.LapsetoType == 2 {
733
+	if lapseto.LapsetoType == 2 || lapseto.LapsetoType == 3 {
734 734
 		now := time.Now()
735 735
 		deleteScheduleErr := utx.Model(&models.PatientSchedule{}).Where("patient_id = ? AND schedule_date >= ? AND status = 1", patient.ID, lapseto.LapsetoTime).Updates(map[string]interface{}{
736 736
 			"status":       0,

+ 74 - 0
service/self_drug_service.go View File

@@ -2561,3 +2561,77 @@ func CreateDrugStockCount(stockCount models.XtDrugStockCount) error {
2561 2561
 	err := XTWriteDB().Create(&stockCount).Error
2562 2562
 	return err
2563 2563
 }
2564
+
2565
+func GetGoodNewPurchaseStockQuery(good_type int64, keyword string, page int64, limit int64, orgid int64, ids []int64, goodIds []int64) (goodinfo []*models.GoodInfoTwenty, total int64, err error) {
2566
+
2567
+	db := XTReadDB().Model(&goodinfo).Where("status = 1 and total_count > 0")
2568
+	offset := (page - 1) * limit
2569
+	likeKey := "%" + keyword + "%"
2570
+	if good_type > 0 {
2571
+		db = db.Where("good_type_id = ?", good_type)
2572
+	}
2573
+
2574
+	if orgid > 0 {
2575
+		db = db.Where("org_id = ?", orgid)
2576
+	}
2577
+	if len(ids) > 0 {
2578
+		db = db.Where("id in(?)", goodIds)
2579
+	}
2580
+	if len(keyword) > 0 {
2581
+		db = db.Where("good_name like ? or manufacturer in(?)", likeKey, ids)
2582
+	}
2583
+	err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&goodinfo).Error
2584
+
2585
+	return goodinfo, total, err
2586
+}
2587
+
2588
+func GetStartLastFLow(goodid int64, orgid int64, startime int64) (models.VmStockFlowTwenty, error) {
2589
+
2590
+	flwo := models.VmStockFlowTwenty{}
2591
+	err := XTReadDB().Where("good_id = ? and user_org_id = ? and status = 1 and ctime < ?", goodid, orgid, startime).Last(&flwo).Error
2592
+	return flwo, err
2593
+}
2594
+
2595
+func GetEndLastFlow(goodid int64, orgid int64, endtime int64) (models.VmStockFlowTwenty, error) {
2596
+	flwo := models.VmStockFlowTwenty{}
2597
+	err := XTReadDB().Where("good_id = ? and user_org_id = ? and status = 1 and ctime <= ?", goodid, orgid, endtime).Last(&flwo).Error
2598
+	return flwo, err
2599
+}
2600
+
2601
+func GetDrugNewPurchaseStockQuery(good_type int64, keyword string, page int64, limit int64, orgid int64, startime int64, endtime int64, ids []int64, infos []int64) (druginfo []*models.VmBaseDrugTwenty, total int64, err error) {
2602
+
2603
+	db := XTReadDB().Model(&druginfo).Where("status = 1")
2604
+	offset := (page - 1) * limit
2605
+	likeKey := "%" + keyword + "%"
2606
+	if good_type > 0 {
2607
+		db = db.Where("drug_type = ?", good_type)
2608
+	}
2609
+
2610
+	if orgid > 0 {
2611
+		db = db.Where("org_id = ?", orgid)
2612
+	}
2613
+
2614
+	if len(keyword) > 0 {
2615
+		db = db.Where("drug_name like ? or manufacturer in(?)", likeKey, ids)
2616
+	}
2617
+	if len(infos) > 0 {
2618
+		db = db.Where("id in(?)", infos)
2619
+	}
2620
+	err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&druginfo).Error
2621
+
2622
+	return druginfo, total, err
2623
+}
2624
+
2625
+func GetDrugStartFlow(drug_id int64, user_org_id int64, startime int64) (models.DrugFlowTwenty, error) {
2626
+
2627
+	flow := models.DrugFlowTwenty{}
2628
+	err := XTReadDB().Where("drug_id = ? and user_org_id = ? and ctime<? and status = 1", drug_id, user_org_id, startime).Last(&flow).Error
2629
+	return flow, err
2630
+}
2631
+
2632
+func GetDrugEndFlow(drug_id int64, user_org_id int64, endtime int64) (models.DrugFlowTwenty, error) {
2633
+
2634
+	flow := models.DrugFlowTwenty{}
2635
+	err := XTReadDB().Where("drug_id = ? and user_org_id = ? and ctime<=? and status = 1", drug_id, user_org_id, endtime).Last(&flow).Error
2636
+	return flow, err
2637
+}

+ 11 - 4
service/stock_service.go View File

@@ -7496,9 +7496,18 @@ func GetDrugWarehouseOutListById(warehouse_out_id int64, orgId int64) (info []*m
7496 7496
 }
7497 7497
 
7498 7498
 func UpdateCheckDrugOut(out models.DrugWarehouseOut, id int64) error {
7499
-
7500
-	err := XTWriteDB().Model(&models.DrugWarehouseOut{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": out.IsCheck}).Error
7499
+	tx := XTWriteDB().Begin()
7500
+	err := tx.Model(&models.DrugWarehouseOut{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": out.IsCheck}).Error
7501
+	if err != nil {
7502
+		tx.Rollback()
7503
+		return err
7504
+	}
7501 7505
 	err = XTWriteDB().Model(&models.DrugWarehouseOutInfo{}).Where("warehouse_out_id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 1}).Error
7506
+	if err != nil {
7507
+		tx.Rollback()
7508
+		return err
7509
+	}
7510
+	tx.Commit()
7502 7511
 	return err
7503 7512
 }
7504 7513
 
@@ -7590,8 +7599,6 @@ func UpdateGoodInfoReduceSumCount(goodid int64, sum_count int64, orgid int64) er
7590 7599
 	tx.Commit()
7591 7600
 	return err
7592 7601
 
7593
-	err = XTWriteDB().Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", goodid, orgid).Update(map[string]interface{}{"sum_count": sum_count}).Error
7594
-	return err
7595 7602
 }
7596 7603
 
7597 7604
 func UpdateGoodInfoAddSumCount(goodid int64, sum_count int64, orgid int64, sum_in_count int64) error {

+ 91 - 75
service/warhouse_service.go View File

@@ -136,8 +136,82 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
136 136
 
137 137
 	stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
138 138
 
139
-	//查找药品信息
140
-	//baseInfo, _ := FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
139
+	var maxNumber int64 = 0
140
+	var minNumber int64 = 0
141
+
142
+	maxNumber = deliver_number / drup.MinNumber
143
+	minNumber = deliver_number % drup.MinNumber
144
+
145
+	if warehouse.StockMaxNumber == 0 && drup.MaxUnit == drup.MinUnit {
146
+		minNumber = maxNumber
147
+	}
148
+
149
+	if drup.MaxUnit != drup.MinUnit {
150
+		if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
151
+			return errors.New("库存数量不足")
152
+		}
153
+	}
154
+
155
+	warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
156
+
157
+	if warehouse.StockMaxNumber < 0 {
158
+		warehouse.StockMaxNumber = 0
159
+	}
160
+	if warehouse.StockMinNumber < 0 {
161
+		warehouse.StockMinNumber = 0
162
+	}
163
+
164
+	warehouse.Mtime = time.Now().Unix()
165
+
166
+	if warehouse.StockMinNumber < minNumber {
167
+
168
+		warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
169
+		warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
170
+	} else {
171
+		if minNumber > 0 {
172
+			warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
173
+		}
174
+
175
+		if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
176
+			if warehouse.StockMinNumber > 0 {
177
+				warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
178
+			}
179
+
180
+		}
181
+
182
+	}
183
+
184
+	if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit {
185
+		if (warehouse.StockMinNumber - deliver_number) > 0 {
186
+			warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
187
+		}
188
+
189
+	}
190
+
191
+	if drup.MaxUnit != drup.MinUnit {
192
+		if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
193
+			return errors.New("库存数量不足")
194
+		}
195
+	}
196
+	if warehouse.StockMinNumber <= 0 {
197
+		warehouse.StockMinNumber = 0
198
+	}
199
+
200
+	errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
201
+
202
+	if errThree != nil {
203
+		return errThree
204
+	}
205
+
206
+	//查询剩余库存
207
+	stockInfo, _ := GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgID, advice.DrugId)
208
+	var sum_count int64
209
+	for _, its := range stockInfo {
210
+		if its.MaxUnit == drup.MaxUnit {
211
+			its.StockMaxNumber = its.StockMaxNumber * drup.MinNumber
212
+		}
213
+		sum_count += its.StockMaxNumber + its.StockMinNumber
214
+	}
141 215
 
142 216
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
143 217
 
@@ -201,6 +275,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
201 275
 			StorehouseId:            storeConfig.DrugStorehouseOut,
202 276
 			WarehouseOutDetailId:    lastDrugOutInfo.ID,
203 277
 			LastPrice:               warehouse.Price,
278
+			OverCount:               sum_count,
204 279
 		}
205 280
 
206 281
 		CreateDrugFlowOne(drugflow)
@@ -227,75 +302,6 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
227 302
 			return errTwo
228 303
 		}
229 304
 
230
-		var maxNumber int64 = 0
231
-		var minNumber int64 = 0
232
-		//var stock_max_number int64 = 0
233
-		//stock_max_number = warehouse.StockMaxNumber
234
-
235
-		maxNumber = deliver_number / drup.MinNumber
236
-		minNumber = deliver_number % drup.MinNumber
237
-
238
-		if warehouse.StockMaxNumber == 0 && drup.MaxUnit == drup.MinUnit {
239
-			minNumber = maxNumber
240
-		}
241
-
242
-		if drup.MaxUnit != drup.MinUnit {
243
-			if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
244
-				return errors.New("库存数量不足")
245
-			}
246
-		}
247
-
248
-		warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
249
-
250
-		if warehouse.StockMaxNumber < 0 {
251
-			warehouse.StockMaxNumber = 0
252
-		}
253
-		if warehouse.StockMinNumber < 0 {
254
-			warehouse.StockMinNumber = 0
255
-		}
256
-
257
-		warehouse.Mtime = time.Now().Unix()
258
-
259
-		if warehouse.StockMinNumber < minNumber {
260
-
261
-			warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
262
-			warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
263
-		} else {
264
-			if minNumber > 0 {
265
-				warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
266
-			}
267
-
268
-			if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
269
-				if warehouse.StockMinNumber > 0 {
270
-					warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
271
-				}
272
-
273
-			}
274
-
275
-		}
276
-
277
-		if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit {
278
-			if (warehouse.StockMinNumber - deliver_number) > 0 {
279
-				warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
280
-			}
281
-
282
-		}
283
-
284
-		if drup.MaxUnit != drup.MinUnit {
285
-			if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
286
-				return errors.New("库存数量不足")
287
-			}
288
-		}
289
-		if warehouse.StockMinNumber <= 0 {
290
-			warehouse.StockMinNumber = 0
291
-		}
292
-
293
-		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
294
-
295
-		if errThree != nil {
296
-			return errThree
297
-		}
298
-
299 305
 		return nil
300 306
 	} else {
301 307
 
@@ -389,6 +395,16 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
389 395
 			return errThree
390 396
 		}
391 397
 
398
+		//查询剩余库存
399
+		stockInfo, _ := GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgID, advice.DrugId)
400
+		var sum_count int64
401
+		for _, its := range stockInfo {
402
+			if its.MaxUnit == drup.MaxUnit {
403
+				its.StockMaxNumber = its.StockMaxNumber * drup.MinNumber
404
+			}
405
+			sum_count += its.StockMaxNumber + its.StockMinNumber
406
+		}
407
+
392 408
 		drugflow := models.DrugFlow{
393 409
 			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
394 410
 			WarehouseOutId:          warehouseout.ID,
@@ -415,6 +431,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
415 431
 			StorehouseId:            storeConfig.DrugStorehouseOut,
416 432
 			WarehouseOutDetailId:    lastDrugOutInfo.ID,
417 433
 			LastPrice:               warehouse.Price,
434
+			OverCount:               sum_count,
418 435
 		}
419 436
 
420 437
 		CreateDrugFlowOne(drugflow)
@@ -1270,7 +1287,6 @@ func ConsumablesDeliveryTotal(orgID int64, patient_id int64, record_time int64,
1270 1287
 			}
1271 1288
 		}
1272 1289
 
1273
-		fmt.Println("goods999923932923923923223wode", goods)
1274 1290
 		for _, item := range goods {
1275 1291
 			var newCount int64 = 0
1276 1292
 			for _, it := range goodOne {
@@ -1287,9 +1303,9 @@ func ConsumablesDeliveryTotal(orgID int64, patient_id int64, record_time int64,
1287 1303
 				out_count += item.Count
1288 1304
 			}
1289 1305
 			cha_count = item.Count - out_count
1290
-			fmt.Println("item.Count", item.Count)
1291
-			fmt.Println("item.Count", out_count)
1292
-			fmt.Println("cha_count2323223232323223", cha_count)
1306
+			//fmt.Println("item.Count", item.Count)
1307
+			//fmt.Println("item.Count", out_count)
1308
+			//fmt.Println("cha_count2323223232323223", cha_count)
1293 1309
 			cha_count_two = out_count - item.Count
1294 1310
 
1295 1311
 			prepare := models.DialysisBeforePrepare{