Browse Source

11月9日库存管理

XMLWAN 2 years ago
parent
commit
414e7fd1f3

+ 38 - 39
controllers/his_api_controller.go View File

@@ -1157,7 +1157,7 @@ func (c *HisApiController) CreateHisPrescription() {
1157 1157
 										}
1158 1158
 										//修改处方
1159 1159
 										if advicelist.ID > 0 {
1160
-											fmt.Println("232323232323232332323o2323o23o23o23o3o")
1160
+
1161 1161
 											//查询最新批次库存
1162 1162
 											info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
1163 1163
 											var batch_number_count int64
@@ -1185,8 +1185,7 @@ func (c *HisApiController) CreateHisPrescription() {
1185 1185
 												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1186 1186
 												number_count = prescribingNumberInt
1187 1187
 											}
1188
-											fmt.Println("number-count23323232233223", number_count)
1189
-											fmt.Println("device_number232323322323233223", device_number)
1188
+
1190 1189
 											//如果修改的数量大于之前修改的数量
1191 1190
 											if (number_count - device_number) > 0 {
1192 1191
 												//如果修改的差数量 大于库存数量
@@ -1195,8 +1194,7 @@ func (c *HisApiController) CreateHisPrescription() {
1195 1194
 														c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1196 1195
 														return
1197 1196
 													}
1198
-													fmt.Println("(number_count - device_number3232323232332", number_count-device_number)
1199
-													fmt.Println("(number_count - device_number3232323232332", batch_number_count)
1197
+
1200 1198
 													if (number_count - device_number) > batch_number_count {
1201 1199
 														c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1202 1200
 														return
@@ -1231,49 +1229,52 @@ func (c *HisApiController) CreateHisPrescription() {
1231 1229
 												}
1232 1230
 
1233 1231
 											}
1232
+											pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
1233
+											if pharmacyConfig.IsOpen != 1 {
1234
+												if device_number != number_count {
1234 1235
 
1235
-											if device_number != number_count {
1236
+													// 查询该药品最后一次出库记录
1237
+													druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
1236 1238
 
1237
-												// 查询该药品最后一次出库记录
1238
-												druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
1239
+													//回退库存
1240
+													if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
1239 1241
 
1240
-												//回退库存
1241
-												if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
1242
+														service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
1243
+													}
1244
+													if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
1245
+														var stock_max_number int64
1246
+														var stock_min_number int64
1242 1247
 
1243
-													service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
1244
-												}
1245
-												if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
1246
-													var stock_max_number int64
1247
-													var stock_min_number int64
1248
+														if number_count >= drug.MinNumber {
1248 1249
 
1249
-													if number_count >= drug.MinNumber {
1250
+															stock_max_number = device_number / drug.MinNumber
1251
+															service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
1252
+															stock_min_number = device_number % drug.MinNumber
1253
+															service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
1250 1254
 
1251
-														stock_max_number = device_number / drug.MinNumber
1252
-														service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
1253
-														stock_min_number = device_number % drug.MinNumber
1254
-														service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
1255
+														} else {
1255 1256
 
1256
-													} else {
1257
+															service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
1258
+														}
1259
+													}
1257 1260
 
1258
-														service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
1261
+													if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
1262
+														service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
1259 1263
 													}
1260
-												}
1264
+													//删除记录
1265
+													service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
1266
+
1267
+													//查询默认仓库剩余多少库存
1268
+													var sum_count int64
1269
+													stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
1270
+													for _, its := range stockInfo {
1271
+														sum_count += its.StockMaxNumber*drug.MinNumber + its.StockMinNumber
1272
+													}
1273
+													service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
1261 1274
 
1262
-												if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
1263
-													service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
1264 1275
 												}
1265
-												//删除记录
1266
-												service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
1267
-
1268
-												//查询默认仓库剩余多少库存
1269
-												var sum_count int64
1270
-												stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
1271
-												for _, its := range stockInfo {
1272
-													sum_count += its.StockMaxNumber*drug.MinNumber + its.StockMinNumber
1273
-												}
1274
-												service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
1275
-
1276 1276
 											}
1277
+
1277 1278
 										}
1278 1279
 									}
1279 1280
 								}
@@ -1424,9 +1425,7 @@ func (c *HisApiController) CreateHisPrescription() {
1424 1425
 															in_count = warehouseInfoList.WarehousingCount
1425 1426
 														}
1426 1427
 													}
1427
-													//fmt.Println("out_count23323232233233223",out_count)
1428
-													//fmt.Println("+(number_count - device_number)",(number_count - device_number))
1429
-													//fmt.Println("in_count23322323222222",in_count)
1428
+
1430 1429
 													if (out_count + (number_count - device_number)) > in_count {
1431 1430
 														c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
1432 1431
 														return

+ 8 - 4
controllers/mobile_api_controllers/patient_api_controller.go View File

@@ -757,8 +757,9 @@ func (c *PatientApiController) ExecDoctorAdvice() {
757 757
 								if adviceSetting.IsAdviceOpen == 1 {
758 758
 									//查询是否出库按钮开启
759 759
 									prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
760
+									pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
760 761
 									if prescriptionConfig.IsOpen == 1 {
761
-										if medical.IsUse == 2 && medical.IsPharmacy != 1 {
762
+										if medical.IsUse == 2 && pharmacyConfig.IsOpen != 1 {
762 763
 											service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
763 764
 
764 765
 											//更新字典里面的库存
@@ -771,7 +772,8 @@ func (c *PatientApiController) ExecDoctorAdvice() {
771 772
 										}
772 773
 									}
773 774
 								} else {
774
-									if medical.IsUse == 2 && medical.IsPharmacy != 1 {
775
+									pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
776
+									if medical.IsUse == 2 && pharmacyConfig.IsOpen != 1 {
775 777
 										service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
776 778
 
777 779
 										stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
@@ -861,7 +863,8 @@ func (c *PatientApiController) ExecDoctorAdvice() {
861 863
 							}
862 864
 
863 865
 							if prescribing_number_total <= total {
864
-								if medical.IsUse == 2 && medical.IsPharmacy != 1 {
866
+								pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
867
+								if medical.IsUse == 2 && pharmacyConfig.IsOpen != 1 {
865 868
 									service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
866 869
 
867 870
 									//更新字典里面的库存
@@ -1165,7 +1168,8 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1165 1168
 						}
1166 1169
 
1167 1170
 						if prescribing_number_total <= total {
1168
-							if medical.IsUse == 2 && medical.IsPharmacy != 1 {
1171
+							pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
1172
+							if medical.IsUse == 2 && pharmacyConfig.IsOpen != 1 {
1169 1173
 
1170 1174
 								if config.IsOpen != 1 {
1171 1175
 									service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)

+ 9 - 4
controllers/patient_api_controller.go View File

@@ -1710,7 +1710,8 @@ func (c *PatientApiController) ExecGroupAdvice() {
1710 1710
 				return
1711 1711
 			}
1712 1712
 			if prescribing_number_total <= total {
1713
-				if medical.IsUse == 2 && medical.IsPharmacy != 1 {
1713
+				pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
1714
+				if medical.IsUse == 2 && pharmacyConfig.IsOpen != 1 {
1714 1715
 					service.DrugsDelivery(adminUserInfo.CurrentOrgId, item.ExecutionStaff, item)
1715 1716
 					//查询默认仓库
1716 1717
 					storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
@@ -1933,8 +1934,9 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1933 1934
 					if adviceSetting.IsAdviceOpen == 1 {
1934 1935
 						//查询是否出库按钮开启
1935 1936
 						prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
1937
+						pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
1936 1938
 						if prescriptionConfig.IsOpen == 1 {
1937
-							if medical.IsUse == 2 && medical.IsPharmacy != 1 {
1939
+							if medical.IsUse == 2 && pharmacyConfig.IsOpen != 1 {
1938 1940
 								service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
1939 1941
 								//查询默认仓库
1940 1942
 								storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
@@ -1971,7 +1973,8 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1971 1973
 						}
1972 1974
 
1973 1975
 					} else {
1974
-						if medical.IsUse == 2 && medical.IsPharmacy != 1 {
1976
+						pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
1977
+						if medical.IsUse == 2 && pharmacyConfig.IsOpen != 1 {
1975 1978
 							service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
1976 1979
 							//更新字典里面的库存
1977 1980
 							var sum_count int64
@@ -2251,9 +2254,11 @@ func (c *PatientApiController) ExecDoctorAdvice() {
2251 2254
 					}
2252 2255
 
2253 2256
 					if prescribing_number_total <= total {
2254
-						if medical.IsUse == 2 && medical.IsPharmacy != 1 {
2257
+						pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
2258
+						if medical.IsUse == 2 && pharmacyConfig.IsOpen != 1 {
2255 2259
 
2256 2260
 							if config.IsOpen != 1 {
2261
+
2257 2262
 								service.HisDrugsDelivery(adminUserInfo.CurrentOrgId, item.ExecutionStaff, item)
2258 2263
 								//查询默认仓库
2259 2264
 								storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)

+ 7 - 7
service/drug_pharmacy_management_service.go View File

@@ -1620,7 +1620,7 @@ func CreatePharmacyConfig(config *models.PharmacyConfig) error {
1620 1620
 
1621 1621
 func UpdatePharmacyConfig(orgid int64, config *models.PharmacyConfig) error {
1622 1622
 
1623
-	err := XTWriteDB().Model(&models.PharmacyConfig{}).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"is_open": config.IsOpen,"mtime": time.Now().Unix()}).Error
1623
+	err := XTWriteDB().Model(&models.PharmacyConfig{}).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"is_open": config.IsOpen, "mtime": time.Now().Unix()}).Error
1624 1624
 	return err
1625 1625
 }
1626 1626
 
@@ -1631,15 +1631,15 @@ func GetPharmacyConfig(orgid int64) (models.PharmacyConfig, error) {
1631 1631
 	if err == gorm.ErrRecordNotFound {
1632 1632
 		tmp := models.PharmacyConfig{
1633 1633
 			UserOrgId: orgid,
1634
-			IsOpen: 2,
1635
-			Status: 1,
1636
-			Ctime: time.Now().Unix(),
1637
-			Mtime: time.Now().Unix(),
1634
+			IsOpen:    2,
1635
+			Status:    1,
1636
+			Ctime:     time.Now().Unix(),
1637
+			Mtime:     time.Now().Unix(),
1638 1638
 		}
1639 1639
 		errs := XTWriteDB().Create(&tmp).Error
1640
-		if errs != nil{
1640
+		if errs != nil {
1641 1641
 			err = errs
1642
-		}else {
1642
+		} else {
1643 1643
 			err = nil
1644 1644
 		}
1645 1645
 		return tmp, err