| | |
| | | using NewPdaSqlServer.DB; |
| | | using NewPdaSqlServer.Dto.service; |
| | | using NewPdaSqlServer.entity; |
| | | using NewPdaSqlServer.entity.Base; |
| | | using NewPdaSqlServer.service.@base; |
| | | using NewPdaSqlServer.util; |
| | | using Newtonsoft.Json; |
| | | using SqlSugar; |
| | | using static Microsoft.EntityFrameworkCore.DbLoggerCategory; |
| | | |
| | | namespace NewPdaSqlServer.service.Warehouse; |
| | | |
| | |
| | | { |
| | | //å½å类已ç»ç»§æ¿äº Repository å¢ãå ãæ¥ãæ¹çæ¹æ³ |
| | | |
| | | public PurchaseInventory SaveBarCodes(WarehouseQuery entity) |
| | | public ItemInBaseModel SaveBarCodes(WarehouseQuery entity) |
| | | { |
| | | string functionName = "éè´å
¥åº", fieldName = null, inFieldVal = null; |
| | | string user = entity.userName, |
| | |
| | | var freeze = 0; |
| | | decimal cSyQty = 0; |
| | | |
| | | if (string.IsNullOrEmpty(sectionCode)) |
| | | throw new Exception("请æ«åºä½æ¡ç ï¼"); |
| | | //if (string.IsNullOrEmpty(sectionCode)) |
| | | // throw new Exception("请æ«åºä½æ¡ç ï¼"); |
| | | |
| | | var itemBarcodeDetails = Db.Queryable<MesInvItemBarcodes>() |
| | | .Where(it => it.ItemBarcode == itemBarcode) |
| | | .First(); |
| | | |
| | | if (itemBarcodeDetails == null) |
| | | throw new Exception("æ¡ç ä¸åå¨ï¼è¯·æ ¸å¯¹ï¼"); |
| | | //if (itemBarcodeDetails == null) |
| | | // throw new Exception("æ¡ç ä¸åå¨ï¼è¯·æ ¸å¯¹ï¼"); |
| | | |
| | | if (itemBarcodeDetails.ComeFlg == 0) |
| | | if (string.IsNullOrEmpty(itemBarcodeDetails.Memo) || itemBarcodeDetails.Memo != "éè´å
¥åº") |
| | | throw new Exception("æ¤æ¡ç ä¸å±äºå°è´§æ¡ç ï¼æ æ³ç¨éè´å
¥åºï¼"); |
| | | |
| | | var inventory = Db.Queryable<MesInvItemArn>() |
| | |
| | | |
| | | if (inventoryDetails == null) |
| | | throw new Exception("æ¤æ¡ç æ¾ä¸å°å¯¹åºæ¶è´§åæç»ï¼"); |
| | | |
| | | if (string.IsNullOrEmpty(inventoryDetails.CheckRes) || inventoryDetails.CheckRes != "åæ ¼") |
| | | { |
| | | throw new Exception("该æ¡ç 对åºçæ¶æåæ£éªä¸åæ ¼ææªæ£éªï¼"); |
| | | } |
| | | |
| | | var depotCode = Db.Queryable<MesDepotSections>() |
| | | .Where(it => it.DepotSectionCode == sectionCode) |
| | |
| | | } |
| | | |
| | | |
| | | num = Db.Queryable<MesInvItemInCDetails>() |
| | | .Where(it => it.ItemBarcode == itemBarcode) |
| | | .Count(); |
| | | //num = Db.Queryable<MesInvItemInCDetails>() |
| | | // .Where(it => it.ItemBarcode == itemBarcode) |
| | | // .Count(); |
| | | |
| | | if (num > 0) |
| | | throw new Exception("æ¤æ¡ç å·²æ«ç å
¥åºå®æï¼è¯·æ ¸å¯¹ï¼"); |
| | | //if (num > 0) |
| | | // throw new Exception("æ¤æ¡ç å·²æ«ç å
¥åºå®æï¼è¯·æ ¸å¯¹ï¼"); |
| | | |
| | | num = Db.Queryable<MesInvItemStocks>() |
| | | .Where(it => it.ItemBarcode == itemBarcode) |
| | | .Count(); |
| | | //num = Db.Queryable<MesInvItemStocks>() |
| | | // .Where(it => it.ItemBarcode == itemBarcode) |
| | | // .Count(); |
| | | |
| | | if (num > 0) |
| | | throw new Exception("æ¤æ¡ç å·²æ«ç å
¥åºï¼è¯·æ ¸å¯¹ï¼"); |
| | | //if (num > 0) |
| | | // throw new Exception("æ¤æ¡ç å·²æ«ç å
¥åºï¼è¯·æ ¸å¯¹ï¼"); |
| | | |
| | | num = Db.Queryable<MesInvItemArn>() |
| | | .Where(a => a.BillNo == itemBarcodeDetails.BillNo) |
| | | .InnerJoin<MesInvItemArnDetail>((a, b) => |
| | | b.ParentGuid == a.Guid && |
| | | b.ItemId == itemBarcodeDetails.ItemId && b.Ischeck == 1) |
| | | .Count(); |
| | | 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" // äºå¡ç±»åä¸åå¨è¿ç¨å¹é
|
| | | ); |
| | | |
| | | num2 = Db.Queryable<MesInvItemArn>() |
| | | .Where(a => a.BillNo == itemBarcodeDetails.BillNo) |
| | | .InnerJoin<MesInvItemArnDetail>((a, b) => b.ParentGuid == a.Guid |
| | | && b.ItemId == itemBarcodeDetails.ItemId |
| | | && (b.CheckRes == "åæ ¼" || b.CheckStates == "ç¹éç´æ¥ä½¿ç¨")) |
| | | .Count(); |
| | | if (Convert.ToInt32(checkResult.result) < 1) |
| | | throw new Exception($"å
¥åºæ ¡éªå¤±è´¥ï¼{checkResult.strMsg}"); |
| | | |
| | | switch (num) |
| | | { |
| | | case 0 when num2 == 0: |
| | | case > 0 when num2 == 0: |
| | | freeze = 1; |
| | | break; |
| | | case 0 when num2 > 0: |
| | | 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("å
¥åºå¤±è´¥,å°è´§åæ®å¯¹åºçéæ±ç»ç»æé®é¢ï¼"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //num = Db.Queryable<MesInvItemArn>() |
| | | // .Where(a => a.BillNo == itemBarcodeDetails.BillNo) |
| | | // .InnerJoin<MesInvItemArnDetail>((a, b) => |
| | | // b.ParentGuid == a.Guid && |
| | | // b.ItemId == itemBarcodeDetails.ItemId && b.Ischeck == 1) |
| | | // .Count(); |
| | | |
| | | var result = new PurchaseInventory(); |
| | | //num2 = Db.Queryable<MesInvItemArn>() |
| | | // .Where(a => a.BillNo == itemBarcodeDetails.BillNo) |
| | | // .InnerJoin<MesInvItemArnDetail>((a, b) => b.ParentGuid == a.Guid |
| | | // && b.ItemId == itemBarcodeDetails.ItemId |
| | | // && (b.CheckRes == "åæ ¼" || b.CheckStates == "ç¹éç´æ¥ä½¿ç¨")) |
| | | // .Count(); |
| | | |
| | | //switch (num) |
| | | //{ |
| | | // case 0 when num2 == 0: |
| | | // case > 0 when num2 == 0: |
| | | // freeze = 1; |
| | | // break; |
| | | // case 0 when num2 > 0: |
| | | // throw new Exception("å
¥åºå¤±è´¥,å°è´§åæ®æé®é¢ï¼"); |
| | | //} |
| | | |
| | | |
| | | // å¤æè´§ä¸»ç±»å |
| | | var owner_type = wmsManager.GetOwnerType(cgddDetails.DemandOrg); |
| | | // 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 ItemInBaseModel(); |
| | | |
| | | 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.TaskNo == itemBarcodeDetails.BillNo |
| | | && it.DepotsCode == mesDepost.DepotCode) |
| | | && it.DepotsId == mesDepost.DepotId) |
| | | .Select(it => new |
| | | { |
| | | it.Guid, |
| | |
| | | it.ItemInId == cId && |
| | | it.ItemId == detailone.ItemId && |
| | | it.DepotId == depotCode2 && |
| | | it.EbelnK3id == detailone.EbelnK3id && |
| | | it.LineK3id == detailone.LineK3id) |
| | | it.itemDabid == itemBarcodeDetails.AboutGuid.ToString()) |
| | | .Count(); |
| | | |
| | | if (existingCount == 0) |
| | |
| | | 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) |
| | | it.ItemInId == cId && |
| | | it.ItemId == detailone.ItemId && |
| | | it.DepotId == depotCode2 && |
| | | it.itemDabid == itemBarcodeDetails.AboutGuid.ToString()) |
| | | //.IgnoreColumns(true) // ä¿ç IgnoreColumns |
| | | .ExecuteCommand(); |
| | | |
| | |
| | | |
| | | if (itemBarcodeDetails.Hbdy != 1) |
| | | { |
| | | //æ´æ°æ¶æåæç» |
| | | db.Updateable<MesInvItemArnDetail>() |
| | | .SetColumns(d => new MesInvItemArnDetail |
| | | { |
| | | OkRkqty = (int)((d.OkRkqty ?? 0) + cSyQty) |
| | | }) |
| | | .Where(d => d.Guid == inventoryDetails.Guid) |
| | | .Where(d => d.Guid == itemBarcodeDetails.AboutGuid) |
| | | .ExecuteCommand(); |
| | | |
| | | var first = db |
| | | .Queryable<MesInvItemArnDetail>() |
| | | .Where(b => |
| | | b.Guid == inventoryDetails.Guid) |
| | | b.Guid == itemBarcodeDetails.AboutGuid) |
| | | .Select(b => new |
| | | { |
| | | TotalQuantity = |
| | |
| | | if (TotalQuantity == TotalOkRkQty) |
| | | db.Updateable<MesInvItemArnDetail>() |
| | | .SetColumns(s => s.IsdepsIn == true) |
| | | .Where(s => s.Guid == inventoryDetails.Guid) |
| | | .Where(s => s.Guid == itemBarcodeDetails.AboutGuid) |
| | | .ExecuteCommand(); |
| | | |
| | | |
| | |
| | | .ExecuteCommand(); |
| | | |
| | | var totalCDetailsQuantity = db.Queryable<MesInvItemInCDetails>() |
| | | .Where(it => it.WorkLine == itemBarcodeDetails.WorkLine && |
| | | .Where(it => it.ItemId == itemBarcodeDetails.ItemId && |
| | | it.WorkNo == itemBarcodeDetails.WorkNo && |
| | | it.CbillNo == itemBarcodeDetails.BillNo) |
| | | it.ItemInId == cId) |
| | | .Sum(it => it.Quantity); |
| | | |
| | | var detailSummary = db.Queryable<MesInvItemArnDetail>() |
| | |
| | | var mesItems = db.Queryable<MesItems>() |
| | | .Where(s => s.Id == itemBarcodeDetails.ItemId).First(); |
| | | |
| | | result.Message = |
| | | $"æ¡ç æ°é {itemBarcodeDetails.Quantity},éè´è®¢å {itemBarcodeDetails.WorkNo} 项次 {itemBarcodeDetails.WorkLine} ç©æ {mesItems.ItemNo} æ¬æ¬¡å
¥åºæ»æ°ï¼{totalCDetailsQuantity} æ»å° {comeQty} å·²å
¥ {invQty} æ¬ {diffQty}"; |
| | | //result.Message = |
| | | // $"æ¡ç æ°é {itemBarcodeDetails.Quantity},éè´è®¢å {itemBarcodeDetails.WorkNo} 项次 {itemBarcodeDetails.WorkLine} ç©æ {mesItems.ItemNo} æ¬æ¬¡å
¥åºæ»æ°ï¼{totalCDetailsQuantity} æ»å° {comeQty} å·²å
¥ {invQty} æ¬ {diffQty}"; |
| | | 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) |
| | | ) |
| | | .Where(a => a.ItemInId == cId && a.ItemId == itemBarcodeDetails.ItemId) |
| | | .Select<dynamic>((a, b) => new |
| | | { |
| | | ItemNo = b.ItemNo, |
| | | ItemName = b.ItemName, |
| | | ItemModel = 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) |
| | | ) |
| | | .Where(a => a.ItemInId == cId && a.ItemId == itemBarcodeDetails.ItemId) |
| | | .Select<dynamic>((a, b) => new |
| | | { |
| | | ItemNo = b.ItemNo, |
| | | ItemName = b.ItemName, |
| | | ItemModel = b.ItemModel, |
| | | FQty = a.Quantity, // ç³è¯·æ°é |
| | | FMaterialId = b.ItemId, |
| | | Id = a.Guid.ToString(), |
| | | kw = a.DepotSectionCode |
| | | }) |
| | | .ToList(); |
| | | |
| | | |
| | | result.ItemNo = mesItems.ItemNo; |
| | | result.SumQuantity = Convert.ToDecimal(totalCDetailsQuantity); |
| | | //result.ItemNo = mesItems.ItemNo; |
| | | result.SumQuantity = Convert.ToDecimal(invQty); |
| | | |
| | | return 1; |
| | | } |
| | |
| | | |
| | | // Step 2: Calculate total sum from `mes_inv_item_in_c_details` |
| | | var totalCDetailsQuantity = db.Queryable<MesInvItemInCDetails>() |
| | | .Where(it => it.CbillNo == itemBarcodeDetails.BillNo && |
| | | it.ItemId == itemBarcodeDetails.ItemId) |
| | | .Where(it => it.Guid == itemBarcodeDetails.AboutGuid) |
| | | .Sum(it => it.Quantity); |
| | | |
| | | // Step 3: Calculate comeQty and invQty from `mes_inv_item_arn_detail` |
| | | var detailSummary = db.Queryable<MesInvItemArnDetail>() |
| | | .Where(it => it.CbillNo == itemBarcodeDetails.BillNo && |
| | | it.ItemId == itemBarcodeDetails.ItemId) |
| | | .Where(it => it.Guid == itemBarcodeDetails.AboutGuid) |
| | | .Select(it => new |
| | | { |
| | | TotalComeQty = SqlFunc.AggregateSum(it.Quantity), |
| | |
| | | $" æ¡ç æ°é:{itemBarcodeDetails.Quantity},ç©æ {mesItems.ItemNo} æ¬æ¬¡å
¥åºæ»æ°ï¼{totalCDetailsQuantity} æ»å° {comeQty} å·²å
¥ {invQty} æ¬ {diffQty}"; |
| | | |
| | | |
| | | result.ItemNo = mesItems.ItemNo; |
| | | //result.ItemNo = mesItems.ItemNo; |
| | | result.SumQuantity = Convert.ToDecimal(totalCDetailsQuantity); |
| | | } |
| | | |
| | |
| | | |
| | | var purchaseInventory = getPurchaseInventory(entity); |
| | | |
| | | result.ItemIns = purchaseInventory.ItemIns; |
| | | result.ItemInDetails = purchaseInventory.ItemInDetails; |
| | | result.InvItemInCDetails = purchaseInventory.InvItemInCDetails; |
| | | |
| | | //result.ItemInDetails = purchaseInventory.ItemInDetails; |
| | | //result.InvItemInCDetails = purchaseInventory.InvItemInCDetails; |
| | | |
| | | return result; |
| | | } |
| | | |
| | | public PurchaseInventory getPurchaseInventory(WarehouseQuery query) |
| | | public ItemInBaseModel getPurchaseInventory(WarehouseQuery query) |
| | | { |
| | | return new PurchaseInventory |
| | | return new ItemInBaseModel |
| | | { |
| | | ItemIns = GetInvItemInsList(query).Items[0], |
| | | ItemInDetails = GetItemInDetails(query.id), |
| | | InvItemInCDetails = GetInvItemInCDetails(query.id) |
| | | //ItemIns = GetInvItemInsList(query).Items[0], |
| | | //ItemInDetails = GetItemInDetails(query.id), |
| | | //InvItemInCDetails = GetInvItemInCDetails(query.id) |
| | | }; |
| | | } |
| | | |