Browse Source

11月8日库存管理

XMLWAN 2 years ago
parent
commit
bda987a629

+ 0 - 2
controllers/drug_stock_api_contorller.go View File

@@ -1337,8 +1337,6 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1337 1337
 
1338 1338
 	var warehousingOutInfo []*models.DrugWarehouseOutInfo
1339 1339
 
1340
-	//var drugFlow []*models.DrugFlow
1341
-
1342 1340
 	if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
1343 1341
 		thisStockIn, _ := dataBody["stockOut"].([]interface{})
1344 1342
 

+ 5 - 1
controllers/manager_center_api_controller.go View File

@@ -1495,6 +1495,8 @@ func (c *ManagerCenterApiController) CreateGoodInfo() {
1495 1495
 	packing_price, _ := c.GetFloat("packing_price")
1496 1496
 	min_unit := c.GetString("min_unit")
1497 1497
 	default_count_unit := c.GetString("default_count_unit")
1498
+	is_user, _ := c.GetInt64("is_user")
1499
+	fmt.Println("is_user23232332323232233323223232323", is_user)
1498 1500
 	adminUserInfo := c.GetAdminUserInfo()
1499 1501
 
1500 1502
 	totals := service.FindGoodInfoByNameTwo(specification_name, adminUserInfo.CurrentOrgId, good_id, good_name)
@@ -1555,6 +1557,7 @@ func (c *ManagerCenterApiController) CreateGoodInfo() {
1555 1557
 		MinUnit:                     min_unit,
1556 1558
 		RegisterNumber:              register_number,
1557 1559
 		ProvincesCode:               provinces_code,
1560
+		IsUser:                      is_user,
1558 1561
 	}
1559 1562
 	err, goodInfos := service.AddSigleGoodInfo(&goodInfo)
1560 1563
 	if err == nil {
@@ -1620,7 +1623,7 @@ func (c *ManagerCenterApiController) ModifyGoodInfo() {
1620 1623
 	min_unit := c.GetString("min_unit")
1621 1624
 	total, _ := c.GetFloat("total")
1622 1625
 	register_number := c.GetString("register_number")
1623
-
1626
+	is_user, _ := c.GetInt64("is_user")
1624 1627
 	adminUserInfo := c.GetAdminUserInfo()
1625 1628
 
1626 1629
 	goodInfo := models.GoodInfo{
@@ -1673,6 +1676,7 @@ func (c *ManagerCenterApiController) ModifyGoodInfo() {
1673 1676
 		MinUnit:                     min_unit,
1674 1677
 		Total:                       total,
1675 1678
 		RegisterNumber:              register_number,
1679
+		IsUser:                      is_user,
1676 1680
 	}
1677 1681
 
1678 1682
 	totals := service.FindGoodInfoByNameOne(specification_name, adminUserInfo.CurrentOrgId, good_id, id, good_name)

+ 272 - 3
controllers/supply_order_api_contorller.go View File

@@ -88,6 +88,15 @@ func SupplyOrderApiRegistRouters() {
88 88
 	beego.Router("/api/supply/deletegoodorder", &SupplyOrderApiController{}, "Get:DeleteGoodOrder")
89 89
 	//生成采购退货单数据
90 90
 	beego.Router("/api/supply/getsupplywarehouseoutbyid", &SupplyOrderApiController{}, "Get:GetSupplyWarehouseById")
91
+	//审核采购单
92
+	beego.Router("/api/supply/checkgoodorderbyid", &SupplyOrderApiController{}, "Get:CheckGoodOrderById")
93
+	//审核退货单
94
+	beego.Router("/api/supply/checkreturnorder", &SupplyOrderApiController{}, "Get:CheckReturnOrder")
95
+
96
+	//删除采购订单
97
+	beego.Router("api/supply/deletepurchaseorder", &SupplyOrderApiController{}, "Get:DeletePurchaseOrder")
98
+	//删除采购单
99
+	beego.Router("/api/supply/deletegoodorderbyid", &SupplyOrderApiController{}, "Get:DeleteGoodOrderById")
91 100
 }
92 101
 
93 102
 //获取供应商列表GetSupplyList
@@ -2099,14 +2108,14 @@ func (this *SupplyOrderApiController) GetGoodOrderCountList() {
2099 2108
 		service.CreateStockFlowOne(flow)
2100 2109
 	}
2101 2110
 	//创建入库单
2102
-	errs := service.CreateDrugWarehousingInfo(warehouseInfoDetail)
2111
+	errs := service.CreateDrugWarehousingInfoSix(warehouseInfoDetail)
2103 2112
 	fmt.Println(errs)
2104 2113
 	for _, items := range drugFlow {
2105 2114
 		drugWarehouseInfo, _ := service.GetLastDrugWarehouseInfo(items.DrugId)
2106 2115
 		items.WarehousingDetailId = drugWarehouseInfo.ID
2107 2116
 	}
2108 2117
 	//创建流水单
2109
-	service.CreateDrugFlow(drugFlow)
2118
+	service.CreateDrugFlowSix(drugFlow)
2110 2119
 
2111 2120
 	drugList, _ := service.GetSupplyDrugList(orgId)
2112 2121
 	if err == nil {
@@ -2147,7 +2156,7 @@ func (this *SupplyOrderApiController) SaveGoodReturnOrder() {
2147 2156
 	return_remark := dataBody["return_marke"].(string)
2148 2157
 
2149 2158
 	supplier_id, _ := this.GetInt64("supplier_id")
2150
-	start_time := this.GetString("start")
2159
+	start_time := this.GetString("start_time")
2151 2160
 	timeLayout := "2006-01-02"
2152 2161
 	loc, _ := time.LoadLocation("Local")
2153 2162
 	var startTime int64
@@ -2316,6 +2325,40 @@ func (this *SupplyOrderApiController) SaveGoodReturnOrder() {
2316 2325
 				}
2317 2326
 				supply_manufacturer := items["supply_manufacturer"].(string)
2318 2327
 
2328
+				if items["supply_batch_number"] == nil || reflect.TypeOf(items["supply_batch_number"]).String() != "string" {
2329
+					utils.ErrorLog("supply_batch_number")
2330
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2331
+					return
2332
+				}
2333
+				supply_batch_number := items["supply_batch_number"].(string)
2334
+
2335
+				if items["supply_product_date"] == nil || reflect.TypeOf(items["supply_product_date"]).String() != "float64" {
2336
+					utils.ErrorLog("supply_product_date")
2337
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2338
+					return
2339
+				}
2340
+				supply_product_date := int64(items["supply_product_date"].(float64))
2341
+
2342
+				if items["supply_expiry_date"] == nil || reflect.TypeOf(items["supply_expiry_date"]).String() != "float64" {
2343
+					utils.ErrorLog("supply_expiry_date")
2344
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2345
+					return
2346
+				}
2347
+				supply_expiry_date := int64(items["supply_expiry_date"].(float64))
2348
+
2349
+				if items["warehousing_id"] == nil || reflect.TypeOf(items["warehousing_id"]).String() != "float64" {
2350
+					utils.ErrorLog("warehousing_id")
2351
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2352
+					return
2353
+				}
2354
+				warehousing_id := int64(items["warehousing_id"].(float64))
2355
+
2356
+				if items["warehouse_info_id"] == nil || reflect.TypeOf(items["warehouse_info_id"]).String() != "float64" {
2357
+					utils.ErrorLog("warehouse_info_id")
2358
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2359
+					return
2360
+				}
2361
+				warehouse_info_id := int64(items["warehouse_info_id"].(float64))
2319 2362
 				cancelOrder := &models.SpSupplierWarehousingCancelOrder{
2320 2363
 					ManufacturerId:          manufacturer_id,
2321 2364
 					OrderNumber:             order_number,
@@ -2342,6 +2385,11 @@ func (this *SupplyOrderApiController) SaveGoodReturnOrder() {
2342 2385
 					Name:                    name,
2343 2386
 					SupplyUnit:              supply_unit,
2344 2387
 					SupplyLicenseNumber:     supply_license_number,
2388
+					SupplyBatchNumber:       supply_batch_number,
2389
+					SupplyExpiryDate:        supply_expiry_date,
2390
+					SupplyProductDate:       supply_product_date,
2391
+					WarehouseInfoId:         warehouse_info_id,
2392
+					WarehousingId:           warehousing_id,
2345 2393
 				}
2346 2394
 				warehouseCancel = append(warehouseCancel, cancelOrder)
2347 2395
 			}
@@ -2807,3 +2855,224 @@ func (this *SupplyOrderApiController) GetSupplyWarehouseById() {
2807 2855
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
2808 2856
 	}
2809 2857
 }
2858
+
2859
+func (this *SupplyOrderApiController) CheckGoodOrderById() {
2860
+
2861
+	id, _ := this.GetInt64("id")
2862
+	recordDateStr := time.Now().Format("2006-01-02")
2863
+	recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
2864
+
2865
+	record_date := recordDate.Unix()
2866
+	checker := this.GetAdminUserInfo().AdminUser.Id
2867
+
2868
+	out := models.SpSupplierWarehouseOut{
2869
+		IsCheck:   1,
2870
+		Checker:   checker,
2871
+		CheckTime: record_date,
2872
+	}
2873
+
2874
+	err := service.UpdateSupplyGoodOrder(id, out)
2875
+	if err == nil {
2876
+		this.ServeSuccessJSON(map[string]interface{}{
2877
+			"out": out,
2878
+		})
2879
+	} else {
2880
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
2881
+	}
2882
+}
2883
+
2884
+func (this *SupplyOrderApiController) CheckReturnOrder() {
2885
+
2886
+	id, _ := this.GetInt64("id")
2887
+	warehouse_out_id, _ := this.GetInt64("warehouse_out_id")
2888
+	recordDateStr := time.Now().Format("2006-01-02")
2889
+	recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
2890
+	orgId := this.GetAdminUserInfo().CurrentOrgId
2891
+	record_date := recordDate.Unix()
2892
+	checker := this.GetAdminUserInfo().AdminUser.Id
2893
+	cancel := models.SpSupplierWarehouseCancel{
2894
+		IsCheck:   1,
2895
+		Checker:   checker,
2896
+		CheckTime: record_date,
2897
+	}
2898
+	err := service.CheckReturnOrder(id, orgId, cancel)
2899
+	//审核成功,出库
2900
+	if err == nil {
2901
+		//获取退库单详情
2902
+		list, _ := service.GetSupplyCancelOrderDetail(id, orgId)
2903
+		for _, item := range list {
2904
+
2905
+			//药品
2906
+			if item.IsSource == 1 {
2907
+				ctime := time.Now().Unix()
2908
+				timeStr := time.Now().Format("2006-01-02")
2909
+				timeArr := strings.Split(timeStr, "-")
2910
+				total, _ := service.FindAllDrugWarehouseOut(orgId)
2911
+
2912
+				total = total + 1
2913
+				warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
2914
+				number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
2915
+				number = number + total
2916
+				warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
2917
+				operation_time := time.Now().Unix()
2918
+				creater := this.GetAdminUserInfo().AdminUser.Id
2919
+				recordDateStr := time.Now().Format("2006-01-02")
2920
+				recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
2921
+				orgId := this.GetAdminUserInfo().CurrentOrgId
2922
+				record_date := recordDate.Unix()
2923
+				warehouseOut := models.DrugWarehouseOut{
2924
+					WarehouseOutOrderNumber: warehousing_out_order,
2925
+					OperationTime:           operation_time,
2926
+					OrgId:                   orgId,
2927
+					Creater:                 creater,
2928
+					Ctime:                   ctime,
2929
+					Status:                  1,
2930
+					WarehouseOutTime:        record_date,
2931
+					Type:                    1,
2932
+				}
2933
+				// 查询今日是否存在出库单
2934
+				_, errcodes := service.GetDrugWarehouseOutById(orgId, record_date)
2935
+				if errcodes == gorm.ErrRecordNotFound {
2936
+					service.AddSigleDrugWarehouseOut(&warehouseOut)
2937
+				}
2938
+
2939
+				lastDrug, _ := service.GetLastDrugWarehouseById(orgId, record_date)
2940
+
2941
+				//获取
2942
+				warehouseOutInfo := &models.DrugWarehouseOutInfo{
2943
+
2944
+					WarehouseOutOrderNumber: lastDrug.WarehouseOutOrderNumber,
2945
+					WarehouseOutId:          lastDrug.ID,
2946
+					DrugId:                  item.ProjectId,
2947
+					Count:                   item.Count,
2948
+					Price:                   item.Price,
2949
+					Status:                  1,
2950
+					Ctime:                   ctime,
2951
+					Remark:                  "",
2952
+					OrgId:                   orgId,
2953
+					Type:                    1,
2954
+					Manufacturer:            item.ManufacturerId,
2955
+					Dealer:                  0,
2956
+					CountUnit:               item.SupplyUnit,
2957
+					ExpiryDate:              item.SupplyExpiryDate,
2958
+					ProductDate:             item.SupplyProductDate,
2959
+					Number:                  item.SupplyLicenseNumber,
2960
+					BatchNumber:             item.SupplyBatchNumber,
2961
+					IsSys:                   0,
2962
+					WarehouseInfoId:         0,
2963
+				}
2964
+
2965
+				drup, _ := service.FindBaseDrugLibRecord(orgId, item.ProjectId)
2966
+				if drup.ID > 0 {
2967
+					prescribingNumber := item.Count
2968
+					service.AutoDrugDeliverInfoNight(orgId, prescribingNumber, &warehouseOut, &drup, warehouseOutInfo)
2969
+				}
2970
+
2971
+			}
2972
+
2973
+			//耗材
2974
+			if item.IsSource == 2 {
2975
+
2976
+				ctime := time.Now().Unix()
2977
+
2978
+				timeStr := time.Now().Format("2006-01-02")
2979
+				timeArr := strings.Split(timeStr, "-")
2980
+				total, _ := service.FindAllWarehouseOut(orgId)
2981
+
2982
+				total = total + 1
2983
+				warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
2984
+				number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
2985
+				number = number + total
2986
+				warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
2987
+				operation_time := time.Now().Unix()
2988
+				creater := this.GetAdminUserInfo().AdminUser.Id
2989
+				recordDateStr := time.Now().Format("2006-01-02")
2990
+				recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
2991
+
2992
+				record_date := recordDate.Unix()
2993
+				warehouseOut := models.WarehouseOut{
2994
+					WarehouseOutOrderNumber: warehousing_out_order,
2995
+					OperationTime:           operation_time,
2996
+					OrgId:                   orgId,
2997
+					Creater:                 creater,
2998
+					Ctime:                   ctime,
2999
+					Status:                  1,
3000
+					WarehouseOutTime:        record_date,
3001
+					Type:                    1,
3002
+				}
3003
+				//查询是否生成出库单
3004
+				_, errcodes := service.FindStockOutByIsSys(orgId, 0, operation_time)
3005
+				if errcodes == gorm.ErrRecordNotFound {
3006
+					service.AddSigleWarehouseOut(&warehouseOut)
3007
+				}
3008
+				outWarehouse, _ := service.GetlastWarehouseOutById(orgId, record_date)
3009
+				info := &models.WarehouseOutInfo{
3010
+					WarehouseOutOrderNumber: outWarehouse.WarehouseOutOrderNumber,
3011
+					WarehouseOutId:          outWarehouse.ID,
3012
+					WarehouseInfotId:        0,
3013
+					GoodId:                  item.ProjectId,
3014
+					GoodTypeId:              0,
3015
+					Count:                   item.Count,
3016
+					Price:                   item.Price,
3017
+					TotalPrice:              0,
3018
+					ProductDate:             item.SupplyProductDate,
3019
+					ExpiryDate:              item.SupplyExpiryDate,
3020
+					Type:                    0,
3021
+					Dealer:                  0,
3022
+					Manufacturer:            item.ManufacturerId,
3023
+					IsSys:                   0,
3024
+					SysRecordTime:           record_date,
3025
+					Number:                  item.SupplyBatchNumber,
3026
+					LicenseNumber:           item.SupplyLicenseNumber,
3027
+					ConsumableType:          0,
3028
+					SupplyCancelOutId:       id,
3029
+				}
3030
+				//出库逻辑
3031
+				parseDateErr := service.ConsumablesDeliveryNight(orgId, record_date, info, &warehouseOut, item.Count, creater, warehouse_out_id, id)
3032
+				if parseDateErr != nil {
3033
+					utils.ErrorLog(parseDateErr.Error())
3034
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
3035
+					return
3036
+				}
3037
+			}
3038
+		}
3039
+	}
3040
+
3041
+	this.ServeSuccessJSON(map[string]interface{}{
3042
+		"msg":        "1",
3043
+		"drug_name":  "",
3044
+		"dose":       "",
3045
+		"dose_unit":  "",
3046
+		"min_number": "",
3047
+		"min_unit":   "",
3048
+		"max_unit":   "",
3049
+	})
3050
+	return
3051
+}
3052
+
3053
+func (this *SupplyOrderApiController) DeletePurchaseOrder() {
3054
+
3055
+	id, _ := this.GetInt64("id")
3056
+	err := service.DeletePurchaseOrder(id)
3057
+	if err == nil {
3058
+		returnData := make(map[string]interface{}, 0)
3059
+		returnData["msg"] = "ok"
3060
+		this.ServeSuccessJSON(returnData)
3061
+		return
3062
+	} else {
3063
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
3064
+	}
3065
+}
3066
+
3067
+func (this *SupplyOrderApiController) DeleteGoodOrderById() {
3068
+	id, _ := this.GetInt64("id")
3069
+	err := service.DeleteGoodOrderById(id)
3070
+	if err == nil {
3071
+		returnData := make(map[string]interface{}, 0)
3072
+		returnData["msg"] = "ok"
3073
+		this.ServeSuccessJSON(returnData)
3074
+		return
3075
+	} else {
3076
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
3077
+	}
3078
+}

+ 1 - 0
models/good_models.go View File

@@ -83,6 +83,7 @@ type GoodInfo struct {
83 83
 	CancelStockInfo             []*CancelStockInfo   `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"cancel_stock_info"`
84 84
 	RegisterNumber              string               `gorm:"column:register_number" json:"register_number" form:"register_number"`
85 85
 	GoodSotckInfo               []*GoodSotckInfo     `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_stock_in"`
86
+	IsUser                      int64                `gorm:"column:is_user" json:"is_user" form:"is_user"`
86 87
 }
87 88
 
88 89
 func (GoodInfo) TableName() string {

+ 1 - 0
models/stock_models.go View File

@@ -237,6 +237,7 @@ type WarehouseOutInfo struct {
237 237
 	LicenseNumber           string       `gorm:"column:license_number" json:"license_number" form:"license_number"`
238 238
 	ConsumableType          int64        `gorm:"column:consumable_type" json:"consumable_type" form:"consumable_type"`
239 239
 	ProjectId               int64        `gorm:"column:project_id" json:"project_id" form:"project_id"`
240
+	SupplyCancelOutId       int64        `gorm:"column:supply_cancel_out_id" json:"supply_cancel_out_id" form:"supply_cancel_out_id"`
240 241
 }
241 242
 
242 243
 func (WarehouseOutInfo) TableName() string {

+ 5 - 0
models/supply.models.go View File

@@ -357,6 +357,11 @@ type SpSupplierWarehousingCancelOrder struct {
357 357
 	Name                    string  `gorm:"column:name" json:"name" form:"name"`
358 358
 	SupplyUnit              string  `gorm:"column:supply_unit" json:"supply_unit" form:"supply_unit"`
359 359
 	SupplyLicenseNumber     string  `gorm:"column:supply_license_number" json:"supply_license_number" form:"supply_license_number"`
360
+	SupplyBatchNumber       string  `gorm:"column:supply_batch_number" json:"supply_batch_number" form:"supply_batch_number"`
361
+	SupplyProductDate       int64   `gorm:"column:supply_product_date" json:"supply_product_date" form:"supply_product_date"`
362
+	SupplyExpiryDate        int64   `gorm:"column:supply_expiry_date" json:"supply_expiry_date" form:"supply_expiry_date"`
363
+	WarehousingId           int64   `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
364
+	WarehouseInfoId         int64   `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
360 365
 }
361 366
 
362 367
 func (SpSupplierWarehousingCancelOrder) TableName() string {

+ 2 - 2
service/mobile_dialysis_service.go View File

@@ -2741,7 +2741,7 @@ func MobileGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64
2741 2741
 			return db.Preload("VMGoodInfo", "status = 1 AND org_id = ?", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND user_org_id = ? AND record_date = ?  AND count > 0 ", orgID, scheduleDate)
2742 2742
 		}).
2743 2743
 		Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
2744
-			return db.Preload("VMGoodInfo", "status = 1 AND org_id = ?  ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0)  ", orgID).Where("status = 1 AND org_id = ? AND count > 0 AND record_time >= ? AND record_time <= ?  ", orgID, scheduleDate, end_time).Group("patient_id,good_id")
2744
+			return db.Preload("VMGoodInfo", "status = 1 AND org_id = ?", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0)  ", orgID).Where("status = 1 AND org_id = ? AND count > 0 AND record_time >= ? AND record_time <= ?  ", orgID, scheduleDate, end_time).Group("patient_id,good_id")
2745 2745
 		}).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
2746 2746
 	if scheduleDate != 0 {
2747 2747
 		db = db.Where("schedule_date = ?", scheduleDate)
@@ -3433,7 +3433,7 @@ func GetHisProjectConfig(orgid int64) (models.XtHisProjectConfig, error) {
3433 3433
 
3434 3434
 func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
3435 3435
 	err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
3436
-		return db.Preload("GoodsType", "status = 1").Where("status = 1 ")
3436
+		return db.Preload("GoodsType", "status = 1").Where("status = 1 and is_user = 2")
3437 3437
 	}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND type = 3", org_id, record_date, patient_id).Find(&project).Error
3438 3438
 
3439 3439
 	return

+ 50 - 1
service/stock_service.go View File

@@ -196,6 +196,7 @@ func FindAllGoodInfoTotal(orgId int64) (total int64) {
196 196
 }
197 197
 
198 198
 func AddSigleGoodInfo(goodInfo *models.GoodInfo) (error, *models.GoodInfo) {
199
+	fmt.Println("goodino232323232323232323", goodInfo.IsUse)
199 200
 	err := writeDb.Create(&goodInfo).Error
200 201
 	return err, goodInfo
201 202
 
@@ -248,6 +249,7 @@ func ModifyGoodInfo(goodInfo *models.GoodInfo) (error, *models.GoodInfo) {
248 249
 		"min_unit":                       goodInfo.MinUnit,
249 250
 		"register_number":                goodInfo.RegisterNumber,
250 251
 		"provinces_code":                 goodInfo.ProvincesCode,
252
+		"is_user":                        goodInfo.IsUser,
251 253
 	}).Error
252 254
 
253 255
 	writeDb.Model(&models.WarehousingInfo{}).Where("good_id = ? AND org_id = ?", goodInfo.ID, goodInfo.OrgId).Updates(map[string]interface{}{"good_type_id": goodInfo.GoodTypeId})
@@ -361,7 +363,7 @@ func FindAllGoodTypeOne(org_id int64) (goodType []*models.GoodsType, err error)
361 363
 }
362 364
 
363 365
 func FindAllGoodInfo(org_id int64) (goodInfo []*models.GoodInfo, err error) {
364
-	err = XTReadDB().Model(&models.GoodInfo{}).Where("org_id = ? AND status = 1", org_id).Find(&goodInfo).Error
366
+	err = XTReadDB().Model(&models.GoodInfo{}).Where("org_id = ? AND status = 1 and is_user = 2", org_id).Find(&goodInfo).Error
365 367
 	return goodInfo, err
366 368
 }
367 369
 
@@ -498,6 +500,53 @@ func CreateDrugWarehousingInfo(warehousingInfo []*models.DrugWarehouseInfo) (err
498 500
 	return
499 501
 }
500 502
 
503
+func CreateDrugWarehousingInfoSix(warehousingInfo []*models.DrugWarehouseInfo) (err error) {
504
+	if len(warehousingInfo) > 0 {
505
+		utx := writeDb.Begin()
506
+		if len(warehousingInfo) > 0 {
507
+			thisSQL := "INSERT INTO xt_drug_warehouse_info (warehousing_id, drug_id, number, product_date,expiry_date,warehousing_count,price,total_price,dealer,manufacturer,remark,ctime,mtime,status,org_id,warehousing_order,type,retail_price,retail_total_price,stock_max_number,max_unit,min_unit,batch_number,stock_min_number,supply_warehouse_id) VALUES "
508
+			insertParams := make([]string, 0)
509
+			insertData := make([]interface{}, 0)
510
+			for _, info := range warehousingInfo {
511
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
512
+				insertData = append(insertData, info.WarehousingId)
513
+				insertData = append(insertData, info.DrugId)
514
+				insertData = append(insertData, info.Number)
515
+				insertData = append(insertData, info.ProductDate)
516
+				insertData = append(insertData, info.ExpiryDate)
517
+				insertData = append(insertData, info.WarehousingCount)
518
+				insertData = append(insertData, info.Price)
519
+				insertData = append(insertData, info.TotalPrice)
520
+				insertData = append(insertData, info.Dealer)
521
+				insertData = append(insertData, info.Manufacturer)
522
+				insertData = append(insertData, info.Remark)
523
+				insertData = append(insertData, info.Ctime)
524
+				insertData = append(insertData, info.Mtime)
525
+				insertData = append(insertData, info.Status)
526
+				insertData = append(insertData, info.OrgId)
527
+				insertData = append(insertData, info.WarehousingOrder)
528
+				insertData = append(insertData, info.Type)
529
+				insertData = append(insertData, info.RetailPrice)
530
+				insertData = append(insertData, info.RetailTotalPrice)
531
+				insertData = append(insertData, info.StockMaxNumber)
532
+				insertData = append(insertData, info.MaxUnit)
533
+				insertData = append(insertData, info.MinUnit)
534
+				insertData = append(insertData, info.BatchNumber)
535
+				insertData = append(insertData, info.StockMinNumber)
536
+				insertData = append(insertData, info.SupplyWarehouseId)
537
+			}
538
+			thisSQL += strings.Join(insertParams, ", ")
539
+			err = utx.Exec(thisSQL, insertData...).Error
540
+			if err != nil {
541
+				utx.Rollback()
542
+				return
543
+			}
544
+		}
545
+		utx.Commit()
546
+	}
547
+	return
548
+}
549
+
501 550
 func UpdateDrugInfo(warehousingInfo []*models.DrugWarehouseInfo) (err error) {
502 551
 	var total float64
503 552
 	var min_number int64

+ 110 - 1
service/supply_service.go View File

@@ -4,6 +4,7 @@ import (
4 4
 	"XT_New/models"
5 5
 	"github.com/jinzhu/gorm"
6 6
 	"strconv"
7
+	"strings"
7 8
 	"time"
8 9
 )
9 10
 
@@ -615,7 +616,7 @@ func GetAllGoodReturnOrderList(checkid int64, keyword string, page int64, limit
615 616
 		db = db.Where("sgj_xt.xt_supplier_warehouse_cancel.is_check = ?", checkid)
616 617
 	}
617 618
 	if len(keyword) > 0 {
618
-		db = db.Joins("join sgj_xt.xt_supplier_name on sgj_xt.xt_supplier_name.id = sgj_xt.xt_supplier_warehouse_out.supplier_id")
619
+		db = db.Joins("join sgj_xt.xt_supplier_name on sgj_xt.xt_supplier_name.id = sgj_xt.xt_supplier_warehouse_cancel.supplier_id")
619 620
 		db = db.Where("sgj_xt.xt_supplier_warehouse_cancel.number like ? or sgj_xt.xt_supplier_name.supplier_name  like ? ", likeKey, likeKey).Group("xt_supplier_warehouse_cancel.id")
620 621
 	}
621 622
 	if startime > 0 {
@@ -766,3 +767,111 @@ func GetGoodCanceListById(id int64, orgid int64) (cancel []*models.VmSpSupplierW
766 767
 	err = XTReadDB().Where("warehouse_out_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&cancel).Error
767 768
 	return cancel, err
768 769
 }
770
+
771
+func CreateDrugFlowSix(drugflow []*models.DrugFlow) (err error) {
772
+	if len(drugflow) > 0 {
773
+		utx := writeDb.Begin()
774
+		if len(drugflow) > 0 {
775
+			thisSQL := "INSERT INTO xt_drug_flow (warehousing_id, drug_id, number,batch_number,count,user_org_id,patient_id,system_time,consumable_type,is_sys,warehousing_order,warehouse_out_id,warehouse_out_order_number,is_edit,cancel_stock_id,cancel_order_number,manufacturer,dealer,creator,update_creator,status,ctime,mtime,price,warehousing_detail_id,warehouse_out_detail_id,cancel_out_detail_id,expire_date,product_date,max_unit,min_unit,supply_warehouse_id) VALUES "
776
+			insertParams := make([]string, 0)
777
+			insertData := make([]interface{}, 0)
778
+			for _, info := range drugflow {
779
+
780
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
781
+				insertData = append(insertData, info.WarehousingId)
782
+				insertData = append(insertData, info.DrugId)
783
+				insertData = append(insertData, info.Number)
784
+				insertData = append(insertData, info.BatchNumber)
785
+				insertData = append(insertData, info.Count)
786
+				insertData = append(insertData, info.UserOrgId)
787
+				insertData = append(insertData, info.PatientId)
788
+				insertData = append(insertData, info.SystemTime)
789
+				insertData = append(insertData, info.ConsumableType)
790
+				insertData = append(insertData, info.IsSys)
791
+				insertData = append(insertData, info.WarehousingOrder)
792
+				insertData = append(insertData, info.WarehouseOutId)
793
+				insertData = append(insertData, info.WarehouseOutOrderNumber)
794
+
795
+				insertData = append(insertData, info.IsEdit)
796
+				insertData = append(insertData, info.CancelStockId)
797
+				insertData = append(insertData, info.CancelOrderNumber)
798
+				insertData = append(insertData, info.Manufacturer)
799
+				insertData = append(insertData, info.Dealer)
800
+				insertData = append(insertData, info.Creator)
801
+				insertData = append(insertData, info.UpdateCreator)
802
+				insertData = append(insertData, info.Status)
803
+				insertData = append(insertData, info.Ctime)
804
+				insertData = append(insertData, info.Mtime)
805
+				insertData = append(insertData, info.Price)
806
+				insertData = append(insertData, info.WarehousingDetailId)
807
+				insertData = append(insertData, info.WarehouseOutDetailId)
808
+				insertData = append(insertData, info.CancelOutDetailId)
809
+				insertData = append(insertData, info.ExpireDate)
810
+				insertData = append(insertData, info.ProductDate)
811
+				insertData = append(insertData, info.MaxUnit)
812
+				insertData = append(insertData, info.MinUnit)
813
+				insertData = append(insertData, info.SupplyWarehouseId)
814
+			}
815
+			thisSQL += strings.Join(insertParams, ", ")
816
+			err = utx.Exec(thisSQL, insertData...).Error
817
+			if err != nil {
818
+				utx.Rollback()
819
+				return
820
+			}
821
+		}
822
+		utx.Commit()
823
+	}
824
+	return
825
+}
826
+
827
+func CheckReturnOrder(id int64, orgid int64, cancel models.SpSupplierWarehouseCancel) error {
828
+
829
+	err := XTWriteDB().Model(&cancel).Where("id = ? and user_org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"is_check": cancel.IsCheck, "checker": cancel.Checker, "check_time": cancel.CheckTime}).Error
830
+	return err
831
+}
832
+
833
+func GetSupplyCancelOrderDetail(id int64, orgid int64) (cancel []*models.SpSupplierWarehousingCancelOrder, err error) {
834
+
835
+	err = XTReadDB().Where("warehouse_cancel_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&cancel).Error
836
+	return cancel, err
837
+}
838
+
839
+func DeletePurchaseOrder(id int64) error {
840
+
841
+	err := XTWriteDB().Model(&models.SupplierWarehousingInfoOrder{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
842
+	return err
843
+}
844
+
845
+func DeleteGoodOrderById(id int64) error {
846
+
847
+	err := XTWriteDB().Model(&models.SpSupplierWarehousingOutOrder{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
848
+	return err
849
+}
850
+
851
+func GetlastWarehouseOutById(user_org_id int64, record_date int64) (models.WarehouseOut, error) {
852
+
853
+	out := models.WarehouseOut{}
854
+	err := XTReadDB().Where("org_id = ? and warehouse_out_time = ? and status = 1", user_org_id, record_date).Find(&out).Error
855
+	return out, err
856
+}
857
+
858
+func GetDrugWarehouseOutById(orgid int64, record_date int64) (*models.DrugWarehouseOut, error) {
859
+
860
+	out := models.DrugWarehouseOut{}
861
+	var err error
862
+	err = XTReadDB().Where("org_id = ? and warehouse_out_time = ?", orgid, record_date).Find(&out).Error
863
+	if err == gorm.ErrRecordNotFound {
864
+		return nil, err
865
+	}
866
+	if err != nil {
867
+		return nil, err
868
+	}
869
+	return &out, nil
870
+}
871
+
872
+func GetLastDrugWarehouseById(orgid int64, record_date int64) (models.DrugWarehouseOut, error) {
873
+
874
+	out := models.DrugWarehouseOut{}
875
+	err := XTReadDB().Where("org_id = ? and warehouse_out_time =? and status = 1", orgid, record_date).Find(&out).Error
876
+	return out, err
877
+}

+ 404 - 0
service/warhouse_service.go View File

@@ -1068,6 +1068,7 @@ func ConsumablesDeliveryTotal(orgID int64, patient_id int64, record_time int64,
1068 1068
 			}
1069 1069
 
1070 1070
 			ConsumablesDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
1071
+
1071 1072
 		}
1072 1073
 
1073 1074
 	}
@@ -2742,3 +2743,406 @@ func HisAuToReduce(orgID int64, prescribingNumber float64, warehouseout *models.
2742 2743
 
2743 2744
 	return
2744 2745
 }
2746
+
2747
+//采购管理耗材出库逻辑
2748
+func ConsumablesDeliveryNight(orgID int64, record_time int64, goods *models.WarehouseOutInfo, warehouseOut *models.WarehouseOut, count int64, creator int64, warehouse_out_id int64, cancel_out_id int64) (err error) {
2749
+
2750
+	var deliver_number int64 = 0
2751
+	var stock_number int64 = 0
2752
+	var maxNumber int64 = 0
2753
+
2754
+	deliver_number = goods.Count
2755
+
2756
+	// 根据先进先出原则,查询最先入库的批次,进行出库
2757
+
2758
+	// 如果没有对应的库存,则报错
2759
+	warehouse, err := FindFirstWarehousingInfoByStockNight(goods.GoodId, goods.GoodTypeId, warehouse_out_id)
2760
+	if err != nil {
2761
+
2762
+		return err
2763
+	}
2764
+
2765
+	stock_number = warehouse.StockCount
2766
+
2767
+	// 当库存数量大于或等于出库数量的话,则正常出库该批次
2768
+	if stock_number >= deliver_number {
2769
+
2770
+		warehouseOutInfo := &models.WarehouseOutInfo{
2771
+			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
2772
+			WarehouseOutId:          warehouseOut.ID,
2773
+			WarehouseInfotId:        warehouse.ID,
2774
+			Status:                  1,
2775
+			Ctime:                   time.Now().Unix(),
2776
+			Remark:                  goods.Remark,
2777
+			OrgId:                   orgID,
2778
+			Type:                    1,
2779
+			Manufacturer:            goods.Manufacturer,
2780
+			Dealer:                  goods.Dealer,
2781
+			IsSys:                   0,
2782
+			SysRecordTime:           record_time,
2783
+			GoodTypeId:              goods.GoodTypeId,
2784
+			GoodId:                  goods.GoodId,
2785
+			ExpiryDate:              goods.ExpiryDate,
2786
+			ProductDate:             goods.ProductDate,
2787
+			Number:                  warehouse.Number,
2788
+			Price:                   goods.Price,
2789
+			LicenseNumber:           goods.LicenseNumber,
2790
+		}
2791
+		warehouseOutInfo.Count = goods.Count
2792
+		//添加出库单详情
2793
+		errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
2794
+		if errOne != nil {
2795
+			return errOne
2796
+		}
2797
+
2798
+		stockFlow := models.VmStockFlow{
2799
+			WarehousingId:           warehouse.ID,
2800
+			GoodId:                  goods.GoodId,
2801
+			Number:                  warehouse.Number,
2802
+			LicenseNumber:           goods.LicenseNumber,
2803
+			Count:                   goods.Count,
2804
+			UserOrgId:               goods.OrgId,
2805
+			PatientId:               goods.PatientId,
2806
+			SystemTime:              record_time,
2807
+			ConsumableType:          2,
2808
+			IsSys:                   goods.IsSys,
2809
+			WarehousingOrder:        "",
2810
+			WarehouseOutId:          warehouseOut.ID,
2811
+			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
2812
+			IsEdit:                  1,
2813
+			CancelStockId:           0,
2814
+			CancelOrderNumber:       "",
2815
+			Manufacturer:            goods.Manufacturer,
2816
+			Dealer:                  goods.Dealer,
2817
+			Creator:                 creator,
2818
+			UpdateCreator:           0,
2819
+			Status:                  1,
2820
+			Ctime:                   time.Now().Unix(),
2821
+			Mtime:                   0,
2822
+			Price:                   warehouse.PackingPrice,
2823
+			WarehousingDetailId:     0,
2824
+			WarehouseOutDetailId:    warehouseOutInfo.ID,
2825
+			CancelOutDetailId:       0,
2826
+			ProductDate:             goods.ProductDate,
2827
+			ExpireDate:              goods.ExpiryDate,
2828
+		}
2829
+
2830
+		//创建出库流水
2831
+		CreateStockFlowOne(stockFlow)
2832
+
2833
+		maxNumber = goods.Count
2834
+
2835
+		if warehouse.StockCount < maxNumber {
2836
+			return errors.New("库存数量不足")
2837
+		}
2838
+
2839
+		warehouse.StockCount = warehouse.StockCount - maxNumber
2840
+		warehouse.Mtime = time.Now().Unix()
2841
+
2842
+		//扣减库存
2843
+		errThree := UpDateWarehouseInfoByStock(&warehouse)
2844
+
2845
+		if errThree != nil {
2846
+			return errThree
2847
+		}
2848
+
2849
+	} else {
2850
+
2851
+		// 当该批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
2852
+		warehouseOutInfo := &models.WarehouseOutInfo{
2853
+			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
2854
+			WarehouseOutId:          warehouseOut.ID,
2855
+			WarehouseInfotId:        warehouse.ID,
2856
+			Status:                  1,
2857
+			Ctime:                   time.Now().Unix(),
2858
+			Remark:                  goods.Remark,
2859
+			OrgId:                   orgID,
2860
+			Type:                    1,
2861
+			Manufacturer:            goods.Manufacturer,
2862
+			Dealer:                  goods.Dealer,
2863
+			IsSys:                   0,
2864
+			SysRecordTime:           record_time,
2865
+			GoodTypeId:              goods.GoodTypeId,
2866
+			GoodId:                  goods.GoodId,
2867
+			ExpiryDate:              goods.ExpiryDate,
2868
+			ProductDate:             goods.ProductDate,
2869
+			Number:                  warehouse.Number,
2870
+			Price:                   warehouse.PackingPrice,
2871
+			LicenseNumber:           goods.LicenseNumber,
2872
+		}
2873
+		warehouseOutInfo.Count = stock_number
2874
+
2875
+		//查询是否已经生成出库单
2876
+		info, errcodes := GetStockInRecoredByGoodIdOne(goods.GoodId, goods.GoodTypeId, goods.SysRecordTime, goods.OrgId)
2877
+		if errcodes == gorm.ErrRecordNotFound {
2878
+			//创建出库单
2879
+			errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
2880
+			if errOne != nil {
2881
+				return errOne
2882
+			}
2883
+		} else {
2884
+			warehouseOutInfo.Count = info.Count + stock_number
2885
+
2886
+			UpdateAutoMaticReduceDetailOne(goods.GoodId, goods.GoodTypeId, goods.SysRecordTime, goods.OrgId, warehouseOutInfo)
2887
+		}
2888
+
2889
+		stockFlow := models.VmStockFlow{
2890
+			WarehousingId:           warehouse.ID,
2891
+			GoodId:                  goods.GoodId,
2892
+			Number:                  warehouse.Number,
2893
+			LicenseNumber:           goods.LicenseNumber,
2894
+			Count:                   stock_number,
2895
+			UserOrgId:               goods.OrgId,
2896
+			PatientId:               0,
2897
+			SystemTime:              record_time,
2898
+			ConsumableType:          2,
2899
+			IsSys:                   0,
2900
+			WarehousingOrder:        "",
2901
+			WarehouseOutId:          warehouseOut.ID,
2902
+			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
2903
+			IsEdit:                  1,
2904
+			CancelStockId:           0,
2905
+			CancelOrderNumber:       "",
2906
+			Manufacturer:            goods.Manufacturer,
2907
+			Dealer:                  goods.Dealer,
2908
+			Creator:                 creator,
2909
+			UpdateCreator:           0,
2910
+			Status:                  1,
2911
+			Ctime:                   time.Now().Unix(),
2912
+			Mtime:                   0,
2913
+			Price:                   warehouse.PackingPrice,
2914
+			WarehousingDetailId:     0,
2915
+			WarehouseOutDetailId:    warehouseOutInfo.ID,
2916
+			CancelOutDetailId:       0,
2917
+			ProductDate:             goods.ProductDate,
2918
+			ExpireDate:              goods.ExpiryDate,
2919
+		}
2920
+
2921
+		//创建出库明细
2922
+		CreateStockFlowOne(stockFlow)
2923
+		// 出库完成后,要将该批次库存清零
2924
+		warehouse.StockCount = 0
2925
+		warehouse.Mtime = time.Now().Unix()
2926
+
2927
+		errThree := UpDateWarehouseInfoByStock(&warehouse)
2928
+
2929
+		if errThree != nil {
2930
+			return errThree
2931
+		}
2932
+		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
2933
+		goods.Count = deliver_number - stock_number
2934
+
2935
+		ConsumablesDeliveryNight(orgID, record_time, goods, warehouseOut, count, creator, warehouse_out_id, cancel_out_id)
2936
+
2937
+	}
2938
+	return nil
2939
+}
2940
+
2941
+func FindFirstWarehousingInfoByStockNight(good_id int64, good_type_id int64, warehouse_out_id int64) (info models.WarehousingInfo, err error) {
2942
+	err = readDb.Model(&models.WarehousingInfo{}).Where("good_id = ? AND good_type_id = ? AND status = 1 and stock_count > 0 and supply_warehouse_id = ?", good_id, good_type_id, warehouse_out_id).Order("ctime").First(&info).Error
2943
+	return info, err
2944
+}
2945
+
2946
+// 药品出库 递归方式
2947
+func AutoDrugDeliverInfoNight(orgID int64, prescribingNumber int64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.DrugWarehouseOutInfo) (err error) {
2948
+
2949
+	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
2950
+	var deliver_number int64 = 0
2951
+	var stock_number int64 = 0
2952
+
2953
+	if advice.CountUnit == drup.MaxUnit {
2954
+		deliver_number = prescribingNumber * drup.MinNumber
2955
+	} else {
2956
+		deliver_number = prescribingNumber
2957
+	}
2958
+
2959
+	// 根据先进先出原则,查询最先入库的批次,进行出库
2960
+	// 如果没有对应的库存,则报错
2961
+	//开启事物
2962
+
2963
+	warehouse, err := FindLastDrugWarehousingInfoByID(advice.DrugId)
2964
+
2965
+	if err != nil {
2966
+
2967
+		return err
2968
+	}
2969
+
2970
+	// 将该批次的剩余库存数量转换为拆零数量
2971
+
2972
+	stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
2973
+
2974
+	// 当库存数量大于或等于出库数量的话,则正常出库该批次
2975
+	if stock_number >= deliver_number {
2976
+
2977
+		warehouseOutInfo := &models.DrugWarehouseOutInfo{
2978
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
2979
+			WarehouseOutId:          warehouseout.ID,
2980
+			Status:                  1,
2981
+			Ctime:                   time.Now().Unix(),
2982
+			Remark:                  advice.Remark,
2983
+			OrgId:                   orgID,
2984
+			Type:                    1,
2985
+			Manufacturer:            advice.Manufacturer,
2986
+			Dealer:                  warehouse.Dealer,
2987
+			IsSys:                   0,
2988
+			SysRecordTime:           advice.Ctime,
2989
+			DrugId:                  advice.DrugId,
2990
+			ExpiryDate:              advice.ExpiryDate,
2991
+			ProductDate:             advice.ProductDate,
2992
+			Number:                  advice.Number,
2993
+			BatchNumber:             warehouse.BatchNumber,
2994
+			Count:                   deliver_number,
2995
+			RetailPrice:             advice.RetailPrice,
2996
+			Price:                   advice.Price,
2997
+			WarehouseInfoId:         warehouse.ID,
2998
+			CountUnit:               drup.MinUnit,
2999
+			AdviceId:                advice.ID,
3000
+		}
3001
+
3002
+		warehouseOutInfo.Count = prescribingNumber
3003
+		warehouseOutInfo.CountUnit = advice.CountUnit
3004
+
3005
+		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
3006
+		if errOne != nil {
3007
+			return errOne
3008
+		}
3009
+
3010
+		drugWareInfo, _ := GetLastWarehouseOutInfoById(advice.DrugId)
3011
+		drugflow := models.DrugFlow{
3012
+			WarehouseOutId:          warehouseout.ID,
3013
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
3014
+			DrugId:                  advice.DrugId,
3015
+			Number:                  warehouse.Number,
3016
+			ProductDate:             advice.ProductDate,
3017
+			ExpireDate:              advice.ExpiryDate,
3018
+			Count:                   deliver_number,
3019
+			Price:                   advice.Price,
3020
+			Status:                  1,
3021
+			Ctime:                   time.Now().Unix(),
3022
+			UserOrgId:               advice.OrgId,
3023
+			Manufacturer:            advice.Manufacturer,
3024
+			Dealer:                  advice.Dealer,
3025
+			BatchNumber:             warehouse.BatchNumber,
3026
+			MaxUnit:                 drup.MinUnit,
3027
+			ConsumableType:          2,
3028
+			IsEdit:                  1,
3029
+			Creator:                 0,
3030
+			IsSys:                   0,
3031
+			WarehouseOutDetailId:    drugWareInfo.ID,
3032
+			AdviceId:                advice.ID,
3033
+		}
3034
+
3035
+		CreateDrugFlowOne(drugflow)
3036
+		// 出库完成后,要减去对应批次的库存数量
3037
+		// 判断处方里药品单位是拆零单位还是包装单位,	如果是拆零单位,则根据规格,将拆零数量转为包装数量
3038
+		var maxNumber int64 = 0
3039
+		var minNumber int64 = 0
3040
+		if advice.CountUnit == drup.MinUnit {
3041
+			maxNumber = prescribingNumber / drup.MinNumber
3042
+			minNumber = prescribingNumber % drup.MinNumber
3043
+		} else {
3044
+			maxNumber = prescribingNumber
3045
+		}
3046
+
3047
+		if warehouse.StockMaxNumber < maxNumber {
3048
+
3049
+			return errors.New("库存数量不足")
3050
+		}
3051
+
3052
+		warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
3053
+		warehouse.Mtime = time.Now().Unix()
3054
+
3055
+		if warehouse.StockMinNumber < minNumber {
3056
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
3057
+			warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
3058
+		} else {
3059
+			warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
3060
+		}
3061
+
3062
+		if warehouse.StockMaxNumber < 0 {
3063
+			return errors.New("库存数量不足")
3064
+		}
3065
+
3066
+		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
3067
+		if errThree != nil {
3068
+			return errThree
3069
+		}
3070
+
3071
+		return nil
3072
+	} else {
3073
+		// 当该批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
3074
+		warehouseOutInfo := &models.DrugWarehouseOutInfo{
3075
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
3076
+			WarehouseOutId:          warehouseout.ID,
3077
+			Status:                  1,
3078
+			Ctime:                   time.Now().Unix(),
3079
+			Remark:                  advice.Remark,
3080
+			OrgId:                   orgID,
3081
+			Type:                    1,
3082
+			Manufacturer:            advice.Manufacturer,
3083
+			Dealer:                  warehouse.Dealer,
3084
+			IsSys:                   0,
3085
+			SysRecordTime:           advice.Ctime,
3086
+			DrugId:                  advice.DrugId,
3087
+			ExpiryDate:              warehouse.ExpiryDate,
3088
+			ProductDate:             warehouse.ProductDate,
3089
+			Number:                  warehouse.Number,
3090
+			BatchNumber:             warehouse.BatchNumber,
3091
+			Count:                   stock_number,
3092
+			RetailPrice:             advice.RetailPrice,
3093
+			Price:                   advice.Price,
3094
+			WarehouseInfoId:         warehouse.ID,
3095
+			CountUnit:               drup.MinUnit,
3096
+			AdviceId:                advice.ID,
3097
+		}
3098
+		warehouseOutInfo.Count = stock_number
3099
+
3100
+		//warehouseOutInfo.CountUnit = advice.CountUnit
3101
+
3102
+		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
3103
+		if errOne != nil {
3104
+			return errOne
3105
+		}
3106
+		drugWareInfo, _ := GetLastWarehouseOutInfoById(advice.DrugId)
3107
+		drugflow := models.DrugFlow{
3108
+			WarehouseOutId:          warehouseout.ID,
3109
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
3110
+			DrugId:                  advice.DrugId,
3111
+			Number:                  warehouse.Number,
3112
+			ProductDate:             advice.ProductDate,
3113
+			ExpireDate:              advice.ExpiryDate,
3114
+			Count:                   stock_number,
3115
+			Price:                   advice.Price,
3116
+			Status:                  1,
3117
+			Ctime:                   time.Now().Unix(),
3118
+			UserOrgId:               advice.OrgId,
3119
+			Manufacturer:            advice.Manufacturer,
3120
+			Dealer:                  advice.Dealer,
3121
+			BatchNumber:             warehouse.BatchNumber,
3122
+			MaxUnit:                 drup.MinUnit,
3123
+			ConsumableType:          2,
3124
+			IsEdit:                  1,
3125
+			Creator:                 0,
3126
+			IsSys:                   0,
3127
+			WarehouseOutDetailId:    drugWareInfo.ID,
3128
+			AdviceId:                advice.ID,
3129
+		}
3130
+		CreateDrugFlowOne(drugflow)
3131
+		// 出库完成后,要将该批次库存清零
3132
+		warehouse.StockMaxNumber = 0
3133
+		warehouse.StockMinNumber = 0
3134
+		warehouse.Mtime = time.Now().Unix()
3135
+		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
3136
+		if errThree != nil {
3137
+			return errThree
3138
+		}
3139
+		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
3140
+		prescribingNumber_two_temp := deliver_number - stock_number
3141
+		fmt.Println("剩余库存323323223232323232323323223", prescribingNumber_two_temp)
3142
+		advice.CountUnit = drup.MinUnit
3143
+
3144
+		AutoDrugDeliverInfoNight(orgID, prescribingNumber_two_temp, warehouseout, drup, advice)
3145
+	}
3146
+
3147
+	return
3148
+}