| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取待处理的退料单明细列表 |
| | | /// 获取待处理的退料单明细列表 |
| | | /// </summary> |
| | | /// <param name="query">仓库查询参数,包含用户名和单据号</param> |
| | | /// <returns>待处理的退料单明细列表</returns> |
| | |
| | | .First(); |
| | | |
| | | // 如果未找到退料单,抛出异常 |
| | | if (mesItemQt == null) |
| | | { |
| | | throw new Exception($"未查询到此其他入库申请单 {p_bill_no}"); |
| | | } |
| | | if (mesItemQt == null) throw new Exception($"未查询到此其他入库申请单 {p_bill_no}"); |
| | | |
| | | // 检查退料单的审核状态(Qt015),未审核则抛出异常 |
| | | if (mesItemQt.Qt015 == false) |
| | | { |
| | | throw new Exception($"其他出库申请单 {p_bill_no} 未审核,请确认!"); |
| | | } |
| | | |
| | | // 检查退料单的完结状态(Qt014),已完结则抛出异常 |
| | | if (mesItemQt.Qt014 == true) |
| | | { |
| | | throw new Exception($"其他出库申请单 {p_bill_no} 已完结,请确认!"); |
| | | } |
| | | |
| | | // 联表查询获取未完成的明细列表 |
| | | // 关联表: |
| | |
| | | var p_transaction_no = 202; |
| | | |
| | | // 检查单据号是否为空 |
| | | if (string.IsNullOrEmpty(p_bill_no)) |
| | | { |
| | | throw new Exception("请选取单据号!"); |
| | | } |
| | | if (string.IsNullOrEmpty(p_bill_no)) throw new Exception("请选取单据号!"); |
| | | |
| | | // 检查是否重复扫描 |
| | | var existingBarcode = Db.Queryable<MesInvItemOutCDetails>() |
| | |
| | | it.ItemBarcode == p_item_barcode && it.PbillNo == p_bill_no) |
| | | .Any(); |
| | | |
| | | if (existingBarcode) |
| | | { |
| | | throw new Exception("此条码已经扫码出库,勿重复扫描!"); |
| | | } |
| | | if (existingBarcode) throw new Exception("此条码已经扫码出库,勿重复扫描!"); |
| | | |
| | | // 获取条码信息 |
| | | var barcode = Db.Queryable<MesInvItemBarcodes>() |
| | |
| | | .First(); |
| | | |
| | | if (barcode == null) |
| | | { |
| | | throw new Exception($"mes中不存在此条码,请核对!{p_item_barcode}"); |
| | | } |
| | | |
| | | // 获取库存信息 |
| | | var stock = Db.Queryable<MesInvItemStocks>() |
| | |
| | | .First(); |
| | | |
| | | if (stock == null) |
| | | { |
| | | throw new Exception($"库存中无此条码,请检查条码是否未入库或已出库!{p_item_barcode}"); |
| | | } |
| | | |
| | | |
| | | if (string.IsNullOrEmpty(stock.DepotsCode)) |
| | | { |
| | | throw new Exception($"调拨中的条码不可发料,请先完成调拨单据{p_item_barcode}"); |
| | | } |
| | | |
| | | if (stock.DepotsCode is "S006" or "S005") |
| | | { |
| | | throw new Exception($"条码在不良品仓下 不可发料{p_item_barcode}"); |
| | | } |
| | | |
| | | // 检查是否在寄存仓位 |
| | | // var isDepotSection = Db.Queryable<MesJcDepot>() |
| | |
| | | .First(); |
| | | |
| | | if (mesItemQt == null) |
| | | { |
| | | throw new Exception($"其他出库申请单 {p_bill_no} 不存在,请确认!"); |
| | | } |
| | | |
| | | // 检查仓库是否一致 |
| | | if (mesItemQt.Qt011 != stock.DepotsCode) |
| | | { |
| | | throw new Exception( |
| | | $"扫码出货仓库{stock.DepotsCode}与其他出库申请仓库{mesItemQt.Qt011}不一致,请核对!"); |
| | | } |
| | | |
| | | // 获取出库单明细 |
| | | var qtDetail = Db.Queryable<MesItemQtDatall>() |
| | |
| | | it.ItemId == stock.ItemId.ToString()) |
| | | .First(); |
| | | |
| | | if (qtDetail == null) |
| | | { |
| | | throw new Exception("扫码物料非本次出库申请物料,请核对!"); |
| | | } |
| | | if (qtDetail == null) throw new Exception("扫码物料非本次出库申请物料,请核对!"); |
| | | |
| | | // 检查剩余数量 |
| | | var remainingQty = (qtDetail.Qd007 ?? 0) - (qtDetail.Qd008 ?? 0); |
| | | if (remainingQty <= 0) |
| | | { |
| | | throw new Exception($"申请物料 {barcode.ItemNo} 已出库完成!"); |
| | | } |
| | | |
| | | // 检查数量是否超出 |
| | | if (stock.Quantity > remainingQty) |
| | |
| | | it.ItemId == stock.ItemId.ToString()) |
| | | .First(); |
| | | |
| | | if (qtDetail == null) |
| | | { |
| | | throw new Exception($"未找到对应的退料单明细信息"); |
| | | } |
| | | if (qtDetail == null) throw new Exception("未找到对应的退料单明细信息"); |
| | | |
| | | // 检查是否已存在出库物料记录 |
| | | var existingOutItem = Db.Queryable<MesInvItemOutItems>() |
| | |
| | | ItemId = !string.IsNullOrEmpty(qtDetail.ItemId) |
| | | ? long.Parse(qtDetail.ItemId) |
| | | : null, |
| | | FType = 0, |
| | | FType = 0 |
| | | // Unit = qtDetail.Qd009 |
| | | }; |
| | | |
| | |
| | | |
| | | // 检查明细是否完成,如果完成则更新状态 |
| | | if ((qtDetail.Qd007 ?? 0) - (qtDetail.Qd008 ?? 0) == stock.Quantity) |
| | | { |
| | | commit += db.Updateable<MesItemQtDatall>() |
| | | .SetColumns(it => it.Qd011 == 1) |
| | | .Where(it => it.Guid == qtDetail.Guid) |
| | | .ExecuteCommand(); |
| | | } |
| | | |
| | | mesItemQtDatalls = Db |
| | | .Queryable<MesItemQt, MesItemQtDatall, MesItems>( |
| | |
| | | |
| | | // 如果没有待处理明细,更新退料单状态为已完成 |
| | | if (CollectionUtil.IsNullOrEmpty(mesItemQtDatalls)) |
| | | { |
| | | db.Updateable<MesItemQt>() |
| | | .SetColumns(it => it.Qt014 == true) |
| | | .Where(it => it.Qtck == p_bill_no) |
| | | .ExecuteCommand(); |
| | | } |
| | | |
| | | // 构建返回消息 |
| | | mess = $"扫码成功!条码 {p_item_barcode} 数量 {stock.Quantity} 已出库"; |
| | |
| | | query.Num = stock.Quantity; |
| | | query.Fum = null; |
| | | |
| | | if (commit < 5) |
| | | { |
| | | throw new Exception("更新失败"); |
| | | } |
| | | if (commit < 5) throw new Exception("更新失败"); |
| | | |
| | | return commit; |
| | | }); |
| | |
| | | var p_transaction_no = 202; |
| | | |
| | | // 检查单据号是否为空 |
| | | if (string.IsNullOrEmpty(p_bill_no)) |
| | | { |
| | | throw new Exception("请选取单据号!"); |
| | | } |
| | | if (string.IsNullOrEmpty(p_bill_no)) throw new Exception("请选取单据号!"); |
| | | |
| | | // 检查数量是否有效 |
| | | if (p_qty <= 0) |
| | | { |
| | | throw new Exception("请输入正确的发料数量!"); |
| | | } |
| | | if (p_qty <= 0) throw new Exception("请输入正确的发料数量!"); |
| | | |
| | | // 获取库存条码信息 |
| | | var stock = Db.Queryable<MesInvItemStocks>() |
| | |
| | | .First(); |
| | | |
| | | if (stock == null) |
| | | { |
| | | throw new Exception($"库存中无此条码,请检查条码是否未入库或已出库!{p_old_barcode}"); |
| | | } |
| | | |
| | | if (string.IsNullOrEmpty(stock.DepotsCode)) |
| | | { |
| | | throw new Exception($"调拨中的条码不可发料,请先完成调拨单据{p_old_barcode}"); |
| | | } |
| | | |
| | | if (stock.DepotsCode is "S006" or "S005") |
| | | { |
| | | throw new Exception($"条码在不良品仓下 不可发料{p_old_barcode}"); |
| | | } |
| | | |
| | | // 获取条码信息 |
| | | var barcode = Db.Queryable<MesInvItemBarcodes>() |
| | |
| | | .First(); |
| | | |
| | | if (barcode == null) |
| | | { |
| | | throw new Exception($"mes中不存在此条码,请核对!{p_old_barcode}"); |
| | | } |
| | | |
| | | // 获取退料单信息 |
| | | var mesItemQt = Db.Queryable<MesItemQt>() |
| | |
| | | .First(); |
| | | |
| | | if (mesItemQt == null) |
| | | { |
| | | throw new Exception($"其他出库申请单 {p_bill_no} 不存在,请确认!"); |
| | | } |
| | | |
| | | if (mesItemQt.Qt011 != stock.DepotsCode) |
| | | { |
| | | throw new Exception( |
| | | $"扫码出货仓库{stock.DepotsCode}与其他出库申请仓库{mesItemQt.Qt011}不一致,请核对!"); |
| | | } |
| | | |
| | | // 获取退料单明细 |
| | | var qtDetail = Db.Queryable<MesItemQtDatall>() |
| | |
| | | it.ItemId == stock.ItemId.ToString()) |
| | | .First(); |
| | | |
| | | if (qtDetail == null) |
| | | { |
| | | throw new Exception("扫码物料非本次出库申请物料,请核对!"); |
| | | } |
| | | if (qtDetail == null) throw new Exception("扫码物料非本次出库申请物料,请核对!"); |
| | | |
| | | var remainingQty = (qtDetail.Qd007 ?? 0) - (qtDetail.Qd008 ?? 0); |
| | | |
| | | if (remainingQty <= 0) |
| | | { |
| | | throw new Exception($"申请物料 {barcode.ItemNo} 已出库完成!"); |
| | | } |
| | | |
| | | if (p_qty > remainingQty) |
| | | { |
| | | throw new Exception( |
| | | $"输入的拆分数量 {p_qty} 不可大于剩余需发数量 {remainingQty} 请修改"); |
| | | } |
| | | |
| | | var totalQty = Db.Queryable<MesInvItemStocks>() |
| | | .Where(it => it.ItemBarcode == p_old_barcode && it.Quantity > 0) |
| | | .Sum(it => it.Quantity); |
| | | |
| | | if (totalQty < p_qty) |
| | | { |
| | | throw new Exception($"输入的发料数量 {p_qty} 不可大于条码数量 {totalQty} 请修改"); |
| | | } |
| | | |
| | | var message = string.Empty; |
| | | var mesItemQtDatalls = new List<MesItemQtDatall>(); |
| | |
| | | ComeFlg = 5, |
| | | EbelnK3id = barcode.EbelnK3id, |
| | | LineK3id = barcode.LineK3id, |
| | | ItemId = barcode.ItemId, |
| | | ItemId = barcode.ItemId |
| | | }).IgnoreColumns(true).ExecuteCommand(); |
| | | |
| | | // 更新原条码数量 |
| | |
| | | BillNo = stock.BillNo, |
| | | EbelnK3id = stock.EbelnK3id, |
| | | LineK3id = stock.LineK3id, |
| | | ItemId = stock.ItemId, |
| | | ItemId = stock.ItemId |
| | | }).IgnoreColumns(true).ExecuteCommand(); |
| | | |
| | | |
| | |
| | | LineK3id = stock.LineK3id, |
| | | SuppId = stock.SuppId, |
| | | SuppNo = stock.SuppNo, |
| | | ItemId = stock.ItemId, |
| | | ItemId = stock.ItemId |
| | | }).IgnoreColumns(true).ExecuteCommand(); |
| | | } |
| | | else |
| | |
| | | commit += db.Insertable(new MesInvItemOuts |
| | | { |
| | | Guid = outId, |
| | | ItemOutNo = $"OUT-{DateTime.Now:yyyyMMddHHmmss}", |
| | | ItemOutNo = outNo, |
| | | TaskNo = p_bill_no, |
| | | Status = 0, |
| | | CreateBy = c_user, |
| | |
| | | PbillNo = p_bill_no, |
| | | OutDate = DateTime.Now, |
| | | Nflag = 0, |
| | | Reason = mesItemQt.Qt010, |
| | | Reason = mesItemQt.Qt010 |
| | | }).ExecuteReturnIdentity(); |
| | | outNo = $"OUT-{DateTime.Now:yyyyMMddHHmmss}"; |
| | | } |
| | | else |
| | | { |
| | |
| | | .First(); |
| | | |
| | | if (outItem == null) |
| | | { |
| | | // 插入新明细 |
| | | db.Insertable(new MesInvItemOutItems |
| | | { |
| | |
| | | ItemId = !string.IsNullOrEmpty(qtDetail.ItemId) |
| | | ? long.Parse(qtDetail.ItemId) |
| | | : null, |
| | | FType = 0, |
| | | FType = 0 |
| | | // Unit = qtDetail.Qd009 |
| | | }).ExecuteCommand(); |
| | | } |
| | | else |
| | | { |
| | | // 更新明细数量 |
| | | db.Updateable<MesInvItemOutItems>() |
| | | .SetColumns(it => |
| | |
| | | it.ItemId == stock.ItemId && |
| | | it.QtOutId == qtDetail.Guid) |
| | | .ExecuteCommand(); |
| | | } |
| | | |
| | | // 插入出库明细 |
| | | db.Insertable(new MesInvItemOutCDetails |
| | |
| | | |
| | | // 如果所有明细完成,更新退料单状态 |
| | | if (!hasUnfinished) |
| | | { |
| | | db.Updateable<MesItemQt>() |
| | | .SetColumns(it => it.Qt014 == true) |
| | | .Where(it => it.Qtck == p_bill_no) |
| | | .ExecuteCommand(); |
| | | } |
| | | |
| | | // 获取剩余待处理明细 |
| | | mesItemQtDatalls = db |