Friday, 11 January 2019

Add range to Custtrans table of CustOpenBalanceCurrency

class EQNCustOpenBalanceFormEventHandler
{
    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [FormDataSourceEventHandler(formDataSourceStr(CustOpenBalanceCurrency, CustTrans), FormDataSourceEventType::Initialized)]
    public static void CustTrans_OnInitialized(FormDataSource sender, FormDataSourceEventArgs e)
    {
        if( CustParameters::find().FINCustCreditCheckType == FINCustCreditCheckType::BasedonExposure)
        {
            Query q = new Query(querystr(EQNCustOpenBalance));

            FormDatasource CustTrans_DS    = sender.formRun().datasource('CustTrans');
       
            CustTrans_DS.query(q);
        }
    }

    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [FormDataSourceEventHandler(formDataSourceStr(CustOpenBalanceCurrency, CustTrans), FormDataSourceEventType::QueryExecuting)]
    public static void CustTrans_OnQueryExecuting(FormDataSource sender, FormDataSourceEventArgs e)
    {
        if( CustParameters::find().FINCustCreditCheckType == FINCustCreditCheckType::BasedonExposure)
        {
            FormDatasource      CustTrans_DS;
     
            CustTrans_DS    = sender.formRun().datasource('CustTrans');
       
       
            AccountNum  custAccount;
            FormRun element =sender.formRun();
            CustTable custTbl;
            SalesTable salesTable;
            CustInvoiceTable custInvoiceTable;
            CustTrans   custTransTmp;
            CustTransOpen   custTransOpen;
            container       conrecid;
            switch (element.args().dataset())
            {
                case tablenum(CustTable) :
                    custTbl = element.args().record();
                    break;
                case tablenum(SalesTable) :
                    salesTable = element.args().record();
                    custTbl = CustTable::find(salesTable.InvoiceAccount);
                    break;
                case tablenum(CustInvoiceTable) :
                    custInvoiceTable = element.args().record();
                    custTbl = CustTable::find(custInvoiceTable.InvoiceAccount);
                    break;
            }
            while select  * from  custTransTmp
                where   custTransTmp.AccountNum == custTbl.AccountNum
                    join  custTransOpen
                         where custTransOpen.RefRecId == custTransTmp.RecId
            {
                if(!PaymTerm::find(CustInvoiceJour::findFromCustTrans(custTransTmp.Invoice,custTransTmp.TransDate,custTransTmp.AccountNum).salesTable().payment).EQNExcludefromexposurecalculations)
                {
                    conrecid += custTransTmp.RecId;
                }
            }
            CustTrans_DS.query().dataSourceTable(tablenum(CustTrans)).addRange(fieldnum(CustTrans, RecId)).value(con2Str(conrecid));
        }
     
    }

}

No comments:

Post a Comment