| | |
| | | using NewPdaSqlServer.DB; |
| | | using Masuit.Tools.Models; |
| | | using NewPdaSqlServer.DB; |
| | | using NewPdaSqlServer.Dto.service; |
| | | using NewPdaSqlServer.entity; |
| | | using NewPdaSqlServer.util; |
| | |
| | | |
| | | var inventoryDetails = Db.Queryable<MesInvItemArnDetail>() |
| | | .Where(it => it.Guid == itemBarcodeDetails.AboutGuid) |
| | | .First(); |
| | | |
| | | var cgddDetails = Db.Queryable<MesRohInData>() |
| | | .Where(it => it.EbelnK3id == inventoryDetails.LineK3id) |
| | | .First(); |
| | | |
| | | if (inventoryDetails == null) |
| | |
| | | throw new Exception("入库失败,到货单据有问题!"); |
| | | } |
| | | |
| | | var owner_type = ""; |
| | | if (Db.Queryable<SysOrganization>().Any(x => x.Fid == cgddDetails.DemandOrg)) |
| | | { |
| | | owner_type = "BD_OwnerOrg"; |
| | | } |
| | | else |
| | | { |
| | | // 第二层判断:检查 MES_CUSTOMER |
| | | if (Db.Queryable<MesCustomer>().Any(x => x.Id == Convert.ToInt32(cgddDetails.DemandOrg))) |
| | | { |
| | | owner_type = "BD_Customer"; |
| | | } |
| | | else |
| | | { |
| | | // 第三层判断:检查 MES_SUPPLIER |
| | | if (Db.Queryable<MesSupplier>().Any(x => x.Id == Convert.ToInt32(cgddDetails.DemandOrg))) |
| | | { |
| | | owner_type = "BD_Supplier"; |
| | | } |
| | | else |
| | | { |
| | | |
| | | // 第四层判断:再次检查 SYS_ORGANIZATION |
| | | if (Db.Queryable<SysOrganization>().Any(x => x.Fid == cgddDetails.ReceivingOrg)) |
| | | { |
| | | owner_type = "BD_OwnerOrg"; |
| | | } |
| | | else |
| | | { |
| | | throw new Exception("入库失败,到货单据对应的需求组织有问题!"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | var result = new PurchaseInventory(); |
| | | |
| | | UseTransaction(db => |
| | |
| | | .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 |
| | | && it.CbillNo == itemBarcodeDetails.BillNo |
| | | && it.DepotsCode == mesDepost.DepotCode) |
| | | .Select(it => new |
| | | { |
| | |
| | | else |
| | | { |
| | | cId = Guid.NewGuid(); |
| | | cBillNo = BillNo.GetBillNo("IN(入库单)"); |
| | | cBillNo = BillNo.GetBillNo("CGRK(采购入库)"); |
| | | |
| | | var suppNo = db.Queryable<MesSupplier>() |
| | | .Where(s => s.Id.ToString() == inventory.SuppId).First(); |
| | |
| | | CbillNo = itemBarcodeDetails.BillNo, |
| | | Fstatus = 0, |
| | | Status = 0, |
| | | ReceiveOrgId = inventory.ReceiveOrgId |
| | | ReceiveOrgId = inventory.ReceiveOrgId, |
| | | InType = "采购入库", |
| | | //WorkNo = itemBarcodeDetails.WorkNo |
| | | }).IgnoreColumns(true).ExecuteCommand(); |
| | | } |
| | | |
| | |
| | | |
| | | // Check if already inserted |
| | | var count = db.Queryable<MesInvItemInCItems>() |
| | | .Where(t => |
| | | t.ItemInId == cId && |
| | | t.ItemId == detail.ItemId && |
| | | t.WorkNo == detail.WorkNo && |
| | | t.WorkLine == detail.WorkLine) |
| | | .Where(it => |
| | | it.ItemInId == cId && |
| | | it.ItemId == detail.ItemId && |
| | | it.DepotId == depotCode2 && |
| | | it.EbelnK3id == detail.EbelnK3id && |
| | | it.LineK3id == detail.LineK3id) |
| | | .Count(); |
| | | |
| | | cSyQty -= remainingQty.Value; |
| | |
| | | SuppNo = itemBarcodeDetails.SuppNo, |
| | | Remark = itemBarcodeDetails.Memo, |
| | | EbelnK3id = detail.EbelnK3id, |
| | | LineK3id = detail.LineK3id |
| | | LineK3id = detail.LineK3id, |
| | | DepotId = depotCode2 |
| | | }).IgnoreColumns(true).ExecuteCommand(); |
| | | else |
| | | db.Updateable<MesInvItemInCItems>() |
| | |
| | | .Where(it => |
| | | it.ItemInId == cId && |
| | | it.ItemId == detail.ItemId && |
| | | it.WorkNo == detail.WorkNo && |
| | | it.WorkLine == detail.WorkLine) |
| | | it.DepotId == depotCode2 && |
| | | it.EbelnK3id == detail.EbelnK3id && |
| | | it.LineK3id == detail.LineK3id) |
| | | .IgnoreColumns(true) |
| | | .ExecuteCommand(); |
| | | |
| | |
| | | EbelnK3id = detail.EbelnK3id, |
| | | LineK3id = detail.LineK3id, |
| | | ItemId = detail.ItemId, |
| | | ReceiveOrgId = inventory.ReceiveOrgId |
| | | ReceiveOrgId = inventory.ReceiveOrgId, |
| | | LotNo = cgddDetails.BatchNumber |
| | | }).IgnoreColumns(true).ExecuteCommand(); |
| | | } |
| | | else |
| | |
| | | .ExecuteCommand(); |
| | | |
| | | var count = db.Queryable<MesInvItemInCItems>() |
| | | .Where(t => |
| | | t.ItemInId == cId && |
| | | t.ItemId == detail.ItemId && |
| | | t.WorkNo == detail.WorkNo && |
| | | t.WorkLine == detail.WorkLine) |
| | | .Where(it => |
| | | it.ItemInId == cId && |
| | | it.ItemId == detail.ItemId && |
| | | it.DepotId == depotCode2 && |
| | | it.EbelnK3id == detail.EbelnK3id && |
| | | it.LineK3id == detail.LineK3id) |
| | | .Count(); |
| | | |
| | | if (count == 0) |
| | |
| | | Remark = itemBarcodeDetails.Memo, |
| | | EbelnK3id = detail.EbelnK3id, |
| | | LineK3id = detail.LineK3id, |
| | | ItemId = detail.ItemId |
| | | ItemId = detail.ItemId, |
| | | DepotId = depotCode2 |
| | | }).IgnoreColumns(true).ExecuteCommand(); |
| | | else |
| | | db.Updateable<MesInvItemInCItems>() |
| | |
| | | .Where(it => |
| | | it.ItemInId == cId && |
| | | it.ItemId == detail.ItemId && |
| | | it.WorkNo == detail.WorkNo && |
| | | it.WorkLine == detail.WorkLine) |
| | | it.DepotId == depotCode2 && |
| | | it.EbelnK3id == detail.EbelnK3id && |
| | | it.LineK3id == detail.LineK3id) |
| | | .IgnoreColumns(true) |
| | | .ExecuteCommand(); |
| | | |
| | |
| | | EbelnK3id = detail.EbelnK3id, |
| | | LineK3id = detail.LineK3id, |
| | | ItemId = detail.ItemId, |
| | | ReceiveOrgId = inventory.ReceiveOrgId |
| | | ReceiveOrgId = inventory.ReceiveOrgId, |
| | | LotNo = cgddDetails.BatchNumber |
| | | }).IgnoreColumns(true).ExecuteCommand(); |
| | | |
| | | cSyQty = 0; // Remaining quantity fulfilled |
| | |
| | | BusinessType = 1, |
| | | ItemBarcode = itemBarcode, |
| | | ItemNo = itemBarcodeDetails.ItemNo, |
| | | LotNo = itemBarcodeDetails.LotNo, |
| | | LotNo = cgddDetails.BatchNumber, |
| | | EpFlag = true, |
| | | Quantity = itemBarcodeDetails.Quantity, |
| | | ToInvDepotsCode = mesDepost.DepotCode, |
| | |
| | | } |
| | | else |
| | | { |
| | | var detailone = db.Queryable<MesInvItemArnDetail>() |
| | | .Where(d => |
| | | d.Guid == itemBarcodeDetails.AboutGuid) |
| | | .First(); |
| | | |
| | | // 检查是否存在于 MES_INV_ITEM_IN_C_ITEMS 表 |
| | | var existingCount = db.Queryable<MesInvItemInCItems>() |
| | | .Where(t => t.ItemInId == cId && |
| | | t.ItemId == itemBarcodeDetails.ItemId && |
| | | t.WorkNo == itemBarcodeDetails.WorkNo && |
| | | t.WorkLine == itemBarcodeDetails.WorkLine) |
| | | .Where(it => |
| | | it.ItemInId == cId && |
| | | it.ItemId == detailone.ItemId && |
| | | it.DepotId == depotCode2 && |
| | | it.EbelnK3id == detailone.EbelnK3id && |
| | | it.LineK3id == detailone.LineK3id) |
| | | .Count(); |
| | | |
| | | if (existingCount == 0) |
| | |
| | | Remark = itemBarcodeDetails.Memo, |
| | | EbelnK3id = itemBarcodeDetails.EbelnK3id, |
| | | LineK3id = itemBarcodeDetails.LineK3id, |
| | | ItemId = itemBarcodeDetails.ItemId |
| | | ItemId = itemBarcodeDetails.ItemId, |
| | | DepotId = depotCode2 |
| | | }).IgnoreColumns(true).ExecuteCommand(); |
| | | else |
| | | // 存在时更新数量 |
| | | db.Updateable<MesInvItemInCItems>() |
| | | .SetColumns(it => |
| | | it.Quantity == |
| | | it.Quantity + itemBarcodeDetails.Quantity) |
| | | .Where(it => it.ItemInId == cId && |
| | | it.ItemId == itemBarcodeDetails.ItemId && |
| | | it.WorkNo == itemBarcodeDetails.WorkNo && |
| | | it.WorkLine == itemBarcodeDetails.WorkLine) |
| | | .IgnoreColumns(true) |
| | | .SetColumns(it => new MesInvItemInCItems |
| | | { |
| | | Quantity = SqlFunc.IsNull(it.Quantity, 0) + itemBarcodeDetails.Quantity // 确保 Quantity 不为 null |
| | | }) |
| | | .Where(it => |
| | | it.ItemInId == cId && |
| | | it.ItemId == detailone.ItemId && |
| | | it.DepotId == depotCode2 && |
| | | it.EbelnK3id == detailone.EbelnK3id && |
| | | it.LineK3id == detailone.LineK3id) |
| | | //.IgnoreColumns(true) // 保留 IgnoreColumns |
| | | .ExecuteCommand(); |
| | | |
| | | // 插入 mes_inv_item_in_c_details 表 |
| | |
| | | EpFlag = true, |
| | | WorkType = 1, |
| | | ItemNo = itemBarcodeDetails.ItemNo, |
| | | LotNo = itemBarcodeDetails.LotNo, |
| | | LotNo = cgddDetails.BatchNumber, |
| | | SuppId = itemBarcodeDetails.SuppId, |
| | | SuppNo = itemBarcodeDetails.SuppNo, |
| | | DepotCode = mesDepost.DepotCode, |
| | |
| | | CheckDate = inventoryDetails.CheckDate, |
| | | CheckRes = inventoryDetails.CheckRes, |
| | | CheckStates = inventoryDetails.CheckStates, |
| | | ReceiveOrgId = inventory.ReceiveOrgId |
| | | ReceiveOrgId = inventory.ReceiveOrgId, |
| | | DepotId = Convert.ToInt64(depotCode2) |
| | | }).IgnoreColumns(true).ExecuteCommand(); |
| | | |
| | | // 插入 mes_inv_business2 表 |
| | |
| | | // 插入 mes_inv_item_stocks 表 |
| | | } |
| | | |
| | | |
| | | |
| | | db.Insertable(new MesInvItemStocks |
| | | { |
| | | TaskNo = itemBarcodeDetails.TaskNo, |
| | | ItemBarcode = itemBarcode, |
| | | ItemNo = itemBarcodeDetails.ItemNo, |
| | | ItemNo = cgddDetails.BatchNumber, |
| | | LotNo = itemBarcodeDetails.LotNo, |
| | | Quantity = itemBarcodeDetails.Quantity, |
| | | DepotsCode = mesDepost.DepotCode, |
| | |
| | | LineK3id = itemBarcodeDetails.LineK3id, |
| | | ItemId = itemBarcodeDetails.ItemId, |
| | | BillNo = itemBarcodeDetails.BillNo, |
| | | DepotId = Convert.ToInt32(depotCode2) |
| | | DepotId = Convert.ToInt32(depotCode2), |
| | | OwnerId = cgddDetails.DemandOrg, |
| | | OwnerType = owner_type, |
| | | StockOrgId = mesDepost.FSubsidiary, |
| | | IndepUserCode = user |
| | | }).IgnoreColumns(true).ExecuteCommand(); |
| | | |
| | | itemBarcodeDetails.Hbdy ??= 0; |