| | |
| | | using Masuit.Tools.Models; |
| | | using NewPdaSqlServer.DB; |
| | | using NewPdaSqlServer.DB; |
| | | using NewPdaSqlServer.Dto.service; |
| | | using NewPdaSqlServer.entity; |
| | | using NewPdaSqlServer.entity.Base; |
| | |
| | | using NewPdaSqlServer.util; |
| | | using Newtonsoft.Json; |
| | | using SqlSugar; |
| | | using static Microsoft.EntityFrameworkCore.DbLoggerCategory; |
| | | |
| | | namespace NewPdaSqlServer.service.Warehouse; |
| | | |
| | |
| | | if (itemBarcodeDetails == null) |
| | | throw new Exception("条码不存在,请核对!"); |
| | | |
| | | if (string.IsNullOrEmpty(itemBarcodeDetails.Memo) || itemBarcodeDetails.Memo != "采购入库") |
| | | if (string.IsNullOrEmpty(itemBarcodeDetails.Memo) || |
| | | itemBarcodeDetails.Memo != "采购入库") |
| | | throw new Exception("此条码不属于到货条码,无法用采购入库!"); |
| | | |
| | | var inventory = Db.Queryable<MesInvItemArn>() |
| | | .Where(it => it.BillNo == itemBarcodeDetails.BillNo && it.Fstatus == true ) |
| | | .Where(it => |
| | | it.BillNo == itemBarcodeDetails.BillNo && it.Fstatus == true) |
| | | .First(); |
| | | |
| | | if (inventory == null) |
| | |
| | | throw new Exception("此条码找不到对应收货单明细!"); |
| | | |
| | | //获取到货检验明细 |
| | | var sqlParams = new List<SugarParameter> { new("@dhmxGuid", itemBarcodeDetails.AboutGuid) }; |
| | | var sqlParams = new List<SugarParameter> |
| | | { new("@dhmxGuid", itemBarcodeDetails.AboutGuid) }; |
| | | var sql1 = @"SELECT *FROM v_dhmx WHERE dhmxGuid = @dhmxGuid "; |
| | | var dhjymx = Db.Ado.SqlQuery<vDhmx>(sql1, sqlParams).First(); |
| | | //判定检验能否入库 |
| | | if (dhjymx.CanStore!= 1) |
| | | { |
| | | throw new Exception($"该条码对应的收料单检验结果:【{dhjymx.InspectionResult}】,判定结果:【{dhjymx.JudgmentResult}】,处理意见:【{dhjymx.HandlingSuggestion}】,无法入库"); |
| | | } |
| | | if (dhjymx.CanStore != 1) |
| | | throw new Exception( |
| | | $"该条码对应的收料单检验结果:【{dhjymx.InspectionResult}】,判定结果:【{dhjymx.JudgmentResult}】,处理意见:【{dhjymx.HandlingSuggestion}】,无法入库"); |
| | | |
| | | var depotCode = Db.Queryable<MesDepotSections>() |
| | | .Where(it => it.DepotSectionCode == sectionCode) |
| | |
| | | |
| | | var checkGuid = UtilityHelper.CheckGuid(depotCode); |
| | | if (checkGuid && depotCode != null) |
| | | { |
| | | mesDepost = Db.Queryable<MesDepots>() |
| | | .Where(s => s.DepotId.ToString() == depotCode).First(); |
| | | |
| | | // if (depotCode != mesDepost.Guid) |
| | | // throw new Exception("扫描库位与采购入库库位不一致!"); |
| | | } |
| | | // if (depotCode != mesDepost.Guid) |
| | | // throw new Exception("扫描库位与采购入库库位不一致!"); |
| | | else |
| | | { |
| | | throw new Exception("库位编码 " + sectionCode + " 不存在,请确认!"); |
| | | } |
| | | |
| | | |
| | | //num = Db.Queryable<MesInvItemInCDetails>() |
| | |
| | | var wmsManager = new WmsBaseMangeer(); |
| | | // 新增入库校验(调用存储过程) |
| | | var checkResult = wmsManager.pdaInvJY( |
| | | db: Db, |
| | | edtUserNo: entity.userName, |
| | | barcode: entity.barcode, |
| | | sectionCode: sectionCode, |
| | | stockId: mesDepost.DepotId.ToString(), |
| | | stockOrgId: mesDepost.FSubsidiary, |
| | | billNo: "", // 根据实际单据号传值 |
| | | transactionNo: "101" // 事务类型与存储过程匹配 |
| | | Db, |
| | | entity.userName, |
| | | entity.barcode, |
| | | sectionCode, |
| | | mesDepost.DepotId.ToString(), |
| | | mesDepost.FSubsidiary, |
| | | "", // 根据实际单据号传值 |
| | | "101" // 事务类型与存储过程匹配 |
| | | ); |
| | | |
| | | if (Convert.ToInt32(checkResult.result) < 1) |
| | | throw new Exception($"入库校验失败:{checkResult.strMsg}"); |
| | | |
| | | |
| | | |
| | | //num = Db.Queryable<MesInvItemArn>() |
| | |
| | | UseTransaction(db => |
| | | { |
| | | var existingRecord = db.Queryable<MesInvItemIns>() |
| | | .Where(it => it.InsDate.Value.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd") |
| | | && it.TaskNo == itemBarcodeDetails.BillNo |
| | | && it.Status == 0 |
| | | && it.TransctionNo == transactionNo |
| | | && it.CreateBy == entity.userName |
| | | && it.BillTypeId == billTypeId |
| | | && it.DepotsId == mesDepost.DepotId) |
| | | .Where(it => |
| | | it.InsDate.Value.ToString("yyyy-MM-dd") == |
| | | DateTime.Now.ToString("yyyy-MM-dd") |
| | | && it.TaskNo == itemBarcodeDetails.BillNo |
| | | && it.Status == 0 |
| | | && it.TransctionNo == transactionNo |
| | | && it.CreateBy == entity.userName |
| | | && it.BillTypeId == billTypeId |
| | | && it.DepotsId == mesDepost.DepotId) |
| | | .Select(it => new |
| | | { |
| | | it.Guid, |
| | |
| | | CreateDate = DateTime.Now, |
| | | LastupdateBy = user, |
| | | LastupdateDate = DateTime.Now, |
| | | UrgentFlag = itemBarcodeDetails.UrgentFlag.GetValueOrDefault() ? "1" : "0", |
| | | UrgentFlag = |
| | | itemBarcodeDetails.UrgentFlag.GetValueOrDefault() |
| | | ? "1" |
| | | : "0", |
| | | CbillNo = itemBarcodeDetails.BillNo, |
| | | Fstatus = 0, |
| | | Status = 0, |
| | |
| | | var count = db.Queryable<MesInvItemInCItems>() |
| | | .Where(it => |
| | | it.ItemInId == cId && |
| | | it.ItemId == detail.ItemId && |
| | | it.DepotId == mesDepost.DepotId.ToString() && |
| | | it.EbelnK3id == detail.EbelnK3id && |
| | | it.LineK3id == detail.LineK3id) |
| | | it.ItemId == detail.ItemId && |
| | | it.DepotId == mesDepost.DepotId.ToString() && |
| | | it.EbelnK3id == detail.EbelnK3id && |
| | | it.LineK3id == detail.LineK3id) |
| | | .Count(); |
| | | |
| | | cSyQty -= remainingQty.Value; |
| | |
| | | EbelnK3id = detail.EbelnK3id, |
| | | LineK3id = detail.LineK3id, |
| | | DepotId = mesDepost.DepotId.ToString(), |
| | | itemDabid = itemBarcodeDetails.AboutGuid.ToString() |
| | | itemDabid = itemBarcodeDetails.AboutGuid |
| | | .ToString() |
| | | }).IgnoreColumns(true).ExecuteCommand(); |
| | | else |
| | | db.Updateable<MesInvItemInCItems>() |
| | |
| | | .Where(it => |
| | | it.ItemInId == cId && |
| | | it.ItemId == detail.ItemId && |
| | | it.DepotId == mesDepost.DepotId.ToString() && |
| | | it.DepotId == |
| | | mesDepost.DepotId.ToString() && |
| | | it.EbelnK3id == detail.EbelnK3id && |
| | | it.LineK3id == detail.LineK3id) |
| | | .IgnoreColumns(true) |
| | |
| | | var count = db.Queryable<MesInvItemInCItems>() |
| | | .Where(it => |
| | | it.ItemInId == cId && |
| | | it.ItemId == detail.ItemId && |
| | | it.DepotId == mesDepost.DepotId.ToString() && |
| | | it.EbelnK3id == detail.EbelnK3id && |
| | | it.LineK3id == detail.LineK3id) |
| | | it.ItemId == detail.ItemId && |
| | | it.DepotId == mesDepost.DepotId.ToString() && |
| | | it.EbelnK3id == detail.EbelnK3id && |
| | | it.LineK3id == detail.LineK3id) |
| | | .Count(); |
| | | |
| | | if (count == 0) |
| | |
| | | .Where(it => |
| | | it.ItemInId == cId && |
| | | it.ItemId == detail.ItemId && |
| | | it.DepotId == mesDepost.DepotId.ToString() && |
| | | it.DepotId == |
| | | mesDepost.DepotId.ToString() && |
| | | it.EbelnK3id == detail.EbelnK3id && |
| | | it.LineK3id == detail.LineK3id) |
| | | .IgnoreColumns(true) |
| | |
| | | // 检查是否存在于 MES_INV_ITEM_IN_C_ITEMS 表 |
| | | var existingCount = db.Queryable<MesInvItemInCItems>() |
| | | .Where(it => |
| | | it.ItemInId == cId && |
| | | it.ItemId == detailone.ItemId && |
| | | it.DepotId == mesDepost.DepotId.ToString() && |
| | | it.itemDabid == itemBarcodeDetails.AboutGuid.ToString()) |
| | | it.ItemInId == cId && |
| | | it.ItemId == detailone.ItemId && |
| | | it.DepotId == mesDepost.DepotId.ToString() && |
| | | it.itemDabid == itemBarcodeDetails.AboutGuid.ToString()) |
| | | .Count(); |
| | | |
| | | if (existingCount == 0) |
| | |
| | | db.Updateable<MesInvItemInCItems>() |
| | | .SetColumns(it => new MesInvItemInCItems |
| | | { |
| | | Quantity = SqlFunc.IsNull(it.Quantity, 0) + itemBarcodeDetails.Quantity // 确保 Quantity 不为 null |
| | | Quantity = SqlFunc.IsNull(it.Quantity, 0) + |
| | | itemBarcodeDetails |
| | | .Quantity // 确保 Quantity 不为 null |
| | | }) |
| | | .Where(it => |
| | | it.ItemInId == cId && |
| | | it.ItemId == detailone.ItemId && |
| | | it.DepotId == mesDepost.DepotId.ToString() && |
| | | it.itemDabid == itemBarcodeDetails.AboutGuid.ToString()) |
| | | it.ItemInId == cId && |
| | | it.ItemId == detailone.ItemId && |
| | | it.DepotId == mesDepost.DepotId.ToString() && |
| | | it.itemDabid == |
| | | itemBarcodeDetails.AboutGuid.ToString()) |
| | | //.IgnoreColumns(true) // 保留 IgnoreColumns |
| | | .ExecuteCommand(); |
| | | |
| | |
| | | |
| | | // 插入 mes_inv_item_stocks 表 |
| | | } |
| | | |
| | | |
| | | |
| | | db.Insertable(new MesInvItemStocks |
| | |
| | | |
| | | //result.Message = |
| | | // $"条码数量 {itemBarcodeDetails.Quantity},采购订单 {itemBarcodeDetails.WorkNo} 项次 {itemBarcodeDetails.WorkLine} 物料 {mesItems.ItemNo} 本次入库总数:{totalCDetailsQuantity} 总到 {comeQty} 已入 {invQty} 欠 {diffQty}"; |
| | | result.Message = $"物料{mesItems.ItemNo}入库成功数量{itemBarcodeDetails.Quantity.ToString()}"; |
| | | result.Message = |
| | | $"物料{mesItems.ItemNo}入库成功数量{itemBarcodeDetails.Quantity.ToString()}"; |
| | | |
| | | result.itemDetail = mesItems; |
| | | |
| | | result.ItemInDetails = db.Queryable<MesInvItemInCItems,MesItems>( |
| | | (a, b) => new JoinQueryInfos( |
| | | JoinType.Left, |
| | | a.ItemId == b.ItemId) |
| | | result.ItemInDetails = db |
| | | .Queryable<MesInvItemInCItems, MesItems>((a, b) => |
| | | new JoinQueryInfos( |
| | | JoinType.Left, |
| | | a.ItemId == b.ItemId) |
| | | ) |
| | | .Where(a => a.ItemInId == cId && a.ItemId == itemBarcodeDetails.ItemId) |
| | | .Select<dynamic>((a, b) => new |
| | | .Where(a => |
| | | a.ItemInId == cId && |
| | | a.ItemId == itemBarcodeDetails.ItemId) |
| | | .Select<dynamic>((a, b) => new |
| | | { |
| | | ItemNo = b.ItemNo, |
| | | ItemName = b.ItemName, |
| | | ItemModel = b.ItemModel, |
| | | b.ItemNo, |
| | | b.ItemName, |
| | | b.ItemModel, |
| | | FQty = a.Quantity, // 申请数量 |
| | | FMaterialId = b.ItemId, |
| | | Id = b.Guid.ToString() |
| | | }) |
| | | .ToList(); |
| | | |
| | | result.ItemBarCDetails = db.Queryable<MesInvItemInCDetails, MesItems>( |
| | | (a, b) => new JoinQueryInfos( |
| | | JoinType.Left, |
| | | a.ItemId == b.ItemId) |
| | | result.ItemBarCDetails = db |
| | | .Queryable<MesInvItemInCDetails, MesItems>((a, b) => |
| | | new JoinQueryInfos( |
| | | JoinType.Left, |
| | | a.ItemId == b.ItemId) |
| | | ) |
| | | .Where(a => a.ItemInId == cId && a.ItemId == itemBarcodeDetails.ItemId) |
| | | .Where(a => |
| | | a.ItemInId == cId && |
| | | a.ItemId == itemBarcodeDetails.ItemId) |
| | | .Select<dynamic>((a, b) => new |
| | | { |
| | | ItemNo = b.ItemNo, |
| | | ItemName = b.ItemName, |
| | | ItemModel = b.ItemModel, |
| | | b.ItemNo, |
| | | b.ItemName, |
| | | b.ItemModel, |
| | | FQty = a.Quantity, // 申请数量 |
| | | FMaterialId = b.ItemId, |
| | | Id = a.Guid.ToString(), |
| | |
| | | |
| | | // 创建 插入日志 |
| | | var logService = new LogService(); |
| | | var LogMsg = "【PDA】采购入库。条码【" + entity.barcode + "】 入库单号【" + cBillNo + "】"; |
| | | logService.CreateLog(db, entity.userName, inventory.Guid.ToString(), "MES_INV_ITEM_ARN", LogMsg, inventory.BillNo); |
| | | var LogMsg = "【PDA】采购入库。条码【" + entity.barcode + "】 入库单号【" + |
| | | cBillNo + "】"; |
| | | logService.CreateLog(db, entity.userName, inventory.Guid.ToString(), |
| | | "MES_INV_ITEM_ARN", LogMsg, inventory.BillNo); |
| | | |
| | | return 1; |
| | | }); |
| | | |
| | | var purchaseInventory = getPurchaseInventory(entity); |
| | | |
| | | |
| | | |
| | | //result.ItemInDetails = purchaseInventory.ItemInDetails; |
| | | //result.InvItemInCDetails = purchaseInventory.InvItemInCDetails; |
| | | |
| | |
| | | } |
| | | |
| | | 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())) |
| | | 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 |
| | |
| | | if (!isValid) |
| | | throw new ApplicationException("GUID转换错误"); |
| | | |
| | | var result = Db.Queryable<MesInvItemInCDetails, MesItems, MesUnit>( |
| | | (g, c, d) => new JoinQueryInfos( |
| | | 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) |
| | | ) |
| | |
| | | if (!isValid) |
| | | throw new ApplicationException("GUID转换错误"); |
| | | |
| | | var result = Db.Queryable<MesInvItemInCDetails, MesItems, MesUnit>( |
| | | (g, c, d) => new JoinQueryInfos( |
| | | 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 |
| | |
| | | if (invItemIns.Status == 1) throw new Exception("入库单已审核,不能重复推送"); |
| | | |
| | | var materials = Db.Queryable<MesInvItemInCItems, MesItems, MesUnit, |
| | | MesInvItemArnDetail>( |
| | | (g, c, d, a) => new JoinQueryInfos( |
| | | JoinType.Left, |
| | | 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 |
| | | MesInvItemArnDetail>((g, c, d, a) => new JoinQueryInfos( |
| | | JoinType.Left, |
| | | 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 |
| | | { |
| | | FMaterialId = c.ItemNo, |
| | | FRealQty = g.Quantity.ToString(), |