Step 2: Defining the DAC for the Grid View of the Form

The Open Payment Summary (RS401000) form, which you have created in the previous step, displays information about repair work orders (including the details of the invoice created for each order). All fields on this form are unbound, and you do not need to work with the fields on the Repair Work Orders (RS301000) form, which works with the RSSVWorkOrder DAC.

In this step, for the grid view of the Open Payment Summary form, you will derive the new RSSVWorkOrderToPay class from RSSVWorkOrder and extend the new class with additional DAC fields that are specific to the inquiry form. In the derived DAC, you will add the OrderNbr, InvoiceNbr, and Status abstract classes (which are defined in the base RSSVWorkOrder DAC) with the new modifier. You need to define new abstract classes because you will use the data fields of the derived class in BQL statements (such as the BQL statements in the data view of a processing form and in attributes).

Note: If you do not define the abstract classes for the original fields in the derived DAC, these fields will be referred to in the SQL statement that corresponds to the BQL query as the fields of the original DAC. (In this example, the OrderNbr, InvoiceNbr, and Status fields will be referred to as the fields of the RSSVWorkOrder DAC). Data inconsistency issues may result when the original and the derived DACs are used in the same BQL statement.

In the derived DAC, you will also add the PercentPaid field. During the retrieval of each of the RSSVWorkOrder records, the value of the PercentPaid field is calculated from the database as the percentage of invoice amount that has been paid.

To define the RSSVWorkOrderToPay DAC, do the following:

  1. In the Helper/Messages.cs file, add the RSSVWorkOrderToPay string to the Messages class as shown in the following code. This message will me used in the PXCacheName attribute for the new DAC.
            public const string RSSVWorkOrderToPay = "Repair Work Order to Pay";
  2. In the RSSVWorkOrder.cs file, declare the RSSVWorkOrderToPay DAC: Derive the RSSVWorkOrderToPay class from RSSVWorkOrder, as shown in the following code.
        [PXCacheName(Messages.RSSVWorkOrderToPay)]
        public class RSSVWorkOrderToPay : RSSVWorkOrder
        {
        }
  3. In the RSSVWorkOrderToPay class, define the OrderNbr, InvoiceNbr, and Status abstract classes with the new modifier, as shown in the following code.
            #region InvoiceNbr
            public new abstract class invoiceNbr :
                PX.Data.BQL.BqlString.Field<invoiceNbr>
            { }
            #endregion
    
            #region Status
            public new abstract class status :
                PX.Data.BQL.BqlString.Field<status>
            { }
            #endregion
    
            #region OrderNbr
            public new abstract class orderNbr :
                PX.Data.BQL.BqlString.Field<orderNbr>
            { }
            #endregion
  4. In the RSSVWorkOrderToPay class, define the PercentPaid field, as shown in the following code.
            #region PercentPaid
            [PXDecimal]
            [PXUIField(DisplayName = "Percent Paid")]
            public virtual Decimal? PercentPaid { get; set; }
            public abstract class percentPaid :
                PX.Data.BQL.BqlDecimal.Field<percentPaid>
            { }
            #endregion
  5. In the RSSVPaymentPlanInq.cs file, in the RSSVPaymentPlanInq graph, add the calculation of the PercentPaid field value in the FieldSelecting event, as shown in the following code.
            protected virtual void _(Events.FieldSelecting<RSSVWorkOrderToPay,
                RSSVWorkOrderToPay.percentPaid> e)
            {
                if (e.Row == null) return;
                if (e.Row.OrderTotal == 0) return;
                RSSVWorkOrderToPay order = e.Row;
                var invoices = SelectFrom<ARInvoice>.
                    Where<ARInvoice.refNbr.IsEqual<@P.AsString>>.View.Select(
                    this, order.InvoiceNbr);
                if (invoices.Count == 0)
                    return;
                ARInvoice first = invoices[0];
                e.ReturnValue = (order.OrderTotal - first.CuryDocBal) /
                    order.OrderTotal * 100;
            }

    In the event handler, you are selecting the invoice with the same number as the one specified in the repair work order; you are then calculating the percentage.

    You need to use an event handler instead of attributes because you cannot check for 0 values by using attributes.

    Note: If you have generated the RSSVPaymentPlanInq graph from the Code Editor, you can remove the Save and Cancel actions defined in the graph.
  6. In the RSSVPaymentPlanInq.cs file, add the required using directives, which are shown in the following code.
    using PX.Data.BQL.Fluent;
    using PX.Data.BQL;
    using PX.Objects.AR;
  7. Build the project.