ソースを参照

库存调拨修改

28169 2 年 前
コミット
9da3f69eae

+ 6 - 6
controllers/base_api_controller.go ファイルの表示

@@ -82,7 +82,7 @@ func (this *BaseAuthAPIController) Prepare() {
82 82
 		userAdmin.ModifyTime = 1530786071
83 83
 		var subscibe models.ServeSubscibe
84 84
 		subscibe.ID = 11
85
-		subscibe.OrgId = 10447 //机构id
85
+		subscibe.OrgId = 9671 //机构id
86 86
 		subscibe.PeriodStart = 1547447814
87 87
 		subscibe.PeriodEnd = 1550039814
88 88
 		subscibe.State = 1
@@ -92,8 +92,8 @@ func (this *BaseAuthAPIController) Prepare() {
92 92
 		subscibes := make(map[int64]*models.ServeSubscibe, 0)
93 93
 		subscibes[4] = &subscibe
94 94
 		var adminUserInfo service.AdminUserInfo
95
-		adminUserInfo.CurrentOrgId = 10447 //机构id小英9675或4
96
-		adminUserInfo.CurrentAppId = 10340 //4
95
+		adminUserInfo.CurrentOrgId = 9671 //机构id小英9675或4
96
+		adminUserInfo.CurrentAppId = 3244 //4
97 97
 		adminUserInfo.AdminUser = &userAdmin
98 98
 		adminUserInfo.Subscibes = subscibes
99 99
 		this.SetSession("admin_user_info", &adminUserInfo)
@@ -328,7 +328,7 @@ func (this *BaseServeAPIController) Prepare() {
328 328
 		userAdmin.ModifyTime = 1530786071
329 329
 		var subscibe models.ServeSubscibe
330 330
 		subscibe.ID = 11
331
-		subscibe.OrgId = 10447 //机构id小英9675或4
331
+		subscibe.OrgId = 9671 //机构id小英9675或4
332 332
 		subscibe.PeriodStart = 1538035409
333 333
 		subscibe.PeriodEnd = 1569571409
334 334
 		subscibe.State = 1
@@ -338,8 +338,8 @@ func (this *BaseServeAPIController) Prepare() {
338 338
 		subscibes := make(map[int64]*models.ServeSubscibe, 0)
339 339
 		subscibes[4] = &subscibe
340 340
 		var adminUserInfo service.AdminUserInfo
341
-		adminUserInfo.CurrentOrgId = 10447 //机构id小英9675或4
342
-		adminUserInfo.CurrentAppId = 10340 //4
341
+		adminUserInfo.CurrentOrgId = 9671 //机构id小英9675或4
342
+		adminUserInfo.CurrentAppId = 3244 //4
343 343
 		adminUserInfo.AdminUser = &userAdmin
344 344
 		adminUserInfo.Subscibes = subscibes
345 345
 		this.SetSession("admin_user_info", &adminUserInfo)

+ 5 - 2
controllers/his_api_controller.go ファイルの表示

@@ -1709,7 +1709,8 @@ func (c *HisApiController) CreateHisPrescription() {
1709 1709
 
1710 1710
 										//查找该耗材的出库记录
1711 1711
 										goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
1712
-										fmt.Println("goodWarehouseInfo---------------------------------------------", goodWarehouseInfo)
1712
+
1713
+										//没有出库记录
1713 1714
 										if len(goodWarehouseInfo) == 0 {
1714 1715
 											//查询耗材库存
1715 1716
 											list, _ := service.GetGoodWarehouseInfoSeven(project_id)
@@ -1753,10 +1754,13 @@ func (c *HisApiController) CreateHisPrescription() {
1753 1754
 												}
1754 1755
 
1755 1756
 											}
1757
+
1756 1758
 											//删除记录
1757 1759
 											service.DeleteAutoWarehouse(patient_id, recordDateTime)
1758 1760
 
1759 1761
 										}
1762
+
1763
+										//有出库记录
1760 1764
 										if len(goodWarehouseInfo) > 0 {
1761 1765
 											//查询该患者耗材的历史数据
1762 1766
 											ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
@@ -1805,7 +1809,6 @@ func (c *HisApiController) CreateHisPrescription() {
1805 1809
 													service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
1806 1810
 												}
1807 1811
 
1808
-												//删除记录
1809 1812
 												service.DeleteAutoWarehouse(patient_id, recordDateTime)
1810 1813
 
1811 1814
 											}

+ 1 - 0
controllers/manage_api_controller.go ファイルの表示

@@ -1933,6 +1933,7 @@ func (this *MachineApiController) GetQuery() {
1933 1933
 	cultures, err := service.GetCultureData(bedid, start, end, OrgID)
1934 1934
 	fmt.Print(err)
1935 1935
 	dialysate, err := service.GetDialysateData(bedid, start, end, OrgID)
1936
+
1936 1937
 	ions, err := service.GetDeviceIonData(bedid, start, end, OrgID)
1937 1938
 
1938 1939
 	oxygenates, err := service.GetOxygenates(bedid, start, end, OrgID)

+ 4 - 1
controllers/mobile_api_controllers/check_weight_api_controller.go ファイルの表示

@@ -655,7 +655,10 @@ func (c *CheckWeightApiController) SavePatientInfoDialysis() {
655 655
 				evaluation.BreathingRate = lastPredialysisEvaluation.BreathingRate
656 656
 				evaluation.Catheter = lastPredialysisEvaluation.Catheter
657 657
 				evaluation.InternalFistula = lastPredialysisEvaluation.InternalFistula
658
-				evaluation.PulseFrequency = lastPredialysisEvaluation.PulseFrequency
658
+				if adminUserInfo.Org.Id != 10445 {
659
+					evaluation.PulseFrequency = lastPredialysisEvaluation.PulseFrequency
660
+				}
661
+
659 662
 				evaluation.Complication = lastPredialysisEvaluation.Complication
660 663
 				evaluation.LastPostDialysis = lastPredialysisEvaluation.LastPostDialysis
661 664
 				evaluation.DialysisInterphase = lastPredialysisEvaluation.DialysisInterphase

+ 146 - 132
controllers/mobile_api_controllers/dialysis_api_controller.go ファイルの表示

@@ -5665,9 +5665,6 @@ func (c *DialysisAPIController) EditConsumables() {
5665 5665
 
5666 5666
 				}
5667 5667
 
5668
-				fmt.Println("退库长度", len(cancelbefor))
5669
-				fmt.Println("出库长度", len(outbefor))
5670
-
5671 5668
 				//退库
5672 5669
 				for _, item := range cancelbefor {
5673 5670
 					warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
@@ -5682,8 +5679,33 @@ func (c *DialysisAPIController) EditConsumables() {
5682 5679
 
5683 5680
 					delete_count = warehouseOutInfos.Count - item.Count
5684 5681
 
5682
+					//增加库存数量
5683
+					service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
5684
+
5685
+					//增加出库库存数量
5686
+					service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
5687
+
5688
+					// 删除出库完成后,要增加对应批次的库存数量
5689
+
5690
+					service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
5691
+
5685 5692
 					houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
5686 5693
 
5694
+					//更新剩余库存
5695
+					goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
5696
+					var flush_count int64
5697
+					for _, it := range goodListOne {
5698
+						flush_count += it.StockCount
5699
+					}
5700
+					service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
5701
+
5702
+					//查询剩余库存
5703
+					goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
5704
+					var sum_count int64
5705
+					for _, item := range goodList {
5706
+						sum_count += item.StockCount
5707
+					}
5708
+
5687 5709
 					// 在出库记录表里记录退库详情
5688 5710
 					warehouseOutInfo := &models.WarehouseOutInfo{
5689 5711
 						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
@@ -5700,6 +5722,7 @@ func (c *DialysisAPIController) EditConsumables() {
5700 5722
 						ConsumableType:          2,
5701 5723
 						StorehouseId:            houseConfig.StorehouseOutInfo,
5702 5724
 						IsCheck:                 1,
5725
+						OverCount:               sum_count,
5703 5726
 					}
5704 5727
 					warehouseOutInfo.Count = item.Count
5705 5728
 
@@ -5783,6 +5806,15 @@ func (c *DialysisAPIController) EditConsumables() {
5783 5806
 
5784 5807
 					} else if errcod == nil {
5785 5808
 						service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
5809
+
5810
+						fmt.Println("进来-------------------------------------------------")
5811
+
5812
+						//查询剩余库存
5813
+						goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
5814
+						var sum_count int64
5815
+						for _, item := range goodList {
5816
+							sum_count += item.StockCount
5817
+						}
5786 5818
 						//插入详情明细表
5787 5819
 						stockFlow := models.VmStockFlow{
5788 5820
 							WarehousingId:           warehouseOutInfos.WarehouseInfotId,
@@ -5810,6 +5842,7 @@ func (c *DialysisAPIController) EditConsumables() {
5810 5842
 							PatientId:               patient_id,
5811 5843
 							ReturnCount:             delete_count,
5812 5844
 							StorehouseId:            houseConfig.StorehouseOutInfo,
5845
+							OverCount:               sum_count,
5813 5846
 						}
5814 5847
 						exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
5815 5848
 
@@ -5844,8 +5877,10 @@ func (c *DialysisAPIController) EditConsumables() {
5844 5877
 								PatientId:               patient_id,
5845 5878
 								ReturnCount:             delete_count,
5846 5879
 								StorehouseId:            houseConfig.StorehouseOutInfo,
5880
+								OverCount:               exsit.OverCount + delete_count,
5847 5881
 							}
5848
-							service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
5882
+							fmt.Println("stockFlow--------------------", stockFlow.OverCount)
5883
+							service.UpdatedStockFlowFive(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
5849 5884
 						}
5850 5885
 
5851 5886
 					}
@@ -5877,16 +5912,8 @@ func (c *DialysisAPIController) EditConsumables() {
5877 5912
 
5878 5913
 					}
5879 5914
 
5880
-					service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
5881
-
5882
-					//增加出库库存数量
5883
-					service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
5884
-
5885
-					errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, item.GoodId, delete_count, patient_id)
5886
-					fmt.Println("errOne", errOne)
5887
-					// 删除出库完成后,要增加对应批次的库存数量
5888
-
5889
-					service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
5915
+					//errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, item.GoodId, delete_count, patient_id)
5916
+					//fmt.Println("errOne", errOne)
5890 5917
 
5891 5918
 					//查询默认仓库
5892 5919
 					storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
@@ -5897,31 +5924,42 @@ func (c *DialysisAPIController) EditConsumables() {
5897 5924
 					}
5898 5925
 					//基础库插入数据
5899 5926
 					service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
5900
-					//更新剩余库存
5901
-					goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
5902
-					var flush_count int64
5903
-					for _, it := range goodList {
5904
-						flush_count += it.StockCount
5905
-					}
5906
-					service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
5927
+
5907 5928
 				}
5908 5929
 
5909
-				//出库
5910
-				for _, item := range outbefor {
5911
-					fmt.Println("出库ID", item.GoodId)
5912
-					var last_total int64
5913
-					//1.查看该患者该耗材型号最后一次出库数量
5914
-					goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
5915
-					//计算当前出库和最后一次出库数据相差数据
5916
-					last_total = item.Count - goodInfoOne.Count
5930
+				fmt.Println("lnet---------------------------", len(outbefor))
5931
+				if len(outbefor) > 0 {
5932
+					//出库
5933
+					for _, item := range outbefor {
5934
+						fmt.Println("出库ID", item.GoodId)
5935
+						var last_total int64
5936
+						//1.查看该患者该耗材型号最后一次出库数量
5937
+						goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
5938
+						//计算当前出库和最后一次出库数据相差数据
5939
+						last_total = item.Count - goodInfoOne.Count
5940
+
5941
+						//查询该批次剩余库存
5942
+						lastInfo, _ := service.GetLastStockOut(goodInfoOne.WarehouseInfotId)
5943
+
5944
+						if lastInfo.StockCount == 0 {
5945
+							//查询该耗材的总库存
5946
+							wareinfo, _ := service.GetStockGoodCount(item.GoodId)
5947
+							if wareinfo.StockCount == 0 {
5948
+								goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
5949
+								c.ServeSuccessJSON(map[string]interface{}{
5950
+									"message":            "1",
5951
+									"good_name":          goodObj.GoodName,
5952
+									"specification_name": goodObj.SpecificationName,
5953
+								})
5954
+								return
5955
+							}
5917 5956
 
5918
-					//查询该批次剩余库存
5919
-					lastInfo, _ := service.GetLastStockOut(goodInfoOne.WarehouseInfotId)
5957
+						}
5920 5958
 
5921
-					if lastInfo.StockCount == 0 {
5922 5959
 						//查询该耗材的总库存
5923 5960
 						wareinfo, _ := service.GetStockGoodCount(item.GoodId)
5924
-						if wareinfo.StockCount == 0 {
5961
+						// 如果库存差大于剩余库存则提示库存不足
5962
+						if last_total > wareinfo.StockCount {
5925 5963
 							goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
5926 5964
 							c.ServeSuccessJSON(map[string]interface{}{
5927 5965
 								"message":            "1",
@@ -5929,101 +5967,85 @@ func (c *DialysisAPIController) EditConsumables() {
5929 5967
 								"specification_name": goodObj.SpecificationName,
5930 5968
 							})
5931 5969
 							return
5932
-						}
5933
-
5934
-					}
5935
-
5936
-					//查询该耗材的总库存
5937
-					wareinfo, _ := service.GetStockGoodCount(item.GoodId)
5938
-					// 如果库存差大于剩余库存则提示库存不足
5939
-					if last_total > wareinfo.StockCount {
5940
-						goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
5941
-						c.ServeSuccessJSON(map[string]interface{}{
5942
-							"message":            "1",
5943
-							"good_name":          goodObj.GoodName,
5944
-							"specification_name": goodObj.SpecificationName,
5945
-						})
5946
-						return
5947
-					} else {
5970
+						} else {
5971
+
5972
+							out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
5973
+							houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
5974
+							if err == gorm.ErrRecordNotFound {
5975
+								//没有记录,则创建出库单
5976
+								timeStr := time.Now().Format("2006-01-02")
5977
+								timeArr := strings.Split(timeStr, "-")
5978
+								total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
5979
+								total = total + 1
5980
+								warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
5981
+								number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
5982
+								number = number + total
5983
+								warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
5984
+								warehouseOut := models.WarehouseOut{
5985
+									WarehouseOutOrderNumber: warehousing_out_order,
5986
+									OperationTime:           time.Now().Unix(),
5987
+									OrgId:                   adminInfo.Org.Id,
5988
+									Creater:                 adminInfo.AdminUser.Id,
5989
+									Ctime:                   time.Now().Unix(),
5990
+									Status:                  1,
5991
+									WarehouseOutTime:        record_time,
5992
+									Dealer:                  0,
5993
+									Manufacturer:            0,
5994
+									Type:                    1,
5995
+									IsSys:                   1,
5996
+									StorehouseId:            houseConfig.StorehouseOutInfo,
5997
+									IsCheck:                 1,
5998
+								}
5999
+								service.AddSigleWarehouseOut(&warehouseOut)
5948 6000
 
5949
-						fmt.Println("出库2o2o2o2o2oo2o2o2o2o2o2o", item.GoodId)
5950
-
5951
-						out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
5952
-						houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
5953
-						if err == gorm.ErrRecordNotFound {
5954
-							//没有记录,则创建出库单
5955
-							timeStr := time.Now().Format("2006-01-02")
5956
-							timeArr := strings.Split(timeStr, "-")
5957
-							total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
5958
-							total = total + 1
5959
-							warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
5960
-							number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
5961
-							number = number + total
5962
-							warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
5963
-							warehouseOut := models.WarehouseOut{
5964
-								WarehouseOutOrderNumber: warehousing_out_order,
5965
-								OperationTime:           time.Now().Unix(),
5966
-								OrgId:                   adminInfo.Org.Id,
5967
-								Creater:                 adminInfo.AdminUser.Id,
5968
-								Ctime:                   time.Now().Unix(),
5969
-								Status:                  1,
5970
-								WarehouseOutTime:        record_time,
5971
-								Dealer:                  0,
5972
-								Manufacturer:            0,
5973
-								Type:                    1,
5974
-								IsSys:                   1,
5975
-								StorehouseId:            houseConfig.StorehouseOutInfo,
5976
-								IsCheck:                 1,
5977 6001
 							}
5978
-							service.AddSigleWarehouseOut(&warehouseOut)
6002
+							//出库
6003
+							//err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
6004
+							//houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
6005
+							//1.查看该患者该耗材型号最后一次出库数量
6006
+							goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
5979 6007
 
5980
-						}
5981
-						//出库
5982
-						//err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
5983
-						//houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
5984
-						//1.查看该患者该耗材型号最后一次出库数量
5985
-						goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
6008
+							fmt.Println("count2323323222323wi", item.Count)
6009
+							prepare := models.DialysisBeforePrepare{
6010
+								UserOrgId:    adminInfo.Org.Id,
6011
+								PatientId:    patient_id,
6012
+								RecordDate:   record_time,
6013
+								GoodId:       item.GoodId,
6014
+								GoodTypeId:   item.GoodTypeId,
6015
+								Count:        item.Count - goodInfoTwo.Count,
6016
+								Ctime:        time.Now().Unix(),
6017
+								Mtime:        0,
6018
+								Creater:      adminInfo.AdminUser.Id,
6019
+								Modifier:     adminInfo.AdminUser.Id,
6020
+								Status:       1,
6021
+								CommdityCode: "",
6022
+								NewCount:     0,
6023
+								ProjectId:    0,
6024
+								StorehouseId: houseConfig.StorehouseOutInfo,
6025
+							}
6026
+							//fmt.Println("prepare", prepare.Count)
6027
+							//fmt.Println("count", item.Count)
6028
+							service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
6029
+							//增加出库数量
6030
+							service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
6031
+
6032
+							storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
6033
+							stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
6034
+							var total_count int64
6035
+							for _, it := range stockList {
6036
+								total_count += it.StockCount
6037
+							}
6038
+							//基础库插入数据
6039
+							service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
6040
+							//剩余库存
5986 6041
 
5987
-						fmt.Println("count2323323222323wi", item.Count)
5988
-						prepare := models.DialysisBeforePrepare{
5989
-							UserOrgId:    adminInfo.Org.Id,
5990
-							PatientId:    patient_id,
5991
-							RecordDate:   record_time,
5992
-							GoodId:       item.GoodId,
5993
-							GoodTypeId:   item.GoodTypeId,
5994
-							Count:        item.Count - goodInfoTwo.Count,
5995
-							Ctime:        time.Now().Unix(),
5996
-							Mtime:        0,
5997
-							Creater:      adminInfo.AdminUser.Id,
5998
-							Modifier:     adminInfo.AdminUser.Id,
5999
-							Status:       1,
6000
-							CommdityCode: "",
6001
-							NewCount:     0,
6002
-							ProjectId:    0,
6003
-							StorehouseId: houseConfig.StorehouseOutInfo,
6004
-						}
6005
-						fmt.Println("prepare", prepare.Count)
6006
-						fmt.Println("count", item.Count)
6007
-						service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
6008
-						//增加出库数量
6009
-						service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
6010
-
6011
-						storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
6012
-						stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
6013
-						var total_count int64
6014
-						for _, it := range stockList {
6015
-							total_count += it.StockCount
6016
-						}
6017
-						//基础库插入数据
6018
-						service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
6019
-						//剩余库存
6020
-
6021
-						goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
6022
-						var flush_count int64
6023
-						for _, it := range goodList {
6024
-							flush_count += it.StockCount
6042
+							goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
6043
+							var flush_count int64
6044
+							for _, it := range goodList {
6045
+								flush_count += it.StockCount
6046
+							}
6047
+							service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
6025 6048
 						}
6026
-						service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
6027 6049
 					}
6028 6050
 				}
6029 6051
 
@@ -6063,15 +6085,7 @@ func (c *DialysisAPIController) EditConsumables() {
6063 6085
 						flush_count += it.StockCount
6064 6086
 					}
6065 6087
 					service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
6066
-					//if err != nil {
6067
-					//	goodObj, _ := service.GetGoodInformationByGoodId(it.GoodId)
6068
-					//	c.ServeSuccessJSON(map[string]interface{}{
6069
-					//		"message":            "2",
6070
-					//		"good_name":          goodObj.GoodName,
6071
-					//		"specification_name": goodObj.SpecificationName,
6072
-					//	})
6073
-					//	return
6074
-					//}
6088
+
6075 6089
 				}
6076 6090
 			}
6077 6091
 		}

+ 2 - 1
controllers/mobile_api_controllers/patient_api_controller.go ファイルの表示

@@ -1200,8 +1200,9 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1200 1200
 						}
1201 1201
 
1202 1202
 						if prescribing_number_total <= total {
1203
-							pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
1204 1203
 
1204
+							pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
1205
+							//判断药品是否零用
1205 1206
 							if medical.IsUse == 2 {
1206 1207
 
1207 1208
 								if config.IsOpen != 1 {

+ 587 - 1
service/new_warehouse_service.go ファイルの表示

@@ -2,6 +2,7 @@ package service
2 2
 
3 3
 import (
4 4
 	"XT_New/models"
5
+	"XT_New/utils"
5 6
 	"errors"
6 7
 	"fmt"
7 8
 	"github.com/jinzhu/gorm"
@@ -11,7 +12,7 @@ import (
11 12
 	"time"
12 13
 )
13 14
 
14
-//耗材出库
15
+// 耗材出库
15 16
 func ConsumablesGoodDelivery(orgID int64, patient_id int64, record_time int64, goods *models.DialysisBeforePrepare, warehouseOut *models.WarehouseOut, count int64) (err error) {
16 17
 
17 18
 	//开事务
@@ -2962,3 +2963,588 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2962 2963
 
2963 2964
 	return
2964 2965
 }
2966
+
2967
+// 耗材出库
2968
+func ConsumablesGoodDeliveryFivety(orgID int64, patient_id int64, record_time int64, goods *models.DialysisBeforePrepare, warehouseOut *models.WarehouseOut, count int64) (err error) {
2969
+
2970
+	//开事务
2971
+	tx := XTWriteDB().Begin()
2972
+	defer func() {
2973
+		if err != nil {
2974
+			utils.ErrorLog("事务失败,原因为: %v", err)
2975
+			tx.Rollback()
2976
+		} else {
2977
+			tx.Commit()
2978
+		}
2979
+	}()
2980
+
2981
+	var deliver_number int64 = 0
2982
+	var stock_number int64 = 0
2983
+	var maxNumber int64 = 0
2984
+
2985
+	deliver_number = goods.Count
2986
+
2987
+	// 根据先进先出原则,查询最先入库的批次,进行出库
2988
+	// 如果没有对应的库存,则报错
2989
+
2990
+	warehouse, err := FindFirstWarehousingInfoByStock(goods.GoodId, goods.GoodTypeId, goods.StorehouseId)
2991
+	if err != nil {
2992
+		return errors.New("库存数量不足")
2993
+	}
2994
+
2995
+	stock_number = warehouse.StockCount
2996
+
2997
+	// 当库存数量大于或等于出库数量的话,则正常出库该批次
2998
+	if stock_number >= deliver_number {
2999
+
3000
+		maxNumber = goods.Count
3001
+		//出库
3002
+		warehouse.StockCount = warehouse.StockCount - maxNumber
3003
+		warehouse.Mtime = time.Now().Unix()
3004
+		if warehouse.StockCount < 0 {
3005
+			return errors.New("库存数量不足")
3006
+		}
3007
+		err := tx.Save(&warehouse).Error
3008
+		if err != nil {
3009
+			return err
3010
+		}
3011
+		//更新his_prescripton_project出库状态值
3012
+		project := models.HisPrescriptionProject{}
3013
+		err = tx.Model(&project).Where("project_id  = ? and record_date = ? and user_org_id = ? and patient_id = ? and status = 1", goods.GoodId, record_time, orgID, patient_id).Update(map[string]interface{}{"is_out": 1}).Error
3014
+		if err != nil {
3015
+			return err
3016
+		}
3017
+		//查询剩余库存
3018
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
3019
+		var sum_count int64
3020
+		for _, item := range goodList {
3021
+			sum_count += item.StockCount
3022
+		}
3023
+
3024
+		warehouseOutInfo := &models.WarehouseOutInfo{
3025
+			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
3026
+			WarehouseOutId:          warehouseOut.ID,
3027
+			WarehouseInfotId:        warehouse.ID,
3028
+			Status:                  1,
3029
+			Ctime:                   time.Now().Unix(),
3030
+			Remark:                  warehouse.Remark,
3031
+			OrgId:                   orgID,
3032
+			Type:                    1,
3033
+			Manufacturer:            warehouse.Manufacturer,
3034
+			Dealer:                  warehouse.Dealer,
3035
+			IsSys:                   1,
3036
+			SysRecordTime:           record_time,
3037
+			GoodTypeId:              goods.GoodTypeId,
3038
+			GoodId:                  goods.GoodId,
3039
+			PatientId:               patient_id,
3040
+			Number:                  warehouse.Number,
3041
+			LicenseNumber:           warehouse.LicenseNumber,
3042
+			Price:                   warehouse.PackingPrice,
3043
+			ExpiryDate:              warehouse.ExpiryDate,
3044
+			ProductDate:             warehouse.ProductDate,
3045
+			ProjectId:               goods.ProjectId,
3046
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
3047
+			StorehouseId:            goods.StorehouseId,
3048
+			IsCheck:                 1,
3049
+			OverCount:               sum_count,
3050
+			RegisterNumber:          warehouse.RegisterNumber,
3051
+		}
3052
+		warehouseOutInfo.Count = count
3053
+		if orgID == 9671 || orgID == 10265 {
3054
+			goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
3055
+			warehouseOutInfo.Price = goodsInfo.PackingPrice
3056
+		}
3057
+		_, errcodes := GetWarehouseOutInfoIsExistOne(goods.GoodId, patient_id, record_time, goods.ProjectId)
3058
+		if errcodes == gorm.ErrRecordNotFound {
3059
+			err := tx.Create(&warehouseOutInfo).Error
3060
+			if err != nil {
3061
+				return err
3062
+			}
3063
+		} else if errcodes == nil {
3064
+
3065
+			outInfoOne, _ := GetWarehouseOutInfoIsExistTwo(goods.GoodId, patient_id, record_time, goods.ProjectId)
3066
+			if count != outInfoOne.Count {
3067
+				outInfo := models.WarehouseOutInfo{}
3068
+				err := tx.Model(&outInfo).Where("good_id = ? and patient_id = ? and sys_record_time  =? and status = 1", goods.GoodId, patient_id, record_time).Updates(map[string]interface{}{"warehouse_out_id": warehouseOutInfo.WarehouseOutId, "WarehouseOutOrderNumber": warehouseOutInfo.WarehouseOutOrderNumber, "sys_record_time": warehouseOutInfo.SysRecordTime, "good_type_id": warehouseOutInfo.GoodTypeId, "patient_id": warehouseOutInfo.PatientId, "consumable_type": warehouseOutInfo.ConsumableType, "count": warehouseOutInfo.Count, "price": warehouseOutInfo.Price, "dealer": warehouseOutInfo.Dealer, "manufacturer": warehouseOutInfo.Manufacturer, "number": warehouseOutInfo.Number, "license_number": warehouseOutInfo.LicenseNumber, "over_count": warehouseOutInfo.OverCount}).Error
3069
+				if err != nil {
3070
+					return err
3071
+				}
3072
+			}
3073
+
3074
+		}
3075
+		lastOut, _ := FindWarehouseOutInfoByPatientId(patient_id, record_time, goods.GoodId, orgID)
3076
+
3077
+		//查询已经出库的数据
3078
+		flowGood, _ := GetStockFlowIsBatchNumber(warehouse.ID, patient_id, record_time, goods.GoodId)
3079
+		var out_count int64
3080
+		var out_count_one int64
3081
+		for _, item := range flowGood {
3082
+			out_count += item.Count
3083
+		}
3084
+
3085
+		//查询退库数据
3086
+		flowGoodTwo, _ := GetStockFlowIsBatchNumberThree(patient_id, record_time, goods.GoodId)
3087
+		for _, item := range flowGoodTwo {
3088
+			out_count_one += item.Count
3089
+		}
3090
+		//如果本次出库数据大于历史出库数据 新增1条流水
3091
+		if count > (out_count - out_count_one) {
3092
+
3093
+			flow := models.VmStockFlow{
3094
+				WarehouseOutId:          warehouseOut.ID,
3095
+				WarehousingId:           warehouse.ID,
3096
+				GoodId:                  goods.GoodId,
3097
+				Number:                  warehouse.Number,
3098
+				ProductDate:             warehouse.ProductDate,
3099
+				ExpireDate:              warehouse.ExpiryDate,
3100
+				Count:                   count - out_count + out_count_one,
3101
+				Price:                   warehouse.PackingPrice,
3102
+				Status:                  1,
3103
+				Ctime:                   time.Now().Unix(),
3104
+				UserOrgId:               orgID,
3105
+				Manufacturer:            warehouse.Manufacturer,
3106
+				Dealer:                  warehouse.Dealer,
3107
+				LicenseNumber:           warehouse.LicenseNumber,
3108
+				IsEdit:                  2,
3109
+				Creator:                 warehouseOut.Creater,
3110
+				SystemTime:              record_time,
3111
+				ConsumableType:          3,
3112
+				WarehouseOutDetailId:    lastOut.ID,
3113
+				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
3114
+				IsSys:                   1,
3115
+				PatientId:               patient_id,
3116
+				ProjectId:               goods.ProjectId,
3117
+				SupplyWarehouseId:       warehouse.SupplyWarehouseId,
3118
+				StorehouseId:            goods.StorehouseId,
3119
+				OverCount:               sum_count,
3120
+				BuyPrice:                warehouse.Price,
3121
+				RegisterNumber:          warehouse.RegisterNumber,
3122
+			}
3123
+			if orgID == 9671 || orgID == 10265 {
3124
+				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
3125
+				flow.Price = goodsInfo.PackingPrice
3126
+				flow.BuyPrice = goodsInfo.BuyPrice
3127
+			}
3128
+			err := tx.Create(&flow).Error
3129
+			if err != nil {
3130
+				return err
3131
+			}
3132
+
3133
+		}
3134
+
3135
+		//如果本次出库数据小于历史出库数据 新增1条退库流水
3136
+
3137
+		if count < (out_count - out_count_one) {
3138
+
3139
+			operation_time := time.Now().Unix()
3140
+
3141
+			//创建退库单
3142
+			timeStr := time.Now().Format("2006-01-02")
3143
+			timeArr := strings.Split(timeStr, "-")
3144
+			total, _ := FindAllCancelStockTotal(orgID)
3145
+			total = total + 1
3146
+			orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
3147
+
3148
+			cancelStock := models.CancelStock{
3149
+				OrderNumber:  orderNumber,
3150
+				OperaTime:    operation_time,
3151
+				OrgId:        orgID,
3152
+				Creater:      warehouseOut.Creater,
3153
+				Ctime:        time.Now().Unix(),
3154
+				Status:       1,
3155
+				ReturnTime:   record_time,
3156
+				Type:         1,
3157
+				StorehouseId: goods.StorehouseId,
3158
+				IsCheck:      1,
3159
+			}
3160
+			_, msgerrkonde := GetCancelStockDetailByOrderNumberOne(record_time, orgID)
3161
+			if msgerrkonde == gorm.ErrRecordNotFound {
3162
+
3163
+				err := tx.Create(&cancelStock).Error
3164
+				if err != nil {
3165
+					return err
3166
+				}
3167
+			}
3168
+
3169
+			cancel, _ := GetLastCancelStockById(orgID)
3170
+
3171
+			manufacturer, _ := GetManufactureById(warehouse.Manufacturer)
3172
+			deaerler, _ := GetDealerById(warehouse.Dealer)
3173
+			cancelStockInfo := models.CancelStockInfo{
3174
+				GoodId:          goods.GoodId,
3175
+				CancelStockId:   cancel.ID,
3176
+				GoodTypeId:      goods.GoodTypeId,
3177
+				Count:           out_count - out_count_one - count,
3178
+				Price:           warehouse.PackingPrice,
3179
+				Total:           0,
3180
+				ProductDate:     warehouse.ProductDate,
3181
+				ExpiryDate:      warehouse.ExpiryDate,
3182
+				Ctime:           time.Now().Unix(),
3183
+				Status:          1,
3184
+				OrgId:           orgID,
3185
+				OrderNumber:     cancel.OrderNumber,
3186
+				Type:            0,
3187
+				Dealer:          deaerler.DealerName,
3188
+				Manufacturer:    manufacturer.ManufacturerName,
3189
+				Number:          warehouse.Number,
3190
+				RegisterAccount: "",
3191
+				Remark:          "",
3192
+				WarehouseInfoId: warehouse.ID,
3193
+				PatientId:       patient_id,
3194
+				RecordDate:      record_time,
3195
+				StorehouseId:    goods.StorehouseId,
3196
+				IsCheck:         1,
3197
+			}
3198
+			if orgID == 9671 || orgID == 10265 {
3199
+				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
3200
+				cancelStockInfo.Price = goodsInfo.PackingPrice
3201
+			}
3202
+
3203
+			err := tx.Create(&cancelStockInfo).Error
3204
+			if err != nil {
3205
+				return err
3206
+			}
3207
+
3208
+			cancelInfo, _ := GetLastCancelStockInfoByGoodId(goods.GoodId)
3209
+
3210
+			flow := models.VmStockFlow{
3211
+				WarehousingId:           warehouse.ID,
3212
+				GoodId:                  goods.GoodId,
3213
+				Number:                  warehouse.Number,
3214
+				LicenseNumber:           warehouse.LicenseNumber,
3215
+				Count:                   out_count - out_count_one - count,
3216
+				UserOrgId:               orgID,
3217
+				PatientId:               patient_id,
3218
+				SystemTime:              record_time,
3219
+				ConsumableType:          7,
3220
+				IsSys:                   1,
3221
+				WarehousingOrder:        "",
3222
+				WarehouseOutId:          lastOut.WarehouseOutId,
3223
+				WarehouseOutOrderNumber: lastOut.WarehouseOutOrderNumber,
3224
+				IsEdit:                  0,
3225
+				CancelStockId:           cancel.ID,
3226
+				CancelOrderNumber:       cancel.OrderNumber,
3227
+				Manufacturer:            manufacturer.ID,
3228
+				Dealer:                  0,
3229
+				Creator:                 warehouseOut.Creater,
3230
+				UpdateCreator:           0,
3231
+				Status:                  1,
3232
+				Ctime:                   time.Now().Unix(),
3233
+				Mtime:                   0,
3234
+				Price:                   warehouse.PackingPrice,
3235
+				WarehousingDetailId:     warehouse.ID,
3236
+				WarehouseOutDetailId:    lastOut.ID,
3237
+				CancelOutDetailId:       cancelInfo.ID,
3238
+				ProductDate:             warehouse.ProductDate,
3239
+				ExpireDate:              warehouse.ExpiryDate,
3240
+				StorehouseId:            goods.StorehouseId,
3241
+				BuyPrice:                warehouse.Price,
3242
+				ProjectId:               goods.ProjectId,
3243
+				OverCount:               sum_count,
3244
+				RegisterNumber:          warehouse.RegisterNumber,
3245
+			}
3246
+			if orgID == 9671 || orgID == 10265 {
3247
+				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
3248
+				flow.Price = goodsInfo.PackingPrice
3249
+				flow.BuyPrice = goodsInfo.BuyPrice
3250
+			}
3251
+
3252
+			err = tx.Create(&flow).Error
3253
+			if err != nil {
3254
+				return err
3255
+			}
3256
+		}
3257
+
3258
+		details := models.BloodAutomaticReduceDetail{
3259
+			WarehouseOutId:          lastOut.ID,
3260
+			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
3261
+			PatientId:               patient_id,
3262
+			Ctime:                   time.Now().Unix(),
3263
+			Mtime:                   time.Now().Unix(),
3264
+			Status:                  1,
3265
+			RecordTime:              record_time,
3266
+			OrgId:                   orgID,
3267
+			GoodId:                  goods.GoodId,
3268
+			GoodTypeId:              goods.GoodTypeId,
3269
+			Count:                   count,
3270
+			ProjectId:               goods.ProjectId,
3271
+			StorehouseId:            goods.StorehouseId,
3272
+		}
3273
+
3274
+		////查询该耗材已经出库的数量
3275
+		_, errcode := GetAutoMaticReduceDetailTwenty(orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId)
3276
+		if errcode == gorm.ErrRecordNotFound {
3277
+
3278
+			err := tx.Create(&details).Error
3279
+			if err != nil {
3280
+				return err
3281
+			}
3282
+
3283
+		} else if errcode == nil {
3284
+
3285
+			detail := models.BloodAutomaticReduceDetail{}
3286
+			err := tx.Model(&detail).Where("org_id = ? and patient_id = ? and record_time = ? and status =1 and good_id = ? and good_type_id = ?", orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
3287
+			if err != nil {
3288
+				return err
3289
+			}
3290
+
3291
+			err = tx.Create(&detail).Error
3292
+			if err != nil {
3293
+				return err
3294
+			}
3295
+
3296
+		}
3297
+
3298
+		return err
3299
+	} else {
3300
+
3301
+		// 当刚批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
3302
+		warehouse.StockCount = 0
3303
+		warehouse.Mtime = time.Now().Unix()
3304
+		errThree := UpDateWarehouseInfoByStock(&warehouse)
3305
+		if errThree != nil {
3306
+			return errThree
3307
+		}
3308
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
3309
+		var sum_count int64
3310
+		for _, item := range goodList {
3311
+			sum_count += item.StockCount
3312
+		}
3313
+		warehouseOutInfo := &models.WarehouseOutInfo{
3314
+			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
3315
+			WarehouseOutId:          warehouseOut.ID,
3316
+			WarehouseInfotId:        warehouse.ID,
3317
+			Status:                  1,
3318
+			Ctime:                   time.Now().Unix(),
3319
+			Remark:                  warehouse.Remark,
3320
+			OrgId:                   orgID,
3321
+			Type:                    1,
3322
+			Manufacturer:            warehouse.Manufacturer,
3323
+			Dealer:                  warehouse.Dealer,
3324
+			IsSys:                   1,
3325
+			SysRecordTime:           record_time,
3326
+			GoodTypeId:              goods.GoodTypeId,
3327
+			GoodId:                  goods.GoodId,
3328
+			PatientId:               patient_id,
3329
+			Number:                  warehouse.Number,
3330
+			LicenseNumber:           warehouse.LicenseNumber,
3331
+			Price:                   warehouse.PackingPrice,
3332
+			ExpiryDate:              warehouse.ExpiryDate,
3333
+			ProductDate:             warehouse.ProductDate,
3334
+			ProjectId:               goods.ProjectId,
3335
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
3336
+			StorehouseId:            goods.StorehouseId,
3337
+			IsCheck:                 1,
3338
+			OverCount:               sum_count,
3339
+			RegisterNumber:          warehouse.RegisterNumber,
3340
+		}
3341
+		warehouseOutInfo.Count = stock_number
3342
+		if orgID == 9671 || orgID == 10265 {
3343
+			goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
3344
+			warehouseOutInfo.Price = goodsInfo.PackingPrice
3345
+		}
3346
+		_, errcodes := GetWarehouseOutInfoIsExistOne(goods.GoodId, patient_id, record_time, goods.ProjectId)
3347
+
3348
+		if errcodes == gorm.ErrRecordNotFound {
3349
+
3350
+			outInfo := models.WarehouseOutInfo{}
3351
+			err := tx.Model(&outInfo).Where("good_id = ? and patient_id = ? and sys_record_time  =? and status = 1", goods.GoodId, patient_id, record_time).Updates(map[string]interface{}{"warehouse_out_id": warehouseOutInfo.WarehouseOutId, "WarehouseOutOrderNumber": warehouseOutInfo.WarehouseOutOrderNumber, "sys_record_time": warehouseOutInfo.SysRecordTime, "good_type_id": warehouseOutInfo.GoodTypeId, "patient_id": warehouseOutInfo.PatientId, "consumable_type": warehouseOutInfo.ConsumableType, "count": warehouseOutInfo.Count, "price": warehouseOutInfo.Price, "dealer": warehouseOutInfo.Dealer, "manufacturer": warehouseOutInfo.Manufacturer, "number": warehouseOutInfo.Number, "license_number": warehouseOutInfo.LicenseNumber, "over_count": warehouseOutInfo.OverCount}).Error
3352
+			if err != nil {
3353
+				return err
3354
+			}
3355
+
3356
+		} else if errcodes == nil {
3357
+			goods.Count = deliver_number - stock_number
3358
+			//更新数量为  该批次剩余数量  + 还有未出的数量
3359
+			warehouseOutInfo.Count = stock_number
3360
+			outInfoOne, _ := GetWarehouseOutInfoIsExistTwo(goods.GoodId, patient_id, record_time, goods.ProjectId)
3361
+			if count != outInfoOne.Count {
3362
+				outInfo := models.WarehouseOutInfo{}
3363
+				err := tx.Model(&outInfo).Where("good_id = ? and patient_id = ? and sys_record_time  =? and status = 1", goods.GoodId, patient_id, record_time).Updates(map[string]interface{}{"warehouse_out_id": warehouseOutInfo.WarehouseOutId, "WarehouseOutOrderNumber": warehouseOutInfo.WarehouseOutOrderNumber, "sys_record_time": warehouseOutInfo.SysRecordTime, "good_type_id": warehouseOutInfo.GoodTypeId, "patient_id": warehouseOutInfo.PatientId, "consumable_type": warehouseOutInfo.ConsumableType, "count": warehouseOutInfo.Count, "price": warehouseOutInfo.Price, "dealer": warehouseOutInfo.Dealer, "manufacturer": warehouseOutInfo.Manufacturer, "number": warehouseOutInfo.Number, "license_number": warehouseOutInfo.LicenseNumber, "over_count": warehouseOutInfo.OverCount}).Error
3364
+				if err != nil {
3365
+					return err
3366
+				}
3367
+			}
3368
+
3369
+		}
3370
+		lastOut, _ := FindWarehouseOutInfoByPatientId(patient_id, record_time, goods.GoodId, orgID)
3371
+		//查询该该批次已经出库的数据
3372
+		flowGood, _ := GetStockFlowIsBatchNumber(warehouse.ID, patient_id, record_time, goods.GoodId)
3373
+		var out_count int64
3374
+		var out_count_one int64
3375
+		for _, item := range flowGood {
3376
+			out_count += item.Count
3377
+		}
3378
+		flowGoodTwo, _ := GetStockFlowIsBatchNumberThree(patient_id, record_time, goods.GoodId)
3379
+		for _, item := range flowGoodTwo {
3380
+			out_count_one += item.Count
3381
+		}
3382
+		//如果出库数量 大于 历史出库数据 新增1条流水
3383
+		if count > out_count-out_count_one {
3384
+			flow := models.VmStockFlow{
3385
+				WarehouseOutId:          warehouseOut.ID,
3386
+				WarehousingId:           warehouse.ID,
3387
+				GoodId:                  goods.GoodId,
3388
+				Number:                  warehouse.Number,
3389
+				ProductDate:             warehouse.ProductDate,
3390
+				ExpireDate:              warehouse.ExpiryDate,
3391
+				Count:                   stock_number,
3392
+				Price:                   warehouse.PackingPrice,
3393
+				Status:                  1,
3394
+				Ctime:                   time.Now().Unix(),
3395
+				UserOrgId:               orgID,
3396
+				Manufacturer:            warehouse.Manufacturer,
3397
+				Dealer:                  warehouse.Dealer,
3398
+				LicenseNumber:           warehouse.LicenseNumber,
3399
+				IsEdit:                  2,
3400
+				Creator:                 warehouseOut.Creater,
3401
+				SystemTime:              record_time,
3402
+				ConsumableType:          3,
3403
+				WarehouseOutDetailId:    lastOut.ID,
3404
+				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
3405
+				IsSys:                   1,
3406
+				PatientId:               patient_id,
3407
+				ProjectId:               goods.ProjectId,
3408
+				SupplyWarehouseId:       warehouse.SupplyWarehouseId,
3409
+				StorehouseId:            goods.StorehouseId,
3410
+				OverCount:               sum_count,
3411
+				BuyPrice:                warehouse.Price,
3412
+				RegisterNumber:          warehouse.RegisterNumber,
3413
+			}
3414
+			if orgID == 9671 || orgID == 10265 {
3415
+				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
3416
+				flow.Price = goodsInfo.PackingPrice
3417
+				flow.BuyPrice = goodsInfo.BuyPrice
3418
+			}
3419
+			err := tx.Create(&flow).Error
3420
+			if err != nil {
3421
+				return err
3422
+			}
3423
+		}
3424
+		//退库
3425
+		if count < out_count-out_count_one {
3426
+			operation_time := time.Now().Unix()
3427
+
3428
+			//创建退库单
3429
+			timeStr := time.Now().Format("2006-01-02")
3430
+			timeArr := strings.Split(timeStr, "-")
3431
+			total, _ := FindAllCancelStockTotal(orgID)
3432
+			total = total + 1
3433
+			orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
3434
+
3435
+			cancelStock := models.CancelStock{
3436
+				OrderNumber:  orderNumber,
3437
+				OperaTime:    operation_time,
3438
+				OrgId:        orgID,
3439
+				Creater:      warehouseOut.Creater,
3440
+				Ctime:        time.Now().Unix(),
3441
+				Status:       1,
3442
+				ReturnTime:   record_time,
3443
+				Type:         1,
3444
+				StorehouseId: goods.StorehouseId,
3445
+				IsCheck:      1,
3446
+			}
3447
+			_, msgerrkonde := GetCancelStockDetailByOrderNumberOne(record_time, orgID)
3448
+			if msgerrkonde == gorm.ErrRecordNotFound {
3449
+				err := tx.Create(&cancelStock).Error
3450
+				if err != nil {
3451
+					return err
3452
+				}
3453
+			}
3454
+
3455
+			cancel, _ := GetLastCancelStockById(orgID)
3456
+
3457
+			manufacturer, _ := GetManufactureById(warehouse.Manufacturer)
3458
+			deaerler, _ := GetDealerById(warehouse.Dealer)
3459
+			cancelStockInfo := models.CancelStockInfo{
3460
+				GoodId:          goods.GoodId,
3461
+				CancelStockId:   cancel.ID,
3462
+				GoodTypeId:      goods.GoodTypeId,
3463
+				Count:           out_count - out_count_one - count,
3464
+				Price:           warehouse.PackingPrice,
3465
+				Total:           0,
3466
+				ProductDate:     warehouse.ProductDate,
3467
+				ExpiryDate:      warehouse.ExpiryDate,
3468
+				Ctime:           time.Now().Unix(),
3469
+				Status:          1,
3470
+				OrgId:           orgID,
3471
+				OrderNumber:     cancel.OrderNumber,
3472
+				Type:            0,
3473
+				Dealer:          deaerler.DealerName,
3474
+				Manufacturer:    manufacturer.ManufacturerName,
3475
+				Number:          warehouse.Number,
3476
+				RegisterAccount: "",
3477
+				Remark:          "",
3478
+				WarehouseInfoId: warehouse.ID,
3479
+				PatientId:       patient_id,
3480
+				RecordDate:      record_time,
3481
+				StorehouseId:    goods.StorehouseId,
3482
+				IsCheck:         1,
3483
+			}
3484
+			if orgID == 9671 || orgID == 10265 {
3485
+				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
3486
+				cancelStockInfo.Price = goodsInfo.PackingPrice
3487
+			}
3488
+			err := tx.Create(&cancelStockInfo).Error
3489
+			if err != nil {
3490
+				return err
3491
+			}
3492
+
3493
+			cancelInfo, _ := GetLastCancelStockInfoByGoodId(goods.GoodId)
3494
+
3495
+			flow := models.VmStockFlow{
3496
+				WarehousingId:           warehouse.ID,
3497
+				GoodId:                  goods.GoodId,
3498
+				Number:                  warehouse.Number,
3499
+				LicenseNumber:           warehouse.LicenseNumber,
3500
+				Count:                   out_count - count,
3501
+				UserOrgId:               orgID,
3502
+				PatientId:               patient_id,
3503
+				SystemTime:              record_time,
3504
+				ConsumableType:          7,
3505
+				IsSys:                   1,
3506
+				WarehousingOrder:        "",
3507
+				WarehouseOutId:          lastOut.WarehouseOutId,
3508
+				WarehouseOutOrderNumber: lastOut.WarehouseOutOrderNumber,
3509
+				IsEdit:                  0,
3510
+				CancelStockId:           cancel.ID,
3511
+				CancelOrderNumber:       cancel.OrderNumber,
3512
+				Manufacturer:            manufacturer.ID,
3513
+				Dealer:                  0,
3514
+				Creator:                 warehouseOut.Creater,
3515
+				UpdateCreator:           0,
3516
+				Status:                  1,
3517
+				Ctime:                   time.Now().Unix(),
3518
+				Mtime:                   0,
3519
+				Price:                   warehouse.PackingPrice,
3520
+				WarehousingDetailId:     warehouse.ID,
3521
+				WarehouseOutDetailId:    lastOut.ID,
3522
+				CancelOutDetailId:       cancelInfo.ID,
3523
+				ProductDate:             warehouse.ProductDate,
3524
+				ExpireDate:              warehouse.ExpiryDate,
3525
+				StorehouseId:            goods.StorehouseId,
3526
+				BuyPrice:                warehouse.Price,
3527
+				ProjectId:               goods.ProjectId,
3528
+				OverCount:               sum_count,
3529
+				RegisterNumber:          warehouse.RegisterNumber,
3530
+			}
3531
+			if orgID == 9671 || orgID == 10265 {
3532
+				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
3533
+				flow.Price = goodsInfo.PackingPrice
3534
+				flow.BuyPrice = goodsInfo.BuyPrice
3535
+			}
3536
+
3537
+			err = tx.Create(&flow).Error
3538
+			if err != nil {
3539
+				return err
3540
+			}
3541
+		}
3542
+
3543
+		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
3544
+		goods.Count = deliver_number - stock_number
3545
+
3546
+		ConsumablesGoodDelivery(orgID, patient_id, record_time, goods, warehouseOut, count)
3547
+
3548
+	}
3549
+	return err
3550
+}

+ 6 - 0
service/stock_service.go ファイルの表示

@@ -5068,6 +5068,12 @@ func UpdatedStockFlowOne(flow models.VmStockFlow, warehousing_id int64, patient_
5068 5068
 	return err
5069 5069
 }
5070 5070
 
5071
+func UpdatedStockFlowFive(flow models.VmStockFlow, warehouse_out_id int64, patient_id int64, record_time int64, good_id int64) error {
5072
+
5073
+	err = XTWriteDB().Model(&flow).Where("warehouse_out_id = ? and patient_id = ? and system_time = ? and good_id = ? and status = 1", warehouse_out_id, patient_id, record_time, good_id).Updates(map[string]interface{}{"number": flow.Number, "license_number": flow.LicenseNumber, "count": flow.Count, "expire_date": flow.ExpireDate, "product_date": flow.ProductDate, "price": flow.Price, "manufacturer": flow.Manufacturer, "dealer": flow.Dealer, "over_count": flow.OverCount}).Error
5074
+	return err
5075
+}
5076
+
5071 5077
 func GetStockFlowIsExsit(warehousing_id int64, patient_id int64, record_time int64, good_id int64) (*models.VmStockFlow, error) {
5072 5078
 
5073 5079
 	stock := models.VmStockFlow{}

File diff suppressed because it is too large
+ 0 - 6109
service/warhouse_service.go