| | |
| | | var p_transaction_no = 301; // 交易编号 |
| | | |
| | | // 验证单据号 |
| | | if (string.IsNullOrEmpty(p_bill_no)) |
| | | { |
| | | throw new Exception("请选取单据号!"); |
| | | } |
| | | if (string.IsNullOrEmpty(p_bill_no)) throw new Exception("请选取单据号!"); |
| | | |
| | | // 查询出库单并验证状态 |
| | | var transferOut = Db.Queryable<TransferOut>() |
| | | .Where(x => x.BillNo == p_bill_no && x.Status == 1) |
| | | .First(); |
| | | if (transferOut == null) |
| | | { |
| | | throw new Exception("未找到调拨申请单或者调拨申请单没审核"); |
| | | } |
| | | if (transferOut == null) throw new Exception("未找到调拨申请单或者调拨申请单没审核"); |
| | | |
| | | // 查询条码库存信息并验证 |
| | | var stock = Db.Queryable<MesInvItemStocks>() |
| | |
| | | && x.Quantity > 0 |
| | | && !string.IsNullOrEmpty(x.DepotsCode)) |
| | | .First(); |
| | | if (stock == null) |
| | | { |
| | | throw new Exception($"库存中无此条码,请核对!{p_item_barcode}"); |
| | | } |
| | | if (stock == null) throw new Exception($"库存中无此条码,请核对!{p_item_barcode}"); |
| | | |
| | | // 验证仓库一致性 |
| | | if (stock.DepotsCode != transferOut.InvCode) |
| | | { |
| | | throw new Exception( |
| | | $"条码库存仓库{stock.DepotsCode}和申请仓库不一致{transferOut.InvCode}"); |
| | | } |
| | | |
| | | // 查询物料信息 |
| | | var item = Db.Queryable<MesItems>() |
| | | .Where(x => x.Id == stock.ItemId) |
| | | .First(); |
| | | if (item == null) |
| | | { |
| | | throw new Exception("未找到物料"); |
| | | } |
| | | if (item == null) throw new Exception("未找到物料"); |
| | | |
| | | // 查询调拨明细并验证 |
| | | var detail = Db.Queryable<TransferOutDetail>() |
| | | .Where(x => x.ItemId == stock.ItemId && x.Pid == transferOut.Guid) |
| | | .First(); |
| | | if (detail == null) |
| | | { |
| | | throw new Exception("未找到条码物料相应的调拨申请"); |
| | | } |
| | | if (detail == null) throw new Exception("未找到条码物料相应的调拨申请"); |
| | | |
| | | // 验证数量是否超出未扫数量 |
| | | if ((detail.ShNum ?? 0) - (detail.YsNum ?? 0) < stock.Quantity) |
| | | { |
| | | throw new Exception("条码数量大于申请未扫数量,请拆分了再扫码"); |
| | | } |
| | | |
| | | // 使用事务处理数据更新 |
| | | UseTransaction(db => |
| | |
| | | SuppNo = stock.SuppNo, |
| | | ItemId = stock.ItemId, |
| | | EbelnK3id = stock.EbelnK3id, |
| | | LineK3id = stock.LineK3id, |
| | | LineK3id = stock.LineK3id |
| | | // RkDepot = transferOut.RkDepot, |
| | | // CkDepot = transferOut.CkDepot |
| | | }; |
| | |
| | | SuppNo = stock.SuppNo, |
| | | ItemId = (int)stock.ItemId, |
| | | EbelnK3id = stock.EbelnK3id, |
| | | LineK3id = stock.LineK3id, |
| | | LineK3id = stock.LineK3id |
| | | // RkDepot = transferOut.RkDepot, |
| | | // CkDepot = transferOut.CkDepot |
| | | }; |
| | |
| | | WorkLine = stock.WorkLine, |
| | | EbelnK3id = (int)stock.EbelnK3id, |
| | | LineK3id = (int)stock.LineK3id, |
| | | Quantity = stock.Quantity, |
| | | Quantity = stock.Quantity |
| | | // Unit = stock.ItemUnit |
| | | }; |
| | | |
| | |
| | | var totals = db.Queryable<TransferOutDetail, TransferOut>((b, a) => |
| | | new JoinQueryInfos(JoinType.Left, b.Pid == a.Guid)) |
| | | .Where((b, a) => a.BillNo == p_bill_no) |
| | | .Select((b, a) => new { |
| | | .Select((b, a) => new |
| | | { |
| | | ShNum = SqlFunc.AggregateSum(b.ShNum), // 申请总数量 |
| | | YsNum = SqlFunc.AggregateSum(b.YsNum) // 已扫总数量 |
| | | }) |
| | |
| | | |
| | | // 如果申请数量等于已扫数量,更新单据完成状态 |
| | | if (totals.ShNum == totals.YsNum) |
| | | { |
| | | commit += db.Updateable<TransferOut>() |
| | | .SetColumns(x => x.IsWc == 1) |
| | | .Where(x => x.BillNo == p_bill_no) |
| | | .ExecuteCommand(); |
| | | } |
| | | |
| | | // 更新返回参数 |
| | | query.itemNo = item.ItemNo; |
| | | query.Num = stock.Quantity; |
| | | |
| | | // 验证更新操作是否全部成功 |
| | | if (commit < 4) |
| | | { |
| | | throw new Exception("更新失败"); |
| | | } |
| | | if (commit < 4) throw new Exception("更新失败"); |
| | | |
| | | return commit; |
| | | }); |