|
@@ -743,7 +743,7 @@ func FindDrugWarehousingInfoByIdOne(id []string, org_id int64) (list []*models.S
|
743
|
743
|
if org_id > 0 {
|
744
|
744
|
db = db.Where("x.org_id = ?", org_id)
|
745
|
745
|
}
|
746
|
|
- err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.max_unit,x.min_unit,x.stock_max_number,x.stock_min_number,x.price,x.remark,x.batch_number,t.manufacturer,t.dealer,t.drug_name,t.last_price,t.dose_unit,t.dose,t.min_number,t.min_unit,t.max_unit,t.drug_type").Joins("left join xt_base_drug as t on t.id = x.drug_id").Scan(&list).Error
|
|
746
|
+ err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.price,x.remark,x.batch_number,x.batch_number,t.manufacturer,t.dealer,t.drug_name,t.last_price,t.dose_unit,t.dose,t.min_number,t.min_unit,t.max_unit,t.drug_type").Joins("left join xt_base_drug as t on t.id = x.drug_id").Scan(&list).Error
|
747
|
747
|
return list, err
|
748
|
748
|
}
|
749
|
749
|
|
|
@@ -3146,7 +3146,7 @@ func GetExprotStockList(orgid int64, orderid []string, startime int64, endtime i
|
3146
|
3146
|
if endtime > 0 {
|
3147
|
3147
|
db = db.Where("x.ctime<=?", endtime)
|
3148
|
3148
|
}
|
3149
|
|
- err = db.Select("x.id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,Sum(x.warehousing_count)as total_count,x.price,x.dealer,x.manufacturer,x.remark,t.good_name,t.packing_unit,t.specification_name,t.manufacturer,t.dealer").Joins("left join xt_good_information as t on t.id = x.good_id").Group("x.good_id").Scan(&info).Error
|
|
3149
|
+ err = db.Select("x.id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.price,x.dealer,x.manufacturer,x.remark,x.license_number,t.good_name,t.packing_unit,t.specification_name,t.manufacturer,t.dealer").Joins("left join xt_good_information as t on t.id = x.good_id").Scan(&info).Error
|
3150
|
3150
|
|
3151
|
3151
|
return info, err
|
3152
|
3152
|
}
|
|
@@ -3189,7 +3189,7 @@ func GetOutExprotList(orgid int64, ids []string, startime int64, endtime int64)
|
3189
|
3189
|
db = db.Where("x.ctime<=?", endtime)
|
3190
|
3190
|
}
|
3191
|
3191
|
|
3192
|
|
- err = db.Select("x.id,x.warehouse_out_id,x.good_id,x.good_type_id,x.warehousing_out_target,Sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.remark,x.number,t.good_name,t.specification_name,t.min_number,t.packing_price,t.min_unit,t.packing_unit,t.manufacturer,t.dealer").Joins("left join xt_good_information as t on t.id = x.good_id").Group("x.good_id").Scan(&out).Error
|
|
3192
|
+ err = db.Select("x.id,x.warehouse_out_id,x.good_id,x.good_type_id,x.warehousing_out_target,x.count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.remark,x.number,x.license_number,t.good_name,t.specification_name,t.min_number,t.packing_price,t.min_unit,t.packing_unit,t.manufacturer,t.dealer").Joins("left join xt_good_information as t on t.id = x.good_id").Scan(&out).Error
|
3193
|
3193
|
return out, err
|
3194
|
3194
|
|
3195
|
3195
|
}
|
|
@@ -3316,13 +3316,13 @@ func GetWarehoureOrderInfoList(goodid int64, orgid int64) (info []*models.Wareho
|
3316
|
3316
|
db = db.Where("x.org_id = ?", orgid)
|
3317
|
3317
|
}
|
3318
|
3318
|
|
3319
|
|
- err = db.Select("x.id,x.warehousing_id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.price,x.total_price,x.dealer,x.manufacturer,x.remark,x.is_return,x.warehousing_order,x.warehousing_unit,x.stock_count,x.license_number").Order("x.ctime desc").Find(&info).Error
|
|
3319
|
+ err = db.Select("x.id,x.warehousing_id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.price,x.total_price,x.dealer,x.manufacturer,x.remark,x.is_return,x.warehousing_order,x.warehousing_unit,x.stock_count,x.license_number,x.org_id").Find(&info).Error
|
3320
|
3320
|
return info, err
|
3321
|
3321
|
}
|
3322
|
3322
|
|
3323
|
3323
|
func UpdateWarehousingCount(info *models.WarehousingInfo, goodid int64, orgid int64, warehousingId int64) error {
|
3324
|
3324
|
|
3325
|
|
- err := XTWriteDB().Model(&info).Where("good_id = ? and org_id = ? and status =1 and warehousing_id = ?", goodid, orgid, warehousingId).Updates(map[string]interface{}{"stock_cout": info.StockCount}).Error
|
|
3325
|
+ err := XTWriteDB().Model(&info).Where("good_id = ? and org_id = ? and status =1 and warehousing_id = ?", goodid, orgid, warehousingId).Updates(map[string]interface{}{"stock_count": info.StockCount}).Error
|
3326
|
3326
|
return err
|
3327
|
3327
|
}
|
3328
|
3328
|
|
|
@@ -3332,11 +3332,10 @@ func GetSingleCancelOrder(id int64, orgid int64) (info []*models.CancelStockInfo
|
3332
|
3332
|
return info, err
|
3333
|
3333
|
}
|
3334
|
3334
|
|
3335
|
|
-func UpdateCancelOut(list []*models.WarehousingInfo, count int64) {
|
|
3335
|
+func UpdateCancelOut(list []*models.WarehousingInfo, count int64) error {
|
3336
|
3336
|
|
3337
|
3337
|
//遍历循环入库数据
|
3338
|
|
- for _, item := range list {
|
3339
|
|
-
|
|
3338
|
+ for i, item := range list {
|
3340
|
3339
|
//计算每个批次剩余库存与入库数据的差 然后和退库数量比较
|
3341
|
3340
|
if (item.WarehousingCount - item.StockCount) >= count {
|
3342
|
3341
|
//如果差距大于退库数量,则直接把退库数量增加到该批次中
|
|
@@ -3344,7 +3343,7 @@ func UpdateCancelOut(list []*models.WarehousingInfo, count int64) {
|
3344
|
3343
|
GoodId: item.GoodId,
|
3345
|
3344
|
OrgId: item.OrgId,
|
3346
|
3345
|
WarehousingId: item.WarehousingId,
|
3347
|
|
- StockCount: count,
|
|
3346
|
+ StockCount: item.StockCount + count,
|
3348
|
3347
|
}
|
3349
|
3348
|
UpdateWarehousingCount(&info, item.GoodId, item.OrgId, item.WarehousingId)
|
3350
|
3349
|
break
|
|
@@ -3354,19 +3353,61 @@ func UpdateCancelOut(list []*models.WarehousingInfo, count int64) {
|
3354
|
3353
|
|
3355
|
3354
|
//如果该批次小于退库数量,则先出库该相差数量
|
3356
|
3355
|
var countOne = item.WarehousingCount - item.StockCount
|
|
3356
|
+
|
3357
|
3357
|
infoOne := models.WarehousingInfo{
|
3358
|
3358
|
GoodId: item.GoodId,
|
3359
|
3359
|
OrgId: item.OrgId,
|
3360
|
3360
|
WarehousingId: item.WarehousingId,
|
3361
|
|
- StockCount: countOne,
|
|
3361
|
+ StockCount: countOne + item.StockCount,
|
3362
|
3362
|
}
|
3363
|
3363
|
|
3364
|
|
- UpdateWarehousingCount(&infoOne, item.GoodId, item.OrgId, item.WarehousingId)
|
|
3364
|
+ err := UpdateWarehousingCount(&infoOne, item.GoodId, item.OrgId, item.WarehousingId)
|
|
3365
|
+ if err == nil {
|
|
3366
|
+ //剩余的出库到第二个批次
|
|
3367
|
+ var countTwo = count - countOne
|
|
3368
|
+ infos := append(list, list[i+1])
|
|
3369
|
+ var idArray []*models.WarehousingInfo
|
|
3370
|
+ for _, it := range infos {
|
|
3371
|
+ if it.WarehousingId != item.WarehousingId {
|
|
3372
|
+ idArray = append(idArray, it)
|
|
3373
|
+ }
|
|
3374
|
+ }
|
|
3375
|
+ //查询更新后的库存
|
|
3376
|
+ UpdateCancelOut(idArray, countTwo)
|
|
3377
|
+ return err
|
|
3378
|
+ } else {
|
|
3379
|
+ return err
|
|
3380
|
+ }
|
3365
|
3381
|
|
3366
|
|
- //剩余的出库到第二个批次
|
3367
|
|
- var countTwo = count - countOne
|
3368
|
|
- UpdateCancelOut(list, countTwo)
|
3369
|
3382
|
}
|
3370
|
3383
|
}
|
3371
|
3384
|
|
|
3385
|
+ return err
|
|
3386
|
+}
|
|
3387
|
+
|
|
3388
|
+func GetCancelStockOrderPrint(idstr []string) (info []*models.CancelStockInfo, err error) {
|
|
3389
|
+
|
|
3390
|
+ if len(idstr) > 0 {
|
|
3391
|
+ err = XTReadDB().Model(&info).Where("cancel_stock_id in(?)", idstr).Preload("GoodInfo", "status = 1").Find(&info).Error
|
|
3392
|
+ } else {
|
|
3393
|
+ err = XTReadDB().Model(&info).Preload("GoodInfo", "status = 1").Find(&info).Error
|
|
3394
|
+ }
|
|
3395
|
+ return info, err
|
|
3396
|
+}
|
|
3397
|
+
|
|
3398
|
+func GetCancelOutTotalCount(startime int64, endtime int64, orgid int64) (info []*models.VmCancelStockInfo, err error) {
|
|
3399
|
+
|
|
3400
|
+ db := XTReadDB().Table("xt_cancel_stock_info as x").Where("x.status = 1")
|
|
3401
|
+
|
|
3402
|
+ if startime > 0 {
|
|
3403
|
+ db = db.Where("x.ctime >=?", startime)
|
|
3404
|
+ }
|
|
3405
|
+ if endtime > 0 {
|
|
3406
|
+ db = db.Where("x.ctime <= ?", endtime)
|
|
3407
|
+ }
|
|
3408
|
+ if orgid > 0 {
|
|
3409
|
+ db = db.Where("x.org_id = ?", orgid)
|
|
3410
|
+ }
|
|
3411
|
+ err = db.Select("x.good_id,sum(x.count) as count").Group("x.good_id").Scan(&info).Error
|
|
3412
|
+ return info, err
|
3372
|
3413
|
}
|