service/Warehouse/MesInvItemInCDetailsManager.cs
@@ -17,9 +17,9 @@
        string user = entity.userName,
            sectionCode = entity.sectionCode,
            itemBarcode = entity.barcode;
        string transactionNo = "101";
        var transactionNo = "101";
        int? billTypeId = 100, num = 0, num2 = 0;
        int freeze = 0;
        var freeze = 0;
        decimal cSyQty = 0;
        if (string.IsNullOrEmpty(sectionCode))
@@ -32,7 +32,7 @@
        if (itemBarcodeDetails == null)
            throw new Exception("条码不存在,请核对!");
        if (!itemBarcodeDetails.ComeFlg.Value)
        if (itemBarcodeDetails.ComeFlg == 0)
            throw new Exception("此条码不属于到货条码,无法用采购入库!");
        var inventory = Db.Queryable<MesInvItemArn>()
@@ -42,11 +42,15 @@
        if (inventory == null)
            throw new Exception("此条码找不到对应收货单!");
        // var inventoryDetails = Db.Queryable<MesInvItemArnDetail>()
        //     .Where(it => it.ParentGuid == inventory.Guid
        //                  && it.ItemId == itemBarcodeDetails.ItemId
        //                  && it.EbelnLine == itemBarcodeDetails.WorkLine
        //                  && it.Ebeln == itemBarcodeDetails.WorkNo)
        //     .First();
        var inventoryDetails = Db.Queryable<MesInvItemArnDetail>()
            .Where(it => it.ParentGuid == inventory.Guid
                         && it.ItemId == itemBarcodeDetails.ItemId
                         && it.EbelnLine == itemBarcodeDetails.WorkLine
                         && it.Ebeln == itemBarcodeDetails.WorkNo)
            .Where(it => it.Guid == itemBarcodeDetails.AboutGuid)
            .First();
        if (inventoryDetails == null)
@@ -70,8 +74,8 @@
            mesDepost = Db.Queryable<MesDepots>()
                .Where(s => s.DepotId.ToString() == depotCode2).First();
            if (depotCode != mesDepost.Guid)
                throw new Exception("扫描库位与采购入库库位不一致!");
            // if (depotCode != mesDepost.Guid)
            //     throw new Exception("扫描库位与采购入库库位不一致!");
        }
        else
        {
@@ -117,12 +121,12 @@
                throw new Exception("入库失败,到货单据有问题!");
        }
        PurchaseInventory result = new PurchaseInventory();
        var result = new PurchaseInventory();
        UseTransaction(db =>
        {
            var existingRecord = db.Queryable<MesInvItemIns>()
                .Where(it => it.InsDate.Value.Date == DateTime.Now.Date
                .Where(it => it.InsDate.Value.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd")
                             && it.Status == 0
                             && it.TransctionNo == transactionNo
                             && it.BillNo == itemBarcodeDetails.BillNo
@@ -134,7 +138,7 @@
                })
                .First();
            Guid cId = Guid.Empty;
            var cId = Guid.Empty;
            string cBillNo = null;
            if (existingRecord != null)
@@ -149,8 +153,7 @@
                cBillNo = BillNo.GetBillNo("IN(入库单)");
                var suppNo = db.Queryable<MesSupplier>()
                    .Where(s => s.Id.ToString() == inventory.SuppId)
                    .Select(s => s.SuppNo).First();
                    .Where(s => s.Id.ToString() == inventory.SuppId).First();
                db.Insertable(new MesInvItemIns
                {
@@ -158,21 +161,30 @@
                    BillNo = cBillNo,
                    BillTypeId = billTypeId,
                    InsDate = DateTime.Now,
                    DepotsId = mesDepost.DepotId,
                    DepotsCode = mesDepost.DepotCode,
                    TransctionNo = transactionNo,
                    SuppNo = suppNo,
                    SuppId = suppNo.Id.ToString(),
                    SuppNo = suppNo.SuppNo,
                    CreateBy = user,
                    CreateDate = DateTime.Now,
                    LastupdateBy = user,
                    LastupdateDate = DateTime.Now,
                    UrgentFlag = itemBarcodeDetails.UrgentFlag.Value ? 1 : 0,
                    UrgentFlag = itemBarcodeDetails.UrgentFlag.Value
                        ? "1"
                        : "0",
                    CbillNo = itemBarcodeDetails.BillNo,
                    Fstatus = 0,
                    Status = 0
                    Status = 0,
                    ReceiveOrgId = inventory.ReceiveOrgId
                }).IgnoreColumns(true).ExecuteCommand();
            }
            cSyQty = itemBarcodeDetails.Quantity.Value;
            entity.id = cId.ToString();
            entity.PageIndex = 1;
            entity.Limit = 1;
            itemBarcodeDetails.Hbdy ??= 0;
            if (itemBarcodeDetails.Hbdy == 1)
@@ -200,7 +212,7 @@
                                IsdepsIn = true
                            })
                            .Where(d => d.Guid == detail.Guid)
                            .IgnoreColumns(ignoreAllNullColumns: true)
                            .IgnoreColumns(true)
                            .ExecuteCommand();
                        // Check if already inserted
@@ -215,7 +227,6 @@
                        cSyQty -= remainingQty.Value;
                        if (count == 0)
                        {
                            // Insert new item into MES_INV_ITEM_IN_C_ITEMS
                            db.Insertable(new MesInvItemInCItems
                            {
@@ -227,19 +238,18 @@
                                DepotCode = mesDepost.DepotCode,
                                ItemSname = itemBarcodeDetails.ItemSname,
                                Unit = itemBarcodeDetails.Unit,
                                Ebeln = detail.WorkNo,
                                Ebeln = detail.Ebeln,
                                BillNo = cBillNo,
                                WorkNo = detail.WorkNo,
                                CbillNo = detail.CbillNo,
                                WorkLine = detail.WorkLine,
                                SuppId = itemBarcodeDetails.SuppId,
                                SuppNo = itemBarcodeDetails.SuppNo,
                                Remark = itemBarcodeDetails.Memo,
                                EbelnK3id = detail.EbelnK3id,
                                LineK3id = detail.LineK3id
                            }).IgnoreColumns(true).ExecuteCommand();
                        }
                        else
                        {
                            db.Updateable<MesInvItemInCItems>()
                                .SetColumns(it =>
                                    it.Quantity == it.Quantity + remainingQty)
@@ -248,9 +258,8 @@
                                    it.ItemId == detail.ItemId &&
                                    it.WorkNo == detail.WorkNo &&
                                    it.WorkLine == detail.WorkLine)
                                .IgnoreColumns(ignoreAllNullColumns: true)
                                .IgnoreColumns(true)
                                .ExecuteCommand();
                        }
                        // Insert new detail into MES_INV_ITEM_IN_C_DETAILS
                        db.Insertable(new MesInvItemInCDetails
@@ -263,6 +272,7 @@
                            EpFlag = true,
                            WorkType = 1,
                            ItemNo = detail.ItemNo,
                            SuppId = itemBarcodeDetails.SuppId,
                            SuppNo = itemBarcodeDetails.SuppNo,
                            DepotCode = mesDepost.DepotCode,
                            DepotSectionCode = sectionCode,
@@ -282,7 +292,8 @@
                            TaskNo = detail.WorkNo,
                            EbelnK3id = detail.EbelnK3id,
                            LineK3id = detail.LineK3id,
                            ItemId = detail.ItemId
                            ItemId = detail.ItemId,
                            ReceiveOrgId = inventory.ReceiveOrgId
                        }).IgnoreColumns(true).ExecuteCommand();
                    }
                    else
@@ -294,7 +305,7 @@
                                OkRkqty = (int)((d.OkRkqty ?? 0) + cSyQty)
                            })
                            .Where(d => d.Guid == detail.Guid)
                            .IgnoreColumns(ignoreAllNullColumns: true)
                            .IgnoreColumns(true)
                            .ExecuteCommand();
                        var count = db.Queryable<MesInvItemInCItems>()
@@ -306,7 +317,6 @@
                            .Count();
                        if (count == 0)
                        {
                            db.Insertable(new MesInvItemInCItems
                            {
                                ItemInId = cId,
@@ -323,15 +333,14 @@
                                EbelnLineNo = detail.EbelnLine,
                                CbillNo = detail.CbillNo,
                                WorkLine = detail.WorkLine,
                                SuppId = itemBarcodeDetails.SuppId,
                                SuppNo = itemBarcodeDetails.SuppNo,
                                Remark = itemBarcodeDetails.Memo,
                                EbelnK3id = detail.EbelnK3id,
                                LineK3id = detail.LineK3id,
                                ItemId = detail.ItemId
                            }).IgnoreColumns(true).ExecuteCommand();
                        }
                        else
                        {
                            db.Updateable<MesInvItemInCItems>()
                                .SetColumns(it =>
                                    it.Quantity == it.Quantity + cSyQty)
@@ -340,9 +349,8 @@
                                    it.ItemId == detail.ItemId &&
                                    it.WorkNo == detail.WorkNo &&
                                    it.WorkLine == detail.WorkLine)
                                .IgnoreColumns(ignoreAllNullColumns: true)
                                .IgnoreColumns(true)
                                .ExecuteCommand();
                        }
                        db.Insertable(new MesInvItemInCDetails
                        {
@@ -354,6 +362,7 @@
                            EpFlag = true,
                            WorkType = 1,
                            ItemNo = detail.ItemNo,
                            SuppId = itemBarcodeDetails.SuppId,
                            SuppNo = itemBarcodeDetails.SuppNo,
                            DepotCode = mesDepost.DepotCode,
                            DepotSectionCode = sectionCode,
@@ -374,7 +383,8 @@
                            TaskNo = detail.WorkNo,
                            EbelnK3id = detail.EbelnK3id,
                            LineK3id = detail.LineK3id,
                            ItemId = detail.ItemId
                            ItemId = detail.ItemId,
                            ReceiveOrgId = inventory.ReceiveOrgId
                        }).IgnoreColumns(true).ExecuteCommand();
                        cSyQty = 0; // Remaining quantity fulfilled
@@ -403,6 +413,7 @@
                    BillNo = cBillNo,
                    WorkNo = itemBarcodeDetails.WorkNo,
                    WorkLine = itemBarcodeDetails.WorkLine,
                    SuppId = itemBarcodeDetails.SuppId,
                    SuppNo = itemBarcodeDetails.SuppNo,
                    EbelnK3id = itemBarcodeDetails.EbelnK3id,
                    LineK3id = itemBarcodeDetails.LineK3id,
@@ -422,7 +433,6 @@
                    .Count();
                if (existingCount == 0)
                {
                    // 不存在时插入新记录
                    db.Insertable(new MesInvItemInCItems
                    {
@@ -440,15 +450,14 @@
                        EbelnLineNo = itemBarcodeDetails.WorkLine,
                        CbillNo = itemBarcodeDetails.BillNo,
                        WorkLine = itemBarcodeDetails.WorkLine,
                        SuppId = itemBarcodeDetails.SuppId,
                        SuppNo = itemBarcodeDetails.SuppNo,
                        Remark = itemBarcodeDetails.Memo,
                        EbelnK3id = itemBarcodeDetails.EbelnK3id,
                        LineK3id = itemBarcodeDetails.LineK3id,
                        ItemId = itemBarcodeDetails.ItemId
                    }).IgnoreColumns(true).ExecuteCommand();
                }
                else
                {
                    // 存在时更新数量
                    db.Updateable<MesInvItemInCItems>()
                        .SetColumns(it =>
@@ -458,9 +467,8 @@
                                     it.ItemId == itemBarcodeDetails.ItemId &&
                                     it.WorkNo == itemBarcodeDetails.WorkNo &&
                                     it.WorkLine == itemBarcodeDetails.WorkLine)
                        .IgnoreColumns(ignoreAllNullColumns: true)
                        .IgnoreColumns(true)
                        .ExecuteCommand();
                }
                // 插入 mes_inv_item_in_c_details 表
                db.Insertable(new MesInvItemInCDetails
@@ -474,6 +482,7 @@
                    WorkType = 1,
                    ItemNo = itemBarcodeDetails.ItemNo,
                    LotNo = itemBarcodeDetails.LotNo,
                    SuppId = itemBarcodeDetails.SuppId,
                    SuppNo = itemBarcodeDetails.SuppNo,
                    DepotCode = mesDepost.DepotCode,
                    DepotSectionCode = sectionCode,
@@ -498,7 +507,8 @@
                    Ischeck = true,
                    CheckDate = inventoryDetails.CheckDate,
                    CheckRes = inventoryDetails.CheckRes,
                    CheckStates = inventoryDetails.CheckStates
                    CheckStates = inventoryDetails.CheckStates,
                    ReceiveOrgId = inventory.ReceiveOrgId
                }).IgnoreColumns(true).ExecuteCommand();
                // 插入 mes_inv_business2 表
@@ -526,6 +536,7 @@
                    BillNo = cBillNo,
                    WorkNo = itemBarcodeDetails.WorkNo,
                    WorkLine = itemBarcodeDetails.WorkLine,
                    SuppId = itemBarcodeDetails.SuppId,
                    SuppNo = itemBarcodeDetails.SuppNo,
                    EbelnK3id = itemBarcodeDetails.EbelnK3id,
                    LineK3id = itemBarcodeDetails.LineK3id,
@@ -550,11 +561,13 @@
                BoardStyle = itemBarcodeDetails.BoardStyle,
                WorkNo = itemBarcodeDetails.WorkNo,
                WorkLine = itemBarcodeDetails.WorkLine,
                SuppId = itemBarcodeDetails.SuppId,
                SuppNo = itemBarcodeDetails.SuppNo,
                EbelnK3id = itemBarcodeDetails.EbelnK3id,
                LineK3id = itemBarcodeDetails.LineK3id,
                ItemId = itemBarcodeDetails.ItemId,
                BillNo = itemBarcodeDetails.BillNo
                BillNo = itemBarcodeDetails.BillNo,
                DepotId = Convert.ToInt32(depotCode2)
            }).IgnoreColumns(true).ExecuteCommand();
            itemBarcodeDetails.Hbdy ??= 0;
@@ -585,12 +598,10 @@
                var TotalOkRkQty = first.TotalOkRkQty ?? 0;
                if (TotalQuantity == TotalOkRkQty)
                {
                    db.Updateable<MesInvItemArnDetail>()
                        .SetColumns(s => s.IsdepsIn == true)
                        .Where(s => s.Guid == inventoryDetails.Guid)
                        .ExecuteCommand();
                }
                var totalSummary = db.Queryable<MesInvItemArnDetail>()
@@ -606,12 +617,10 @@
                if ((totalSummary.TotalQuantity ?? 0) ==
                    (totalSummary.TotalOkRkQty ?? 0))
                {
                    db.Updateable<MesInvItemArn>()
                        .SetColumns(it => it.Status == 1)
                        .Where(it => it.BillNo == itemBarcodeDetails.BillNo)
                        .ExecuteCommand();
                }
                var totalCDetailsQuantity = db.Queryable<MesInvItemInCDetails>()
                    .Where(it => it.WorkLine == itemBarcodeDetails.WorkLine &&
@@ -633,15 +642,18 @@
                var diffQty = comeQty - invQty;
                if (detailSummary == null)
                {
                    throw new Exception("此条码找不到对应收货单明细!");
                }
                var mesItems = db.Queryable<MesItems>()
                    .Where(s=>s.Id == itemBarcodeDetails.ItemId).First();
                    .Where(s => s.Id == itemBarcodeDetails.ItemId).First();
                result.Message =
                    $"条码数量 {itemBarcodeDetails.Quantity},采购订单 {itemBarcodeDetails.WorkNo} 项次 {itemBarcodeDetails.WorkLine} 物料 {mesItems.ItemNo} 本次入库总数:{totalCDetailsQuantity} 总到 {comeQty} 已入 {invQty} 欠 {diffQty}";
                result.ItemNo = mesItems.ItemNo;
                result.SumQuantity = Convert.ToDecimal(totalCDetailsQuantity);
                return 1;
            }
            else
@@ -660,12 +672,10 @@
                if ((totalSummary.TotalQuantity ?? 0) ==
                    (totalSummary.TotalOkRkQty ?? 0))
                {
                    db.Updateable<MesInvItemArn>()
                        .SetColumns(it => it.Status == 1)
                        .Where(it => it.BillNo == itemBarcodeDetails.BillNo)
                        .ExecuteCommand();
                }
                // Step 2: Calculate total sum from `mes_inv_item_in_c_details`
                var totalCDetailsQuantity = db.Queryable<MesInvItemInCDetails>()
@@ -685,40 +695,155 @@
                    .First();
                if (detailSummary == null)
                {
                    throw new Exception("此条码找不到对应收货单明细!");
                }
                var comeQty = detailSummary.TotalComeQty ?? 0;
                var invQty = detailSummary.TotalInvQty ?? 0;
                var diffQty = comeQty - invQty;
                var mesItems = db.Queryable<MesItems>()
                    .Where(s=>s.Id == itemBarcodeDetails.ItemId).First();
                    .Where(s => s.Id == itemBarcodeDetails.ItemId).First();
                // Step 5: Combine final result
                result.Message =
                    $" 条码数量:{itemBarcodeDetails.Quantity},物料 {mesItems.ItemNo} 本次入库总数:{totalCDetailsQuantity} 总到 {comeQty} 已入 {invQty} 欠 {diffQty}";
            }
                result.ItemNo = mesItems.ItemNo;
                result.SumQuantity = Convert.ToDecimal(totalCDetailsQuantity);
            }
            var mesInvItemInCDetails =
                base.GetSingle(it => it.ItemBarcode == entity.barcode);
            if (mesInvItemInCDetails == null)
                throw new Exception("物料入库条码明细不存在"); // 抛出异常以供前台处理
            //
            // var itemInId = mesInvItemInCDetails.ItemInId;
            // entity.id = itemInId;
            // entity.PageIndex = 1;
            // entity.Limit = 1;
            //var inventory = getPurchaseInventory(entity);
            // inventory.ItemNo = parts[0];
            // inventory.SumQuantity = Convert.ToDecimal(parts[1]);
            //return inventory;
            return 1;
        });
        var purchaseInventory = getPurchaseInventory(entity);
        result.ItemIns = purchaseInventory.ItemIns;
        result.ItemInDetails = purchaseInventory.ItemInDetails;
        result.InvItemInCDetails = purchaseInventory.InvItemInCDetails;
        return result;
    }
    public PurchaseInventory getPurchaseInventory(WarehouseQuery query)
    {
        return new PurchaseInventory
        {
            ItemIns = GetInvItemInsList(query).Items[0],
            ItemInDetails = GetItemInDetails(query.id),
            InvItemInCDetails = GetInvItemInCDetails(query.id)
        };
    }
    public (List<MesInvItemIns> Items, int TotalCount) GetInvItemInsList(
        WarehouseQuery query)
    {
        var parsedGuid = Guid.Empty;
        if (!string.IsNullOrEmpty(query.id))
        {
            var isValid = Guid.TryParse(query.id, out parsedGuid);
            if (!isValid)
                throw new ApplicationException("GUID转换错误");
        }
        var totalCount = 0;
        var result = Db.Queryable<MesInvItemIns, MesDepots, MesSupplier>(
                (a, b, c) =>
                    new JoinQueryInfos(JoinType.Left,
                        a.DepotsId == b.DepotId,
                        JoinType.Left, a.SuppId == c.Id.ToString()))
            .WhereIF(UtilityHelper.CheckGuid(parsedGuid),
                (a, b, c) => a.Guid == parsedGuid)
            .Select((a, b, c) => new MesInvItemIns
            {
                Guid = a.Guid,
                SuppNo = a.SuppNo,
                InsDate = a.InsDate,
                PaperBillNo = a.PaperBillNo,
                Remark = a.Remark,
                DepotsCode = a.DepotsCode,
                CbillNo = a.CbillNo,
                Status = a.Status,
                BillNo = a.BillNo,
                CreateDate = a.CreateDate,
                CreateBy = a.CreateBy,
                DepotName = b.DepotName,
                SuppName = c.SuppName
            }).ToPageList(query.PageIndex, query.Limit, ref totalCount);
        return (result, totalCount);
    }
    public List<MesInvItemInCItems> GetItemInDetails(string? pid)
    {
        //string转guid
        var parsedGuid = Guid.Empty;
        if (string.IsNullOrEmpty(pid)) return [];
        var isValid = Guid.TryParse(pid, out parsedGuid);
        if (!isValid)
            throw new ApplicationException("GUID转换错误");
        var result = Db.Queryable<MesInvItemInCDetails, MesItems, MesUnit>(
                (g, c, d) => new JoinQueryInfos(
                    JoinType.Left, g.ItemId == c.Id,
                    JoinType.Inner, d.Id == Convert.ToDecimal(g.Unit)
                )
            ).WhereIF(UtilityHelper.CheckGuid(parsedGuid),
                (g, c, d) => g.ItemInId == parsedGuid)
            .Select((g, c, d) => new MesInvItemInCItems
            {
                Guid = g.Guid,
                WorkNo = g.WorkNo,
                ItemNo = c.ItemNo,
                ItemSname = g.ItemSname,
                Quantity = g.Quantity,
                Unit = d.Fname
            })
            .ToList();
        return result;
    }
    public List<MesInvItemInCDetails> GetInvItemInCDetails(string? pid)
    {
        //string转guid
        var parsedGuid = Guid.Empty;
        if (string.IsNullOrEmpty(pid)) return [];
        var isValid = Guid.TryParse(pid, out parsedGuid);
        if (!isValid)
            throw new ApplicationException("GUID转换错误");
        var result = Db.Queryable<MesInvItemInCDetails, MesItems, MesUnit>(
                (g, c, d) => new JoinQueryInfos(
                    JoinType.Left,
                    g.ItemId == c.Id, JoinType.Inner,
                    d.Id.ToString() == c.Fpurchaseunitid
                )
            ).WhereIF(UtilityHelper.CheckGuid(parsedGuid),
                (g, c, d) => g.ItemInId == parsedGuid)
            .Select((g, c, d) => new MesInvItemInCDetails
            {
                Guid = g.Guid,
                ItemName = c.ItemName,
                ItemModel = c.ItemModel,
                ItemUnit = d.Fname,
                DepotSectionCode = g.DepotSectionCode,
                CbillNo = g.CbillNo,
                ItemBarcode = g.ItemBarcode,
                UrgentFlag = g.UrgentFlag,
                ItemNo = c.ItemNo,
                WorkNo = g.WorkNo,
                Quantity = g.Quantity
            })
            .ToList();
        return result;
    }
@@ -740,8 +865,12 @@
        }
        var ErpUrl = AppsettingsUtility.Settings.ProductionErpUrl;
        var newGuid = Guid.NewGuid();
        var message = new MessageCenter
        {
            Guid = newGuid,
            //Pid = newGuid,
            TableName = tableName,
            Url = ErpUrl,
            Status = 1,
@@ -765,11 +894,10 @@
        var message = MesToErpParam(query);
        var executeReturnIdentity =
            Db.Insertable(message).ExecuteReturnIdentity();
            Db.Insertable(message).ExecuteCommand();
        if (executeReturnIdentity > 0)
        {
            //message.Guid = executeReturnIdentity;
            message.Pid = executeReturnIdentity;
            message.Pid = message.Guid;
            return message;
        }
@@ -797,7 +925,7 @@
            .SetColumns(x => x.Status == entity.status)
            .SetColumns(x => x.InsDate == entity.date)
            .Where(x => x.BillNo == entity.billNo)
            .IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand() > 0;
            .IgnoreColumns(true).ExecuteCommand() > 0;
    }
    private string GetErpParameters(string? billNo)
@@ -813,24 +941,20 @@
            MesInvItemArnDetail>(
            (g, c, d, a) => new JoinQueryInfos(
                JoinType.Left,
                g.ItemNo == c.ItemNo && g.Company == c.Company &&
                g.Factory == c.Factory, JoinType.Inner,
                d.Id == Convert.ToDecimal(c.ItemUnit),
                JoinType.Inner,
                a.Ebeln == g.WorkNo && a.WorkLine == g.EbelnLineNo
                                    && g.CbillNo == a.CbillNo
                g.ItemId == c.Id, JoinType.Inner,
                d.Id.ToString() == c.Fpurchaseunitid,
                JoinType.Inner, a.Ebeln == g.WorkNo && g.CbillNo == a.CbillNo
            )
        ).Where((g, c, d, a) => g.BillNo == billNo).Select<Material>(
            (g, c, d, a) => new Material
            {
                // FstockId = g.DepotCode,
                // FuintId = d.Fnumber,
                // FsrcEntryId = a.Id,
                // FmesEntryId = g.Id,
                // FmaterialId = a.ItemNo,
                // DepotSectionCode = g.DepotSectionCode,
                // WorkNo = g.WorkNo,
                // Frealqty = g.Quantity
                FMaterialId = c.ItemNo,
                FRealQty = g.Quantity.ToString(),
                FStockId = g.DepotCode,
                FLot = a.CbillNo,
                FUnitID = d.Fnumber,
                FsrcEntryId = a.Guid.ToString(),
                FMesEntryid = g.Guid.ToString()
            }).ToList();
@@ -840,12 +964,13 @@
        var jsonEntries = materials.Select(d => new
        {
            // FMaterialId = d.FmaterialId,
            // FUintId = d.FuintId,
            // FRealQty = d.Frealqty,
            // FStockId = d.FstockId,
            // FSRCENTRYID = d.FsrcEntryId.ToString(),
            // F_MES_ENTRYID = d.FmesEntryId.ToString()
            d.FMaterialId,
            d.FRealQty,
            d.FStockId,
            d.FLot,
            FUintId = d.FUnitID,
            FSRCENTRYID = d.FsrcEntryId,
            F_MES_ENTRYID = d.FMesEntryid
        }).ToList();
        var fdate = DateTime.Now.ToString("yyyy-MM-dd");