0
votes

I have the same issue as the below link but with a different graph (APPrintChecks)

how-do-i-override-pxfilteredprocessingjoin-in-a-graph-extension-without-altering

I am overriding the main view to pull in the remittance name from APContact to show in the grid.

[PXFilterable]
public PXFilteredProcessingJoin<APPayment, PrintChecksFilter,
  InnerJoin<Vendor, On<Vendor.bAccountID, Equal<APPayment.vendorID>>,
  InnerJoin<APContact, On<APContact.contactID, Equal<APPayment.remitContactID>>>>,
  Where<boolTrue, Equal<boolTrue>>,
  OrderBy<Asc<Vendor.acctName, Asc<APPayment.refNbr>>>> APPaymentList;

However, I do not know how to override the delegate so I won't have the same problem as the other poster (no filter being applied).

protected virtual IEnumerable appaymentlist()
    {
        if (cleared)
        {
            foreach (APPayment doc in APPaymentList.Cache.Updated)
            {
                doc.Passed = false;
            }
        }

        foreach (PXResult<APPayment, Vendor, PaymentMethod, CABatchDetail> doc in PXSelectJoin<APPayment,
            InnerJoinSingleTable<Vendor, On<Vendor.bAccountID, Equal<APPayment.vendorID>>,
            InnerJoin<PaymentMethod, On<PaymentMethod.paymentMethodID, Equal<APPayment.paymentMethodID>>,
            LeftJoin<CABatchDetail, On<CABatchDetail.origModule, Equal<BatchModule.moduleAP>,
                    And<CABatchDetail.origDocType, Equal<APPayment.docType>,
                    And<CABatchDetail.origRefNbr, Equal<APPayment.refNbr>>>>>>>,
            Where2<Where<APPayment.status, Equal<APDocStatus.pendingPrint>,
                And<CABatchDetail.batchNbr, IsNull,
                And<APPayment.cashAccountID, Equal<Current<PrintChecksFilter.payAccountID>>,
                And<APPayment.paymentMethodID, Equal<Current<PrintChecksFilter.payTypeID>>,
                And<Match<Vendor, Current<AccessInfo.userName>>>>>>>,
                And<APPayment.docType, In3<APDocType.check, APDocType.prepayment, APDocType.quickCheck>>>>.Select(this))
        {
            yield return new PXResult<APPayment, Vendor>(doc, doc);
            if (_copies.ContainsKey((APPayment)doc))
            {
                _copies.Remove((APPayment)doc);
            }
            _copies.Add((APPayment)doc, PXCache<APPayment>.CreateCopy(doc));
        }
    }

There are other private variables that are referenced in this. Any help appreciated.

Also, if there's a simpler way to pull in a related value on a grid like this (virtual field in DAC?) I'm not stuck on doing it with a graph extension.

3

3 Answers

0
votes

So this appears to work but it seems messy and duplicates a lot of code and private variables. Appreciate any feedback if there's a better way to do this:

 public class APPrintChecks_Extension : PXGraphExtension<APPrintChecks> {

[PXFilterable]
public PXFilteredProcessingJoin<APPayment, PrintChecksFilter,
  InnerJoin<Vendor, On<Vendor.bAccountID, Equal<APPayment.vendorID>>,
  InnerJoin<APContact, On<APContact.contactID, Equal<APPayment.remitContactID>>>>,
  Where<boolTrue, Equal<boolTrue>>,
  OrderBy<Asc<Vendor.acctName, Asc<APPayment.refNbr>>>> APPaymentList;


    public IEnumerable appaymentlist()
    {
      
      if (cleared)
      {
        foreach (APPayment doc in APPaymentList.Cache.Updated)
        {
          doc.Passed = false;
        }
      }

      foreach (PXResult<APPayment, Vendor, APContact, PaymentMethod, CABatchDetail> doc in PXSelectJoin<APPayment,
        InnerJoinSingleTable<Vendor, On<Vendor.bAccountID, Equal<APPayment.vendorID>>,
        InnerJoin<APContact, On<APContact.contactID, Equal<APPayment.remitContactID>>,
        InnerJoin<PaymentMethod, On<PaymentMethod.paymentMethodID, Equal<APPayment.paymentMethodID>>,
         LeftJoin<CABatchDetail, On<CABatchDetail.origModule, Equal<BatchModule.moduleAP>,
            And<CABatchDetail.origDocType, Equal<APPayment.docType>,
            And<CABatchDetail.origRefNbr, Equal<APPayment.refNbr>>>>>>>>,
        Where2<Where<APPayment.status, Equal<APDocStatus.pendingPrint>,
          And<CABatchDetail.batchNbr, IsNull,
          And<APPayment.cashAccountID, Equal<Current<PrintChecksFilter.payAccountID>>,
          And<APPayment.paymentMethodID, Equal<Current<PrintChecksFilter.payTypeID>>,
          And<Match<Vendor, Current<AccessInfo.userName>>>>>>>,
          And<APPayment.docType, In3<APDocType.check, APDocType.prepayment, APDocType.quickCheck>>>>.Select(Base))
      {
        yield return new PXResult<APPayment, Vendor, APContact>(doc, doc, doc);
        if (_copies.ContainsKey((APPayment)doc))
        {
          _copies.Remove((APPayment)doc);
        }
        _copies.Add((APPayment)doc, PXCache<APPayment>.CreateCopy(doc));
      }
    }
    
    private bool cleared;
    public void Clear()
    {
      Base.Filter.Current.CurySelTotal = 0m;
      Base.Filter.Current.SelTotal = 0m;
      Base.Filter.Current.SelCount = 0;
      cleared = true;
      Base.Clear();
    }

    private readonly Dictionary<object, object> _copies = new Dictionary<object, object>();

}

0
votes

Per Rick's suggestion I implemented the FieldSelecting method. Much, much simpler/cleaner code. It does in fact cause a round trip to the database for each row when using this in a grid column, however, for check printing this should be acceptable. Thanks Rick! Code below.

protected void APPayment_UsrRemitTo_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
    {

        var row = (APPayment)e.Row;
        // fill usrRemitTo from APContact
        if (row != null)
        {
            var extension = PXCache<APRegister>.GetExtension<APRegisterExt>(row);

            using (PXConnectionScope cs = new PXConnectionScope())
            {
                APContact rec = PXSelectReadonly<APContact, Where<APContact.contactID, Equal<Required<APPayment.remitContactID>>>>.Select(Base, row.RemitContactID);

                if (rec != null)
                {
                    string remitToName = (!string.IsNullOrEmpty(rec.FullName)) ? rec.FullName : "";
                   
                    e.ReturnValue = remitToName;
                }
                else
                {
                    e.ReturnValue = "";
                }
            }
        }



    }
0
votes

Using DBScalar, you can further simplify your event with just one line :

public class APPaymentExt : PXCacheExtension<APPayment>
{
  #region UsrRemitTo
  [PXString(100)]
  [PXUIField(DisplayName="Remit To")]    
  [PXDBScalar(typeof(Search<APContact.fullName,Where<APContact.contactID, Equal<APPayment.remitContactID>>>))]
  public virtual string UsrRemitTo { get; set; }
  public abstract class usrRemitTo : PX.Data.BQL.BqlString.Field<usrRemitTo> { }
  #endregion
}