Ver código fonte

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

csx 3 anos atrás
pai
commit
365b65834f
3 arquivos alterados com 297 adições e 176 exclusões
  1. 242 168
      controllers/supply_order_api_contorller.go
  2. 10 8
      models/drug_stock.go
  3. 45 0
      service/supply_service.go

+ 242 - 168
controllers/supply_order_api_contorller.go Ver arquivo

@@ -1883,7 +1883,7 @@ func (this *SupplyOrderApiController) UpdateGoodOrder() {
1883 1883
 				warehouse_info_id := int64(items["warehouse_info_id"].(float64))
1884 1884
 
1885 1885
 				if items["warehousing_id"] == nil || reflect.TypeOf(items["warehousing_id"]).String() != "float64" {
1886
-					utils.ErrorLog("warehouse_info_id")
1886
+					utils.ErrorLog("warehousing_id")
1887 1887
 					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1888 1888
 					return
1889 1889
 				}
@@ -2645,6 +2645,14 @@ func (this *SupplyOrderApiController) SaveGoodReturnOrder() {
2645 2645
 
2646 2646
 	for _, item := range warehouseCancel {
2647 2647
 		service.CreateCancelReturnOrder(item)
2648
+		//查询该商品在退库单中是否存在
2649
+		_, errcodes := service.GetSupplyWarehouseOutIsExsit(item.WarehouseOutId, item.ProjectId, orgId)
2650
+		//如果不存在则情况退库单的关联信息
2651
+		if errcodes == gorm.ErrRecordNotFound {
2652
+			service.ModfySupplyCancel(item.WarehouseCancelId, orgId)
2653
+
2654
+		}
2655
+
2648 2656
 	}
2649 2657
 
2650 2658
 	cancelOrder, err := service.GetReturnCancelOrder(order.ID, orgId)
@@ -3139,185 +3147,251 @@ func (this *SupplyOrderApiController) CheckReturnOrder() {
3139 3147
 	orgId := this.GetAdminUserInfo().CurrentOrgId
3140 3148
 	record_date := recordDate.Unix()
3141 3149
 	checker := this.GetAdminUserInfo().AdminUser.Id
3142
-	cancel := models.SpSupplierWarehouseCancel{
3143
-		IsCheck:   1,
3144
-		Checker:   checker,
3145
-		CheckTime: record_date,
3146
-	}
3147
-	err := service.CheckReturnOrder(id, orgId, cancel)
3148
-	//审核成功,出库
3149
-	if err == nil {
3150
-		//获取退库单详情
3151
-		list, _ := service.GetSupplyCancelOrderDetail(id, orgId)
3152
-		for _, item := range list {
3153 3150
 
3154
-			//药品
3155
-			if item.IsSource == 1 {
3156
-				ctime := time.Now().Unix()
3157
-				timeStr := time.Now().Format("2006-01-02")
3158
-				timeArr := strings.Split(timeStr, "-")
3159
-				total, _ := service.FindAllDrugWarehouseOut(orgId)
3160
-
3161
-				total = total + 1
3162
-				warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
3163
-				number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
3164
-				number = number + total
3165
-				warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
3166
-				operation_time := time.Now().Unix()
3167
-				creater := this.GetAdminUserInfo().AdminUser.Id
3168
-				recordDateStr := time.Now().Format("2006-01-02")
3169
-				recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
3170
-				orgId := this.GetAdminUserInfo().CurrentOrgId
3171
-				record_date := recordDate.Unix()
3172
-				warehouseOut := models.DrugWarehouseOut{
3173
-					WarehouseOutOrderNumber: warehousing_out_order,
3174
-					OperationTime:           operation_time,
3175
-					OrgId:                   orgId,
3176
-					Creater:                 creater,
3177
-					Ctime:                   ctime,
3178
-					Status:                  1,
3179
-					WarehouseOutTime:        record_date,
3180
-					Type:                    1,
3181
-					SupplyCancelOutId:       id,
3182
-					SupplyWarehouseId:       warehouse_out_id,
3183
-				}
3184
-				// 查询今日是否存在出库单
3185
-				_, errcodes := service.GetDrugWarehouseOutById(orgId, record_date)
3186
-				if errcodes == gorm.ErrRecordNotFound {
3187
-					service.AddSigleDrugWarehouseOut(&warehouseOut)
3188
-				}
3151
+	//获取退库单详情
3152
+	list, _ := service.GetSupplyCancelOrderDetail(id, orgId)
3153
+	for _, item := range list {
3189 3154
 
3190
-				lastDrug, _ := service.GetLastDrugWarehouseById(orgId, record_date)
3155
+		var total_count int64
3156
+		var prescribing_number_total int64
3157
+		//药品
3158
+		if item.IsSource == 1 {
3191 3159
 
3192
-				//获取
3193
-				warehouseOutInfo := &models.DrugWarehouseOutInfo{
3160
+			//获取药品库存
3161
+			info, _ := service.GetDrugTotalCountTwenTy(item.ProjectId, item.SupplyWarehouseDetailInfo)
3194 3162
 
3195
-					WarehouseOutOrderNumber: lastDrug.WarehouseOutOrderNumber,
3196
-					WarehouseOutId:          lastDrug.ID,
3197
-					DrugId:                  item.ProjectId,
3198
-					Count:                   item.Count,
3199
-					Price:                   item.Price,
3200
-					Status:                  1,
3201
-					Ctime:                   ctime,
3202
-					Remark:                  "",
3203
-					OrgId:                   orgId,
3204
-					Type:                    1,
3205
-					Manufacturer:            item.ManufacturerId,
3206
-					Dealer:                  0,
3207
-					CountUnit:               item.SupplyUnit,
3208
-					ExpiryDate:              item.SupplyExpiryDate,
3209
-					ProductDate:             item.SupplyProductDate,
3210
-					Number:                  item.SupplyLicenseNumber,
3211
-					BatchNumber:             item.SupplyBatchNumber,
3212
-					IsSys:                   0,
3213
-					WarehouseInfoId:         0,
3214
-					SupplyCancelOutId:       id,
3215
-					SupplyWarehouseId:       warehouse_out_id,
3216
-				}
3217
-
3218
-				drup, _ := service.FindBaseDrugLibRecord(orgId, item.ProjectId)
3219
-				if drup.ID > 0 {
3220
-					prescribingNumber := item.Count
3221
-					service.AutoDrugDeliverInfoNight(orgId, prescribingNumber, &warehouseOut, &drup, warehouseOutInfo)
3222
-				}
3223
-
3224
-				//修改原数据
3225
-				orderInfo := models.SpSupplierWarehousingCancelOrder{
3226
-					SourceCount: item.Count - item.SourceCount,
3227
-				}
3228
-				service.UpdateSupplyCancelById(item.ID, orderInfo)
3163
+			for _, it := range info {
3164
+				total_count += it.StockMaxNumber*it.MinNumber + it.StockMinNumber
3229 3165
 			}
3166
+			//查询改药品信息
3167
+			medical, _ := service.GetBaseDrugMedical(item.ProjectId)
3230 3168
 
3231
-			//耗材
3232
-			if item.IsSource == 2 {
3169
+			//判断单位是否相等
3170
+			if medical.MaxUnit == item.SupplyUnit {
3171
+				//转化为最小单位
3172
+				prescribing_number_total = item.Count * medical.MinNumber
3173
+			}
3174
+			if medical.MinUnit == item.SupplyUnit {
3175
+				prescribing_number_total = item.Count
3176
+			}
3177
+
3178
+			//判断单位
3179
+			if total_count == 0 {
3180
+				goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
3181
+				this.ServeSuccessJSON(map[string]interface{}{
3182
+					"msg":        "3",
3183
+					"drug_name":  goodObj.DrugName,
3184
+					"dose":       goodObj.Dose,
3185
+					"dose_unit":  goodObj.DoseUnit,
3186
+					"min_number": goodObj.MinNumber,
3187
+					"min_unit":   goodObj.MinUnit,
3188
+					"max_unit":   goodObj.MaxUnit,
3189
+				})
3190
+				return
3191
+			}
3192
+
3193
+			if prescribing_number_total > total_count {
3194
+
3195
+				goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
3196
+				this.ServeSuccessJSON(map[string]interface{}{
3197
+					"msg":        "3",
3198
+					"drug_name":  goodObj.DrugName,
3199
+					"dose":       goodObj.Dose,
3200
+					"dose_unit":  goodObj.DoseUnit,
3201
+					"min_number": goodObj.MinNumber,
3202
+					"min_unit":   goodObj.MinUnit,
3203
+					"max_unit":   goodObj.MaxUnit,
3204
+				})
3205
+				return
3206
+			}
3207
+
3208
+			ctime := time.Now().Unix()
3209
+			timeStr := time.Now().Format("2006-01-02")
3210
+			timeArr := strings.Split(timeStr, "-")
3211
+			total, _ := service.FindAllDrugWarehouseOut(orgId)
3212
+
3213
+			total = total + 1
3214
+			warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
3215
+			number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
3216
+			number = number + total
3217
+			warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
3218
+			operation_time := time.Now().Unix()
3219
+			creater := this.GetAdminUserInfo().AdminUser.Id
3220
+			recordDateStr := time.Now().Format("2006-01-02")
3221
+			recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
3222
+			orgId := this.GetAdminUserInfo().CurrentOrgId
3223
+			record_date := recordDate.Unix()
3224
+			warehouseOut := models.DrugWarehouseOut{
3225
+				WarehouseOutOrderNumber: warehousing_out_order,
3226
+				OperationTime:           operation_time,
3227
+				OrgId:                   orgId,
3228
+				Creater:                 creater,
3229
+				Ctime:                   ctime,
3230
+				Status:                  1,
3231
+				WarehouseOutTime:        record_date,
3232
+				Type:                    1,
3233
+				SupplyCancelOutId:       id,
3234
+				SupplyWarehouseId:       warehouse_out_id,
3235
+			}
3236
+			// 查询今日是否存在出库单
3237
+			_, errcodes := service.GetDrugWarehouseOutById(orgId, record_date)
3238
+			if errcodes == gorm.ErrRecordNotFound {
3239
+				service.AddSigleDrugWarehouseOut(&warehouseOut)
3240
+			}
3241
+
3242
+			lastDrug, _ := service.GetLastDrugWarehouseById(orgId, record_date)
3243
+
3244
+			//获取
3245
+			warehouseOutInfo := &models.DrugWarehouseOutInfo{
3246
+
3247
+				WarehouseOutOrderNumber: lastDrug.WarehouseOutOrderNumber,
3248
+				WarehouseOutId:          lastDrug.ID,
3249
+				DrugId:                  item.ProjectId,
3250
+				Count:                   item.Count,
3251
+				Price:                   item.Price,
3252
+				Status:                  1,
3253
+				Ctime:                   ctime,
3254
+				Remark:                  "",
3255
+				OrgId:                   orgId,
3256
+				Type:                    1,
3257
+				Manufacturer:            item.ManufacturerId,
3258
+				Dealer:                  0,
3259
+				CountUnit:               item.SupplyUnit,
3260
+				ExpiryDate:              item.SupplyExpiryDate,
3261
+				ProductDate:             item.SupplyProductDate,
3262
+				Number:                  item.SupplyLicenseNumber,
3263
+				BatchNumber:             item.SupplyBatchNumber,
3264
+				IsSys:                   0,
3265
+				WarehouseInfoId:         0,
3266
+				SupplyCancelOutId:       id,
3267
+				SupplyWarehouseId:       warehouse_out_id,
3268
+			}
3269
+
3270
+			drup, _ := service.FindBaseDrugLibRecord(orgId, item.ProjectId)
3271
+			if drup.ID > 0 {
3272
+				prescribingNumber := item.Count
3273
+				service.AutoDrugDeliverInfoNight(orgId, prescribingNumber, &warehouseOut, &drup, warehouseOutInfo)
3274
+			}
3275
+
3276
+			//修改原数据
3277
+			orderInfo := models.SpSupplierWarehousingCancelOrder{
3278
+				SourceCount: item.Count - item.SourceCount,
3279
+			}
3280
+			service.UpdateSupplyCancelById(item.ID, orderInfo)
3281
+		}
3282
+
3283
+		//耗材
3284
+		if item.IsSource == 2 {
3285
+			// 查询该耗材是否有库存
3286
+			warehouseOne, _ := service.FindWarehousingInfoTwenTy(item.ProjectId, item.SupplyWarehouseDetailInfo)
3287
+
3288
+			// 如果出库数量大于该批次剩余库存数量
3289
+			if item.Count > warehouseOne.StockCount {
3233 3290
 
3234
-				ctime := time.Now().Unix()
3235
-
3236
-				timeStr := time.Now().Format("2006-01-02")
3237
-				timeArr := strings.Split(timeStr, "-")
3238
-				total, _ := service.FindAllWarehouseOut(orgId)
3239
-
3240
-				total = total + 1
3241
-				warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
3242
-				number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
3243
-				number = number + total
3244
-				warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
3245
-				operation_time := time.Now().Unix()
3246
-				creater := this.GetAdminUserInfo().AdminUser.Id
3247
-				recordDateStr := time.Now().Format("2006-01-02")
3248
-				recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
3249
-
3250
-				record_date := recordDate.Unix()
3251
-				warehouseOut := models.WarehouseOut{
3252
-					WarehouseOutOrderNumber: warehousing_out_order,
3253
-					OperationTime:           operation_time,
3254
-					OrgId:                   orgId,
3255
-					Creater:                 creater,
3256
-					Ctime:                   ctime,
3257
-					Status:                  1,
3258
-					WarehouseOutTime:        record_date,
3259
-					Type:                    1,
3260
-					SupplyCancelOutId:       id,
3261
-					SupplyWarehouseId:       warehouse_out_id,
3262
-					IsSys:                   0,
3263
-				}
3264
-				//查询是否生成出库单
3265
-				_, errcodes := service.FindStockOutByIsSys(orgId, 0, operation_time)
3266
-				if errcodes == gorm.ErrRecordNotFound {
3267
-					service.AddSigleWarehouseOut(&warehouseOut)
3268
-				}
3269
-				outWarehouse, _ := service.GetlastWarehouseOutById(orgId, record_date)
3270 3291
 				goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
3271
-				info := &models.WarehouseOutInfo{
3272
-					WarehouseOutOrderNumber: outWarehouse.WarehouseOutOrderNumber,
3273
-					WarehouseOutId:          outWarehouse.ID,
3274
-					WarehouseInfotId:        0,
3275
-					GoodId:                  item.ProjectId,
3276
-					GoodTypeId:              goodObj.GoodTypeId,
3277
-					Count:                   item.Count,
3278
-					Price:                   item.Price,
3279
-					TotalPrice:              0,
3280
-					ProductDate:             item.SupplyProductDate,
3281
-					ExpiryDate:              item.SupplyExpiryDate,
3282
-					Type:                    0,
3283
-					Dealer:                  0,
3284
-					Manufacturer:            item.ManufacturerId,
3285
-					IsSys:                   0,
3286
-					SysRecordTime:           record_date,
3287
-					Number:                  item.SupplyBatchNumber,
3288
-					LicenseNumber:           item.SupplyLicenseNumber,
3289
-					ConsumableType:          0,
3290
-					SupplyCancelOutId:       id,
3291
-					OrgId:                   orgId,
3292
-					SupplyWarehouseId:       warehouse_out_id,
3293
-				}
3294
-				//出库逻辑
3295
-				parseDateErr := service.ConsumablesDeliveryNight(orgId, record_date, info, &warehouseOut, item.Count, creater, warehouse_out_id, id)
3296
-
3297
-				if parseDateErr != nil {
3298
-					utils.ErrorLog(parseDateErr.Error())
3299
-					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
3300
-					return
3301
-				}
3302
-				//更改原退库数据
3303
-				order := models.SpSupplierWarehousingCancelOrder{
3304
-					SourceCount: item.SourceCount - item.Count,
3305
-				}
3306
-				service.UpdateSupplyCancelById(item.ID, order)
3292
+				this.ServeSuccessJSON(map[string]interface{}{
3293
+					"msg":                "2",
3294
+					"good_name":          goodObj.GoodName,
3295
+					"specification_name": goodObj.SpecificationName,
3296
+				})
3297
+				return
3298
+
3299
+			}
3300
+			ctime := time.Now().Unix()
3301
+
3302
+			timeStr := time.Now().Format("2006-01-02")
3303
+			timeArr := strings.Split(timeStr, "-")
3304
+			total, _ := service.FindAllWarehouseOut(orgId)
3305
+
3306
+			total = total + 1
3307
+			warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
3308
+			number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
3309
+			number = number + total
3310
+			warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
3311
+			operation_time := time.Now().Unix()
3312
+			creater := this.GetAdminUserInfo().AdminUser.Id
3313
+			recordDateStr := time.Now().Format("2006-01-02")
3314
+			recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
3315
+
3316
+			record_date := recordDate.Unix()
3317
+			warehouseOut := models.WarehouseOut{
3318
+				WarehouseOutOrderNumber: warehousing_out_order,
3319
+				OperationTime:           operation_time,
3320
+				OrgId:                   orgId,
3321
+				Creater:                 creater,
3322
+				Ctime:                   ctime,
3323
+				Status:                  1,
3324
+				WarehouseOutTime:        record_date,
3325
+				Type:                    1,
3326
+				SupplyCancelOutId:       id,
3327
+				SupplyWarehouseId:       warehouse_out_id,
3328
+				IsSys:                   0,
3329
+			}
3330
+			//查询是否生成出库单
3331
+			_, errcodes := service.FindStockOutByIsSys(orgId, 0, operation_time)
3332
+			if errcodes == gorm.ErrRecordNotFound {
3333
+				service.AddSigleWarehouseOut(&warehouseOut)
3334
+			}
3335
+			outWarehouse, _ := service.GetlastWarehouseOutById(orgId, record_date)
3336
+			goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
3337
+			info := &models.WarehouseOutInfo{
3338
+				WarehouseOutOrderNumber: outWarehouse.WarehouseOutOrderNumber,
3339
+				WarehouseOutId:          outWarehouse.ID,
3340
+				WarehouseInfotId:        0,
3341
+				GoodId:                  item.ProjectId,
3342
+				GoodTypeId:              goodObj.GoodTypeId,
3343
+				Count:                   item.Count,
3344
+				Price:                   item.Price,
3345
+				TotalPrice:              0,
3346
+				ProductDate:             item.SupplyProductDate,
3347
+				ExpiryDate:              item.SupplyExpiryDate,
3348
+				Type:                    0,
3349
+				Dealer:                  0,
3350
+				Manufacturer:            item.ManufacturerId,
3351
+				IsSys:                   0,
3352
+				SysRecordTime:           record_date,
3353
+				Number:                  item.SupplyBatchNumber,
3354
+				LicenseNumber:           item.SupplyLicenseNumber,
3355
+				ConsumableType:          0,
3356
+				SupplyCancelOutId:       id,
3357
+				OrgId:                   orgId,
3358
+				SupplyWarehouseId:       warehouse_out_id,
3359
+			}
3360
+			//出库逻辑
3361
+			parseDateErr := service.ConsumablesDeliveryNight(orgId, record_date, info, &warehouseOut, item.Count, creater, warehouse_out_id, id)
3362
+
3363
+			if parseDateErr != nil {
3364
+				utils.ErrorLog(parseDateErr.Error())
3365
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
3366
+				return
3367
+			}
3368
+			//更改原退库数据
3369
+			order := models.SpSupplierWarehousingCancelOrder{
3370
+				SourceCount: item.SourceCount - item.Count,
3307 3371
 			}
3372
+			service.UpdateSupplyCancelById(item.ID, order)
3308 3373
 		}
3309 3374
 	}
3375
+	cancel := models.SpSupplierWarehouseCancel{
3376
+		IsCheck:   1,
3377
+		Checker:   checker,
3378
+		CheckTime: record_date,
3379
+	}
3380
+	err := service.CheckReturnOrder(id, orgId, cancel)
3381
+
3382
+	if err == nil {
3383
+		this.ServeSuccessJSON(map[string]interface{}{
3384
+			"msg":        "1",
3385
+			"drug_name":  "",
3386
+			"dose":       "",
3387
+			"dose_unit":  "",
3388
+			"min_number": "",
3389
+			"min_unit":   "",
3390
+			"max_unit":   "",
3391
+		})
3392
+		return
3393
+	}
3310 3394
 
3311
-	this.ServeSuccessJSON(map[string]interface{}{
3312
-		"msg":        "1",
3313
-		"drug_name":  "",
3314
-		"dose":       "",
3315
-		"dose_unit":  "",
3316
-		"min_number": "",
3317
-		"min_unit":   "",
3318
-		"max_unit":   "",
3319
-	})
3320
-	return
3321 3395
 }
3322 3396
 
3323 3397
 func (this *SupplyOrderApiController) DeletePurchaseOrder() {

+ 10 - 8
models/drug_stock.go Ver arquivo

@@ -295,14 +295,16 @@ type VmDrugAutomaticReduceDetail struct {
295 295
 }
296 296
 
297 297
 type VmDrugWarehouseInfo struct {
298
-	DrugId         int64  `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
299
-	Count          int64  `gorm:"column:count" json:"count" form:"count"`
300
-	MaxUnit        string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
301
-	MinUnit        string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
302
-	CountUnit      string `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
303
-	StockMinNumber int64  `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
304
-	StockMaxNumber int64  `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
305
-	MinNumber      int64  `gorm:"column:min_number" json:"min_number" form:"min_number"`
298
+	DrugId                    int64  `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
299
+	Count                     int64  `gorm:"column:count" json:"count" form:"count"`
300
+	MaxUnit                   string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
301
+	MinUnit                   string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
302
+	CountUnit                 string `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
303
+	StockMinNumber            int64  `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
304
+	StockMaxNumber            int64  `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
305
+	MinNumber                 int64  `gorm:"column:min_number" json:"min_number" form:"min_number"`
306
+	SupplyWarehouseId         int64  `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
307
+	SupplyWarehouseDetailInfo int64  `gorm:"column:supply_warehouse_detail_info" json:"supply_warehouse_detail_info" form:"supply_warehouse_detail_info"`
306 308
 }
307 309
 
308 310
 type StDrugWarehouseOutInfo struct {

+ 45 - 0
service/supply_service.go Ver arquivo

@@ -2,6 +2,7 @@ package service
2 2
 
3 3
 import (
4 4
 	"XT_New/models"
5
+	"fmt"
5 6
 	"github.com/jinzhu/gorm"
6 7
 	"strings"
7 8
 	"time"
@@ -1009,3 +1010,47 @@ func ModfySupplyWarehouseOut(warehousing_id int64, orgid int64) error {
1009 1010
 	err := XTWriteDB().Model(&out).Where("warehousing_id = ? and user_org_id =? and status = 1", warehousing_id, orgid).Updates(map[string]interface{}{"warehousing_id": 0, "number": ""}).Error
1010 1011
 	return err
1011 1012
 }
1013
+
1014
+func FindWarehousingInfoTwenTy(goodId int64, supply_warehouse_detail_info int64) (models.WarehousingInfo, error) {
1015
+	info := models.WarehousingInfo{}
1016
+	err := XTReadDB().Select(" good_id,sum(stock_count) as stock_count").Where("good_id = ? and status = 1 and supply_warehouse_detail_info =?", goodId, supply_warehouse_detail_info).Find(&info).Error
1017
+	return info, err
1018
+}
1019
+
1020
+func GetDrugTotalCountTwenTy(drugid int64, supply_warehouse_detail_info int64) (list []*models.VmDrugWarehouseInfo, err error) {
1021
+
1022
+	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
1023
+	table := XTReadDB().Table("xt_base_drug as d").Where("d.status = 1")
1024
+	fmt.Println(table)
1025
+	if drugid > 0 {
1026
+		db = db.Where("x.drug_id = ?", drugid)
1027
+	}
1028
+	if supply_warehouse_detail_info > 0 {
1029
+		db = db.Where("x.supply_warehouse_detail_info = ?", supply_warehouse_detail_info)
1030
+	}
1031
+	err = db.Select("x.drug_id,x.stock_max_number,x.stock_min_number,d.min_number").Joins("left join xt_base_drug as d on d.id = x.drug_id").Scan(&list).Error
1032
+
1033
+	return list, err
1034
+}
1035
+
1036
+func GetSupplyWarehouseOutIsExsit(warehouse_out_id int64, project_id int64, orgid int64) (*models.SpSupplierWarehousingOutOrder, error) {
1037
+
1038
+	out := models.SpSupplierWarehousingOutOrder{}
1039
+	var err error
1040
+	err = XTReadDB().Where("warehouse_out_id = ? and project_id = ? and user_org_id = ? and status = 1", warehouse_out_id, project_id, orgid).Find(&out).Error
1041
+	if err == gorm.ErrRecordNotFound {
1042
+		return nil, err
1043
+	}
1044
+	if err != nil {
1045
+		return nil, err
1046
+	}
1047
+	return &out, nil
1048
+}
1049
+
1050
+func ModfySupplyCancel(id int64, orgid int64) error {
1051
+
1052
+	err := XTWriteDB().Model(models.SpSupplierWarehouseCancel{}).Where("id = ? and user_org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"warehouse_out_id": 0}).Error
1053
+
1054
+	err = XTWriteDB().Model(models.SpSupplierWarehousingCancelOrder{}).Where("warehouse_cancel_id = ? and user_org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"warehouse_info_id": 0, "warehouse_out_id": 0, "warehousing_id": 0, "good_number": "", "order_number": ""}).Error
1055
+	return err
1056
+}