Browse Source

Merge remote-tracking branch 'origin/20230223_xt_api_new_branch' into 20230223_xt_api_new_branch

XMLWAN 2 years ago
parent
commit
551828a8bc

+ 14 - 3
controllers/doctors_api_controller.go View File

@@ -1488,7 +1488,8 @@ func (c *DoctorsApiController) CreateFirstDisease() {
1488 1488
 	diagnostic_basis := dataBody["diagnostic_basis"].(string)
1489 1489
 	differential_diagnosis := dataBody["differential_diagnosis"].(string)
1490 1490
 	treatment_plan := dataBody["treatment_plan"].(string)
1491
-
1491
+	inspect_date := dataBody["inspect_date"].(string)
1492
+	project_id := dataBody["project_id"].(string)
1492 1493
 	orgId := c.GetAdminUserInfo().CurrentOrgId
1493 1494
 	firstdisease := models.XtPatientFirstDisease{
1494 1495
 		Title:                 title,
@@ -1505,6 +1506,8 @@ func (c *DoctorsApiController) CreateFirstDisease() {
1505 1506
 		Ctime:                 time.Now().Unix(),
1506 1507
 		Mtime:                 0,
1507 1508
 		Status:                1,
1509
+		ProjectId:             project_id,
1510
+		InspectDate:           inspect_date,
1508 1511
 	}
1509 1512
 
1510 1513
 	error := service.CreatePatientFirstDisease(firstdisease)
@@ -1543,9 +1546,14 @@ func (c *DoctorsApiController) GetFirstDetailById() {
1543 1546
 
1544 1547
 	id, _ := c.GetInt64("id")
1545 1548
 	list, err := service.GetFirstDetailById(id)
1549
+	ids := strings.Split(list.ProjectId, ",")
1550
+	datelist := strings.Split(list.InspectDate, ",")
1551
+	fmt.Println("list232323232323w", datelist)
1552
+	inspectlist, err := service.GetInspectionItemlist(list.PatientId, datelist, ids)
1546 1553
 	if err == nil {
1547 1554
 		c.ServeSuccessJSON(map[string]interface{}{
1548
-			"detail": list,
1555
+			"detail":      list,
1556
+			"inspectlist": inspectlist,
1549 1557
 		})
1550 1558
 		return
1551 1559
 	}
@@ -1571,7 +1579,8 @@ func (c *DoctorsApiController) UpdateFirstDisease() {
1571 1579
 	diagnostic_basis := dataBody["diagnostic_basis"].(string)
1572 1580
 	differential_diagnosis := dataBody["differential_diagnosis"].(string)
1573 1581
 	treatment_plan := dataBody["treatment_plan"].(string)
1574
-
1582
+	inspect_date := dataBody["inspect_date"].(string)
1583
+	project_id := dataBody["project_id"].(string)
1575 1584
 	orgId := c.GetAdminUserInfo().CurrentOrgId
1576 1585
 	firstdisease := models.XtPatientFirstDisease{
1577 1586
 		Title:                 title,
@@ -1589,6 +1598,8 @@ func (c *DoctorsApiController) UpdateFirstDisease() {
1589 1598
 		Mtime:                 0,
1590 1599
 		Status:                1,
1591 1600
 		ID:                    id,
1601
+		InspectDate:           inspect_date,
1602
+		ProjectId:             project_id,
1592 1603
 	}
1593 1604
 
1594 1605
 	error := service.UpdatePatientFirstDisease(firstdisease, id)

+ 0 - 1
controllers/his_api_controller.go View File

@@ -1948,7 +1948,6 @@ func (c *HisApiController) CreateHisPrescription() {
1948 1948
 
1949 1949
 											}
1950 1950
 
1951
-											//删除记录
1952 1951
 											service.DeleteAutoWarehouse(patient_id, recordDateTime)
1953 1952
 
1954 1953
 										}

+ 270 - 232
controllers/mobile_api_controllers/dialysis_api_controller.go View File

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

+ 0 - 6
controllers/new_mobile_api_controllers/dialysis_parameter_api_controller.go View File

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

+ 13 - 8
controllers/patient_api_controller.go View File

@@ -84,7 +84,7 @@ func PatientApiRegistRouters() {
84 84
 
85 85
 }
86 86
 
87
-//GetPatientsList 取患者列表
87
+// GetPatientsList 取患者列表
88 88
 func (c *PatientApiController) GetPatientsList() {
89 89
 	var err error
90 90
 	defer func() {
@@ -157,7 +157,7 @@ func (c *PatientApiController) GetPatientsList() {
157 157
 
158 158
 }
159 159
 
160
-//GetPatientTotal
160
+// GetPatientTotal
161 161
 func (c *PatientApiController) GetPatientTotal() {
162 162
 	adminUserInfo := c.GetAdminUserInfo()
163 163
 
@@ -182,7 +182,7 @@ func (c *PatientApiController) GetPatientsAllList() {
182 182
 	return
183 183
 }
184 184
 
185
-//GenerateDialysisNo 生成透析号
185
+// GenerateDialysisNo 生成透析号
186 186
 func (c *PatientApiController) GenerateDialysisNo() {
187 187
 	adminUserInfo := c.GetAdminUserInfo()
188 188
 
@@ -206,7 +206,7 @@ func (c *PatientApiController) GenerateDialysisNo() {
206 206
 	return
207 207
 }
208 208
 
209
-//CreatePatient 创建患者
209
+// CreatePatient 创建患者
210 210
 func (c *PatientApiController) CreatePatient() {
211 211
 	record_date := c.GetString("record_date")
212 212
 	is_infectious, _ := c.GetInt64("is_infectious")
@@ -443,7 +443,7 @@ func (c *PatientApiController) CreatePatient() {
443 443
 	return
444 444
 }
445 445
 
446
-//EditPatient 修改
446
+// EditPatient 修改
447 447
 func (c *PatientApiController) EditPatient() {
448 448
 	id, _ := c.GetInt64("id", 0)
449 449
 
@@ -1074,7 +1074,7 @@ func (c *PatientApiController) DeleteDialysisSolution() {
1074 1074
 	return
1075 1075
 }
1076 1076
 
1077
-//GetDryWeights 取患者干体重调整铺
1077
+// GetDryWeights 取患者干体重调整铺
1078 1078
 func (c *PatientApiController) GetDryWeights() {
1079 1079
 	page, _ := c.GetInt64("page", 1)
1080 1080
 	limit, _ := c.GetInt64("limit", 10)
@@ -1289,9 +1289,9 @@ func (c *PatientApiController) CreateGroupAdvice() {
1289 1289
 	Remark := ""
1290 1290
 	if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
1291 1291
 		remark, _ := dataBody["remark"].(string)
1292
+
1292 1293
 		Remark = remark
1293 1294
 	}
1294
-
1295 1295
 	var advices []*models.GroupAdvice
1296 1296
 	if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
1297 1297
 		utils.ErrorLog("adviceNames")
@@ -1323,6 +1323,7 @@ func (c *PatientApiController) CreateGroupAdvice() {
1323 1323
 			return
1324 1324
 		}
1325 1325
 		adviceName, _ := adviceNameM["advice_name"].(string)
1326
+		fmt.Println("adviceceNMAE--------------------------------", adviceName)
1326 1327
 		if len(adviceName) == 0 {
1327 1328
 			utils.ErrorLog("len(advice_name) == 0")
1328 1329
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -1416,6 +1417,10 @@ func (c *PatientApiController) CreateGroupAdvice() {
1416 1417
 			advice.DrugNameId = drug_name_id
1417 1418
 		}
1418 1419
 
1420
+		remark, _ := adviceNameM["remark"].(string)
1421
+		fmt.Println("哦哦撒搜哦搜搜哦remark-----------------------------------", remark)
1422
+		advice.Remark = remark
1423
+
1419 1424
 		if adviceType == 1 {
1420 1425
 
1421 1426
 			if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
@@ -3029,7 +3034,7 @@ func (c *PatientApiController) DeleteGroupAdvice() {
3029 3034
 	return
3030 3035
 }
3031 3036
 
3032
-//GetDoctorAdvices 医嘱列表
3037
+// GetDoctorAdvices 医嘱列表
3033 3038
 func (c *PatientApiController) GetDoctorAdvices() {
3034 3039
 	id, _ := c.GetInt64("id", 0)
3035 3040
 	adviceType, _ := c.GetInt64("advice_type", 0)

+ 1 - 1
controllers/self_drug_api_congtroller.go View File

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

+ 2 - 0
models/dialysis.go View File

@@ -1103,6 +1103,7 @@ type DialysisBeforePrepareGoods struct {
1103 1103
 	PatientId         int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1104 1104
 	OrderId           int64  `gorm:"column:order_id" json:"order_id" form:"order_id"`
1105 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 1109
 type NewDialysisBeforePrepareGoods struct {
@@ -1119,6 +1120,7 @@ type NewDialysisBeforePrepareGoods struct {
1119 1120
 	ChildNewDialysisBeforePrepareGoods []*NewDialysisBeforePrepareGoods `gorm:"ForeignKey:GoodId;AssociationForeignKey:GoodId" json:"child"`
1120 1121
 	PatientId                          int64                            `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1121 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 1126
 type OldDialysisBeforePrepareGoods struct {

+ 2 - 0
models/patient_models.go View File

@@ -1818,6 +1818,8 @@ type XtPatientFirstDisease struct {
1818 1818
 	Ctime                 int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
1819 1819
 	Mtime                 int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
1820 1820
 	Status                int64  `gorm:"column:status" json:"status" form:"status"`
1821
+	ProjectId             string `gorm:"column:project_id" json:"project_id" form:"project_id"`
1822
+	InspectDate           string `gorm:"column:inspect_date" json:"inspect_date" form:"inspect_date"`
1821 1823
 }
1822 1824
 
1823 1825
 func (XtPatientFirstDisease) TableName() string {

+ 1 - 1
service/dialysis_service.go View File

@@ -1593,7 +1593,7 @@ func GetAllPcAdvicestByList(orgID int64, scheduleDate int64) (advices []*VMDocto
1593 1593
 	advice_list_str, _ := redis.Get(key).Result()
1594 1594
 
1595 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 1597
 		if err != nil {
1598 1598
 			if err == gorm.ErrRecordNotFound {
1599 1599
 				if len(advices) <= 0 {

+ 595 - 4
service/new_warehouse_service.go View File

@@ -26,8 +26,10 @@ func ConsumablesGoodDelivery(orgID int64, patient_id int64, record_time int64, g
26 26
 	// 如果没有对应的库存,则报错
27 27
 
28 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 35
 	stock_number = warehouse.StockCount
@@ -36,6 +38,7 @@ func ConsumablesGoodDelivery(orgID int64, patient_id int64, record_time int64, g
36 38
 	if stock_number >= deliver_number {
37 39
 
38 40
 		maxNumber = goods.Count
41
+
39 42
 		//出库
40 43
 		warehouse.StockCount = warehouse.StockCount - maxNumber
41 44
 		warehouse.Mtime = time.Now().Unix()
@@ -352,7 +355,7 @@ func ConsumablesGoodDelivery(orgID int64, patient_id int64, record_time int64, g
352 355
 			warehouseOutInfo.Price = goodsInfo.PackingPrice
353 356
 		}
354 357
 		_, errcodes := GetWarehouseOutInfoIsExistOne(goods.GoodId, patient_id, record_time, goods.ProjectId)
355
-		//fmt.Println("errcodes23332322332323223", errcodes, goods.ProjectId)
358
+
356 359
 		if errcodes == gorm.ErrRecordNotFound {
357 360
 			errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
358 361
 			if errOne != nil {
@@ -3004,7 +3007,8 @@ func ConsumablesGoodDeliveryFivety(orgID int64, patient_id int64, record_time in
3004 3007
 		if warehouse.StockCount < 0 {
3005 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 3012
 		if err != nil {
3009 3013
 			return err
3010 3014
 		}
@@ -3548,3 +3552,590 @@ func ConsumablesGoodDeliveryFivety(orgID int64, patient_id int64, record_time in
3548 3552
 	}
3549 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
+}

+ 2 - 2
service/patientmanage_service.go View File

@@ -1055,7 +1055,7 @@ func GetInspectionDetail(patientid int64, date int64, orgid int64, projectid int
1055 1055
 	if projectid > 0 {
1056 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 1059
 	return inspection, err
1060 1060
 }
1061 1061
 
@@ -1948,7 +1948,7 @@ func GetFirstDetailById(id int64) (models.XtPatientFirstDisease, error) {
1948 1948
 
1949 1949
 func UpdatePatientFirstDisease(disease models.XtPatientFirstDisease, id int64) error {
1950 1950
 
1951
-	err := XTWriteDB().Model(&models.XtPatientFirstDisease{}).Where("id =? and status = 1", id).Update(map[string]interface{}{"title": disease.Title, "doctor": disease.Doctor, "record_date": disease.RecordDate, "main_content": disease.MainContent, "patient_case": disease.PatientCase, "tentative_diagnosis": disease.TentativeDiagnosis, "diagnostic_basis": disease.DiagnosticBasis, "differential_diagnosis": disease.DifferentialDiagnosis, "treatment_plan": disease.TreatmentPlan}).Error
1951
+	err := XTWriteDB().Model(&models.XtPatientFirstDisease{}).Where("id =? and status = 1", id).Update(map[string]interface{}{"title": disease.Title, "doctor": disease.Doctor, "record_date": disease.RecordDate, "main_content": disease.MainContent, "patient_case": disease.PatientCase, "tentative_diagnosis": disease.TentativeDiagnosis, "diagnostic_basis": disease.DiagnosticBasis, "differential_diagnosis": disease.DifferentialDiagnosis, "treatment_plan": disease.TreatmentPlan, "project_id": disease.ProjectId, "inspect_date": disease.InspectDate}).Error
1952 1952
 	return err
1953 1953
 }
1954 1954
 

+ 8 - 0
service/stock_service.go View File

@@ -8508,3 +8508,11 @@ func GetGoodOutOpenConfigOne(user_org_id int64) (models.XtGoodOutConfig, error)
8508 8508
 	err := XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Find(&config).Error
8509 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 View File

@@ -1208,6 +1208,7 @@ func ConsumablesDeliveryTotal(orgID int64, patient_id int64, record_time int64,
1208 1208
 
1209 1209
 	//查询该患者当天已经出库的耗材信息
1210 1210
 	goods_yc, _ := FindConsumablesByDateTwo(orgID, patient_id, record_time)
1211
+
1211 1212
 	// 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
1212 1213
 	for i := len(goods_yc) - 1; i >= 0; i-- {
1213 1214
 		goods_yc_temp := goods_yc[i]
@@ -1244,7 +1245,8 @@ func ConsumablesDeliveryTotal(orgID int64, patient_id int64, record_time int64,
1244 1245
 
1245 1246
 	// goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
1246 1247
 	// goods 这个数据就是需要出库的耗材的数据(新增的数据)
1247
-
1248
+	fmt.Println("len233333333333333w", len(goods_yc))
1249
+	fmt.Println("需要出库的数据", len(goods))
1248 1250
 	if len(goods) > 0 {
1249 1251
 		out, err := FindStockOutByIsSys(orgID, 1, record_time)
1250 1252
 		houseConfig, _ := GetAllStoreHouseConfig(orgID)
@@ -1293,15 +1295,15 @@ func ConsumablesDeliveryTotal(orgID int64, patient_id int64, record_time int64,
1293 1295
 
1294 1296
 			var cha_count int64
1295 1297
 			var cha_count_two int64
1298
+			//查询已经出库的数量
1296 1299
 			flowGood, _ := GetStockFlowIsBatchNumberTwo(patient_id, record_time, item.GoodId)
1297 1300
 			var out_count int64
1298 1301
 			for _, item := range flowGood {
1299 1302
 				out_count += item.Count
1300 1303
 			}
1304
+			//已经出库的数量 减掉目前需要出库的数据
1301 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 1307
 			cha_count_two = out_count - item.Count
1306 1308
 
1307 1309
 			prepare := models.DialysisBeforePrepare{
@@ -1313,17 +1315,22 @@ func ConsumablesDeliveryTotal(orgID int64, patient_id int64, record_time int64,
1313 1315
 			}
1314 1316
 
1315 1317
 			ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
1318
+
1316 1319
 			//数量增加
1317 1320
 			if cha_count > 0 {
1318 1321
 				//出库数量累加
1319 1322
 				ModifyGoodSumCount(houseConfig.StorehouseOutInfo, cha_count, orgID, item.GoodId)
1320 1323
 			}
1321
-			//数量减少
1324
+
1325
+			//已经出库的数据 大于 目前需要出库的数据
1322 1326
 			if cha_count_two > 0 {
1327
+
1323 1328
 				ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, cha_count_two, orgID, item.GoodId)
1324 1329
 				//退库数量增加
1325 1330
 				UpdateSumAddCancelCount(orgID, item.GoodId, houseConfig.StorehouseOutInfo, cha_count_two)
1326 1331
 
1332
+				//生成退库单
1333
+
1327 1334
 			}
1328 1335
 			//更新剩余库存
1329 1336
 			goodListSix, _ := GetSumGoodList(orgID, houseConfig.StorehouseOutInfo, item.GoodId)
@@ -1826,6 +1833,7 @@ func ConsumablesDeliveryDelete(orgID int64, patient_id int64, record_time int64,
1826 1833
 		if errThree != nil {
1827 1834
 			return errThree
1828 1835
 		}
1836
+		fmt.Println("errThreee23333333333333333333333", errThree)
1829 1837
 		//查询剩余库存
1830 1838
 		houseConfig, _ := GetAllStoreHouseConfig(orgID)
1831 1839
 		goodList, _ := GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
@@ -1833,6 +1841,7 @@ func ConsumablesDeliveryDelete(orgID int64, patient_id int64, record_time int64,
1833 1841
 		for _, item := range goodList {
1834 1842
 			sum_count += item.StockCount
1835 1843
 		}
1844
+		fmt.Println("sum_count++++++++++++++++++++++++++++++++=", sum_count)
1836 1845
 		// 判断当前出库的数据和删除出库数量
1837 1846
 		if good_yc.Count <= ware.Count {
1838 1847
 			delete_count = good_yc.Count
@@ -1902,6 +1911,103 @@ func ConsumablesDeliveryDelete(orgID int64, patient_id int64, record_time int64,
1902 1911
 		//退库数量相加
1903 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 2012
 		good_yc.Count = good_yc.Count - delete_count
1907 2013
 		if good_yc.Count == 0 {
@@ -6044,6 +6150,18 @@ func ModifyReduceGoodSumCount(storehouse_id int64, count int64, user_org_id int6
6044 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 6165
 func ModifyAddGoodSumCount(storehouse_id int64, count int64, user_org_id int64, good_id int64) error {
6048 6166
 	ut := XTWriteDB().Begin()
6049 6167