public virtual void POOrderRS_CuryID_FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e) { POOrderRS row = (POOrderRS)e.Row; APInvoice doc = Base.Document.Current; if (row != null && doc != null) { if (row.CuryID != doc.CuryID) { string fieldName = typeof(POOrderRS.curyID).Name; PXErrorLevel msgLevel = PXErrorLevel.RowWarning; e.ReturnState = PXFieldState.CreateInstance(e.ReturnState, typeof(String), false, null, null, null, null, null, fieldName, null, null, AP.Messages.APDocumentCurrencyDiffersFromSourceDocument, msgLevel, null, null, null, PXUIVisibility.Undefined, null, null, null); e.IsAltered = true; } } }
private static void AddPOOrderToBill(PXGraph graph, APInvoiceEntry invoiceEntry, EntityValueField orderType, EntityValueField orderNbr) { var state = invoiceEntry.Transactions.Cache.GetStateExt <APTran.pOOrderType>(new APTran { }) as PXStringState; if (state != null && state.AllowedLabels.Contains(orderType.Value)) { orderType.Value = state.ValueLabelDic.Single(p => p.Value == orderType.Value).Key; } if (orderType.Value == POOrderType.RegularSubcontract) { var constructionExt = graph.GetExtension <CN.Subcontracts.AP.GraphExtensions.ApInvoiceEntryAddSubcontractsExtension>(); POOrderRS line = (POOrderRS)(constructionExt.Subcontracts.Select().Where(x => (((POOrderRS)x).OrderType == orderType.Value && ((POOrderRS)x).OrderNbr == orderNbr.Value)).FirstOrDefault()); if (line == null) { throw new PXException($"Subcontract {orderNbr.Value} was not found."); } line.Selected = true; constructionExt.Subcontracts.Update(line); constructionExt.AddSubcontract.Press(); } else { var orderExtension = graph.GetExtension <PO.GraphExtensions.APInvoiceSmartPanel.AddPOOrderExtension>(); POOrderRS line = (POOrderRS)(orderExtension.poorderslist.Select().Where(x => (((POOrderRS)x).OrderType == orderType.Value && ((POOrderRS)x).OrderNbr == orderNbr.Value)).FirstOrDefault()); if (line == null) { throw new PXException($"Purchase Order {orderType.Value} {orderNbr.Value} was not found."); } line.Selected = true; orderExtension.poorderslist.Update(line); orderExtension.addPOOrder2.Press(); } }
public virtual IEnumerable pOOrderslist() { APInvoice doc = Base.Document.Current; bool isInvoice = (doc.DocType == APDocType.Invoice), isPrepayment = (doc.DocType == APDocType.Prepayment); if (doc?.VendorID == null || doc.VendorLocationID == null || !isInvoice && !isPrepayment) { yield break; } var usedOrderLines = new Dictionary <APTran, int>(new POOrderComparer()); foreach (APTran aPTran in Base.Transactions.Select().RowCast <APTran>().AsEnumerable() .Where(t => !string.IsNullOrEmpty(t.PONbr) && (isPrepayment || t.POAccrualType == POAccrualType.Order))) { usedOrderLines.TryGetValue(aPTran, out int count); usedOrderLines[aPTran] = count + 1; } PXSelectBase <POOrderRS> cmd = new PXSelectJoinGroupBy < POOrderRS, InnerJoin <POLine, On <POLine.orderType, Equal <POOrderRS.orderType>, And <POLine.orderNbr, Equal <POOrderRS.orderNbr> > > >, Where <POOrderRS.orderType, NotIn3 <POOrderType.blanket, POOrderType.standardBlanket>, And <POOrderRS.curyID, Equal <Current <APInvoice.curyID> >, And <POLine.cancelled, NotEqual <True>, And <POLine.closed, NotEqual <True>, And <POOrderRS.status, In3 <POOrderStatus.open, POOrderStatus.completed> > > > > >, Aggregate <GroupBy <POOrderRS.orderType, GroupBy <POOrderRS.orderNbr, GroupBy <POOrderRS.orderDate, GroupBy <POOrderRS.curyID, GroupBy <POOrderRS.curyOrderTotal, GroupBy <POOrderRS.hold, GroupBy <POOrderRS.cancelled, Sum <POLine.orderQty, Sum <POLine.curyExtCost, Sum <POLine.extCost, Count <POLine.lineNbr> > > > > > > > > > > > >(Base); if (isInvoice) { cmd.WhereAnd <Where <POLine.pOAccrualType, Equal <POAccrualType.order> > >(); } else if (isPrepayment) { cmd.WhereAnd <Where <POOrderRS.taxZoneID, Equal <Current <APInvoice.taxZoneID> >, Or <POOrderRS.taxZoneID, IsNull, And <Current <APInvoice.taxZoneID>, IsNull> > > >(); } if (Base.APSetup.Current.RequireSingleProjectPerDocument == true) { cmd.WhereAnd <Where <POOrderRS.projectID, Equal <Current <APInvoice.projectID> > > >(); } if (PXAccess.FeatureInstalled <FeaturesSet.vendorRelations>()) { cmd.WhereAnd <Where <POOrderRS.vendorID, Equal <Current <APInvoice.suppliedByVendorID> >, And <POOrderRS.vendorLocationID, Equal <Current <APInvoice.suppliedByVendorLocationID> >, And <POOrderRS.payToVendorID, Equal <Current <APInvoice.vendorID> > > > > >(); } else { cmd.WhereAnd <Where <POOrderRS.vendorID, Equal <Current <APInvoice.vendorID> >, And <POOrderRS.vendorLocationID, Equal <Current <APInvoice.vendorLocationID> > > > >(); } foreach (PXResult <POOrderRS, POLine> result in cmd.View.SelectMultiBound(new object[] { doc })) { POOrderRS order = result; APTran aPTran = new APTran { PONbr = order.OrderNbr, POOrderType = order.OrderType }; usedOrderLines.TryGetValue(aPTran, out int count); if (count < result.RowCount) { yield return(order); } } }