Przeglądaj źródła

11月8日库存管理

XMLWAN 3 lat temu
rodzic
commit
4dd38ccc82

+ 805 - 8
controllers/supply_order_api_contorller.go Wyświetl plik

@@ -20,14 +20,38 @@ type SupplyOrderApiController struct {
20 20
 
21 21
 func SupplyOrderApiRegistRouters() {
22 22
 
23
+	//初始化商品数据
23 24
 	beego.Router("/api/supply/getinitorder", &SupplyOrderApiController{}, "get:GetInitOrder")
25
+	//保存购货订单
24 26
 	beego.Router("/api/supply/savepurchaseorder", &SupplyOrderApiController{}, "post:SavePurchaseOrder")
27
+	//获取所有供应商
25 28
 	beego.Router("/api/supply/getallsupply", &SupplyOrderApiController{}, "get:GetAllSupply")
29
+	//获取供应商订单列表
26 30
 	beego.Router("/api/supply/getallpurchaseorderlist", &SupplyOrderApiController{}, "get:GetAllPurchaseOrderList")
31
+	//修改购货订单
27 32
 	beego.Router("/api/supply/updatepurchaseorder", &SupplyOrderApiController{}, "Post:UpdatePurchaseOrder")
33
+	//审核购货订单
28 34
 	beego.Router("/api/supply/checkpurchaseorder", &SupplyOrderApiController{}, "get:UpdateSupplyWaresing")
35
+	//获取购货订单详情
29 36
 	beego.Router("/api/supply/getpurchaseorderdetail", &SupplyOrderApiController{}, "get:GetPurchaseOrderDetail")
37
+	//新增购货单
30 38
 	beego.Router("/api/supply/addgoodorder", &SupplyOrderApiController{}, "post:AddGoodOrder")
39
+	//获取购货单列表
40
+	beego.Router("/api/supply/getallgoodorderlist", &SupplyOrderApiController{}, "Get:GetAllGoodOderList")
41
+	//修改购货订单详情
42
+	beego.Router("/api/supply/getgoodorderdetail", &SupplyOrderApiController{}, "Get:GetGoodOrderDetail")
43
+	//修改购货订单
44
+	beego.Router("/api/supply/updategoodorder", &SupplyOrderApiController{}, "Post:UpdateGoodOrder")
45
+	//删除购货订单
46
+	beego.Router("/api/supply/deletepurchorder", &SupplyOrderApiController{}, "Get:DeletePurchOrder")
47
+	//生成购货单的判断
48
+	beego.Router("/api/supply/getallordercountlist", &SupplyOrderApiController{}, "Get:GetAllOrderCountList")
49
+	// 生成购货单
50
+	beego.Router("/api/supply/getpurchaseorderinfo", &SupplyOrderApiController{}, "Get:GetPurchOrderInfo")
51
+	//反审核 获取关联的购货单数据
52
+	beego.Router("/api/supply/getgoodorderlist", &SupplyOrderApiController{}, "Get:GetGoodOrderList")
53
+	//反审核购货订单
54
+	beego.Router("/api/supply/getreturnorder", &SupplyOrderApiController{}, "Get:GetReturnOrder")
31 55
 }
32 56
 
33 57
 func (this *SupplyOrderApiController) GetInitOrder() {
@@ -98,7 +122,7 @@ func (this *SupplyOrderApiController) SavePurchaseOrder() {
98 122
 		return
99 123
 	}
100 124
 
101
-	//生成订
125
+	//生成购货订单
102 126
 	timeStr := time.Now().Format("2006-01-02")
103 127
 	timeArr := strings.Split(timeStr, "-")
104 128
 	orgId := this.GetAdminUserInfo().CurrentOrgId
@@ -123,6 +147,7 @@ func (this *SupplyOrderApiController) SavePurchaseOrder() {
123 147
 		DocumentDate:     startTime,
124 148
 		DeliveryDate:     endTime,
125 149
 		SupplierId:       supplier_id,
150
+		IsWarehouse:      2,
126 151
 	}
127 152
 	err = service.CreateSupplyWarehouse(info)
128 153
 	warehouseInfo, _ := service.FindLastSupplyWarehouseInfo(orgId)
@@ -235,6 +260,13 @@ func (this *SupplyOrderApiController) SavePurchaseOrder() {
235 260
 
236 261
 				supply_unit := items["supply_unit"].(string)
237 262
 
263
+				if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
264
+					utils.ErrorLog("manufacturer_id")
265
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
266
+					return
267
+				}
268
+				manufacturer_id := int64(items["manufacturer_id"].(float64))
269
+
238 270
 				order := models.SupplierWarehousingInfoOrder{
239 271
 					OrderNumber:             warehousing_order,
240 272
 					IsSource:                is_source,
@@ -255,6 +287,7 @@ func (this *SupplyOrderApiController) SavePurchaseOrder() {
255 287
 					SupplyManufacturer:      supply_manufacturer,
256 288
 					Name:                    name,
257 289
 					SupplyUnit:              supply_unit,
290
+					ManufacturerId:          manufacturer_id,
258 291
 				}
259 292
 
260 293
 				warehousingInfo = append(warehousingInfo, &order)
@@ -355,7 +388,7 @@ func (this *SupplyOrderApiController) UpdatePurchaseOrder() {
355 388
 	}
356 389
 	var endTime int64
357 390
 	if len(end_time) > 0 {
358
-		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
391
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
359 392
 		if err != nil {
360 393
 			utils.ErrorLog(err.Error())
361 394
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -504,6 +537,13 @@ func (this *SupplyOrderApiController) UpdatePurchaseOrder() {
504 537
 				}
505 538
 
506 539
 				supply_unit := items["supply_unit"].(string)
540
+
541
+				if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
542
+					utils.ErrorLog("manufacturer_id")
543
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
544
+					return
545
+				}
546
+				manufacturer_id := int64(items["manufacturer_id"].(float64))
507 547
 				if id > 0 {
508 548
 					order := models.SupplierWarehousingInfoOrder{
509 549
 						ID:                      id,
@@ -523,6 +563,7 @@ func (this *SupplyOrderApiController) UpdatePurchaseOrder() {
523 563
 						SupplyManufacturer:      supply_manufacturer,
524 564
 						Name:                    name,
525 565
 						SupplyUnit:              supply_unit,
566
+						ManufacturerId:          manufacturer_id,
526 567
 					}
527 568
 
528 569
 					updateWarehousingInfo = append(updateWarehousingInfo, &order)
@@ -550,6 +591,7 @@ func (this *SupplyOrderApiController) UpdatePurchaseOrder() {
550 591
 						SupplyManufacturer:      supply_manufacturer,
551 592
 						Name:                    name,
552 593
 						SupplyUnit:              supply_unit,
594
+						ManufacturerId:          manufacturer_id,
553 595
 					}
554 596
 					warehousingInfo = append(warehousingInfo, &order)
555 597
 				}
@@ -640,12 +682,767 @@ func (this *SupplyOrderApiController) AddGoodOrder() {
640 682
 		}
641 683
 		startTime = theTime.Unix()
642 684
 	}
643
-	good_number := this.GetString("good_number")
644
-	arrerage, _ := this.GetInt64("arrerage")
645
-	payment, _ := this.GetInt64("payment")
685
+	arrerage := this.GetString("arrerage")
686
+	arrerage_float, _ := strconv.ParseFloat(arrerage, 64)
687
+	payment := this.GetString("payment")
688
+	payment_float, _ := strconv.ParseFloat(payment, 64)
646 689
 	warehousing_id, _ := this.GetInt64("warehousing_id")
647 690
 	number := this.GetString("number")
648
-	rate_of_concession, _ := this.GetInt64("rate_of_concession")
649
-	discount_amount, _ := this.GetInt64("discount_amount")
650
-	fmt.Println(supplier_id, startTime, good_number, arrerage, payment, warehousing_id, number, rate_of_concession, discount_amount)
691
+	rate_of_concession := this.GetString("rate_of_concession")
692
+	rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
693
+	discount_amount := this.GetString("discount_amount")
694
+	discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
695
+	fmt.Println(supplier_id, startTime, arrerage, payment, warehousing_id, number, rate_of_concession, discount_amount)
696
+	orgId := this.GetAdminUserInfo().CurrentOrgId
697
+	creater := this.GetAdminUserInfo().AdminUser.Id
698
+	//生成购货单
699
+	timeStr := time.Now().Format("2006-01-02")
700
+	timeArr := strings.Split(timeStr, "-")
701
+	total, _ := service.FindAllSupplyWarehouseOutOrder(orgId)
702
+	total = total + 1
703
+	warehousing_order := "CG" + timeArr[0] + timeArr[1] + timeArr[2] + "00" + strconv.FormatInt(total, 10)
704
+	recordDateStr := time.Now().Format("2006-01-02")
705
+	recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
706
+
707
+	warehouse_out := models.SpSupplierWarehouseOut{
708
+		Number:           number,
709
+		UserOrgId:        orgId,
710
+		Creater:          creater,
711
+		Ctime:            time.Now().Unix(),
712
+		Mtime:            0,
713
+		Status:           1,
714
+		RecordDate:       recordDate.Unix(),
715
+		IsCheck:          2,
716
+		WarehousingId:    warehousing_id,
717
+		GoodNumber:       warehousing_order,
718
+		Arrearage:        arrerage_float,
719
+		Payment:          payment_float,
720
+		RateOfConcession: rate_of_concession_float,
721
+		DiscountAmount:   discount_amount_float,
722
+		DocumentDate:     startTime,
723
+		SupplierId:       supplier_id,
724
+		Checker:          0,
725
+		CheckTime:        0,
726
+	}
727
+
728
+	service.CreateSupplyWarehouseOut(warehouse_out)
729
+
730
+	//获取最后一条
731
+	warehouseOut, _ := service.FindSupplyWarehouseOutById(orgId)
732
+
733
+	dataBody := make(map[string]interface{}, 0)
734
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
735
+	if err != nil {
736
+		utils.ErrorLog(err.Error())
737
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
738
+		return
739
+	}
740
+	var warehousingOut []*models.SpSupplierWarehousingOutOrder
741
+	if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
742
+		thisStockIn, _ := dataBody["stockIn"].([]interface{})
743
+		if len(thisStockIn) > 0 {
744
+			for _, item := range thisStockIn {
745
+				items := item.(map[string]interface{})
746
+
747
+				if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
748
+					utils.ErrorLog("supply_count")
749
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
750
+					return
751
+				}
752
+				supply_count := int64(items["supply_count"].(float64))
753
+
754
+				if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
755
+					utils.ErrorLog("id")
756
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
757
+					return
758
+				}
759
+				id := int64(items["id"].(float64))
760
+
761
+				if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
762
+					utils.ErrorLog("manufacturer_id")
763
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
764
+					return
765
+				}
766
+				manufacturer_id := int64(items["manufacturer_id"].(float64))
767
+
768
+				if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
769
+					utils.ErrorLog("name")
770
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
771
+					return
772
+				}
773
+				name := items["name"].(string)
774
+
775
+				if items["order_number"] == nil || reflect.TypeOf(items["order_number"]).String() != "string" {
776
+					utils.ErrorLog("order_number")
777
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
778
+					return
779
+				}
780
+				order_number := items["order_number"].(string)
781
+
782
+				if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
783
+					utils.ErrorLog("supply_price")
784
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
785
+					return
786
+				}
787
+				supply_price := items["supply_price"].(string)
788
+
789
+				price_float, _ := strconv.ParseFloat(supply_price, 64)
790
+
791
+				if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
792
+					utils.ErrorLog("supply_total_price")
793
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
794
+					return
795
+				}
796
+				supply_total_price := items["supply_total_price"].(string)
797
+
798
+				supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
799
+
800
+				if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
801
+					utils.ErrorLog("project_id")
802
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
803
+					return
804
+				}
805
+				project_id := int64(items["project_id"].(float64))
806
+
807
+				if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
808
+					utils.ErrorLog("supply_remake")
809
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
810
+					return
811
+				}
812
+				supply_remake := items["supply_remake"].(string)
813
+
814
+				if items["supply_batch_number"] == nil || reflect.TypeOf(items["supply_batch_number"]).String() != "string" {
815
+					utils.ErrorLog("supply_batch_number")
816
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
817
+					return
818
+				}
819
+				supply_batch_number := items["supply_batch_number"].(string)
820
+
821
+				var supply_expiry_date_time int64
822
+				if items["supply_expiry_date"] == nil || reflect.TypeOf(items["supply_expiry_date"]).String() != "string" {
823
+					utils.ErrorLog("supply_expiry_date")
824
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
825
+					return
826
+				}
827
+				supply_expiry_date := items["supply_expiry_date"].(string)
828
+
829
+				if len(supply_expiry_date) > 0 {
830
+					theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_expiry_date+" 00:00:00", loc)
831
+					if err != nil {
832
+						this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
833
+						return
834
+					}
835
+					supply_expiry_date_time = theTime.Unix()
836
+				}
837
+
838
+				if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
839
+					utils.ErrorLog("supply_license_number")
840
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
841
+					return
842
+				}
843
+				supply_license_number := items["supply_license_number"].(string)
844
+
845
+				var supply_product_date_time int64
846
+				if items["supply_product_date"] == nil || reflect.TypeOf(items["supply_product_date"]).String() != "string" {
847
+					utils.ErrorLog("supply_product_date")
848
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
849
+					return
850
+				}
851
+				supply_product_date := items["supply_product_date"].(string)
852
+
853
+				if len(supply_product_date) > 0 {
854
+					theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_product_date+" 00:00:00", loc)
855
+					if err != nil {
856
+						this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
857
+						return
858
+					}
859
+					supply_product_date_time = theTime.Unix()
860
+				}
861
+
862
+				if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
863
+					utils.ErrorLog("supply_specification_name")
864
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
865
+					return
866
+				}
867
+				supply_specification_name := items["supply_specification_name"].(string)
868
+
869
+				if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
870
+					utils.ErrorLog("supply_total")
871
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
872
+					return
873
+				}
874
+				supply_total := items["supply_total"].(string)
875
+
876
+				if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
877
+					utils.ErrorLog("supply_type")
878
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
879
+					return
880
+				}
881
+				supply_type := items["supply_type"].(string)
882
+
883
+				if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
884
+					utils.ErrorLog("supply_unit")
885
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
886
+					return
887
+				}
888
+				supply_unit := items["supply_unit"].(string)
889
+
890
+				if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
891
+					utils.ErrorLog("type")
892
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
893
+					return
894
+				}
895
+				is_source := int64(items["type"].(float64))
896
+
897
+				if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
898
+					utils.ErrorLog("supply_manufacturer")
899
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
900
+					return
901
+				}
902
+				supply_manufacturer := items["supply_manufacturer"].(string)
903
+				order := models.SpSupplierWarehousingOutOrder{
904
+					OrderNumber:             order_number,
905
+					ProjectId:               project_id,
906
+					IsSource:                is_source,
907
+					Count:                   supply_count,
908
+					Amount:                  supply_total_price_float,
909
+					Price:                   price_float,
910
+					Remark:                  supply_remake,
911
+					IsCheck:                 2,
912
+					UserOrgId:               orgId,
913
+					Status:                  1,
914
+					Ctime:                   time.Now().Unix(),
915
+					Mtime:                   0,
916
+					WarehouseOutId:          warehouseOut.ID,
917
+					Type:                    1,
918
+					SupplyBatchNumber:       supply_batch_number,
919
+					SupplyProductDate:       supply_product_date_time,
920
+					SupplyExpiryDate:        supply_expiry_date_time,
921
+					WarehousingId:           warehousing_id,
922
+					WarehouseInfoId:         id,
923
+					SupplyType:              supply_type,
924
+					SupplyUnit:              supply_unit,
925
+					SupplyTotal:             supply_total,
926
+					SupplySpecificationName: supply_specification_name,
927
+					SupplyLicenseNumber:     supply_license_number,
928
+					Name:                    name,
929
+					ManufacturerId:          manufacturer_id,
930
+					GoodNumber:              warehouseOut.GoodNumber,
931
+					SupplyManufacturer:      supply_manufacturer,
932
+				}
933
+				warehousingOut = append(warehousingOut, &order)
934
+			}
935
+		}
936
+	}
937
+
938
+	for _, item := range warehousingOut {
939
+		//如果是手动新增的,type 等于2
940
+		if item.WarehouseInfoId == 0 {
941
+			item.Type = 2
942
+		}
943
+		err = service.CreateSupplyWarehousOutOrder(item)
944
+	}
945
+
946
+	list, parseDateErr := service.GetSupplyWarehouseOutById(warehouseOut.ID, orgId)
947
+
948
+	if parseDateErr == nil {
949
+		this.ServeSuccessJSON(map[string]interface{}{
950
+			"list":         list,
951
+			"warehouseOut": warehouseOut,
952
+		})
953
+	} else {
954
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
955
+	}
956
+}
957
+
958
+func (this *SupplyOrderApiController) GetAllGoodOderList() {
959
+
960
+	check_id, _ := this.GetInt64("check_id")
961
+	start_time := this.GetString("start_time")
962
+	end_time := this.GetString("end_time")
963
+	keyword := this.GetString("keyword")
964
+	page, _ := this.GetInt64("page")
965
+	limit, _ := this.GetInt64("limit")
966
+	timeLayout := "2006-01-02"
967
+	loc, _ := time.LoadLocation("Local")
968
+	var startTime int64
969
+	if len(start_time) > 0 {
970
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
971
+		if err != nil {
972
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
973
+			return
974
+		}
975
+		startTime = theTime.Unix()
976
+	}
977
+	var endTime int64
978
+	if len(end_time) > 0 {
979
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
980
+		if err != nil {
981
+			utils.ErrorLog(err.Error())
982
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
983
+			return
984
+		}
985
+		endTime = theTime.Unix()
986
+
987
+	}
988
+	orgId := this.GetAdminUserInfo().CurrentOrgId
989
+
990
+	list, total, err := service.GetAllGoodOderList(check_id, keyword, page, limit, startTime, endTime, orgId)
991
+	if err == nil {
992
+		this.ServeSuccessJSON(map[string]interface{}{
993
+			"list":  list,
994
+			"total": total,
995
+		})
996
+	} else {
997
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
998
+	}
999
+}
1000
+
1001
+func (this *SupplyOrderApiController) GetGoodOrderDetail() {
1002
+
1003
+	id, _ := this.GetInt64("id")
1004
+	orgId := this.GetAdminUserInfo().CurrentOrgId
1005
+	out, err := service.GetGoodOrderDetail(id, orgId)
1006
+	list, _ := service.GetSupplyWarehouseOutById(id, orgId)
1007
+	drugList, _ := service.GetSupplyDrugList(orgId)
1008
+	goodList, _ := service.GetSupplyGoodList(orgId)
1009
+	if err == nil {
1010
+		this.ServeSuccessJSON(map[string]interface{}{
1011
+			"out":      out,
1012
+			"list":     list,
1013
+			"goodList": goodList,
1014
+			"drugList": drugList,
1015
+		})
1016
+	} else {
1017
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1018
+	}
1019
+}
1020
+
1021
+func (this *SupplyOrderApiController) UpdateGoodOrder() {
1022
+	supplier_id, _ := this.GetInt64("supplier_id")
1023
+	start_time := this.GetString("start")
1024
+	timeLayout := "2006-01-02"
1025
+	loc, _ := time.LoadLocation("Local")
1026
+	var startTime int64
1027
+	if len(start_time) > 0 {
1028
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
1029
+		if err != nil {
1030
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1031
+			return
1032
+		}
1033
+		startTime = theTime.Unix()
1034
+	}
1035
+	arrerage := this.GetString("arrerage")
1036
+	arrerage_float, _ := strconv.ParseFloat(arrerage, 64)
1037
+	payment := this.GetString("payment")
1038
+	payment_float, _ := strconv.ParseFloat(payment, 64)
1039
+	warehose_out_id, _ := this.GetInt64("warehose_out_id")
1040
+	number := this.GetString("number")
1041
+	rate_of_concession := this.GetString("rate_of_concession")
1042
+	rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
1043
+	discount_amount := this.GetString("discount_amount")
1044
+	discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
1045
+	good_number := this.GetString("good_number")
1046
+	fmt.Println(supplier_id, startTime, arrerage, payment, warehose_out_id, number, rate_of_concession, discount_amount)
1047
+	orgId := this.GetAdminUserInfo().CurrentOrgId
1048
+	dataBody := make(map[string]interface{}, 0)
1049
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
1050
+	if err != nil {
1051
+		utils.ErrorLog(err.Error())
1052
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1053
+		return
1054
+	}
1055
+	var warehousingOut []*models.SpSupplierWarehousingOutOrder
1056
+	var updateWarehout []*models.SpSupplierWarehousingOutOrder
1057
+	if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
1058
+		thisStockIn, _ := dataBody["stockIn"].([]interface{})
1059
+		if len(thisStockIn) > 0 {
1060
+			for _, item := range thisStockIn {
1061
+				items := item.(map[string]interface{})
1062
+
1063
+				if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
1064
+					utils.ErrorLog("id")
1065
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1066
+					return
1067
+				}
1068
+				id := int64(items["id"].(float64))
1069
+
1070
+				if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
1071
+					utils.ErrorLog("supply_count")
1072
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1073
+					return
1074
+				}
1075
+				supply_count := int64(items["supply_count"].(float64))
1076
+
1077
+				if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
1078
+					utils.ErrorLog("manufacturer_id")
1079
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1080
+					return
1081
+				}
1082
+				manufacturer_id := int64(items["manufacturer_id"].(float64))
1083
+
1084
+				if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
1085
+					utils.ErrorLog("name")
1086
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1087
+					return
1088
+				}
1089
+				name := items["name"].(string)
1090
+
1091
+				if items["order_number"] == nil || reflect.TypeOf(items["order_number"]).String() != "string" {
1092
+					utils.ErrorLog("order_number")
1093
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1094
+					return
1095
+				}
1096
+				order_number := items["order_number"].(string)
1097
+
1098
+				if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
1099
+					utils.ErrorLog("supply_price")
1100
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1101
+					return
1102
+				}
1103
+				supply_price := items["supply_price"].(string)
1104
+
1105
+				price_float, _ := strconv.ParseFloat(supply_price, 64)
1106
+
1107
+				if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
1108
+					utils.ErrorLog("supply_total_price")
1109
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1110
+					return
1111
+				}
1112
+				supply_total_price := items["supply_total_price"].(string)
1113
+
1114
+				supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
1115
+
1116
+				if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
1117
+					utils.ErrorLog("project_id")
1118
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1119
+					return
1120
+				}
1121
+				project_id := int64(items["project_id"].(float64))
1122
+
1123
+				if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
1124
+					utils.ErrorLog("supply_remake")
1125
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1126
+					return
1127
+				}
1128
+				supply_remake := items["supply_remake"].(string)
1129
+
1130
+				if items["supply_batch_number"] == nil || reflect.TypeOf(items["supply_batch_number"]).String() != "string" {
1131
+					utils.ErrorLog("supply_batch_number")
1132
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1133
+					return
1134
+				}
1135
+				supply_batch_number := items["supply_batch_number"].(string)
1136
+
1137
+				var supply_expiry_date_time int64
1138
+				if items["supply_expiry_date"] == nil || reflect.TypeOf(items["supply_expiry_date"]).String() != "string" {
1139
+					utils.ErrorLog("supply_expiry_date")
1140
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1141
+					return
1142
+				}
1143
+				supply_expiry_date := items["supply_expiry_date"].(string)
1144
+
1145
+				if len(supply_expiry_date) > 0 {
1146
+					theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_expiry_date+" 00:00:00", loc)
1147
+					if err != nil {
1148
+						this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1149
+						return
1150
+					}
1151
+					supply_expiry_date_time = theTime.Unix()
1152
+				}
1153
+
1154
+				if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
1155
+					utils.ErrorLog("supply_license_number")
1156
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1157
+					return
1158
+				}
1159
+				supply_license_number := items["supply_license_number"].(string)
1160
+
1161
+				var supply_product_date_time int64
1162
+				if items["supply_product_date"] == nil || reflect.TypeOf(items["supply_product_date"]).String() != "string" {
1163
+					utils.ErrorLog("supply_product_date")
1164
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1165
+					return
1166
+				}
1167
+				supply_product_date := items["supply_product_date"].(string)
1168
+
1169
+				if len(supply_product_date) > 0 {
1170
+					theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_product_date+" 00:00:00", loc)
1171
+					if err != nil {
1172
+						this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1173
+						return
1174
+					}
1175
+					supply_product_date_time = theTime.Unix()
1176
+				}
1177
+
1178
+				if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
1179
+					utils.ErrorLog("supply_specification_name")
1180
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1181
+					return
1182
+				}
1183
+				supply_specification_name := items["supply_specification_name"].(string)
1184
+
1185
+				if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
1186
+					utils.ErrorLog("supply_total")
1187
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1188
+					return
1189
+				}
1190
+				supply_total := items["supply_total"].(string)
1191
+
1192
+				if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
1193
+					utils.ErrorLog("supply_type")
1194
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1195
+					return
1196
+				}
1197
+				supply_type := items["supply_type"].(string)
1198
+
1199
+				if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
1200
+					utils.ErrorLog("supply_unit")
1201
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1202
+					return
1203
+				}
1204
+				supply_unit := items["supply_unit"].(string)
1205
+
1206
+				if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
1207
+					utils.ErrorLog("type")
1208
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1209
+					return
1210
+				}
1211
+				is_source := int64(items["type"].(float64))
1212
+
1213
+				if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
1214
+					utils.ErrorLog("supply_manufacturer")
1215
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1216
+					return
1217
+				}
1218
+				supply_manufacturer := items["supply_manufacturer"].(string)
1219
+
1220
+				if items["warehouse_info_id"] == nil || reflect.TypeOf(items["warehouse_info_id"]).String() != "float64" {
1221
+					utils.ErrorLog("warehouse_info_id")
1222
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1223
+					return
1224
+				}
1225
+				warehouse_info_id := int64(items["warehouse_info_id"].(float64))
1226
+
1227
+				if items["warehousing_id"] == nil || reflect.TypeOf(items["warehousing_id"]).String() != "float64" {
1228
+					utils.ErrorLog("warehouse_info_id")
1229
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1230
+					return
1231
+				}
1232
+				warehousing_id := int64(items["warehousing_id"].(float64))
1233
+				if id > 0 {
1234
+					order := models.SpSupplierWarehousingOutOrder{
1235
+						ID:                      id,
1236
+						OrderNumber:             order_number,
1237
+						ProjectId:               project_id,
1238
+						IsSource:                is_source,
1239
+						Count:                   supply_count,
1240
+						Amount:                  supply_total_price_float,
1241
+						Price:                   price_float,
1242
+						Remark:                  supply_remake,
1243
+						IsCheck:                 2,
1244
+						UserOrgId:               orgId,
1245
+						Status:                  1,
1246
+						Ctime:                   time.Now().Unix(),
1247
+						Mtime:                   0,
1248
+						WarehouseOutId:          warehose_out_id,
1249
+						Type:                    1,
1250
+						SupplyBatchNumber:       supply_batch_number,
1251
+						SupplyProductDate:       supply_product_date_time,
1252
+						SupplyExpiryDate:        supply_expiry_date_time,
1253
+						SupplyType:              supply_type,
1254
+						SupplyUnit:              supply_unit,
1255
+						SupplyTotal:             supply_total,
1256
+						SupplySpecificationName: supply_specification_name,
1257
+						SupplyLicenseNumber:     supply_license_number,
1258
+						Name:                    name,
1259
+						ManufacturerId:          manufacturer_id,
1260
+						GoodNumber:              good_number,
1261
+						SupplyManufacturer:      supply_manufacturer,
1262
+						WarehouseInfoId:         warehouse_info_id,
1263
+						WarehousingId:           warehousing_id,
1264
+					}
1265
+					updateWarehout = append(updateWarehout, &order)
1266
+				}
1267
+
1268
+				if id == 0 {
1269
+					order := models.SpSupplierWarehousingOutOrder{
1270
+						OrderNumber:             order_number,
1271
+						ProjectId:               project_id,
1272
+						IsSource:                is_source,
1273
+						Count:                   supply_count,
1274
+						Amount:                  supply_total_price_float,
1275
+						Price:                   price_float,
1276
+						Remark:                  supply_remake,
1277
+						IsCheck:                 2,
1278
+						UserOrgId:               orgId,
1279
+						Status:                  1,
1280
+						Ctime:                   time.Now().Unix(),
1281
+						Mtime:                   0,
1282
+						WarehouseOutId:          warehose_out_id,
1283
+						Type:                    1,
1284
+						SupplyBatchNumber:       supply_batch_number,
1285
+						SupplyProductDate:       supply_product_date_time,
1286
+						SupplyExpiryDate:        supply_expiry_date_time,
1287
+						WarehouseInfoId:         id,
1288
+						SupplyType:              supply_type,
1289
+						SupplyUnit:              supply_unit,
1290
+						SupplyTotal:             supply_total,
1291
+						SupplySpecificationName: supply_specification_name,
1292
+						SupplyLicenseNumber:     supply_license_number,
1293
+						Name:                    name,
1294
+						ManufacturerId:          manufacturer_id,
1295
+						GoodNumber:              good_number,
1296
+						SupplyManufacturer:      supply_manufacturer,
1297
+					}
1298
+					warehousingOut = append(warehousingOut, &order)
1299
+				}
1300
+
1301
+			}
1302
+		}
1303
+	}
1304
+	out := models.SpSupplierWarehouseOut{
1305
+		Arrearage:        arrerage_float,
1306
+		Payment:          payment_float,
1307
+		RateOfConcession: rate_of_concession_float,
1308
+		DiscountAmount:   discount_amount_float,
1309
+		SupplierId:       supplier_id,
1310
+		DocumentDate:     startTime,
1311
+	}
1312
+	//更改购货单据
1313
+	service.UpdateGoodWarehouseOut(warehose_out_id, out)
1314
+
1315
+	for _, item := range warehousingOut {
1316
+		//如果是手动新增的,type 等于2
1317
+		if item.WarehouseInfoId == 0 {
1318
+			item.Type = 2
1319
+		}
1320
+		err = service.CreateSupplyWarehousOutOrder(item)
1321
+	}
1322
+	for _, item := range updateWarehout {
1323
+
1324
+		service.UpdateGoodWarehouseOutOrder(item)
1325
+	}
1326
+	if err == nil {
1327
+		this.ServeSuccessJSON(map[string]interface{}{
1328
+			"out": out,
1329
+		})
1330
+	} else {
1331
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1332
+	}
1333
+}
1334
+
1335
+func (this *SupplyOrderApiController) DeletePurchOrder() {
1336
+
1337
+	id, _ := this.GetInt64("id")
1338
+	orgId := this.GetAdminUserInfo().CurrentOrgId
1339
+	err := service.DeletePurchOrder(id, orgId)
1340
+	if err == nil {
1341
+		returnData := make(map[string]interface{}, 0)
1342
+		returnData["msg"] = "ok"
1343
+		this.ServeSuccessJSON(returnData)
1344
+		return
1345
+	} else {
1346
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1347
+	}
1348
+
1349
+}
1350
+
1351
+func (this *SupplyOrderApiController) GetAllOrderCountList() {
1352
+
1353
+	id, _ := this.GetInt64("id")
1354
+	orgId := this.GetAdminUserInfo().CurrentOrgId
1355
+	//获取购货订单的数据
1356
+	purcaseOrder, _ := service.GetAllPurcaseOrderById(id, orgId)
1357
+	//获取购货单的数据
1358
+	goodOrder, err := service.GetAllGoodOrderById(id, orgId)
1359
+	drugList, err := service.GetSupplyDrugList(orgId)
1360
+	if err == nil {
1361
+		this.ServeSuccessJSON(map[string]interface{}{
1362
+			"purcaseOrder": purcaseOrder,
1363
+			"goodOrder":    goodOrder,
1364
+			"drugList":     drugList,
1365
+		})
1366
+	} else {
1367
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1368
+	}
1369
+}
1370
+
1371
+func (this *SupplyOrderApiController) GetPurchOrderInfo() {
1372
+	id, _ := this.GetInt64("id")
1373
+	ids := this.GetString("ids")
1374
+	if len(ids) == 0 {
1375
+		info, _ := service.GetPurchaseOrderDetail(id)
1376
+		//查询
1377
+		orderInfo, err := service.GetSupplyWarehousingOrderInfo(id)
1378
+		orgId := this.GetAdminUserInfo().CurrentOrgId
1379
+		supplyList, _ := service.GetSupplierList(orgId)
1380
+		//获取药品库数据
1381
+		baseList, _ := service.GetSupplyDrugList(orgId)
1382
+
1383
+		goodList, _ := service.GetSupplyGoodList(orgId)
1384
+		if err == nil {
1385
+			this.ServeSuccessJSON(map[string]interface{}{
1386
+				"info":       info,
1387
+				"orderInfo":  orderInfo,
1388
+				"supplyList": supplyList,
1389
+				"baseList":   baseList,
1390
+				"goodList":   goodList,
1391
+			})
1392
+		} else {
1393
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1394
+		}
1395
+	}
1396
+	if len(ids) > 0 {
1397
+		idArray := strings.Split(ids, ",")
1398
+		info, _ := service.GetPurchaseOrderDetail(id)
1399
+		//查询
1400
+		orderInfo, err := service.GetSupplyWarehousingOrderInfoTwo(id, idArray)
1401
+		orgId := this.GetAdminUserInfo().CurrentOrgId
1402
+		supplyList, _ := service.GetSupplierList(orgId)
1403
+		//获取药品库数据
1404
+		baseList, _ := service.GetSupplyDrugList(orgId)
1405
+
1406
+		goodList, _ := service.GetSupplyGoodList(orgId)
1407
+		if err == nil {
1408
+			this.ServeSuccessJSON(map[string]interface{}{
1409
+				"info":       info,
1410
+				"orderInfo":  orderInfo,
1411
+				"supplyList": supplyList,
1412
+				"baseList":   baseList,
1413
+				"goodList":   goodList,
1414
+			})
1415
+		} else {
1416
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1417
+		}
1418
+	}
1419
+}
1420
+
1421
+func (this *SupplyOrderApiController) GetGoodOrderList() {
1422
+
1423
+	id, _ := this.GetInt64("id")
1424
+	orgId := this.GetAdminUserInfo().CurrentOrgId
1425
+	list, err := service.GetGoodOrderList(id, orgId)
1426
+	if err == nil {
1427
+		this.ServeSuccessJSON(map[string]interface{}{
1428
+			"list": list,
1429
+		})
1430
+	} else {
1431
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1432
+	}
1433
+}
1434
+
1435
+func (this *SupplyOrderApiController) GetReturnOrder() {
1436
+
1437
+	id, _ := this.GetInt64("id")
1438
+	orgId := this.GetAdminUserInfo().CurrentOrgId
1439
+	err := service.GetReturnOrder(id, orgId)
1440
+	if err == nil {
1441
+		returnData := make(map[string]interface{}, 0)
1442
+		returnData["msg"] = "ok"
1443
+		this.ServeSuccessJSON(returnData)
1444
+		return
1445
+	} else {
1446
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1447
+	}
651 1448
 }

+ 118 - 0
models/supply.models.go Wyświetl plik

@@ -112,6 +112,7 @@ type SupplierWarehousingInfoOrder struct {
112 112
 	SupplyManufacturer      string  `gorm:"column:supply_manufacturer" json:"supply_manufacturer" form:"supply_manufacturer"`
113 113
 	Name                    string  `gorm:"column:name" json:"name" form:"name"`
114 114
 	SupplyUnit              string  `gorm:"column:supply_unit" json:"supply_unit" form:"supply_unit"`
115
+	ManufacturerId          int64   `gorm:"column:manufacturer_id" json:"manufacturer_id" form:"manufacturer_id"`
115 116
 }
116 117
 
117 118
 func (SupplierWarehousingInfoOrder) TableName() string {
@@ -135,6 +136,7 @@ type SupplierWarehouseInfo struct {
135 136
 	SupplierId       int64   `gorm:"column:supplier_id" json:"supplier_id" form:"supplier_id"`
136 137
 	Checker          int64   `gorm:"column:checker" json:"checker" form:"checker"`
137 138
 	CheckTime        int64   `gorm:"column:check_time" json:"check_time" form:"check_time"`
139
+	IsWarehouse      int64   `gorm:"column:is_warehouse" json:"is_warehouse" form:"is_warehouse"`
138 140
 }
139 141
 
140 142
 func (SupplierWarehouseInfo) TableName() string {
@@ -158,9 +160,125 @@ type VmSupplierWarehouseInfo struct {
158 160
 	SupplierId                   int64                           `gorm:"column:supplier_id" json:"supplier_id" form:"supplier_id"`
159 161
 	Checker                      int64                           `gorm:"column:checker" json:"checker" form:"checker"`
160 162
 	CheckTime                    int64                           `gorm:"column:check_time" json:"check_time" form:"check_time"`
163
+	IsWarehouse                  int64                           `gorm:"column:is_warehouse" json:"is_warehouse" form:"is_warehouse"`
161 164
 	SupplierWarehousingInfoOrder []*SupplierWarehousingInfoOrder `gorm:"ForeignKey:WarehousingId;AssociationForeignKey:ID" json:"orderInfo"`
165
+	SpSupplierWarehouseOut       []*SpSupplierWarehouseOut       `gorm:"ForeignKey:WarehousingId;AssociationForeignKey:ID" json:"orderOut"`
162 166
 }
163 167
 
164 168
 func (VmSupplierWarehouseInfo) TableName() string {
165 169
 	return "xt_supplier_warehouse_info"
166 170
 }
171
+
172
+type SpSupplierWarehousingOutOrder struct {
173
+	ID                      int64   `gorm:"column:id" json:"id" form:"id"`
174
+	OrderNumber             string  `gorm:"column:order_number" json:"order_number" form:"order_number"`
175
+	ProjectId               int64   `gorm:"column:project_id" json:"project_id" form:"project_id"`
176
+	IsSource                int64   `gorm:"column:is_source" json:"is_source" form:"is_source"`
177
+	Count                   int64   `gorm:"column:count" json:"count" form:"count"`
178
+	Price                   float64 `gorm:"column:price" json:"price" form:"price"`
179
+	Amount                  float64 `gorm:"column:amount" json:"amount" form:"amount"`
180
+	Remark                  string  `gorm:"column:remark" json:"remark" form:"remark"`
181
+	IsCheck                 int64   `gorm:"column:is_check" json:"is_check" form:"is_check"`
182
+	UserOrgId               int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
183
+	Status                  int64   `gorm:"column:status" json:"status" form:"status"`
184
+	Ctime                   int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
185
+	Mtime                   int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
186
+	WarehouseOutId          int64   `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
187
+	Type                    int64   `gorm:"column:type" json:"type" form:"type"`
188
+	SupplyBatchNumber       string  `gorm:"column:supply_batch_number" json:"supply_batch_number" form:"supply_batch_number"`
189
+	SupplyProductDate       int64   `gorm:"column:supply_product_date" json:"supply_product_date" form:"supply_product_date"`
190
+	SupplyExpiryDate        int64   `gorm:"column:supply_expiry_date" json:"supply_expiry_date" form:"supply_expiry_date"`
191
+	WarehousingId           int64   `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
192
+	WarehouseInfoId         int64   `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
193
+	SupplyType              string  `gorm:"column:supply_type" json:"supply_type" form:"supply_type"`
194
+	SupplySpecificationName string  `gorm:"column:supply_specification_name" json:"supply_specification_name" form:"supply_specification_name"`
195
+	SupplyTotal             string  `gorm:"column:supply_total" json:"supply_total" form:"supply_total"`
196
+	SupplyManufacturer      string  `gorm:"column:supply_manufacturer" json:"supply_manufacturer" form:"supply_manufacturer"`
197
+	Name                    string  `gorm:"column:name" json:"name" form:"name"`
198
+	SupplyUnit              string  `gorm:"column:supply_unit" json:"supply_unit" form:"supply_unit"`
199
+	ManufacturerId          int64   `gorm:"column:manufacturer_id" json:"manufacturer_id" form:"manufacturer_id"`
200
+	SupplyLicenseNumber     string  `gorm:"column:supply_license_number" json:"supply_license_number" form:"supply_license_number"`
201
+	GoodNumber              string  `gorm:"column:good_number" json:"good_number" form:"good_number"`
202
+}
203
+
204
+func (SpSupplierWarehousingOutOrder) TableName() string {
205
+	return "xt_supplier_warehousing_out_order"
206
+}
207
+
208
+type SpSupplierWarehouseOut struct {
209
+	ID               int64   `gorm:"column:id" json:"id" form:"id"`
210
+	Number           string  `gorm:"column:number" json:"number" form:"number"`
211
+	UserOrgId        int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
212
+	Creater          int64   `gorm:"column:creater" json:"creater" form:"creater"`
213
+	Ctime            int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
214
+	Mtime            int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
215
+	Status           int64   `gorm:"column:status" json:"status" form:"status"`
216
+	RecordDate       int64   `gorm:"column:record_date" json:"record_date" form:"record_date"`
217
+	IsCheck          int64   `gorm:"column:is_check" json:"is_check" form:"is_check"`
218
+	WarehousingId    int64   `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
219
+	GoodNumber       string  `gorm:"column:good_number" json:"good_number" form:"good_number"`
220
+	Arrearage        float64 `gorm:"column:arrearage" json:"arrearage" form:"arrearage"`
221
+	Payment          float64 `gorm:"column:payment" json:"payment" form:"payment"`
222
+	RateOfConcession float64 `gorm:"column:rate_of_concession" json:"rate_of_concession" form:"rate_of_concession"`
223
+	DiscountAmount   float64 `gorm:"column:discount_amount" json:"discount_amount" form:"discount_amount"`
224
+	DocumentDate     int64   `gorm:"column:document_date" json:"document_date" form:"document_date"`
225
+	SupplierId       int64   `gorm:"column:supplier_id" json:"supplier_id" form:"supplier_id"`
226
+	Checker          int64   `gorm:"column:checker" json:"checker" form:"checker"`
227
+	CheckTime        int64   `gorm:"column:check_time" json:"check_time" form:"check_time"`
228
+}
229
+
230
+func (SpSupplierWarehouseOut) TableName() string {
231
+	return "xt_supplier_warehouse_out"
232
+}
233
+
234
+type VmSupplierWarehouseOut struct {
235
+	ID                            int64                            `gorm:"column:id" json:"id" form:"id"`
236
+	Number                        string                           `gorm:"column:number" json:"number" form:"number"`
237
+	UserOrgId                     int64                            `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
238
+	Creater                       int64                            `gorm:"column:creater" json:"creater" form:"creater"`
239
+	Ctime                         int64                            `gorm:"column:ctime" json:"ctime" form:"ctime"`
240
+	Mtime                         int64                            `gorm:"column:mtime" json:"mtime" form:"mtime"`
241
+	Status                        int64                            `gorm:"column:status" json:"status" form:"status"`
242
+	RecordDate                    int64                            `gorm:"column:record_date" json:"record_date" form:"record_date"`
243
+	IsCheck                       int64                            `gorm:"column:is_check" json:"is_check" form:"is_check"`
244
+	WarehousingId                 int64                            `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
245
+	GoodNumber                    string                           `gorm:"column:good_number" json:"good_number" form:"good_number"`
246
+	Arrearage                     float64                          `gorm:"column:arrearage" json:"arrearage" form:"arrearage"`
247
+	Payment                       float64                          `gorm:"column:payment" json:"payment" form:"payment"`
248
+	RateOfConcession              float64                          `gorm:"column:rate_of_concession" json:"rate_of_concession" form:"rate_of_concession"`
249
+	DiscountAmount                float64                          `gorm:"column:discount_amount" json:"discount_amount" form:"discount_amount"`
250
+	DocumentDate                  int64                            `gorm:"column:document_date" json:"document_date" form:"document_date"`
251
+	SupplierId                    int64                            `gorm:"column:supplier_id" json:"supplier_id" form:"supplier_id"`
252
+	Checker                       int64                            `gorm:"column:checker" json:"checker" form:"checker"`
253
+	CheckTime                     int64                            `gorm:"column:check_time" json:"check_time" form:"check_time"`
254
+	SpSupplierWarehousingOutOrder []*SpSupplierWarehousingOutOrder `gorm:"ForeignKey:warehouse_out_id;AssociationForeignKey:ID" json:"orderOut"`
255
+}
256
+
257
+func (VmSupplierWarehouseOut) TableName() string {
258
+	return "xt_supplier_warehouse_out"
259
+}
260
+
261
+type VSpSupplierWarehousingOutOrder struct {
262
+	ID          int64  `gorm:"column:id" json:"id" form:"id"`
263
+	OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
264
+	ProjectId   int64  `gorm:"column:project_id" json:"project_id" form:"project_id"`
265
+	Count       int64  `gorm:"column:count" json:"count" form:"count"`
266
+	Status      int64  `gorm:"column:status" json:"status" form:"status"`
267
+	SupplyUnit  string `gorm:"column:supply_unit" json:"supply_unit" form:"supply_unit"`
268
+	IsSource    int64  `gorm:"column:is_source" json:"is_source" form:"is_source"`
269
+}
270
+
271
+func (VSpSupplierWarehousingOutOrder) TableName() string {
272
+	return "xt_supplier_warehousing_out_order"
273
+}
274
+
275
+type VSupplierWarehousingInfoOrder struct {
276
+	Count      int64  `gorm:"column:count" json:"count" form:"count"`
277
+	ProjectId  int64  `gorm:"column:project_id" json:"project_id" form:"project_id"`
278
+	SupplyUnit string `gorm:"column:supply_unit" json:"supply_unit" form:"supply_unit"`
279
+	IsSource   int64  `gorm:"column:is_source" json:"is_source" form:"is_source"`
280
+}
281
+
282
+func (VSupplierWarehousingInfoOrder) TableName() string {
283
+	return "xt_supplier_warehousing_info_order"
284
+}

+ 1 - 1
service/patientmanage_service.go Wyświetl plik

@@ -439,7 +439,7 @@ func FindPatientByDialysisNoOne(orgID int64, dialysisNo string, id int64) (patie
439 439
 }
440 440
 
441 441
 func FindPatientByMobileOne(mobile string, orgID int64, id int64) (patient models.XtPatientsNew, err error) {
442
-	//err = readDb.Model(&models.Patients{}).Where(" status=1 and user_org_id=? and   phone=? and id<>?", orgID, mobile, id).First(&patient).Error
442
+	//err = readDb.Model(&models.XtPatientsNew{}).Where(" status=1 and user_org_id=? and   phone=? and id<>?", orgID, mobile, id).First(&patient).Error
443 443
 	//return
444 444
 	db := readDb.Table("xt_patients_new as x")
445 445
 	err = db.Not("phone = ?", mobile).Where("user_org_id = ? and id = ? and status =1", orgID, id).Find(&patient).Error

+ 124 - 9
service/supply_service.go Wyświetl plik

@@ -61,27 +61,27 @@ func CreateSupplyWarehousingOrder(order *models.SupplierWarehousingInfoOrder) er
61 61
 
62 62
 func GetAllPurchaseOrderList(check_id int64, startime int64, endtime int64, keyword string, page int64, limit int64, orgid int64) (info []*models.VmSupplierWarehouseInfo, total int64, err error) {
63 63
 
64
-	db := XTReadDB().Model(&info).Where("status = 1")
64
+	db := XTReadDB().Model(&info).Where("sgj_xt.xt_supplier_warehouse_info.status = 1")
65 65
 	likeKey := "%" + keyword + "%"
66 66
 	offset := (page - 1) * limit
67 67
 	if check_id > 0 {
68
-		db = db.Where("xt_supplier_warehouse_info.is_check = ?", check_id)
68
+		db = db.Where("sgj_xt.xt_supplier_warehouse_info.is_check = ?", check_id)
69 69
 	}
70 70
 	if startime > 0 {
71
-		db = db.Where("xt_supplier_warehouse_info.record_date >= ?", startime)
71
+		db = db.Where("sgj_xt.xt_supplier_warehouse_info.record_date >= ?", startime)
72 72
 	}
73 73
 	if endtime > 0 {
74
-		db = db.Where("xt_supplier_warehouse_info.record_date<=?", endtime)
74
+		db = db.Where("sgj_xt.xt_supplier_warehouse_info.record_date<=?", endtime)
75 75
 	}
76 76
 
77 77
 	if len(keyword) > 0 {
78
-		db.Joins("join xt_supplier_name on xt_supplier_name.id = xt_supplier_warehouse_info.supplier_id")
79
-		db = db.Where("xt_supplier_warehouse_info.number like ? or xt_supplier_name.supplier_name like ? ", likeKey, likeKey).Group("xt_supplier_warehouse_info.id")
78
+		db = db.Joins("join sgj_xt.xt_supplier_name on sgj_xt.xt_supplier_name.id = sgj_xt.xt_supplier_warehouse_info.supplier_id")
79
+		db = db.Where("sgj_xt.xt_supplier_warehouse_info.number like ? or sgj_xt.xt_supplier_name.supplier_name like ? ", likeKey, likeKey).Group("sgj_xt.xt_supplier_warehouse_info.id")
80 80
 	}
81 81
 	if orgid > 0 {
82
-		db = db.Where("xt_supplier_warehouse_info.user_org_id = ?", orgid)
82
+		db = db.Where("sgj_xt.xt_supplier_warehouse_info.user_org_id = ?", orgid)
83 83
 	}
84
-	err = db.Count(&total).Offset(offset).Limit(limit).Preload("SupplierWarehousingInfoOrder", "status= 1 and user_org_id = ?", orgid).Find(&info).Error
84
+	err = db.Count(&total).Offset(offset).Limit(limit).Preload("SupplierWarehousingInfoOrder", "status= 1 and user_org_id = ?", orgid).Preload("SpSupplierWarehouseOut", "status = 1 and user_org_id =?", orgid).Find(&info).Error
85 85
 	return info, total, err
86 86
 }
87 87
 
@@ -91,6 +91,12 @@ func GetSupplyWarehousingOrderInfo(id int64) (order []*models.SupplierWarehousin
91 91
 	return order, err
92 92
 }
93 93
 
94
+func GetSupplyWarehousingOrderInfoTwo(id int64, ids []string) (order []*models.SupplierWarehousingInfoOrder, err error) {
95
+
96
+	err = XTReadDB().Where("warehousing_id = ? and status = 1 and project_id in(?)", id, ids).Find(&order).Error
97
+	return order, err
98
+}
99
+
94 100
 func ModefySupplyWarehouseInfo(id int64, info models.SupplierWarehouseInfo) error {
95 101
 
96 102
 	err := XTWriteDB().Model(&models.SupplierWarehouseInfo{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"rate_of_concession": info.RateOfConcession, "discount_amount": info.DiscountAmount, "document_date": info.DocumentDate, "delivery_date": info.DeliveryDate, "supplier_id": info.SupplierId}).Error
@@ -99,7 +105,7 @@ func ModefySupplyWarehouseInfo(id int64, info models.SupplierWarehouseInfo) erro
99 105
 
100 106
 func ModifySupplyWarehouseOrder(order *models.SupplierWarehousingInfoOrder) error {
101 107
 
102
-	err := XTWriteDB().Model(&models.SupplierWarehousingInfoOrder{}).Where("id = ? and status = 1", order.ID).Updates(map[string]interface{}{}).Updates(map[string]interface{}{"is_source": order.IsSource, "count": order.Count, "price": order.Price, "amount": order.Amount, "remark": order.Remark, "project_id": order.ProjectId, "supply_license_number": order.SupplyLicenseNumber, "supply_type": order.SupplyType, "supply_specification_name": order.SupplySpecificationName, "supply_total": order.SupplyTotal, "supply_manufacturer": order.SupplyManufacturer, "name": order.Name, "supply_unit": order.SupplyUnit}).Error
108
+	err := XTWriteDB().Model(&models.SupplierWarehousingInfoOrder{}).Where("id = ? and status = 1", order.ID).Updates(map[string]interface{}{}).Updates(map[string]interface{}{"is_source": order.IsSource, "count": order.Count, "price": order.Price, "amount": order.Amount, "remark": order.Remark, "project_id": order.ProjectId, "supply_license_number": order.SupplyLicenseNumber, "supply_type": order.SupplyType, "supply_specification_name": order.SupplySpecificationName, "supply_total": order.SupplyTotal, "supply_manufacturer": order.SupplyManufacturer, "name": order.Name, "supply_unit": order.SupplyUnit, "manufacturer_id": order.ManufacturerId}).Error
103 109
 	return err
104 110
 }
105 111
 
@@ -115,3 +121,112 @@ func GetPurchaseOrderDetail(id int64) (models.SupplierWarehouseInfo, error) {
115 121
 	err := XTReadDB().Model(&info).Where("id =? and status =1", id).Find(&info).Error
116 122
 	return info, err
117 123
 }
124
+
125
+func FindAllSupplyWarehouseOutOrder(orgid int64) (total int64, err error) {
126
+	err = XTReadDB().Model(&models.SpSupplierWarehouseOut{}).Where("user_org_id = ? and status = 1", orgid).Count(&total).Error
127
+	return total, err
128
+}
129
+
130
+func FindSupplyWarehouseOutById(orgid int64) (models.SpSupplierWarehouseOut, error) {
131
+	out := models.SpSupplierWarehouseOut{}
132
+	err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Last(&out).Error
133
+	return out, err
134
+}
135
+
136
+func CreateSupplyWarehouseOut(out models.SpSupplierWarehouseOut) error {
137
+
138
+	err := XTWriteDB().Create(&out).Error
139
+	return err
140
+}
141
+
142
+func CreateSupplyWarehousOutOrder(order *models.SpSupplierWarehousingOutOrder) error {
143
+
144
+	err := XTWriteDB().Create(&order).Error
145
+	return err
146
+}
147
+
148
+func GetSupplyWarehouseOutById(id int64, user_org_id int64) (order []*models.SpSupplierWarehousingOutOrder, err error) {
149
+
150
+	err = XTReadDB().Where("warehouse_out_id = ? and status = 1 and user_org_id = ?", id, user_org_id).Find(&order).Error
151
+	return order, err
152
+}
153
+
154
+func GetAllGoodOderList(check_id int64, keyword string, page int64, limit int64, startime int64, endtime int64, orgid int64) (out []*models.VmSupplierWarehouseOut, total int64, err error) {
155
+	db := XTReadDB().Model(&out).Where("status = 1")
156
+	likeKey := "%" + keyword + "%"
157
+	offset := (page - 1) * limit
158
+	if check_id > 0 {
159
+		db = db.Where("xt_supplier_warehouse_out.is_check = ?", check_id)
160
+	}
161
+	if startime > 0 {
162
+		db = db.Where("xt_supplier_warehouse_out.record_date >= ?", startime)
163
+	}
164
+	if endtime > 0 {
165
+		db = db.Where("xt_supplier_warehouse_out.record_date<=?", endtime)
166
+	}
167
+
168
+	if len(keyword) > 0 {
169
+		db.Joins("join xt_supplier_name on xt_supplier_name.id = xt_supplier_warehouse_out.supplier_id")
170
+		db = db.Where("xt_supplier_warehouse_out.number like ? or xt_supplier_name.supplier_name like ? ", likeKey, likeKey).Group("xt_supplier_warehouse_out.id")
171
+	}
172
+	if orgid > 0 {
173
+		db = db.Where("xt_supplier_warehouse_out.user_org_id = ?", orgid)
174
+	}
175
+	err = db.Count(&total).Offset(offset).Limit(limit).Preload("SpSupplierWarehousingOutOrder", "status= 1 and user_org_id = ?", orgid).Find(&out).Error
176
+	return out, total, err
177
+}
178
+
179
+func GetGoodOrderDetail(id int64, orgid int64) (models.SpSupplierWarehouseOut, error) {
180
+	out := models.SpSupplierWarehouseOut{}
181
+	err := XTReadDB().Where("id = ? and user_org_id = ? and status = 1", id, orgid).Find(&out).Error
182
+	return out, err
183
+}
184
+
185
+func UpdateGoodWarehouseOut(id int64, out models.SpSupplierWarehouseOut) error {
186
+
187
+	err := XTWriteDB().Model(&out).Where("id=? and status = 1", id).Updates(map[string]interface{}{"arrearage": out.Arrearage, "payment": out.Payment, "rate_of_concession": out.RateOfConcession, "discount_amount": out.DiscountAmount, "document_date": out.DocumentDate}).Error
188
+	return err
189
+}
190
+
191
+func UpdateGoodWarehouseOutOrder(order *models.SpSupplierWarehousingOutOrder) error {
192
+
193
+	err := XTWriteDB().Model(&order).Where("id = ? and status = 1", order.ID).Updates(map[string]interface{}{"project_id": order.ProjectId, "is_source": order.IsSource, "count": order.Count, "price": order.Count, "amount": order.Amount, "remark": order.Amount, "supply_batch_number": order.SupplyBatchNumber, "supply_product_date": order.SupplyProductDate, "supply_expiry_date": order.SupplyExpiryDate, "supply_type": order.SupplyType, "supply_specification_name": order.SupplySpecificationName, "supply_total": order.SupplySpecificationName, "supply_manufacturer": order.SupplyManufacturer, "name": order.Name, "supply_unit": order.SupplyUnit, "manufacturer_id": order.ManufacturerId, "supply_license_number": order.SupplyLicenseNumber}).Error
194
+	return err
195
+}
196
+
197
+func DeletePurchOrder(id int64, orgid int64) error {
198
+
199
+	err := XTWriteDB().Model(&models.SupplierWarehouseInfo{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
200
+	err = XTWriteDB().Model(&models.SupplierWarehousingInfoOrder{}).Where("warehousing_id =? and user_org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
201
+	return err
202
+}
203
+
204
+func GetAllPurcaseOrderById(id int64, orgid int64) (order []*models.VSupplierWarehousingInfoOrder, err error) {
205
+
206
+	err = XTReadDB().Model(&order).Where("warehousing_id = ? and user_org_id = ? and status =1", id, orgid).Find(&order).Error
207
+	return order, err
208
+}
209
+
210
+func GetAllGoodOrderById(id int64, orgid int64) (order []*models.VSpSupplierWarehousingOutOrder, err error) {
211
+	db := XTReadDB().Table("xt_supplier_warehousing_out_order as o").Where("o.status = 1")
212
+	if id > 0 {
213
+		db = db.Where("o.warehousing_id = ?", id)
214
+	}
215
+	if orgid > 0 {
216
+		db = db.Where("o.user_org_id =?", orgid)
217
+	}
218
+	err = db.Select("o.id,o.order_number,o.project_id,o.count as count,o.supply_unit,o.is_source").Find(&order).Error
219
+	return order, err
220
+}
221
+
222
+func GetGoodOrderList(id int64, orgid int64) (info []*models.SpSupplierWarehouseOut, err error) {
223
+
224
+	err = XTReadDB().Where("warehousing_id = ? and status = 1 and user_org_id = ?", id, orgid).Find(&info).Error
225
+	return info, err
226
+}
227
+
228
+func GetReturnOrder(id int64, orgid int64) error {
229
+
230
+	err := XTWriteDB().Model(&models.SupplierWarehouseInfo{}).Where("id = ? and status = 1 and user_org_id = ?", id, orgid).Updates(map[string]interface{}{"is_check": 2, "mtime": time.Now().Unix(), "check_time": 0, "checker": 0}).Error
231
+	return err
232
+}