Browse Source

Merge branch '20201014_xt_api_new_branch' of http://git.shengws.com/csx/XT_New into 20201014_xt_api_new_branch

csx 3 years ago
parent
commit
03cad6d2fb
2 changed files with 142 additions and 123 deletions
  1. 2 1
      service/stock_service.go
  2. 140 122
      service/warhouse_service.go

+ 2 - 1
service/stock_service.go View File

@@ -2739,6 +2739,7 @@ func GetAllStockList(page int64, limit int64, startime int64, endtime int64, goo
2739 2739
 
2740 2740
 	offset := (page - 1) * limit
2741 2741
 	db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status= 1")
2742
+
2742 2743
 	table := XTReadDB().Table("xt_good_information as t").Where("t.status = 1")
2743 2744
 	fmt.Println(table)
2744 2745
 	if startime > 0 {
@@ -2758,7 +2759,7 @@ func GetAllStockList(page int64, limit int64, startime int64, endtime int64, goo
2758 2759
 	if good_type > 0 {
2759 2760
 		db = db.Where("t.good_type_id = ?", good_type)
2760 2761
 	}
2761
-	err = db.Select("x.id,x.warehousing_id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehousing_unit,x.stock_count,x.price,x.total_price,x.dealer,x.manufacturer,x.remark,x.ctime,x.is_return,x.warehousing_order,x.type,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.min_unit").Joins("left join xt_good_information as t on t.id = x.good_id").Offset(offset).Count(&total).Group("x.good_id").Scan(&info).Error
2762
+	err = db.Select("x.id,x.warehousing_id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehousing_unit,x.stock_count,x.price,x.total_price,x.dealer,x.remark,x.ctime,x.is_return,x.warehousing_order,x.type,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.min_unit,t.manufacturer").Joins("left join xt_good_information as t on t.id = x.good_id").Offset(offset).Count(&total).Group("x.good_id").Scan(&info).Error
2762 2763
 	return info, total, err
2763 2764
 }
2764 2765
 

+ 140 - 122
service/warhouse_service.go View File

@@ -650,6 +650,7 @@ func ConsumablesDeliveryTotal(orgID int64, patient_id int64, record_time int64,
650 650
 				if goods_yc_temp.Count == goods_temp.Count {
651 651
 					goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
652 652
 					goods = append(goods[:j], goods[j+1:]...)
653
+					break
653 654
 				}
654 655
 				fmt.Println("998888888888888", goods_yc_temp.Count)
655 656
 				fmt.Println("7777777777777777", goods_temp.Count)
@@ -657,7 +658,6 @@ func ConsumablesDeliveryTotal(orgID int64, patient_id int64, record_time int64,
657 658
 				if goods_yc_temp.Count > goods_temp.Count {
658 659
 					fmt.Println("进来了是吗")
659 660
 					temp_count := goods_yc_temp.Count - goods_temp.Count
660
-
661 661
 					goods_yc[i].Count = temp_count
662 662
 					goods = append(goods[:j], goods[j+1:]...)
663 663
 					break
@@ -671,6 +671,7 @@ func ConsumablesDeliveryTotal(orgID int64, patient_id int64, record_time int64,
671 671
 					goods[j].Count = temp_count
672 672
 					goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
673 673
 					fmt.Println("888888888", goods_yc)
674
+					break
674 675
 				}
675 676
 			}
676 677
 		}
@@ -715,23 +716,31 @@ func ConsumablesDeliveryTotal(orgID int64, patient_id int64, record_time int64,
715 716
 		}
716 717
 
717 718
 		for _, item := range goods {
719
+			var newCount int64 = 0
718 720
 			for _, it := range goodOne {
719 721
 				if item.GoodTypeId == it.GoodTypeId && it.GoodId == it.GoodId {
720
-					it.NewCount = item.Count
722
+					newCount = it.Count
721 723
 				}
722 724
 			}
723
-		}
724
-
725
-		for _, item := range goodOne {
726 725
 			prepare := models.DialysisBeforePrepare{
727 726
 				GoodTypeId: item.GoodTypeId,
728 727
 				GoodId:     item.GoodId,
729 728
 				Count:      item.Count,
730
-				NewCount:   item.NewCount,
731 729
 			}
732
-			fmt.Println("数量99999999999999999", item.Count)
733
-			ConsumablesDelivery(orgID, patient_id, record_time, &prepare, &out, item.Count)
730
+
731
+			ConsumablesDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
734 732
 		}
733
+
734
+		// for _, item := range goodOne {
735
+		// 	prepare := models.DialysisBeforePrepare{
736
+		// 		GoodTypeId: item.GoodTypeId,
737
+		// 		GoodId:     item.GoodId,
738
+		// 		Count:      item.Count,
739
+		// 		NewCount:   item.NewCount,
740
+		// 	}
741
+		// 	fmt.Println("数量99999999999999999", item.Count)
742
+		// 	ConsumablesDelivery(orgID, patient_id, record_time, &prepare, &out, item.Count)
743
+		// }
735 744
 	}
736 745
 
737 746
 	if len(goods_yc) > 0 {
@@ -785,7 +794,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
785 794
 			GoodId:                  goods.GoodId,
786 795
 			PatientId:               patient_id,
787 796
 		}
788
-		warehouseOutInfo.Count = goods.Count
797
+		warehouseOutInfo.Count = count
789 798
 		stockInInfo, _ := FindLastStockInInfoRecord(goods.GoodId, orgID)
790 799
 		warehouseOutInfo.Price = stockInInfo.Price
791 800
 
@@ -840,7 +849,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
840 849
 				GoodId:                  goods.GoodId,
841 850
 				PatientId:               patient_id,
842 851
 			}
843
-			warehouseOutInfo.Count = goods.Count
852
+			warehouseOutInfo.Count = count
844 853
 			//更新入库详情表
845 854
 			UpdateAutoMaticReduceDetail(goods.GoodId, goods.GoodTypeId, record_time, patient_id, orgID, warehouseOutInfo)
846 855
 			details := models.BloodAutomaticReduceDetail{
@@ -870,11 +879,9 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
870 879
 			}
871 880
 		}
872 881
 		fmt.Println("newcount9999999999999999999999999999999", goods.NewCount)
873
-		if goods.NewCount == 0 {
874
-			maxNumber = count
875
-		} else {
876
-			maxNumber = goods.NewCount
877
-		}
882
+		
883
+		maxNumber = goods.Count
884
+		
878 885
 
879 886
 		if warehouse.StockCount < maxNumber {
880 887
 			return errors.New("库存数量不足")
@@ -896,112 +903,123 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
896 903
 		return nil
897 904
 	} else {
898 905
 		// 当改批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
899
-		warehouseOutInfo := &models.WarehouseOutInfo{
900
-			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
901
-			WarehouseOutId:          warehouseOut.ID,
902
-			WarehouseInfotId:        warehouse.ID,
903
-			Status:                  1,
904
-			Ctime:                   time.Now().Unix(),
905
-			Remark:                  "",
906
-			OrgId:                   orgID,
907
-			Type:                    1,
908
-			Manufacturer:            0,
909
-			Dealer:                  0,
910
-			IsSys:                   1,
911
-			SysRecordTime:           record_time,
912
-			GoodTypeId:              goods.GoodTypeId,
913
-			GoodId:                  goods.GoodId,
914
-			PatientId:               patient_id,
915
-		}
916
-		warehouseOutInfo.Count = stock_number
917
-		stockInInfo, _ := service.FindLastStockInInfoRecord(goods.GoodId, orgID)
918
-		warehouseOutInfo.Price = stockInInfo.Price
919
-
920
-		_, errcode := GetStockInRecoredByGoodId(goods.GoodId, goods.GoodTypeId, record_time, patient_id, orgID)
921
-		if errcode == gorm.ErrRecordNotFound {
922
-			errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
923
-
924
-			if errOne != nil {
925
-				return errOne
926
-			} else {
927
-				details := &models.AutomaticReduceDetail{
928
-					WarehouseOutId:          warehouseOutInfo.ID,
929
-					WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
930
-					PatientId:               patient_id,
931
-					Ctime:                   time.Now().Unix(),
932
-					Mtime:                   time.Now().Unix(),
933
-					Status:                  1,
934
-					RecordTime:              record_time,
935
-					OrgId:                   orgID,
936
-					GoodId:                  goods.GoodId,
937
-					GoodTypeId:              goods.GoodTypeId,
938
-					Count:                   goods.Count,
939
-				}
940
-				errTwo := service.AddSigleAutoReduceRecordInfo(details)
941
-				if errTwo != nil {
942
-					return errTwo
943
-				}
944
-			}
945
-			// 出库完成后,要将该批次库存清零
946
-			warehouse.StockCount = 0
947
-			warehouse.Mtime = time.Now().Unix()
948
-			errThree := UpDateWarehouseInfoByStock(&warehouse)
949
-			if errThree != nil {
950
-				return errThree
951
-			}
952
-			// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
953
-			goods.Count = deliver_number - stock_number
954
-
955
-			ConsumablesDelivery(orgID, patient_id, record_time, goods, warehouseOut, count)
956
-		} else if errcode == nil {
957
-
958
-			warehouseOutInfo := &models.WarehouseOutInfo{
959
-				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
960
-				WarehouseOutId:          warehouseOut.ID,
961
-				WarehouseInfotId:        warehouse.ID,
962
-				Status:                  1,
963
-				Ctime:                   time.Now().Unix(),
964
-				Remark:                  "",
965
-				OrgId:                   orgID,
966
-				Type:                    1,
967
-				Manufacturer:            0,
968
-				Dealer:                  0,
969
-				IsSys:                   1,
970
-				SysRecordTime:           record_time,
971
-				GoodTypeId:              goods.GoodTypeId,
972
-				GoodId:                  goods.GoodId,
973
-				PatientId:               patient_id,
974
-			}
975
-			warehouseOutInfo.Count = goods.Count
976
-			//更新入库详情表
977
-			UpdateAutoMaticReduceDetail(goods.GoodId, goods.GoodTypeId, record_time, patient_id, orgID, warehouseOutInfo)
978
-			details := models.BloodAutomaticReduceDetail{
979
-				WarehouseOutId:          warehouseOutInfo.ID,
980
-				WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
981
-				PatientId:               patient_id,
982
-				Ctime:                   time.Now().Unix(),
983
-				Mtime:                   time.Now().Unix(),
984
-				Status:                  1,
985
-				RecordTime:              record_time,
986
-				OrgId:                   orgID,
987
-				GoodId:                  goods.GoodId,
988
-				GoodTypeId:              goods.GoodTypeId,
989
-				Count:                   count,
990
-			}
991
-			//查询当天耗材是否已经存在数据
992
-			_, errcode := GetAutoMaticReduceDetail(orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId)
993
-			if errcode == gorm.ErrRecordNotFound {
994
-				errTwo := CreateAutoReduceRecord(&details)
995
-				if errTwo != nil {
996
-					return errTwo
997
-				}
998
-			} else if errcode == nil {
999
-				DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId)
1000
-
1001
-				CreateAutoReduceRecord(&details)
1002
-			}
906
+		// warehouseOutInfo := &models.WarehouseOutInfo{
907
+		// 	WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
908
+		// 	WarehouseOutId:          warehouseOut.ID,
909
+		// 	WarehouseInfotId:        warehouse.ID,
910
+		// 	Status:                  1,
911
+		// 	Ctime:                   time.Now().Unix(),
912
+		// 	Remark:                  "",
913
+		// 	OrgId:                   orgID,
914
+		// 	Type:                    1,
915
+		// 	Manufacturer:            0,
916
+		// 	Dealer:                  0,
917
+		// 	IsSys:                   1,
918
+		// 	SysRecordTime:           record_time,
919
+		// 	GoodTypeId:              goods.GoodTypeId,
920
+		// 	GoodId:                  goods.GoodId,
921
+		// 	PatientId:               patient_id,
922
+		// }
923
+		// warehouseOutInfo.Count = stock_number
924
+		// stockInInfo, _ := service.FindLastStockInInfoRecord(goods.GoodId, orgID)
925
+		// warehouseOutInfo.Price = stockInInfo.Price
926
+
927
+		// cur_warehouse, errcode := GetStockInRecoredByGoodId(goods.GoodId, goods.GoodTypeId, record_time, patient_id, orgID)
928
+		// if errcode == gorm.ErrRecordNotFound {
929
+		// 	errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
930
+
931
+		// 	if errOne != nil {
932
+		// 		return errOne
933
+		// 	} else {
934
+		// 		details := &models.AutomaticReduceDetail{
935
+		// 			WarehouseOutId:          warehouseOutInfo.ID,
936
+		// 			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
937
+		// 			PatientId:               patient_id,
938
+		// 			Ctime:                   time.Now().Unix(),
939
+		// 			Mtime:                   time.Now().Unix(),
940
+		// 			Status:                  1,
941
+		// 			RecordTime:              record_time,
942
+		// 			OrgId:                   orgID,
943
+		// 			GoodId:                  goods.GoodId,
944
+		// 			GoodTypeId:              goods.GoodTypeId,
945
+		// 			Count:                   goods.Count,
946
+		// 		}
947
+		// 		errTwo := service.AddSigleAutoReduceRecordInfo(details)
948
+		// 		if errTwo != nil {
949
+		// 			return errTwo
950
+		// 		}
951
+		// 	}
952
+		// 	// 出库完成后,要将该批次库存清零
953
+		// 	warehouse.StockCount = 0
954
+		// 	warehouse.Mtime = time.Now().Unix()
955
+		// 	errThree := UpDateWarehouseInfoByStock(&warehouse)
956
+		// 	if errThree != nil {
957
+		// 		return errThree
958
+		// 	}
959
+		// 	// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
960
+		// 	goods.Count = deliver_number - stock_number
961
+
962
+		// 	ConsumablesDelivery(orgID, patient_id, record_time, goods, warehouseOut, count)
963
+		// } else if errcode == nil {
964
+
965
+		// 	warehouseOutInfo := &models.WarehouseOutInfo{
966
+		// 		WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
967
+		// 		WarehouseOutId:          warehouseOut.ID,
968
+		// 		WarehouseInfotId:        warehouse.ID,
969
+		// 		Status:                  1,
970
+		// 		Ctime:                   time.Now().Unix(),
971
+		// 		Remark:                  "",
972
+		// 		OrgId:                   orgID,
973
+		// 		Type:                    1,
974
+		// 		Manufacturer:            0,
975
+		// 		Dealer:                  0,
976
+		// 		IsSys:                   1,
977
+		// 		SysRecordTime:           record_time,
978
+		// 		GoodTypeId:              goods.GoodTypeId,
979
+		// 		GoodId:                  goods.GoodId,
980
+		// 		PatientId:               patient_id,
981
+		// 	}
982
+		// 	warehouseOutInfo.Count = cur_warehouse.Count + StockCount
983
+		// 	//更新入库详情表
984
+		// 	UpdateAutoMaticReduceDetail(goods.GoodId, goods.GoodTypeId, record_time, patient_id, orgID, warehouseOutInfo)
985
+		// 	details := models.BloodAutomaticReduceDetail{
986
+		// 		WarehouseOutId:          warehouseOutInfo.ID,
987
+		// 		WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
988
+		// 		PatientId:               patient_id,
989
+		// 		Ctime:                   time.Now().Unix(),
990
+		// 		Mtime:                   time.Now().Unix(),
991
+		// 		Status:                  1,
992
+		// 		RecordTime:              record_time,
993
+		// 		OrgId:                   orgID,
994
+		// 		GoodId:                  goods.GoodId,
995
+		// 		GoodTypeId:              goods.GoodTypeId,
996
+		// 		Count:                   count,
997
+		// 	}
998
+		// 	//查询当天耗材是否已经存在数据
999
+		// 	_, errcode := GetAutoMaticReduceDetail(orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId)
1000
+		// 	if errcode == gorm.ErrRecordNotFound {
1001
+		// 		errTwo := CreateAutoReduceRecord(&details)
1002
+		// 		if errTwo != nil {
1003
+		// 			return errTwo
1004
+		// 		}
1005
+		// 	} else if errcode == nil {
1006
+		// 		DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId)
1007
+
1008
+		// 		CreateAutoReduceRecord(&details)
1009
+		// 	}
1010
+		// }
1011
+		// 出库完成后,要将该批次库存清零
1012
+		warehouse.StockCount = 0
1013
+		warehouse.Mtime = time.Now().Unix()
1014
+		errThree := UpDateWarehouseInfoByStock(&warehouse)
1015
+		if errThree != nil {
1016
+			return errThree
1003 1017
 		}
1018
+		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
1019
+		goods.Count = deliver_number - stock_number
1004 1020
 
1021
+		ConsumablesDelivery(orgID, patient_id, record_time, goods, warehouseOut, count)
1022
+		
1005 1023
 	}
1006 1024
 	return nil
1007 1025
 }
@@ -1041,10 +1059,10 @@ func ConsumablesDeliveryDelete(orgID int64, patient_id int64, record_time int64,
1041 1059
 			GoodId:        good_yc.GoodId,
1042 1060
 			PatientId:     patient_id,
1043 1061
 		}
1044
-		warehouseOutInfo.Count = delete_count
1062
+		warehouseOutInfo.Count = ware.Count - delete_count
1045 1063
 		stockInInfo, _ := FindLastStockInInfoRecord(good_yc.GoodId, orgID)
1046 1064
 		warehouseOutInfo.Price = stockInInfo.Price
1047
-		errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
1065
+		errOne := UpdateAutoMaticReduceDetail(good_yc.GoodId, good_yc.GoodTypeId, record_time, patient_id, orgID, warehouseOutInfo)
1048 1066
 		if errOne != nil {
1049 1067
 			return errOne
1050 1068
 		} else {
@@ -1059,7 +1077,7 @@ func ConsumablesDeliveryDelete(orgID int64, patient_id int64, record_time int64,
1059 1077
 				OrgId:                   orgID,
1060 1078
 				GoodId:                  good_yc.GoodId,
1061 1079
 				GoodTypeId:              good_yc.GoodTypeId,
1062
-				Count:                   delete_count,
1080
+				Count:                   warehouseOutInfo.Count,
1063 1081
 				Type:                    2,
1064 1082
 			}
1065 1083
 			//查询是否当天已经存在数据