Saturday, October 9, 2021

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);

}


Wednesday, February 12, 2020

Calling class from form and form DS level

Class TDCFinishPreOperation

Field level :
--------------

void clicked()
{
    Args args = new Args();

    super();

    args.record(ProdParmReportFinished);

    TDCFinishPreOperation::main(args);
 }
-----------------------------------------------------------------------------

Scenario 2: Form level
------------------------------
void init()
{
    args args;
    ProdTable   prodTableLocal ;
    ProjId      projId;

    if(!element.args().caller())
        throw error(strFmt("@NCC174",'NCProjProdWizardEdit'));

    // get record from the Class, not from callerForm
 
    args      = element.args().caller().getArgs();
    prodTableLocal = args.record();

    this.setProdTable(prodTableLocal);
    this.setParentProjId(prodTableLocal.ProjId);

    super(); 

    this.insertProjToProdValues();

    //----------------BLR97124
}

Create Journal for Production orders

public void FinishPreOprDiggEnterprinor(ProdId _prodId, OprNum _oprNum, ProdParmReportFinished _prodParmReportFinished)
{
    ProdParmReportFinished              prodParmReportFinishedLoc;

    select prodRoute where prodRoute.ProdId == _prodId &&
                           prodRoute.OprNum == _oprNum;

    prodParmReportFinishedLoc.clear();
    prodParmReportFinishedLoc.initValue();
    prodParmReportFinishedLoc.initFromProdTable(ProdTable::find(_prodParmReportFinished.ProdId));
    prodParmReportFinishedLoc.FromOprNum         = _oprNum;
    prodParmReportFinishedLoc.ToOprNum           = _oprNum;
    prodParmReportFinishedLoc.AcceptError        = _prodParmReportFinished.AcceptError;
    prodParmReportFinishedLoc.EndRouteCard       = _prodParmReportFinished.EndRouteCard;
    prodParmReportFinishedLoc.EndJob             = _prodParmReportFinished.EndJob;
    prodParmReportFinishedLoc.AutoUpdate         = _prodParmReportFinished.AutoUpdate;
    prodParmReportFinishedLoc.BOMJournalNameId   = _prodParmReportFinished.BOMJournalNameId;
    prodParmReportFinishedLoc.BOMAutoConsump     = _prodParmReportFinished.BOMAutoConsump;
    prodParmReportFinishedLoc.ExecutedDateTime   = DateTimeUtil::getSystemDateTime();
    prodParmReportFinishedLoc.JobStatus          = ParmJobStatus::Executed;
    prodParmReportFinishedLoc.JournalShowInfo    = _prodParmReportFinished.JournalShowInfo;
    prodParmReportFinishedLoc.LineNum            = 1;
    prodParmReportFinishedLoc.ParmId             = _prodParmReportFinished.ParmId;
    prodParmReportFinishedLoc.QtyGood            = _prodParmReportFinished.QtyGood;
    prodParmReportFinishedLoc.QtyError           = _prodParmReportFinished.QtyError;
    prodParmReportFinishedLoc.TransDate          = _prodParmReportFinished.TransDate;
    prodParmReportFinishedLoc.ProdJournalNameId  = _prodParmReportFinished.ProdJournalNameId;
    prodParmReportFinishedLoc.RouteJournalNameId = _prodParmReportFinished.RouteJournalNameId;
    prodParmReportFinishedLoc.insert();

    prodJournalCreate = ProdJournalCreateRoute::newReportFinished(_prodParmReportFinished);
    prodJournalCreate.parmOprNumFrom(_oprNum);
    prodJournalCreate.parmOprNumTo(_oprNum);
    prodJournalCreate.run();

    prodJournalTable = prodJournalCreate.usedProdJournalTable();

    if (prodJournalTable.RecId && prodJournalTable.JournalId)
    {
        prodJournalCheckPostRoute = ProdJournalCheckPostRoute::newPostJournal(prodJournalTable.JournalId,_prodParmReportFinished.JournalShowInfo);
        prodJournalCheckPostRoute.run();
    }
}
------------------------------------------------------------
static void main(Args _args)
{
    TDCFinishPreOperation  tDCFinishPreOperation = new TDCFinishPreOperation();
    ProdParmReportFinished parmReportFinished;

    if (_args.dataset() == tableNum(ProdParmReportFinished))
    {
        parmReportFinished = _args.record();
    }

    tDCFinishPreOperation.ParmProdParmReportFinished(parmReportFinished);
    tDCFinishPreOperation.run();
}

Create Journal for ProdRoute table productions : Finish Previous Operation Digging/Enterprinor

class TDCFinishPreOperation
{
    ProdJournalTable                    prodJournalTable;
    ProdJournalRoute                    prodJournalRoute;
    ProdRoute                           prodRoute, prodRouteLoc; 
    RouteOprId                          routeOprId;
    ProdJournalCheckPostRoute           prodJournalCheckPostRoute;
    ProdJournalCreateRoute              prodJournalCreate;
    ProdParmReportFinished              prodParmReportFinished;
}

public ProdParmReportFinished ParmProdParmReportFinished(ProdParmReportFinished _prodParmReportFinished = prodParmReportFinished)
{
    prodParmReportFinished = _prodParmReportFinished;

    return prodParmReportFinished;
}
public void run()
{
    ProdTable               prodTable = ProdTable::find(ProdParmReportFinished.ProdId);

    RouteOprTable           routeOprTableLoc;
    int                     oprNextNum;

    select firstOnly RecId, OprId from routeOprTableLoc
                  join OprNum from prodRoute where routeOprTableLoc.OprId == prodRoute.OprId &&
                                             (routeOprTableLoc.ExecuteBy == NCExecuteBy::Digging ||
                                             routeOprTableLoc.ExecuteBy == NCExecuteBy::Entreprenor) &&
                                             prodRoute.ProdId == prodTable.ProdId &&
                                             prodRoute.OprNum == ProdParmReportFinished.FromOprNum;
    if (routeOprTableLoc.RecId)
    {
        oprNextNum = prodRoute.OprNum;

        while select prodRouteLoc order by OprNum where prodRouteLoc.OprNum < oprNextNum &&
                                                        prodRouteLoc.ProdId == prodTable.ProdId &&
                                                        prodRouteLoc.ProdStatus == ProdStatus::StartedUp
        {
           this.FinishPreOprDiggEnterprinor(prodRouteLoc.ProdId, prodRouteLoc.OprNum, prodParmReportFinished);
        }
    }
}