28169 2 vuotta sitten
vanhempi
commit
91146103aa

+ 3 - 0
controllers/doctors_api_controller.go Näytä tiedosto

123
 		hisAdvices, err := service.GetHisDoctorAdvicesTwentyOne(orgID, date.Unix(), delivery_way, schedule_type, partition_type, patient_id, excution_way, 0, execution_frequency)
123
 		hisAdvices, err := service.GetHisDoctorAdvicesTwentyOne(orgID, date.Unix(), delivery_way, schedule_type, partition_type, patient_id, excution_way, 0, execution_frequency)
124
 		adminUser, _ := service.GetAllAdminUsers(orgID, adminUserInfo.CurrentAppId)
124
 		adminUser, _ := service.GetAllAdminUsers(orgID, adminUserInfo.CurrentAppId)
125
 		project, _ := service.GetPCHisPrescriptionProject(orgID, date.Unix(), delivery_way, patientType, partition_type, patient_id, excution_way)
125
 		project, _ := service.GetPCHisPrescriptionProject(orgID, date.Unix(), delivery_way, patientType, partition_type, patient_id, excution_way)
126
+
127
+		drug, _ := service.GetAllBaseDrugListTwenty(orgID)
126
 		for _, item := range project {
128
 		for _, item := range project {
127
 			index := 0
129
 			index := 0
128
 			for _, subItem := range item.HisPrescriptionTeamProject {
130
 			for _, subItem := range item.HisPrescriptionTeamProject {
152
 				"config":         config,
154
 				"config":         config,
153
 				"project_config": project_config,
155
 				"project_config": project_config,
154
 				"project":        project,
156
 				"project":        project,
157
+				"drug":           drug,
155
 			})
158
 			})
156
 		}
159
 		}
157
 	}
160
 	}

+ 0 - 1
controllers/his_api_controller.go Näytä tiedosto

1755
 
1755
 
1756
 											}
1756
 											}
1757
 
1757
 
1758
-											//删除记录
1759
 											service.DeleteAutoWarehouse(patient_id, recordDateTime)
1758
 											service.DeleteAutoWarehouse(patient_id, recordDateTime)
1760
 
1759
 
1761
 										}
1760
 										}

+ 270 - 232
controllers/mobile_api_controllers/dialysis_api_controller.go Näytä tiedosto

4913
 			}
4913
 			}
4914
 		}
4914
 		}
4915
 
4915
 
4916
-		fmt.Println("active------------------------------------", active)
4917
-		fmt.Println("len------------------------------", len(goods))
4918
 		//新增
4916
 		//新增
4919
 		if active == 1 && len(goods) > 0 {
4917
 		if active == 1 && len(goods) > 0 {
4920
 			for _, item := range dialysisBefor {
4918
 			for _, item := range dialysisBefor {
5686
 
5684
 
5687
 				}
5685
 				}
5688
 
5686
 
5689
-				//退库
5690
-				for _, item := range cancelbefor {
5691
-					warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
5692
-					creater := adminInfo.AdminUser.Id
5687
+				if len(cancelbefor) > 0 {
5693
 					//退库
5688
 					//退库
5694
-					//err = ConsumablesDeliveryTotalSeven(adminInfo.Org.Id, patient_id, record_time, cancelbefor, adminInfo.AdminUser.Id, item.Count)
5695
-					//查询该患者当天已经出库的耗材信息
5689
+					for _, item := range cancelbefor {
5690
+						warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
5691
+						creater := adminInfo.AdminUser.Id
5696
 
5692
 
5697
-					warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
5693
+						//查询该患者当天已经出库的耗材信息
5694
+						warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
5698
 
5695
 
5699
-					var delete_count int64 = 0
5696
+						var delete_count int64 = 0
5700
 
5697
 
5701
-					delete_count = warehouseOutInfos.Count - item.Count
5698
+						delete_count = warehouseOutInfos.Count - item.Count
5702
 
5699
 
5703
-					//增加库存数量
5704
-					service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
5700
+						//增加库存数量
5701
+						service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
5705
 
5702
 
5706
-					//增加出库库存数量
5707
-					service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
5703
+						//减少实际出库库存数量
5704
+						service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
5708
 
5705
 
5709
-					// 删除出库完成后,要增加对应批次的库存数量
5706
+						// 删除出库完成后,要增加对应批次的库存数量
5710
 
5707
 
5711
-					service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
5708
+						service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
5712
 
5709
 
5713
-					houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
5710
+						houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
5714
 
5711
 
5715
-					//更新剩余库存
5716
-					goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
5717
-					var flush_count int64
5718
-					for _, it := range goodListOne {
5719
-						flush_count += it.StockCount
5720
-					}
5721
-					service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
5712
+						//更新剩余库存
5713
+						goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
5714
+						var flush_count int64
5715
+						for _, it := range goodListOne {
5716
+							flush_count += it.StockCount
5717
+						}
5718
+						service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
5722
 
5719
 
5723
-					//查询剩余库存
5724
-					goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
5725
-					var sum_count int64
5726
-					for _, item := range goodList {
5727
-						sum_count += item.StockCount
5728
-					}
5720
+						//查询剩余库存
5721
+						goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
5722
+						var sum_count int64
5723
+						for _, item := range goodList {
5724
+							sum_count += item.StockCount
5725
+						}
5729
 
5726
 
5730
-					// 在出库记录表里记录退库详情
5731
-					warehouseOutInfo := &models.WarehouseOutInfo{
5732
-						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5733
-						WarehouseOutId:          warehouseOut.ID,
5734
-						Status:                  1,
5735
-						Ctime:                   time.Now().Unix(),
5736
-						OrgId:                   adminInfo.Org.Id,
5737
-						Type:                    1,
5738
-						IsSys:                   1,
5739
-						SysRecordTime:           record_time,
5740
-						GoodTypeId:              item.GoodTypeId,
5741
-						GoodId:                  item.GoodId,
5742
-						PatientId:               patient_id,
5743
-						ConsumableType:          2,
5744
-						StorehouseId:            houseConfig.StorehouseOutInfo,
5745
-						IsCheck:                 1,
5746
-						OverCount:               sum_count,
5747
-					}
5748
-					warehouseOutInfo.Count = item.Count
5749
-
5750
-					stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
5751
-					warehouseOutInfo.Price = stockInInfo.Price
5752
-					warehouseOutInfo.Dealer = stockInInfo.Dealer
5753
-					warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
5754
-					warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
5755
-					warehouseOutInfo.ProductDate = stockInInfo.ProductDate
5756
-					warehouseOutInfo.Number = warehouseOutInfos.Number
5757
-					warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
5758
-					warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
5759
-					//查找当天是否存在出库记录
5760
-					_, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
5761
-
5762
-					if errcod == gorm.ErrRecordNotFound {
5763
-						service.AddSigleWarehouseOutInfo(warehouseOutInfo)
5764
-						//插入详情明细表
5765
-						stockFlow := models.VmStockFlow{
5727
+						// 在出库记录表里记录退库详情
5728
+						warehouseOutInfo := &models.WarehouseOutInfo{
5766
 							WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5729
 							WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5767
 							WarehouseOutId:          warehouseOut.ID,
5730
 							WarehouseOutId:          warehouseOut.ID,
5768
-							GoodId:                  item.GoodId,
5769
-							Number:                  warehouseOutInfos.Number,
5770
-							ProductDate:             stockInInfo.ProductDate,
5771
-							ExpireDate:              stockInInfo.ExpiryDate,
5772
-							Count:                   item.Count,
5773
-							Price:                   stockInInfo.Price,
5774
 							Status:                  1,
5731
 							Status:                  1,
5775
 							Ctime:                   time.Now().Unix(),
5732
 							Ctime:                   time.Now().Unix(),
5776
-							UserOrgId:               adminInfo.Org.Id,
5777
-							Manufacturer:            stockInInfo.Manufacturer,
5778
-							Dealer:                  stockInInfo.Dealer,
5779
-							LicenseNumber:           stockInInfo.LicenseNumber,
5780
-							IsEdit:                  2,
5781
-							Creator:                 creater,
5782
-							SystemTime:              record_time,
5783
-							ConsumableType:          3,
5784
-							WarehousingDetailId:     0,
5733
+							OrgId:                   adminInfo.Org.Id,
5734
+							Type:                    1,
5785
 							IsSys:                   1,
5735
 							IsSys:                   1,
5786
-							UpdateCreator:           creater,
5736
+							SysRecordTime:           record_time,
5737
+							GoodTypeId:              item.GoodTypeId,
5738
+							GoodId:                  item.GoodId,
5787
 							PatientId:               patient_id,
5739
 							PatientId:               patient_id,
5740
+							ConsumableType:          2,
5788
 							StorehouseId:            houseConfig.StorehouseOutInfo,
5741
 							StorehouseId:            houseConfig.StorehouseOutInfo,
5742
+							IsCheck:                 1,
5743
+							OverCount:               sum_count,
5789
 						}
5744
 						}
5790
-						exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
5791
-						if errflow == gorm.ErrRecordNotFound {
5792
-							//创建流水表
5793
-							err := service.CreateStockFlowOne(stockFlow)
5794
-							fmt.Println("err", err)
5795
-						} else if errflow == nil {
5745
+						warehouseOutInfo.Count = item.Count
5746
+
5747
+						stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
5748
+						warehouseOutInfo.Price = stockInInfo.Price
5749
+						warehouseOutInfo.Dealer = stockInInfo.Dealer
5750
+						warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
5751
+						warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
5752
+						warehouseOutInfo.ProductDate = stockInInfo.ProductDate
5753
+						warehouseOutInfo.Number = warehouseOutInfos.Number
5754
+						warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
5755
+						warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
5756
+						//查找当天是否存在出库记录
5757
+						_, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
5758
+
5759
+						if errcod == gorm.ErrRecordNotFound {
5760
+							service.AddSigleWarehouseOutInfo(warehouseOutInfo)
5796
 							//插入详情明细表
5761
 							//插入详情明细表
5797
 							stockFlow := models.VmStockFlow{
5762
 							stockFlow := models.VmStockFlow{
5798
-								ID:                      exsit.ID,
5799
-								WarehousingId:           warehouseOutInfos.WarehouseInfotId,
5800
 								WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5763
 								WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5801
 								WarehouseOutId:          warehouseOut.ID,
5764
 								WarehouseOutId:          warehouseOut.ID,
5802
 								GoodId:                  item.GoodId,
5765
 								GoodId:                  item.GoodId,
5803
 								Number:                  warehouseOutInfos.Number,
5766
 								Number:                  warehouseOutInfos.Number,
5804
 								ProductDate:             stockInInfo.ProductDate,
5767
 								ProductDate:             stockInInfo.ProductDate,
5805
 								ExpireDate:              stockInInfo.ExpiryDate,
5768
 								ExpireDate:              stockInInfo.ExpiryDate,
5806
-								Count:                   exsit.Count - delete_count,
5769
+								Count:                   item.Count,
5807
 								Price:                   stockInInfo.Price,
5770
 								Price:                   stockInInfo.Price,
5808
 								Status:                  1,
5771
 								Status:                  1,
5809
 								Ctime:                   time.Now().Unix(),
5772
 								Ctime:                   time.Now().Unix(),
5821
 								PatientId:               patient_id,
5784
 								PatientId:               patient_id,
5822
 								StorehouseId:            houseConfig.StorehouseOutInfo,
5785
 								StorehouseId:            houseConfig.StorehouseOutInfo,
5823
 							}
5786
 							}
5787
+							exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
5788
+							if errflow == gorm.ErrRecordNotFound {
5789
+								//创建流水表
5790
+								err := service.CreateStockFlowOne(stockFlow)
5791
+								fmt.Println("err", err)
5792
+							} else if errflow == nil {
5793
+								//插入详情明细表
5794
+								stockFlow := models.VmStockFlow{
5795
+									ID:                      exsit.ID,
5796
+									WarehousingId:           warehouseOutInfos.WarehouseInfotId,
5797
+									WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5798
+									WarehouseOutId:          warehouseOut.ID,
5799
+									GoodId:                  item.GoodId,
5800
+									Number:                  warehouseOutInfos.Number,
5801
+									ProductDate:             stockInInfo.ProductDate,
5802
+									ExpireDate:              stockInInfo.ExpiryDate,
5803
+									Count:                   exsit.Count - delete_count,
5804
+									Price:                   stockInInfo.Price,
5805
+									Status:                  1,
5806
+									Ctime:                   time.Now().Unix(),
5807
+									UserOrgId:               adminInfo.Org.Id,
5808
+									Manufacturer:            stockInInfo.Manufacturer,
5809
+									Dealer:                  stockInInfo.Dealer,
5810
+									LicenseNumber:           stockInInfo.LicenseNumber,
5811
+									IsEdit:                  2,
5812
+									Creator:                 creater,
5813
+									SystemTime:              record_time,
5814
+									ConsumableType:          3,
5815
+									WarehousingDetailId:     0,
5816
+									IsSys:                   1,
5817
+									UpdateCreator:           creater,
5818
+									PatientId:               patient_id,
5819
+									StorehouseId:            houseConfig.StorehouseOutInfo,
5820
+								}
5824
 
5821
 
5825
-							service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
5826
-						}
5822
+								service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
5823
+							}
5827
 
5824
 
5828
-					} else if errcod == nil {
5829
-						service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
5825
+						} else if errcod == nil {
5826
+							service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
5830
 
5827
 
5831
-						fmt.Println("进来-------------------------------------------------")
5828
+							//查询剩余库存
5829
+							goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
5830
+							var sum_count int64
5831
+							for _, item := range goodList {
5832
+								sum_count += item.StockCount
5833
+							}
5832
 
5834
 
5833
-						//查询剩余库存
5834
-						goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
5835
-						var sum_count int64
5836
-						for _, item := range goodList {
5837
-							sum_count += item.StockCount
5835
+							//创建退库单,生成退库数据
5836
+							houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
5837
+							good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
5838
+
5839
+							operation_time := time.Now().Unix()
5840
+							creater := adminInfo.AdminUser.Id
5841
+							//创建退库单
5842
+							timeStr := time.Now().Format("2006-01-02")
5843
+							timeArr := strings.Split(timeStr, "-")
5844
+							total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
5845
+							total = total + 1
5846
+							orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
5847
+
5848
+							cancelStock := models.CancelStock{
5849
+								OrderNumber:  orderNumber,
5850
+								OperaTime:    operation_time,
5851
+								OrgId:        adminInfo.Org.Id,
5852
+								Creater:      creater,
5853
+								Ctime:        time.Now().Unix(),
5854
+								Status:       1,
5855
+								ReturnTime:   record_time,
5856
+								Type:         1,
5857
+								StorehouseId: houseConfig.StorehouseOutInfo,
5858
+								IsCheck:      1,
5859
+							}
5860
+							_, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
5861
+							if msgerrkonde == gorm.ErrRecordNotFound {
5862
+								service.AddSigleCancelStock(&cancelStock)
5863
+							}
5864
+							cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
5865
+
5866
+							//查询是否有出库
5867
+							info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
5868
+
5869
+							manufacturer, _ := service.GetManufactureById(info.Manufacturer)
5870
+							deaerler, _ := service.GetDealerById(info.Dealer)
5871
+
5872
+							if info.ID > 0 {
5873
+								cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
5874
+								cancelStockInfo := models.CancelStockInfo{
5875
+									GoodId:          item.GoodId,
5876
+									CancelStockId:   cancel.ID,
5877
+									GoodTypeId:      good.GoodTypeId,
5878
+									Count:           delete_count,
5879
+									Price:           info.Price,
5880
+									Total:           0,
5881
+									ProductDate:     info.ProductDate,
5882
+									ExpiryDate:      info.ExpiryDate,
5883
+									Ctime:           time.Now().Unix(),
5884
+									Status:          1,
5885
+									OrgId:           adminInfo.Org.Id,
5886
+									OrderNumber:     cancel.OrderNumber,
5887
+									Type:            0,
5888
+									Dealer:          deaerler.DealerName,
5889
+									Manufacturer:    manufacturer.ManufacturerName,
5890
+									Number:          info.Number,
5891
+									RegisterAccount: "",
5892
+									Remark:          "",
5893
+									WarehouseInfoId: info.WarehouseInfotId,
5894
+									PatientId:       info.PatientId,
5895
+									RecordDate:      info.SysRecordTime,
5896
+									StorehouseId:    houseConfig.StorehouseOutInfo,
5897
+									IsCheck:         1,
5898
+								}
5899
+
5900
+								service.CreateCancelStockInfoOne(&cancelStockInfo)
5901
+
5902
+								//退库数量增加
5903
+								service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
5904
+
5905
+								//查询剩余库存
5906
+								goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
5907
+								var over_count int64
5908
+								for _, it := range goodList {
5909
+									over_count += it.StockCount
5910
+								}
5911
+
5912
+								flow := models.VmStockFlow{
5913
+									WarehousingId:           info.WarehouseInfotId,
5914
+									GoodId:                  item.GoodId,
5915
+									Number:                  info.Number,
5916
+									LicenseNumber:           info.LicenseNumber,
5917
+									Count:                   delete_count,
5918
+									UserOrgId:               adminInfo.Org.Id,
5919
+									PatientId:               patient_id,
5920
+									SystemTime:              info.SysRecordTime,
5921
+									ConsumableType:          7,
5922
+									IsSys:                   0,
5923
+									WarehousingOrder:        "",
5924
+									WarehouseOutId:          info.WarehouseOutId,
5925
+									WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
5926
+									IsEdit:                  0,
5927
+									CancelStockId:           cancel.ID,
5928
+									CancelOrderNumber:       cancel.OrderNumber,
5929
+									Manufacturer:            manufacturer.ID,
5930
+									Dealer:                  0,
5931
+									Creator:                 adminInfo.AdminUser.Id,
5932
+									UpdateCreator:           0,
5933
+									Status:                  1,
5934
+									Ctime:                   time.Now().Unix(),
5935
+									Mtime:                   0,
5936
+									Price:                   info.Price,
5937
+									WarehousingDetailId:     info.WarehouseInfotId,
5938
+									WarehouseOutDetailId:    info.ID,
5939
+									CancelOutDetailId:       cancelInfo.ID,
5940
+									ProductDate:             info.ProductDate,
5941
+									ExpireDate:              info.ExpiryDate,
5942
+									StorehouseId:            houseConfig.StorehouseOutInfo,
5943
+									OverCount:               over_count,
5944
+								}
5945
+								service.CreateStockFlowOne(flow)
5946
+
5947
+							}
5838
 						}
5948
 						}
5839
-						//插入详情明细表
5840
-						stockFlow := models.VmStockFlow{
5841
-							WarehousingId:           warehouseOutInfos.WarehouseInfotId,
5842
-							WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5843
-							WarehouseOutId:          warehouseOut.ID,
5949
+
5950
+						//更改自动出库的表格
5951
+						details := models.BloodAutomaticReduceDetail{
5952
+							WarehouseOutId:          warehouseOutInfo.ID,
5953
+							WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
5954
+							PatientId:               patient_id,
5955
+							Ctime:                   time.Now().Unix(),
5956
+							Mtime:                   time.Now().Unix(),
5957
+							Status:                  1,
5958
+							RecordTime:              record_time,
5959
+							OrgId:                   adminInfo.Org.Id,
5844
 							GoodId:                  item.GoodId,
5960
 							GoodId:                  item.GoodId,
5845
-							Number:                  warehouseOutInfos.Number,
5846
-							ProductDate:             stockInInfo.ProductDate,
5847
-							ExpireDate:              stockInInfo.ExpiryDate,
5961
+							GoodTypeId:              item.GoodTypeId,
5848
 							Count:                   item.Count,
5962
 							Count:                   item.Count,
5849
-							Price:                   stockInInfo.Price,
5850
-							Status:                  1,
5851
-							Ctime:                   time.Now().Unix(),
5852
-							UserOrgId:               adminInfo.Org.Id,
5853
-							Manufacturer:            stockInInfo.Manufacturer,
5854
-							Dealer:                  stockInInfo.Dealer,
5855
-							LicenseNumber:           stockInInfo.LicenseNumber,
5856
-							IsEdit:                  2,
5857
-							Creator:                 creater,
5858
-							SystemTime:              record_time,
5859
-							ConsumableType:          3,
5860
-							WarehousingDetailId:     0,
5861
-							IsSys:                   1,
5862
-							UpdateCreator:           creater,
5863
-							PatientId:               patient_id,
5864
-							ReturnCount:             delete_count,
5865
 							StorehouseId:            houseConfig.StorehouseOutInfo,
5963
 							StorehouseId:            houseConfig.StorehouseOutInfo,
5866
-							OverCount:               sum_count,
5867
-						}
5868
-						exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
5869
-
5870
-						if errflows == gorm.ErrRecordNotFound {
5871
-							//创建流水表
5872
-							service.CreateStockFlowOne(stockFlow)
5873
-						} else if errflows == nil {
5874
-							stockFlow := models.VmStockFlow{
5875
-								WarehousingId:           warehouseOutInfos.WarehouseInfotId,
5876
-								ID:                      exsit.ID,
5877
-								WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5878
-								WarehouseOutId:          warehouseOut.ID,
5879
-								GoodId:                  item.GoodId,
5880
-								Number:                  warehouseOutInfos.Number,
5881
-								ProductDate:             stockInInfo.ProductDate,
5882
-								ExpireDate:              stockInInfo.ExpiryDate,
5883
-								Count:                   exsit.Count - delete_count,
5884
-								Price:                   stockInInfo.Price,
5885
-								Status:                  1,
5886
-								Ctime:                   time.Now().Unix(),
5887
-								UserOrgId:               adminInfo.Org.Id,
5888
-								Manufacturer:            stockInInfo.Manufacturer,
5889
-								Dealer:                  stockInInfo.Dealer,
5890
-								LicenseNumber:           stockInInfo.LicenseNumber,
5891
-								IsEdit:                  2,
5892
-								Creator:                 creater,
5893
-								SystemTime:              record_time,
5894
-								ConsumableType:          3,
5895
-								WarehousingDetailId:     0,
5896
-								IsSys:                   1,
5897
-								UpdateCreator:           creater,
5898
-								PatientId:               patient_id,
5899
-								ReturnCount:             delete_count,
5900
-								StorehouseId:            houseConfig.StorehouseOutInfo,
5901
-								OverCount:               exsit.OverCount + delete_count,
5902
-							}
5903
-							fmt.Println("stockFlow--------------------", stockFlow.OverCount)
5904
-							service.UpdatedStockFlowFive(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
5905
 						}
5964
 						}
5965
+						//查询当天耗材是否已经存在数据
5966
+						_, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
5906
 
5967
 
5907
-					}
5908
-
5909
-					//更改自动出库的表格
5910
-					details := models.BloodAutomaticReduceDetail{
5911
-						WarehouseOutId:          warehouseOutInfo.ID,
5912
-						WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
5913
-						PatientId:               patient_id,
5914
-						Ctime:                   time.Now().Unix(),
5915
-						Mtime:                   time.Now().Unix(),
5916
-						Status:                  1,
5917
-						RecordTime:              record_time,
5918
-						OrgId:                   adminInfo.Org.Id,
5919
-						GoodId:                  item.GoodId,
5920
-						GoodTypeId:              item.GoodTypeId,
5921
-						Count:                   item.Count,
5922
-						StorehouseId:            houseConfig.StorehouseOutInfo,
5923
-					}
5924
-					//查询当天耗材是否已经存在数据
5925
-					_, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
5926
-
5927
-					if errcode == gorm.ErrRecordNotFound {
5928
-						service.CreateAutoReduceRecord(&details)
5968
+						if errcode == gorm.ErrRecordNotFound {
5969
+							service.CreateAutoReduceRecord(&details)
5929
 
5970
 
5930
-					} else if errcode == nil {
5931
-						service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
5932
-						service.CreateAutoReduceRecord(&details)
5971
+						} else if errcode == nil {
5972
+							service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
5973
+							service.CreateAutoReduceRecord(&details)
5933
 
5974
 
5934
-					}
5975
+						}
5935
 
5976
 
5936
-					//errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, item.GoodId, delete_count, patient_id)
5937
-					//fmt.Println("errOne", errOne)
5977
+						//查询默认仓库
5978
+						storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
5979
+						stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
5980
+						var total_count int64
5981
+						for _, it := range stockList {
5982
+							total_count += it.StockCount
5983
+						}
5984
+						//基础库插入数据
5985
+						service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
5938
 
5986
 
5939
-					//查询默认仓库
5940
-					storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
5941
-					stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
5942
-					var total_count int64
5943
-					for _, it := range stockList {
5944
-						total_count += it.StockCount
5945
 					}
5987
 					}
5946
-					//基础库插入数据
5947
-					service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
5948
-
5949
 				}
5988
 				}
5950
 
5989
 
5951
 				fmt.Println("lnet---------------------------", len(outbefor))
5990
 				fmt.Println("lnet---------------------------", len(outbefor))
5959
 						//计算当前出库和最后一次出库数据相差数据
5998
 						//计算当前出库和最后一次出库数据相差数据
5960
 						last_total = item.Count - goodInfoOne.Count
5999
 						last_total = item.Count - goodInfoOne.Count
5961
 
6000
 
5962
-						//查询该批次剩余库存
5963
-						lastInfo, _ := service.GetLastStockOut(goodInfoOne.WarehouseInfotId)
5964
-
5965
-						if lastInfo.StockCount == 0 {
5966
-							//查询该耗材的总库存
5967
-							wareinfo, _ := service.GetStockGoodCount(item.GoodId)
5968
-							if wareinfo.StockCount == 0 {
5969
-								goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
5970
-								c.ServeSuccessJSON(map[string]interface{}{
5971
-									"message":            "1",
5972
-									"good_name":          goodObj.GoodName,
5973
-									"specification_name": goodObj.SpecificationName,
5974
-								})
5975
-								return
5976
-							}
5977
-
5978
-						}
5979
-
5980
 						//查询该耗材的总库存
6001
 						//查询该耗材的总库存
5981
 						wareinfo, _ := service.GetStockGoodCount(item.GoodId)
6002
 						wareinfo, _ := service.GetStockGoodCount(item.GoodId)
6003
+
5982
 						// 如果库存差大于剩余库存则提示库存不足
6004
 						// 如果库存差大于剩余库存则提示库存不足
5983
 						if last_total > wareinfo.StockCount {
6005
 						if last_total > wareinfo.StockCount {
5984
 							goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
6006
 							goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
6044
 								ProjectId:    0,
6066
 								ProjectId:    0,
6045
 								StorehouseId: houseConfig.StorehouseOutInfo,
6067
 								StorehouseId: houseConfig.StorehouseOutInfo,
6046
 							}
6068
 							}
6047
-							//fmt.Println("prepare", prepare.Count)
6048
-							//fmt.Println("count", item.Count)
6069
+
6049
 							service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
6070
 							service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
6050
 							//增加出库数量
6071
 							//增加出库数量
6051
 							service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
6072
 							service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
6105
 					for _, it := range goodList {
6126
 					for _, it := range goodList {
6106
 						flush_count += it.StockCount
6127
 						flush_count += it.StockCount
6107
 					}
6128
 					}
6129
+
6108
 					service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
6130
 					service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
6109
 
6131
 
6110
 				}
6132
 				}
6369
 				}
6391
 				}
6370
 				project_id := int64(items["project_id"].(float64))
6392
 				project_id := int64(items["project_id"].(float64))
6371
 
6393
 
6394
+				new_count := int64(items["new_count"].(float64))
6395
+				old_count := int64(items["old_count"].(float64))
6396
+
6372
 				prepare := &models.DialysisBeforePrepareGoods{
6397
 				prepare := &models.DialysisBeforePrepareGoods{
6373
 					GoodId:       good_id,
6398
 					GoodId:       good_id,
6374
 					GoodTypeId:   good_type_id,
6399
 					GoodTypeId:   good_type_id,
6375
 					Count:        count,
6400
 					Count:        count,
6376
 					ProjectId:    project_id,
6401
 					ProjectId:    project_id,
6377
 					StorehouseId: houseConfig.StorehouseOutInfo,
6402
 					StorehouseId: houseConfig.StorehouseOutInfo,
6403
+					NewCount:     new_count,
6404
+					OldCount:     old_count,
6378
 				}
6405
 				}
6406
+
6379
 				beforePrepares = append(beforePrepares, prepare)
6407
 				beforePrepares = append(beforePrepares, prepare)
6380
 
6408
 
6381
 				newPrepare := &models.NewDialysisBeforePrepareGoods{
6409
 				newPrepare := &models.NewDialysisBeforePrepareGoods{
6384
 					Count:        count,
6412
 					Count:        count,
6385
 					ProjectId:    project_id,
6413
 					ProjectId:    project_id,
6386
 					StorehouseId: houseConfig.StorehouseOutInfo,
6414
 					StorehouseId: houseConfig.StorehouseOutInfo,
6415
+					NewCount:     new_count,
6416
+					OldCount:     old_count,
6387
 				}
6417
 				}
6418
+
6388
 				newBeforePrepares = append(newBeforePrepares, newPrepare)
6419
 				newBeforePrepares = append(newBeforePrepares, newPrepare)
6420
+
6389
 			}
6421
 			}
6390
 		}
6422
 		}
6391
 	}
6423
 	}
6392
 
6424
 
6393
 	//查询是否有库存
6425
 	//查询是否有库存
6426
+
6394
 	for _, item := range beforePrepares {
6427
 	for _, item := range beforePrepares {
6395
-		storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
6396
-		warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
6397
-		if item.Count > warehouse.Count {
6398
-			goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
6399
-			c.ServeSuccessJSON(map[string]interface{}{
6400
-				"message":            "1",
6401
-				"good_name":          goodObj.GoodName,
6402
-				"specification_name": goodObj.SpecificationName,
6403
-			})
6404
-			return
6428
+
6429
+		if item.NewCount > 0 {
6430
+			storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
6431
+			warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
6432
+
6433
+			if item.Count > warehouse.Count {
6434
+				goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
6435
+				c.ServeSuccessJSON(map[string]interface{}{
6436
+					"message":            "1",
6437
+					"good_name":          goodObj.GoodName,
6438
+					"specification_name": goodObj.SpecificationName,
6439
+				})
6440
+				return
6441
+			}
6405
 		}
6442
 		}
6443
+
6406
 	}
6444
 	}
6407
 
6445
 
6408
 	//出库逻辑
6446
 	//出库逻辑

+ 0 - 6
controllers/new_mobile_api_controllers/dialysis_parameter_api_controller.go Näytä tiedosto

30
 	loc, _ := time.LoadLocation("Local")
30
 	loc, _ := time.LoadLocation("Local")
31
 	adminUserInfo := this.GetMobileAdminUserInfo()
31
 	adminUserInfo := this.GetMobileAdminUserInfo()
32
 	orgid := adminUserInfo.Org.Id
32
 	orgid := adminUserInfo.Org.Id
33
-	fmt.Println(orgid)
34
 	keywords := this.GetString("keyword")
33
 	keywords := this.GetString("keyword")
35
 	start_time := this.GetString("start_time")
34
 	start_time := this.GetString("start_time")
36
-	fmt.Println("start_time", start_time)
37
 	limit, _ := this.GetInt64("limit")
35
 	limit, _ := this.GetInt64("limit")
38
-	fmt.Println(limit)
39
 	page, _ := this.GetInt64("page")
36
 	page, _ := this.GetInt64("page")
40
-	fmt.Println(page)
41
 	partitionType, _ := this.GetInt64("partitionType")
37
 	partitionType, _ := this.GetInt64("partitionType")
42
-	fmt.Println("partiontype", partitionType)
43
 	scheduleType, _ := this.GetInt64("scheduleType")
38
 	scheduleType, _ := this.GetInt64("scheduleType")
44
-	fmt.Println(scheduleType)
45
 
39
 
46
 	theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
40
 	theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
47
 	if len(keywords) > 0 {
41
 	if len(keywords) > 0 {

+ 1 - 1
controllers/self_drug_api_congtroller.go Näytä tiedosto

2716
 	})
2716
 	})
2717
 }
2717
 }
2718
 
2718
 
2719
-//库存优化接口
2719
+// 库存优化接口
2720
 func (this *SelfDrugApiController) GetStorehouseList() {
2720
 func (this *SelfDrugApiController) GetStorehouseList() {
2721
 
2721
 
2722
 	orgId := this.GetAdminUserInfo().CurrentOrgId
2722
 	orgId := this.GetAdminUserInfo().CurrentOrgId

+ 2 - 0
models/dialysis.go Näytä tiedosto

1103
 	PatientId         int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1103
 	PatientId         int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1104
 	OrderId           int64  `gorm:"column:order_id" json:"order_id" form:"order_id"`
1104
 	OrderId           int64  `gorm:"column:order_id" json:"order_id" form:"order_id"`
1105
 	NewCount          int64  `gorm:"column:new_count" json:"new_count" form:"new_count"`
1105
 	NewCount          int64  `gorm:"column:new_count" json:"new_count" form:"new_count"`
1106
+	OldCount          int64  `gorm:"column:old_count" json:"old_count" form:"old_count"`
1106
 }
1107
 }
1107
 
1108
 
1108
 type NewDialysisBeforePrepareGoods struct {
1109
 type NewDialysisBeforePrepareGoods struct {
1119
 	ChildNewDialysisBeforePrepareGoods []*NewDialysisBeforePrepareGoods `gorm:"ForeignKey:GoodId;AssociationForeignKey:GoodId" json:"child"`
1120
 	ChildNewDialysisBeforePrepareGoods []*NewDialysisBeforePrepareGoods `gorm:"ForeignKey:GoodId;AssociationForeignKey:GoodId" json:"child"`
1120
 	PatientId                          int64                            `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1121
 	PatientId                          int64                            `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1121
 	OrderId                            int64                            `gorm:"column:order_id" json:"order_id" form:"order_id"`
1122
 	OrderId                            int64                            `gorm:"column:order_id" json:"order_id" form:"order_id"`
1123
+	OldCount                           int64                            `gorm:"column:old_count" json:"old_count" form:"old_count"`
1122
 }
1124
 }
1123
 
1125
 
1124
 type OldDialysisBeforePrepareGoods struct {
1126
 type OldDialysisBeforePrepareGoods struct {

+ 1 - 1
routers/router.go Näytä tiedosto

11
 func init() {
11
 func init() {
12
 	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
12
 	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
13
 		//AllowAllOrigins:  true,
13
 		//AllowAllOrigins:  true,
14
-		AllowOrigins: []string{"https://xt.kuyicloud.com", "http://localhost:9528", "http://localhost:9529", "http://localhost:9531", "http://xt.test.shengws.com", "http://new_mobile.test.sgjyun.com", "https://xt.test.shengws.com", "http://xt.test.sgjyun.com", "https://xt.test.sgjyun.com", "http://localhost:8081", "http://localhost:8082", "https://pad.kuyicloud.com", "http://pad.kuyicloud.com", "http://pad.test.sgjyun.com", "https://pad.test.sgjyun.com", "http://admin.xt.test.sgjyun.com", "http://admin.xt.kuyicloud.com", "http://mobile.sgjyun.com", "http://mobile.kuyicloud.com"},
14
+		AllowOrigins: []string{"https://xt.kuyicloud.com", "http://localhost:9528", "http://localhost:9529", "http://localhost:9531", "http://xt.test.shengws.com", "http://new_mobile.test.sgjyun.com", "https://api.xt.test.sgjyun.com", "https://xt.test.shengws.com", "http://xt.test.sgjyun.com", "https://xt.test.sgjyun.com", "http://localhost:8081", "http://localhost:8082", "https://pad.kuyicloud.com", "http://pad.kuyicloud.com", "http://pad.test.sgjyun.com", "https://pad.test.sgjyun.com", "http://admin.xt.test.sgjyun.com", "http://admin.xt.kuyicloud.com", "http://mobile.sgjyun.com", "http://mobile.kuyicloud.com"},
15
 		//AllowOrigins:     []string{"https://xt.kuyicloud.com", "http://localhost:9528", "http://xt.test.shengws.com","https://xt.test.shengws.com", "http://xt.test.sgjyun.com","https://xt.test.sgjyun.com", "http://localhost:8081", "http://localhost:8082", "https://pad.kuyicloud.com", "http://pad.kuyicloud.com", "http://pad.test.sgjyun.com","https://pad.test.sgjyun.com", "http://admin.xt.test.sgjyun.com", "http://admin.xt.kuyicloud.com","http://mobile.sgjyun.com","http://mobile.kuyicloud.com"},
15
 		//AllowOrigins:     []string{"https://xt.kuyicloud.com", "http://localhost:9528", "http://xt.test.shengws.com","https://xt.test.shengws.com", "http://xt.test.sgjyun.com","https://xt.test.sgjyun.com", "http://localhost:8081", "http://localhost:8082", "https://pad.kuyicloud.com", "http://pad.kuyicloud.com", "http://pad.test.sgjyun.com","https://pad.test.sgjyun.com", "http://admin.xt.test.sgjyun.com", "http://admin.xt.kuyicloud.com","http://mobile.sgjyun.com","http://mobile.kuyicloud.com"},
16
 		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
16
 		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
17
 		AllowHeaders:     []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type", "X-XSRF-TOKEN", "Permission", "KyToken"},
17
 		AllowHeaders:     []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type", "X-XSRF-TOKEN", "Permission", "KyToken"},

+ 1 - 1
service/dialysis_service.go Näytä tiedosto

1593
 	advice_list_str, _ := redis.Get(key).Result()
1593
 	advice_list_str, _ := redis.Get(key).Result()
1594
 
1594
 
1595
 	if len(advice_list_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
1595
 	if len(advice_list_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
1596
-		err = readDb.Where("status = 1 AND user_org_id = ? AND advice_type = 2 AND advice_date = ? ", orgID, scheduleDate).Find(&advices).Error
1596
+		err = readDb.Where("status = 1 AND user_org_id = ? AND advice_type = 2 AND advice_date = ? and id desc ", orgID, scheduleDate).Find(&advices).Error
1597
 		if err != nil {
1597
 		if err != nil {
1598
 			if err == gorm.ErrRecordNotFound {
1598
 			if err == gorm.ErrRecordNotFound {
1599
 				if len(advices) <= 0 {
1599
 				if len(advices) <= 0 {

+ 595 - 4
service/new_warehouse_service.go Näytä tiedosto

26
 	// 如果没有对应的库存,则报错
26
 	// 如果没有对应的库存,则报错
27
 
27
 
28
 	warehouse, err := FindFirstWarehousingInfoByStock(goods.GoodId, goods.GoodTypeId, goods.StorehouseId)
28
 	warehouse, err := FindFirstWarehousingInfoByStock(goods.GoodId, goods.GoodTypeId, goods.StorehouseId)
29
-	if err != nil {
30
-		return errors.New("库存数量不足")
29
+	if goods.Count > 0 {
30
+		if err != nil {
31
+			return errors.New("库存数量不足")
32
+		}
31
 	}
33
 	}
32
 
34
 
33
 	stock_number = warehouse.StockCount
35
 	stock_number = warehouse.StockCount
36
 	if stock_number >= deliver_number {
38
 	if stock_number >= deliver_number {
37
 
39
 
38
 		maxNumber = goods.Count
40
 		maxNumber = goods.Count
41
+
39
 		//出库
42
 		//出库
40
 		warehouse.StockCount = warehouse.StockCount - maxNumber
43
 		warehouse.StockCount = warehouse.StockCount - maxNumber
41
 		warehouse.Mtime = time.Now().Unix()
44
 		warehouse.Mtime = time.Now().Unix()
352
 			warehouseOutInfo.Price = goodsInfo.PackingPrice
355
 			warehouseOutInfo.Price = goodsInfo.PackingPrice
353
 		}
356
 		}
354
 		_, errcodes := GetWarehouseOutInfoIsExistOne(goods.GoodId, patient_id, record_time, goods.ProjectId)
357
 		_, errcodes := GetWarehouseOutInfoIsExistOne(goods.GoodId, patient_id, record_time, goods.ProjectId)
355
-		//fmt.Println("errcodes23332322332323223", errcodes, goods.ProjectId)
358
+
356
 		if errcodes == gorm.ErrRecordNotFound {
359
 		if errcodes == gorm.ErrRecordNotFound {
357
 			errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
360
 			errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
358
 			if errOne != nil {
361
 			if errOne != nil {
3004
 		if warehouse.StockCount < 0 {
3007
 		if warehouse.StockCount < 0 {
3005
 			return errors.New("库存数量不足")
3008
 			return errors.New("库存数量不足")
3006
 		}
3009
 		}
3007
-		err := tx.Save(&warehouse).Error
3010
+		var info models.WarehousingInfo
3011
+		err := tx.Model(&info).Where("id = ?", warehouse.ID).Updates(map[string]interface{}{"stock_count": warehouse.StockCount}).Error
3008
 		if err != nil {
3012
 		if err != nil {
3009
 			return err
3013
 			return err
3010
 		}
3014
 		}
3548
 	}
3552
 	}
3549
 	return err
3553
 	return err
3550
 }
3554
 }
3555
+
3556
+func ConsumablesGoodDeliveryNew(orgID int64, patient_id int64, record_time int64, goods *models.DialysisBeforePrepare, warehouseOut *models.WarehouseOut, count int64) (err error) {
3557
+
3558
+	//开事务
3559
+	tx := XTWriteDB().Begin()
3560
+	if err != nil {
3561
+		utils.ErrorLog("事务失败,原因为: %v", err)
3562
+		tx.Rollback()
3563
+	} else {
3564
+		fmt.Println("err-----------------------", err)
3565
+		tx.Commit()
3566
+	}
3567
+	var deliver_number int64 = 0
3568
+	var stock_number int64 = 0
3569
+	var maxNumber int64 = 0
3570
+
3571
+	deliver_number = goods.Count
3572
+
3573
+	// 根据先进先出原则,查询最先入库的批次,进行出库
3574
+	// 如果没有对应的库存,则报错
3575
+
3576
+	warehouse, err := FindFirstWarehousingInfoByStock(goods.GoodId, goods.GoodTypeId, goods.StorehouseId)
3577
+	if goods.Count > 0 {
3578
+		if err != nil {
3579
+			return errors.New("库存数量不足")
3580
+		}
3581
+	}
3582
+
3583
+	stock_number = warehouse.StockCount
3584
+
3585
+	// 当库存数量大于或等于出库数量的话,则正常出库该批次
3586
+	if stock_number >= deliver_number {
3587
+
3588
+		maxNumber = goods.Count
3589
+
3590
+		//出库
3591
+		warehouse.StockCount = warehouse.StockCount - maxNumber
3592
+		warehouse.Mtime = time.Now().Unix()
3593
+		if warehouse.StockCount < 0 {
3594
+			return errors.New("库存数量不足")
3595
+		}
3596
+
3597
+		err := tx.Save(&warehouse).Error
3598
+		if err != nil {
3599
+			return err
3600
+		}
3601
+		//更新his_prescripton_project出库状态值
3602
+		UpdateHisPrescriptionProjectStatus(goods.GoodId, record_time, orgID, patient_id)
3603
+
3604
+		var info []*models.WarehousingInfo
3605
+		err = tx.Where("good_id = ? and org_id = ? and is_check =1 and status= 1 and stock_count > 0 and storehouse_id = ?", goods.GoodId, orgID, goods.StorehouseId).Find(&info).Error
3606
+		var sum_count int64
3607
+		for _, item := range info {
3608
+			sum_count += item.StockCount
3609
+		}
3610
+
3611
+		warehouseOutInfo := &models.WarehouseOutInfo{
3612
+			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
3613
+			WarehouseOutId:          warehouseOut.ID,
3614
+			WarehouseInfotId:        warehouse.ID,
3615
+			Status:                  1,
3616
+			Ctime:                   time.Now().Unix(),
3617
+			Remark:                  warehouse.Remark,
3618
+			OrgId:                   orgID,
3619
+			Type:                    1,
3620
+			Manufacturer:            warehouse.Manufacturer,
3621
+			Dealer:                  warehouse.Dealer,
3622
+			IsSys:                   1,
3623
+			SysRecordTime:           record_time,
3624
+			GoodTypeId:              goods.GoodTypeId,
3625
+			GoodId:                  goods.GoodId,
3626
+			PatientId:               patient_id,
3627
+			Number:                  warehouse.Number,
3628
+			LicenseNumber:           warehouse.LicenseNumber,
3629
+			Price:                   warehouse.PackingPrice,
3630
+			ExpiryDate:              warehouse.ExpiryDate,
3631
+			ProductDate:             warehouse.ProductDate,
3632
+			ProjectId:               goods.ProjectId,
3633
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
3634
+			StorehouseId:            goods.StorehouseId,
3635
+			IsCheck:                 1,
3636
+			OverCount:               sum_count,
3637
+			RegisterNumber:          warehouse.RegisterNumber,
3638
+		}
3639
+		warehouseOutInfo.Count = count
3640
+		if orgID == 9671 || orgID == 10265 {
3641
+			goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
3642
+			warehouseOutInfo.Price = goodsInfo.PackingPrice
3643
+		}
3644
+		_, errcodes := GetWarehouseOutInfoIsExistOne(goods.GoodId, patient_id, record_time, goods.ProjectId)
3645
+		if errcodes == gorm.ErrRecordNotFound {
3646
+			err := tx.Create(&warehouseOutInfo).Error
3647
+			if err != nil {
3648
+				return err
3649
+			}
3650
+		} else if errcodes == nil {
3651
+
3652
+			outInfoOne, _ := GetWarehouseOutInfoIsExistTwo(goods.GoodId, patient_id, record_time, goods.ProjectId)
3653
+			if count != outInfoOne.Count {
3654
+
3655
+				outInfo := models.WarehouseOutInfo{}
3656
+				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
3657
+				if err != nil {
3658
+					return err
3659
+				}
3660
+			}
3661
+
3662
+		}
3663
+		lastOut, _ := FindWarehouseOutInfoByPatientId(patient_id, record_time, goods.GoodId, orgID)
3664
+
3665
+		//查询已经出库的数据
3666
+		flowGood, _ := GetStockFlowIsBatchNumber(warehouse.ID, patient_id, record_time, goods.GoodId)
3667
+		var out_count int64
3668
+		var out_count_one int64
3669
+		for _, item := range flowGood {
3670
+			out_count += item.Count
3671
+		}
3672
+
3673
+		//查询退库数据
3674
+		flowGoodTwo, _ := GetStockFlowIsBatchNumberThree(patient_id, record_time, goods.GoodId)
3675
+		for _, item := range flowGoodTwo {
3676
+			out_count_one += item.Count
3677
+		}
3678
+		//如果本次出库数据大于历史出库数据 新增1条流水
3679
+		if count > (out_count - out_count_one) {
3680
+
3681
+			flow := models.VmStockFlow{
3682
+				WarehouseOutId:          warehouseOut.ID,
3683
+				WarehousingId:           warehouse.ID,
3684
+				GoodId:                  goods.GoodId,
3685
+				Number:                  warehouse.Number,
3686
+				ProductDate:             warehouse.ProductDate,
3687
+				ExpireDate:              warehouse.ExpiryDate,
3688
+				Count:                   count - out_count + out_count_one,
3689
+				Price:                   warehouse.PackingPrice,
3690
+				Status:                  1,
3691
+				Ctime:                   time.Now().Unix(),
3692
+				UserOrgId:               orgID,
3693
+				Manufacturer:            warehouse.Manufacturer,
3694
+				Dealer:                  warehouse.Dealer,
3695
+				LicenseNumber:           warehouse.LicenseNumber,
3696
+				IsEdit:                  2,
3697
+				Creator:                 warehouseOut.Creater,
3698
+				SystemTime:              record_time,
3699
+				ConsumableType:          3,
3700
+				WarehouseOutDetailId:    lastOut.ID,
3701
+				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
3702
+				IsSys:                   1,
3703
+				PatientId:               patient_id,
3704
+				ProjectId:               goods.ProjectId,
3705
+				SupplyWarehouseId:       warehouse.SupplyWarehouseId,
3706
+				StorehouseId:            goods.StorehouseId,
3707
+				OverCount:               sum_count,
3708
+				BuyPrice:                warehouse.Price,
3709
+				RegisterNumber:          warehouse.RegisterNumber,
3710
+			}
3711
+			if orgID == 9671 || orgID == 10265 {
3712
+				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
3713
+				flow.Price = goodsInfo.PackingPrice
3714
+				flow.BuyPrice = goodsInfo.BuyPrice
3715
+			}
3716
+
3717
+			err := tx.Create(&flow).Error
3718
+			if err != nil {
3719
+				return err
3720
+			}
3721
+
3722
+		}
3723
+
3724
+		//如果本次出库数据小于历史出库数据 新增1条退库流水
3725
+
3726
+		if count < (out_count - out_count_one) {
3727
+
3728
+			operation_time := time.Now().Unix()
3729
+
3730
+			//创建退库单
3731
+			timeStr := time.Now().Format("2006-01-02")
3732
+			timeArr := strings.Split(timeStr, "-")
3733
+			total, _ := FindAllCancelStockTotal(orgID)
3734
+			total = total + 1
3735
+			orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
3736
+
3737
+			cancelStock := models.CancelStock{
3738
+				OrderNumber:  orderNumber,
3739
+				OperaTime:    operation_time,
3740
+				OrgId:        orgID,
3741
+				Creater:      warehouseOut.Creater,
3742
+				Ctime:        time.Now().Unix(),
3743
+				Status:       1,
3744
+				ReturnTime:   record_time,
3745
+				Type:         1,
3746
+				StorehouseId: goods.StorehouseId,
3747
+				IsCheck:      1,
3748
+			}
3749
+			_, msgerrkonde := GetCancelStockDetailByOrderNumberOne(record_time, orgID)
3750
+			if msgerrkonde == gorm.ErrRecordNotFound {
3751
+
3752
+				err := tx.Create(&cancelStock).Error
3753
+				if err != nil {
3754
+					return err
3755
+				}
3756
+			}
3757
+
3758
+			cancel, _ := GetLastCancelStockById(orgID)
3759
+
3760
+			manufacturer, _ := GetManufactureById(warehouse.Manufacturer)
3761
+			deaerler, _ := GetDealerById(warehouse.Dealer)
3762
+			cancelStockInfo := models.CancelStockInfo{
3763
+				GoodId:          goods.GoodId,
3764
+				CancelStockId:   cancel.ID,
3765
+				GoodTypeId:      goods.GoodTypeId,
3766
+				Count:           out_count - out_count_one - count,
3767
+				Price:           warehouse.PackingPrice,
3768
+				Total:           0,
3769
+				ProductDate:     warehouse.ProductDate,
3770
+				ExpiryDate:      warehouse.ExpiryDate,
3771
+				Ctime:           time.Now().Unix(),
3772
+				Status:          1,
3773
+				OrgId:           orgID,
3774
+				OrderNumber:     cancel.OrderNumber,
3775
+				Type:            0,
3776
+				Dealer:          deaerler.DealerName,
3777
+				Manufacturer:    manufacturer.ManufacturerName,
3778
+				Number:          warehouse.Number,
3779
+				RegisterAccount: "",
3780
+				Remark:          "",
3781
+				WarehouseInfoId: warehouse.ID,
3782
+				PatientId:       patient_id,
3783
+				RecordDate:      record_time,
3784
+				StorehouseId:    goods.StorehouseId,
3785
+				IsCheck:         1,
3786
+			}
3787
+			if orgID == 9671 || orgID == 10265 {
3788
+				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
3789
+				cancelStockInfo.Price = goodsInfo.PackingPrice
3790
+			}
3791
+
3792
+			err := tx.Create(&cancelStockInfo).Error
3793
+			if err != nil {
3794
+				return err
3795
+			}
3796
+
3797
+			cancelInfo, _ := GetLastCancelStockInfoByGoodId(goods.GoodId)
3798
+
3799
+			flow := models.VmStockFlow{
3800
+				WarehousingId:           warehouse.ID,
3801
+				GoodId:                  goods.GoodId,
3802
+				Number:                  warehouse.Number,
3803
+				LicenseNumber:           warehouse.LicenseNumber,
3804
+				Count:                   out_count - out_count_one - count,
3805
+				UserOrgId:               orgID,
3806
+				PatientId:               patient_id,
3807
+				SystemTime:              record_time,
3808
+				ConsumableType:          7,
3809
+				IsSys:                   1,
3810
+				WarehousingOrder:        "",
3811
+				WarehouseOutId:          lastOut.WarehouseOutId,
3812
+				WarehouseOutOrderNumber: lastOut.WarehouseOutOrderNumber,
3813
+				IsEdit:                  0,
3814
+				CancelStockId:           cancel.ID,
3815
+				CancelOrderNumber:       cancel.OrderNumber,
3816
+				Manufacturer:            manufacturer.ID,
3817
+				Dealer:                  0,
3818
+				Creator:                 warehouseOut.Creater,
3819
+				UpdateCreator:           0,
3820
+				Status:                  1,
3821
+				Ctime:                   time.Now().Unix(),
3822
+				Mtime:                   0,
3823
+				Price:                   warehouse.PackingPrice,
3824
+				WarehousingDetailId:     warehouse.ID,
3825
+				WarehouseOutDetailId:    lastOut.ID,
3826
+				CancelOutDetailId:       cancelInfo.ID,
3827
+				ProductDate:             warehouse.ProductDate,
3828
+				ExpireDate:              warehouse.ExpiryDate,
3829
+				StorehouseId:            goods.StorehouseId,
3830
+				BuyPrice:                warehouse.Price,
3831
+				ProjectId:               goods.ProjectId,
3832
+				OverCount:               sum_count,
3833
+				RegisterNumber:          warehouse.RegisterNumber,
3834
+			}
3835
+			if orgID == 9671 || orgID == 10265 {
3836
+				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
3837
+				flow.Price = goodsInfo.PackingPrice
3838
+				flow.BuyPrice = goodsInfo.BuyPrice
3839
+			}
3840
+
3841
+			err = tx.Create(&flow).Error
3842
+			if err != nil {
3843
+				return err
3844
+			}
3845
+		}
3846
+
3847
+		details := models.BloodAutomaticReduceDetail{
3848
+			WarehouseOutId:          lastOut.ID,
3849
+			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
3850
+			PatientId:               patient_id,
3851
+			Ctime:                   time.Now().Unix(),
3852
+			Mtime:                   time.Now().Unix(),
3853
+			Status:                  1,
3854
+			RecordTime:              record_time,
3855
+			OrgId:                   orgID,
3856
+			GoodId:                  goods.GoodId,
3857
+			GoodTypeId:              goods.GoodTypeId,
3858
+			Count:                   count,
3859
+			ProjectId:               goods.ProjectId,
3860
+			StorehouseId:            goods.StorehouseId,
3861
+		}
3862
+
3863
+		////查询该耗材已经出库的数量
3864
+		_, errcode := GetAutoMaticReduceDetailTwenty(orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId)
3865
+		if errcode == gorm.ErrRecordNotFound {
3866
+
3867
+			err := tx.Create(&details).Error
3868
+			if err != nil {
3869
+				return err
3870
+			}
3871
+		} else if errcode == nil {
3872
+
3873
+			detail := models.BloodAutomaticReduceDetail{}
3874
+			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
3875
+			if err != nil {
3876
+				return err
3877
+			}
3878
+
3879
+			err = tx.Create(&detail).Error
3880
+			if err != nil {
3881
+				return err
3882
+			}
3883
+		}
3884
+
3885
+		return nil
3886
+	} else {
3887
+
3888
+		// 当刚批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
3889
+		warehouse.StockCount = 0
3890
+		warehouse.Mtime = time.Now().Unix()
3891
+
3892
+		err := tx.Save(&warehouse).Error
3893
+		if err != nil {
3894
+			return err
3895
+		}
3896
+		var info []*models.WarehousingInfo
3897
+		err = tx.Where("good_id = ? and org_id = ? and is_check =1 and status= 1 and stock_count > 0 and storehouse_id = ?", goods.GoodId, orgID, goods.StorehouseId).Find(&info).Error
3898
+		var sum_count int64
3899
+		for _, item := range info {
3900
+			sum_count += item.StockCount
3901
+		}
3902
+		warehouseOutInfo := &models.WarehouseOutInfo{
3903
+			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
3904
+			WarehouseOutId:          warehouseOut.ID,
3905
+			WarehouseInfotId:        warehouse.ID,
3906
+			Status:                  1,
3907
+			Ctime:                   time.Now().Unix(),
3908
+			Remark:                  warehouse.Remark,
3909
+			OrgId:                   orgID,
3910
+			Type:                    1,
3911
+			Manufacturer:            warehouse.Manufacturer,
3912
+			Dealer:                  warehouse.Dealer,
3913
+			IsSys:                   1,
3914
+			SysRecordTime:           record_time,
3915
+			GoodTypeId:              goods.GoodTypeId,
3916
+			GoodId:                  goods.GoodId,
3917
+			PatientId:               patient_id,
3918
+			Number:                  warehouse.Number,
3919
+			LicenseNumber:           warehouse.LicenseNumber,
3920
+			Price:                   warehouse.PackingPrice,
3921
+			ExpiryDate:              warehouse.ExpiryDate,
3922
+			ProductDate:             warehouse.ProductDate,
3923
+			ProjectId:               goods.ProjectId,
3924
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
3925
+			StorehouseId:            goods.StorehouseId,
3926
+			IsCheck:                 1,
3927
+			OverCount:               sum_count,
3928
+			RegisterNumber:          warehouse.RegisterNumber,
3929
+		}
3930
+		warehouseOutInfo.Count = stock_number
3931
+		if orgID == 9671 || orgID == 10265 {
3932
+			goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
3933
+			warehouseOutInfo.Price = goodsInfo.PackingPrice
3934
+		}
3935
+		_, errcodes := GetWarehouseOutInfoIsExistOne(goods.GoodId, patient_id, record_time, goods.ProjectId)
3936
+
3937
+		if errcodes == gorm.ErrRecordNotFound {
3938
+
3939
+			errors := tx.Create(warehouseOutInfo).Error
3940
+			if errors != nil {
3941
+				return errors
3942
+			}
3943
+		} else if errcodes == nil {
3944
+			goods.Count = deliver_number - stock_number
3945
+			//更新数量为  该批次剩余数量  + 还有未出的数量
3946
+			warehouseOutInfo.Count = stock_number
3947
+			outInfoOne, _ := GetWarehouseOutInfoIsExistTwo(goods.GoodId, patient_id, record_time, goods.ProjectId)
3948
+			if count != outInfoOne.Count {
3949
+
3950
+				outInfo := models.WarehouseOutInfo{}
3951
+				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
3952
+				if err != nil {
3953
+					return err
3954
+				}
3955
+			}
3956
+
3957
+		}
3958
+		lastOut, _ := FindWarehouseOutInfoByPatientId(patient_id, record_time, goods.GoodId, orgID)
3959
+		//查询该该批次已经出库的数据
3960
+		flowGood, _ := GetStockFlowIsBatchNumber(warehouse.ID, patient_id, record_time, goods.GoodId)
3961
+		var out_count int64
3962
+		var out_count_one int64
3963
+		for _, item := range flowGood {
3964
+			out_count += item.Count
3965
+		}
3966
+		flowGoodTwo, _ := GetStockFlowIsBatchNumberThree(patient_id, record_time, goods.GoodId)
3967
+		for _, item := range flowGoodTwo {
3968
+			out_count_one += item.Count
3969
+		}
3970
+		//如果出库数量 大于 历史出库数据 新增1条流水
3971
+		if count > out_count-out_count_one {
3972
+			flow := models.VmStockFlow{
3973
+				WarehouseOutId:          warehouseOut.ID,
3974
+				WarehousingId:           warehouse.ID,
3975
+				GoodId:                  goods.GoodId,
3976
+				Number:                  warehouse.Number,
3977
+				ProductDate:             warehouse.ProductDate,
3978
+				ExpireDate:              warehouse.ExpiryDate,
3979
+				Count:                   stock_number,
3980
+				Price:                   warehouse.PackingPrice,
3981
+				Status:                  1,
3982
+				Ctime:                   time.Now().Unix(),
3983
+				UserOrgId:               orgID,
3984
+				Manufacturer:            warehouse.Manufacturer,
3985
+				Dealer:                  warehouse.Dealer,
3986
+				LicenseNumber:           warehouse.LicenseNumber,
3987
+				IsEdit:                  2,
3988
+				Creator:                 warehouseOut.Creater,
3989
+				SystemTime:              record_time,
3990
+				ConsumableType:          3,
3991
+				WarehouseOutDetailId:    lastOut.ID,
3992
+				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
3993
+				IsSys:                   1,
3994
+				PatientId:               patient_id,
3995
+				ProjectId:               goods.ProjectId,
3996
+				SupplyWarehouseId:       warehouse.SupplyWarehouseId,
3997
+				StorehouseId:            goods.StorehouseId,
3998
+				OverCount:               sum_count,
3999
+				BuyPrice:                warehouse.Price,
4000
+				RegisterNumber:          warehouse.RegisterNumber,
4001
+			}
4002
+			if orgID == 9671 || orgID == 10265 {
4003
+				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
4004
+				flow.Price = goodsInfo.PackingPrice
4005
+				flow.BuyPrice = goodsInfo.BuyPrice
4006
+			}
4007
+
4008
+			err := tx.Create(&flow).Error
4009
+			if err != nil {
4010
+				return err
4011
+			}
4012
+		}
4013
+		//退库
4014
+		if count < out_count-out_count_one {
4015
+			operation_time := time.Now().Unix()
4016
+
4017
+			//创建退库单
4018
+			timeStr := time.Now().Format("2006-01-02")
4019
+			timeArr := strings.Split(timeStr, "-")
4020
+			total, _ := FindAllCancelStockTotal(orgID)
4021
+			total = total + 1
4022
+			orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
4023
+
4024
+			cancelStock := models.CancelStock{
4025
+				OrderNumber:  orderNumber,
4026
+				OperaTime:    operation_time,
4027
+				OrgId:        orgID,
4028
+				Creater:      warehouseOut.Creater,
4029
+				Ctime:        time.Now().Unix(),
4030
+				Status:       1,
4031
+				ReturnTime:   record_time,
4032
+				Type:         1,
4033
+				StorehouseId: goods.StorehouseId,
4034
+				IsCheck:      1,
4035
+			}
4036
+			_, msgerrkonde := GetCancelStockDetailByOrderNumberOne(record_time, orgID)
4037
+			if msgerrkonde == gorm.ErrRecordNotFound {
4038
+
4039
+				err := tx.Create(&cancelStock).Error
4040
+				if err != nil {
4041
+					return err
4042
+				}
4043
+			}
4044
+
4045
+			cancel, _ := GetLastCancelStockById(orgID)
4046
+
4047
+			manufacturer, _ := GetManufactureById(warehouse.Manufacturer)
4048
+			deaerler, _ := GetDealerById(warehouse.Dealer)
4049
+			cancelStockInfo := models.CancelStockInfo{
4050
+				GoodId:          goods.GoodId,
4051
+				CancelStockId:   cancel.ID,
4052
+				GoodTypeId:      goods.GoodTypeId,
4053
+				Count:           out_count - out_count_one - count,
4054
+				Price:           warehouse.PackingPrice,
4055
+				Total:           0,
4056
+				ProductDate:     warehouse.ProductDate,
4057
+				ExpiryDate:      warehouse.ExpiryDate,
4058
+				Ctime:           time.Now().Unix(),
4059
+				Status:          1,
4060
+				OrgId:           orgID,
4061
+				OrderNumber:     cancel.OrderNumber,
4062
+				Type:            0,
4063
+				Dealer:          deaerler.DealerName,
4064
+				Manufacturer:    manufacturer.ManufacturerName,
4065
+				Number:          warehouse.Number,
4066
+				RegisterAccount: "",
4067
+				Remark:          "",
4068
+				WarehouseInfoId: warehouse.ID,
4069
+				PatientId:       patient_id,
4070
+				RecordDate:      record_time,
4071
+				StorehouseId:    goods.StorehouseId,
4072
+				IsCheck:         1,
4073
+			}
4074
+			if orgID == 9671 || orgID == 10265 {
4075
+				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
4076
+				cancelStockInfo.Price = goodsInfo.PackingPrice
4077
+			}
4078
+
4079
+			err := tx.Create(&cancelStockInfo).Error
4080
+			if err != nil {
4081
+				return err
4082
+			}
4083
+
4084
+			cancelInfo, _ := GetLastCancelStockInfoByGoodId(goods.GoodId)
4085
+
4086
+			flow := models.VmStockFlow{
4087
+				WarehousingId:           warehouse.ID,
4088
+				GoodId:                  goods.GoodId,
4089
+				Number:                  warehouse.Number,
4090
+				LicenseNumber:           warehouse.LicenseNumber,
4091
+				Count:                   out_count - count,
4092
+				UserOrgId:               orgID,
4093
+				PatientId:               patient_id,
4094
+				SystemTime:              record_time,
4095
+				ConsumableType:          7,
4096
+				IsSys:                   1,
4097
+				WarehousingOrder:        "",
4098
+				WarehouseOutId:          lastOut.WarehouseOutId,
4099
+				WarehouseOutOrderNumber: lastOut.WarehouseOutOrderNumber,
4100
+				IsEdit:                  0,
4101
+				CancelStockId:           cancel.ID,
4102
+				CancelOrderNumber:       cancel.OrderNumber,
4103
+				Manufacturer:            manufacturer.ID,
4104
+				Dealer:                  0,
4105
+				Creator:                 warehouseOut.Creater,
4106
+				UpdateCreator:           0,
4107
+				Status:                  1,
4108
+				Ctime:                   time.Now().Unix(),
4109
+				Mtime:                   0,
4110
+				Price:                   warehouse.PackingPrice,
4111
+				WarehousingDetailId:     warehouse.ID,
4112
+				WarehouseOutDetailId:    lastOut.ID,
4113
+				CancelOutDetailId:       cancelInfo.ID,
4114
+				ProductDate:             warehouse.ProductDate,
4115
+				ExpireDate:              warehouse.ExpiryDate,
4116
+				StorehouseId:            goods.StorehouseId,
4117
+				BuyPrice:                warehouse.Price,
4118
+				ProjectId:               goods.ProjectId,
4119
+				OverCount:               sum_count,
4120
+				RegisterNumber:          warehouse.RegisterNumber,
4121
+			}
4122
+			if orgID == 9671 || orgID == 10265 {
4123
+				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
4124
+				flow.Price = goodsInfo.PackingPrice
4125
+				flow.BuyPrice = goodsInfo.BuyPrice
4126
+			}
4127
+			err = tx.Create(&flow).Error
4128
+			if err != nil {
4129
+				return err
4130
+			}
4131
+		}
4132
+
4133
+		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
4134
+		goods.Count = deliver_number - stock_number
4135
+
4136
+		ConsumablesGoodDelivery(orgID, patient_id, record_time, goods, warehouseOut, count)
4137
+
4138
+	}
4139
+
4140
+	return nil
4141
+}

+ 1 - 1
service/patientmanage_service.go Näytä tiedosto

1055
 	if projectid > 0 {
1055
 	if projectid > 0 {
1056
 		db = db.Where("x.project_id = ?", projectid)
1056
 		db = db.Where("x.project_id = ?", projectid)
1057
 	}
1057
 	}
1058
-	err = db.Group("x.id").Select("x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,x.status,x.created_time,x.updated_time,r.range_type,r.range_min,r.range_max,r.range_value,r.range_options,r.unit").Joins("left join xt_inspection_reference as r on (r.item_id = x.item_id AND r.org_id > 0) OR ( x.item_id = r.id AND r.org_id = 0)   ").Scan(&inspection).Error
1058
+	err = db.Group("x.id").Select("x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,x.status,x.created_time,x.updated_time,r.range_type,r.range_min,r.range_max,r.range_value,r.range_options,r.unit").Joins("left join xt_inspection_reference as r on (r.item_id = x.item_id AND r.org_id = x.org_id) OR ( x.item_id = r.id AND r.org_id = 0)   ").Scan(&inspection).Error
1059
 	return inspection, err
1059
 	return inspection, err
1060
 }
1060
 }
1061
 
1061
 

+ 60 - 61
service/pharmacy_service.go Näytä tiedosto

30
 	XTWriteDB().Create(&tmp)
30
 	XTWriteDB().Create(&tmp)
31
 }
31
 }
32
 
32
 
33
-//
34
 func SavePharmacy() (err error) {
33
 func SavePharmacy() (err error) {
35
 	var advice_info []*models.HisDoctorAdviceInfo
34
 	var advice_info []*models.HisDoctorAdviceInfo
36
 	err = XTReadDB().Raw("select * from xt_doctor_advice where id > 21780 and id < 21790").Scan(&advice_info).Error
35
 	err = XTReadDB().Raw("select * from xt_doctor_advice where id > 21780 and id < 21790").Scan(&advice_info).Error
40
 	return nil
39
 	return nil
41
 }
40
 }
42
 
41
 
43
-//查询药房中某一天的患者人数,is_medicine:0未发,1已发(改)
42
+// 查询药房中某一天的患者人数,is_medicine:0未发,1已发(改)
44
 func GetTodayPharmacy(stime, etime, orgid, is_medicine int64) (num int, err error) {
43
 func GetTodayPharmacy(stime, etime, orgid, is_medicine int64) (num int, err error) {
45
 	//orgid = 9675
44
 	//orgid = 9675
46
 	InitDrugidIsNil(orgid, stime, etime)
45
 	InitDrugidIsNil(orgid, stime, etime)
75
 
74
 
76
 }
75
 }
77
 
76
 
78
-//(改)
77
+// (改)
79
 func GetTodayDrug(stime, etime, orgid, is_medicine int64, keyword string) (list []*models.TmpPatient, err error) {
78
 func GetTodayDrug(stime, etime, orgid, is_medicine int64, keyword string) (list []*models.TmpPatient, err error) {
80
 	InitDrugidIsNil(orgid, stime, etime)
79
 	InitDrugidIsNil(orgid, stime, etime)
81
 	//病人
80
 	//病人
150
 
149
 
151
 }
150
 }
152
 
151
 
153
-//查询患者(改)
152
+// 查询患者(改)
154
 func GetManyUsers(tmp []int64) (list []*models.TmpPatient, err error) {
153
 func GetManyUsers(tmp []int64) (list []*models.TmpPatient, err error) {
155
 
154
 
156
 	for i := 0; i < len(tmp); i++ {
155
 	for i := 0; i < len(tmp); i++ {
167
 	return
166
 	return
168
 }
167
 }
169
 
168
 
170
-//查询患者当天时间段中的药,is_medicine:0未发,1已发(改)
169
+// 查询患者当天时间段中的药,is_medicine:0未发,1已发(改)
171
 func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (pp []*models.PharmacyContent, err error) {
170
 func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (pp []*models.PharmacyContent, err error) {
172
 	InitDrugidIsNil(orgid, stime, etime)
171
 	InitDrugidIsNil(orgid, stime, etime)
173
 	var tmp []*models.HisDoctorAdviceInfoL
172
 	var tmp []*models.HisDoctorAdviceInfoL
230
 	return
229
 	return
231
 }
230
 }
232
 
231
 
233
-//获取创建者姓名(改)
232
+// 获取创建者姓名(改)
234
 func GetAdminUserName(doctor, orgid int64) string {
233
 func GetAdminUserName(doctor, orgid int64) string {
235
 	var tmp models.VmUserAdminRole
234
 	var tmp models.VmUserAdminRole
236
 	XTReadDB().Model(&models.VmUserAdminRole{}).Where("admin_user_id = ? and org_id = ? and status = 1", doctor, orgid).Find(&tmp)
235
 	XTReadDB().Model(&models.VmUserAdminRole{}).Where("admin_user_id = ? and org_id = ? and status = 1", doctor, orgid).Find(&tmp)
237
 	return tmp.UserName
236
 	return tmp.UserName
238
 }
237
 }
239
 
238
 
240
-//查询该机构的药房配置,true: 通过药房发药,false:不通过药房发药。如果没有该机构的信息则生成一条数据
239
+// 查询该机构的药房配置,true: 通过药房发药,false:不通过药房发药。如果没有该机构的信息则生成一条数据
241
 func GetOrgIdPharmacyConfig(orgid int64) bool {
240
 func GetOrgIdPharmacyConfig(orgid int64) bool {
242
 	var total int
241
 	var total int
243
 	var tmp_pharmacy models.PharmacyConfig
242
 	var tmp_pharmacy models.PharmacyConfig
263
 	}
262
 	}
264
 }
263
 }
265
 
264
 
266
-//修改该机构的药房配置
265
+// 修改该机构的药房配置
267
 func ModifyPharmacyConfig(orgid, isopen int64) (err error) {
266
 func ModifyPharmacyConfig(orgid, isopen int64) (err error) {
268
 	if isopen == 1 || isopen == 2 {
267
 	if isopen == 1 || isopen == 2 {
269
 		err = XTWriteDB().Model(&models.PharmacyConfig{}).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{
268
 		err = XTWriteDB().Model(&models.PharmacyConfig{}).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{
276
 	return
275
 	return
277
 }
276
 }
278
 
277
 
279
-//查询该药品是否通过药房发药.0否;1是
278
+// 查询该药品是否通过药房发药.0否;1是
280
 func DrugAllocation(drug_id int64) (is_pharmacy int64, err error) {
279
 func DrugAllocation(drug_id int64) (is_pharmacy int64, err error) {
281
 	tmp := models.BaseDrugLib{}
280
 	tmp := models.BaseDrugLib{}
282
 	err = XTReadDB().Model(&models.BaseDrugLib{}).Where("id = ?", drug_id).Find(&tmp).Error
281
 	err = XTReadDB().Model(&models.BaseDrugLib{}).Where("id = ?", drug_id).Find(&tmp).Error
283
 	return tmp.IsPharmacy, err
282
 	return tmp.IsPharmacy, err
284
 }
283
 }
285
 
284
 
286
-//根据id查询该药是否发药
285
+// 根据id查询该药是否发药
287
 func MedicineState(id int64) (is_medicine models.HisDoctorAdviceInfoL, err error) {
286
 func MedicineState(id int64) (is_medicine models.HisDoctorAdviceInfoL, err error) {
288
 	tmp := models.HisDoctorAdviceInfoL{}
287
 	tmp := models.HisDoctorAdviceInfoL{}
289
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where("id = ?", id).Find(&tmp).Error
288
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where("id = ?", id).Find(&tmp).Error
290
 	return tmp, err
289
 	return tmp, err
291
 }
290
 }
292
 
291
 
293
-//发药明细列表(
292
+// 发药明细列表(
294
 func DispensingDetailsList(stime, etime, orgid, page, limit int64, keyword string) (dislist []*models.DispensingList, total int64, err error) {
293
 func DispensingDetailsList(stime, etime, orgid, page, limit int64, keyword string) (dislist []*models.DispensingList, total int64, err error) {
295
 	var fenye []*models.Pharmary //分页用的
294
 	var fenye []*models.Pharmary //分页用的
296
 	offset := (page - 1) * limit
295
 	offset := (page - 1) * limit
329
 	return
328
 	return
330
 }
329
 }
331
 
330
 
332
-//处方详情//////////////////////
331
+// 处方详情//////////////////////
333
 func PrescriptionDetails(patient_id, record_date, orgid int64) (pre []*models.PrescripDetails, err error) {
332
 func PrescriptionDetails(patient_id, record_date, orgid int64) (pre []*models.PrescripDetails, err error) {
334
 	var tmp []*models.HisDoctorAdviceInfoL
333
 	var tmp []*models.HisDoctorAdviceInfoL
335
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
334
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
371
 	return
370
 	return
372
 }
371
 }
373
 
372
 
374
-//查询病人的his id
373
+// 查询病人的his id
375
 func GetHisID(prescription_id, orgid int64) (id int64) {
374
 func GetHisID(prescription_id, orgid int64) (id int64) {
376
 	var tmp models.HisPrintPrescription
375
 	var tmp models.HisPrintPrescription
377
 	XTReadDB().Model(&models.HisPrintPrescription{}).Where("id = ?", prescription_id).Find(&tmp)
376
 	XTReadDB().Model(&models.HisPrintPrescription{}).Where("id = ?", prescription_id).Find(&tmp)
380
 	return fin.ID
379
 	return fin.ID
381
 }
380
 }
382
 
381
 
383
-//根据药品id获取药品信息
382
+// 根据药品id获取药品信息
384
 func GetDrugNameTX(id int64, tx *gorm.DB) (tmp models.SpBaseDrug, err error) {
383
 func GetDrugNameTX(id int64, tx *gorm.DB) (tmp models.SpBaseDrug, err error) {
385
 	err = tx.Model(&models.SpBaseDrug{}).Where("id = ? and status = 1", id).Find(&tmp).Error
384
 	err = tx.Model(&models.SpBaseDrug{}).Where("id = ? and status = 1", id).Find(&tmp).Error
386
 	return
385
 	return
392
 	return
391
 	return
393
 }
392
 }
394
 
393
 
395
-//查询药品(使用keyword)
394
+// 查询药品(使用keyword)
396
 func GetManyDrugs(orgid int64, keyword string) (map[int64]models.PharmacyBaseDrug, error) {
395
 func GetManyDrugs(orgid int64, keyword string) (map[int64]models.PharmacyBaseDrug, error) {
397
 	var tmp []*models.PharmacyBaseDrug
396
 	var tmp []*models.PharmacyBaseDrug
398
 	tt := make(map[int64]models.PharmacyBaseDrug)
397
 	tt := make(map[int64]models.PharmacyBaseDrug)
403
 	return tt, err
402
 	return tt, err
404
 }
403
 }
405
 
404
 
406
-//查询(
405
+// 查询(
407
 func GetTodayMedicine(stime, etime, orgid, is_medicine int64, keyword string) (finlly []*models.ListOfDrugs, err error) {
406
 func GetTodayMedicine(stime, etime, orgid, is_medicine int64, keyword string) (finlly []*models.ListOfDrugs, err error) {
408
 	InitDrugidIsNil(orgid, stime, etime)
407
 	InitDrugidIsNil(orgid, stime, etime)
409
 	var tmp []*models.TmpLLL
408
 	var tmp []*models.TmpLLL
474
 	return
473
 	return
475
 }
474
 }
476
 
475
 
477
-//根据药品id获取药品规格(
476
+// 根据药品id获取药品规格(
478
 func FindDrugSpecifications(id int64) (name, specifications string) {
477
 func FindDrugSpecifications(id int64) (name, specifications string) {
479
 	var tmp models.PharmacyBaseDrug
478
 	var tmp models.PharmacyBaseDrug
480
 	XTReadDB().Model(&models.PharmacyBaseDrug{}).Where("id = ?", id).Find(&tmp)
479
 	XTReadDB().Model(&models.PharmacyBaseDrug{}).Where("id = ?", id).Find(&tmp)
483
 	return
482
 	return
484
 }
483
 }
485
 
484
 
486
-//根据药品id获取当前药品出库仓库的库存数量
485
+// 根据药品id获取当前药品出库仓库的库存数量
487
 func GetInventoryQuantity(orgid, drugid int64) (number string, err error) {
486
 func GetInventoryQuantity(orgid, drugid int64) (number string, err error) {
488
 	//获取药品拆零数量
487
 	//获取药品拆零数量
489
 	var phar models.PharmacyBaseDrug
488
 	var phar models.PharmacyBaseDrug
516
 	return
515
 	return
517
 }
516
 }
518
 
517
 
519
-//获取该药品的病人信息(
518
+// 获取该药品的病人信息(
520
 func FindMedicationList(orgid, drug_id, stime, etime, is_medicine int64) (pp []*models.PatientInformation, err error) { ///////////////
519
 func FindMedicationList(orgid, drug_id, stime, etime, is_medicine int64) (pp []*models.PatientInformation, err error) { ///////////////
521
 	InitDrugidIsNil(orgid, stime, etime)
520
 	InitDrugidIsNil(orgid, stime, etime)
522
 	var tmp []*models.HisDoctorAdviceInfoL
521
 	var tmp []*models.HisDoctorAdviceInfoL
566
 	return
565
 	return
567
 }
566
 }
568
 
567
 
569
-//患者发药按钮点击(
568
+// 患者发药按钮点击(
570
 func DispensingMedicine(orgid, patient_id, stime, etime, creater int64) (err error) {
569
 func DispensingMedicine(orgid, patient_id, stime, etime, creater int64) (err error) {
571
 	//开事务
570
 	//开事务
572
 	tx := XTWriteDB().Begin()
571
 	tx := XTWriteDB().Begin()
688
 	return
687
 	return
689
 }
688
 }
690
 
689
 
691
-//患者退药按钮点击
690
+// 患者退药按钮点击
692
 func DrugWithdrawal(orgid, patient_id, stime, etime, creater int64) (err error) {
691
 func DrugWithdrawal(orgid, patient_id, stime, etime, creater int64) (err error) {
693
 	//开事务
692
 	//开事务
694
 	tx := XTWriteDB().Begin()
693
 	tx := XTWriteDB().Begin()
829
 	return
828
 	return
830
 }
829
 }
831
 
830
 
832
-//获取患者名称
831
+// 获取患者名称
833
 func FindUserName(patient_id int64) (name string) {
832
 func FindUserName(patient_id int64) (name string) {
834
 	var tmp models.GetHisName
833
 	var tmp models.GetHisName
835
 	XTReadDB().Model(&models.GetHisName{}).Where("id = ?", patient_id).Find(&tmp)
834
 	XTReadDB().Model(&models.GetHisName{}).Where("id = ?", patient_id).Find(&tmp)
837
 	return
836
 	return
838
 }
837
 }
839
 
838
 
840
-//获取药品名称
839
+// 获取药品名称
841
 func FindDrugsName(drug_id int64) (name string) {
840
 func FindDrugsName(drug_id int64) (name string) {
842
 	var tmp models.Drug
841
 	var tmp models.Drug
843
 	XTReadDB().Model(&models.Drug{}).Where("id = ?", drug_id).Find(&tmp)
842
 	XTReadDB().Model(&models.Drug{}).Where("id = ?", drug_id).Find(&tmp)
845
 	return
844
 	return
846
 }
845
 }
847
 
846
 
848
-//药品发药按钮点击(
847
+// 药品发药按钮点击(
849
 func MedicineDeparture(ids string, creater, orgid int64) (err error) {
848
 func MedicineDeparture(ids string, creater, orgid int64) (err error) {
850
 	//开事务
849
 	//开事务
851
 	tx := XTWriteDB().Begin()
850
 	tx := XTWriteDB().Begin()
995
 	return
994
 	return
996
 }
995
 }
997
 
996
 
998
-//获取领药人姓名(
997
+// 获取领药人姓名(
999
 func GetUserAdminName(id, orgID int64) string {
998
 func GetUserAdminName(id, orgID int64) string {
1000
 	var tmp models.XTSgjUserAdminRole
999
 	var tmp models.XTSgjUserAdminRole
1001
 	XTReadDB().Model(&models.XTSgjUserAdminRole{}).Where("admin_user_id = ? and org_id = ?", id, orgID).Find(&tmp)
1000
 	XTReadDB().Model(&models.XTSgjUserAdminRole{}).Where("admin_user_id = ? and org_id = ?", id, orgID).Find(&tmp)
1002
 	return tmp.UserName
1001
 	return tmp.UserName
1003
 }
1002
 }
1004
 
1003
 
1005
-//根据id查询是否已发药,true已发药,false未发药gai
1004
+// 根据id查询是否已发药,true已发药,false未发药gai
1006
 func GiveTheMedicine(id int64) bool {
1005
 func GiveTheMedicine(id int64) bool {
1007
 	var xue models.PharmacyDoctorAdvice
1006
 	var xue models.PharmacyDoctorAdvice
1008
 	XTReadDB().Model(&models.PharmacyDoctorAdvice{}).Where("id = ?", id).Find(&xue)
1007
 	XTReadDB().Model(&models.PharmacyDoctorAdvice{}).Where("id = ?", id).Find(&xue)
1012
 	return false
1011
 	return false
1013
 }
1012
 }
1014
 
1013
 
1015
-//查询改组中的药品是否包含已发药的,true已发药,false未发药
1014
+// 查询改组中的药品是否包含已发药的,true已发药,false未发药
1016
 func GiveGroupMedicine(orgid, groupNo int64) bool {
1015
 func GiveGroupMedicine(orgid, groupNo int64) bool {
1017
 	var total int
1016
 	var total int
1018
 	XTReadDB().Model(&models.DoctorAdvice{}).Where("user_org_id = ? and groupno = ? and status = 1 and is_medicine = 1", orgid, groupNo).Count(&total)
1017
 	XTReadDB().Model(&models.DoctorAdvice{}).Where("user_org_id = ? and groupno = ? and status = 1 and is_medicine = 1", orgid, groupNo).Count(&total)
1022
 	return false
1021
 	return false
1023
 }
1022
 }
1024
 
1023
 
1025
-//查询处方中是否包含已发药的
1024
+// 查询处方中是否包含已发药的
1026
 func GiveChuMedicine(id int64) bool {
1025
 func GiveChuMedicine(id int64) bool {
1027
 	var total int
1026
 	var total int
1028
 	XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where("prescription_id = ? and status = 1 and is_medicine = 1", id).Count(&total)
1027
 	XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where("prescription_id = ? and status = 1 and is_medicine = 1", id).Count(&total)
1032
 	return false
1031
 	return false
1033
 }
1032
 }
1034
 
1033
 
1035
-//根据处方id查找该处方中是否存在已发药的药品
1034
+// 根据处方id查找该处方中是否存在已发药的药品
1036
 func IsChuIssuedDrugs(prescription_id int64) bool {
1035
 func IsChuIssuedDrugs(prescription_id int64) bool {
1037
 	var total int
1036
 	var total int
1038
 	XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where("prescription_id = ? and status = 1 and is_medicine = 1", prescription_id).Count(&total)
1037
 	XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where("prescription_id = ? and status = 1 and is_medicine = 1", prescription_id).Count(&total)
1042
 	return false
1041
 	return false
1043
 }
1042
 }
1044
 
1043
 
1045
-//判断该药品是否通过药房管理出库,true是,false否
1046
-//id 药品id,org_id 机构id
1044
+// 判断该药品是否通过药房管理出库,true是,false否
1045
+// id 药品id,org_id 机构id
1047
 func IsPharmacyDelivery(id, org_id int64) bool {
1046
 func IsPharmacyDelivery(id, org_id int64) bool {
1048
 	//判断药品是否通过药房管理
1047
 	//判断药品是否通过药房管理
1049
 	var total01 int
1048
 	var total01 int
1057
 	return false
1056
 	return false
1058
 }
1057
 }
1059
 
1058
 
1060
-//判断机构是否通过药房管理出库
1059
+// 判断机构是否通过药房管理出库
1061
 func IsPharmacyConfig(orgid int64) (bo bool) {
1060
 func IsPharmacyConfig(orgid int64) (bo bool) {
1062
 	var total int
1061
 	var total int
1063
 	XTReadDB().Model(&models.PharmacyConfig{}).Where("user_org_id = ? and is_open = 1 and status = 1", orgid).Count(&total)
1062
 	XTReadDB().Model(&models.PharmacyConfig{}).Where("user_org_id = ? and is_open = 1 and status = 1", orgid).Count(&total)
1067
 	return false
1066
 	return false
1068
 }
1067
 }
1069
 
1068
 
1070
-//根据患者id和发药时间,获取医生的id和姓名
1069
+// 根据患者id和发药时间,获取医生的id和姓名
1071
 func GetDoctorIds(id, recordtime, orgid int64) (doctor_id int64, doctor_name string, err error) {
1070
 func GetDoctorIds(id, recordtime, orgid int64) (doctor_id int64, doctor_name string, err error) {
1072
 	var tmp []*models.TmpAdviceDoctor
1071
 	var tmp []*models.TmpAdviceDoctor
1073
 	//var tmp []int64
1072
 	//var tmp []int64
1091
 	return dataString
1090
 	return dataString
1092
 }
1091
 }
1093
 
1092
 
1094
-//封装扣减库存
1093
+// 封装扣减库存
1095
 func FenStock(orgid, creater int64, v *models.HisDoctorAdviceInfo) (err error) {
1094
 func FenStock(orgid, creater int64, v *models.HisDoctorAdviceInfo) (err error) {
1096
 
1095
 
1097
 	err = HisDrugsDelivery(orgid, creater, v)
1096
 	err = HisDrugsDelivery(orgid, creater, v)
1118
 	return
1117
 	return
1119
 }
1118
 }
1120
 
1119
 
1121
-//封装查询药品库存是否足够
1120
+// 封装查询药品库存是否足够
1122
 func FenDrugInventory(item *models.HisDoctorAdviceInfo, orgid int64) bool {
1121
 func FenDrugInventory(item *models.HisDoctorAdviceInfo, orgid int64) bool {
1123
 	var total int64
1122
 	var total int64
1124
 	var prescribing_number_total int64
1123
 	var prescribing_number_total int64
1233
 	return false, err
1232
 	return false, err
1234
 }
1233
 }
1235
 
1234
 
1236
-//判断药品是否零用
1235
+// 判断药品是否零用
1237
 func PettyCash(id int64) bool {
1236
 func PettyCash(id int64) bool {
1238
 	drug := models.XtBaseDrug{}
1237
 	drug := models.XtBaseDrug{}
1239
 	XTReadDB().Model(&drug).Where("id = ? and status = 1", id).Find(&drug)
1238
 	XTReadDB().Model(&drug).Where("id = ? and status = 1", id).Find(&drug)
1243
 	return false
1242
 	return false
1244
 }
1243
 }
1245
 
1244
 
1246
-//初始化
1245
+// 初始化
1247
 func InitDrugidIsNil(orgid, stime, etime int64) {
1246
 func InitDrugidIsNil(orgid, stime, etime int64) {
1248
 	var advice []*models.DoctorAdvice
1247
 	var advice []*models.DoctorAdvice
1249
 	XTReadDB().Model(&models.DoctorAdvice{}).Where("drug_id = 0 and user_org_id = ? and status = 1 and created_time >= ? and created_time <= ?", orgid, stime, etime).Find(&advice)
1248
 	XTReadDB().Model(&models.DoctorAdvice{}).Where("drug_id = 0 and user_org_id = ? and status = 1 and created_time >= ? and created_time <= ?", orgid, stime, etime).Find(&advice)
1250
 	for _, v := range advice {
1249
 	for _, v := range advice {
1251
-		XTWriteDB().Exec("update xt_doctor_advice set drug_id = (select id from xt_base_drug where drug_name = ? and org_id = ?) where id = ?", v.AdviceName, v.UserOrgId, v.ID)
1250
+		XTWriteDB().Exec("update xt_doctor_advice set drug_id = (select id from xt_base_drug where drug_name = ? and org_id = ? and status = 1 limit 1) where id = ?", v.AdviceName, v.UserOrgId, v.ID)
1252
 	}
1251
 	}
1253
 }
1252
 }
1254
 
1253
 
1255
-//改变处方状态(发药
1254
+// 改变处方状态(发药
1256
 func ChangeHisPrescription(tmp []int64) (err error) {
1255
 func ChangeHisPrescription(tmp []int64) (err error) {
1257
 	var advice_info []*models.HisDoctorAdviceInfo
1256
 	var advice_info []*models.HisDoctorAdviceInfo
1258
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfo{}).Where("id in (?) and status = 1", tmp).Find(&advice_info).Error
1257
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfo{}).Where("id in (?) and status = 1", tmp).Find(&advice_info).Error
1279
 	return
1278
 	return
1280
 }
1279
 }
1281
 
1280
 
1282
-//改变处方状态(退药
1281
+// 改变处方状态(退药
1283
 func ChangeHisPrescriptionT(tmp []int64) (err error) {
1282
 func ChangeHisPrescriptionT(tmp []int64) (err error) {
1284
 	var advice_info []*models.HisDoctorAdviceInfo
1283
 	var advice_info []*models.HisDoctorAdviceInfo
1285
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfo{}).Where("id in (?) and status = 1", tmp).Find(&advice_info).Error
1284
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfo{}).Where("id in (?) and status = 1", tmp).Find(&advice_info).Error
1311
 	return
1310
 	return
1312
 }
1311
 }
1313
 
1312
 
1314
-//改变处方状态
1313
+// 改变处方状态
1315
 func ChangeHisPrescriptionid(id string) (err error) {
1314
 func ChangeHisPrescriptionid(id string) (err error) {
1316
 	var advice models.HisDoctorAdviceInfo
1315
 	var advice models.HisDoctorAdviceInfo
1317
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ? and status = 1", id).Find(&advice).Error
1316
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ? and status = 1", id).Find(&advice).Error
1331
 	return
1330
 	return
1332
 }
1331
 }
1333
 
1332
 
1334
-//获取药品规格
1333
+// 获取药品规格
1335
 func ReplacementDrugs(orgid int64, special bool) (list []*models.ReplacementDrugs, err error) {
1334
 func ReplacementDrugs(orgid int64, special bool) (list []*models.ReplacementDrugs, err error) {
1336
 	var g errgroup.Group
1335
 	var g errgroup.Group
1337
 	var lib []*models.BaseDrugLib
1336
 	var lib []*models.BaseDrugLib
1368
 	return
1367
 	return
1369
 }
1368
 }
1370
 
1369
 
1371
-//获取药品规格,不考虑特殊病
1370
+// 获取药品规格,不考虑特殊病
1372
 func ReplacementDrugsT(orgid int64) (list []*models.ReplacementDrugs, err error) {
1371
 func ReplacementDrugsT(orgid int64) (list []*models.ReplacementDrugs, err error) {
1373
 	var lib []*models.BaseDrugLib
1372
 	var lib []*models.BaseDrugLib
1374
 	err = readDb.Model(&models.BaseDrugLib{}).Where("org_id = ?  AND status = 1 and drug_status not like '%停用%' ", orgid).Find(&lib).Error
1373
 	err = readDb.Model(&models.BaseDrugLib{}).Where("org_id = ?  AND status = 1 and drug_status not like '%停用%' ", orgid).Find(&lib).Error
1390
 	return
1389
 	return
1391
 }
1390
 }
1392
 
1391
 
1393
-//根据药品id获取药品名字
1392
+// 根据药品id获取药品名字
1394
 func IdToDrugName(id int64) (name string) {
1393
 func IdToDrugName(id int64) (name string) {
1395
 	var lib models.BaseDrugLib
1394
 	var lib models.BaseDrugLib
1396
 	readDb.Model(&models.BaseDrugLib{}).Where("id = ?", id).Find(&lib)
1395
 	readDb.Model(&models.BaseDrugLib{}).Where("id = ?", id).Find(&lib)
1397
 	return lib.DrugName
1396
 	return lib.DrugName
1398
 }
1397
 }
1399
 
1398
 
1400
-//获取项目和耗材和套餐
1399
+// 获取项目和耗材和套餐
1401
 func ProjectConsumables3(orgid int64) (list []*models.DropDownList, err error) {
1400
 func ProjectConsumables3(orgid int64) (list []*models.DropDownList, err error) {
1402
 
1401
 
1403
 	var project []*models.XtHisProject
1402
 	var project []*models.XtHisProject
1439
 	return
1438
 	return
1440
 }
1439
 }
1441
 
1440
 
1442
-//获取项目和耗材
1441
+// 获取项目和耗材
1443
 func ProjectConsumables2(orgid int64, special bool) (list []*models.DropDownList, err error) {
1442
 func ProjectConsumables2(orgid int64, special bool) (list []*models.DropDownList, err error) {
1444
 
1443
 
1445
 	var project []*models.XtHisProject
1444
 	var project []*models.XtHisProject
1477
 	return
1476
 	return
1478
 }
1477
 }
1479
 
1478
 
1480
-//获取项目和耗材不考虑特殊病
1479
+// 获取项目和耗材不考虑特殊病
1481
 func ProjectConsumables2T(orgid int64) (list []*models.DropDownList, err error) {
1480
 func ProjectConsumables2T(orgid int64) (list []*models.DropDownList, err error) {
1482
 
1481
 
1483
 	var project []*models.XtHisProject
1482
 	var project []*models.XtHisProject
1507
 	return
1506
 	return
1508
 }
1507
 }
1509
 
1508
 
1510
-//查询药品
1509
+// 查询药品
1511
 func FindPatientDrug(orgid, patient_id, drugid, mode int64) bool {
1510
 func FindPatientDrug(orgid, patient_id, drugid, mode int64) bool {
1512
 	var total int
1511
 	var total int
1513
 	XTReadDB().Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and status = 1 and "+
1512
 	XTReadDB().Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and status = 1 and "+
1519
 	return false
1518
 	return false
1520
 }
1519
 }
1521
 
1520
 
1522
-//查询项目
1521
+// 查询项目
1523
 func FindPatientXiang(orgid, patient_id, drugid, mode int64) bool {
1522
 func FindPatientXiang(orgid, patient_id, drugid, mode int64) bool {
1524
 	var total int
1523
 	var total int
1525
 	XTReadDB().Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and status = 1 and type = 2 and "+
1524
 	XTReadDB().Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and status = 1 and type = 2 and "+
1531
 	return false
1530
 	return false
1532
 }
1531
 }
1533
 
1532
 
1534
-//查询耗材
1533
+// 查询耗材
1535
 func FindPatientXiang2(orgid, patient_id, drugid, mode int64) bool {
1534
 func FindPatientXiang2(orgid, patient_id, drugid, mode int64) bool {
1536
 	var total int
1535
 	var total int
1537
 	XTReadDB().Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and status = 1 and type = 3 and "+
1536
 	XTReadDB().Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and status = 1 and type = 3 and "+
1543
 	return false
1542
 	return false
1544
 }
1543
 }
1545
 
1544
 
1546
-//types处方类型,1.药品 2.项目,model透析模式
1545
+// types处方类型,1.药品 2.项目,model透析模式
1547
 func GetHisInfoTempalteId(model, orgid, types int64) (tp []int64) {
1546
 func GetHisInfoTempalteId(model, orgid, types int64) (tp []int64) {
1548
 	type tmpid struct {
1547
 	type tmpid struct {
1549
 		Id int64
1548
 		Id int64
1557
 	return
1556
 	return
1558
 }
1557
 }
1559
 
1558
 
1560
-//替换药品处方模板
1559
+// 替换药品处方模板
1561
 func ReplaceDrugPrescriptionTemplate(orgid, patient_id, drugid int64, ids []int64, s models.HisPrescriptionAdviceTemplate, tx *gorm.DB) (err error) {
1560
 func ReplaceDrugPrescriptionTemplate(orgid, patient_id, drugid int64, ids []int64, s models.HisPrescriptionAdviceTemplate, tx *gorm.DB) (err error) {
1562
 	err = tx.Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and "+
1561
 	err = tx.Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and "+
1563
 		"status = 1 and prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1562
 		"status = 1 and prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1577
 	return err
1576
 	return err
1578
 }
1577
 }
1579
 
1578
 
1580
-//替换项目模板
1579
+// 替换项目模板
1581
 func ReplaceProjectPrescriptionTemplate(orgid, patient_id, drugid int64, ids []int64, s models.HisPrescriptionProjectTemplate, tx *gorm.DB) (err error) {
1580
 func ReplaceProjectPrescriptionTemplate(orgid, patient_id, drugid int64, ids []int64, s models.HisPrescriptionProjectTemplate, tx *gorm.DB) (err error) {
1582
 	err = tx.Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and "+
1581
 	err = tx.Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and "+
1583
 		"status = 1 and prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1582
 		"status = 1 and prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1599
 	return err
1598
 	return err
1600
 }
1599
 }
1601
 
1600
 
1602
-//删除项目模板
1601
+// 删除项目模板
1603
 func DeleteProjectTemplate(orgid, patient_id, drugid int64, ids []int64, tx *gorm.DB) (err error) {
1602
 func DeleteProjectTemplate(orgid, patient_id, drugid int64, ids []int64, tx *gorm.DB) (err error) {
1604
 	err = tx.Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and "+
1603
 	err = tx.Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and "+
1605
 		"prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1604
 		"prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1609
 	return err
1608
 	return err
1610
 }
1609
 }
1611
 
1610
 
1612
-//删除处方模板
1611
+// 删除处方模板
1613
 func DeletePrescriptionTemplate(orgid, patient_id, drugid int64, ids []int64, tx *gorm.DB) (err error) {
1612
 func DeletePrescriptionTemplate(orgid, patient_id, drugid int64, ids []int64, tx *gorm.DB) (err error) {
1614
 	err = tx.Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and "+
1613
 	err = tx.Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and "+
1615
 		"prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1614
 		"prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1619
 	return err
1618
 	return err
1620
 }
1619
 }
1621
 
1620
 
1622
-//根据透析模式和患者id获取该患者的处方内容
1621
+// 根据透析模式和患者id获取该患者的处方内容
1623
 func PTemplateInformation(orgid, mode_id, patient_id int64) (tmp interface{}, err error) {
1622
 func PTemplateInformation(orgid, mode_id, patient_id int64) (tmp interface{}, err error) {
1624
 	//获取处方id
1623
 	//获取处方id
1625
 	var tt []*models.HisPrescriptionTemplate
1624
 	var tt []*models.HisPrescriptionTemplate
1695
 
1694
 
1696
 }
1695
 }
1697
 
1696
 
1698
-//收尾工作
1697
+// 收尾工作
1699
 func Scavenger(orgid int64) (err error) {
1698
 func Scavenger(orgid int64) (err error) {
1700
 	//开事务
1699
 	//开事务
1701
 	tx := XTWriteDB().Begin()
1700
 	tx := XTWriteDB().Begin()
1764
 	return
1763
 	return
1765
 }
1764
 }
1766
 
1765
 
1767
-//分区和收费(患者发药
1766
+// 分区和收费(患者发药
1768
 func PartitionAndLayout(stime, etime, orgid, shift, partition int64, flist []*models.TmpPatient) (tmp []*models.TmpPatient, err error) {
1767
 func PartitionAndLayout(stime, etime, orgid, shift, partition int64, flist []*models.TmpPatient) (tmp []*models.TmpPatient, err error) {
1769
 	//获取排班
1768
 	//获取排班
1770
 	var sch []*models.XtScheduleTwo
1769
 	var sch []*models.XtScheduleTwo
1794
 	return
1793
 	return
1795
 }
1794
 }
1796
 
1795
 
1797
-//分区和收费(药品发药
1796
+// 分区和收费(药品发药
1798
 func PartitionAndLayoutDrug(deliveryway string, stime, etime, orgid, shift, partition int64, flist []*models.PatientInformation) (tmp []*models.PatientInformation, err error) {
1797
 func PartitionAndLayoutDrug(deliveryway string, stime, etime, orgid, shift, partition int64, flist []*models.PatientInformation) (tmp []*models.PatientInformation, err error) {
1799
 	//获取排班
1798
 	//获取排班
1800
 	var sch []*models.XtScheduleTwo
1799
 	var sch []*models.XtScheduleTwo
1833
 	return
1832
 	return
1834
 }
1833
 }
1835
 
1834
 
1836
-//给药途径
1835
+// 给药途径
1837
 func Administration(deliveryway string, orgid int64, flist []*models.ListOfDrugs) (tmp []*models.ListOfDrugs, err error) {
1836
 func Administration(deliveryway string, orgid int64, flist []*models.ListOfDrugs) (tmp []*models.ListOfDrugs, err error) {
1838
 	//查询药品
1837
 	//查询药品
1839
 	var pp []*models.PharmacyBaseDrug
1838
 	var pp []*models.PharmacyBaseDrug
1860
 	return
1859
 	return
1861
 }
1860
 }
1862
 
1861
 
1863
-//计算总量
1862
+// 计算总量
1864
 func CalculateTheTotalAmount(tmp []*models.PatientInformation, drug_id int64) (total string, err error) {
1863
 func CalculateTheTotalAmount(tmp []*models.PatientInformation, drug_id int64) (total string, err error) {
1865
 	//获取药品信息
1864
 	//获取药品信息
1866
 	var t models.SpBaseDrug
1865
 	var t models.SpBaseDrug

+ 8 - 0
service/stock_service.go Näytä tiedosto

8508
 	err := XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Find(&config).Error
8508
 	err := XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Find(&config).Error
8509
 	return config, err
8509
 	return config, err
8510
 }
8510
 }
8511
+
8512
+func UpdateDeleteAutoGood(good_id int64, record_date int64, patient_id int64) error {
8513
+
8514
+	err := XTWriteDB().Model(&models.AutomaticReduceDetail{}).Where("good_id = ? and record_time = ? and patient_id = ?", good_id, record_date, patient_id).Updates(map[string]interface{}{"status": 1}).Error
8515
+
8516
+	err = XTWriteDB().Model(&models.DialysisBeforePrepare{}).Where("good_id = ? and record_date = ? and patient_id = ?", good_id, record_date, patient_id).Updates(map[string]interface{}{"status": 1}).Error
8517
+	return err
8518
+}

+ 123 - 5
service/warhouse_service.go Näytä tiedosto

1208
 
1208
 
1209
 	//查询该患者当天已经出库的耗材信息
1209
 	//查询该患者当天已经出库的耗材信息
1210
 	goods_yc, _ := FindConsumablesByDateTwo(orgID, patient_id, record_time)
1210
 	goods_yc, _ := FindConsumablesByDateTwo(orgID, patient_id, record_time)
1211
+
1211
 	// 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
1212
 	// 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
1212
 	for i := len(goods_yc) - 1; i >= 0; i-- {
1213
 	for i := len(goods_yc) - 1; i >= 0; i-- {
1213
 		goods_yc_temp := goods_yc[i]
1214
 		goods_yc_temp := goods_yc[i]
1244
 
1245
 
1245
 	// goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
1246
 	// goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
1246
 	// goods 这个数据就是需要出库的耗材的数据(新增的数据)
1247
 	// goods 这个数据就是需要出库的耗材的数据(新增的数据)
1247
-
1248
+	fmt.Println("len233333333333333w", len(goods_yc))
1249
+	fmt.Println("需要出库的数据", len(goods))
1248
 	if len(goods) > 0 {
1250
 	if len(goods) > 0 {
1249
 		out, err := FindStockOutByIsSys(orgID, 1, record_time)
1251
 		out, err := FindStockOutByIsSys(orgID, 1, record_time)
1250
 		houseConfig, _ := GetAllStoreHouseConfig(orgID)
1252
 		houseConfig, _ := GetAllStoreHouseConfig(orgID)
1293
 
1295
 
1294
 			var cha_count int64
1296
 			var cha_count int64
1295
 			var cha_count_two int64
1297
 			var cha_count_two int64
1298
+			//查询已经出库的数量
1296
 			flowGood, _ := GetStockFlowIsBatchNumberTwo(patient_id, record_time, item.GoodId)
1299
 			flowGood, _ := GetStockFlowIsBatchNumberTwo(patient_id, record_time, item.GoodId)
1297
 			var out_count int64
1300
 			var out_count int64
1298
 			for _, item := range flowGood {
1301
 			for _, item := range flowGood {
1299
 				out_count += item.Count
1302
 				out_count += item.Count
1300
 			}
1303
 			}
1304
+			//已经出库的数量 减掉目前需要出库的数据
1301
 			cha_count = item.Count - out_count
1305
 			cha_count = item.Count - out_count
1302
-			//fmt.Println("item.Count", item.Count)
1303
-			//fmt.Println("item.Count", out_count)
1304
-			//fmt.Println("cha_count2323223232323223", cha_count)
1306
+
1305
 			cha_count_two = out_count - item.Count
1307
 			cha_count_two = out_count - item.Count
1306
 
1308
 
1307
 			prepare := models.DialysisBeforePrepare{
1309
 			prepare := models.DialysisBeforePrepare{
1313
 			}
1315
 			}
1314
 
1316
 
1315
 			ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
1317
 			ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
1318
+
1316
 			//数量增加
1319
 			//数量增加
1317
 			if cha_count > 0 {
1320
 			if cha_count > 0 {
1318
 				//出库数量累加
1321
 				//出库数量累加
1319
 				ModifyGoodSumCount(houseConfig.StorehouseOutInfo, cha_count, orgID, item.GoodId)
1322
 				ModifyGoodSumCount(houseConfig.StorehouseOutInfo, cha_count, orgID, item.GoodId)
1320
 			}
1323
 			}
1321
-			//数量减少
1324
+
1325
+			//已经出库的数据 大于 目前需要出库的数据
1322
 			if cha_count_two > 0 {
1326
 			if cha_count_two > 0 {
1327
+
1323
 				ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, cha_count_two, orgID, item.GoodId)
1328
 				ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, cha_count_two, orgID, item.GoodId)
1324
 				//退库数量增加
1329
 				//退库数量增加
1325
 				UpdateSumAddCancelCount(orgID, item.GoodId, houseConfig.StorehouseOutInfo, cha_count_two)
1330
 				UpdateSumAddCancelCount(orgID, item.GoodId, houseConfig.StorehouseOutInfo, cha_count_two)
1326
 
1331
 
1332
+				//生成退库单
1333
+
1327
 			}
1334
 			}
1328
 			//更新剩余库存
1335
 			//更新剩余库存
1329
 			goodListSix, _ := GetSumGoodList(orgID, houseConfig.StorehouseOutInfo, item.GoodId)
1336
 			goodListSix, _ := GetSumGoodList(orgID, houseConfig.StorehouseOutInfo, item.GoodId)
1826
 		if errThree != nil {
1833
 		if errThree != nil {
1827
 			return errThree
1834
 			return errThree
1828
 		}
1835
 		}
1836
+		fmt.Println("errThreee23333333333333333333333", errThree)
1829
 		//查询剩余库存
1837
 		//查询剩余库存
1830
 		houseConfig, _ := GetAllStoreHouseConfig(orgID)
1838
 		houseConfig, _ := GetAllStoreHouseConfig(orgID)
1831
 		goodList, _ := GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
1839
 		goodList, _ := GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
1833
 		for _, item := range goodList {
1841
 		for _, item := range goodList {
1834
 			sum_count += item.StockCount
1842
 			sum_count += item.StockCount
1835
 		}
1843
 		}
1844
+		fmt.Println("sum_count++++++++++++++++++++++++++++++++=", sum_count)
1836
 		// 判断当前出库的数据和删除出库数量
1845
 		// 判断当前出库的数据和删除出库数量
1837
 		if good_yc.Count <= ware.Count {
1846
 		if good_yc.Count <= ware.Count {
1838
 			delete_count = good_yc.Count
1847
 			delete_count = good_yc.Count
1902
 		//退库数量相加
1911
 		//退库数量相加
1903
 		UpdateSumAddCancelCount(good_yc.UserOrgId, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
1912
 		UpdateSumAddCancelCount(good_yc.UserOrgId, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
1904
 
1913
 
1914
+		operation_time := time.Now().Unix()
1915
+		//创建退库单
1916
+		timeStr := time.Now().Format("2006-01-02")
1917
+		timeArr := strings.Split(timeStr, "-")
1918
+		total, _ := FindAllCancelStockTotal(good_yc.UserOrgId)
1919
+		total = total + 1
1920
+		orderNumber := "CKTKD" + strconv.FormatInt(good_yc.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
1921
+
1922
+		cancelStock := models.CancelStock{
1923
+			OrderNumber:  orderNumber,
1924
+			OperaTime:    operation_time,
1925
+			OrgId:        good_yc.UserOrgId,
1926
+			Creater:      warehouseOut.Creater,
1927
+			Ctime:        time.Now().Unix(),
1928
+			Status:       1,
1929
+			ReturnTime:   record_time,
1930
+			Type:         1,
1931
+			StorehouseId: houseConfig.StorehouseOutInfo,
1932
+			IsCheck:      1,
1933
+		}
1934
+		_, msgerrkonde := GetCancelStockDetailByOrderNumberOne(record_time, good_yc.UserOrgId)
1935
+		if msgerrkonde == gorm.ErrRecordNotFound {
1936
+			AddSigleCancelStock(&cancelStock)
1937
+		}
1938
+		cancel, _ := GetLastCancelStockById(good_yc.UserOrgId)
1939
+
1940
+		manufacturer, _ := GetManufactureById(ware.Manufacturer)
1941
+		deaerler, _ := GetDealerById(ware.Dealer)
1942
+
1943
+		cancelStockInfo := models.CancelStockInfo{
1944
+			GoodId:          ware.GoodId,
1945
+			CancelStockId:   cancel.ID,
1946
+			GoodTypeId:      ware.GoodTypeId,
1947
+			Count:           delete_count,
1948
+			Price:           ware.Price,
1949
+			Total:           0,
1950
+			ProductDate:     ware.ProductDate,
1951
+			ExpiryDate:      ware.ExpiryDate,
1952
+			Ctime:           time.Now().Unix(),
1953
+			Status:          1,
1954
+			OrgId:           good_yc.UserOrgId,
1955
+			OrderNumber:     cancel.OrderNumber,
1956
+			Type:            0,
1957
+			Dealer:          deaerler.DealerName,
1958
+			Manufacturer:    manufacturer.ManufacturerName,
1959
+			Number:          ware.Number,
1960
+			RegisterAccount: "",
1961
+			Remark:          "",
1962
+			WarehouseInfoId: ware.WarehouseInfotId,
1963
+			PatientId:       ware.PatientId,
1964
+			RecordDate:      record_time,
1965
+			StorehouseId:    houseConfig.StorehouseOutInfo,
1966
+			IsCheck:         1,
1967
+		}
1968
+
1969
+		CreateCancelStockInfoOne(&cancelStockInfo)
1970
+		cancelInfo, _ := GetLastCancelStockInfoByGoodId(ware.GoodId)
1971
+		goodListOne, _ := GetSumGoodList(good_yc.UserOrgId, houseConfig.StorehouseOutInfo, good_yc.GoodId)
1972
+		var over_count int64
1973
+		for _, it := range goodListOne {
1974
+			over_count += it.StockCount
1975
+		}
1976
+		flow := models.VmStockFlow{
1977
+			WarehousingId:           ware.WarehouseInfotId,
1978
+			GoodId:                  ware.GoodId,
1979
+			Number:                  ware.Number,
1980
+			LicenseNumber:           ware.LicenseNumber,
1981
+			Count:                   ware.Count,
1982
+			UserOrgId:               ware.OrgId,
1983
+			PatientId:               ware.PatientId,
1984
+			SystemTime:              record_time,
1985
+			ConsumableType:          7,
1986
+			IsSys:                   0,
1987
+			WarehousingOrder:        "",
1988
+			WarehouseOutId:          ware.WarehouseOutId,
1989
+			WarehouseOutOrderNumber: ware.WarehouseOutOrderNumber,
1990
+			IsEdit:                  0,
1991
+			CancelStockId:           cancel.ID,
1992
+			CancelOrderNumber:       cancel.OrderNumber,
1993
+			Manufacturer:            manufacturer.ID,
1994
+			Dealer:                  0,
1995
+			Creator:                 warehouseOut.Creater,
1996
+			UpdateCreator:           0,
1997
+			Status:                  1,
1998
+			Ctime:                   time.Now().Unix(),
1999
+			Mtime:                   0,
2000
+			Price:                   ware.Price,
2001
+			WarehousingDetailId:     ware.WarehouseInfotId,
2002
+			WarehouseOutDetailId:    ware.ID,
2003
+			CancelOutDetailId:       cancelInfo.ID,
2004
+			ProductDate:             ware.ProductDate,
2005
+			ExpireDate:              ware.ExpiryDate,
2006
+			StorehouseId:            houseConfig.StorehouseOutInfo,
2007
+			OverCount:               over_count,
2008
+		}
2009
+		CreateStockFlowOne(flow)
2010
+
1905
 		// 增加了对应的库存后,看看还有多少需要退库的
2011
 		// 增加了对应的库存后,看看还有多少需要退库的
1906
 		good_yc.Count = good_yc.Count - delete_count
2012
 		good_yc.Count = good_yc.Count - delete_count
1907
 		if good_yc.Count == 0 {
2013
 		if good_yc.Count == 0 {
6044
 	return err
6150
 	return err
6045
 }
6151
 }
6046
 
6152
 
6153
+func ModifyReduceGoodSumCountTwenty(storehouse_id int64, count int64, user_org_id int64, good_id int64) error {
6154
+	ut := XTWriteDB().Begin()
6155
+
6156
+	err = ut.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id  = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("stock_out_count", gorm.Expr("stock_out_count - ?", count)).Error
6157
+	if err != nil {
6158
+		ut.Rollback()
6159
+		return err
6160
+	}
6161
+	ut.Commit()
6162
+	return err
6163
+}
6164
+
6047
 func ModifyAddGoodSumCount(storehouse_id int64, count int64, user_org_id int64, good_id int64) error {
6165
 func ModifyAddGoodSumCount(storehouse_id int64, count int64, user_org_id int64, good_id int64) error {
6048
 	ut := XTWriteDB().Begin()
6166
 	ut := XTWriteDB().Begin()
6049
 
6167