Browse Source

11月9日库存管理

XMLWAN 2 years ago
parent
commit
0280e8eb72

+ 42 - 30
controllers/dialysis_api_controller.go View File

@@ -3764,7 +3764,7 @@ func (this *DialysisApiController) GetTodayMonitor() {
3764 3764
 				record.UltrafiltrationRate = ultrafiltration_rate
3765 3765
 			}
3766 3766
 
3767
-			if adminInfo.CurrentOrgId == 10395 {
3767
+			if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 {
3768 3768
 				ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
3769 3769
 
3770 3770
 				record.UltrafiltrationRate = ultrafiltration_rate
@@ -3792,7 +3792,7 @@ func (this *DialysisApiController) GetTodayMonitor() {
3792 3792
 
3793 3793
 	}
3794 3794
 
3795
-	if adminInfo.CurrentOrgId == 10395 {
3795
+	if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 {
3796 3796
 
3797 3797
 		if ultrafiltration_rate > 0 {
3798 3798
 			ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate / 1000)
@@ -4358,33 +4358,43 @@ func (this *DialysisApiController) SaveDialysisSetting() {
4358 4358
 	bicarbonate_set, _ := this.GetInt64("bicarbonate_set")
4359 4359
 	glucose_set, _ := this.GetInt64("glucose_set")
4360 4360
 
4361
+	sodium_set, _ := this.GetInt64("sodium_set")
4362
+	calcium_set, _ := this.GetInt64("calcium_set")
4363
+	blood_access_set, _ := this.GetInt64("blood_access_set")
4364
+	dialyzer_perfusion_apparatus_set, _ := this.GetInt64("dialyzer_perfusion_apparatus_set")
4365
+	displace_liqui_part_set, _ := this.GetInt64("displace_liqui_part_set")
4361 4366
 	dialysisSetting := models.XtDialysisSetting{
4362
-		UserOrgId:             orgId,
4363
-		Status:                1,
4364
-		DeviceNumber:          device_number_set,
4365
-		DeviceType:            device_type_set,
4366
-		Name:                  name_set,
4367
-		AdmissionNumber:       admission_number_set,
4368
-		DialysisNo:            dialysis_no_set,
4369
-		WeightBefor:           weight_befor_set,
4370
-		DryWeight:             dry_weight_set,
4371
-		BloodPressure:         blood_pressure_set,
4372
-		UltrafiltrationVolume: ultrafiltration_volume_set,
4373
-		InternalFistula:       internal_fistula_set,
4374
-		BloodFlowVolume:       blood_flow_volume_set,
4375
-		Anticoagulant:         anticoagulant_set,
4376
-		SealingFluidDispose:   sealing_fluid_dispose_set,
4377
-		ModeId:                mode_id_set,
4378
-		DialysisTime:          dialysis_time_set,
4379
-		DialysisDialyszers:    dialysis_dialyszers_set,
4380
-		DialysisIrrigation:    dialysis_irrigation_set,
4381
-		Gaijiliang:            gaijiliang_set,
4382
-		Kalium:                kalium_set,
4383
-		DisplaceLiquiValue:    displace_liqui_value_set,
4384
-		Bicarbonate:           bicarbonate_set,
4385
-		Glucose:               glucose_set,
4386
-		Ctime:                 time.Now().Unix(),
4387
-		Mtime:                 time.Now().Unix(),
4367
+		Sodium:                     sodium_set,
4368
+		Calcium:                    calcium_set,
4369
+		BloodAccess:                blood_access_set,
4370
+		DialyzerPerfusionApparatus: dialyzer_perfusion_apparatus_set,
4371
+		DisplaceLiquiPart:          displace_liqui_part_set,
4372
+		UserOrgId:                  orgId,
4373
+		Status:                     1,
4374
+		DeviceNumber:               device_number_set,
4375
+		DeviceType:                 device_type_set,
4376
+		Name:                       name_set,
4377
+		AdmissionNumber:            admission_number_set,
4378
+		DialysisNo:                 dialysis_no_set,
4379
+		WeightBefor:                weight_befor_set,
4380
+		DryWeight:                  dry_weight_set,
4381
+		BloodPressure:              blood_pressure_set,
4382
+		UltrafiltrationVolume:      ultrafiltration_volume_set,
4383
+		InternalFistula:            internal_fistula_set,
4384
+		BloodFlowVolume:            blood_flow_volume_set,
4385
+		Anticoagulant:              anticoagulant_set,
4386
+		SealingFluidDispose:        sealing_fluid_dispose_set,
4387
+		ModeId:                     mode_id_set,
4388
+		DialysisTime:               dialysis_time_set,
4389
+		DialysisDialyszers:         dialysis_dialyszers_set,
4390
+		DialysisIrrigation:         dialysis_irrigation_set,
4391
+		Gaijiliang:                 gaijiliang_set,
4392
+		Kalium:                     kalium_set,
4393
+		DisplaceLiquiValue:         displace_liqui_value_set,
4394
+		Bicarbonate:                bicarbonate_set,
4395
+		Glucose:                    glucose_set,
4396
+		Ctime:                      time.Now().Unix(),
4397
+		Mtime:                      time.Now().Unix(),
4388 4398
 	}
4389 4399
 	err := service.SaveDialysisSetting(dialysisSetting)
4390 4400
 	if err == nil {
@@ -4430,10 +4440,12 @@ func (this *DialysisApiController) GetDialysisParameterList() {
4430 4440
 
4431 4441
 	list, total, err := service.GetDialysisParameterList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId)
4432 4442
 
4443
+	dialysisSett, _ := service.GetDialysisSetting(orgId)
4433 4444
 	if err == nil {
4434 4445
 		this.ServeSuccessJSON(map[string]interface{}{
4435
-			"list":  list,
4436
-			"total": total,
4446
+			"list":         list,
4447
+			"total":        total,
4448
+			"dialysisSett": dialysisSett,
4437 4449
 		})
4438 4450
 		return
4439 4451
 

+ 38 - 25
controllers/drug_stock_api_contorller.go View File

@@ -3759,6 +3759,7 @@ func (c *StockDrugApiController) CheckDrugOut() {
3759 3759
 	storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
3760 3760
 
3761 3761
 	for _, it := range warehousingOutInfoList {
3762
+		fmt.Println("countunit23322332232323wo", it.CountUnit)
3762 3763
 		var total_count int64
3763 3764
 		var out_count int64
3764 3765
 		//查询剩余库存
@@ -3800,27 +3801,17 @@ func (c *StockDrugApiController) CheckDrugOut() {
3800 3801
 			return
3801 3802
 		}
3802 3803
 	}
3803
-	for _, it := range warehousingOutInfoList {
3804
-
3805
-		drup, _ := service.FindBaseDrugLibRecord(it.OrgId, it.DrugId)
3806
-		//出库逻辑
3807
-		service.AutoDrugDeliverInfoFourtyOne(orgId, it.Count, &drugWarehouseOut, &drup, it)
3804
+	warehousingOutInfoListTwo, _ := service.GetDrugWarehouseOutListById(warehouse_out_id, orgId)
3808 3805
 
3806
+	for _, it := range warehousingOutInfoListTwo {
3809 3807
 		medical, _ := service.GetBaseDrugMedical(it.DrugId)
3810
-		//查询剩余库存
3811
-		stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, it.OrgId, it.DrugId)
3812
-		var sum_count int64
3813
-		for _, its := range stockInfo {
3814
-			if its.MaxUnit == medical.MaxUnit {
3815
-				its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
3816
-			}
3817
-			sum_count += its.StockMaxNumber + its.StockMinNumber
3818
-		}
3819
-		//更新基础库库存
3820
-		service.UpdateBaseDrugSumTwo(it.DrugId, sum_count, it.OrgId)
3821
-
3822 3808
 		////出库数量累加
3823 3809
 		var out_count_one int64
3810
+		fmt.Println("it.count", it.CountUnit)
3811
+		fmt.Println("MaxUnit", medical.MaxUnit)
3812
+		fmt.Println("MinUnit", medical.MinUnit)
3813
+		fmt.Println("count", it.Count)
3814
+		fmt.Println("number", medical.MinNumber)
3824 3815
 		if it.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
3825 3816
 			out_count_one = it.Count * medical.MinNumber
3826 3817
 		}
@@ -3829,21 +3820,43 @@ func (c *StockDrugApiController) CheckDrugOut() {
3829 3820
 			out_count_one = it.Count
3830 3821
 		}
3831 3822
 
3832
-		if it.CountUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
3823
+		if it.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
3833 3824
 			out_count_one = it.Count
3834 3825
 		}
3835
-
3826
+		fmt.Println("countone3232232323323232332332wo", out_count_one)
3836 3827
 		//增加出库数量
3837 3828
 		service.AddDrugCount(it.DrugId, it.OrgId, storeHouseConfig.DrugStorehouseOut, out_count_one)
3829
+		fmt.Println("countunit23322332232323", it.CountUnit)
3838 3830
 
3839
-		//查询该药品剩余库存
3840
-		infolist, _ := service.FindDrugWarehouseInfoFlushCountByStorehouse(it.DrugId, it.OrgId, storeHouseConfig.DrugStorehouseOut)
3841
-		var over_count int64
3842
-		for _, its := range infolist {
3843
-			over_count += its.StockMaxNumber*medical.MinNumber + its.StockMinNumber
3831
+	}
3832
+	warehousingOutInfoListThree, _ := service.GetDrugWarehouseOutListById(warehouse_out_id, orgId)
3833
+	for _, it := range warehousingOutInfoListThree {
3834
+		medical, _ := service.GetBaseDrugMedical(it.DrugId)
3835
+		drup, _ := service.FindBaseDrugLibRecord(it.OrgId, it.DrugId)
3836
+		//出库逻辑
3837
+		service.AutoDrugDeliverInfoFourtyOne(orgId, it.Count, &drugWarehouseOut, &drup, it)
3838
+
3839
+		//查询剩余库存
3840
+		stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, it.OrgId, it.DrugId)
3841
+		var sum_count int64
3842
+		for _, its := range stockInfo {
3843
+			if its.MaxUnit == medical.MaxUnit {
3844
+				its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
3845
+			}
3846
+			sum_count += its.StockMaxNumber + its.StockMinNumber
3844 3847
 		}
3848
+		//更新基础库库存
3849
+		service.UpdateBaseDrugSumTwo(it.DrugId, sum_count, it.OrgId)
3850
+
3851
+		//查询该药品剩余库存
3852
+		//infolist, _ := service.FindDrugWarehouseInfoFlushCountByStorehouse(it.DrugId, it.OrgId, storeHouseConfig.DrugStorehouseOut)
3853
+		//var over_count int64
3854
+		//for _, its := range infolist {
3855
+		//  over_count += its.StockMaxNumber*medical.MinNumber + its.StockMinNumber
3856
+		//}
3845 3857
 		//更新剩余库存
3846
-		service.UpdateDrugStockCount(it.DrugId, it.OrgId, storeHouseConfig.DrugStorehouseOut, over_count)
3858
+		service.UpdateDrugStockCount(it.DrugId, it.OrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
3859
+
3847 3860
 	}
3848 3861
 
3849 3862
 	out := models.DrugWarehouseOut{

+ 295 - 152
controllers/his_api_controller.go View File

@@ -1109,7 +1109,7 @@ func (c *HisApiController) CreateHisPrescription() {
1109 1109
 												return
1110 1110
 											}
1111 1111
 
1112
-											if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 9671 {
1112
+											if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
1113 1113
 												if prescribing_number > batch_number_all_count {
1114 1114
 													c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1115 1115
 													return
@@ -1126,7 +1126,7 @@ func (c *HisApiController) CreateHisPrescription() {
1126 1126
 												c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1127 1127
 												return
1128 1128
 											}
1129
-											if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 9671 {
1129
+											if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
1130 1130
 												if num > batch_number_all_count {
1131 1131
 													c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1132 1132
 													return
@@ -1195,7 +1195,7 @@ func (c *HisApiController) CreateHisPrescription() {
1195 1195
 														c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1196 1196
 														return
1197 1197
 													}
1198
-													if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 9671 {
1198
+													if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
1199 1199
 														if prescribing_number > batch_number_all_count {
1200 1200
 															c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1201 1201
 															return
@@ -1213,7 +1213,7 @@ func (c *HisApiController) CreateHisPrescription() {
1213 1213
 															c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1214 1214
 															return
1215 1215
 														}
1216
-														if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 9671 {
1216
+														if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
1217 1217
 															if prescribing_number > batch_number_all_count {
1218 1218
 																c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1219 1219
 																return
@@ -2563,89 +2563,164 @@ func (c *HisApiController) DeletePrescription() {
2563 2563
 					manufacturer, _ := service.GetManufactureById(info.Manufacturer)
2564 2564
 					deaerler, _ := service.GetDealerById(info.Dealer)
2565 2565
 
2566
-					//查询今日该患者开了多少耗材
2567
-					//projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
2568
-					//
2569 2566
 					var total_count int64
2570
-					//var cha_count int64
2571
-					//for _, item := range projectList {
2572
-					//  count, _ := strconv.ParseInt(item.Count, 10, 64)
2573
-					//  total_count += count
2574
-					//}
2575 2567
 					count, _ := strconv.ParseInt(item.Count, 10, 64)
2576 2568
 					total_count += count
2577
-					//回退库存
2578
-					service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
2569
+
2579 2570
 					goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
2580 2571
 					var flush_count int64
2581 2572
 					for _, it := range goodList {
2582 2573
 						flush_count += it.StockCount
2583 2574
 					}
2584 2575
 					if info.ID > 0 {
2585
-						cancelStockInfo := models.CancelStockInfo{
2586
-							GoodId:          item.ProjectId,
2587
-							CancelStockId:   cancel.ID,
2588
-							GoodTypeId:      good.GoodTypeId,
2589
-							Count:           prescribingNumber,
2590
-							Price:           info.Price,
2591
-							Total:           0,
2592
-							ProductDate:     info.ProductDate,
2593
-							ExpiryDate:      info.ExpiryDate,
2594
-							Ctime:           time.Now().Unix(),
2595
-							Status:          1,
2596
-							OrgId:           c.GetAdminUserInfo().CurrentOrgId,
2597
-							OrderNumber:     cancel.OrderNumber,
2598
-							Type:            0,
2599
-							Dealer:          deaerler.DealerName,
2600
-							Manufacturer:    manufacturer.ManufacturerName,
2601
-							Number:          info.Number,
2602
-							RegisterAccount: "",
2603
-							Remark:          "",
2604
-							WarehouseInfoId: info.WarehouseInfotId,
2605
-							PatientId:       info.PatientId,
2606
-							RecordDate:      info.SysRecordTime,
2607
-							StorehouseId:    houseConfig.StorehouseOutInfo,
2608
-							IsCheck:         1,
2576
+						if info.Count >= total_count {
2577
+
2578
+							//回退库存
2579
+							service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
2580
+							cancelStockInfo := models.CancelStockInfo{
2581
+								GoodId:          item.ProjectId,
2582
+								CancelStockId:   cancel.ID,
2583
+								GoodTypeId:      good.GoodTypeId,
2584
+								Count:           prescribingNumber,
2585
+								Price:           info.Price,
2586
+								Total:           0,
2587
+								ProductDate:     info.ProductDate,
2588
+								ExpiryDate:      info.ExpiryDate,
2589
+								Ctime:           time.Now().Unix(),
2590
+								Status:          1,
2591
+								OrgId:           c.GetAdminUserInfo().CurrentOrgId,
2592
+								OrderNumber:     cancel.OrderNumber,
2593
+								Type:            0,
2594
+								Dealer:          deaerler.DealerName,
2595
+								Manufacturer:    manufacturer.ManufacturerName,
2596
+								Number:          info.Number,
2597
+								RegisterAccount: "",
2598
+								Remark:          "",
2599
+								WarehouseInfoId: info.WarehouseInfotId,
2600
+								PatientId:       info.PatientId,
2601
+								RecordDate:      info.SysRecordTime,
2602
+								StorehouseId:    houseConfig.StorehouseOutInfo,
2603
+								IsCheck:         1,
2604
+							}
2605
+
2606
+							service.CreateCancelStockInfoOne(&cancelStockInfo)
2607
+
2608
+							cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
2609
+
2610
+							flow := models.VmStockFlow{
2611
+								WarehousingId:           info.WarehouseInfotId,
2612
+								GoodId:                  item.ProjectId,
2613
+								Number:                  info.Number,
2614
+								LicenseNumber:           info.LicenseNumber,
2615
+								Count:                   prescribingNumber,
2616
+								UserOrgId:               c.GetAdminUserInfo().CurrentOrgId,
2617
+								PatientId:               item.PatientId,
2618
+								SystemTime:              info.SysRecordTime,
2619
+								ConsumableType:          7,
2620
+								IsSys:                   0,
2621
+								WarehousingOrder:        "",
2622
+								WarehouseOutId:          info.WarehouseOutId,
2623
+								WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
2624
+								IsEdit:                  0,
2625
+								CancelStockId:           cancel.ID,
2626
+								CancelOrderNumber:       cancel.OrderNumber,
2627
+								Manufacturer:            manufacturer.ID,
2628
+								Dealer:                  0,
2629
+								Creator:                 c.GetAdminUserInfo().CurrentOrgId,
2630
+								UpdateCreator:           0,
2631
+								Status:                  1,
2632
+								Ctime:                   time.Now().Unix(),
2633
+								Mtime:                   0,
2634
+								Price:                   info.Price,
2635
+								WarehousingDetailId:     info.WarehouseInfotId,
2636
+								WarehouseOutDetailId:    info.ID,
2637
+								CancelOutDetailId:       cancelInfo.ID,
2638
+								ProductDate:             info.ProductDate,
2639
+								ExpireDate:              info.ExpiryDate,
2640
+								StorehouseId:            houseConfig.StorehouseOutInfo,
2641
+								OverCount:               flush_count,
2642
+							}
2643
+							service.CreateStockFlowOne(flow)
2644
+
2645
+							//退库数量增加
2646
+							service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
2647
+							//出库数量减少
2648
+							service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
2609 2649
 						}
2610 2650
 
2611
-						service.CreateCancelStockInfoOne(&cancelStockInfo)
2612
-
2613
-						cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
2614
-
2615
-						flow := models.VmStockFlow{
2616
-							WarehousingId:           info.WarehouseInfotId,
2617
-							GoodId:                  item.ProjectId,
2618
-							Number:                  info.Number,
2619
-							LicenseNumber:           info.LicenseNumber,
2620
-							Count:                   prescribingNumber,
2621
-							UserOrgId:               c.GetAdminUserInfo().CurrentOrgId,
2622
-							PatientId:               item.PatientId,
2623
-							SystemTime:              info.SysRecordTime,
2624
-							ConsumableType:          7,
2625
-							IsSys:                   0,
2626
-							WarehousingOrder:        "",
2627
-							WarehouseOutId:          info.WarehouseOutId,
2628
-							WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
2629
-							IsEdit:                  0,
2630
-							CancelStockId:           cancel.ID,
2631
-							CancelOrderNumber:       cancel.OrderNumber,
2632
-							Manufacturer:            manufacturer.ID,
2633
-							Dealer:                  0,
2634
-							Creator:                 c.GetAdminUserInfo().CurrentOrgId,
2635
-							UpdateCreator:           0,
2636
-							Status:                  1,
2637
-							Ctime:                   time.Now().Unix(),
2638
-							Mtime:                   0,
2639
-							Price:                   info.Price,
2640
-							WarehousingDetailId:     info.WarehouseInfotId,
2641
-							WarehouseOutDetailId:    info.ID,
2642
-							CancelOutDetailId:       cancelInfo.ID,
2643
-							ProductDate:             info.ProductDate,
2644
-							ExpireDate:              info.ExpiryDate,
2645
-							StorehouseId:            houseConfig.StorehouseOutInfo,
2646
-							OverCount:               flush_count,
2651
+						if info.Count < total_count {
2652
+							//回退库存
2653
+							service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
2654
+							cancelStockInfo := models.CancelStockInfo{
2655
+								GoodId:          item.ProjectId,
2656
+								CancelStockId:   cancel.ID,
2657
+								GoodTypeId:      good.GoodTypeId,
2658
+								Count:           info.Count,
2659
+								Price:           info.Price,
2660
+								Total:           0,
2661
+								ProductDate:     info.ProductDate,
2662
+								ExpiryDate:      info.ExpiryDate,
2663
+								Ctime:           time.Now().Unix(),
2664
+								Status:          1,
2665
+								OrgId:           c.GetAdminUserInfo().CurrentOrgId,
2666
+								OrderNumber:     cancel.OrderNumber,
2667
+								Type:            0,
2668
+								Dealer:          deaerler.DealerName,
2669
+								Manufacturer:    manufacturer.ManufacturerName,
2670
+								Number:          info.Number,
2671
+								RegisterAccount: "",
2672
+								Remark:          "",
2673
+								WarehouseInfoId: info.WarehouseInfotId,
2674
+								PatientId:       info.PatientId,
2675
+								RecordDate:      info.SysRecordTime,
2676
+								StorehouseId:    houseConfig.StorehouseOutInfo,
2677
+								IsCheck:         1,
2678
+							}
2679
+
2680
+							service.CreateCancelStockInfoOne(&cancelStockInfo)
2681
+
2682
+							cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
2683
+
2684
+							flow := models.VmStockFlow{
2685
+								WarehousingId:           info.WarehouseInfotId,
2686
+								GoodId:                  item.ProjectId,
2687
+								Number:                  info.Number,
2688
+								LicenseNumber:           info.LicenseNumber,
2689
+								Count:                   info.Count,
2690
+								UserOrgId:               c.GetAdminUserInfo().CurrentOrgId,
2691
+								PatientId:               item.PatientId,
2692
+								SystemTime:              info.SysRecordTime,
2693
+								ConsumableType:          7,
2694
+								IsSys:                   0,
2695
+								WarehousingOrder:        "",
2696
+								WarehouseOutId:          info.WarehouseOutId,
2697
+								WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
2698
+								IsEdit:                  0,
2699
+								CancelStockId:           cancel.ID,
2700
+								CancelOrderNumber:       cancel.OrderNumber,
2701
+								Manufacturer:            manufacturer.ID,
2702
+								Dealer:                  0,
2703
+								Creator:                 c.GetAdminUserInfo().CurrentOrgId,
2704
+								UpdateCreator:           0,
2705
+								Status:                  1,
2706
+								Ctime:                   time.Now().Unix(),
2707
+								Mtime:                   0,
2708
+								Price:                   info.Price,
2709
+								WarehousingDetailId:     info.WarehouseInfotId,
2710
+								WarehouseOutDetailId:    info.ID,
2711
+								CancelOutDetailId:       cancelInfo.ID,
2712
+								ProductDate:             info.ProductDate,
2713
+								ExpireDate:              info.ExpiryDate,
2714
+								StorehouseId:            houseConfig.StorehouseOutInfo,
2715
+								OverCount:               flush_count,
2716
+							}
2717
+							service.CreateStockFlowOne(flow)
2718
+
2719
+							//退库数量增加
2720
+							service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
2721
+							//出库数量减少
2722
+							service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
2647 2723
 						}
2648
-						service.CreateStockFlowOne(flow)
2649 2724
 
2650 2725
 						//查询已出库数量
2651 2726
 						dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
@@ -2655,16 +2730,11 @@ func (c *HisApiController) DeletePrescription() {
2655 2730
 							service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
2656 2731
 						}
2657 2732
 
2658
-						if prescribingNumber == dialysisInfo.Count {
2733
+						if prescribingNumber >= dialysisInfo.Count {
2659 2734
 							//删除出库表
2660 2735
 							service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
2661 2736
 						}
2662 2737
 
2663
-						//退库数量增加
2664
-						service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
2665
-						//出库数量减少
2666
-						service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
2667
-
2668 2738
 						//更新库存
2669 2739
 						service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
2670 2740
 
@@ -2969,77 +3039,156 @@ func (c *HisApiController) DeleteProject() {
2969 3039
 			manufacturer, _ := service.GetManufactureById(info.Manufacturer)
2970 3040
 			deaerler, _ := service.GetDealerById(info.Dealer)
2971 3041
 			if info.ID > 0 {
2972
-				cancelStockInfo := models.CancelStockInfo{
2973
-					GoodId:          project.ProjectId,
2974
-					CancelStockId:   cancel.ID,
2975
-					GoodTypeId:      good.GoodTypeId,
2976
-					Count:           prescribingNumber,
2977
-					Price:           info.Price,
2978
-					Total:           0,
2979
-					ProductDate:     info.ProductDate,
2980
-					ExpiryDate:      info.ExpiryDate,
2981
-					Ctime:           time.Now().Unix(),
2982
-					Status:          1,
2983
-					OrgId:           adminInfo.CurrentOrgId,
2984
-					OrderNumber:     cancel.OrderNumber,
2985
-					Type:            0,
2986
-					Dealer:          deaerler.DealerName,
2987
-					Manufacturer:    manufacturer.ManufacturerName,
2988
-					Number:          info.Number,
2989
-					RegisterAccount: "",
2990
-					Remark:          "",
2991
-					WarehouseInfoId: info.WarehouseInfotId,
2992
-					PatientId:       info.PatientId,
2993
-					RecordDate:      info.SysRecordTime,
2994
-					StorehouseId:    houseConfig.StorehouseOutInfo,
2995
-					IsCheck:         1,
2996
-				}
2997
-
2998
-				service.CreateCancelStockInfoOne(&cancelStockInfo)
2999
-
3000 3042
 				cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
3043
+				if info.Count >= prescribingNumber {
3044
+					cancelStockInfo := models.CancelStockInfo{
3045
+						GoodId:          project.ProjectId,
3046
+						CancelStockId:   cancel.ID,
3047
+						GoodTypeId:      good.GoodTypeId,
3048
+						Count:           prescribingNumber,
3049
+						Price:           info.Price,
3050
+						Total:           0,
3051
+						ProductDate:     info.ProductDate,
3052
+						ExpiryDate:      info.ExpiryDate,
3053
+						Ctime:           time.Now().Unix(),
3054
+						Status:          1,
3055
+						OrgId:           adminInfo.CurrentOrgId,
3056
+						OrderNumber:     cancel.OrderNumber,
3057
+						Type:            0,
3058
+						Dealer:          deaerler.DealerName,
3059
+						Manufacturer:    manufacturer.ManufacturerName,
3060
+						Number:          info.Number,
3061
+						RegisterAccount: "",
3062
+						Remark:          "",
3063
+						WarehouseInfoId: info.WarehouseInfotId,
3064
+						PatientId:       info.PatientId,
3065
+						RecordDate:      info.SysRecordTime,
3066
+						StorehouseId:    houseConfig.StorehouseOutInfo,
3067
+						IsCheck:         1,
3068
+					}
3069
+
3070
+					service.CreateCancelStockInfoOne(&cancelStockInfo)
3071
+					//回退库存
3072
+					service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
3073
+					//退库数量增加
3074
+					service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
3075
+					//出库数量减少
3076
+					service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
3077
+				}
3078
+				if info.Count < prescribingNumber {
3079
+					cancelStockInfo := models.CancelStockInfo{
3080
+						GoodId:          project.ProjectId,
3081
+						CancelStockId:   cancel.ID,
3082
+						GoodTypeId:      good.GoodTypeId,
3083
+						Count:           info.Count,
3084
+						Price:           info.Price,
3085
+						Total:           0,
3086
+						ProductDate:     info.ProductDate,
3087
+						ExpiryDate:      info.ExpiryDate,
3088
+						Ctime:           time.Now().Unix(),
3089
+						Status:          1,
3090
+						OrgId:           adminInfo.CurrentOrgId,
3091
+						OrderNumber:     cancel.OrderNumber,
3092
+						Type:            0,
3093
+						Dealer:          deaerler.DealerName,
3094
+						Manufacturer:    manufacturer.ManufacturerName,
3095
+						Number:          info.Number,
3096
+						RegisterAccount: "",
3097
+						Remark:          "",
3098
+						WarehouseInfoId: info.WarehouseInfotId,
3099
+						PatientId:       info.PatientId,
3100
+						RecordDate:      info.SysRecordTime,
3101
+						StorehouseId:    houseConfig.StorehouseOutInfo,
3102
+						IsCheck:         1,
3103
+					}
3104
+
3105
+					service.CreateCancelStockInfoOne(&cancelStockInfo)
3106
+					//回退库存
3107
+					service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
3108
+					//退库数量增加
3109
+					service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
3110
+					//出库数量减少
3111
+					service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
3112
+				}
3001 3113
 
3002
-				//回退库存
3003
-				service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
3004 3114
 				goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
3005 3115
 				var over_count int64
3006 3116
 				for _, it := range goodList {
3007 3117
 					over_count += it.StockCount
3008 3118
 				}
3009
-				flow := models.VmStockFlow{
3010
-					WarehousingId:           info.WarehouseInfotId,
3011
-					GoodId:                  project.ProjectId,
3012
-					Number:                  info.Number,
3013
-					LicenseNumber:           info.LicenseNumber,
3014
-					Count:                   prescribingNumber,
3015
-					UserOrgId:               adminInfo.CurrentOrgId,
3016
-					PatientId:               project.PatientId,
3017
-					SystemTime:              info.SysRecordTime,
3018
-					ConsumableType:          7,
3019
-					IsSys:                   0,
3020
-					WarehousingOrder:        "",
3021
-					WarehouseOutId:          info.WarehouseOutId,
3022
-					WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
3023
-					IsEdit:                  0,
3024
-					CancelStockId:           cancel.ID,
3025
-					CancelOrderNumber:       cancel.OrderNumber,
3026
-					Manufacturer:            manufacturer.ID,
3027
-					Dealer:                  0,
3028
-					Creator:                 adminInfo.AdminUser.Id,
3029
-					UpdateCreator:           0,
3030
-					Status:                  1,
3031
-					Ctime:                   time.Now().Unix(),
3032
-					Mtime:                   0,
3033
-					Price:                   info.Price,
3034
-					WarehousingDetailId:     info.WarehouseInfotId,
3035
-					WarehouseOutDetailId:    info.ID,
3036
-					CancelOutDetailId:       cancelInfo.ID,
3037
-					ProductDate:             info.ProductDate,
3038
-					ExpireDate:              info.ExpiryDate,
3039
-					StorehouseId:            houseConfig.StorehouseOutInfo,
3040
-					OverCount:               over_count,
3119
+				if info.Count >= prescribingNumber {
3120
+					flow := models.VmStockFlow{
3121
+						WarehousingId:           info.WarehouseInfotId,
3122
+						GoodId:                  project.ProjectId,
3123
+						Number:                  info.Number,
3124
+						LicenseNumber:           info.LicenseNumber,
3125
+						Count:                   prescribingNumber,
3126
+						UserOrgId:               adminInfo.CurrentOrgId,
3127
+						PatientId:               project.PatientId,
3128
+						SystemTime:              info.SysRecordTime,
3129
+						ConsumableType:          7,
3130
+						IsSys:                   0,
3131
+						WarehousingOrder:        "",
3132
+						WarehouseOutId:          info.WarehouseOutId,
3133
+						WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
3134
+						IsEdit:                  0,
3135
+						CancelStockId:           cancel.ID,
3136
+						CancelOrderNumber:       cancel.OrderNumber,
3137
+						Manufacturer:            manufacturer.ID,
3138
+						Dealer:                  0,
3139
+						Creator:                 adminInfo.AdminUser.Id,
3140
+						UpdateCreator:           0,
3141
+						Status:                  1,
3142
+						Ctime:                   time.Now().Unix(),
3143
+						Mtime:                   0,
3144
+						Price:                   info.Price,
3145
+						WarehousingDetailId:     info.WarehouseInfotId,
3146
+						WarehouseOutDetailId:    info.ID,
3147
+						CancelOutDetailId:       cancelInfo.ID,
3148
+						ProductDate:             info.ProductDate,
3149
+						ExpireDate:              info.ExpiryDate,
3150
+						StorehouseId:            houseConfig.StorehouseOutInfo,
3151
+						OverCount:               over_count,
3152
+					}
3153
+					service.CreateStockFlowOne(flow)
3154
+				}
3155
+
3156
+				if info.Count < prescribingNumber {
3157
+					flow := models.VmStockFlow{
3158
+						WarehousingId:           info.WarehouseInfotId,
3159
+						GoodId:                  project.ProjectId,
3160
+						Number:                  info.Number,
3161
+						LicenseNumber:           info.LicenseNumber,
3162
+						Count:                   info.Count,
3163
+						UserOrgId:               adminInfo.CurrentOrgId,
3164
+						PatientId:               project.PatientId,
3165
+						SystemTime:              info.SysRecordTime,
3166
+						ConsumableType:          7,
3167
+						IsSys:                   0,
3168
+						WarehousingOrder:        "",
3169
+						WarehouseOutId:          info.WarehouseOutId,
3170
+						WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
3171
+						IsEdit:                  0,
3172
+						CancelStockId:           cancel.ID,
3173
+						CancelOrderNumber:       cancel.OrderNumber,
3174
+						Manufacturer:            manufacturer.ID,
3175
+						Dealer:                  0,
3176
+						Creator:                 adminInfo.AdminUser.Id,
3177
+						UpdateCreator:           0,
3178
+						Status:                  1,
3179
+						Ctime:                   time.Now().Unix(),
3180
+						Mtime:                   0,
3181
+						Price:                   info.Price,
3182
+						WarehousingDetailId:     info.WarehouseInfotId,
3183
+						WarehouseOutDetailId:    info.ID,
3184
+						CancelOutDetailId:       cancelInfo.ID,
3185
+						ProductDate:             info.ProductDate,
3186
+						ExpireDate:              info.ExpiryDate,
3187
+						StorehouseId:            houseConfig.StorehouseOutInfo,
3188
+						OverCount:               over_count,
3189
+					}
3190
+					service.CreateStockFlowOne(flow)
3041 3191
 				}
3042
-				service.CreateStockFlowOne(flow)
3043 3192
 
3044 3193
 				//查询已出库数量
3045 3194
 				dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
@@ -3048,18 +3197,12 @@ func (c *HisApiController) DeleteProject() {
3048 3197
 					//改变数量
3049 3198
 					service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
3050 3199
 				}
3051
-				fmt.Println("prescribingNumber", prescribingNumber)
3052
-				fmt.Println("Count2332333223qw", dialysisInfo.Count)
3053
-				if prescribingNumber == dialysisInfo.Count {
3200
+
3201
+				if prescribingNumber >= dialysisInfo.Count {
3054 3202
 					//删除出库表
3055 3203
 					service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
3056 3204
 				}
3057 3205
 
3058
-				//退库数量增加
3059
-				service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
3060
-				//出库数量减少
3061
-				service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
3062
-
3063 3206
 				//更新剩余库存
3064 3207
 				service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
3065 3208
 

+ 369 - 73
controllers/mobile_api_controllers/dialysis_api_controller.go View File

@@ -2959,7 +2959,7 @@ func (this *DialysisAPIController) GetLastMonitorRecordTody() {
2959 2959
 				record.UltrafiltrationRate = ultrafiltration_rate
2960 2960
 			}
2961 2961
 
2962
-			if adminInfo.Org.Id == 10395 {
2962
+			if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 {
2963 2963
 				ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
2964 2964
 
2965 2965
 				record.UltrafiltrationRate = ultrafiltration_rate
@@ -2989,7 +2989,7 @@ func (this *DialysisAPIController) GetLastMonitorRecordTody() {
2989 2989
 		}
2990 2990
 	}
2991 2991
 
2992
-	if adminInfo.Org.Id == 10395 {
2992
+	if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 {
2993 2993
 
2994 2994
 		if ultrafiltration_rate > 0 {
2995 2995
 			ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate / 1000)
@@ -4886,6 +4886,9 @@ func (c *DialysisAPIController) EditConsumables() {
4886 4886
 
4887 4887
 	var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
4888 4888
 
4889
+	var cancelbefor []*models.DialysisBeforePrepareGoods
4890
+	var outbefor []*models.DialysisBeforePrepareGoods
4891
+
4889 4892
 	//判断是否开启自动出库
4890 4893
 	_, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
4891 4894
 
@@ -4949,62 +4952,280 @@ func (c *DialysisAPIController) EditConsumables() {
4949 4952
 					goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
4950 4953
 					//判断当前出库数量和最后一次出库数量的大小
4951 4954
 					//如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
4952
-
4953 4955
 					if item.Count < goodInfo.Count {
4954
-						//退库
4955
-						err = ConsumablesDeliveryTotalSeven(adminInfo.Org.Id, patient_id, record_time, beforePrepares, adminInfo.AdminUser.Id, item.Count)
4956
-
4957
-						//查询默认仓库
4958
-						storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
4959
-						stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
4960
-						var total_count int64
4961
-						for _, it := range stockList {
4962
-							total_count += it.StockCount
4963
-						}
4964
-						//基础库插入数据
4965
-						service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
4966
-						//更新剩余库存
4967
-						goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
4968
-						var flush_count int64
4969
-						for _, it := range goodList {
4970
-							flush_count += it.StockCount
4971
-						}
4972
-						service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
4973
-						break
4956
+						cancelbefor = append(cancelbefor, item)
4974 4957
 					}
4975 4958
 
4976
-					var last_total int64
4977
-
4978 4959
 					//如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
4979 4960
 					if item.Count > goodInfo.Count {
4980 4961
 
4981
-						//计算当前出库和最后一次出库数据相差数据
4982
-						last_total = item.Count - goodInfo.Count
4983
-
4984
-						//查询该批次剩余库存
4985
-						lastInfo, _ := service.GetLastStockOut(goodInfo.WarehouseInfotId)
4986
-
4987
-						if lastInfo.StockCount == 0 {
4988
-							//查询该耗材的总库存
4989
-							wareinfo, _ := service.GetStockGoodCount(item.GoodId)
4990
-							if wareinfo.StockCount == 0 {
4991
-								goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
4992
-								c.ServeSuccessJSON(map[string]interface{}{
4993
-									"message":            "1",
4994
-									"good_name":          goodObj.GoodName,
4995
-									"specification_name": goodObj.SpecificationName,
4996
-								})
4997
-								return
4962
+						outbefor = append(outbefor, item)
4963
+					}
4964
+
4965
+					//处理编辑耗材新增不了的问题
4966
+					if goodInfo.Count == item.Count {
4967
+						lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
4968
+						service.UpdateLastAutoCount(lastCount.ID, item.Count)
4969
+					}
4970
+
4971
+				}
4972
+
4973
+				fmt.Println("退库长度", len(cancelbefor))
4974
+				fmt.Println("出库长度", len(outbefor))
4975
+				//退库
4976
+				for _, item := range cancelbefor {
4977
+					warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
4978
+					creater := adminInfo.AdminUser.Id
4979
+					//退库
4980
+					//err = ConsumablesDeliveryTotalSeven(adminInfo.Org.Id, patient_id, record_time, cancelbefor, adminInfo.AdminUser.Id, item.Count)
4981
+					//查询该患者当天已经出库的耗材信息
4982
+
4983
+					warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
4984
+
4985
+					var delete_count int64 = 0
4986
+
4987
+					delete_count = warehouseOutInfos.Count - item.Count
4988
+
4989
+					houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
4990
+
4991
+					// 在出库记录表里记录退库详情
4992
+					warehouseOutInfo := &models.WarehouseOutInfo{
4993
+						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
4994
+						WarehouseOutId:          warehouseOut.ID,
4995
+						Status:                  1,
4996
+						Ctime:                   time.Now().Unix(),
4997
+						OrgId:                   adminInfo.Org.Id,
4998
+						Type:                    1,
4999
+						IsSys:                   1,
5000
+						SysRecordTime:           record_time,
5001
+						GoodTypeId:              item.GoodTypeId,
5002
+						GoodId:                  item.GoodId,
5003
+						PatientId:               patient_id,
5004
+						ConsumableType:          2,
5005
+						StorehouseId:            houseConfig.StorehouseOutInfo,
5006
+						IsCheck:                 1,
5007
+					}
5008
+					warehouseOutInfo.Count = item.Count
5009
+
5010
+					stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
5011
+					warehouseOutInfo.Price = stockInInfo.Price
5012
+					warehouseOutInfo.Dealer = stockInInfo.Dealer
5013
+					warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
5014
+					warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
5015
+					warehouseOutInfo.ProductDate = stockInInfo.ProductDate
5016
+					warehouseOutInfo.Number = warehouseOutInfos.Number
5017
+					warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
5018
+					warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
5019
+					//查找当天是否存在出库记录
5020
+
5021
+					_, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
5022
+
5023
+					if errcod == gorm.ErrRecordNotFound {
5024
+						service.AddSigleWarehouseOutInfo(warehouseOutInfo)
5025
+						//插入详情明细表
5026
+						stockFlow := models.VmStockFlow{
5027
+							WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5028
+							WarehouseOutId:          warehouseOut.ID,
5029
+							GoodId:                  item.GoodId,
5030
+							Number:                  warehouseOutInfos.Number,
5031
+							ProductDate:             stockInInfo.ProductDate,
5032
+							ExpireDate:              stockInInfo.ExpiryDate,
5033
+							Count:                   item.Count,
5034
+							Price:                   stockInInfo.Price,
5035
+							Status:                  1,
5036
+							Ctime:                   time.Now().Unix(),
5037
+							UserOrgId:               adminInfo.Org.Id,
5038
+							Manufacturer:            stockInInfo.Manufacturer,
5039
+							Dealer:                  stockInInfo.Dealer,
5040
+							LicenseNumber:           stockInInfo.LicenseNumber,
5041
+							IsEdit:                  2,
5042
+							Creator:                 creater,
5043
+							SystemTime:              record_time,
5044
+							ConsumableType:          3,
5045
+							WarehousingDetailId:     0,
5046
+							IsSys:                   1,
5047
+							UpdateCreator:           creater,
5048
+							PatientId:               patient_id,
5049
+							StorehouseId:            houseConfig.StorehouseOutInfo,
5050
+						}
5051
+						exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
5052
+						if errflow == gorm.ErrRecordNotFound {
5053
+							//创建流水表
5054
+							err := service.CreateStockFlowOne(stockFlow)
5055
+							fmt.Println("err", err)
5056
+						} else if errflow == nil {
5057
+							//插入详情明细表
5058
+							stockFlow := models.VmStockFlow{
5059
+								ID:                      exsit.ID,
5060
+								WarehousingId:           warehouseOutInfos.WarehouseInfotId,
5061
+								WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5062
+								WarehouseOutId:          warehouseOut.ID,
5063
+								GoodId:                  item.GoodId,
5064
+								Number:                  warehouseOutInfos.Number,
5065
+								ProductDate:             stockInInfo.ProductDate,
5066
+								ExpireDate:              stockInInfo.ExpiryDate,
5067
+								Count:                   exsit.Count - delete_count,
5068
+								Price:                   stockInInfo.Price,
5069
+								Status:                  1,
5070
+								Ctime:                   time.Now().Unix(),
5071
+								UserOrgId:               adminInfo.Org.Id,
5072
+								Manufacturer:            stockInInfo.Manufacturer,
5073
+								Dealer:                  stockInInfo.Dealer,
5074
+								LicenseNumber:           stockInInfo.LicenseNumber,
5075
+								IsEdit:                  2,
5076
+								Creator:                 creater,
5077
+								SystemTime:              record_time,
5078
+								ConsumableType:          3,
5079
+								WarehousingDetailId:     0,
5080
+								IsSys:                   1,
5081
+								UpdateCreator:           creater,
5082
+								PatientId:               patient_id,
5083
+								StorehouseId:            houseConfig.StorehouseOutInfo,
4998 5084
 							}
4999 5085
 
5086
+							service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
5000 5087
 						}
5001 5088
 
5002
-						//比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
5089
+					} else if errcod == nil {
5090
+						service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
5091
+						//插入详情明细表
5092
+						stockFlow := models.VmStockFlow{
5093
+							WarehousingId:           warehouseOutInfos.WarehouseInfotId,
5094
+							WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5095
+							WarehouseOutId:          warehouseOut.ID,
5096
+							GoodId:                  item.GoodId,
5097
+							Number:                  warehouseOutInfos.Number,
5098
+							ProductDate:             stockInInfo.ProductDate,
5099
+							ExpireDate:              stockInInfo.ExpiryDate,
5100
+							Count:                   item.Count,
5101
+							Price:                   stockInInfo.Price,
5102
+							Status:                  1,
5103
+							Ctime:                   time.Now().Unix(),
5104
+							UserOrgId:               adminInfo.Org.Id,
5105
+							Manufacturer:            stockInInfo.Manufacturer,
5106
+							Dealer:                  stockInInfo.Dealer,
5107
+							LicenseNumber:           stockInInfo.LicenseNumber,
5108
+							IsEdit:                  2,
5109
+							Creator:                 creater,
5110
+							SystemTime:              record_time,
5111
+							ConsumableType:          3,
5112
+							WarehousingDetailId:     0,
5113
+							IsSys:                   1,
5114
+							UpdateCreator:           creater,
5115
+							PatientId:               patient_id,
5116
+							ReturnCount:             delete_count,
5117
+							StorehouseId:            houseConfig.StorehouseOutInfo,
5118
+						}
5119
+						exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
5120
+						if errflows == gorm.ErrRecordNotFound {
5121
+							//创建流水表
5122
+							service.CreateStockFlowOne(stockFlow)
5123
+						} else if errflows == nil {
5124
+							stockFlow := models.VmStockFlow{
5125
+								WarehousingId:           warehouseOutInfos.WarehouseInfotId,
5126
+								ID:                      exsit.ID,
5127
+								WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5128
+								WarehouseOutId:          warehouseOut.ID,
5129
+								GoodId:                  item.GoodId,
5130
+								Number:                  warehouseOutInfos.Number,
5131
+								ProductDate:             stockInInfo.ProductDate,
5132
+								ExpireDate:              stockInInfo.ExpiryDate,
5133
+								Count:                   exsit.Count - delete_count,
5134
+								Price:                   stockInInfo.Price,
5135
+								Status:                  1,
5136
+								Ctime:                   time.Now().Unix(),
5137
+								UserOrgId:               adminInfo.Org.Id,
5138
+								Manufacturer:            stockInInfo.Manufacturer,
5139
+								Dealer:                  stockInInfo.Dealer,
5140
+								LicenseNumber:           stockInInfo.LicenseNumber,
5141
+								IsEdit:                  2,
5142
+								Creator:                 creater,
5143
+								SystemTime:              record_time,
5144
+								ConsumableType:          3,
5145
+								WarehousingDetailId:     0,
5146
+								IsSys:                   1,
5147
+								UpdateCreator:           creater,
5148
+								PatientId:               patient_id,
5149
+								ReturnCount:             delete_count,
5150
+								StorehouseId:            houseConfig.StorehouseOutInfo,
5151
+							}
5152
+							service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
5153
+						}
5154
+
5155
+					}
5156
+
5157
+					//更改自动出库的表格
5158
+					details := models.BloodAutomaticReduceDetail{
5159
+						WarehouseOutId:          warehouseOutInfo.ID,
5160
+						WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
5161
+						PatientId:               patient_id,
5162
+						Ctime:                   time.Now().Unix(),
5163
+						Mtime:                   time.Now().Unix(),
5164
+						Status:                  1,
5165
+						RecordTime:              record_time,
5166
+						OrgId:                   adminInfo.Org.Id,
5167
+						GoodId:                  item.GoodId,
5168
+						GoodTypeId:              item.GoodTypeId,
5169
+						Count:                   item.Count,
5170
+						StorehouseId:            houseConfig.StorehouseOutInfo,
5171
+					}
5172
+					//查询当天耗材是否已经存在数据
5173
+					_, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
5174
+
5175
+					if errcode == gorm.ErrRecordNotFound {
5176
+						service.CreateAutoReduceRecord(&details)
5177
+
5178
+					} else if errcode == nil {
5179
+						service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
5180
+						service.CreateAutoReduceRecord(&details)
5181
+
5182
+					}
5183
+
5184
+					service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
5185
+
5186
+					//增加出库库存数量
5187
+					service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
5188
+
5189
+					errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, item.GoodId, delete_count, patient_id)
5190
+					fmt.Println("errOne", errOne)
5191
+					// 删除出库完成后,要增加对应批次的库存数量
5192
+
5193
+					service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
5194
+
5195
+					//查询默认仓库
5196
+					storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
5197
+					stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
5198
+					var total_count int64
5199
+					for _, it := range stockList {
5200
+						total_count += it.StockCount
5201
+					}
5202
+					//基础库插入数据
5203
+					service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
5204
+					//更新剩余库存
5205
+					goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
5206
+					var flush_count int64
5207
+					for _, it := range goodList {
5208
+						flush_count += it.StockCount
5209
+					}
5210
+					service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
5211
+				}
5212
+
5213
+				//出库
5214
+				for _, item := range outbefor {
5215
+					fmt.Println("出库ID", item.GoodId)
5216
+					var last_total int64
5217
+					//1.查看该患者该耗材型号最后一次出库数量
5218
+					goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
5219
+					//计算当前出库和最后一次出库数据相差数据
5220
+					last_total = item.Count - goodInfoOne.Count
5221
+
5222
+					//查询该批次剩余库存
5223
+					lastInfo, _ := service.GetLastStockOut(goodInfoOne.WarehouseInfotId)
5003 5224
 
5225
+					if lastInfo.StockCount == 0 {
5004 5226
 						//查询该耗材的总库存
5005 5227
 						wareinfo, _ := service.GetStockGoodCount(item.GoodId)
5006
-						// 如果库存差大于剩余库存则提示库存不足
5007
-						if last_total > wareinfo.StockCount {
5228
+						if wareinfo.StockCount == 0 {
5008 5229
 							goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
5009 5230
 							c.ServeSuccessJSON(map[string]interface{}{
5010 5231
 								"message":            "1",
@@ -5012,31 +5233,104 @@ func (c *DialysisAPIController) EditConsumables() {
5012 5233
 								"specification_name": goodObj.SpecificationName,
5013 5234
 							})
5014 5235
 							return
5015
-						} else {
5236
+						}
5016 5237
 
5017
-							//出库
5018
-							err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
5238
+					}
5019 5239
 
5020
-							storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
5021
-							stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
5022
-							var total_count int64
5023
-							for _, it := range stockList {
5024
-								total_count += it.StockCount
5025
-							}
5026
-							//基础库插入数据
5027
-							service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
5028
-							//剩余库存
5240
+					//比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
5029 5241
 
5030
-							goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
5031
-							var flush_count int64
5032
-							for _, it := range goodList {
5033
-								flush_count += it.StockCount
5242
+					//查询该耗材的总库存
5243
+					wareinfo, _ := service.GetStockGoodCount(item.GoodId)
5244
+					// 如果库存差大于剩余库存则提示库存不足
5245
+					if last_total > wareinfo.StockCount {
5246
+						goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
5247
+						c.ServeSuccessJSON(map[string]interface{}{
5248
+							"message":            "1",
5249
+							"good_name":          goodObj.GoodName,
5250
+							"specification_name": goodObj.SpecificationName,
5251
+						})
5252
+						return
5253
+					} else {
5254
+
5255
+						fmt.Println("出库2o2o2o2o2oo2o2o2o2o2o2o", item.GoodId)
5256
+
5257
+						out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
5258
+						houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
5259
+						if err == gorm.ErrRecordNotFound {
5260
+							//没有记录,则创建出库单
5261
+							timeStr := time.Now().Format("2006-01-02")
5262
+							timeArr := strings.Split(timeStr, "-")
5263
+							total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
5264
+							total = total + 1
5265
+							warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
5266
+							number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
5267
+							number = number + total
5268
+							warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
5269
+							warehouseOut := models.WarehouseOut{
5270
+								WarehouseOutOrderNumber: warehousing_out_order,
5271
+								OperationTime:           time.Now().Unix(),
5272
+								OrgId:                   adminInfo.Org.Id,
5273
+								Creater:                 adminInfo.AdminUser.Id,
5274
+								Ctime:                   time.Now().Unix(),
5275
+								Status:                  1,
5276
+								WarehouseOutTime:        record_time,
5277
+								Dealer:                  0,
5278
+								Manufacturer:            0,
5279
+								Type:                    1,
5280
+								IsSys:                   1,
5281
+								StorehouseId:            houseConfig.StorehouseOutInfo,
5282
+								IsCheck:                 1,
5034 5283
 							}
5035
-							service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
5036
-							break
5284
+							service.AddSigleWarehouseOut(&warehouseOut)
5285
+
5037 5286
 						}
5038
-					}
5287
+						//出库
5288
+						//err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
5289
+						//houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
5290
+						//1.查看该患者该耗材型号最后一次出库数量
5291
+						goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
5039 5292
 
5293
+						fmt.Println("count2323323222323wi", item.Count)
5294
+						prepare := models.DialysisBeforePrepare{
5295
+							UserOrgId:    adminInfo.Org.Id,
5296
+							PatientId:    patient_id,
5297
+							RecordDate:   record_time,
5298
+							GoodId:       item.GoodId,
5299
+							GoodTypeId:   item.GoodTypeId,
5300
+							Count:        item.Count - goodInfoTwo.Count,
5301
+							Ctime:        time.Now().Unix(),
5302
+							Mtime:        0,
5303
+							Creater:      adminInfo.AdminUser.Id,
5304
+							Modifier:     adminInfo.AdminUser.Id,
5305
+							Status:       1,
5306
+							CommdityCode: "",
5307
+							NewCount:     0,
5308
+							ProjectId:    0,
5309
+							StorehouseId: houseConfig.StorehouseOutInfo,
5310
+						}
5311
+						fmt.Println("prepare", prepare.Count)
5312
+						fmt.Println("count", item.Count)
5313
+						service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
5314
+						//增加出库数量
5315
+						service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
5316
+
5317
+						storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
5318
+						stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
5319
+						var total_count int64
5320
+						for _, it := range stockList {
5321
+							total_count += it.StockCount
5322
+						}
5323
+						//基础库插入数据
5324
+						service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
5325
+						//剩余库存
5326
+
5327
+						goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
5328
+						var flush_count int64
5329
+						for _, it := range goodList {
5330
+							flush_count += it.StockCount
5331
+						}
5332
+						service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
5333
+					}
5040 5334
 				}
5041 5335
 
5042 5336
 				//查询今日出库数据
@@ -5075,15 +5369,15 @@ func (c *DialysisAPIController) EditConsumables() {
5075 5369
 						flush_count += it.StockCount
5076 5370
 					}
5077 5371
 					service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
5078
-					if err != nil {
5079
-						goodObj, _ := service.GetGoodInformationByGoodId(it.GoodId)
5080
-						c.ServeSuccessJSON(map[string]interface{}{
5081
-							"message":            "2",
5082
-							"good_name":          goodObj.GoodName,
5083
-							"specification_name": goodObj.SpecificationName,
5084
-						})
5085
-						return
5086
-					}
5372
+					//if err != nil {
5373
+					//	goodObj, _ := service.GetGoodInformationByGoodId(it.GoodId)
5374
+					//	c.ServeSuccessJSON(map[string]interface{}{
5375
+					//		"message":            "2",
5376
+					//		"good_name":          goodObj.GoodName,
5377
+					//		"specification_name": goodObj.SpecificationName,
5378
+					//	})
5379
+					//	return
5380
+					//}
5087 5381
 				}
5088 5382
 			}
5089 5383
 		}
@@ -6072,6 +6366,7 @@ func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int6
6072 6366
 	// goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
6073 6367
 	// goods 这个数据就是需要出库的耗材的数据(新增的数据)
6074 6368
 
6369
+	fmt.Println("剩余需要出库的", len(goods))
6075 6370
 	if len(goods) > 0 {
6076 6371
 		out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
6077 6372
 		houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
@@ -6251,6 +6546,7 @@ func (this *DialysisAPIController) GetRoleList() {
6251 6546
 
6252 6547
 func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
6253 6548
 
6549
+	fmt.Println("退库222322232322332232332322332232332233wo", good_yc.GoodId)
6254 6550
 	// 先根据相关信息查询当天该耗材的出库信息
6255 6551
 	warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
6256 6552
 

+ 2 - 1
models/device_models.go View File

@@ -145,7 +145,7 @@ type DeviceNumber struct {
145 145
 	Number     string     `gorm:"column:number" json:"number"`
146 146
 	GroupID    int64      `gorm:"column:group_id" json:"group_id"`
147 147
 	ZoneID     int64      `gorm:"column:zone_id" json:"zone_id"`
148
-	Status     int8       `json:"-"`
148
+	Status     int64      `gorm:"column:status" json:"status" form:"status"`
149 149
 	CreateTime int64      `gorm:"column:ctime" json:"-"`
150 150
 	ModifyTime int64      `gorm:"column:mtime" json:"-"`
151 151
 	Sort       int64      `gorm:"column:sort" json:"sort" form:"sort"`
@@ -868,6 +868,7 @@ type XtAssessmentAfterDislysis struct {
868 868
 	CvcA                            float64 `gorm:"column:cvc_a" json:"cvc_a" form:"cvc_a"`
869 869
 	CvcV                            float64 `gorm:"column:cvc_v" json:"cvc_v" form:"cvc_v"`
870 870
 	Channel                         int64   `gorm:"column:channel" json:"channel" form:"channel"`
871
+	SealingFluidDispose             string  `gorm:"column:sealing_fluid_dispose" json:"sealing_fluid_dispose" form:"sealing_fluid_dispose"`
871 872
 }
872 873
 
873 874
 func (XtAssessmentAfterDislysis) TableName() string {

+ 32 - 27
models/new_stock_models.go View File

@@ -145,33 +145,38 @@ func (NewBaseDrug) TableName() string {
145 145
 }
146 146
 
147 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"`
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
+	Sodium                     int64 `gorm:"column:sodium" json:"sodium" form:"sodium"`
176
+	Calcium                    int64 `gorm:"column:calcium" json:"calcium" form:"calcium"`
177
+	BloodAccess                int64 `gorm:"column:blood_access" json:"blood_access" form:"blood_access"`
178
+	DialyzerPerfusionApparatus int64 `gorm:"column:dialyzer_perfusion_apparatus" json:"dialyzer_perfusion_apparatus" form:"dialyzer_perfusion_apparatus"`
179
+	DisplaceLiquiPart          int64 `gorm:"column:displace_liqui_part" json:"displace_liqui_part" form:"displace_liqui_part"`
175 180
 }
176 181
 
177 182
 func (XtDialysisSetting) TableName() string {

+ 8 - 4
models/schedule_models.go View File

@@ -306,10 +306,13 @@ type VmBloodSchedule struct {
306 306
 	DeviceNumber               *NewMDeviceNumberVM        `gorm:"ForeignKey:BedId" json:"device_number"`
307 307
 	SchedualPatient            *NewMSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
308 308
 	DialysisSolution           DialysisSolution           `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"dialysis_solution"`
309
-	DialysisPrescription       DialysisPrescription       `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,RecordDate" json:"dialysis_prescription"`
310
-	XtAssessmentBeforeDislysis XtAssessmentBeforeDislysis `gorm:"ForeignKey:PatientId,AssessmentDate;AssociationForeignKey:PatientId,AssessmentDate" json:"assessment_befor_dislysis"`
311
-	XtDoctorAdvice             XtDoctorAdvice             `gorm:"ForeignKey:PatientId,AdviceDate;AssociationForeignKey:PatientId,AdviceDate" json:"xt_doctor_advice"`
312
-	HisDoctorAdvice            HisDoctorAdvice            `gorm:"ForeignKey:PatientId,AdviceDate;AssociationForeignKey:PatientId,AdviceDate" json:"his_doctor_advice"`
309
+	DialysisPrescription       DialysisPrescription       `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"dialysis_prescription"`
310
+	XtAssessmentBeforeDislysis XtAssessmentBeforeDislysis `gorm:"ForeignKey:PatientId,AssessmentDate;AssociationForeignKey:PatientId,ScheduleDate" json:"assessment_befor_dislysis"`
311
+	XtDoctorAdvice             XtDoctorAdvice             `gorm:"ForeignKey:PatientId,AdviceDate;AssociationForeignKey:PatientId,ScheduleDate" json:"xt_doctor_advice"`
312
+	HisDoctorAdvice            HisDoctorAdvice            `gorm:"ForeignKey:PatientId,AdviceDate;AssociationForeignKey:PatientId,ScheduleDate" json:"his_doctor_advice"`
313
+	ReceiveTreatmentAsses      ReceiveTreatmentAsses      `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"xt_receive_treatment_asses"`
314
+	XtAssessmentAfterDislysis  XtAssessmentAfterDislysis  `gorm:"ForeignKey:PatientId,AssessmentDate;AssociationForeignKey:PatientId,ScheduleDate" json:"xt_assesment_after_dislysis"`
315
+	LastAfterWeight            AssessmentAfterDislysis    `gorm:"ForeignKey:PatientID;AssociationForeignKey:PatientID" json:"lastafterweight"`
313 316
 }
314 317
 
315 318
 func (VmBloodSchedule) TableName() string {
@@ -340,6 +343,7 @@ type NewMSchedualPatientVMList struct {
340 343
 	IdCardNo           string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
341 344
 	UserSysBeforeCount int64  `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
342 345
 	TrobleShoot        int64  `gorm:"column:troble_shoot" json:"troble_shoot" form:"troble_shoot"`
346
+	Status             int64  `gorm:"column:status" json:"status" form:"status"`
343 347
 }
344 348
 
345 349
 func (NewMSchedualPatientVMList) TableName() string {

+ 1 - 1
service/dialysis_service.go View File

@@ -1508,7 +1508,7 @@ func SaveHisProject(advice *models.HisPrescriptionProject) (err error) {
1508 1508
 }
1509 1509
 
1510 1510
 func FindAllHisProjectById(orgID int64, patient_id int64, record_time int64) (advice []*models.HisPrescriptionProject, err error) {
1511
-	err = readDb.Model(&models.HisPrescriptionProject{}).Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("user_org_id=? and status=1 and patient_id = ? AND record_date = ?", orgID, patient_id, record_time).Find(&advice).Error
1511
+	err = readDb.Model(&models.HisPrescriptionProject{}).Preload("HisProject", "status = 1 and user_org_id = ?", orgID).Preload("GoodInfo", "status = 1 and org_id = ?", orgID).Where("user_org_id=? and status=1 and patient_id = ? AND record_date = ?", orgID, patient_id, record_time).Find(&advice).Error
1512 1512
 	return
1513 1513
 }
1514 1514
 

+ 34 - 19
service/dialysis_solution_service.go View File

@@ -2,6 +2,7 @@ package service
2 2
 
3 3
 import (
4 4
 	"XT_New/models"
5
+	"github.com/jinzhu/gorm"
5 6
 )
6 7
 
7 8
 func GetPatientSolutionGroupList(patient_id int64, orgid int64) (solution []*models.DialysisSolution, err error) {
@@ -41,28 +42,29 @@ func GetLastPatientDialysisSolution(patient_id int64, orgid int64) (models.Dialy
41 42
 
42 43
 func GetPatientDialysisSolutionGroupList(keywords string, limit int64, page int64, partition_id int64, schedule_type int64, scheduleDate int64, orgID int64) (schedule []*models.VmBloodSchedule, total int64, err error) {
43 44
 
44
-	db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("status = 1")
45
+	db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("xt_schedule.status = 1")
45 46
 	offset := (page - 1) * limit
46 47
 	if scheduleDate > 0 {
47
-		db = db.Where("schedule_date = ?", scheduleDate)
48
+		db = db.Where("xt_schedule.schedule_date = ?", scheduleDate)
48 49
 	}
49 50
 	if schedule_type > 0 {
50
-		db = db.Where("schedule_type = ?", schedule_type)
51
+		db = db.Where("xt_schedule.schedule_type = ?", schedule_type)
51 52
 	}
52 53
 	if partition_id > 0 {
53
-		db = db.Where("partition_id = ?", partition_id)
54
+		db = db.Where("xt_schedule.partition_id = ?", partition_id)
54 55
 	}
55 56
 	if orgID > 0 {
56
-		db = db.Where("user_org_id  = ?", orgID)
57
+		db = db.Where("xt_schedule.user_org_id  = ?", orgID)
57 58
 	}
58 59
 
59 60
 	if len(keywords) > 0 {
60 61
 		keywords = "%" + keywords + "%"
61
-		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)
62
-		err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
62
+		db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
63 63
 			Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
64 64
 			Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
65
-			Preload("DialysisSolution", "status = 1 AND user_org_id = ? and solution_status = 1", orgID).Find(&schedule).Error
65
+			Preload("DialysisSolution", "status = 1 AND user_org_id = ? and solution_status = 1", orgID)
66
+		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)
67
+		err = db.Count(&total).Offset(offset).Limit(limit).Find(&schedule).Error
66 68
 	} else {
67 69
 		err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
68 70
 			Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
@@ -74,19 +76,19 @@ func GetPatientDialysisSolutionGroupList(keywords string, limit int64, page int6
74 76
 }
75 77
 
76 78
 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")
79
+	db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("xt_schedule.status = 1")
78 80
 	offset := (page - 1) * limit
79 81
 	if scheduleDate > 0 {
80
-		db = db.Where("schedule_date = ?", scheduleDate)
82
+		db = db.Where("xt_schedule.schedule_date = ?", scheduleDate)
81 83
 	}
82 84
 	if schedule_type > 0 {
83
-		db = db.Where("schedule_type = ?", schedule_type)
85
+		db = db.Where("xt_schedule.schedule_type = ?", schedule_type)
84 86
 	}
85 87
 	if partition_id > 0 {
86
-		db = db.Where("partition_id = ?", partition_id)
88
+		db = db.Where("xt_schedule.partition_id = ?", partition_id)
87 89
 	}
88 90
 	if orgID > 0 {
89
-		db = db.Where("user_org_id  = ?", orgID)
91
+		db = db.Where("xt_schedule.user_org_id  = ?", orgID)
90 92
 	}
91 93
 
92 94
 	if len(keywords) > 0 {
@@ -130,19 +132,19 @@ func GetDialysisSetting(orgid int64) (models.XtDialysisSetting, error) {
130 132
 }
131 133
 
132 134
 func GetDialysisParameterList(keywords string, limit int64, page int64, partition_id int64, schedule_type int64, scheduleDate int64, orgID int64) (schedule []*models.VmBloodSchedule, total int64, err error) {
133
-	db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("status = 1")
135
+	db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("xt_schedule.status = 1")
134 136
 	offset := (page - 1) * limit
135 137
 	if scheduleDate > 0 {
136
-		db = db.Where("schedule_date = ?", scheduleDate)
138
+		db = db.Where("xt_schedule.schedule_date = ?", scheduleDate)
137 139
 	}
138 140
 	if schedule_type > 0 {
139
-		db = db.Where("schedule_type = ?", schedule_type)
141
+		db = db.Where("xt_schedule.schedule_type = ?", schedule_type)
140 142
 	}
141 143
 	if partition_id > 0 {
142
-		db = db.Where("partition_id = ?", partition_id)
144
+		db = db.Where("xt_schedule.partition_id = ?", partition_id)
143 145
 	}
144 146
 	if orgID > 0 {
145
-		db = db.Where("user_org_id  = ?", orgID)
147
+		db = db.Where("xt_schedule.user_org_id  = ?", orgID)
146 148
 	}
147 149
 
148 150
 	if len(keywords) > 0 {
@@ -150,15 +152,28 @@ func GetDialysisParameterList(keywords string, limit int64, page int64, partitio
150 152
 		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)
151 153
 		err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
152 154
 			Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
155
+			Preload("DialysisSolution", "status = 1 AND user_org_id = ?", orgID).
153 156
 			Preload("DialysisPrescription", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate).
154 157
 			Preload("XtAssessmentBeforeDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate).
158
+			Preload("ReceiveTreatmentAsses", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate).
159
+			Preload("XtAssessmentAfterDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate).
160
+			Preload("LastAfterWeight", func(db *gorm.DB) *gorm.DB {
161
+				return db.Where("user_org_id = ? and status = 1 and assessment_date < ?", orgID, scheduleDate)
162
+			}).
163
+			Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ? and advice_type = 1", orgID, scheduleDate).
155 164
 			Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
156 165
 	} else {
157 166
 		err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
158 167
 			Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
168
+			Preload("DialysisSolution", "status = 1 AND user_org_id = ?", orgID).
159 169
 			Preload("DialysisPrescription", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate).
160 170
 			Preload("XtAssessmentBeforeDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate).
161
-			Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
171
+			Preload("ReceiveTreatmentAsses", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate).
172
+			Preload("XtAssessmentAfterDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate).
173
+			Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ? and advice_type = 1", orgID, scheduleDate).
174
+			Preload("LastAfterWeight", func(db *gorm.DB) *gorm.DB {
175
+				return db.Where("user_org_id = ? and status = 1 and assessment_date < ?", orgID, scheduleDate)
176
+			}).Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
162 177
 	}
163 178
 
164 179
 	return schedule, total, err

+ 14 - 0
service/new_stock_service.go View File

@@ -345,3 +345,17 @@ func UpdateSumOutDrug(orgid int64, storehouse_id int64, drug_id int64, sum_out_c
345 345
 	db.Commit()
346 346
 	return err
347 347
 }
348
+
349
+func GetAutoGoodLastCount(goodid int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
350
+
351
+	detail := models.AutomaticReduceDetail{}
352
+	err := XTReadDB().Where("good_id = ? and count = ? and record_time = ? and patient_id = ?", goodid, count, record_time, patient_id).Last(&detail).Error
353
+	return detail, err
354
+}
355
+
356
+func UpdateLastAutoCount(id int64, count int64) error {
357
+
358
+	detail := models.AutomaticReduceDetail{}
359
+	err := XTWriteDB().Model(&detail).Where("id = ?", id).Update(map[string]interface{}{"count": count, "status": 1}).Error
360
+	return err
361
+}

+ 40 - 6
service/new_warehouse_service.go View File

@@ -1301,7 +1301,24 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1301 1301
 		return err
1302 1302
 	}
1303 1303
 	// 将该批次的剩余库存数量转换为拆零数量
1304
-	stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
1304
+	// 将该批次的剩余库存数量转换为拆零数量
1305
+	if warehouse.MaxUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
1306
+		fmt.Println("进来1")
1307
+		stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
1308
+		fmt.Println("剩余库存1", stock_number)
1309
+	}
1310
+	if warehouse.MaxUnit == drup.MinUnit && drup.MaxUnit != drup.MinUnit {
1311
+		fmt.Println("进来2")
1312
+		stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
1313
+		fmt.Println("剩余库存2", stock_number)
1314
+	}
1315
+	if warehouse.MaxUnit == drup.MaxUnit && drup.MaxUnit == drup.MinUnit {
1316
+		fmt.Println("进来3")
1317
+		stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
1318
+		fmt.Println("剩余库存3", stock_number)
1319
+	}
1320
+	fmt.Println("剩余库存23333333333333333333333333333wo", stock_number)
1321
+	fmt.Println("出库数量2333333333333333333333333333333333333wo", deliver_number)
1305 1322
 
1306 1323
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
1307 1324
 	if stock_number >= deliver_number {
@@ -1322,7 +1339,15 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1322 1339
 			}
1323 1340
 		}
1324 1341
 
1325
-		warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
1342
+		if drup.MinUnit == warehouse.MaxUnit && drup.MaxUnit != drup.MinUnit {
1343
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*drup.MinNumber
1344
+		}
1345
+		if drup.MaxUnit == warehouse.MaxUnit && drup.MaxUnit != drup.MinUnit {
1346
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
1347
+		}
1348
+		if drup.MaxUnit == warehouse.MaxUnit && drup.MaxUnit == drup.MinUnit {
1349
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
1350
+		}
1326 1351
 
1327 1352
 		if warehouse.StockMaxNumber < 0 {
1328 1353
 			warehouse.StockMaxNumber = 0
@@ -1333,18 +1358,27 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1333 1358
 
1334 1359
 		warehouse.Mtime = time.Now().Unix()
1335 1360
 
1361
+		fmt.Println("minnU目标而332322323323233223323223我", minNumber)
1362
+		fmt.Println("max_number232232332232322wo", maxNumber)
1363
+		fmt.Println(" warehouse.StockMinNumber", warehouse.StockMinNumber)
1336 1364
 		if warehouse.StockMinNumber < minNumber {
1337 1365
 
1338 1366
 			warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
1339 1367
 			warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
1340 1368
 		} else {
1341 1369
 			if minNumber > 0 {
1342
-				warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
1370
+				if (warehouse.StockMinNumber - minNumber) >= 0 {
1371
+					warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
1372
+				}
1373
+
1343 1374
 			}
1344 1375
 
1345 1376
 			if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
1346 1377
 				if warehouse.StockMinNumber > 0 {
1347
-					warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
1378
+					if warehouse.StockMinNumber-deliver_number >= 0 {
1379
+						warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
1380
+					}
1381
+
1348 1382
 				}
1349 1383
 
1350 1384
 			}
@@ -1352,7 +1386,7 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1352 1386
 		}
1353 1387
 
1354 1388
 		if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit {
1355
-			if (warehouse.StockMinNumber - deliver_number) > 0 {
1389
+			if (warehouse.StockMinNumber - deliver_number) >= 0 {
1356 1390
 				warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
1357 1391
 			}
1358 1392
 
@@ -1960,7 +1994,7 @@ func GetSigleDrugWarehouseOutInfoOne(patient_id int64, advice_date int64, orgid
1960 1994
 
1961 1995
 func UpdateSingleDrugWarehouseOutInfoSix(patient_id int64, advice_date int64, orgid int64, info *models.DrugWarehouseOutInfo, advice_id int64) error {
1962 1996
 
1963
-	err := XTWriteDB().Model(&models.XtDrugWarehouseOutInfo{}).Where("patient_id = ? and advice_date = ? and org_id = ? and advice_id = ?", patient_id, advice_date, orgid, advice_id).Update(map[string]interface{}{"count": info.Count, "price": info.Price, "total_price": info.TotalPrice, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "remark": info.Remark, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "retail_price": info.RetailPrice, "number": info.Number, "batch_number": info.BatchNumber, "count_unit": info.CountUnit, "warehouse_info_id": info.WarehouseInfoId, "storehouse_id": info.StorehouseId}).Error
1997
+	err := XTWriteDB().Model(&models.XtDrugWarehouseOutInfo{}).Where("patient_id = ? and sys_record_time = ? and org_id = ? and advice_id = ?", patient_id, advice_date, orgid, advice_id).Update(map[string]interface{}{"count": info.Count, "price": info.Price, "total_price": info.TotalPrice, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "remark": info.Remark, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "retail_price": info.RetailPrice, "number": info.Number, "batch_number": info.BatchNumber, "count_unit": info.CountUnit, "warehouse_info_id": info.WarehouseInfoId, "storehouse_id": info.StorehouseId}).Error
1964 1998
 	return err
1965 1999
 }
1966 2000
 

+ 68 - 14
service/warhouse_service.go View File

@@ -134,7 +134,21 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
134 134
 
135 135
 	// 将该批次的剩余库存数量转换为拆零数量
136 136
 
137
-	stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
137
+	if warehouse.MaxUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
138
+
139
+		stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
140
+
141
+	}
142
+	if warehouse.MaxUnit == drup.MinUnit && drup.MaxUnit != drup.MinUnit {
143
+
144
+		stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
145
+
146
+	}
147
+	if warehouse.MaxUnit == drup.MaxUnit && drup.MaxUnit == drup.MinUnit {
148
+
149
+		stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
150
+
151
+	}
138 152
 
139 153
 	var maxNumber int64 = 0
140 154
 	var minNumber int64 = 0
@@ -152,7 +166,15 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
152 166
 		}
153 167
 	}
154 168
 
155
-	warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
169
+	if drup.MinUnit == warehouse.MaxUnit && drup.MaxUnit != drup.MinUnit {
170
+		warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*drup.MinNumber
171
+	}
172
+	if drup.MaxUnit == warehouse.MaxUnit && drup.MaxUnit != drup.MinUnit {
173
+		warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
174
+	}
175
+	if drup.MaxUnit == warehouse.MaxUnit && drup.MaxUnit == drup.MinUnit {
176
+		warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
177
+	}
156 178
 
157 179
 	if warehouse.StockMaxNumber < 0 {
158 180
 		warehouse.StockMaxNumber = 0
@@ -169,12 +191,18 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
169 191
 		warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
170 192
 	} else {
171 193
 		if minNumber > 0 {
172
-			warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
194
+			if (warehouse.StockMinNumber - minNumber) >= 0 {
195
+				warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
196
+			}
197
+
173 198
 		}
174 199
 
175 200
 		if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
176 201
 			if warehouse.StockMinNumber > 0 {
177
-				warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
202
+				if (warehouse.StockMinNumber - deliver_number) >= 0 {
203
+					warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
204
+				}
205
+
178 206
 			}
179 207
 
180 208
 		}
@@ -182,7 +210,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
182 210
 	}
183 211
 
184 212
 	if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit {
185
-		if (warehouse.StockMinNumber - deliver_number) > 0 {
213
+		if (warehouse.StockMinNumber - deliver_number) >= 0 {
186 214
 			warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
187 215
 		}
188 216
 
@@ -5480,7 +5508,9 @@ func ConsumablesDeliveryThirty(orgID int64, record_time int64, goods *models.War
5480 5508
 
5481 5509
 // 药品手动出库 递归方式
5482 5510
 func AutoDrugDeliverInfoFourtyOne(orgID int64, prescribingNumber int64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.DrugWarehouseOutInfo) (err error) {
5483
-	//开事务
5511
+
5512
+	fmt.Println("出库数量", prescribingNumber)
5513
+
5484 5514
 	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
5485 5515
 	var deliver_number int64 = 0
5486 5516
 	var stock_number int64 = 0
@@ -5503,6 +5533,8 @@ func AutoDrugDeliverInfoFourtyOne(orgID int64, prescribingNumber int64, warehous
5503 5533
 		var stockMin int64
5504 5534
 		stockMax = lastWarehouse.StockMinNumber / drup.MinNumber
5505 5535
 		stockMin = lastWarehouse.StockMinNumber % drup.MinNumber
5536
+		fmt.Println("stockmax", stockMax)
5537
+		fmt.Println("stockMin", stockMin)
5506 5538
 		ChangeMaxNumber(lastWarehouse.ID, stockMax)
5507 5539
 		UpdateMinNumber(lastWarehouse.ID, stockMin)
5508 5540
 	}
@@ -5515,9 +5547,18 @@ func AutoDrugDeliverInfoFourtyOne(orgID int64, prescribingNumber int64, warehous
5515 5547
 	}
5516 5548
 
5517 5549
 	// 将该批次的剩余库存数量转换为拆零数量
5550
+	if warehouse.MaxUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
5551
+		stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
5552
+	}
5553
+	if warehouse.MaxUnit == drup.MinUnit && drup.MaxUnit != drup.MinUnit {
5554
+		stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
5555
+	}
5556
+	if warehouse.MaxUnit == drup.MaxUnit && drup.MaxUnit == drup.MinUnit {
5557
+		stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
5558
+	}
5518 5559
 
5519
-	stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
5520
-
5560
+	fmt.Println("stock_number", stock_number)
5561
+	fmt.Println("deliver_number", deliver_number)
5521 5562
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
5522 5563
 	if stock_number >= deliver_number {
5523 5564
 
@@ -5539,7 +5580,15 @@ func AutoDrugDeliverInfoFourtyOne(orgID int64, prescribingNumber int64, warehous
5539 5580
 			}
5540 5581
 		}
5541 5582
 
5542
-		warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
5583
+		if drup.MinUnit == warehouse.MaxUnit && drup.MaxUnit != drup.MinUnit {
5584
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*drup.MinNumber
5585
+		}
5586
+		if drup.MaxUnit == warehouse.MaxUnit && drup.MaxUnit != drup.MinUnit {
5587
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
5588
+		}
5589
+		if drup.MaxUnit == warehouse.MaxUnit && drup.MaxUnit == drup.MinUnit {
5590
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
5591
+		}
5543 5592
 
5544 5593
 		if warehouse.StockMaxNumber < 0 {
5545 5594
 			warehouse.StockMaxNumber = 0
@@ -5554,25 +5603,30 @@ func AutoDrugDeliverInfoFourtyOne(orgID int64, prescribingNumber int64, warehous
5554 5603
 			warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
5555 5604
 			warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
5556 5605
 		} else {
5606
+			fmt.Println("maxNumber23323323332322323w9", maxNumber)
5607
+			fmt.Println("maxNumber23323323332322323w9", minNumber)
5557 5608
 			if minNumber > 0 {
5558 5609
 				if minNumber == 1 && maxNumber == 1 && drup.MaxUnit != drup.MinUnit {
5559 5610
 					warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
5560 5611
 				} else {
5561
-					warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
5612
+					if (warehouse.StockMinNumber - minNumber) >= 0 {
5613
+						warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
5614
+					}
5615
+
5562 5616
 				}
5563 5617
 			}
5564 5618
 
5565 5619
 			if minNumber == 0 && maxNumber != 1 {
5566 5620
 				if warehouse.StockMinNumber > 0 {
5567
-					warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
5621
+					if (warehouse.StockMinNumber - deliver_number) >= 0 {
5622
+						warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
5623
+					}
5568 5624
 				}
5569
-
5570 5625
 			}
5571
-
5572 5626
 		}
5573 5627
 
5574 5628
 		if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit {
5575
-			if (warehouse.StockMinNumber - deliver_number) > 0 {
5629
+			if (warehouse.StockMinNumber - deliver_number) >= 0 {
5576 5630
 				warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
5577 5631
 			}
5578 5632