南骏 池
2025-06-20 7b84eb64d11b12b6fb41ae7f7085452512ad5d3f
service/Warehouse/MesInvItemOutsManager.cs
@@ -340,9 +340,7 @@
        }
        if (!UtilityHelper.CheckGuid(parsedGuid))
        {
            throw new ApplicationException("更新错误,数据是不合法的");
        }
        var userName = entity.userName ?? "system";
        return Db.Updateable<MesInvItemOuts>()
@@ -382,10 +380,7 @@
        message.Pid = newGuid;
        var executeReturnIdentity =
            Db.Insertable(message).IgnoreColumns(true).ExecuteCommand();
        if (executeReturnIdentity > 0)
        {
            return message;
        }
        if (executeReturnIdentity > 0) return message;
        throw new Exception("获取数据失败");
    }
@@ -410,7 +405,7 @@
        var dto = new OutItemDto();
        dto.SumItem = GetItems(query);
        //dto.SumItem = GetItems(query);
        var mesInvItemStocks = Db.Queryable<MesInvItemStocks>()
            .Where(a => a.ItemBarcode == query.barcode).Single();
@@ -528,7 +523,7 @@
                FUnitID = d.Fnumber,
                FLot = b.WorkNo,
                F_MES_ENTRYID = b.Guid,
                FsrcEntryId = e.Guid.ToString(),
                FsrcEntryId = e.Guid.ToString()
            }).ToList();
@@ -537,13 +532,13 @@
        var jsonEntries = materials.Select(d => new
        {
            FMaterialId = d.FMaterialId,
            FRMREALQTY = d.FRMREALQTY,
            FStockId = d.FStockId,
            FUnitID = d.FUnitID,
            FLot = d.FLot,
            d.FMaterialId,
            d.FRMREALQTY,
            d.FStockId,
            d.FUnitID,
            d.FLot,
            F_MES_ENTRYID = d.F_MES_ENTRYID.ToString(),
            FsrcEntryId = d.FsrcEntryId,
            d.FsrcEntryId
        }).ToList();
        var fdate = DateTime.Now.ToString("yyyy-MM-dd");
        var jsonString = JsonConvert.SerializeObject(jsonEntries);
@@ -642,10 +637,7 @@
        //调用存储过程 
        var prcRfPdaBarcodeCgth = PrcRfPdaBarcodeCgth(query);
        if (!prcRfPdaBarcodeCgth)
        {
            throw new Exception("执行失败");
        }
        if (!prcRfPdaBarcodeCgth) throw new Exception("执行失败");
        // 变量用于保存查询结果
        decimal? C_SQ_QTY = 0;
@@ -687,10 +679,7 @@
        var commit = UseTransaction(db =>
        {
            if (string.IsNullOrEmpty(p_bill_no))
            {
                throw new Exception("请选取单据号!");
            }
            if (string.IsNullOrEmpty(p_bill_no)) throw new Exception("请选取单据号!");
            // Retrieve mes_inv_item_outs
            var c_mes_inv_item_outs = db.Queryable<MesInvItemOuts>()
@@ -698,19 +687,13 @@
                .First();
            if (c_mes_inv_item_outs == null)
            {
                throw new Exception("请选择或扫描正确的采购退货单!");
            }
            if (c_mes_inv_item_outs.Status == 0)
            {
                throw new Exception("采购退货申请单未审核!");
            }
            if (c_mes_inv_item_outs.Nflag == 1)
            {
                throw new Exception("采购退货单已完结推送ERP,不能操作!");
            }
            // Check for duplicate barcode scan
            c_num = db.Queryable<MesInvItemOutCDetails>()
@@ -719,10 +702,7 @@
                    b.ItemOutId == c_mes_inv_item_outs.Guid)
                .Count();
            if (c_num > 0)
            {
                throw new Exception("此条码已采购退货扫码完成!");
            }
            if (c_num > 0) throw new Exception("此条码已采购退货扫码完成!");
            // Query item stock info
            var c_mes_inv_item_stocks = db.Queryable<MesInvItemStocks>()
@@ -730,17 +710,13 @@
                .First();
            if (c_mes_inv_item_stocks == null)
            {
                throw new Exception($"库存中无此条码,请核对!{p_item_barcode}");
            }
            // Validate depot codes
            if (c_mes_inv_item_outs.DepotCode !=
                c_mes_inv_item_stocks.DepotsCode)
            {
                throw new Exception(
                    $"此条码属于仓库 {c_mes_inv_item_stocks.DepotsCode} 与采购退货申请仓库 {c_mes_inv_item_outs.DepotCode} 不一致,请核对!");
            }
            C_STOCKNUM = c_mes_inv_item_stocks.Quantity.Value;
@@ -748,7 +724,7 @@
            var quantities = db.Queryable<MesInvItemOutItems, MesInvItemOuts>(
                    (s, d) => new object[]
                    {
                        JoinType.Left, s.ItemOutId == d.Guid,
                        JoinType.Left, s.ItemOutId == d.Guid
                    })
                .Where((s, d) =>
                    d.ItemOutNo == p_bill_no &&
@@ -763,9 +739,7 @@
                .First();
            if (quantities == null)
            {
                throw new Exception("采购退料单 '" + p_bill_no + "'未审核");
            }
            C_SQTY = quantities.TotalQuantity ?? 0;
            C_OKQTY = quantities.CompletedQuantity ?? 0;
@@ -774,7 +748,7 @@
            if (C_CQTY < C_STOCKNUM) return 1;
            // Handle barcode reduction
            decimal p_number2 = C_STOCKNUM;
            var p_number2 = C_STOCKNUM;
            var itemOutItems = db.Queryable<MesInvItemOutItems>()
                .Where(s =>
                    s.ItemOutId == c_mes_inv_item_outs.Guid &&
@@ -799,9 +773,7 @@
                    .First();
                if (c_mes_inv_item_arn_detail == null)
                {
                    throw new Exception("未找到采购退料来源单据");
                }
                if (CMI.Quantity - CMI.TlQty <= p_number2)
                {
@@ -862,15 +834,13 @@
                        TaskNo = CMI.WorkNo,
                        ItemId = c_mes_inv_item_stocks.ItemId,
                        EbelnK3id = c_mes_inv_item_stocks.EbelnK3id,
                        LineK3id = c_mes_inv_item_stocks.LineK3id,
                        LineK3id = c_mes_inv_item_stocks.LineK3id
                    }).IgnoreColumns(true).ExecuteCommand();
                    if (p_number2 == 0)
                    {
                        db.Deleteable<MesInvItemStocks>()
                            .Where(s => s.Guid == c_mes_inv_item_outs.Guid)
                            .ExecuteCommand();
                    }
                }
                else
                {
@@ -935,16 +905,13 @@
                        SuppId = c_mes_inv_item_outs.SuppId.ToString(),
                        ItemId = c_mes_inv_item_stocks.ItemId,
                        EbelnK3id = c_mes_inv_item_stocks.EbelnK3id,
                        LineK3id = c_mes_inv_item_stocks.LineK3id,
                        LineK3id = c_mes_inv_item_stocks.LineK3id
                    }).IgnoreColumns(true).ExecuteCommand();
                    p_number2 = 0;
                }
            }
            if (p_number2 > 0)
            {
                throw new Exception("物料数量将超采购退料申请单数量,无法出库");
            }
            if (p_number2 > 0) throw new Exception("物料数量将超采购退料申请单数量,无法出库");
            return 1;
        });