|
@@ -3682,9 +3682,9 @@ func NewBloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehous
|
3682
|
3682
|
var deliver_number_one int64 = 0
|
3683
|
3683
|
var stock_number int64 = 0
|
3684
|
3684
|
|
3685
|
|
- fmt.Println(deliver_number)
|
3686
|
|
- fmt.Println(deliver_number_one)
|
3687
|
|
- fmt.Println(stock_number)
|
|
3685
|
+ //fmt.Println(deliver_number)
|
|
3686
|
+ //fmt.Println(deliver_number_one)
|
|
3687
|
+ //fmt.Println(stock_number)
|
3688
|
3688
|
prescribingNumber_temp := strconv.FormatFloat(math.Abs(prescribingNumber), 'f', 0, 64)
|
3689
|
3689
|
count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
|
3690
|
3690
|
|
|
@@ -3857,12 +3857,6 @@ func NewBloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehous
|
3857
|
3857
|
//扣减库存数据
|
3858
|
3858
|
UpDateNewDrugWarehouseInfoByStock(&warehouse, tx)
|
3859
|
3859
|
|
3860
|
|
- //更改字典里面的价格
|
3861
|
|
- //if advice.UserOrgId == 10265 || advice.UserOrgId == 10215 {
|
3862
|
|
- //
|
3863
|
|
- // UpdateNewBasePrice(lastWarehouse.DrugId, lastWarehouse.RetailPrice, tx)
|
3864
|
|
- //}
|
3865
|
|
- //
|
3866
|
3860
|
////查询剩余库存
|
3867
|
3861
|
stockInfo, _ := GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgID, advice.DrugId, tx)
|
3868
|
3862
|
var sum_count int64
|
|
@@ -3873,55 +3867,54 @@ func NewBloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehous
|
3873
|
3867
|
sum_count += its.StockMaxNumber + its.StockMinNumber
|
3874
|
3868
|
}
|
3875
|
3869
|
|
3876
|
|
- if orgID != 10188 && orgID != 10217 && orgID != 3877 {
|
3877
|
|
- warehouseOutInfo := &models.DrugWarehouseOutInfo{
|
3878
|
|
- WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
|
3879
|
|
- WarehouseOutId: warehouseout.ID,
|
3880
|
|
- Status: 1,
|
3881
|
|
- Ctime: advice.RecordDate,
|
3882
|
|
- Mtime: time.Now().Unix(),
|
3883
|
|
- Remark: warehouse.Remark,
|
3884
|
|
- OrgId: orgID,
|
3885
|
|
- Type: 1,
|
3886
|
|
- Manufacturer: warehouse.Manufacturer,
|
3887
|
|
- Dealer: warehouse.Dealer,
|
3888
|
|
- IsSys: 1,
|
3889
|
|
- SysRecordTime: advice.RecordDate,
|
3890
|
|
- DrugId: advice.DrugId,
|
3891
|
|
- Number: warehouse.Number,
|
3892
|
|
- BatchNumber: warehouse.BatchNumber,
|
3893
|
|
- Price: warehouse.RetailPrice,
|
3894
|
|
- CountUnit: drup.MinUnit,
|
3895
|
|
- RetailPrice: warehouse.RetailPrice,
|
3896
|
|
- ProductDate: warehouse.ProductDate,
|
3897
|
|
- ExpiryDate: warehouse.ExpiryDate,
|
3898
|
|
- PatientId: advice.PatientId,
|
3899
|
|
- Count: deliver_number, //出最小单位
|
3900
|
|
- WarehouseInfoId: warehouse.ID,
|
3901
|
|
- SupplyWarehouseId: warehouse.SupplyWarehouseId,
|
3902
|
|
- StorehouseId: storeConfig.DrugStorehouseOut,
|
3903
|
|
- IsCheck: 1,
|
3904
|
|
- OverCount: sum_count,
|
3905
|
|
- AdviceId: advice.ID,
|
3906
|
|
- }
|
|
3870
|
+ warehouseOutInfo := &models.DrugWarehouseOutInfo{
|
|
3871
|
+ WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
|
|
3872
|
+ WarehouseOutId: warehouseout.ID,
|
|
3873
|
+ Status: 1,
|
|
3874
|
+ Ctime: advice.RecordDate,
|
|
3875
|
+ Mtime: time.Now().Unix(),
|
|
3876
|
+ Remark: warehouse.Remark,
|
|
3877
|
+ OrgId: orgID,
|
|
3878
|
+ Type: 1,
|
|
3879
|
+ Manufacturer: warehouse.Manufacturer,
|
|
3880
|
+ Dealer: warehouse.Dealer,
|
|
3881
|
+ IsSys: 1,
|
|
3882
|
+ SysRecordTime: advice.RecordDate,
|
|
3883
|
+ DrugId: advice.DrugId,
|
|
3884
|
+ Number: warehouse.Number,
|
|
3885
|
+ BatchNumber: warehouse.BatchNumber,
|
|
3886
|
+ Price: warehouse.RetailPrice,
|
|
3887
|
+ CountUnit: drup.MinUnit,
|
|
3888
|
+ RetailPrice: warehouse.RetailPrice,
|
|
3889
|
+ ProductDate: warehouse.ProductDate,
|
|
3890
|
+ ExpiryDate: warehouse.ExpiryDate,
|
|
3891
|
+ PatientId: advice.PatientId,
|
|
3892
|
+ Count: deliver_number, //出最小单位
|
|
3893
|
+ WarehouseInfoId: warehouse.ID,
|
|
3894
|
+ SupplyWarehouseId: warehouse.SupplyWarehouseId,
|
|
3895
|
+ StorehouseId: storeConfig.DrugStorehouseOut,
|
|
3896
|
+ IsCheck: 1,
|
|
3897
|
+ OverCount: sum_count,
|
|
3898
|
+ AdviceId: advice.ID,
|
|
3899
|
+ }
|
3907
|
3900
|
|
3908
|
|
- //查询今日该药品该患者是否有出库数据
|
3909
|
|
- lastDrugOutInfo, _ := GetNewNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID, tx)
|
|
3901
|
+ //查询今日该药品该患者是否有出库数据
|
|
3902
|
+ lastDrugOutInfo, _ := GetNewNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID, tx)
|
3910
|
3903
|
|
3911
|
|
- if lastDrugOutInfo.ID == 0 {
|
3912
|
|
- //删除在新增
|
3913
|
|
- UpdateNewDrugWarehouseOutInfoTen(lastDrugOutInfo.PatientId, lastDrugOutInfo.SysRecordTime, advice.ID, tx)
|
3914
|
|
- AddNewSigleDrugWarehouseOutInfo(warehouseOutInfo, tx)
|
3915
|
|
- }
|
3916
|
|
- if lastDrugOutInfo.ID > 0 {
|
|
3904
|
+ if lastDrugOutInfo.ID == 0 {
|
|
3905
|
+ //删除在新增
|
|
3906
|
+ UpdateNewDrugWarehouseOutInfoTen(lastDrugOutInfo.PatientId, lastDrugOutInfo.SysRecordTime, advice.ID, tx)
|
|
3907
|
+ AddNewSigleDrugWarehouseOutInfo(warehouseOutInfo, tx)
|
|
3908
|
+ }
|
|
3909
|
+ if lastDrugOutInfo.ID > 0 {
|
3917
|
3910
|
|
3918
|
|
- //删除在新增
|
3919
|
|
- UpdateNewDrugWarehouseOutInfoTen(lastDrugOutInfo.PatientId, lastDrugOutInfo.SysRecordTime, advice.ID, tx)
|
|
3911
|
+ //删除在新增
|
|
3912
|
+ UpdateNewDrugWarehouseOutInfoTen(lastDrugOutInfo.PatientId, lastDrugOutInfo.SysRecordTime, advice.ID, tx)
|
3920
|
3913
|
|
3921
|
|
- AddNewSigleDrugWarehouseOutInfo(warehouseOutInfo, tx)
|
|
3914
|
+ AddNewSigleDrugWarehouseOutInfo(warehouseOutInfo, tx)
|
3922
|
3915
|
|
3923
|
|
- }
|
3924
|
3916
|
}
|
|
3917
|
+
|
3925
|
3918
|
//
|
3926
|
3919
|
var out_count int64
|
3927
|
3920
|
var cancel_count int64
|
|
@@ -3938,44 +3931,18 @@ func NewBloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehous
|
3938
|
3931
|
cancel_count += item.Count
|
3939
|
3932
|
}
|
3940
|
3933
|
|
3941
|
|
- if deliver_number_one-(out_count-cancel_count) >= 0 {
|
3942
|
|
- if (deliver_number_one - out_count - cancel_count) != 0 {
|
|
3934
|
+ fmt.Println("已经出库数据", out_count)
|
3943
|
3935
|
|
3944
|
|
- if orgID == 10217 || orgID == 10188 || orgID == 3877 {
|
3945
|
|
- warehouseOutInfo := &models.DrugWarehouseOutInfo{
|
3946
|
|
- WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
|
3947
|
|
- WarehouseOutId: warehouseout.ID,
|
3948
|
|
- Status: 1,
|
3949
|
|
- Ctime: advice.RecordDate,
|
3950
|
|
- Mtime: time.Now().Unix(),
|
3951
|
|
- Remark: warehouse.Remark,
|
3952
|
|
- OrgId: orgID,
|
3953
|
|
- Type: 1,
|
3954
|
|
- Manufacturer: warehouse.Manufacturer,
|
3955
|
|
- Dealer: warehouse.Dealer,
|
3956
|
|
- IsSys: 1,
|
3957
|
|
- SysRecordTime: advice.RecordDate,
|
3958
|
|
- DrugId: advice.DrugId,
|
3959
|
|
- Number: warehouse.Number,
|
3960
|
|
- BatchNumber: warehouse.BatchNumber,
|
3961
|
|
- Price: warehouse.RetailPrice,
|
3962
|
|
- CountUnit: drup.MinUnit,
|
3963
|
|
- RetailPrice: warehouse.RetailPrice,
|
3964
|
|
- ProductDate: warehouse.ProductDate,
|
3965
|
|
- ExpiryDate: warehouse.ExpiryDate,
|
3966
|
|
- PatientId: advice.PatientId,
|
3967
|
|
- Count: deliver_number_one - (out_count - cancel_count), //出最小单位
|
3968
|
|
- WarehouseInfoId: warehouse.ID,
|
3969
|
|
- SupplyWarehouseId: warehouse.SupplyWarehouseId,
|
3970
|
|
- StorehouseId: storeConfig.DrugStorehouseOut,
|
3971
|
|
- IsCheck: 1,
|
3972
|
|
- OverCount: sum_count,
|
3973
|
|
- AdviceId: advice.ID,
|
3974
|
|
- }
|
|
3936
|
+ fmt.Println("已经退库数据", cancel_count)
|
3975
|
3937
|
|
3976
|
|
- AddNewSigleDrugWarehouseOutInfo(warehouseOutInfo, tx)
|
|
3938
|
+ fmt.Println("当前正在出库的数据", deliver_number_one)
|
|
3939
|
+
|
|
3940
|
+ fmt.Println("差", deliver_number_one-out_count-cancel_count)
|
|
3941
|
+
|
|
3942
|
+ //如果本次出库数据大于历史出库数据 新增1条退库流水
|
|
3943
|
+ if deliver_number_one-(out_count-cancel_count) >= 0 {
|
|
3944
|
+ if (deliver_number_one - out_count - cancel_count) != 0 {
|
3977
|
3945
|
|
3978
|
|
- }
|
3979
|
3946
|
lastDrugOutInfo, _ := GetNewNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID, tx)
|
3980
|
3947
|
|
3981
|
3948
|
drugflow := models.DrugFlow{
|
|
@@ -4143,7 +4110,6 @@ func NewBloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehous
|
4143
|
4110
|
StorehouseId: storeConfig.DrugStorehouseOut,
|
4144
|
4111
|
AdviceId: advice.ID,
|
4145
|
4112
|
}
|
4146
|
|
-
|
4147
|
4113
|
AddNewSigleDrugAutoReduceRecordInfo(details, tx)
|
4148
|
4114
|
|
4149
|
4115
|
return nil
|
|
@@ -4476,3 +4442,792 @@ func NewBloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehous
|
4476
|
4442
|
|
4477
|
4443
|
return
|
4478
|
4444
|
}
|
|
4445
|
+
|
|
4446
|
+func HisStoryBloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.HisDoctorAdviceInfo, hisprescribingNumber float64, unit string, tx *gorm.DB) (err error) {
|
|
4447
|
+
|
|
4448
|
+ // 判断处方里药品单位是拆零单位还是包装单位, 如果是包装单位,则根据规格,将包装数量转为拆零数量
|
|
4449
|
+ var deliver_number int64 = 0
|
|
4450
|
+
|
|
4451
|
+ var stock_number int64 = 0
|
|
4452
|
+
|
|
4453
|
+ prescribingNumber_temp := strconv.FormatFloat(math.Abs(prescribingNumber), 'f', 0, 64)
|
|
4454
|
+ count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
|
|
4455
|
+
|
|
4456
|
+ if advice.PrescribingNumberUnit == drup.MaxUnit {
|
|
4457
|
+ deliver_number = count * drup.MinNumber
|
|
4458
|
+
|
|
4459
|
+ } else {
|
|
4460
|
+ deliver_number = count
|
|
4461
|
+
|
|
4462
|
+ }
|
|
4463
|
+
|
|
4464
|
+ // 根据先进先出原则,查询最先入库的批次,进行出库
|
|
4465
|
+ // 如果没有对应的库存,则报错
|
|
4466
|
+ storeConfig, _ := GetNewAllStoreHouseConfig(advice.UserOrgId, tx)
|
|
4467
|
+ lastWarehouse, _ := FindNewLastDrugWarehousingInfoByID(advice.DrugId, storeConfig.DrugStorehouseOut, tx)
|
|
4468
|
+
|
|
4469
|
+ if lastWarehouse.MaxUnit != lastWarehouse.MinUnit && drup.MaxUnit != drup.MinUnit && lastWarehouse.MinUnit != "" {
|
|
4470
|
+ if lastWarehouse.StockMinNumber >= drup.MinNumber {
|
|
4471
|
+ var stockMax int64
|
|
4472
|
+ var stockMin int64
|
|
4473
|
+ stockMax = lastWarehouse.StockMinNumber / drup.MinNumber
|
|
4474
|
+ stockMin = lastWarehouse.StockMinNumber % drup.MinNumber
|
|
4475
|
+
|
|
4476
|
+ ChangeNewMaxNumber(lastWarehouse.ID, stockMax, tx)
|
|
4477
|
+ UpdateNewMinNumber(lastWarehouse.ID, stockMin, tx)
|
|
4478
|
+
|
|
4479
|
+ }
|
|
4480
|
+ }
|
|
4481
|
+
|
|
4482
|
+ if lastWarehouse.MaxUnit == lastWarehouse.MinUnit && drup.MaxUnit != drup.MinUnit && lastWarehouse.MinUnit != "" {
|
|
4483
|
+
|
|
4484
|
+ lastWarehouse.StockMaxNumber = lastWarehouse.StockMaxNumber + lastWarehouse.StockMinNumber
|
|
4485
|
+ ChangeNewMaxNumberOne(lastWarehouse.ID, lastWarehouse.StockMaxNumber, tx)
|
|
4486
|
+
|
|
4487
|
+ }
|
|
4488
|
+
|
|
4489
|
+ warehouse, _ := FindNewLastDrugWarehousingInfoByID(advice.DrugId, storeConfig.DrugStorehouseOut, tx)
|
|
4490
|
+
|
|
4491
|
+ // 将该批次的剩余库存数量转换为拆零数量
|
|
4492
|
+ if warehouse.MaxUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
|
|
4493
|
+
|
|
4494
|
+ stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
|
|
4495
|
+
|
|
4496
|
+ }
|
|
4497
|
+ if warehouse.MaxUnit == drup.MinUnit && drup.MaxUnit != drup.MinUnit {
|
|
4498
|
+
|
|
4499
|
+ stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
|
|
4500
|
+
|
|
4501
|
+ }
|
|
4502
|
+ if warehouse.MaxUnit == drup.MaxUnit && drup.MaxUnit == drup.MinUnit {
|
|
4503
|
+
|
|
4504
|
+ stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
|
|
4505
|
+
|
|
4506
|
+ }
|
|
4507
|
+
|
|
4508
|
+ //fmt.Println("stock_number", stock_number)
|
|
4509
|
+ //fmt.Println("deliver_number=============", deliver_number)
|
|
4510
|
+ // 当库存数量大于或等于出库数量的话,则正常出库该批次
|
|
4511
|
+ if stock_number >= deliver_number {
|
|
4512
|
+
|
|
4513
|
+ var maxNumber int64 = 0
|
|
4514
|
+ var minNumber int64 = 0
|
|
4515
|
+
|
|
4516
|
+ maxNumber = deliver_number / drup.MinNumber
|
|
4517
|
+ minNumber = deliver_number % drup.MinNumber
|
|
4518
|
+
|
|
4519
|
+ if warehouse.StockMaxNumber == 0 && drup.MaxUnit == drup.MinUnit {
|
|
4520
|
+ minNumber = maxNumber
|
|
4521
|
+ }
|
|
4522
|
+
|
|
4523
|
+ if drup.MaxUnit != drup.MinUnit {
|
|
4524
|
+ if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
|
|
4525
|
+ return errors.New("库存数量不足")
|
|
4526
|
+ }
|
|
4527
|
+ }
|
|
4528
|
+
|
|
4529
|
+ if drup.MinUnit == warehouse.MaxUnit && drup.MaxUnit != drup.MinUnit {
|
|
4530
|
+
|
|
4531
|
+ warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*drup.MinNumber
|
|
4532
|
+ }
|
|
4533
|
+
|
|
4534
|
+ if drup.MaxUnit == warehouse.MaxUnit && drup.MaxUnit != drup.MinUnit {
|
|
4535
|
+
|
|
4536
|
+ warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
|
|
4537
|
+ }
|
|
4538
|
+ if drup.MaxUnit == warehouse.MaxUnit && drup.MaxUnit == drup.MinUnit {
|
|
4539
|
+
|
|
4540
|
+ warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
|
|
4541
|
+ }
|
|
4542
|
+
|
|
4543
|
+ if warehouse.StockMaxNumber < 0 {
|
|
4544
|
+ warehouse.StockMaxNumber = 0
|
|
4545
|
+ }
|
|
4546
|
+ if warehouse.StockMinNumber < 0 {
|
|
4547
|
+ warehouse.StockMinNumber = 0
|
|
4548
|
+ }
|
|
4549
|
+
|
|
4550
|
+ warehouse.Mtime = time.Now().Unix()
|
|
4551
|
+
|
|
4552
|
+ //fmt.Println("hahhahahah", warehouse.StockMinNumber)
|
|
4553
|
+ //fmt.Println("howowowoowow", minNumber)
|
|
4554
|
+ if warehouse.StockMinNumber < minNumber {
|
|
4555
|
+
|
|
4556
|
+ warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
|
|
4557
|
+ if warehouse.MaxUnit != warehouse.MinUnit {
|
|
4558
|
+ warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
|
|
4559
|
+ }
|
|
4560
|
+ if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
|
|
4561
|
+ warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
|
|
4562
|
+ }
|
|
4563
|
+ } else {
|
|
4564
|
+
|
|
4565
|
+ if minNumber > 0 {
|
|
4566
|
+ if (warehouse.StockMinNumber - minNumber) >= 0 {
|
|
4567
|
+ warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
|
|
4568
|
+ }
|
|
4569
|
+
|
|
4570
|
+ }
|
|
4571
|
+
|
|
4572
|
+ if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
|
|
4573
|
+
|
|
4574
|
+ if warehouse.StockMinNumber > 0 {
|
|
4575
|
+ if warehouse.StockMinNumber-deliver_number >= 0 {
|
|
4576
|
+ warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
|
|
4577
|
+ }
|
|
4578
|
+
|
|
4579
|
+ }
|
|
4580
|
+
|
|
4581
|
+ }
|
|
4582
|
+
|
|
4583
|
+ }
|
|
4584
|
+
|
|
4585
|
+ //fmt.Println("maxNumber", maxNumber)
|
|
4586
|
+ //fmt.Println("minNumber", maxNumber)
|
|
4587
|
+ if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
|
|
4588
|
+ if (warehouse.StockMinNumber - deliver_number) >= 0 {
|
|
4589
|
+
|
|
4590
|
+ warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
|
|
4591
|
+ }
|
|
4592
|
+
|
|
4593
|
+ }
|
|
4594
|
+
|
|
4595
|
+ if drup.MaxUnit != drup.MinUnit {
|
|
4596
|
+ if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
|
|
4597
|
+ return errors.New("库存数量不足")
|
|
4598
|
+ }
|
|
4599
|
+ }
|
|
4600
|
+ if warehouse.StockMinNumber <= 0 {
|
|
4601
|
+ warehouse.StockMinNumber = 0
|
|
4602
|
+ }
|
|
4603
|
+
|
|
4604
|
+ //fmt.Println("warehouse.StockMaxNumber-------------------", warehouse.StockMaxNumber)
|
|
4605
|
+ //
|
|
4606
|
+ //fmt.Println("warehouse.StockMinNumber-------------------", warehouse.StockMinNumber)
|
|
4607
|
+
|
|
4608
|
+ //扣减库存数据
|
|
4609
|
+ UpDateNewDrugWarehouseInfoByStock(&warehouse, tx)
|
|
4610
|
+
|
|
4611
|
+ ////查询剩余库存
|
|
4612
|
+ stockInfo, _ := GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgID, advice.DrugId, tx)
|
|
4613
|
+ var sum_count int64
|
|
4614
|
+ for _, its := range stockInfo {
|
|
4615
|
+ if its.MaxUnit == drup.MaxUnit {
|
|
4616
|
+ its.StockMaxNumber = its.StockMaxNumber * drup.MinNumber
|
|
4617
|
+ }
|
|
4618
|
+ sum_count += its.StockMaxNumber + its.StockMinNumber
|
|
4619
|
+ }
|
|
4620
|
+
|
|
4621
|
+ warehouseOutInfo := &models.DrugWarehouseOutInfo{
|
|
4622
|
+ WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
|
|
4623
|
+ WarehouseOutId: warehouseout.ID,
|
|
4624
|
+ Status: 1,
|
|
4625
|
+ Ctime: advice.RecordDate,
|
|
4626
|
+ Mtime: time.Now().Unix(),
|
|
4627
|
+ Remark: warehouse.Remark,
|
|
4628
|
+ OrgId: orgID,
|
|
4629
|
+ Type: 1,
|
|
4630
|
+ Manufacturer: warehouse.Manufacturer,
|
|
4631
|
+ Dealer: warehouse.Dealer,
|
|
4632
|
+ IsSys: 1,
|
|
4633
|
+ SysRecordTime: advice.RecordDate,
|
|
4634
|
+ DrugId: advice.DrugId,
|
|
4635
|
+ Number: warehouse.Number,
|
|
4636
|
+ BatchNumber: warehouse.BatchNumber,
|
|
4637
|
+ Price: warehouse.RetailPrice,
|
|
4638
|
+ CountUnit: drup.MinUnit,
|
|
4639
|
+ RetailPrice: warehouse.RetailPrice,
|
|
4640
|
+ ProductDate: warehouse.ProductDate,
|
|
4641
|
+ ExpiryDate: warehouse.ExpiryDate,
|
|
4642
|
+ PatientId: advice.PatientId,
|
|
4643
|
+ Count: deliver_number, //出最小单位
|
|
4644
|
+ WarehouseInfoId: warehouse.ID,
|
|
4645
|
+ SupplyWarehouseId: warehouse.SupplyWarehouseId,
|
|
4646
|
+ StorehouseId: storeConfig.DrugStorehouseOut,
|
|
4647
|
+ IsCheck: 1,
|
|
4648
|
+ OverCount: sum_count,
|
|
4649
|
+ AdviceId: advice.ID,
|
|
4650
|
+ }
|
|
4651
|
+
|
|
4652
|
+ //查询今日该药品该患者是否有出库数据
|
|
4653
|
+ lastDrugOutInfo, _ := GetNewNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID, tx)
|
|
4654
|
+
|
|
4655
|
+ if lastDrugOutInfo.ID == 0 {
|
|
4656
|
+ AddNewSigleDrugWarehouseOutInfo(warehouseOutInfo, tx)
|
|
4657
|
+ }
|
|
4658
|
+ //如果有数量则新增数量
|
|
4659
|
+ if lastDrugOutInfo.ID > 0 {
|
|
4660
|
+
|
|
4661
|
+ UpdateSigleDrugWarehouseOutInfoDetail(lastDrugOutInfo.ID, warehouseOutInfo.Count, tx)
|
|
4662
|
+
|
|
4663
|
+ }
|
|
4664
|
+
|
|
4665
|
+ drugflow := models.DrugFlow{
|
|
4666
|
+ WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
|
|
4667
|
+ WarehouseOutId: warehouseout.ID,
|
|
4668
|
+ DrugId: advice.DrugId,
|
|
4669
|
+ Number: warehouse.Number,
|
|
4670
|
+ ProductDate: warehouse.ProductDate,
|
|
4671
|
+ ExpireDate: warehouse.ExpiryDate,
|
|
4672
|
+ Count: deliver_number, //按最小单位计算,
|
|
4673
|
+ Price: warehouse.RetailPrice,
|
|
4674
|
+ Status: 1,
|
|
4675
|
+ Ctime: advice.AdviceDate,
|
|
4676
|
+ Mtime: time.Now().Unix(),
|
|
4677
|
+ UserOrgId: orgID,
|
|
4678
|
+ Manufacturer: warehouse.Manufacturer,
|
|
4679
|
+ Dealer: warehouse.Dealer,
|
|
4680
|
+ BatchNumber: warehouse.BatchNumber,
|
|
4681
|
+ MaxUnit: drup.MinUnit,
|
|
4682
|
+ ConsumableType: 3,
|
|
4683
|
+ IsEdit: 1,
|
|
4684
|
+ Creator: advice.ExecutionStaff,
|
|
4685
|
+ IsSys: 1,
|
|
4686
|
+ PatientId: advice.PatientId,
|
|
4687
|
+ SystemTime: advice.AdviceDate,
|
|
4688
|
+ WarehousingDetailId: warehouse.ID,
|
|
4689
|
+ SupplyWarehouseId: warehouse.SupplyWarehouseId,
|
|
4690
|
+ StorehouseId: storeConfig.DrugStorehouseOut,
|
|
4691
|
+ WarehouseOutDetailId: lastDrugOutInfo.ID,
|
|
4692
|
+ OverCount: sum_count,
|
|
4693
|
+ AdviceId: advice.ID,
|
|
4694
|
+ LastPrice: warehouse.Price,
|
|
4695
|
+ }
|
|
4696
|
+
|
|
4697
|
+ CreateNewDrugFlowOne(drugflow, tx)
|
|
4698
|
+
|
|
4699
|
+ AddNewDrugCount(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, drugflow.Count, tx)
|
|
4700
|
+
|
|
4701
|
+ //查询是否存在数据
|
|
4702
|
+ details := &models.DrugAutomaticReduceDetail{
|
|
4703
|
+ WarehouseOutId: warehouseout.ID,
|
|
4704
|
+ WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
|
|
4705
|
+ PatientId: advice.PatientId,
|
|
4706
|
+ Ctime: advice.RecordDate,
|
|
4707
|
+ Mtime: time.Now().Unix(),
|
|
4708
|
+ Status: 1,
|
|
4709
|
+ RecordTime: advice.RecordDate,
|
|
4710
|
+ OrgId: orgID,
|
|
4711
|
+ DrugId: advice.DrugId,
|
|
4712
|
+ Count: deliver_number,
|
|
4713
|
+ CountUnit: drup.MinUnit,
|
|
4714
|
+ WarehouseInfoId: warehouse.ID,
|
|
4715
|
+ StorehouseId: storeConfig.DrugStorehouseOut,
|
|
4716
|
+ AdviceId: advice.ID,
|
|
4717
|
+ }
|
|
4718
|
+
|
|
4719
|
+ //查找是否有数据
|
|
4720
|
+ autoMaticReduceDetail, _ := GetDrugAutoMaticReduceDetail(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID, tx)
|
|
4721
|
+
|
|
4722
|
+ if autoMaticReduceDetail.ID == 0 {
|
|
4723
|
+ AddNewSigleDrugAutoReduceRecordInfo(details, tx)
|
|
4724
|
+ }
|
|
4725
|
+
|
|
4726
|
+ if autoMaticReduceDetail.ID > 0 {
|
|
4727
|
+ UpdateNewSingleDrugAutoReduceRecordInfo(autoMaticReduceDetail.ID, deliver_number, tx)
|
|
4728
|
+ }
|
|
4729
|
+
|
|
4730
|
+ return nil
|
|
4731
|
+
|
|
4732
|
+ } else {
|
|
4733
|
+
|
|
4734
|
+ info := models.XtDrugWarehouseInfo{
|
|
4735
|
+ ID: warehouse.ID,
|
|
4736
|
+ WarehousingId: warehouse.WarehousingId,
|
|
4737
|
+ DrugId: warehouse.DrugId,
|
|
4738
|
+ Number: warehouse.Number,
|
|
4739
|
+ ProductDate: warehouse.ProductDate,
|
|
4740
|
+ ExpiryDate: warehouse.ExpiryDate,
|
|
4741
|
+ WarehousingCount: warehouse.WarehousingCount,
|
|
4742
|
+ Price: warehouse.RetailPrice,
|
|
4743
|
+ TotalPrice: warehouse.TotalPrice,
|
|
4744
|
+ Dealer: warehouse.Dealer,
|
|
4745
|
+ Manufacturer: warehouse.Manufacturer,
|
|
4746
|
+ Remark: warehouse.Remark,
|
|
4747
|
+ Ctime: warehouse.Ctime,
|
|
4748
|
+ Mtime: warehouse.Mtime,
|
|
4749
|
+ Status: 1,
|
|
4750
|
+ OrgId: warehouse.OrgId,
|
|
4751
|
+ IsReturn: warehouse.IsReturn,
|
|
4752
|
+ WarehousingOrder: warehouse.WarehousingOrder,
|
|
4753
|
+ Type: warehouse.Type,
|
|
4754
|
+ RetailPrice: warehouse.RetailPrice,
|
|
4755
|
+ RetailTotalPrice: warehouse.RetailPrice,
|
|
4756
|
+ StockMaxNumber: 0,
|
|
4757
|
+ StockMinNumber: 0,
|
|
4758
|
+ BatchNumber: warehouse.BatchNumber,
|
|
4759
|
+ MaxUnit: warehouse.MaxUnit,
|
|
4760
|
+ MinUnit: drup.MinUnit,
|
|
4761
|
+ WarehousingInfoId: warehouse.WarehousingInfoId,
|
|
4762
|
+ SupplyWarehouseId: warehouse.SupplyWarehouseId,
|
|
4763
|
+ StorehouseId: storeConfig.DrugStorehouseOut,
|
|
4764
|
+ IsCheck: 1,
|
|
4765
|
+ }
|
|
4766
|
+ //扣减库存
|
|
4767
|
+ UpDateNewDrugWarehouseInfoByStock(&info, tx)
|
|
4768
|
+
|
|
4769
|
+ //查询剩余库存
|
|
4770
|
+ stockInfo, _ := GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgID, advice.DrugId, tx)
|
|
4771
|
+ var sum_count int64
|
|
4772
|
+ for _, its := range stockInfo {
|
|
4773
|
+ if its.MaxUnit == drup.MaxUnit {
|
|
4774
|
+ its.StockMaxNumber = its.StockMaxNumber * drup.MinNumber
|
|
4775
|
+ }
|
|
4776
|
+ sum_count += its.StockMaxNumber + its.StockMinNumber
|
|
4777
|
+ }
|
|
4778
|
+
|
|
4779
|
+ // 当该批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
|
|
4780
|
+ warehouseOutInfo := &models.DrugWarehouseOutInfo{
|
|
4781
|
+ WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
|
|
4782
|
+ WarehouseOutId: warehouseout.ID,
|
|
4783
|
+ Status: 1,
|
|
4784
|
+ Ctime: advice.RecordDate,
|
|
4785
|
+ Mtime: time.Now().Unix(),
|
|
4786
|
+ Remark: warehouse.Remark,
|
|
4787
|
+ OrgId: orgID,
|
|
4788
|
+ Type: 1,
|
|
4789
|
+ Manufacturer: warehouse.Manufacturer,
|
|
4790
|
+ Dealer: warehouse.Dealer,
|
|
4791
|
+ IsSys: 1,
|
|
4792
|
+ SysRecordTime: advice.RecordDate,
|
|
4793
|
+ DrugId: advice.DrugId,
|
|
4794
|
+ Number: warehouse.Number,
|
|
4795
|
+ BatchNumber: warehouse.BatchNumber,
|
|
4796
|
+ Price: warehouse.RetailPrice,
|
|
4797
|
+ CountUnit: drup.MinUnit,
|
|
4798
|
+ ProductDate: warehouse.ProductDate,
|
|
4799
|
+ ExpiryDate: warehouse.ExpiryDate,
|
|
4800
|
+ PatientId: advice.PatientId,
|
|
4801
|
+ Count: stock_number,
|
|
4802
|
+ WarehouseInfoId: warehouse.ID,
|
|
4803
|
+ SupplyWarehouseId: warehouse.SupplyWarehouseId,
|
|
4804
|
+ StorehouseId: storeConfig.DrugStorehouseOut,
|
|
4805
|
+ IsCheck: 1,
|
|
4806
|
+ OverCount: sum_count,
|
|
4807
|
+ AdviceId: advice.ID,
|
|
4808
|
+ }
|
|
4809
|
+
|
|
4810
|
+ //查询今日该药品该患者是否有出库数据
|
|
4811
|
+ lastDrugOutInfo, _ := GetNewNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID, tx)
|
|
4812
|
+
|
|
4813
|
+ if lastDrugOutInfo.ID == 0 {
|
|
4814
|
+ AddNewSigleDrugWarehouseOutInfo(warehouseOutInfo, tx)
|
|
4815
|
+ }
|
|
4816
|
+ //如果有数量则新增数量
|
|
4817
|
+ if lastDrugOutInfo.ID > 0 {
|
|
4818
|
+
|
|
4819
|
+ UpdateSigleDrugWarehouseOutInfoDetail(lastDrugOutInfo.ID, warehouseOutInfo.Count, tx)
|
|
4820
|
+
|
|
4821
|
+ }
|
|
4822
|
+
|
|
4823
|
+ //查询是否存在数据
|
|
4824
|
+ details := &models.DrugAutomaticReduceDetail{
|
|
4825
|
+ WarehouseOutId: warehouseout.ID,
|
|
4826
|
+ WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
|
|
4827
|
+ PatientId: advice.PatientId,
|
|
4828
|
+ Ctime: advice.RecordDate,
|
|
4829
|
+ Mtime: time.Now().Unix(),
|
|
4830
|
+ Status: 1,
|
|
4831
|
+ RecordTime: advice.RecordDate,
|
|
4832
|
+ OrgId: orgID,
|
|
4833
|
+ DrugId: advice.DrugId,
|
|
4834
|
+ Count: stock_number,
|
|
4835
|
+ CountUnit: drup.MinUnit,
|
|
4836
|
+ WarehouseInfoId: warehouse.ID,
|
|
4837
|
+ StorehouseId: storeConfig.DrugStorehouseOut,
|
|
4838
|
+ AdviceId: advice.ID,
|
|
4839
|
+ }
|
|
4840
|
+
|
|
4841
|
+ //查找是否有数据
|
|
4842
|
+ autoMaticReduceDetail, _ := GetDrugAutoMaticReduceDetail(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID, tx)
|
|
4843
|
+
|
|
4844
|
+ if autoMaticReduceDetail.ID == 0 {
|
|
4845
|
+ AddNewSigleDrugAutoReduceRecordInfo(details, tx)
|
|
4846
|
+ }
|
|
4847
|
+
|
|
4848
|
+ if autoMaticReduceDetail.ID > 0 {
|
|
4849
|
+ UpdateNewSingleDrugAutoReduceRecordInfo(autoMaticReduceDetail.ID, deliver_number, tx)
|
|
4850
|
+ }
|
|
4851
|
+
|
|
4852
|
+ drugflow := models.DrugFlow{
|
|
4853
|
+ WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
|
|
4854
|
+ WarehouseOutId: warehouseout.ID,
|
|
4855
|
+ DrugId: advice.DrugId,
|
|
4856
|
+ Number: warehouse.Number,
|
|
4857
|
+ ProductDate: warehouse.ProductDate,
|
|
4858
|
+ ExpireDate: warehouse.ExpiryDate,
|
|
4859
|
+ Count: stock_number,
|
|
4860
|
+ Price: warehouse.RetailPrice,
|
|
4861
|
+ Status: 1,
|
|
4862
|
+ Ctime: advice.AdviceDate,
|
|
4863
|
+ Mtime: time.Now().Unix(),
|
|
4864
|
+ UserOrgId: orgID,
|
|
4865
|
+ Manufacturer: warehouse.Manufacturer,
|
|
4866
|
+ Dealer: warehouse.Dealer,
|
|
4867
|
+ BatchNumber: warehouse.BatchNumber,
|
|
4868
|
+ MaxUnit: drup.MinUnit,
|
|
4869
|
+ ConsumableType: 3,
|
|
4870
|
+ IsEdit: 1,
|
|
4871
|
+ Creator: advice.ExecutionStaff,
|
|
4872
|
+ IsSys: 1,
|
|
4873
|
+ PatientId: advice.PatientId,
|
|
4874
|
+ WarehousingDetailId: warehouse.ID,
|
|
4875
|
+ SupplyWarehouseId: warehouse.SupplyWarehouseId,
|
|
4876
|
+ StorehouseId: storeConfig.DrugStorehouseOut,
|
|
4877
|
+ WarehouseOutDetailId: lastDrugOutInfo.ID,
|
|
4878
|
+ OverCount: sum_count,
|
|
4879
|
+ AdviceId: advice.ID,
|
|
4880
|
+ LastPrice: warehouse.Price,
|
|
4881
|
+ SystemTime: advice.AdviceDate,
|
|
4882
|
+ }
|
|
4883
|
+
|
|
4884
|
+ CreateNewDrugFlowOne(drugflow, tx)
|
|
4885
|
+ //出库数量相加
|
|
4886
|
+ AddNewDrugCount(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, drugflow.Count, tx)
|
|
4887
|
+
|
|
4888
|
+ // 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
|
|
4889
|
+ prescribingNumber_two_temp := deliver_number - stock_number
|
|
4890
|
+
|
|
4891
|
+ overPlusNumber := float64(prescribingNumber_two_temp)
|
|
4892
|
+
|
|
4893
|
+ advice.PrescribingNumber = float64(prescribingNumber_two_temp)
|
|
4894
|
+ advice.PrescribingNumberUnit = drup.MinUnit
|
|
4895
|
+
|
|
4896
|
+ HisStoryBloodHisDrugDeliverInfo(orgID, overPlusNumber, warehouseout, drup, advice, hisprescribingNumber, unit, tx)
|
|
4897
|
+ }
|
|
4898
|
+
|
|
4899
|
+ return
|
|
4900
|
+}
|
|
4901
|
+
|
|
4902
|
+func NewHisDrugCancelInfo(orgID int64, creater int64, advice *models.HisDoctorAdviceInfo, cha_count int64, drug models.BaseDrugLibSeven, tx *gorm.DB) (err error) {
|
|
4903
|
+
|
|
4904
|
+ storeConfig, _ := GetNewAllStoreHouseConfig(advice.UserOrgId, tx)
|
|
4905
|
+
|
|
4906
|
+ //查找患者最后一条的退库数据是否满足要求
|
|
4907
|
+ var out_count int64
|
|
4908
|
+ drugOutInfo, _ := GetDrugWarehouseOutInfoByAdviceIdTwo(advice.PatientId, advice.UserOrgId, advice.AdviceDate, advice.DrugId, advice.ID, tx)
|
|
4909
|
+
|
|
4910
|
+ if drugOutInfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
|
|
4911
|
+
|
|
4912
|
+ out_count = drugOutInfo.Count * drug.MinNumber
|
|
4913
|
+ }
|
|
4914
|
+
|
|
4915
|
+ if drugOutInfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
|
|
4916
|
+
|
|
4917
|
+ out_count = drugOutInfo.Count
|
|
4918
|
+ }
|
|
4919
|
+
|
|
4920
|
+ if drugOutInfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
|
|
4921
|
+
|
|
4922
|
+ out_count = drugOutInfo.Count
|
|
4923
|
+ }
|
|
4924
|
+
|
|
4925
|
+ //如果最后1条出库数量大于退库数量,则直接退库,满足退库要求
|
|
4926
|
+ if out_count >= cha_count {
|
|
4927
|
+ //退库 退回 cha_count 的数量
|
|
4928
|
+ ModifyNewDrugWarehouseInfoStockMinNumber(cha_count, drugOutInfo.DrugId, drugOutInfo.OrgId, drugOutInfo.WarehouseInfoId, tx)
|
|
4929
|
+
|
|
4930
|
+ if out_count == cha_count {
|
|
4931
|
+ //删除该出库单
|
|
4932
|
+ DeleteDrugWarehouseOutInfoByNumber(drugOutInfo.ID, tx)
|
|
4933
|
+ }
|
|
4934
|
+
|
|
4935
|
+ //减去出库单里面的数量
|
|
4936
|
+ ModifyDrugWarehouseOutInfoByNumber(drugOutInfo.ID, cha_count, tx)
|
|
4937
|
+
|
|
4938
|
+ //创建退库单
|
|
4939
|
+ //查询剩余库存
|
|
4940
|
+ stockInfo, _ := GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgID, advice.DrugId, tx)
|
|
4941
|
+ var sum_count int64
|
|
4942
|
+ for _, its := range stockInfo {
|
|
4943
|
+ if its.MaxUnit == drug.MaxUnit {
|
|
4944
|
+ its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
|
|
4945
|
+ }
|
|
4946
|
+ sum_count += its.StockMaxNumber + its.StockMinNumber
|
|
4947
|
+ }
|
|
4948
|
+
|
|
4949
|
+ //创建退库单
|
|
4950
|
+ operation_time := time.Now().Unix()
|
|
4951
|
+ ctime := time.Now().Unix()
|
|
4952
|
+ timeStr := time.Now().Format("2006-01-02")
|
|
4953
|
+ timeArr := strings.Split(timeStr, "-")
|
|
4954
|
+ total, _ := FindAllDrugCancelStockTotal(advice.UserOrgId)
|
|
4955
|
+ total = total + 1
|
|
4956
|
+ orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
|
|
4957
|
+ cancelStock := models.DrugCancelStock{
|
|
4958
|
+ OrderNumber: orderNumber,
|
|
4959
|
+ OperaTime: operation_time,
|
|
4960
|
+ OrgId: advice.UserOrgId,
|
|
4961
|
+ Creater: advice.ExecutionStaff,
|
|
4962
|
+ Ctime: ctime,
|
|
4963
|
+ Status: 1,
|
|
4964
|
+ ReturnTime: advice.AdviceDate,
|
|
4965
|
+ Dealer: 0,
|
|
4966
|
+ Manufacturer: 0,
|
|
4967
|
+ Type: 1,
|
|
4968
|
+ StorehouseId: storeConfig.DrugStorehouseOut,
|
|
4969
|
+ IsCheck: 1,
|
|
4970
|
+ }
|
|
4971
|
+
|
|
4972
|
+ _, errCode := FindNewDrugCancelStock(advice.AdviceDate, advice.UserOrgId, tx)
|
|
4973
|
+ if errCode == gorm.ErrRecordNotFound {
|
|
4974
|
+ AddNewSigleDrugCancelStock(&cancelStock, tx)
|
|
4975
|
+ }
|
|
4976
|
+ lastDrugCancelStock, _ := FindNewLastDrugCancelStock(advice.AdviceDate, advice.UserOrgId, tx)
|
|
4977
|
+
|
|
4978
|
+ manufactureName, _ := GetNewManufactureById(drugOutInfo.Manufacturer, tx)
|
|
4979
|
+ dealer, _ := GetNewDealerById(drugOutInfo.Dealer, tx)
|
|
4980
|
+ cancelInfo, _ := GetNewLastDrugCancelStockById(advice.UserOrgId, tx)
|
|
4981
|
+ cancelStockInfo := models.DrugCancelStockInfo{
|
|
4982
|
+ OrderNumber: cancelInfo.OrderNumber,
|
|
4983
|
+ CancelStockId: lastDrugCancelStock.ID,
|
|
4984
|
+ DrugId: advice.DrugId,
|
|
4985
|
+ Count: cha_count,
|
|
4986
|
+ Status: 1,
|
|
4987
|
+ Ctime: advice.AdviceDate,
|
|
4988
|
+ Mtime: time.Now().Unix(),
|
|
4989
|
+ OrgId: advice.UserOrgId,
|
|
4990
|
+ Type: 1,
|
|
4991
|
+ Manufacturer: manufactureName.ManufacturerName,
|
|
4992
|
+ Dealer: dealer.DealerName,
|
|
4993
|
+ Total: 0,
|
|
4994
|
+ RetailPrice: drugOutInfo.RetailPrice,
|
|
4995
|
+ RetailTotalPrice: drugOutInfo.RetailTotalPrice,
|
|
4996
|
+ Price: drugOutInfo.Price,
|
|
4997
|
+ RegisterAccount: "",
|
|
4998
|
+ Remark: drugOutInfo.Remark,
|
|
4999
|
+ BatchNumber: drugOutInfo.BatchNumber,
|
|
5000
|
+ MaxUnit: drugOutInfo.CountUnit,
|
|
5001
|
+ ProductDate: drugOutInfo.ProductDate,
|
|
5002
|
+ ExpiryDate: drugOutInfo.ExpiryDate,
|
|
5003
|
+ BatchNumberId: drugOutInfo.WarehouseInfoId,
|
|
5004
|
+ StorehouseId: storeConfig.DrugStorehouseOut,
|
|
5005
|
+ IsCheck: 1,
|
|
5006
|
+ }
|
|
5007
|
+ CreatedNewCancelStock(cancelStockInfo, tx)
|
|
5008
|
+
|
|
5009
|
+ flow := models.DrugFlow{
|
|
5010
|
+ WarehousingId: drugOutInfo.WarehouseInfoId,
|
|
5011
|
+ DrugId: drugOutInfo.DrugId,
|
|
5012
|
+ Number: "",
|
|
5013
|
+ BatchNumber: drugOutInfo.BatchNumber,
|
|
5014
|
+ Count: cha_count,
|
|
5015
|
+ UserOrgId: advice.UserOrgId,
|
|
5016
|
+ PatientId: advice.PatientId,
|
|
5017
|
+ SystemTime: advice.AdviceDate,
|
|
5018
|
+ ConsumableType: 7,
|
|
5019
|
+ IsSys: 0,
|
|
5020
|
+ WarehousingOrder: "",
|
|
5021
|
+ WarehouseOutId: 0,
|
|
5022
|
+ WarehouseOutOrderNumber: "",
|
|
5023
|
+ IsEdit: 0,
|
|
5024
|
+ CancelStockId: cancelStock.ID,
|
|
5025
|
+ CancelOrderNumber: cancelStock.OrderNumber,
|
|
5026
|
+ Manufacturer: drugOutInfo.Manufacturer,
|
|
5027
|
+ Dealer: drugOutInfo.Dealer,
|
|
5028
|
+ Creator: advice.ExecutionStaff,
|
|
5029
|
+ UpdateCreator: 0,
|
|
5030
|
+ Status: 1,
|
|
5031
|
+ Ctime: advice.AdviceDate,
|
|
5032
|
+ Mtime: time.Now().Unix(),
|
|
5033
|
+ Price: drugOutInfo.RetailPrice,
|
|
5034
|
+ WarehousingDetailId: drugOutInfo.ID,
|
|
5035
|
+ WarehouseOutDetailId: 0,
|
|
5036
|
+ CancelOutDetailId: lastDrugCancelStock.ID,
|
|
5037
|
+ ExpireDate: drugOutInfo.ExpiryDate,
|
|
5038
|
+ ProductDate: drugOutInfo.ProductDate,
|
|
5039
|
+ MaxUnit: drugOutInfo.CountUnit,
|
|
5040
|
+ MinUnit: "",
|
|
5041
|
+ AdviceId: advice.ID,
|
|
5042
|
+ StorehouseId: storeConfig.DrugStorehouseOut,
|
|
5043
|
+ LastPrice: drugOutInfo.Price,
|
|
5044
|
+ OverCount: sum_count,
|
|
5045
|
+ }
|
|
5046
|
+ CreateNewDrugFlowOne(flow, tx)
|
|
5047
|
+
|
|
5048
|
+ AddNewCancelSumCountOne(storeConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, flow.Count, tx)
|
|
5049
|
+
|
|
5050
|
+ ReduceNewDrugCountTwo(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, flow.Count, tx)
|
|
5051
|
+
|
|
5052
|
+ }
|
|
5053
|
+
|
|
5054
|
+ //如果出库的数据小于这个退库的数量差,则先该批次出库数量出完
|
|
5055
|
+ if out_count < cha_count {
|
|
5056
|
+
|
|
5057
|
+ //把该出库单的数量退完
|
|
5058
|
+ ModifyNewDrugWarehouseInfoStockMinNumber(out_count, drugOutInfo.DrugId, drugOutInfo.OrgId, drugOutInfo.WarehouseInfoId, tx)
|
|
5059
|
+
|
|
5060
|
+ //删除该出库单
|
|
5061
|
+ DeleteDrugWarehouseOutInfoByNumber(drugOutInfo.ID, tx)
|
|
5062
|
+
|
|
5063
|
+ //创建退库单
|
|
5064
|
+ //查询剩余库存
|
|
5065
|
+ stockInfo, _ := GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgID, advice.DrugId, tx)
|
|
5066
|
+ var sum_count int64
|
|
5067
|
+ for _, its := range stockInfo {
|
|
5068
|
+ if its.MaxUnit == drug.MaxUnit {
|
|
5069
|
+ its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
|
|
5070
|
+ }
|
|
5071
|
+ sum_count += its.StockMaxNumber + its.StockMinNumber
|
|
5072
|
+ }
|
|
5073
|
+
|
|
5074
|
+ //创建退库单
|
|
5075
|
+ operation_time := time.Now().Unix()
|
|
5076
|
+ ctime := time.Now().Unix()
|
|
5077
|
+ timeStr := time.Now().Format("2006-01-02")
|
|
5078
|
+ timeArr := strings.Split(timeStr, "-")
|
|
5079
|
+ total, _ := FindAllDrugCancelStockTotal(advice.UserOrgId)
|
|
5080
|
+ total = total + 1
|
|
5081
|
+ orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
|
|
5082
|
+ cancelStock := models.DrugCancelStock{
|
|
5083
|
+ OrderNumber: orderNumber,
|
|
5084
|
+ OperaTime: operation_time,
|
|
5085
|
+ OrgId: advice.UserOrgId,
|
|
5086
|
+ Creater: advice.ExecutionStaff,
|
|
5087
|
+ Ctime: ctime,
|
|
5088
|
+ Status: 1,
|
|
5089
|
+ ReturnTime: advice.AdviceDate,
|
|
5090
|
+ Dealer: 0,
|
|
5091
|
+ Manufacturer: 0,
|
|
5092
|
+ Type: 1,
|
|
5093
|
+ StorehouseId: storeConfig.DrugStorehouseOut,
|
|
5094
|
+ IsCheck: 1,
|
|
5095
|
+ }
|
|
5096
|
+
|
|
5097
|
+ _, errCode := FindNewDrugCancelStock(advice.AdviceDate, advice.UserOrgId, tx)
|
|
5098
|
+ if errCode == gorm.ErrRecordNotFound {
|
|
5099
|
+ AddNewSigleDrugCancelStock(&cancelStock, tx)
|
|
5100
|
+ }
|
|
5101
|
+ lastDrugCancelStock, _ := FindNewLastDrugCancelStock(advice.AdviceDate, advice.UserOrgId, tx)
|
|
5102
|
+
|
|
5103
|
+ manufactureName, _ := GetNewManufactureById(drugOutInfo.Manufacturer, tx)
|
|
5104
|
+ dealer, _ := GetNewDealerById(drugOutInfo.Dealer, tx)
|
|
5105
|
+ cancelInfo, _ := GetNewLastDrugCancelStockById(advice.UserOrgId, tx)
|
|
5106
|
+ cancelStockInfo := models.DrugCancelStockInfo{
|
|
5107
|
+ OrderNumber: cancelInfo.OrderNumber,
|
|
5108
|
+ CancelStockId: lastDrugCancelStock.ID,
|
|
5109
|
+ DrugId: advice.DrugId,
|
|
5110
|
+ Count: out_count,
|
|
5111
|
+ Status: 1,
|
|
5112
|
+ Ctime: advice.AdviceDate,
|
|
5113
|
+ Mtime: time.Now().Unix(),
|
|
5114
|
+ OrgId: advice.UserOrgId,
|
|
5115
|
+ Type: 1,
|
|
5116
|
+ Manufacturer: manufactureName.ManufacturerName,
|
|
5117
|
+ Dealer: dealer.DealerName,
|
|
5118
|
+ Total: 0,
|
|
5119
|
+ RetailPrice: drugOutInfo.RetailPrice,
|
|
5120
|
+ RetailTotalPrice: drugOutInfo.RetailTotalPrice,
|
|
5121
|
+ Price: drugOutInfo.Price,
|
|
5122
|
+ RegisterAccount: "",
|
|
5123
|
+ Remark: drugOutInfo.Remark,
|
|
5124
|
+ BatchNumber: drugOutInfo.BatchNumber,
|
|
5125
|
+ MaxUnit: drugOutInfo.CountUnit,
|
|
5126
|
+ ProductDate: drugOutInfo.ProductDate,
|
|
5127
|
+ ExpiryDate: drugOutInfo.ExpiryDate,
|
|
5128
|
+ BatchNumberId: drugOutInfo.WarehouseInfoId,
|
|
5129
|
+ StorehouseId: storeConfig.DrugStorehouseOut,
|
|
5130
|
+ IsCheck: 1,
|
|
5131
|
+ }
|
|
5132
|
+ CreatedNewCancelStock(cancelStockInfo, tx)
|
|
5133
|
+
|
|
5134
|
+ flow := models.DrugFlow{
|
|
5135
|
+ WarehousingId: drugOutInfo.WarehouseInfoId,
|
|
5136
|
+ DrugId: drugOutInfo.DrugId,
|
|
5137
|
+ Number: "",
|
|
5138
|
+ BatchNumber: drugOutInfo.BatchNumber,
|
|
5139
|
+ Count: out_count,
|
|
5140
|
+ UserOrgId: advice.UserOrgId,
|
|
5141
|
+ PatientId: advice.PatientId,
|
|
5142
|
+ SystemTime: advice.AdviceDate,
|
|
5143
|
+ ConsumableType: 7,
|
|
5144
|
+ IsSys: 0,
|
|
5145
|
+ WarehousingOrder: "",
|
|
5146
|
+ WarehouseOutId: 0,
|
|
5147
|
+ WarehouseOutOrderNumber: "",
|
|
5148
|
+ IsEdit: 0,
|
|
5149
|
+ CancelStockId: cancelStock.ID,
|
|
5150
|
+ CancelOrderNumber: cancelStock.OrderNumber,
|
|
5151
|
+ Manufacturer: drugOutInfo.Manufacturer,
|
|
5152
|
+ Dealer: drugOutInfo.Dealer,
|
|
5153
|
+ Creator: advice.ExecutionStaff,
|
|
5154
|
+ UpdateCreator: 0,
|
|
5155
|
+ Status: 1,
|
|
5156
|
+ Ctime: advice.AdviceDate,
|
|
5157
|
+ Mtime: time.Now().Unix(),
|
|
5158
|
+ Price: drugOutInfo.RetailPrice,
|
|
5159
|
+ WarehousingDetailId: drugOutInfo.ID,
|
|
5160
|
+ WarehouseOutDetailId: 0,
|
|
5161
|
+ CancelOutDetailId: lastDrugCancelStock.ID,
|
|
5162
|
+ ExpireDate: drugOutInfo.ExpiryDate,
|
|
5163
|
+ ProductDate: drugOutInfo.ProductDate,
|
|
5164
|
+ MaxUnit: drugOutInfo.CountUnit,
|
|
5165
|
+ MinUnit: "",
|
|
5166
|
+ AdviceId: advice.ID,
|
|
5167
|
+ StorehouseId: storeConfig.DrugStorehouseOut,
|
|
5168
|
+ LastPrice: drugOutInfo.Price,
|
|
5169
|
+ OverCount: sum_count,
|
|
5170
|
+ }
|
|
5171
|
+ CreateNewDrugFlowOne(flow, tx)
|
|
5172
|
+
|
|
5173
|
+ AddNewCancelSumCountOne(storeConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, flow.Count, tx)
|
|
5174
|
+
|
|
5175
|
+ ReduceNewDrugCountTwo(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, flow.Count, tx)
|
|
5176
|
+
|
|
5177
|
+ //计算还有多少没有退库
|
|
5178
|
+ var over_count = cha_count - out_count
|
|
5179
|
+
|
|
5180
|
+ NewHisDrugCancelInfo(orgID, creater, advice, over_count, drug, tx)
|
|
5181
|
+ }
|
|
5182
|
+ return err
|
|
5183
|
+
|
|
5184
|
+}
|
|
5185
|
+
|
|
5186
|
+func NewHisDrugAutoCancelInfo(orgID int64, creater int64, advice *models.HisDoctorAdviceInfo, cha_count int64, drug models.BaseDrugLibSeven, tx *gorm.DB) error {
|
|
5187
|
+
|
|
5188
|
+ //查找患者最后一条的退库数据是否满足要求
|
|
5189
|
+ var out_count int64
|
|
5190
|
+ drugOutInfo, _ := GetDrugAutoOutInfoByAdviceIdTwo(advice.PatientId, advice.UserOrgId, advice.AdviceDate, advice.DrugId, advice.ID, tx)
|
|
5191
|
+
|
|
5192
|
+ if drugOutInfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
|
|
5193
|
+
|
|
5194
|
+ out_count = drugOutInfo.Count * drug.MinNumber
|
|
5195
|
+ }
|
|
5196
|
+
|
|
5197
|
+ if drugOutInfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
|
|
5198
|
+
|
|
5199
|
+ out_count = drugOutInfo.Count
|
|
5200
|
+ }
|
|
5201
|
+
|
|
5202
|
+ if drugOutInfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
|
|
5203
|
+
|
|
5204
|
+ out_count = drugOutInfo.Count
|
|
5205
|
+ }
|
|
5206
|
+
|
|
5207
|
+ //fmt.Println("out_count++++==++", out_count)
|
|
5208
|
+ //fmt.Println("cha_count-------", cha_count)
|
|
5209
|
+
|
|
5210
|
+ //如果最后1条出库数量大于退库数量,则直接退库,满足退库要求
|
|
5211
|
+ if out_count >= cha_count {
|
|
5212
|
+ //减去出库单里面的数量
|
|
5213
|
+ ModifyDrugAuToWarehouseOut(drugOutInfo.ID, cha_count, tx)
|
|
5214
|
+
|
|
5215
|
+ if out_count == cha_count {
|
|
5216
|
+ //删除该出库单
|
|
5217
|
+ DeleteDrugWarehouseAutoByNumber(drugOutInfo.ID, tx)
|
|
5218
|
+ }
|
|
5219
|
+ }
|
|
5220
|
+
|
|
5221
|
+ //如果出库的数据小于这个退库的数量差,则先该批次出库数量出完
|
|
5222
|
+ if out_count < cha_count {
|
|
5223
|
+
|
|
5224
|
+ //删除该出库单
|
|
5225
|
+ DeleteDrugWarehouseAutoByNumber(drugOutInfo.ID, tx)
|
|
5226
|
+
|
|
5227
|
+ //计算还有多少没有退库
|
|
5228
|
+ var over_count = cha_count - out_count
|
|
5229
|
+
|
|
5230
|
+ NewHisDrugAutoCancelInfo(orgID, creater, advice, over_count, drug, tx)
|
|
5231
|
+ }
|
|
5232
|
+ return err
|
|
5233
|
+}
|