public virtual IEnumerable POReceiptLinesSelection() { APInvoice doc = Base.Document.Current; if (doc?.VendorID == null || doc.VendorLocationID == null || doc.DocType != APDocType.Invoice && doc.DocType != APDocType.DebitAdj) { yield break; } string poReceiptType = doc.DocType == APDocType.Invoice ? POReceiptType.POReceipt : POReceiptType.POReturn; var comparer = new POAccrualComparer(); HashSet <APTran> usedSourceLine = new HashSet <APTran>(comparer); HashSet <APTran> unusedSourceLine = new HashSet <APTran>(comparer); foreach (APTran aPTran in Base.Transactions.Cache.Inserted) { usedSourceLine.Add(aPTran); } foreach (APTran aPTran in Base.Transactions.Cache.Deleted) { if (Base.Transactions.Cache.GetStatus(aPTran) != PXEntryStatus.InsertedDeleted) { if (!usedSourceLine.Remove(aPTran)) { unusedSourceLine.Add(aPTran); } } } foreach (APTran aPTran in Base.Transactions.Cache.Updated) { APTran originAPTran = new APTran { POAccrualType = (string)Base.Transactions.Cache.GetValueOriginal <APTran.pOAccrualType>(aPTran), POAccrualRefNoteID = (Guid?)Base.Transactions.Cache.GetValueOriginal <APTran.pOAccrualRefNoteID>(aPTran), POAccrualLineNbr = (int?)Base.Transactions.Cache.GetValueOriginal <APTran.pOAccrualLineNbr>(aPTran), POOrderType = (string)Base.Transactions.Cache.GetValueOriginal <APTran.pOOrderType>(aPTran), PONbr = (string)Base.Transactions.Cache.GetValueOriginal <APTran.pONbr>(aPTran), POLineNbr = (int?)Base.Transactions.Cache.GetValueOriginal <APTran.pOLineNbr>(aPTran), ReceiptNbr = (string)Base.Transactions.Cache.GetValueOriginal <APTran.receiptNbr>(aPTran), ReceiptType = (string)Base.Transactions.Cache.GetValueOriginal <APTran.receiptType>(aPTran), ReceiptLineNbr = (int?)Base.Transactions.Cache.GetValueOriginal <APTran.receiptLineNbr>(aPTran) }; if (!usedSourceLine.Remove(originAPTran)) { unusedSourceLine.Add(originAPTran); } if (!unusedSourceLine.Remove(aPTran)) { usedSourceLine.Add(aPTran); } } PXSelectBase <LinkLineReceipt> cmd = new PXSelect <LinkLineReceipt, Where <LinkLineReceipt.receiptType, Equal <Required <POReceipt.receiptType> >, And <Where <LinkLineReceipt.orderNbr, Equal <Current <POReceiptFilter.orderNbr> >, Or <Current <POReceiptFilter.orderNbr>, IsNull> > > > >(Base); if (Base.APSetup.Current.RequireSingleProjectPerDocument == true) { cmd.WhereAnd <Where <LinkLineReceipt.projectID, Equal <Current <APInvoice.projectID> > > >(); } if (PXAccess.FeatureInstalled <FeaturesSet.vendorRelations>()) { cmd.WhereAnd <Where <LinkLineReceipt.vendorID, Equal <Current <APInvoice.suppliedByVendorID> >, And <LinkLineReceipt.vendorLocationID, Equal <Current <APInvoice.suppliedByVendorLocationID> >, And <Where <LinkLineReceipt.payToVendorID, IsNull, Or <LinkLineReceipt.payToVendorID, Equal <Current <APInvoice.vendorID> > > > > > > >(); } else { cmd.WhereAnd <Where <LinkLineReceipt.vendorID, Equal <Current <APInvoice.vendorID> >, And <LinkLineReceipt.vendorLocationID, Equal <Current <APInvoice.vendorLocationID> > > > >(); } foreach (LinkLineReceipt item in cmd.View.SelectMultiBound(new object[] { doc }, poReceiptType)) { APTran aPTran = new APTran { POAccrualType = item.POAccrualType, POAccrualRefNoteID = item.POAccrualRefNoteID, POAccrualLineNbr = item.POAccrualLineNbr, POOrderType = item.OrderType, PONbr = item.OrderNbr, POLineNbr = item.OrderLineNbr, ReceiptType = item.ReceiptType, ReceiptNbr = item.ReceiptNbr, ReceiptLineNbr = item.ReceiptLineNbr }; if (!usedSourceLine.Contains(aPTran)) { var res = (POReceiptLineAdd)ReceipLineAdd.Select(item.ReceiptNbr, item.ReceiptLineNbr); if (res != null) { yield return(res); } } } foreach (APTran item in unusedSourceLine.Where(t => t.POAccrualType != null)) { foreach (POReceiptLineAdd res in PXSelect <POReceiptLineAdd, Where <POReceiptLineAdd.pOAccrualType, Equal <Required <LinkLineReceipt.pOAccrualType> >, And <POReceiptLineAdd.pOAccrualRefNoteID, Equal <Required <LinkLineReceipt.pOAccrualRefNoteID> >, And <POReceiptLineAdd.pOAccrualLineNbr, Equal <Required <LinkLineReceipt.pOAccrualLineNbr> >, And <POReceiptLineAdd.unbilledQty, Greater <decimal0> > > > > > .Select(Base, item.POAccrualType, item.POAccrualRefNoteID, item.POAccrualLineNbr)) { yield return(res); } } }
public virtual IEnumerable LinkLineReceiptTran() { APTran currentAPTran = Base.Transactions.Current; if (currentAPTran == null) { yield break; } var comparer = new POAccrualComparer(); HashSet <APTran> usedSourceLine = new HashSet <APTran>(comparer); HashSet <APTran> unusedSourceLine = new HashSet <APTran>(comparer); foreach (APTran aPTran in Base.Transactions.Cache.Inserted) { if (currentAPTran.InventoryID == aPTran.InventoryID && currentAPTran.UOM == aPTran.UOM) { usedSourceLine.Add(aPTran); } } foreach (APTran aPTran in Base.Transactions.Cache.Deleted) { if (currentAPTran.InventoryID == aPTran.InventoryID && currentAPTran.UOM == aPTran.UOM && Base.Transactions.Cache.GetStatus(aPTran) != PXEntryStatus.InsertedDeleted) { if (!usedSourceLine.Remove(aPTran)) { unusedSourceLine.Add(aPTran); } } } foreach (APTran aPTran in Base.Transactions.Cache.Updated) { if (currentAPTran.InventoryID == aPTran.InventoryID && currentAPTran.UOM == aPTran.UOM) { APTran originAPTran = new APTran { POAccrualType = (string)Base.Transactions.Cache.GetValueOriginal <APTran.pOAccrualType>(aPTran), POAccrualRefNoteID = (Guid?)Base.Transactions.Cache.GetValueOriginal <APTran.pOAccrualRefNoteID>(aPTran), POAccrualLineNbr = (int?)Base.Transactions.Cache.GetValueOriginal <APTran.pOAccrualLineNbr>(aPTran), POOrderType = (string)Base.Transactions.Cache.GetValueOriginal <APTran.pOOrderType>(aPTran), PONbr = (string)Base.Transactions.Cache.GetValueOriginal <APTran.pONbr>(aPTran), POLineNbr = (int?)Base.Transactions.Cache.GetValueOriginal <APTran.pOLineNbr>(aPTran), ReceiptNbr = (string)Base.Transactions.Cache.GetValueOriginal <APTran.receiptNbr>(aPTran), ReceiptType = (string)Base.Transactions.Cache.GetValueOriginal <APTran.receiptType>(aPTran), ReceiptLineNbr = (int?)Base.Transactions.Cache.GetValueOriginal <APTran.receiptLineNbr>(aPTran) }; if (!usedSourceLine.Remove(originAPTran)) { unusedSourceLine.Add(originAPTran); } if (!unusedSourceLine.Remove(aPTran)) { usedSourceLine.Add(aPTran); } } } unusedSourceLine.Add(currentAPTran); PXSelectBase <LinkLineReceipt> cmd = new PXSelect <LinkLineReceipt, Where2 < Where <Current <LinkLineFilter.pOOrderNbr>, Equal <LinkLineReceipt.orderNbr>, Or <Current <LinkLineFilter.pOOrderNbr>, IsNull> >, And2 <Where <Current <LinkLineFilter.siteID>, IsNull, Or <LinkLineReceipt.receiptSiteID, Equal <Current <LinkLineFilter.siteID> > > >, And <LinkLineReceipt.inventoryID, Equal <Current <APTran.inventoryID> >, And <LinkLineReceipt.uOM, Equal <Current <APTran.uOM> >, And <LinkLineReceipt.receiptType, Equal <POReceiptType.poreceipt> > > > > > >(Base); if (Base.APSetup.Current.RequireSingleProjectPerDocument == true) { cmd.WhereAnd <Where <LinkLineReceipt.projectID, Equal <Current <APInvoice.projectID> > > >(); } if (PXAccess.FeatureInstalled <FeaturesSet.vendorRelations>()) { cmd.WhereAnd <Where <LinkLineReceipt.vendorID, Equal <Current <APInvoice.suppliedByVendorID> >, And <LinkLineReceipt.vendorLocationID, Equal <Current <APInvoice.suppliedByVendorLocationID> >, And <Where <LinkLineReceipt.payToVendorID, IsNull, Or <LinkLineReceipt.payToVendorID, Equal <Current <APInvoice.vendorID> > > > > > > >(); } else { cmd.WhereAnd <Where <LinkLineReceipt.vendorID, Equal <Current <APInvoice.vendorID> >, And <LinkLineReceipt.vendorLocationID, Equal <Current <APInvoice.vendorLocationID> > > > >(); } foreach (LinkLineReceipt item in cmd.Select()) { APTran aPTran = new APTran { POAccrualType = item.POAccrualType, POAccrualRefNoteID = item.POAccrualRefNoteID, POAccrualLineNbr = item.POAccrualLineNbr, POOrderType = item.OrderType, PONbr = item.OrderNbr, POLineNbr = item.OrderLineNbr, ReceiptType = item.ReceiptType, ReceiptNbr = item.ReceiptNbr, ReceiptLineNbr = item.ReceiptLineNbr }; if (!usedSourceLine.Contains(aPTran)) { var res = (PXResult <POReceiptLineS, POReceipt>)ReceipLineLinked.Select(item.ReceiptNbr, item.ReceiptLineNbr); if (linkLineReceiptTran.Cache.GetStatus((POReceiptLineS)res) != PXEntryStatus.Updated && ((POReceiptLineS)res).CompareReferenceKey(currentAPTran)) { linkLineReceiptTran.Cache.SetValue <POReceiptLineS.selected>((POReceiptLineS)res, true); linkLineReceiptTran.Cache.SetStatus((POReceiptLineS)res, PXEntryStatus.Updated); } yield return(res); } } foreach (APTran item in unusedSourceLine.Where(t => t.POAccrualType != null)) { foreach (PXResult <POReceiptLineS, POReceipt> res in PXSelectJoin <POReceiptLineS, LeftJoin <POReceipt, On <POReceiptLineS.receiptNbr, Equal <POReceipt.receiptNbr>, And <POReceiptLineS.receiptType, Equal <POReceipt.receiptType> > > >, Where <POReceiptLineS.pOAccrualType, Equal <Required <LinkLineReceipt.pOAccrualType> >, And <POReceiptLineS.pOAccrualRefNoteID, Equal <Required <LinkLineReceipt.pOAccrualRefNoteID> >, And <POReceiptLineS.pOAccrualLineNbr, Equal <Required <LinkLineReceipt.pOAccrualLineNbr> > > > > > .Select(Base, item.POAccrualType, item.POAccrualRefNoteID, item.POAccrualLineNbr)) { if (currentAPTran.InventoryID == ((POReceiptLineS)res).InventoryID) { if (linkLineReceiptTran.Cache.GetStatus((POReceiptLineS)res) != PXEntryStatus.Updated && ((POReceiptLineS)res).CompareReferenceKey(currentAPTran)) { linkLineReceiptTran.Cache.SetValue <POReceiptLineS.selected>((POReceiptLineS)res, true); linkLineReceiptTran.Cache.SetStatus((POReceiptLineS)res, PXEntryStatus.Updated); } yield return(res); } } } }