Saturday, October 9, 2021

AX 2012: SSRS Report

Parameter form




Contract Class
public class CustAgingReportUIBuilder extends SrsReportDataContractUIBuilder
{
    DialogField billingClassificationField;
}

public void billingClassificationLookup()
{
    Query       query               = new Query(queryStr(CustBillingClassificationLookup));

    TableId     multiSelectTableNum = tableNum(CustBillingClassification);

    container   selectedFields      = [multiSelectTableNum, fieldName2id(multiSelectTableNum, fieldStr(CustBillingClassification, BillingClassification))];

    SysLookupMultiSelectCtrl::constructWithQuery(this.dialog().dialogForm().formRun(), billingClassificationField.control(), query, false, selectedFields);
}
public void build()
{
    boolean                 isBillingClassEnabled;
    DialogField             inclTransWithNoBillingClassField;
    CustAgingReportContract custAgingReportContract;

    super();

    custAgingReportContract = this.dataContractObject() as CustAgingReportContract;

    billingClassificationField          = this.bindInfo().getDialogField(custAgingReportContract, methodStr(custAgingReportContract, parmBillingClassification));
    inclTransWithNoBillingClassField    = this.bindInfo().getDialogField(custAgingReportContract, methodStr(custAgingReportContract, parmInclTransWithNoBillingClass));

    // controlling visibility
    if (billingClassificationField && inclTransWithNoBillingClassField)
    {
        isBillingClassEnabled = CustParameters::isBillingClassificationEnabled();
        billingClassificationField.visible(isBillingClassEnabled);
        inclTransWithNoBillingClassField.visible(isBillingClassEnabled);
        billingClassificationField.lookupButton(FormLookupButton::Always);
    }
}

public void lookupEntity(FormStringControl _formStringControl)
{
    Query       query = new Query();
    container   cnt;

 
    str         da = 'AWRL,AWRF,AWRT';
    Args        args;
    query.addDataSource(tableNum(DataArea));
    args = this.controller().parmArgs();

    query.dataSourceTable(tableNum(DataArea)).addSelectionField(fieldNum(DataArea,Id));
    if(args.menuItemName() == menuitemOutputStr(AweCustAging))
    {
        query.dataSourceTable(tableNum(DataArea)).addRange(fieldNum(DataArea,Id) ).value(da);
    }
    

    query.dataSourceTable(tableNum(DataArea)).addSelectionField(fieldNum(DataArea,Name));
    SysLookupMultiSelectGrid::lookup(query,_formStringControl,_formStringControl,cnt);

}

public void postBuild()

{

    DialogField dialogEntity;

    Args args = this.controller().parmArgs();

    super();

    dialogEntity= this.bindInfo().getDialogField(this.dataContractObject(), methodStr(custAgingReportContract, parmDataArea));  

    if (args && args.menuItemName() == menuitemoutputstr(AweCustAgingReportForMultiCompanies)||menuitemoutputstr(AweCustAging))// || menuitemOutputStr(AweCustAgingWithFinancialDimensions)) 

    {

        dialogEntity.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(CustAgingReportUIBuilder,lookupEntity),this);

        if (dialogEntity)

        {

            dialogEntity.lookupButton(2);//(2);

        }

    }

    else

    {

        dialogEntity.visible(false);

        dialogEntity.value("");

    }

}

public void postRun()

{

    if (CustParameters::isBillingClassificationEnabled())

    {

        this.billingClassificationLookup();

    }  

   /* else

    {

        super();

    }*/  

}

Controller class:

public class CustAgingReportController extends SrsReportRunController

{

}

private str getReportName(CustAgingReportContract _contract)

{

    str reportNameLocal;

    if (_contract.parmDetailed())

    {

        if (_contract.parmIncludeAmountCur())

        {

            reportNameLocal = ssrsReportStr(CustAgingReport,                   DesignWithDetailAndWithTransactionCur);

        }

        else

        {

            reportNameLocal = ssrsReportStr(CustAgingReport, DesignWithDetailAndNoTransactionCur);

        }        

        if(_contract.parmMenuItemName() == menuitemoutputstr(AweCustAging))

        {

            if (_contract.parmIncludeAmountCur())

            {

                reportNameLocal = ssrsReportStr(CustAgingReport, AweDesignWithDetailAndWithTransaction);

            }

            else

            {

                reportNameLocal = ssrsReportStr(CustAgingReport, AweDesignWithDetailAndNoTransaction);

            }

        }       

       if (_contract.parmMenuItemName() == menuitemoutputstr(AweCustAgingWithFinancialDimensions))

        {

            if (_contract.parmIncludeAmountCur())

            {

                reportNameLocal = ssrsReportStr(CustAgingReport, AweDimensionWithDetailAndWithTransaction);

            }

            else

            {

                 reportNameLocal = ssrsReportStr(CustAgingReport, AweDimensionWithDetailAndNoTransaction);

            }

        }        

    }

    else

    {

        if (_contract.parmIncludeAmountCur())

        {

            reportNameLocal = ssrsReportStr(CustAgingReport, DesignWithNoDetailAndWithTransactionCur);

        }

        else

        {

            reportNameLocal = ssrsReportStr(CustAgingReport, DesignWithNoDetailAndNoTransactionCur);

        }

    }        

    return reportNameLocal;

}

protected void prePromptModifyContract()

{

    CustAgingReportContract contract = this.parmReportContract().parmRdpContract() as CustAgingReportContract;

    this.setRanges(this.parmReportContract().parmQueryContracts().lookup(this.getFirstQueryContractKey()), contract);

}

protected void preRunModifyContract()

{

    CustAgingReportContract contract = this.parmReportContract().parmRdpContract() as CustAgingReportContract;

    this.parmReportContract().parmReportName(this.getReportName(contract));

    super();

}

protected container preRunValidate()

{

    // Now that this report is a preprocess tempdb report, we no longer need

    // the limits that were required in the SYS version of the report.

    return super();

}

public void setRanges(Query _query, CustAgingReportContract _contract)

{

    CustAgingReportTmp custAgingReportTmp;

    // Checking the current table number

    if (this.parmArgs() && this.parmArgs().record() && this.parmArgs().record().TableId == tableNum(CustAgingReportTmp))

    {

        custAgingReportTmp = this.parmArgs().record();

        // Modifying the query

        _query.dataSourceTable(tableNum(CustTable)).rangeField(fieldNum(CustTable, AccountNum)).value(custAgingReportTmp.AccountNum);

        // Setting the ranges

        _contract.parmDateTransactionDuedate(any2int(custAgingReportTmp.Balance01));

        _contract.parmAgingBuckets(custAgingReportTmp.Txt);

    }

}

public static void main(Args _args)

{

    CustAgingReportContract contract;

    CustAgingReportController controller = new CustAgingReportController();

    //CustAgingReportController controllerLoc = new CustAgingReportController();

    controller.parmReportName(ssrsReportStr(CustAgingReport, DesignWithNoDetailAndNoTransactionCur));

    //controllerLoc.parmReportName(ssrsReportStr(CustAgingReport, AweCustAgingWithFinancialDimensions));

    contract = controller.parmReportContract().parmRdpContract() as CustAgingReportContract;

    contract.parmMenuItemName(_args.menuItemName());

    if (contract.parmMenuItemName()==menuitemoutputstr(AweCustAging))

    {

        contract.parmDetailed(true);

    }

    if (contract.parmMenuItemName()==menuitemoutputstr(AweCustAgingWithFinancialDimensions))

    {

        contract.parmDetailed(true);

    }   

    controller.parmArgs(_args);

    controller.startOperation();

}

[

    SRSReportQueryAttribute(queryStr(CustAgingReport)),

    SRSReportParameterAttribute(classStr(CustAgingReportContract))

]

DP Class:

private CustAgingReportTmp insertCustAgingReportTmp(boolean _reverseAmountsAndHeadings)

{

    Str1260 asOfDate = strFmt("@SYS84682", date2StrUsr(contract.parmZeroDate(), DateFlags::FormatAll), contract.parmDateTransactionDuedate());

    Addressing headingAccount = strFmt("@SYS24500");

    TransTxt headingName = strFmt("@SYS7399");

    AmountMST balance = 100;

    CustVendTransAging custVendTransAging = custVendBalanceList.getCustVendTransAging();   

    #define.Location("Location")

    #Define.Department("Department")

    #Define.Product("Product")

    #Define.Project("Project")

    #define.LOB("LineofBusiness")

    SubledgerVoucherGeneralJournalEntry subledgervouchergenraljournalentry;

    GeneralJournalEntry                 generalJournalEntry;

    DimensionAttribute                  dimAttribute;

    GeneralJournalAccountEntry          generalJournalAccountEntry,generalJournalAccountEntryDimension;

    DimensionAttributeLevelValueAllView dimView;

    DefaultDimensionView                defaultDimensionView;

    MainAccountLedgerDimensionView      mainAccountView;

    Name                                awaDeprtment, awaLOB ,awaLOC, awaProdcut, aweproj;

    int64                               ledgerDimension;

    CustTrans                           custTrans;

    CustTable                           custTable;

    int                                 ledgerAcc;

    if (_reverseAmountsAndHeadings)

    {

        insert_recordset custAgingReportTmp

           (Balance01, Balance02, Balance03, Balance04, Balance05, Balance06, Balance07,

            Balance01cur, Balance02cur, Balance03cur, Balance04cur, Balance05cur, Balance06cur, Balance07cur,

            TransDate, InvoiceId, Voucher, AccountNum, Name, CustAccount, Txt, Currency, CustGroup, BillingClassification,

            AsOfDate, HeadingAccount, HeadingName, HeadingDate, Heading1, Heading2DateValue, Heading2,

            Heading3, Heading4, Heading5, Heading6, Heading7DateValue, Heading7, Heading8, Heading9,

            Heading10, Heading11, Heading12, Heading13, Heading14, HeadingAgingBucketDescription02,

            HeadingAgingBucketDescription03, HeadingAgingBucketDescription04, HeadingAgingBucketDescription05,

            //HeadingAgingBucketDescription06, HeadingAgingBucketDescription07, Balance,

            HeadingAgingBucketDescription06, HeadingAgingBucketDescription07, Balance,

            AweSalesAgreementId,        

            AweSalesPoolId,

            AweClaimId,SortOrder)    

        select

            Balance01, Balance07, Balance06, Balance05, Balance04, Balance03, Balance02,

            Balance01cur, Balance07cur, Balance06cur, Balance05cur, Balance04cur, Balance03cur, Balance02cur,

            TransDate, InvoiceId, Voucher, AccountNum, Name, AccountNum, Txt, CurrencyCode, GroupId, BillingClassification,

            asOfDate, headingAccount, headingName, headingDate, heading01, heading02, heading07Text,

            heading03, heading04, heading05, heading06, heading07, heading02Text, heading011, heading03,

            heading031, heading041, heading051, heading061, heading061, headingAgingBucketDescription02,

            headingAgingBucketDescription03, headingAgingBucketDescription04, headingAgingBucketDescription05,

            headingAgingBucketDescription06, headingAgingBucketDescription07, balance,    

            AweSalesAgreementId,        

            AweSalesPoolId,      

            AweClaimId         

        from tmpAccountSum

            join SortOrder

                from custVendTransAging

                    where tmpAccountSum.AccountNum == custVendTransAging.AccountNum;

    }

    else

    {

        insert_recordset custAgingReportTmp

           (Balance01, Balance02, Balance03, Balance04, Balance05, Balance06, Balance07,

            Balance01cur, Balance02cur, Balance03cur, Balance04cur, Balance05cur, Balance06cur, Balance07cur,

            TransDate, InvoiceId, Voucher, AccountNum, Name, CustAccount, Txt, Currency, CustGroup, BillingClassification,

            AsOfDate, HeadingAccount, HeadingName, HeadingDate, Heading1, Heading2DateValue, Heading2,

            Heading3, Heading4, Heading5, Heading6, Heading7DateValue, Heading7, Heading8, Heading9,

            Heading10, Heading11, Heading12, Heading13, Heading14, HeadingAgingBucketDescription02,

            HeadingAgingBucketDescription03, HeadingAgingBucketDescription04, HeadingAgingBucketDescription05,          

            HeadingAgingBucketDescription06, HeadingAgingBucketDescription07, Balance,          

            AweSalesAgreementId,          

            AweSalesPoolId,           

            AweClaimId,SortOrder)      

        select

            Balance01, Balance02, Balance03, Balance04, Balance05, Balance06, Balance07,

            Balance01cur, Balance02cur, Balance03cur, Balance04cur, Balance05cur, Balance06cur, Balance07cur,

            TransDate, InvoiceId, Voucher, AccountNum, Name, AccountNum, Txt, CurrencyCode, GroupId, BillingClassification,

            asOfDate, headingAccount, headingName, headingDate, heading01, heading02, heading02Text,

            heading03, heading04, heading05, heading06, heading07, heading07Text, heading011, heading021,

            heading031, heading041, heading051, heading061, heading071, headingAgingBucketDescription02,

            headingAgingBucketDescription03, headingAgingBucketDescription04, headingAgingBucketDescription05,

            headingAgingBucketDescription06, headingAgingBucketDescription07, balance,          

            AweSalesAgreementId,           

            AweSalesPoolId,           

            AweClaimId    

        from tmpAccountSum

            join SortOrder

                from custVendTransAging

                    where tmpAccountSum.AccountNum == custVendTransAging.AccountNum;    

    if(contract.parmmenuitemname() == menuitemoutputstr(awecustaging))

    {

        while select forupdate custAgingReportTmp

        {

            custAgingReportTmp.awelocation   = this.getDimensionValueLocation(CustTable::find(custAgingReportTmp.AccountNum).DefaultDimension);

            custAgingReportTmp.update();

        }

    }

      if (contract.parmMenuItemName()==menuitemoutputstr(AweCustAgingWithFinancialDimensions))

       {

           while select accountnum from tmpAccountSum

            {

                while select AccountNum from custTable

                    where custTable.AccountNum == tmpAccountSum.AccountNum

                {

                    while select forUpdate custAgingReportTmp

                       where custAgingReportTmp.AccountNum == tmpAccountSum.AccountNum

                    {

                        ttsBegin;

                        custAgingReportTmp.AWEDataArea = curext();

                        custAgingReportTmp.update();

                        select firstOnly subledgervouchergenraljournalentry

                        where subledgervouchergenraljournalentry.Voucher == custAgingReportTmp.Voucher //custTrans.Voucher &&     join RecId from generalJournalEntry

                        where generalJournalEntry.RecId == subledgervouchergenraljournalentry.GeneralJournalEntry

                            join GeneralJournalEntry, LedgerDimension , LedgerAccount from generalJournalAccountEntry

                        where generalJournalAccountEntry.GeneralJournalEntry == generalJournalEntry.RecId

                            join mainAccountView

                        where mainAccountView.LedgerDimensionId == generalJournalAccountEntry.LedgerDimension &&

                              mainAccountView.Type == DimensionLedgerAccountType::ProfitAndLoss

                            join custTrans

                        where custTrans.AccountNum == custAgingReportTmp.AccountNum;

                        ledgerAcc = strLen(generalJournalAccountEntry.LedgerAccount);

                        if (generalJournalAccountEntry.LedgerDimension)

                        {

                            ledgerDimension = generalJournalAccountEntry.LedgerDimension;

                           while select dimView where dimView.ValueCombinationRecId == ledgerDimension

                           join dimAttribute

                               where dimAttribute.RecId == dimView.DimensionAttribute

                           {

                               if (dimAttribute.Name == 'LineofBusiness')

                               {

                                   custAgingReportTmp.AWELOB = dimView.DisplayValue;

                                   custAgingReportTmp.update();

                               }

                               if (dimAttribute.Name == 'Location' )

                                {

                                    custAgingReportTmp.AWELOC = dimView.DisplayValue;

                                    custAgingReportTmp.update();

                                }

                                if (dimAttribute.Name == 'Department')

                                {

                                    custAgingReportTmp.AweDepartment = dimView.DisplayValue;

                                    custAgingReportTmp.update();

                                }

                                if (dimAttribute.Name == 'Product' )

                                 {

                                     custAgingReportTmp.AWEProduct = dimView.DisplayValue;

                                     custAgingReportTmp.update();

                                 }

                                 if (dimAttribute.Name == 'Project')

                                 {

                                     custAgingReportTmp.AWEProject =  dimView.DisplayValue;

                                     custAgingReportTmp.update();

                                 }

                              }

                         }

                        else 

                             {

                                 select subledgervouchergenraljournalentry

                                    where subledgervouchergenraljournalentry.Voucher == custAgingReportTmp.Voucher //custTrans.Voucher &&

                                        join RecId from generalJournalEntry

                                    where generalJournalEntry.RecId == subledgervouchergenraljournalentry.GeneralJournalEntry

                                        join GeneralJournalEntry, LedgerDimension , LedgerAccount from generalJournalAccountEntry

                                    where generalJournalAccountEntry.GeneralJournalEntry == generalJournalEntry.RecId

                                        join mainAccountView

                                    where mainAccountView.LedgerDimensionId == generalJournalAccountEntry.LedgerDimension //&&

                                        join custTrans

                                    where custTrans.AccountNum == custAgingReportTmp.AccountNum;


                                    ledgerAcc = strLen(generalJournalAccountEntry.LedgerAccount);

                                    ledgerDimension = generalJournalAccountEntry.LedgerDimension;

                                 if (ledgerAcc >= 12)//17)

                                 {

                                       while select dimView where dimView.ValueCombinationRecId == ledgerDimension

                                           join dimAttribute

                                               where dimAttribute.RecId == dimView.DimensionAttribute

                                           {

                                               if (dimAttribute.Name == 'LineofBusiness')

                                               {

                                                   custAgingReportTmp.AWELOB = dimView.DisplayValue;

                                                   custAgingReportTmp.update();

                                               }

                                               if (dimAttribute.Name == 'Location' )

                                                {

                                                    custAgingReportTmp.AWELOC = dimView.DisplayValue;

                                                    custAgingReportTmp.update();

                                                }

                                                if (dimAttribute.Name == 'Department')

                                                {

                                                    custAgingReportTmp.AweDepartment = dimView.DisplayValue;

                                                    custAgingReportTmp.update();

                                                }

                                                if (dimAttribute.Name == 'Product' )

                                                 {

                                                     custAgingReportTmp.AWEProduct = dimView.DisplayValue;

                                                     custAgingReportTmp.update();

                                                 }

                                                 if (dimAttribute.Name == 'Project')

                                                 {

                                                     custAgingReportTmp.AWEProject =  dimView.DisplayValue;

                                                     custAgingReportTmp.update();

                                                 }

                                            }

                                 }                               

                              }

                        ttsCommit;

                    }

                }

            }

        }      

    }

    return custAgingReportTmp;

}

[SysEntryPointAttribute]

public void processReport()

{

 List            dataArea;

    ListIterator    iterator;

    DataAreaId      dataAreaId;

    dataArea    =   new List(Types::String);

    contract    =   this.parmDataContract() as CustAgingReportContract;

    dataArea    =   contract.parmDataArea();

    if (dataArea && !dataArea.empty())

    {

        iterator = new ListIterator(dataArea);

        while(iterator.more())

        {

            dataAreaId = iterator.value();

            changeCompany(dataAreaId)

            {

                this.AweProcessReport();

            }

            iterator.next();

        }

    }

    else

    {

        this.AweProcessReport();

    }

}








AX 2012: Lookup - Getting records against company

Form Lookup: Getting records against company


public void lookup()

{

    Query query = new Query();

    QueryBuildDataSource    queryBuildDataSource;

    QueryBuildRange         queryBuildRange;

    SysTableLookup          sysTableLookup;

    AweFinDimMappingView    findingEntity;

    select firstOnly CompanyCode from findingEntity where findingEntity.CompanyCode == curext();

    sysTableLookup = SysTableLookup::newParameters(tableNum(AweFinDimMappingView), this);

    sysTableLookup.addLookupField(fieldNum(AweFinDimMappingView, Location));

    sysTableLookup.addLookupField(fieldNum(AweFinDimMappingView, Description));

    queryBuildDataSource = query.addDataSource(tableNum(AweFinDimMappingView));

    queryBuildDataSource.addRange(fieldNum(AweFinDimMappingView, Location));

    if (findingEntity.CompanyCode)

    {

       queryBuildDataSource.addRange(fieldNum( AweFinDimMappingView, CompanyCode)).value(findingEntity.CompanyCode);

    }

    sysTableLookup.parmQuery(query);

    sysTableLookup.performFormLookup();

    //super();

}

AX 2012: Entry Form-- Record will flow based button controls Edit, Delete, Submit, Approve

 Entry Form: Submitter and Approver has specified roles for taking action

Parameter Form:


Form code:

public class FormRun extends ObjectRun

{

    boolean roleExist;

    boolean warningmsg1, warningmsg2;

    AweSalesPriceTMP    salesPriceTMP;

}

public void init() // Form level

{

    super();

    AweSalesPriceTMP_ds.executeQuery();

}

public void initValue() // Form DS level

{

    super();

    AweSalesPriceTMP.SalesCurrency = 'USD';

    AweSalesPriceTMP.ProjSalesPriceModel = ProjSalesPriceModel::PercentMarkup;

    AweSalesPriceTMP.Type = ProjType::TimeMaterial;

}

public int active() // Form DS level

{

    int ret;

    ret = super();

    if (AweSalesPriceTMP.Status == AweStagingPriceStatus::Approved || AweSalesPriceTMP.Status == AweStagingPriceStatus::Submitted)

    {

        AweSalesPriceTMP_ds.allowEdit(false);

    }

    else

    {

        AweSalesPriceTMP_ds.allowEdit(true);

    }

    return ret;

}

public void executeQuery() // Form DS level

{

    if (AweSalesPriceStagingTable_Status.valueStr() == enum2str(AweStagingPriceStatus::Approved))

    {

        this.query().dataSourceTable(tableNum(AweSalesPriceTMP)).clearRanges();

        this.query().dataSourceTable(tableNum(AweSalesPriceTMP)).addRange(fieldNum(AweSalesPriceTMP, Status)).value(enum2str(AweStagingPriceStatus::Approved));

         super();

    }

     else if (AweSalesPriceStagingTable_Status.valueStr() == enum2str(AweStagingPriceStatus::NotProcessed))

    {

        this.query().dataSourceTable(tableNum(AweSalesPriceTMP)).clearRanges();

        this.query().dataSourceTable(tableNum(AweSalesPriceTMP)).addRange(fieldNum(AweSalesPriceTMP, Status)).value(enum2str(AweStagingPriceStatus::NotProcessed));

         super();

    }

     else if (AweSalesPriceStagingTable_Status.valueStr() == enum2str(AweStagingPriceStatus::Submitted))

    {

        this.query().dataSourceTable(tableNum(AweSalesPriceTMP)).clearRanges();

        this.query().dataSourceTable(tableNum(AweSalesPriceTMP)).addRange(fieldNum(AweSalesPriceTMP, Status)).value(enum2str(AweStagingPriceStatus::Submitted));

        super();

    }

     else if (AweSalesPriceStagingTable_Status.valueStr() == enum2str(AweStagingPriceStatus::ALL))

     {

         this.query().dataSourceTable(tableNum(AweSalesPriceTMP)).clearRanges();

         this.query().dataSourceTable(tableNum(AweSalesPriceTMP)).addRange(fieldNum(AweSalesPriceTMP, Status));

         super();

     }

}

void clicked() // Approved button

{

    //super();

    SecurityRole                    securityRole;

    SecurityUserRole                securityUserRole;

    UserInfo                        userInfo;

    str                             submitRole, ApproveRole, userRole,recid;

    AweSalesPriceTMP                aweSalesPriceTMPLoc;

    int                             track = 0;

    int64                           recIdLoc;

    ProjCostSalesPrice              salesPriceExpense;

    AweProjSalesPriceItem           salesPriceItem;

    warningmsg1     = false;

    warningmsg2     = false;

    aweSalesPriceTMPLoc    = AweSalesPriceTMP_ds.getFirst(true);

    ApproveRole               = AweProjSalesPriceParameter::find().AweApproveRole;

    while select securityRole

            exists join securityUserRole

                    where securityRole.RecId    == securityUserRole.SecurityRole &&

                          securityUserRole.User == curUserId()

    {

        userRole    =   securityRole.Name;

        if (userRole == ApproveRole || userRole == 'System administrator')

        {

            roleExist   = false;

            while (aweSalesPriceTMPLoc.RecId != 0 && aweSalesPriceTMPLoc.Status == AweStagingPriceStatus::Submitted)

            {

                recIdLoc = aweSalesPriceTMPLoc.RecId;

                ttsBegin;

                select forUpdate aweSalesPriceTMPLoc

                    where  aweSalesPriceTMPLoc.RecId == recIdLoc;

                aweSalesPriceTMPLoc.Status = AweStagingPriceStatus::Approved;

                aweSalesPriceTMPLoc.ApprovedUser = curUserId();

                aweSalesPriceTMPLoc.ApprovedDateTime = DateTimeUtil::getSystemDateTime();

                aweSalesPriceTMPLoc.update();

                select forUpdate salesPriceExpense;

                salesPriceExpense.TransDate             = aweSalesPriceTMPLoc.EffectiveDate;

                salesPriceExpense.CategoryId            = aweSalesPriceTMPLoc.CategoryId;

                salesPriceExpense.Worker                = aweSalesPriceTMPLoc.Worker;

                salesPriceExpense.ProjValidFor          = aweSalesPriceTMPLoc.ProjValidFor;

                salesPriceExpense.ProjId                = aweSalesPriceTMPLoc.ProjId;

                salesPriceExpense.PSAProjInvoiceProjId  = aweSalesPriceTMPLoc.PSAProjInvoiceProjId;

                salesPriceExpense.PSACustAccount        = aweSalesPriceTMPLoc.PSACustAccount;

                salesPriceExpense.ProjPriceGroup        = aweSalesPriceTMPLoc.ProjPriceGroup;

                salesPriceExpense.CurrencyId            = aweSalesPriceTMPLoc.SalesCurrency;

                salesPriceExpense.ProjSalesPriceModel   = aweSalesPriceTMPLoc.ProjSalesPriceModel;

                salesPriceExpense.ProjSalesPricing      = aweSalesPriceTMPLoc.Pricing;

                salesPriceExpense.insert();

                select forUpdate salesPriceItem;

                salesPriceItem.CustomerAccount      = aweSalesPriceTMPLoc.PSACustAccount;

                salesPriceItem.EffectiveDate        = aweSalesPriceTMPLoc.EffectiveDate;

                salesPriceItem.ProjectContractId    = aweSalesPriceTMPLoc.PSAProjInvoiceProjId;

                salesPriceItem.Pricing              = aweSalesPriceTMPLoc.Pricing;

                salesPriceItem.ProjectId            = aweSalesPriceTMPLoc.ProjId;

                salesPriceItem.SalesCurrency        = aweSalesPriceTMPLoc.SalesCurrency;

                salesPriceItem.ProjSalesPriceModel  = aweSalesPriceTMPLoc.ProjSalesPriceModel;

                salesPriceItem.Type                 = aweSalesPriceTMPLoc.Type;

                salesPriceItem.insert();

                ttsCommit;

                aweSalesPriceTMPLoc = AweSalesPriceTMP_ds.getNext();

                track ++;

                roleExist = true;

            }

            if (aweSalesPriceTMPLoc.RecId != 0 && aweSalesPriceTMPLoc.status != AweStagingPriceStatus::Submitted)

            {

                warningmsg1 = true;

            }

            if (aweSalesPriceTMPLoc.RecId != 0 && aweSalesPriceTMPLoc.status == AweStagingPriceStatus::Approved)

            {

                warningmsg2 = true;

            }

            AweSalesPriceTMP_ds.reread();

            AweSalesPriceTMP_ds.executeQuery();

            AweSalesPriceTMP_ds.refresh();

        }

    }

    if (roleExist == true)

    {

       //info(strFmt("Record has been approved successfully: %1",track));

        info("Record has been approved successfully");

    }

    else if (warningmsg1 == true)

         {

            Global::warning("Status should be 'Submitted' state for approve the record");

         }

    else if (warningmsg2 == true)

         {

            Global::warning("Record already been approved state");

         }

    else

    {

        Global::error("User - " +curUserId()+ " - don't have privilleges to submit record");

    }

}

public boolean modified() // Unbounded Enum(Filter)

{

    boolean ret;

    ret = super();

    AweSalesPriceTMP_ds.executeQuery();

    return ret;

}

void clicked() // Delete button

{

    //super();

    SecurityRole                    securityRole;

    SecurityUserRole                securityUserRole;

    UserInfo                        userInfo;

    str                             submitRole, ApproveRole, userRole,recid;

    AweSalesPriceTMP                aweSalesPriceTMPLoc;

    int                             track = 0;

    int64                           recIdLoc;


    aweSalesPriceTMPLoc    = AweSalesPriceTMP_ds.getFirst(true);

    submitRole             = AweProjSalesPriceParameter::find().AweSubmissionRole;

    ApproveRole            = AweProjSalesPriceParameter::find().AweApproveRole;


    while select securityRole

            exists join securityUserRole

                    where securityRole.RecId    == securityUserRole.SecurityRole &&

                          securityUserRole.User == curUserId()

    {

        userRole    =   securityRole.Name;

        if (userRole == submitRole || userRole == ApproveRole || userRole == 'System administrator')

        {

            roleExist   = false;

            while (aweSalesPriceTMPLoc.RecId != 0 && aweSalesPriceTMPLoc.Status ==                     AweStagingPriceStatus::Submitted)

            {

                recIdLoc = aweSalesPriceTMPLoc.RecId;

                ttsBegin;

                select forUpdate aweSalesPriceTMPLoc

                    where  aweSalesPriceTMPLoc.RecId == recIdLoc;

                aweSalesPriceTMPLoc.delete();

                ttsCommit;

                aweSalesPriceTMPLoc = AweSalesPriceTMP_ds.getNext();

                track ++;

            }

            if (aweSalesPriceTMPLoc.RecId != 0 && aweSalesPriceTMPLoc.status == AweStagingPriceStatus::Approved)

            {

                throw Global::warning("Approved record will not be allowed for deletion");

            }

            AweSalesPriceTMP_ds.reread();

            AweSalesPriceTMP_ds.executeQuery();

            AweSalesPriceTMP_ds.refresh();

            roleExist = true;

        }

    }

    while (aweSalesPriceTMPLoc.RecId != 0 && aweSalesPriceTMPLoc.Status == AweStagingPriceStatus::NotProcessed)

    {

        roleExist   = false;

        recIdLoc = aweSalesPriceTMPLoc.RecId;

        ttsBegin;

        select forUpdate aweSalesPriceTMPLoc

            where  aweSalesPriceTMPLoc.RecId == recIdLoc;

        aweSalesPriceTMPLoc.delete();

        ttsCommit;

        aweSalesPriceTMPLoc = AweSalesPriceTMP_ds.getNext();

        track ++;

        if (track)

        {

            AweSalesPriceTMP_ds.reread();

            AweSalesPriceTMP_ds.executeQuery();

            AweSalesPriceTMP_ds.refresh();

            roleExist = true;

        }

    }

    if (roleExist == true)

    {

       //info(strFmt("Record has been Deleted successfully: %1",track));

        info("Record has been Deleted successfully");

    }

    else

    {

        Global::error("User - " +curUserId()+ " - don't have privilleges to submit record");

    }

}

void clicked() // Edit button

{

    //super();

    SecurityRole                    securityRole;

    SecurityUserRole                securityUserRole;

    UserInfo                        userInfo;

    str                             submitRole, ApproveRole, userRole,recid;

    AweSalesPriceTMP                aweSalesPriceTMPLoc;

    int                             track = 0;

    int64                           recIdLoc;

    warningmsg1     = false;

    warningmsg2     = false;

    aweSalesPriceTMPLoc    = AweSalesPriceTMP_ds.getFirst(true);

    submitRole             = AweProjSalesPriceParameter::find().AweSubmissionRole;

    while select securityRole

            exists join securityUserRole

                    where securityRole.RecId    == securityUserRole.SecurityRole &&

                          securityUserRole.User == curUserId()

    {

        userRole    =   securityRole.Name;

        if (userRole == submitRole || userRole == 'System administrator')

        {

            roleExist   = false;

            while (aweSalesPriceTMPLoc.RecId != 0 && aweSalesPriceTMPLoc.Status == AweStagingPriceStatus::Submitted)

            {

                recIdLoc = aweSalesPriceTMPLoc.RecId;

                ttsBegin;

                select forUpdate aweSalesPriceTMPLoc

                    where  aweSalesPriceTMPLoc.RecId == recIdLoc;

                aweSalesPriceTMPLoc.Status = AweStagingPriceStatus::NotProcessed;

                aweSalesPriceTMPLoc.SubmittedUser = '';

                aweSalesPriceTMPLoc.SubmittedDateTime = utcDateTimeNull();

                aweSalesPriceTMPLoc.update();

                ttsCommit;

                aweSalesPriceTMPLoc = AweSalesPriceTMP_ds.getNext();

                track ++;

                roleExist = true;

            }

            if (aweSalesPriceTMPLoc.RecId != 0 && aweSalesPriceTMPLoc.status == AweStagingPriceStatus::Approved)

            {

                warningmsg1 = true;

            }

            if (aweSalesPriceTMPLoc.RecId != 0 && aweSalesPriceTMPLoc.status == AweStagingPriceStatus::NotProcessed)

            {

                warningmsg2 = true;

            }

            AweSalesPriceTMP_ds.reread();

            AweSalesPriceTMP_ds.executeQuery();

            AweSalesPriceTMP_ds.refresh();

        }

    }

    if (roleExist == true)

    {

       //info(strFmt("Record has been moved to NotProcessed state successfully: %1",track));

        info("Record has been moved to NotProcessed state successfully");

    }

    else if (warningmsg1 == true)

         {

             Global::error("Approved records will not be allowing to modify the record");

         }

    else if (warningmsg2 == true)

         {

            Global::warning("The record already in NotProcesed state for modify record");

         }

    else

    {

        Global::error("User - " +curUserId()+ " - don't have privilleges to submit record");

    }

}

void clicked() // Submit button

{

    //super();

    SecurityRole                    securityRole;

    SecurityUserRole                securityUserRole;

    UserInfo                        userInfo;

    str                             submitRole, ApproveRole, userRole,recid;

    AweSalesPriceTMP                aweSalesPriceTMPLoc, aweSalesPriceTMPLocal,aweSalesPriceTMPLocal1;

    int                             track = 0;

    int64                           recIdLoc;

    boolean                         error = false;

    TransDate transDate;

    warningmsg1     = false;

    warningmsg2     = false;

    aweSalesPriceTMPLoc    = AweSalesPriceTMP_ds.getFirst(true);

    submitRole             = AweProjSalesPriceParameter::find().AweSubmissionRole;

    //ApproveRole               = AweProjSalesPriceParameter::find().AweApproveRole;

    while select securityRole

            exists join securityUserRole

                    where securityRole.RecId    == securityUserRole.SecurityRole &&

                          securityUserRole.User == curUserId()

    {

        userRole    =   securityRole.Name;

        if (userRole == submitRole || userRole == 'System administrator')

        {

            if (aweSalesPriceTMPLoc.ProjId && aweSalesPriceTMPLoc.PSAProjInvoiceProjId)

               {

                   throw Global::error(strFmt('The both ProjId %1 and Contractor %2 combination is not allowed', aweSalesPriceTMPLoc.ProjId, aweSalesPriceTMPLoc.PSAProjInvoiceProjId));

                   //error = true;

               }

            if (aweSalesPriceTMPLoc.ProjId && aweSalesPriceTMPLoc.PSACustAccount)

               {

                   throw Global::error(strFmt('The both ProjId %1 and Customer account %2 combination is not allowed', aweSalesPriceTMPLoc.ProjId, aweSalesPriceTMPLoc.PSACustAccount));

                   //error = true;

               }

            if (aweSalesPriceTMPLoc.PSAProjInvoiceProjId && aweSalesPriceTMPLoc.PSACustAccount)

               {

                   throw Global::error(strFmt('The both Contractor %1 and Customer account %2 combination is not allowed', aweSalesPriceTMPLoc.PSAProjInvoiceProjId, aweSalesPriceTMPLoc.PSACustAccount));

                   //error = true;

               }

            transDate = aweSalesPriceTMPLoc.EffectiveDate;

            while select EffectiveDate,Status,ProjId,PSAProjInvoiceProjId,PSACustAccount from aweSalesPriceTMPLocal

                        where aweSalesPriceTMPLocal.EffectiveDate == transDate &&

                              aweSalesPriceTMPLocal.Status != AweStagingPriceStatus::NotProcessed

                {

                    if (aweSalesPriceTMPLocal.ProjId == aweSalesPriceTMPLoc.ProjId &&

                        !aweSalesPriceTMPLocal.PSAProjInvoiceProjId &&

                        !aweSalesPriceTMPLocal.PSACustAccount

                       )

                       {

                            throw Global::warning(strFmt('The record %1 is already exist %2', aweSalesPriceTMPLocal.EffectiveDate, aweSalesPriceTMPLocal.ProjId));

                            //error = true;

                        }

                else if (aweSalesPriceTMPLocal.PSAProjInvoiceProjId == aweSalesPriceTMPLoc.PSAProjInvoiceProjId &&

                         !aweSalesPriceTMPLocal.ProjId &&

                         !aweSalesPriceTMPLocal.PSACustAccount

                        )

                        {

                            throw Global::warning(strFmt('The record %1 is already exist %2', aweSalesPriceTMPLocal.EffectiveDate, aweSalesPriceTMPLocal.PSAProjInvoiceProjId));

                            //error = true;

                        }

                else if (aweSalesPriceTMPLocal.PSACustAccount == aweSalesPriceTMPLoc.PSACustAccount &&

                         !aweSalesPriceTMPLocal.ProjId  &&

                         !aweSalesPriceTMPLocal.PSAProjInvoiceProjId

                        )

                        {

                            throw Global::warning(strFmt('The record %1 is already exist %2', aweSalesPriceTMPLocal.EffectiveDate, aweSalesPriceTMPLocal.PSACustAccount));

                            //error = true;

                         }

                }

            roleExist   = false;

            while (aweSalesPriceTMPLoc.RecId != 0 && aweSalesPriceTMPLoc.Status == AweStagingPriceStatus::NotProcessed)

            {

                recIdLoc = aweSalesPriceTMPLoc.RecId;

                ttsBegin;

                select forUpdate aweSalesPriceTMPLoc

                    where  aweSalesPriceTMPLoc.RecId == recIdLoc;

                aweSalesPriceTMPLoc.Status = AweStagingPriceStatus::Submitted;

                aweSalesPriceTMPLoc.SubmittedUser = curUserId();

                aweSalesPriceTMPLoc.SubmittedDateTime = DateTimeUtil::getSystemDateTime();

                aweSalesPriceTMPLoc.update();

                ttsCommit;

                aweSalesPriceTMPLoc = AweSalesPriceTMP_ds.getNext();

                track ++;

                roleExist = true;

            }

            if (aweSalesPriceTMPLoc.RecId != 0 && aweSalesPriceTMPLoc.status == AweStagingPriceStatus::Submitted)

            {

                warningmsg1 = true;

            }

            if (aweSalesPriceTMPLoc.RecId != 0 && aweSalesPriceTMPLoc.status == AweStagingPriceStatus::Approved)

            {

                 warningmsg2 = true;

            }

            AweSalesPriceTMP_ds.reread();

            AweSalesPriceTMP_ds.executeQuery();

            AweSalesPriceTMP_ds.refresh();

        }

    }

    if (roleExist == true)

    {

       //info(strFmt("Record has been submitted successfully: %1",track));

        info("Record has been submitted successfully");

    }

    else if (warningmsg1 == true)

        {

            Global::warning("Record Status is already in 'Submitted' state");

        }

    else if (warningmsg2 == true)

         {

             Global::error("The Record is in Approved state");

         }

    else

    {

        Global::error("User - " +curUserId()+ " - don't have privilleges to submit record");

    }

}

Friday, October 8, 2021

AX 2012: Enquiry form, finding the file from shared drive based on date

 Batch job: Finding the file from shared drive based on date


public class AWEPaymentTrackerReadFilesFromDirectory extends RunBaseBatch

{

    FilePath                        filePath, filePathOutbound;

    Filename                        filename;

    CommaTextIo                     fileIO;

    Set                             fileSet;

    CommaIo                         commaIo;

    str                             currentFile;

    container                       lineCon;

    RecId                           recIdSAP, recIdOrlando, recIdNashville, recIdEdison;

    date                            systemDate;

    AweHOSPaymentTrackerParameter   filePathparameter;

    #File

    #AviFiles

}

private void getCSVFiles()

{

    System.String[]  files;

    System.Collections.IEnumerator  enumerator;

    str file;

    fileSet = new Set(Types::Container);

    files = System.IO.Directory::GetFiles(filePath, '*.csv');

    enumerator = files.GetEnumerator();

    while (enumerator.MoveNext())

    {

        file = enumerator.get_Current();

        fileSet.add([file]);

    }

}

private void GetTxtFiles()

{

    System.String[]  files;

    System.Collections.IEnumerator  enumerator;

    str file;

    fileSet = new Set(Types::Container);

    files = System.IO.Directory::GetFiles(filePath, '*.txt');

    enumerator = files.GetEnumerator();

    while (enumerator.MoveNext())

    {

        file = enumerator.get_Current();

        fileSet.add([file]);

    }

}

private void GetXmlFiles()

{

    System.String[]  files;

    System.Collections.IEnumerator  enumerator;

    str file;

    fileSet = new Set(Types::Container);

    files = System.IO.Directory::GetFiles(filePathOutbound, '*.xml');

    enumerator = files.GetEnumerator();

    while (enumerator.MoveNext())

    {

        file = enumerator.get_Current();

        fileSet.add([file]);

    }

}

private void readFilesFromDirtecoryACH()

{

    SetEnumerator           sE;

    str                     filenameLoc, filedate;

    date                    fileDateLoc;

    AweHOSPaymentTracker    paymentTracker, paymentTrackerLoc;

    //filePath = @"\\ame001.americanwaterservices.com\CIFS\Shared\PNC Lockbox\AWRL Lockbox\CC ACH\SK-Completed";

    select *from filePathparameter where filePathparameter.FilePathType     == FilePathType::Processed &&     filePathparameter.MethodOfPayment  == MethodOfPayment::ACH_CC;

    filePath = filePathparameter.FilePath;

    systemDate          = systemDateGet(); //17\09\2021;

    this.getCSVFiles();

    sE = fileSet.getEnumerator();

    while (sE.moveNext()) // loop through all files

    {

        filename = sE.current();

        filenameLoc = subStr(filename, 95,5);

        if (filenameLoc == "ACH_2")

        {

            filedate    = subStr(filename, 99,8);

            fileDateLoc = str2Date(filedate, 321);

            if (fileDateLoc == systemDate)

            {

                paymentTracker.TransDate = fileDateLoc;

                paymentTracker.PaymMode = 'ACH';

                //paymentTracker.Inbound = Inbound::None;

                paymentTracker.InboundProcessed = Processed::None;

                //paymentTracker.Outbound = Outbound::None;

                paymentTracker.OutboundProcessed = Processed::None;

                paymentTracker.Processed = Processed::Yes;

                paymentTracker.CompanyId = paymentTracker.dataAreaId;

                paymentTracker.Remarks = '';

                select *from paymentTrackerLoc where paymentTrackerLoc.TransDate == paymentTracker.TransDate &&   paymentTrackerLoc.PaymMode  == paymentTracker.PaymMode;

                if (paymentTrackerLoc.TransDate != paymentTracker.TransDate &&                       paymentTrackerLoc.PaymMode != paymentTracker.PaymMode)

                {

                     paymentTracker.insert();

                }

            }

        }

        else if (filenameLoc == "CC_20")

        {

            filedate    = subStr(filename, 98,8);

            fileDateLoc = str2Date(filedate, 321);

            if (fileDateLoc == systemDate)

            {

                paymentTracker.TransDate = fileDateLoc;

                paymentTracker.PaymMode = 'CreditCard';

                //paymentTracker.Inbound = Inbound::None;

                paymentTracker.InboundProcessed = Processed::None;

                //paymentTracker.Outbound = Outbound::None;

                paymentTracker.OutboundProcessed = Processed::None;

                paymentTracker.Processed = Processed::Yes;

                paymentTracker.CompanyId = paymentTracker.dataAreaId;

                paymentTracker.Remarks = '';

                select *from paymentTrackerLoc where paymentTrackerLoc.TransDate == paymentTracker.TransDate &&    paymentTrackerLoc.PaymMode  == paymentTracker.PaymMode;

                if (paymentTrackerLoc.TransDate != paymentTracker.TransDate && paymentTrackerLoc.PaymMode != paymentTracker.PaymMode)

                {

                     paymentTracker.insert();

                }

            }

        }

        else if (filenameloc == "CC_XX" || filenameloc == "CC_ZZ")

        {

            filedate    = substr(filename, 101,8);

            filedateloc = str2date(filedate, 321);

            if (filedateloc == systemdate)

            {

                paymentTracker.TransDate = fileDateLoc;

                if (filenameloc == "CC_XX")

                {

                   paymentTracker.PaymMode = 'CC_XX';

                }

                else

                {

                   paymentTracker.PaymMode = 'CC_ZZ';

                }

                paymentTracker.Inbound              = Inbound::None;

                paymentTracker.InboundProcessed     = Processed::None;

                paymentTracker.Outbound             = Outbound::None;

                paymentTracker.OutboundProcessed    = Processed::None;

                paymentTracker.Processed            = Processed::Yes;

                paymentTracker.CompanyId            = paymentTracker.dataAreaId;

                paymentTracker.Remarks              = '';

                select *from paymentTrackerLoc where paymentTrackerLoc.TransDate == paymentTracker.TransDate &&   paymentTrackerLoc.PaymMode  == paymentTracker.PaymMode;

                if (paymentTrackerLoc.TransDate != paymentTracker.TransDate && paymentTrackerLoc.PaymMode != paymentTracker.PaymMode)

                {

                     paymentTracker.insert();

                }

            }

        }

    }

    info('ACH Done');

}

private void readFilesFromEdisonLibertyInbound()

{

    SetEnumerator           sE;

    str                     filedate;

    date                    fileDateLoc;

    System.DateTime         systemDateTime;

    //date                    systemDate;

    utcDateTime             utcNow;

    AweHOSPaymentTracker    paymentTracker, paymentTrackerLoc;

    boolean                  RecInster;

    //filePath = @"\\Train-ax01\ax\AIF\I082\Inbound\Archive";

    select *from filePathparameter where filePathparameter.FilePathType     == FilePathType::Inbound &&   filePathparameter.MethodOfPayment  == MethodOfPayment::Edison;

    filePath = filePathparameter.FilePath;

    this.GetTxtFiles();

    sE = fileSet.getEnumerator();

    while (sE.moveNext()) // loop through all files

    {

        filename    = sE.current();

        filedate    = subStr(filename, 60,8);

        fileDateLoc = str2Date(filedate, 321);

        if (fileDateLoc != systemDate)

        {

            if (RecInster == false)

            {

             paymentTracker.TransDate           = systemDate;

             paymentTracker.PaymMode            = 'Edison';

             //paymentTracker.Inbound             = Inbound::No;

             paymentTracker.InboundProcessed    = Processed::No;

             //paymentTracker.Outbound            = Outbound::None;

             paymentTracker.OutboundProcessed   = Processed::None;

             paymentTracker.Processed           = Processed::None;

             paymentTracker.CompanyId           = paymentTracker.dataAreaId;

             paymentTracker.Remarks             = '';

             RecInster = true;

            }

        }

         else if (fileDateLoc == systemDate)

         {

             paymentTracker.TransDate           = systemDate;

             paymentTracker.PaymMode            = 'Edison';

             //paymentTracker.Inbound             = Inbound::Yes;

             paymentTracker.InboundProcessed    = Processed::Yes;

             //paymentTracker.Outbound            = Outbound::None;

             paymentTracker.OutboundProcessed   = Processed::None;

             paymentTracker.Processed           = Processed::None;

             paymentTracker.CompanyId           = paymentTracker.dataAreaId;

             paymentTracker.Remarks             = '';

         }

    }

    select *from paymentTrackerLoc where paymentTrackerLoc.TransDate == paymentTracker.TransDate &&   paymentTrackerLoc.PaymMode  == paymenttracker.PaymMode;

    if (paymentTrackerLoc.TransDate != paymentTracker.TransDate && paymentTrackerLoc.PaymMode != paymentTracker.PaymMode)

    {

        paymentTracker.insert();

        recIdEdison = paymentTracker.recid;

    }

}

private void readFilesFromEdisonLibertyOutbound()

{

    SetEnumerator           sE, sEOutbound;

    str                     filedate;

    date                    fileDateLoc;

    System.DateTime         systemDateTime;

    //date                    systemDate;

    utcDateTime             utcNow;

    boolean                 recInsert;

    AweHOSPaymentTracker    paymentTrackerLoc;

    //filePathOutbound = @"\\ame001.americanwaterservices.com\CIFS\shared\dynamics\Training\ax\SKS\PNC Lockbox\AWRL Lockbox\EdisonLiberty\SK-Completed";

    select *from filePathparameter where filePathparameter.FilePathType     == FilePathType::Outbound &&   filePathparameter.MethodOfPayment  == MethodOfPayment::Edison;

    filePathOutbound = filePathparameter.FilePath;

    this.GetXmlFiles();

    sEOutbound = fileSet.getEnumerator();

    while (sEOutbound.moveNext()) // loop through all files

    {

        filename    = sEOutbound.current();

        filedate    = subStr(filename, 125,8);

        fileDateLoc = str2Date(filedate, 321);

        ttsBegin;

        if (fileDateLoc != systemDate)

         {

             if (recInsert == false)

             {

                select forUpdate paymentTrackerLoc where paymentTrackerLoc.RecId == recIdEdison;

                if (paymentTrackerLoc)

                {

                    //paymentTrackerLoc.Outbound          = Outbound::No;

                    paymentTrackerLoc.OutboundProcessed = Processed::No;

                    paymentTrackerLoc.update();

                }

                recInsert = true;

             }

         }

         else if (fileDateLoc == systemDate)

         {

             select forUpdate paymentTrackerLoc where paymentTrackerLoc.RecId == recIdEdison;

             if (paymentTrackerLoc)

             {

                 //paymentTrackerLoc.Outbound          = Outbound::Yes;

                 paymentTrackerLoc.OutboundProcessed = Processed::Yes;

                 paymentTrackerLoc.doUpdate();

             }

         }

         ttsCommit;

    }

    info('Edison Liberty Done');

}

private void readFilesFromNashvilleInbound()

{

    SetEnumerator           sE;

    str                     filedate;

    date                    fileDateLoc;

    System.DateTime         systemDateTime;

    //date                    systemDate;

    utcDateTime             utcNow;

    AweHOSPaymentTracker    paymentTracker, paymentTrackerLoc;

    boolean                 RecInster;

    //filePath = @"\\Train-ax01\ax\AIF\I099\Inbound\Archive";

    select *from filePathparameter where filePathparameter.FilePathType     == FilePathType::Inbound && filePathparameter.MethodOfPayment  == MethodOfPayment::Nashville;

    filePath = filePathparameter.FilePath;

    this.GetTxtFiles();

    sE = fileSet.getEnumerator();

    while (sE.moveNext()) // loop through all files

    {

        filename = sE.current();

        filedate = subStr(filename, 48,8);

        fileDateLoc = str2Date(filedate, 123);

        if (fileDateLoc != systemDate)

        {

            if (RecInster == false)

            {

             paymentTracker.TransDate           = systemDate;

             paymentTracker.PaymMode            = 'Nashville';

             //paymentTracker.Inbound             = Inbound::No;

             paymentTracker.InboundProcessed    = Processed::No;

             //paymentTracker.Outbound            = Outbound::None;

             paymentTracker.OutboundProcessed   = Processed::None;

             paymentTracker.Processed           = Processed::None;

             paymentTracker.CompanyId           = paymentTracker.dataAreaId;

             paymentTracker.Remarks             = '';

             RecInster = true;

            }

        }

         else if (fileDateLoc == systemDate)

         {

             paymentTracker.TransDate           = systemDate;

             paymentTracker.PaymMode            = 'Nashville';

             //paymentTracker.Inbound             = Inbound::Yes;

             paymentTracker.InboundProcessed    = Processed::Yes;

             //paymentTracker.Outbound            = Outbound::None;

             paymentTracker.OutboundProcessed   = Processed::None;

             paymentTracker.Processed           = Processed::None;

             paymentTracker.CompanyId           = paymentTracker.dataAreaId;

             paymentTracker.Remarks             = '';

         }

    }

    select *from paymentTrackerLoc where paymentTrackerLoc.TransDate == paymentTracker.TransDate &&  paymentTrackerLoc.PaymMode  == paymenttracker.PaymMode;

    if (paymentTrackerLoc.TransDate != paymentTracker.TransDate && paymentTrackerLoc.PaymMode != paymentTracker.PaymMode)

    {

        paymentTracker.insert();

        recIdNashville = paymentTracker.recid;

    }

}

private void readFilesFromNashvilleOutbound()

{

    SetEnumerator           sE, sEOutbound;

    str                     filedate;

    date                    fileDateLoc;

    System.DateTime         systemDateTime;

    //date                    systemDate;

    utcDateTime             utcNow;

    boolean                 recInsert;

    AweHOSPaymentTracker    paymentTrackerLoc;

    //filePathOutbound = @"\\ame001.americanwaterservices.com\CIFS\shared\dynamics\Training\ax\SKS\PNC Lockbox\AWRL Lockbox\Nashville\SK-Completed";

    select *from filePathparameter where filePathparameter.FilePathType == FilePathType::Outbound &&    filePathparameter.MethodOfPayment == MethodOfPayment::Nashville;

    filePathOutbound = filePathparameter.FilePath;

    this.GetXmlFiles();

    sEOutbound = fileSet.getEnumerator();

    while (sEOutbound.moveNext()) // loop through all files

    {

        filename    = sEOutbound.current();

        filedate    = subStr(filename, 121,8);

        fileDateLoc = str2Date(filedate, 321);

        ttsBegin;

        if (fileDateLoc != systemDate)

         {

             if (recInsert == false)

             {

                select forUpdate paymentTrackerLoc where paymentTrackerLoc.RecId == recIdNashville;

                if (paymentTrackerLoc)

                {

                    //paymentTrackerLoc.Outbound          = Outbound::No;

                    paymentTrackerLoc.OutboundProcessed = Processed::No;

                    paymentTrackerLoc.update();

                }

                recInsert = true;

             }

         }

         else if (fileDateLoc == systemDate)

         {

             select forUpdate paymentTrackerLoc where paymentTrackerLoc.RecId == recIdNashville;

             if (paymentTrackerLoc)

             {

                 //paymentTrackerLoc.Outbound          = Outbound::Yes;

                 paymentTrackerLoc.OutboundProcessed = Processed::Yes;

                 paymentTrackerLoc.doUpdate();

             }

         }

         ttsCommit;

    }

    info('Nashville done');

}

private void readFilesFromOrlandoInbound()

{

    SetEnumerator           sE;

    str                     filedate;

    date                    fileDateLoc;

    System.DateTime         systemDateTime;

    //date                    systemDate;

    utcDateTime             utcNow;

    AweHOSPaymentTracker    paymentTracker, paymentTrackerLoc;

    boolean                 RecInster;

    //filePath = @"\\Train-ax01\ax\AIF\CR12414Payment\Inbound\Archive";

    select *from filePathparameter where filePathparameter.FilePathType == FilePathType::Inbound &&

                                         filePathparameter.MethodOfPayment == MethodOfPayment::Orlando;

    filePath = filePathparameter.FilePath;

    this.GetTxtFiles();

    sE = fileSet.getEnumerator();

    while (sE.moveNext()) // loop through all files

    {

        filename = sE.current();

        filedate = subStr(filename, 60,8);

        fileDateLoc = str2Date(filedate, 321);

        if (fileDateLoc != systemDate)

        {

            if (RecInster == false)

            {

             paymentTracker.TransDate           = systemDate;

             paymentTracker.PaymMode            = 'Orlando';

             //paymentTracker.Inbound             = Inbound::No;

             paymentTracker.InboundProcessed    = Processed::No;

             //paymentTracker.Outbound            = Outbound::None;

             paymentTracker.OutboundProcessed   = Processed::None;

             paymentTracker.Processed           = Processed::None;

             paymentTracker.CompanyId           = paymentTracker.dataAreaId;

             paymentTracker.Remarks             = '';

             RecInster = true;

            }

        }

         else if (fileDateLoc == systemDate)

         {

             paymentTracker.TransDate           = systemDate;

             paymentTracker.PaymMode            = 'Orlando';

             //paymentTracker.Inbound             = Inbound::Yes;

             paymentTracker.InboundProcessed    = Processed::Yes;

             //paymentTracker.Outbound            = Outbound::None;

             paymentTracker.OutboundProcessed   = Processed::None;

             paymentTracker.Processed           = Processed::None;

             paymentTracker.CompanyId           = paymentTracker.dataAreaId;

             paymentTracker.Remarks             = '';

         }

    }

    select *from paymentTrackerLoc where paymentTrackerLoc.TransDate == paymentTracker.TransDate &&  paymentTrackerLoc.PaymMode  == paymenttracker.PaymMode;

    if (paymentTrackerLoc.TransDate != paymentTracker.TransDate && paymentTrackerLoc.PaymMode != paymentTracker.PaymMode)

    {

        paymentTracker.insert();

        recIdOrlando = paymentTracker.recid;

    }

}

private void readFilesFromOrlandoOutbound()

{

    SetEnumerator           sE, sEOutbound;

    str                     filedate;

    date                    fileDateLoc;

    System.DateTime         systemDateTime;

    //date                    systemDate;

    utcDateTime             utcNow;

    boolean                 recInsert;

    AweHOSPaymentTracker    paymentTrackerLoc;

    //filePathOutbound = @"\\ame001.americanwaterservices.com\CIFS\Shared\Dynamics\Training\AX\SKS\PNC Lockbox\AWRL Lockbox\Orlando\SK-Completed";

    select *from filePathparameter where filePathparameter.FilePathType == FilePathType::Outbound &&   filePathparameter.MethodOfPayment == MethodOfPayment::Orlando;

    filePathOutbound = filePathparameter.FilePath;

    this.GetXmlFiles();

    sEOutbound = fileSet.getEnumerator();

    while (sEOutbound.moveNext()) // loop through all files

    {

        filename    = sEOutbound.current();

        filedate    = subStr(filename, 119,8);

        fileDateLoc = str2Date(filedate, 321);

        ttsBegin;

        if (fileDateLoc != systemDate)

         {

             if (recInsert == false)

             {

                select forUpdate paymentTrackerLoc where paymentTrackerLoc.RecId == recIdOrlando;

                if (paymentTrackerLoc)

                {

                    //paymentTrackerLoc.Outbound          = Outbound::No;

                    paymentTrackerLoc.OutboundProcessed = Processed::No;

                    paymentTrackerLoc.update();

                }

                recInsert = true;

             }

         }

         else if (fileDateLoc == systemDate)

         {

             select forUpdate paymentTrackerLoc where paymentTrackerLoc.RecId == recIdOrlando;

             if (paymentTrackerLoc)

             {

                 //paymentTrackerLoc.Outbound          = Outbound::Yes;

                 paymentTrackerLoc.OutboundProcessed = Processed::Yes;

                 paymentTrackerLoc.doUpdate();

             }

         }

         ttsCommit;

    }

    info('Orlando done');

}

private void readFilesFromSAPInbound()

{

    SetEnumerator           sE;

    str                     filedate;

    date                    fileDateLoc;

    System.DateTime         systemDateTime;

    utcDateTime             utcNow;

    AweHOSPaymentTracker    paymentTracker, paymentTrackerLoc;

    boolean                 RecInster;

    //filePath = @"\\Train-ax01\ax\AIF\I017\Inbound\Archive";

    select *from filePathparameter where filePathparameter.FilePathType == FilePathType::Inbound &&

                                         filePathparameter.MethodOfPayment == MethodOfPayment::SAP;

    filePath = filePathparameter.FilePath;

    this.GetTxtFiles();

    sE = fileSet.getEnumerator();

    while (sE.moveNext()) // loop through all files

    {

        filename    = sE.current();

        filedate    = subStr(filename, 56,8);

        fileDateLoc = str2Date(filedate, 321);

        if (fileDateLoc != systemDate)

        {

            if (RecInster == false)

            {

             paymentTracker.TransDate           = systemDate;

             paymentTracker.PaymMode            = 'SAP';

             //paymentTracker.Inbound             = Inbound::No;

             paymentTracker.InboundProcessed    = Processed::No;

             //paymentTracker.Outbound            = Outbound::None;

             paymentTracker.OutboundProcessed   = Processed::None;

             paymentTracker.Processed           = Processed::None;

             paymentTracker.CompanyId           = paymentTracker.dataAreaId;

             paymentTracker.Remarks             = '';

             RecInster = true;

            }

        }

         else if (fileDateLoc == systemDate)

         {

             info(strFmt("%1, %2", 'SAP', fileDateLoc));

             paymentTracker.TransDate           = systemDate;

             paymentTracker.PaymMode            = 'SAP';

             //paymentTracker.Inbound             = Inbound::Yes;

             paymentTracker.InboundProcessed    = Processed::Yes;

             //paymentTracker.Outbound            = Outbound::None;

             paymentTracker.OutboundProcessed   = Processed::None;

             paymentTracker.Processed           = Processed::None;

             paymentTracker.CompanyId           = paymentTracker.dataAreaId;

             paymentTracker.Remarks             = '';

         }

    }

    select *from paymentTrackerLoc where paymentTrackerLoc.TransDate == paymentTracker.TransDate &&    paymentTrackerLoc.PaymMode  == paymenttracker.PaymMode;

    if (paymentTrackerLoc.TransDate != paymentTracker.TransDate && paymentTrackerLoc.PaymMode != paymentTracker.PaymMode)

    {

        paymentTracker.insert();

        recIdSAP = paymentTracker.recid;

    }

}

private void readFilesFromSAPOutbound()

{

    SetEnumerator           sE, sEOutbound;

    str                     filedate;

    date                    fileDateLoc;

    System.DateTime         systemDateTime;

    //date                    systemDate;

    utcDateTime             utcNow;

    boolean                 recInsert;

    AweHOSPaymentTracker    paymentTracker, paymentTrackerLoc;

    //filePathOutbound = @"\\ame001.americanwaterservices.com\CIFS\Shared\Dynamics\Training\AX\SKS\PNC Lockbox\AWRL Lockbox\SAP\SK-Completed";

    select *from filePathparameter where filePathparameter.FilePathType == FilePathType::Outbound &&  filePathparameter.MethodOfPayment == MethodOfPayment::SAP;

    filePathOutbound = filePathparameter.FilePath;

    this.GetXmlFiles();

    sEOutbound = fileSet.getEnumerator();

    while (sEOutbound.moveNext()) // loop through all files

    {

        filename = sEOutbound.current();

        filedate = subStr(filename, 115,8);

        fileDateLoc = str2Date(filedate, 321);

        ttsBegin;

        if (fileDateLoc != systemDate)

         {

             if (recInsert == false)

             {

                select forUpdate paymentTrackerLoc where paymentTrackerLoc.RecId == recIdSAP;

                if (paymentTrackerLoc)

                {

                    //paymentTrackerLoc.Outbound = Outbound::No;

                    paymentTrackerLoc.OutboundProcessed = Processed::No;

                    paymentTrackerLoc.update();

                }

                recInsert = true;

             }

         }

         else if (fileDateLoc == systemDate)

         {

             select forUpdate paymentTrackerLoc where paymentTrackerLoc.RecId == recIdSAP;

             if (paymentTrackerLoc)

             {

                 //paymentTrackerLoc.Outbound = Outbound::Yes;

                 paymentTrackerLoc.OutboundProcessed = Processed::Yes;

                 paymentTrackerLoc.doUpdate();

             }

         }

         ttsCommit;

    }

    info('SAP done');

}

public void run()

{

    this.readFilesFromDirtecoryACH();

    this.readFilesFromSAPInbound();

    this.readFilesFromSAPOutbound();

    this.readFilesFromOrlandoInbound();

    this.readFilesFromOrlandoOutbound();

    this.readFilesFromNashvilleInbound();

    this.readFilesFromNashvilleOutbound();

    this.readFilesFromEdisonLibertyInbound();

    this.readFilesFromEdisonLibertyOutbound();

}

Public static AWEPaymentTrackerReadFilesFromDirectory construct()

{

    return new AWEPaymentTrackerReadFilesFromDirectory();

}

public static ClassDescription description()

{

    return 'HOS Customer Payment Tracker';

}

Public static void main(Args _args)

{

    AWEPaymentTrackerReadFilesFromDirectory  readFiles = AWEPaymentTrackerReadFilesFromDirectory::construct();

    if (readFiles.prompt())

    {

        readFiles.run();

    }

}

Enquiry Form with unbounded fields and get the sum of Amount, Total records from Data source(active records in grid)

AX 2012: Enquiry Form




public class FormRun extends ObjectRun

{

}

public void init()   //Form Init method

{

    AweAdvDefHeader advDefHeaderLoc;

    super();

    AweAdvDefLine_ds.executeQuery();

    select RecId, Asofdate from advDefHeaderLoc order by recid desc;

    AsOfDate.dateValue(advDefHeaderLoc.Asofdate);

    AsOfDate.modified();

}

public void executeQuery()   // DS ExecuteQuery

{

    AweAdvDefHeader advDefHeader;

    Name valueStr, dateStr;

    TransDate valueDate;

    valueStr = AsOfDate.valueStr();

    valueDate = str2Date(valueStr, 213);

    select RecId,Asofdate from advDefHeader where advDefHeader.Asofdate == valueDate;

    if (advDefHeader.RecId )

    {

        this.query().dataSourceTable(tableNum(AweAdvDefLine)).clearRanges();

        this.query().dataSourceTable(tableNum(AweAdvDefLine)).addRange(fieldNum(AweAdvDefLine,AweAdvDefHeader )).value(int642str(advDefHeader.RecId));

        super();

    }    

    //Default values

    PostedAmount.realValue(0.00);

    BilledAmount.realValue(0.00);

    CreditAmount.realValue(0.00);

    AdvDefAmount.realValue(0.00);

    RemaingBalance.realValue(0.00);

    TotalRows.value(0);

}

public void lookup()  // Design -- Field level

{

    Query query = new Query();

    QueryBuildDataSource    queryBuildDataSource;

    QueryBuildRange         queryBuildRange;

    SysTableLookup          sysTableLookup;

    AweAdvDefHeader         AdvDefHeader;

    select firstOnly dataAreaId from AdvDefHeader where AdvDefHeader.dataAreaId == curext();

    sysTableLookup = SysTableLookup::newParameters(tableNum(AweAdvDefHeader), this);

    sysTableLookup.addLookupField(fieldNum(AweAdvDefHeader, Asofdate));

    queryBuildDataSource = query.addDataSource(tableNum(AweAdvDefHeader));

    queryBuildDataSource.addRange(fieldNum(AweAdvDefHeader, Asofdate));

    if (AdvDefHeader.dataAreaId)

    {

       queryBuildDataSource.addRange(fieldNum(AweAdvDefHeader, Asofdate)).value(AdvDefHeader.dataAreaId);

    }

    sysTableLookup.parmQuery(query);

    sysTableLookup.performFormLookup();

    //super();

}

public boolean modified()  // Design -- Field level

{

    Name valueStr;

    TransDate valueDate;

    AweAdvDefHeader advDefHeader;

    boolean ret;

    ret = super();

    AweAdvDefLine_ds.executeQuery();

    valueStr  = AsOfDate.valueStr();

    valueDate = str2Date(valueStr, 213);

    select Asofdate,createdDateTime from advDefHeader

                        where advDefHeader.Asofdate == valueDate;

    CreatedDateTime.dateTimeValue(advDefHeader.createdDateTime);

    return ret;

}

void clicked()  // Button clicked

{

    int             rowcount, countLine;

    Amount          PostedAmt, BilledAmt, CreditAmt, RAmt, AdvDefAmt;

    AweAdvDefLine   advDifLineLoc, advDifLineLocal;

    super();

    advDifLineLoc = AweAdvDefLine_ds.getFirst();

    countLine = 0;

    rowcount = AweAdvDefLine_ds.numberOfRowsLoaded();

    while (advDifLineLoc && rowcount >= countLine)

    {

        select RecId, PostedAmount, Billedamount,CRAmount,RemainingBalance,AdvDefAmount

                     from advDifLineLocal where advDifLineLocal.RecId == advDifLineLoc.RecId;

        PostedAmt +=  advDifLineLocal.PostedAmount;

        BilledAmt +=  advDifLineLocal.Billedamount;

        CreditAmt +=  advDifLineLocal.CRAmount;

        AdvDefAmt +=  advDifLineLocal.AdvDefAmount;

        RAmt      +=  advDifLineLocal.RemainingBalance;

        advDifLineLoc = AweAdvDefLine_ds.getNext();

        countLine++;

    }

    PostedAmount.realValue(PostedAmt);

    BilledAmount.realValue(BilledAmt);

    CreditAmount.realValue(CreditAmt);

    AdvDefAmount.realValue(AdvDefAmt);

    RemaingBalance.realValue(RAmt);

    TotalRows.value(rowcount);

}