Browse Source

11月9日库存管理

XMLWAN 2 years ago
parent
commit
3c69fab51f

+ 125 - 1
controllers/dialysis_api_controller.go View File

@@ -76,6 +76,11 @@ func DialysisApiRegistRouters() {
76 76
 	//新接口
77 77
 	beego.Router("/api/patient/getpatientdialysissolutiongrouplist", &DialysisApiController{}, "Get:GetPatientDialysisSolutionGroupList")
78 78
 
79
+	beego.Router("/api/patient/getdialysisadvicetemplatelist", &DialysisApiController{}, "Get:GetDialysisAdviceTemplateList")
80
+
81
+	beego.Router("/api/patient/savedialysissetting", &DialysisApiController{}, "Get:SaveDialysisSetting")
82
+
83
+	beego.Router("/api/patient/getdialysissetting", &DialysisApiController{}, "Get:GetDialysisSetting")
79 84
 }
80 85
 
81 86
 func (c *DialysisApiController) GetQueueCall() {
@@ -4218,6 +4223,7 @@ func (c *DialysisApiController) GetInitPrintDataOne() {
4218 4223
 	}
4219 4224
 }
4220 4225
 
4226
+//新接口
4221 4227
 func (this *DialysisApiController) GetPatientDialysisSolutionGroupList() {
4222 4228
 
4223 4229
 	keyword := this.GetString("keywords")
@@ -4238,7 +4244,7 @@ func (this *DialysisApiController) GetPatientDialysisSolutionGroupList() {
4238 4244
 	orgId := this.GetAdminUserInfo().CurrentOrgId
4239 4245
 
4240 4246
 	list, total, err := service.GetPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId)
4241
-	fmt.Println("err23233223232332323232", list)
4247
+
4242 4248
 	if err == nil {
4243 4249
 		this.ServeSuccessJSON(map[string]interface{}{
4244 4250
 			"list":  list,
@@ -4251,3 +4257,121 @@ func (this *DialysisApiController) GetPatientDialysisSolutionGroupList() {
4251 4257
 		return
4252 4258
 	}
4253 4259
 }
4260
+
4261
+func (this *DialysisApiController) GetDialysisAdviceTemplateList() {
4262
+
4263
+	keyword := this.GetString("keywords")
4264
+
4265
+	limit, _ := this.GetInt64("limit")
4266
+
4267
+	page, _ := this.GetInt64("page")
4268
+
4269
+	partition_id, _ := this.GetInt64("partition_id")
4270
+
4271
+	schedule_type, _ := this.GetInt64("schedule_type")
4272
+
4273
+	start_time := this.GetString("schedule_date")
4274
+	timeLayout := "2006-01-02"
4275
+	loc, _ := time.LoadLocation("Local")
4276
+	startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
4277
+
4278
+	orgId := this.GetAdminUserInfo().CurrentOrgId
4279
+
4280
+	list, total, err := service.GetDialysisAdviceTemplateList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId)
4281
+
4282
+	//获取长期医嘱
4283
+	adviceList, _ := service.GetAllLongAdviceList(orgId)
4284
+
4285
+	//获取医嘱模版
4286
+	templateList, _ := service.GetAllHisAdviceTemplateList(orgId)
4287
+	if err == nil {
4288
+		this.ServeSuccessJSON(map[string]interface{}{
4289
+			"list":         list,
4290
+			"total":        total,
4291
+			"adviceList":   adviceList,
4292
+			"templateList": templateList,
4293
+		})
4294
+		return
4295
+
4296
+	} else {
4297
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
4298
+		return
4299
+	}
4300
+}
4301
+
4302
+func (this *DialysisApiController) SaveDialysisSetting() {
4303
+
4304
+	orgId := this.GetAdminUserInfo().CurrentOrgId
4305
+	device_number_set, _ := this.GetInt64("device_number_set")
4306
+	device_type_set, _ := this.GetInt64("device_type_set")
4307
+	name_set, _ := this.GetInt64("name_set")
4308
+	admission_number_set, _ := this.GetInt64("admission_number_set")
4309
+	dialysis_no_set, _ := this.GetInt64("dialysis_no_set")
4310
+	weight_befor_set, _ := this.GetInt64("weight_befor_set")
4311
+	dry_weight_set, _ := this.GetInt64("dry_weight_set")
4312
+	blood_pressure_set, _ := this.GetInt64("blood_pressure_set")
4313
+	ultrafiltration_volume_set, _ := this.GetInt64("ultrafiltration_volume_set")
4314
+	internal_fistula_set, _ := this.GetInt64("internal_fistula_set")
4315
+	blood_flow_volume_set, _ := this.GetInt64("blood_flow_volume_set")
4316
+	anticoagulant_set, _ := this.GetInt64("anticoagulant_set")
4317
+	sealing_fluid_dispose_set, _ := this.GetInt64("sealing_fluid_dispose_set")
4318
+	mode_id_set, _ := this.GetInt64("mode_id_set")
4319
+	dialysis_time_set, _ := this.GetInt64("dialysis_time_set")
4320
+	dialysis_dialyszers_set, _ := this.GetInt64("dialysis_dialyszers_set")
4321
+	dialysis_irrigation_set, _ := this.GetInt64("dialysis_irrigation_set")
4322
+	gaijiliang_set, _ := this.GetInt64("gaijiliang_set")
4323
+	kalium_set, _ := this.GetInt64("kalium_set")
4324
+	displace_liqui_value_set, _ := this.GetInt64("displace_liqui_value_set")
4325
+	bicarbonate_set, _ := this.GetInt64("bicarbonate_set")
4326
+	glucose_set, _ := this.GetInt64("glucose_set")
4327
+
4328
+	dialysisSetting := models.XtDialysisSetting{
4329
+		UserOrgId:             orgId,
4330
+		Status:                1,
4331
+		DeviceNumber:          device_number_set,
4332
+		DeviceType:            device_type_set,
4333
+		Name:                  name_set,
4334
+		AdmissionNumber:       admission_number_set,
4335
+		DialysisNo:            dialysis_no_set,
4336
+		WeightBefor:           weight_befor_set,
4337
+		DryWeight:             dry_weight_set,
4338
+		BloodPressure:         blood_pressure_set,
4339
+		UltrafiltrationVolume: ultrafiltration_volume_set,
4340
+		InternalFistula:       internal_fistula_set,
4341
+		BloodFlowVolume:       blood_flow_volume_set,
4342
+		Anticoagulant:         anticoagulant_set,
4343
+		SealingFluidDispose:   sealing_fluid_dispose_set,
4344
+		ModeId:                mode_id_set,
4345
+		DialysisTime:          dialysis_time_set,
4346
+		DialysisDialyszers:    dialysis_dialyszers_set,
4347
+		DialysisIrrigation:    dialysis_irrigation_set,
4348
+		Gaijiliang:            gaijiliang_set,
4349
+		Kalium:                kalium_set,
4350
+		DisplaceLiquiValue:    displace_liqui_value_set,
4351
+		Bicarbonate:           bicarbonate_set,
4352
+		Glucose:               glucose_set,
4353
+		Ctime:                 time.Now().Unix(),
4354
+		Mtime:                 time.Now().Unix(),
4355
+	}
4356
+	err := service.SaveDialysisSetting(dialysisSetting)
4357
+	if err == nil {
4358
+		this.ServeSuccessJSON(map[string]interface{}{
4359
+			"dialysisSetting": dialysisSetting,
4360
+		})
4361
+		return
4362
+
4363
+	} else {
4364
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
4365
+		return
4366
+	}
4367
+}
4368
+
4369
+func (this *DialysisApiController) GetDialysisSetting() {
4370
+
4371
+	orgId := this.GetAdminUserInfo().CurrentOrgId
4372
+	dialysisSett, _ := service.GetDialysisSetting(orgId)
4373
+	this.ServeSuccessJSON(map[string]interface{}{
4374
+		"dialysisSett": dialysisSett,
4375
+	})
4376
+	return
4377
+}

+ 217 - 0
controllers/secondary_order_api_contorller.go View File

@@ -1199,6 +1199,7 @@ func (this *SecondaryOrderApiController) CheckSecondOrer() {
1199 1199
 					}
1200 1200
 					service.UpdateBaseDrugSumTwo(item.ProjectId, sum_count, item.UserOrgId)
1201 1201
 				}
1202
+
1202 1203
 			}
1203 1204
 
1204 1205
 			//耗材
@@ -1327,6 +1328,114 @@ func (this *SecondaryOrderApiController) CheckSecondOrer() {
1327 1328
 		}
1328 1329
 	}
1329 1330
 
1331
+	//获取所有的入库仓库
1332
+	druglist, _ := service.GetDrugWarehouseInfoStorehouseList(orgId)
1333
+	for _, item := range druglist {
1334
+		//查询该药品该仓库是否有数据
1335
+		drug, _ := service.GetDrugStockCout(item.DrugId, item.StorehouseId, item.OrgId)
1336
+
1337
+		//查询该仓库该药品的入库数量
1338
+		medical, _ := service.GetBaseDrugMedical(item.DrugId)
1339
+
1340
+		var sum_in_count int64
1341
+		var flush_count int64
1342
+		var sum_out_count int64
1343
+		var cancel_out_count int64
1344
+		//查询入库数量和剩余库存
1345
+		infolist, _ := service.GetDrugWarehouseInfoByStorehouseId(item.StorehouseId, item.DrugId, item.OrgId)
1346
+		for _, it := range infolist {
1347
+			if it.MaxUnit == medical.MaxUnit {
1348
+				it.WarehousingCount = it.WarehousingCount * medical.MinNumber
1349
+				it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
1350
+			}
1351
+			sum_in_count += it.WarehousingCount
1352
+			flush_count += it.StockMaxNumber + it.StockMinNumber
1353
+		}
1354
+
1355
+		//获取出库数量
1356
+		outinfolist, _ := service.GetDrugFlowStockOutCount(item.StorehouseId, item.DrugId, item.OrgId)
1357
+		for _, it := range outinfolist {
1358
+			if it.MaxUnit == medical.MaxUnit {
1359
+				it.Count = it.Count * medical.MinNumber
1360
+			}
1361
+			sum_out_count += it.Count
1362
+		}
1363
+
1364
+		//获取退库数量
1365
+		cancelinfolist, _ := service.GetDrugFlowStockCancelCount(item.StorehouseId, item.DrugId, item.OrgId)
1366
+		for _, it := range cancelinfolist {
1367
+			if it.MaxUnit == medical.MaxUnit {
1368
+				it.Count = it.Count * medical.MinNumber
1369
+			}
1370
+			cancel_out_count += it.Count
1371
+		}
1372
+
1373
+		//新增
1374
+		if drug.ID == 0 {
1375
+			drugstock := models.XtDrugStockCount{
1376
+				UserOrgId:      orgId,
1377
+				StorehouseId:   item.StorehouseId,
1378
+				SumInCount:     sum_in_count,
1379
+				SumOutCount:    sum_out_count - cancel_out_count,
1380
+				SumCancelCount: cancel_out_count,
1381
+				DrugId:         item.DrugId,
1382
+				Ctime:          time.Now().Unix(),
1383
+				Mtime:          0,
1384
+				Status:         1,
1385
+				FlushCount:     flush_count,
1386
+				SumActOutCount: sum_out_count,
1387
+			}
1388
+			service.CreateDrugStockCount(drugstock)
1389
+		}
1390
+	}
1391
+
1392
+	//获取入库数据
1393
+	goodlist, _ := service.GetSendGoodInformation(orgId)
1394
+	for _, it := range goodlist {
1395
+		//查询是否有数据
1396
+		_, errcode := service.GetStockFlush(it.StorehouseId, it.GoodId, it.OrgId)
1397
+		//获取总退库数量
1398
+		var cancel_count int64
1399
+		var out_count int64
1400
+		var act_count int64
1401
+		//退库总数量
1402
+		cancellist, _ := service.GetAllCancelCount(it.StorehouseId, it.GoodId, it.OrgId)
1403
+		for _, item := range cancellist {
1404
+			cancel_count += item.Count
1405
+		}
1406
+		//出库总数量
1407
+		outlist, _ := service.GetAllStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
1408
+		for _, item := range outlist {
1409
+			out_count += item.Count
1410
+		}
1411
+
1412
+		//实际出库总数量
1413
+		actlist, _ := service.GetActStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
1414
+		for _, item := range actlist {
1415
+			act_count += item.Count
1416
+		}
1417
+
1418
+		if errcode == gorm.ErrRecordNotFound {
1419
+			good := models.XtGoodStockCount{
1420
+				UserOrgId:        it.OrgId,
1421
+				GoodId:           it.GoodId,
1422
+				StorehouseId:     it.StorehouseId,
1423
+				Status:           1,
1424
+				Ctime:            time.Now().Unix(),
1425
+				Mtime:            0,
1426
+				StockInCount:     it.WarehousingCount,
1427
+				StockOutCount:    out_count - cancel_count,
1428
+				StockCancelCount: cancel_count,
1429
+				FlushCount:       it.StockCount,
1430
+				StockActOutCount: act_count,
1431
+			}
1432
+			service.CreateGoodCountSix(good)
1433
+		}
1434
+		if errcode == nil {
1435
+			service.UpdateGoodCount(it.WarehousingCount, it.StockCount, out_count, it.StorehouseId, it.GoodId, it.OrgId, cancel_count, act_count)
1436
+		}
1437
+	}
1438
+
1330 1439
 	this.ServeSuccessJSON(map[string]interface{}{
1331 1440
 		"msg": 1,
1332 1441
 	})
@@ -1542,6 +1651,114 @@ func (this *SecondaryOrderApiController) ReturnCheckSecondOrder() {
1542 1651
 		}
1543 1652
 	}
1544 1653
 
1654
+	//获取所有的入库仓库
1655
+	druglist, _ := service.GetDrugWarehouseInfoStorehouseList(orgId)
1656
+	for _, item := range druglist {
1657
+		//查询该药品该仓库是否有数据
1658
+		drug, _ := service.GetDrugStockCout(item.DrugId, item.StorehouseId, item.OrgId)
1659
+
1660
+		//查询该仓库该药品的入库数量
1661
+		medical, _ := service.GetBaseDrugMedical(item.DrugId)
1662
+
1663
+		var sum_in_count int64
1664
+		var flush_count int64
1665
+		var sum_out_count int64
1666
+		var cancel_out_count int64
1667
+		//查询入库数量和剩余库存
1668
+		infolist, _ := service.GetDrugWarehouseInfoByStorehouseId(item.StorehouseId, item.DrugId, item.OrgId)
1669
+		for _, it := range infolist {
1670
+			if it.MaxUnit == medical.MaxUnit {
1671
+				it.WarehousingCount = it.WarehousingCount * medical.MinNumber
1672
+				it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
1673
+			}
1674
+			sum_in_count += it.WarehousingCount
1675
+			flush_count += it.StockMaxNumber + it.StockMinNumber
1676
+		}
1677
+
1678
+		//获取出库数量
1679
+		outinfolist, _ := service.GetDrugFlowStockOutCount(item.StorehouseId, item.DrugId, item.OrgId)
1680
+		for _, it := range outinfolist {
1681
+			if it.MaxUnit == medical.MaxUnit {
1682
+				it.Count = it.Count * medical.MinNumber
1683
+			}
1684
+			sum_out_count += it.Count
1685
+		}
1686
+
1687
+		//获取退库数量
1688
+		cancelinfolist, _ := service.GetDrugFlowStockCancelCount(item.StorehouseId, item.DrugId, item.OrgId)
1689
+		for _, it := range cancelinfolist {
1690
+			if it.MaxUnit == medical.MaxUnit {
1691
+				it.Count = it.Count * medical.MinNumber
1692
+			}
1693
+			cancel_out_count += it.Count
1694
+		}
1695
+
1696
+		//新增
1697
+		if drug.ID == 0 {
1698
+			drugstock := models.XtDrugStockCount{
1699
+				UserOrgId:      orgId,
1700
+				StorehouseId:   item.StorehouseId,
1701
+				SumInCount:     sum_in_count,
1702
+				SumOutCount:    sum_out_count - cancel_out_count,
1703
+				SumCancelCount: cancel_out_count,
1704
+				DrugId:         item.DrugId,
1705
+				Ctime:          time.Now().Unix(),
1706
+				Mtime:          0,
1707
+				Status:         1,
1708
+				FlushCount:     flush_count,
1709
+				SumActOutCount: sum_out_count,
1710
+			}
1711
+			service.CreateDrugStockCount(drugstock)
1712
+		}
1713
+	}
1714
+
1715
+	//获取入库数据
1716
+	goodlist, _ := service.GetSendGoodInformation(orgId)
1717
+	for _, it := range goodlist {
1718
+		//查询是否有数据
1719
+		_, errcode := service.GetStockFlush(it.StorehouseId, it.GoodId, it.OrgId)
1720
+		//获取总退库数量
1721
+		var cancel_count int64
1722
+		var out_count int64
1723
+		var act_count int64
1724
+		//退库总数量
1725
+		cancellist, _ := service.GetAllCancelCount(it.StorehouseId, it.GoodId, it.OrgId)
1726
+		for _, item := range cancellist {
1727
+			cancel_count += item.Count
1728
+		}
1729
+		//出库总数量
1730
+		outlist, _ := service.GetAllStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
1731
+		for _, item := range outlist {
1732
+			out_count += item.Count
1733
+		}
1734
+
1735
+		//实际出库总数量
1736
+		actlist, _ := service.GetActStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
1737
+		for _, item := range actlist {
1738
+			act_count += item.Count
1739
+		}
1740
+
1741
+		if errcode == gorm.ErrRecordNotFound {
1742
+			good := models.XtGoodStockCount{
1743
+				UserOrgId:        it.OrgId,
1744
+				GoodId:           it.GoodId,
1745
+				StorehouseId:     it.StorehouseId,
1746
+				Status:           1,
1747
+				Ctime:            time.Now().Unix(),
1748
+				Mtime:            0,
1749
+				StockInCount:     it.WarehousingCount,
1750
+				StockOutCount:    out_count - cancel_count,
1751
+				StockCancelCount: cancel_count,
1752
+				FlushCount:       it.StockCount,
1753
+				StockActOutCount: act_count,
1754
+			}
1755
+			service.CreateGoodCountSix(good)
1756
+		}
1757
+		if errcode == nil {
1758
+			service.UpdateGoodCount(it.WarehousingCount, it.StockCount, out_count, it.StorehouseId, it.GoodId, it.OrgId, cancel_count, act_count)
1759
+		}
1760
+	}
1761
+
1545 1762
 	this.ServeSuccessJSON(map[string]interface{}{
1546 1763
 		"msg": "1",
1547 1764
 	})

+ 76 - 5
controllers/supply_order_api_contorller.go View File

@@ -2391,6 +2391,7 @@ func (this *SupplyOrderApiController) GetGoodOrderCountList() {
2391 2391
 
2392 2392
 	for _, item := range warehousingInfo {
2393 2393
 		service.CreatedWarehouseingDetail(item)
2394
+
2394 2395
 		//查询该机构默认仓库
2395 2396
 		storeConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
2396 2397
 		//查询剩余库存
@@ -2402,7 +2403,11 @@ func (this *SupplyOrderApiController) GetGoodOrderCountList() {
2402 2403
 			sum_in_count += item.WarehousingCount
2403 2404
 		}
2404 2405
 		service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, item.OrgId)
2406
+		//增加入库数量
2407
+		service.AddGoodSumInCount(storeConfig.StorehouseOutInfo, item.GoodId, item.OrgId, item.WarehousingCount)
2405 2408
 
2409
+		//更新剩余库存
2410
+		service.UpdateGoodFlushCount(storeConfig.StorehouseOutInfo, item.GoodId, item.OrgId, sum_count)
2406 2411
 		warehousinginfo, _ := service.GetLastWarehousingInfo(item.GoodId)
2407 2412
 		flow := models.VmStockFlow{
2408 2413
 			WarehousingOrder:          item.WarehousingOrder,
@@ -2453,6 +2458,8 @@ func (this *SupplyOrderApiController) GetGoodOrderCountList() {
2453 2458
 		}
2454 2459
 		service.UpdateMedicalSumCount(items.DrugId, sum_count, sum_in_count, items.OrgId)
2455 2460
 
2461
+		//更新入库数量和剩余库存
2462
+		service.UpdateDrugCount(houseConfig.DrugStorehouseOut, items.OrgId, items.DrugId, sum_in_count, sum_count)
2456 2463
 	}
2457 2464
 	fmt.Println(errs)
2458 2465
 	for _, items := range drugFlow {
@@ -3246,6 +3253,9 @@ func (this *SupplyOrderApiController) ModefyGoodOrder() {
3246 3253
 					sum_in_count += it.WarehousingCount
3247 3254
 				}
3248 3255
 				service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId)
3256
+
3257
+				//更新库存
3258
+				service.UpdateDrugCount(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId, sum_in_count, sum_count)
3249 3259
 			}
3250 3260
 		} else {
3251 3261
 			for _, it := range goodOrder {
@@ -3540,11 +3550,24 @@ func (this *SupplyOrderApiController) CheckReturnOrder() {
3540 3550
 				service.AutoDrugDeliverInfoNight(orgId, prescribingNumber, &warehouseOut, &drup, warehouseOutInfo, warehouse_out_id, id)
3541 3551
 			}
3542 3552
 
3543
-			//修改原数据
3544
-			/*	orderInfo := models.SpSupplierWarehousingCancelOrder{
3545
-					SourceCount: item.SupplyCount - item.SourceCount,
3546
-				}
3547
-				service.UpdateSupplyCancelById(item.ID, orderInfo)*/
3553
+			//查询默认仓库
3554
+			houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
3555
+			//查询默认仓库剩余多少库存
3556
+			list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgId, drup.ID)
3557
+			var sum_count int64
3558
+			var sum_in_count int64
3559
+			for _, it := range list {
3560
+				baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
3561
+				if it.MaxUnit == baseDrug.MaxUnit {
3562
+					it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
3563
+					it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
3564
+
3565
+				}
3566
+				sum_count += it.StockMaxNumber + it.StockMinNumber
3567
+				sum_in_count += it.WarehousingCount
3568
+			}
3569
+			service.UpdateDrugCountOne(houseConfig.DrugStorehouseOut, orgId, drup.ID, sum_count)
3570
+
3548 3571
 		}
3549 3572
 
3550 3573
 		//耗材
@@ -3638,6 +3661,17 @@ func (this *SupplyOrderApiController) CheckReturnOrder() {
3638 3661
 				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
3639 3662
 				return
3640 3663
 			}
3664
+			//查询该机构默认仓库
3665
+			storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
3666
+			//查询剩余库存
3667
+			goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.ProjectId, orgId)
3668
+			var sum_count int64
3669
+			for _, item := range goodList {
3670
+				sum_count += item.StockCount
3671
+			}
3672
+			//更新剩余库存
3673
+			service.UpdateGoodFlushCount(storeConfig.StorehouseOutInfo, item.ProjectId, orgId, sum_count)
3674
+
3641 3675
 		}
3642 3676
 	}
3643 3677
 	cancel := models.SpSupplierWarehouseCancel{
@@ -3723,6 +3757,8 @@ func (this *SupplyOrderApiController) ModefyReturnOrder() {
3723 3757
 	//获取退库单据日期
3724 3758
 	cancel, _ := service.GetReturnOrderById(id)
3725 3759
 	orgId := this.GetAdminUserInfo().CurrentOrgId
3760
+
3761
+	houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
3726 3762
 	if err == nil {
3727 3763
 		//获取退库单详情
3728 3764
 		list, _ := service.GetSupplyCancelOrderDetail(id, orgId)
@@ -3742,6 +3778,8 @@ func (this *SupplyOrderApiController) ModefyReturnOrder() {
3742 3778
 					var sum_count int64
3743 3779
 					sum_count = item.SupplyCount * base.MinNumber
3744 3780
 					service.ModifyDrugAddInformation(item.ProjectId, sum_count, orgId)
3781
+					//出库数量减少
3782
+					service.ReduceDrugSumOut(houseConfig.DrugStorehouseOut, orgId, item.ProjectId, sum_count)
3745 3783
 				}
3746 3784
 
3747 3785
 				if item.SupplyType == base.MinUnit && base.MaxUnit != base.MinUnit {
@@ -3750,6 +3788,9 @@ func (this *SupplyOrderApiController) ModefyReturnOrder() {
3750 3788
 					}
3751 3789
 					service.UpdateDrugWasehousringOne(item.ProjectId, item.SupplyWarehouseDetailInfo, drugInfo)
3752 3790
 					service.ModifyDrugAddInformation(item.ProjectId, item.SupplyCount, orgId)
3791
+					//出库数量减少
3792
+					service.ReduceDrugSumOut(houseConfig.DrugStorehouseOut, orgId, item.ProjectId, item.SupplyCount)
3793
+
3753 3794
 				}
3754 3795
 
3755 3796
 				//删除流水
@@ -3761,6 +3802,23 @@ func (this *SupplyOrderApiController) ModefyReturnOrder() {
3761 3802
 				if len(drugOutList) == 0 {
3762 3803
 					service.UpdateDrugWarehouseById(drugOut.ID)
3763 3804
 				}
3805
+
3806
+				//查询默认仓库剩余多少库存
3807
+				list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgId, item.ProjectId)
3808
+				var sum_count int64
3809
+				var sum_in_count int64
3810
+				for _, it := range list {
3811
+					baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
3812
+					if it.MaxUnit == baseDrug.MaxUnit {
3813
+						it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
3814
+						it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
3815
+
3816
+					}
3817
+					sum_count += it.StockMaxNumber + it.StockMinNumber
3818
+					sum_in_count += it.WarehousingCount
3819
+				}
3820
+				service.UpdateDrugCountOne(houseConfig.DrugStorehouseOut, orgId, item.ProjectId, sum_count)
3821
+
3764 3822
 			}
3765 3823
 			//耗材
3766 3824
 			if item.IsSource == 2 {
@@ -3772,7 +3830,20 @@ func (this *SupplyOrderApiController) ModefyReturnOrder() {
3772 3830
 
3773 3831
 				//更改库存
3774 3832
 				err := service.UpdateWarehousingInfoById(item.ProjectId, item.SupplyWarehouseDetailInfo, info)
3833
+
3775 3834
 				service.ModifyGoodAddInformation(item.ProjectId, item.SupplyCount, item.UserOrgId)
3835
+
3836
+				//扣减出库数量
3837
+				service.ReduceGoodSumOutCount(houseConfig.StorehouseOutInfo, item.ProjectId, item.UserOrgId, item.SupplyCount)
3838
+
3839
+				//查询剩余库存
3840
+				goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.ProjectId, item.UserOrgId)
3841
+				var sum_count int64
3842
+				for _, item := range goodList {
3843
+					sum_count += item.StockCount
3844
+				}
3845
+				//更新剩余库存
3846
+				service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, item.UserOrgId, sum_count)
3776 3847
 				fmt.Println(err)
3777 3848
 				//删除出库记录
3778 3849
 				service.DeleteGoodWarehouseOut(item.ProjectId, item.WarehouseCancelId, orgId)

+ 1 - 0
models/drug_stock.go View File

@@ -432,6 +432,7 @@ type DrugFlow struct {
432 432
 	IsRead                    int64                `gorm:"column:is_read" json:"is_read" form:"is_read"`
433 433
 	IsCheck                   int64                `gorm:"column:is_check" json:"is_check" form:"is_check"`
434 434
 	OverCount                 int64                `gorm:"column:over_count" json:"over_count" form:"over_count"`
435
+	RetailPrice               float64              `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
435 436
 }
436 437
 
437 438
 func (DrugFlow) TableName() string {

+ 34 - 0
models/new_stock_models.go View File

@@ -143,3 +143,37 @@ type NewBaseDrug struct {
143 143
 func (NewBaseDrug) TableName() string {
144 144
 	return "xt_base_drug"
145 145
 }
146
+
147
+type XtDialysisSetting struct {
148
+	ID                    int64 `gorm:"column:id" json:"id" form:"id"`
149
+	UserOrgId             int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
150
+	Status                int64 `gorm:"column:status" json:"status" form:"status"`
151
+	DeviceNumber          int64 `gorm:"column:device_number" json:"device_number" form:"device_number"`
152
+	DeviceType            int64 `gorm:"column:device_type" json:"device_type" form:"device_type"`
153
+	Name                  int64 `gorm:"column:name" json:"name" form:"name"`
154
+	AdmissionNumber       int64 `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
155
+	DialysisNo            int64 `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
156
+	WeightBefor           int64 `gorm:"column:weight_befor" json:"weight_befor" form:"weight_befor"`
157
+	DryWeight             int64 `gorm:"column:dry_weight" json:"dry_weight" form:"dry_weight"`
158
+	BloodPressure         int64 `gorm:"column:blood_pressure" json:"blood_pressure" form:"blood_pressure"`
159
+	UltrafiltrationVolume int64 `gorm:"column:ultrafiltration_volume" json:"ultrafiltration_volume" form:"ultrafiltration_volume"`
160
+	InternalFistula       int64 `gorm:"column:internal_fistula" json:"internal_fistula" form:"internal_fistula"`
161
+	BloodFlowVolume       int64 `gorm:"column:blood_flow_volume" json:"blood_flow_volume" form:"blood_flow_volume"`
162
+	Anticoagulant         int64 `gorm:"column:anticoagulant" json:"anticoagulant" form:"anticoagulant"`
163
+	SealingFluidDispose   int64 `gorm:"column:sealing_fluid_dispose" json:"sealing_fluid_dispose" form:"sealing_fluid_dispose"`
164
+	ModeId                int64 `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
165
+	DialysisTime          int64 `gorm:"column:dialysis_time" json:"dialysis_time" form:"dialysis_time"`
166
+	DialysisDialyszers    int64 `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
167
+	DialysisIrrigation    int64 `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
168
+	Gaijiliang            int64 `gorm:"column:gaijiliang" json:"gaijiliang" form:"gaijiliang"`
169
+	Kalium                int64 `gorm:"column:kalium" json:"kalium" form:"kalium"`
170
+	DisplaceLiquiValue    int64 `gorm:"column:displace_liqui_value" json:"displace_liqui_value" form:"displace_liqui_value"`
171
+	Bicarbonate           int64 `gorm:"column:bicarbonate" json:"bicarbonate" form:"bicarbonate"`
172
+	Glucose               int64 `gorm:"column:glucose" json:"glucose" form:"glucose"`
173
+	Ctime                 int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
174
+	Mtime                 int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
175
+}
176
+
177
+func (XtDialysisSetting) TableName() string {
178
+	return "xt_dialysis_setting"
179
+}

+ 1 - 2
service/dialysis_service.go View File

@@ -131,8 +131,7 @@ func GetTotalDialysisCout(orgid int64, patientid int64) (order []*models.Dialysi
131 131
 //临时医嘱
132 132
 func FindDoctorAdviceOrderById(orgID int64, patientsId int64, recordDate int64) (patient []*models.DoctorAdvice, err error) {
133 133
 	err = readDb.Model(&models.DoctorAdvice{}).
134
-		Where("patient_id = ? and user_org_id=? and status=1 and advice_date = ? and advice_type = 2", patientsId, orgID, recordDate).
135
-		Where("patient_id = ? and user_org_id=? and status=1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientsId, orgID, recordDate).
134
+		Where("patient_id = ? and user_org_id=? and status=1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientsId, orgID, recordDate).
136 135
 		Select("id, user_org_id, patient_id, advice_type, advice_date, record_date, start_time, advice_name,advice_desc, reminder_date, drug_spec, drug_spec_unit, single_dose, single_dose_unit, prescribing_number, prescribing_number_unit, delivery_way, execution_frequency, advice_doctor, status, created_time,updated_time, advice_affirm, remark, stop_time, stop_reason, stop_doctor, stop_state, parent_id, execution_time, execution_staff, execution_state, checker, check_state, check_time, groupno, IF(parent_id > 0, parent_id, id) as advice_order").Order("start_time asc, groupno desc, advice_order desc, id asc").
137 136
 		Find(&patient).Error
138 137
 	return

+ 57 - 4
service/dialysis_solution_service.go View File

@@ -2,7 +2,6 @@ package service
2 2
 
3 3
 import (
4 4
 	"XT_New/models"
5
-	"fmt"
6 5
 )
7 6
 
8 7
 func GetPatientSolutionGroupList(patient_id int64, orgid int64) (solution []*models.DialysisSolution, err error) {
@@ -70,8 +69,62 @@ func GetPatientDialysisSolutionGroupList(keywords string, limit int64, page int6
70 69
 			Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
71 70
 			Preload("DialysisSolution", "status = 1 AND user_org_id = ? and solution_status = 1", orgID).Find(&schedule).Error
72 71
 	}
73
-	fmt.Println("err2332232323233223232332", err)
74
-	fmt.Println("total99999999999999999999", total)
75
-	fmt.Println("scheudle23323233232", schedule)
72
+
73
+	return schedule, total, err
74
+}
75
+
76
+func GetDialysisAdviceTemplateList(keywords string, limit int64, page int64, partition_id int64, schedule_type int64, scheduleDate int64, orgID int64) (schedule []*models.VmBloodSchedule, total int64, err error) {
77
+	db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("status = 1")
78
+	offset := (page - 1) * limit
79
+	if scheduleDate > 0 {
80
+		db = db.Where("schedule_date = ?", scheduleDate)
81
+	}
82
+	if schedule_type > 0 {
83
+		db = db.Where("schedule_type = ?", schedule_type)
84
+	}
85
+	if partition_id > 0 {
86
+		db = db.Where("partition_id = ?", partition_id)
87
+	}
88
+	if orgID > 0 {
89
+		db = db.Where("user_org_id  = ?", orgID)
90
+	}
91
+
92
+	if len(keywords) > 0 {
93
+		keywords = "%" + keywords + "%"
94
+		db = db.Joins("JOIN xt_patients AS patient ON patient.id=xt_schedule.patient_id AND patient.status = 1 AND patient.user_org_id = ? AND patient.name Like ?", orgID, keywords)
95
+		err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
96
+			Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
97
+			Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
98
+	} else {
99
+		err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
100
+			Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
101
+			Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
102
+	}
103
+
76 104
 	return schedule, total, err
77 105
 }
106
+
107
+func GetAllLongAdviceList(user_org_id int64) (advice []*models.DoctorAdvice, err error) {
108
+
109
+	err = XTReadDB().Where("user_org_id = ? and advice_type = 1 and status = 1", user_org_id).Find(&advice).Error
110
+	return advice, err
111
+}
112
+
113
+func GetAllHisAdviceTemplateList(user_org_id int64) (advice []*models.HisPrescriptionAdviceTemplate, err error) {
114
+
115
+	err = XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Find(&advice).Error
116
+	return advice, err
117
+}
118
+
119
+func SaveDialysisSetting(setting models.XtDialysisSetting) error {
120
+
121
+	err := XTWriteDB().Create(&setting).Error
122
+	return err
123
+}
124
+
125
+func GetDialysisSetting(orgid int64) (models.XtDialysisSetting, error) {
126
+
127
+	setting := models.XtDialysisSetting{}
128
+	err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&setting).Error
129
+	return setting, err
130
+}

+ 1 - 1
service/secondary_service.go View File

@@ -1086,7 +1086,7 @@ func GetStoreHouseDrugWarehouseingInfo(id int64) (models.DrugWarehouseInfo, erro
1086 1086
 
1087 1087
 func GetDrugSumCountByStorehouseId(storehouse_id int64, orgid int64, drug_id int64) (info []*models.DrugWarehouseInfo, err error) {
1088 1088
 
1089
-	err = XTReadDB().Where("storehouse_id = ? and org_id = ? and status = 1 and (stock_max_number >0 or stock_min_number>0) and drug_id =? and is_check = 1", storehouse_id, orgid, drug_id).Find(&info).Error
1089
+	err = XTReadDB().Where("storehouse_id = ? and org_id = ? and status = 1  and drug_id =? and is_check = 1", storehouse_id, orgid, drug_id).Find(&info).Error
1090 1090
 	return info, err
1091 1091
 }
1092 1092
 

+ 133 - 1
service/stock_service.go View File

@@ -4855,7 +4855,7 @@ func GetExportOutOrderDrugListOne(warehouse_out_id []string) (out []*models.StDr
4855 4855
 	if len(warehouse_out_id) > 0 {
4856 4856
 		db = db.Where("x.warehouse_out_id in(?)", warehouse_out_id)
4857 4857
 	}
4858
-	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.count,x.max_unit as count_unit,x.price,x.product_date,x.expire_date,x.warehouse_out_order_number,x.dealer,x.manufacturer,x.is_sys,x.number,x.batch_number,x.patient_id,x.ctime,b.dose,b.dose_unit,b.min_number,b.min_unit,b.max_unit,b.drug_name,b.drug_type,b.min_price").Joins("left join xt_base_drug as b on b.id = x.drug_id").Scan(&out).Error
4858
+	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.count,x.max_unit as count_unit,x.price,x.retail_price,x.product_date,x.expire_date,x.warehouse_out_order_number,x.dealer,x.manufacturer,x.is_sys,x.number,x.batch_number,x.patient_id,x.ctime,b.dose,b.dose_unit,b.min_number,b.min_unit,b.max_unit,b.drug_name,b.drug_type,b.min_price").Joins("left join xt_base_drug as b on b.id = x.drug_id").Scan(&out).Error
4859 4859
 	return out, err
4860 4860
 }
4861 4861
 
@@ -6519,6 +6519,7 @@ func ModifyDrugReduceInformationSix(drug_id int64, sum_count int64, orgid int64,
6519 6519
 
6520 6520
 	err = XTWriteDB().Model(&info).Where("id = ? and org_id = ? and status = 1", drug_id, orgid).UpdateColumn("sum_count", gorm.Expr("sum_count - ?", sum_count)).Error
6521 6521
 	err = XTWriteDB().Model(&info).Where("id=? and org_id = ? and status = 1", drug_id, orgid).Update(map[string]interface{}{"batch_retai_price": batch_retai_price}).Error
6522
+
6522 6523
 	return info, err
6523 6524
 }
6524 6525
 
@@ -7891,3 +7892,134 @@ func GetGoodDialysisOutInfo(orgid int64, patient_id int64, sys_record_time int64
7891 7892
 	err := XTReadDB().Where("org_id =? and patient_id = ? and record_time = ? and good_id = ? and status= 1", orgid, patient_id, sys_record_time, good_id).Find(&detail).Error
7892 7893
 	return detail, err
7893 7894
 }
7895
+
7896
+func AddGoodSumInCount(storehouse_id int64, good_id int64, user_org_id int64, count int64) error {
7897
+
7898
+	ut := XTWriteDB().Begin()
7899
+
7900
+	err := ut.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id  = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("stock_in_count", gorm.Expr("stock_in_count + ?", count)).Error
7901
+	if err != nil {
7902
+		ut.Rollback()
7903
+		return err
7904
+	}
7905
+	ut.Commit()
7906
+	return err
7907
+}
7908
+
7909
+func ReduceGoodSumInCount(storehouse_id int64, good_id int64, user_org_id int64, count int64) error {
7910
+
7911
+	ut := XTWriteDB().Begin()
7912
+
7913
+	err := ut.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id  = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("stock_in_count", gorm.Expr("stock_in_count - ?", count)).Error
7914
+	if err != nil {
7915
+		ut.Rollback()
7916
+		return err
7917
+	}
7918
+	ut.Commit()
7919
+	return err
7920
+}
7921
+
7922
+func UpdateGoodFlushCount(storehouse_id int64, good_id int64, user_org_id int64, flush_count int64) error {
7923
+	ut := XTWriteDB().Begin()
7924
+
7925
+	err := ut.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id  = ? and good_id =?", storehouse_id, user_org_id, good_id).Update(map[string]interface{}{"flush_count": flush_count}).Error
7926
+	if err != nil {
7927
+		ut.Rollback()
7928
+		return err
7929
+	}
7930
+	ut.Commit()
7931
+	return err
7932
+}
7933
+
7934
+func UpdateDrugCount(storehouse_id int64, user_org_id int64, drug_id int64, sum_in_count int64, flush_count int64) error {
7935
+
7936
+	ut := XTWriteDB().Begin()
7937
+	err := ut.Model(&models.XtDrugStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id  = ? and drug_id =?", storehouse_id, user_org_id, drug_id).Update(map[string]interface{}{"sum_in_count": sum_in_count}).Error
7938
+	if err != nil {
7939
+		ut.Rollback()
7940
+		return err
7941
+	}
7942
+	err = ut.Model(&models.XtDrugStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id  = ? and drug_id =?", storehouse_id, user_org_id, drug_id).Update(map[string]interface{}{"flush_count": flush_count}).Error
7943
+	if err != nil {
7944
+		ut.Rollback()
7945
+		return err
7946
+	}
7947
+
7948
+	ut.Commit()
7949
+	return err
7950
+}
7951
+
7952
+func UpdateDrugCountOne(storehouse_id int64, user_org_id int64, drug_id int64, flush_count int64) error {
7953
+
7954
+	ut := XTWriteDB().Begin()
7955
+	err = ut.Model(&models.XtDrugStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id  = ? and drug_id =?", storehouse_id, user_org_id, drug_id).Update(map[string]interface{}{"flush_count": flush_count}).Error
7956
+	if err != nil {
7957
+		ut.Rollback()
7958
+		return err
7959
+	}
7960
+
7961
+	ut.Commit()
7962
+	return err
7963
+}
7964
+
7965
+func AddDrugSumOutCount(storehouse_id int64, sum_out_count int64, user_org_id int64, drug_id int64) error {
7966
+
7967
+	ut := XTWriteDB().Begin()
7968
+	err := ut.Model(&models.XtDrugStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id  = ? and drug_id =?", storehouse_id, user_org_id, drug_id).UpdateColumn("sum_out_count", gorm.Expr("sum_out_count + ?", sum_out_count)).Error
7969
+	if err != nil {
7970
+		ut.Rollback()
7971
+		return err
7972
+	}
7973
+	err = ut.Model(&models.XtDrugStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id  = ? and drug_id =?", storehouse_id, user_org_id, drug_id).UpdateColumn("sum_out_count", gorm.Expr("sum_out_count + ?", sum_out_count)).Error
7974
+	if err != nil {
7975
+		ut.Rollback()
7976
+		return err
7977
+	}
7978
+	ut.Commit()
7979
+	return err
7980
+}
7981
+
7982
+func ReduceDrugSumOut(storehouse_id int64, user_org_id int64, drug_id int64, sum_out_count int64) error {
7983
+	ut := XTWriteDB().Begin()
7984
+	err := ut.Model(&models.XtDrugStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id  = ? and drug_id =?", storehouse_id, user_org_id, drug_id).UpdateColumn("sum_act_out_count", gorm.Expr("sum_act_out_count + ?", sum_out_count)).Error
7985
+	if err != nil {
7986
+		ut.Rollback()
7987
+		return err
7988
+	}
7989
+	ut.Commit()
7990
+	return err
7991
+}
7992
+
7993
+func AddGoodSumOutCount(storehouse_id int64, good_id int64, user_org_id int64, count int64) error {
7994
+	ut := XTWriteDB().Begin()
7995
+	err := ut.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id  = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("stock_out_count", gorm.Expr("stock_out_count + ?", count)).Error
7996
+	if err != nil {
7997
+		ut.Rollback()
7998
+		return err
7999
+	}
8000
+	err = ut.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id  = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("sum_act_out_count", gorm.Expr("sum_act_out_count + ?", count)).Error
8001
+	if err != nil {
8002
+		ut.Rollback()
8003
+		return err
8004
+	}
8005
+
8006
+	ut.Commit()
8007
+	return err
8008
+}
8009
+
8010
+func ReduceGoodSumOutCount(storehouse_id int64, good_id int64, user_org_id int64, count int64) error {
8011
+	ut := XTWriteDB().Begin()
8012
+	err := ut.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id  = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("stock_out_count", gorm.Expr("stock_out_count - ?", count)).Error
8013
+	if err != nil {
8014
+		ut.Rollback()
8015
+		return err
8016
+	}
8017
+	err = ut.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id  = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("sum_act_out_count", gorm.Expr("sum_act_out_count - ?", count)).Error
8018
+	if err != nil {
8019
+		ut.Rollback()
8020
+		return err
8021
+	}
8022
+
8023
+	ut.Commit()
8024
+	return err
8025
+}

+ 43 - 5
service/warhouse_service.go View File

@@ -3335,7 +3335,10 @@ func ConsumablesDeliveryNight(orgID int64, record_time int64, goods *models.Ware
3335 3335
 
3336 3336
 		//扣减库存
3337 3337
 		errThree := UpDateWarehouseInfoByStock(&warehouse)
3338
+		//出库数量增加
3339
+		AddGoodSumOutCount(houseConfig.StorehouseOutInfo, warehouse.GoodId, warehouse.OrgId, goods.Count)
3338 3340
 		ModifyGoodReduceInformationSix(warehouse.GoodId, maxNumber, warehouse.OrgId, warehouse.PackingPrice)
3341
+
3339 3342
 		if errThree != nil {
3340 3343
 			return errThree
3341 3344
 		}
@@ -3430,6 +3433,8 @@ func ConsumablesDeliveryNight(orgID int64, record_time int64, goods *models.Ware
3430 3433
 		if errThree != nil {
3431 3434
 			return errThree
3432 3435
 		}
3436
+		//出库数量增加
3437
+		AddGoodSumOutCount(houseConfig.StorehouseOutInfo, warehouse.GoodId, warehouse.OrgId, warehouse.StockCount)
3433 3438
 		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
3434 3439
 		goods.Count = deliver_number - stock_number
3435 3440
 
@@ -3458,11 +3463,17 @@ func AutoDrugDeliverInfoNight(orgID int64, prescribingNumber int64, warehouseout
3458 3463
 	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
3459 3464
 	var deliver_number int64 = 0
3460 3465
 	var stock_number int64 = 0
3461
-
3466
+	var retail_price float64
3462 3467
 	if advice.CountUnit == drup.MaxUnit {
3463 3468
 		deliver_number = prescribingNumber * drup.MinNumber
3469
+		formatInt := strconv.FormatInt(prescribingNumber, 10)
3470
+		floatcount, _ := strconv.ParseFloat(formatInt, 64)
3471
+		retail_price = floatcount * advice.Price
3464 3472
 	} else {
3465 3473
 		deliver_number = prescribingNumber
3474
+		formatInt := strconv.FormatInt(prescribingNumber, 10)
3475
+		floatcount, _ := strconv.ParseFloat(formatInt, 64)
3476
+		retail_price = floatcount * advice.Price
3466 3477
 	}
3467 3478
 
3468 3479
 	// 根据先进先出原则,查询最先入库的批次,进行出库
@@ -3538,7 +3549,7 @@ func AutoDrugDeliverInfoNight(orgID int64, prescribingNumber int64, warehouseout
3538 3549
 			ProductDate:             advice.ProductDate,
3539 3550
 			ExpireDate:              advice.ExpiryDate,
3540 3551
 			Count:                   deliver_number,
3541
-			Price:                   advice.Price,
3552
+			Price:                   warehouse.RetailPrice,
3542 3553
 			Status:                  1,
3543 3554
 			Ctime:                   time.Now().Unix(),
3544 3555
 			UserOrgId:               advice.OrgId,
@@ -3556,6 +3567,10 @@ func AutoDrugDeliverInfoNight(orgID int64, prescribingNumber int64, warehouseout
3556 3567
 			SupplyWarehouseId:       warehouseout.SupplyWarehouseId,
3557 3568
 			SystemTime:              advice.SysRecordTime,
3558 3569
 			StorehouseId:            warehouse.StorehouseId,
3570
+			WarehousingDetailId:     warehouse.ID,
3571
+			WarehousingId:           warehouse.ID,
3572
+			RetailPrice:             retail_price,
3573
+			LastPrice:               warehouse.Price,
3559 3574
 		}
3560 3575
 
3561 3576
 		CreateDrugFlowOne(drugflow)
@@ -3603,10 +3618,14 @@ func AutoDrugDeliverInfoNight(orgID int64, prescribingNumber int64, warehouseout
3603 3618
 			var sum_count int64
3604 3619
 			sum_count = maxNumber * drup.MinNumber
3605 3620
 			ModifyDrugReduceInformationSix(warehouse.DrugId, sum_count, warehouse.OrgId, warehouse.RetailPrice)
3621
+			//出库数量增加
3622
+			AddDrugSumOutCount(houseConfig.DrugStorehouseOut, sum_count, warehouse.OrgId, warehouse.DrugId)
3606 3623
 		}
3607 3624
 
3608 3625
 		if warehouse.StockMinNumber > 0 {
3609 3626
 			ModifyDrugReduceInformationSix(warehouse.DrugId, minNumber, warehouse.OrgId, warehouse.RetailPrice)
3627
+			//出库数量增加
3628
+			AddDrugSumOutCount(houseConfig.DrugStorehouseOut, minNumber, warehouse.OrgId, warehouse.DrugId)
3610 3629
 		}
3611 3630
 
3612 3631
 		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
@@ -3662,7 +3681,7 @@ func AutoDrugDeliverInfoNight(orgID int64, prescribingNumber int64, warehouseout
3662 3681
 			ProductDate:             advice.ProductDate,
3663 3682
 			ExpireDate:              advice.ExpiryDate,
3664 3683
 			Count:                   stock_number,
3665
-			Price:                   advice.Price,
3684
+			Price:                   warehouse.RetailPrice,
3666 3685
 			Status:                  1,
3667 3686
 			Ctime:                   time.Now().Unix(),
3668 3687
 			UserOrgId:               advice.OrgId,
@@ -3680,16 +3699,22 @@ func AutoDrugDeliverInfoNight(orgID int64, prescribingNumber int64, warehouseout
3680 3699
 			SupplyWarehouseId:       warehouseout.SupplyWarehouseId,
3681 3700
 			SystemTime:              advice.SysRecordTime,
3682 3701
 			StorehouseId:            warehouse.StorehouseId,
3702
+			WarehousingDetailId:     warehouse.ID,
3703
+			WarehousingId:           warehouse.ID,
3704
+			RetailPrice:             retail_price,
3705
+			LastPrice:               warehouse.Price,
3683 3706
 		}
3684 3707
 		CreateDrugFlowOne(drugflow)
3685 3708
 		if warehouse.StockMaxNumber > 0 {
3686 3709
 			var sum_count int64
3687 3710
 			sum_count = warehouse.StockMaxNumber * drup.MinNumber
3688 3711
 			ModifyDrugReduceInformationSix(warehouse.DrugId, sum_count, warehouse.OrgId, warehouse.RetailPrice)
3712
+			AddDrugSumOutCount(houseConfig.DrugStorehouseOut, sum_count, warehouse.OrgId, warehouse.DrugId)
3689 3713
 		}
3690 3714
 
3691 3715
 		if warehouse.StockMinNumber > 0 {
3692 3716
 			ModifyDrugReduceInformationSix(warehouse.DrugId, warehouse.StockMinNumber, warehouse.OrgId, warehouse.RetailPrice)
3717
+			AddDrugSumOutCount(houseConfig.DrugStorehouseOut, warehouse.StockMinNumber, warehouse.OrgId, warehouse.DrugId)
3693 3718
 		}
3694 3719
 
3695 3720
 		// 出库完成后,要将该批次库存清零
@@ -5443,11 +5468,17 @@ func AutoDrugDeliverInfoFourtyOne(orgID int64, prescribingNumber int64, warehous
5443 5468
 	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
5444 5469
 	var deliver_number int64 = 0
5445 5470
 	var stock_number int64 = 0
5446
-
5471
+	var retail_price float64
5447 5472
 	if advice.CountUnit == drup.MaxUnit {
5448 5473
 		deliver_number = prescribingNumber * drup.MinNumber
5474
+		formatInt := strconv.FormatInt(prescribingNumber, 10)
5475
+		floatcount, _ := strconv.ParseFloat(formatInt, 64)
5476
+		retail_price = floatcount * advice.Price
5449 5477
 	} else {
5450 5478
 		deliver_number = prescribingNumber
5479
+		formatInt := strconv.FormatInt(prescribingNumber, 10)
5480
+		floatcount, _ := strconv.ParseFloat(formatInt, 64)
5481
+		retail_price = floatcount * advice.Price
5451 5482
 	}
5452 5483
 
5453 5484
 	lastWarehouse, _ := FindLastDrugWarehousingInfoByID(advice.DrugId, warehouseout.StorehouseId)
@@ -5586,6 +5617,8 @@ func AutoDrugDeliverInfoFourtyOne(orgID int64, prescribingNumber int64, warehous
5586 5617
 			StockCount:              advice.StockCount,
5587 5618
 			WarehousingDetailId:     warehouse.ID,
5588 5619
 			OverCount:               over_count,
5620
+			RetailPrice:             retail_price, //手动出库出库价格
5621
+			WarehousingId:           warehouse.ID,
5589 5622
 		}
5590 5623
 		if warehouse.RetailPrice == 0 {
5591 5624
 			drugflow.Price = advice.Price
@@ -5599,7 +5632,9 @@ func AutoDrugDeliverInfoFourtyOne(orgID int64, prescribingNumber int64, warehous
5599 5632
 		return nil
5600 5633
 
5601 5634
 	} else {
5602
-
5635
+		stock_number_int := strconv.FormatInt(stock_number, 10)
5636
+		stock_number_int_count, _ := strconv.ParseFloat(stock_number_int, 64)
5637
+		retail_price = stock_number_int_count * advice.Price
5603 5638
 		//扣减库存
5604 5639
 		warehouse.StockMaxNumber = 0
5605 5640
 		warehouse.StockMinNumber = 0
@@ -5648,6 +5683,9 @@ func AutoDrugDeliverInfoFourtyOne(orgID int64, prescribingNumber int64, warehous
5648 5683
 			LastPrice:               warehouse.Price,
5649 5684
 			StockCount:              advice.StockCount,
5650 5685
 			OverCount:               over_count,
5686
+			RetailPrice:             retail_price, //手动出库出库价格
5687
+			WarehousingId:           warehouse.ID,
5688
+			WarehousingDetailId:     warehouse.ID,
5651 5689
 		}
5652 5690
 
5653 5691
 		CreateDrugFlowOne(drugflow)