Runbase with query parameters, runtime lookup selection on dialog

 /// <summary>

/// The <c>PayrollPayStatementJournalizeBase</c> handles the dialog logic

/// that is common to all pay statement journalizing actions, such as posting

/// and generating vendor invoices.

/// </summary>

class CMCTimeSheetGenerateInquiryDataService extends RunBaseBatch

{

    QueryRun                        queryRun;

    

    FormBuildComboBoxControl        toDateBuildComboBox;

    FormComboBoxControl             toDateComboBox;

    TSTimesheetPeriod  timeSheetWk;

    container periodFromList,periodToList;

    TransDate periodFrom,periodTo;


    HcmWorker worker;

        

    private const str toDateListControl = 'ToDateListControl';


    #DEFINE.CurrentVersion(1)


    #LOCALMACRO.CurrentList

        timeSheetWk

    #ENDMACRO

   


   






    /// <summary>

    /// Builds the list of period end dates and populates the combo box in

    /// dialog with these values for the process.

    /// </summary>

    protected void createToDateList()

    {

        TSTimesheetTable    timeSheetTableLoc;

        int                 selectionIndex = 1;

        periodFromList = conNull();

        periodToList = conNull();


        while select PeriodFrom, PeriodTo from timeSheetTableLoc group by PeriodTo,PeriodFrom

            where timeSheetTableLoc.ApprovalStatus == TSAppStatus::Approved

            

        {

            toDateComboBox.add(timeSheetTableLoc.displayTimesheetPeriod());

            periodFromList += timeSheetTableLoc.PeriodFrom;

            periodToList += timeSheetTableLoc.PeriodTo;

        }


        toDateComboBox.selection(selectionIndex-1);

    }


    public DialogRunbase dialogInit(DialogRunbase dialog = null, boolean forceOnClient = false)

    {

        const int comboTypeList = 1;


        DialogRunbase   dialogModified;


        dialogModified = super(dialog, forceOnClient);


        toDateBuildComboBox = dialogModified.curFormBuildGroup().addControl(FormControlType::ComboBox, toDateListControl);

        toDateBuildComboBox.label("Timesheet period");

        toDateBuildComboBox.comboType(comboTypeList);


        dialogModified.caption("Select the time sheet period generation criteria");


       


        return dialogModified;

    }


    /// <summary>

    ///     Performs additional actions to the dialog after the run event.

    /// </summary>

    /// <param name="_dialog">

    ///     The dialog object created by the class.

    /// </param>

    public void dialogPostRun(DialogRunbase _dialog)

    {

        super(_dialog);

        toDateComboBox = _dialog.dialogForm().formRun().control(toDateBuildComboBox.id());

         this.createToDateList();

        

    }


 


    /// <summary>

    ///     Gets the values set in the dialog by the user.

    /// </summary>

    /// <returns>

    ///     true if the values were retrieved successfully; otherwise, false.

    /// </returns>

    public boolean getFromDialog()

    {

        boolean ret;


        ret = super();


        timeSheetWk    = toDateComboBox.valueStr();


        periodFrom = conPeek(periodFromList, toDateComboBox.selection() + 1);

        periodTo = conPeek(periodToList, toDateComboBox.selection() + 1);

        return ret;

    }


    public void initParmDefault()

    {

        this.initQuery();

       

        super();


        

    }


/// <summary>

    ///     Initializes the query used by the dialog.

    /// </summary>

    void initQuery()

    {

        

        if (!queryRun)

        {

            Query   query = new Query();

            query.addDataSource(tableNum(CMCTimeSheetWeekDetailedView));

            queryRun = new Queryrun(query);

        }


        if(timeSheetWk)

        {

            periodFrom = conPeek(periodFromList, toDateComboBox.selection() + 1);

            periodTo = conPeek(periodToList, toDateComboBox.selection() + 1);

        }


    }


    public QueryRun queryRun()

    {

        return queryRun;

    }


    /// <summary>

    ///     Validates the values supplied by the user on the dialog.

    /// </summary>

    /// <param name="calledFrom">

    ///     The object that called the dialog.

    /// </param>

    /// <returns>

    ///     true if the values are valid; otherwise, false.

    /// </returns>

    public boolean validate(Object calledFrom = null)

    {

        boolean ret;

        ProjPeriodTimesheetWeek payPeriod;


        ret = super(calledFrom);


        if (ret)

        {

            if (!timeSheetWk)

            {

                ret = checkFailed("You must select timesheet week");

            }

        }


        return ret;

    }


    void run()

    {

        CMCTimesheetEntryGeneratedDataTable helperTmp;

        CMCTimeSheetWeekDetailedView detailedView;

        Query queryLoc =  queryRun.query();

        if(periodFrom && periodTo)

        {

            queryLoc.dataSourceTable(tableNum(CMCTimeSheetWeekDetailedView)).addRange(fieldNum(CMCTimeSheetWeekDetailedView,PeriodFrom)).value(queryValue(periodFrom));

            queryLoc.dataSourceTable(tableNum(CMCTimeSheetWeekDetailedView)).addRange(fieldNum(CMCTimeSheetWeekDetailedView,PeriodTo)).value(queryValue(periodTo));

        }


        QueryRun queryCustom = new QueryRun(queryLoc);

       

        RecordInsertList ins = new RecordInsertList(tableNum(CMCTimesheetEntryGeneratedDataTable));

        while(queryCustom.next())

        {

            detailedView =  queryCustom.get(tableNum(CMCTimeSheetWeekDetailedView));

            helperTmp.clear();

            helperTmp = CMCTimesheetEntryGeneratedDataTable::initHelperData(detailedView,helperTmp);


            if(helperTmp.RefRecId)

            {

                int i=1;

                TransDate dayFrom = detailedView.DayFrom;

                while(dayFrom <= detailedView.DayTo)

                {

                    helperTmp.TransDate = dayFrom;

                    helperTmp.Hours =  detailedView.Hours[i];

                    if(helperTmp.Hours)

                    {

                        helperTmp.Total = helperTmp.Hours * helperTmp.Rate;

                        ins.add(helperTmp);

                    }

                

               

                    dayFrom++;

                    i++;


                }

            }

        }

        ins.insertDatabase();

        info("Operation completed");

       

    }


    boolean unpack(container packedClass)

    {

        Integer                         version = RunBase::getVersion(packedClass);

        container                       packedQuery;

        Description timeSheetWkLast;

    

        #LOCALMACRO.SaveLastList

          timeSheetWkLast

        #ENDMACRO

    

        switch (version)

        {

            case #CurrentVersion:

                if (this.inGetSaveLast())

                {

                    // Only want the query from the save last values.

                    [version, #SaveLastList, packedQuery] = packedClass;

                }

                else

                {

                    [version, #CurrentList, packedQuery] = packedClass;

                }

    

                if (SysQuery::isPackedOk(packedQuery))

                {

                    queryRun = new QueryRun(packedQuery);

                }

                else

                {

                    this.initQuery();

                }

                break;

    

            default:

                return false;

        }

    

        return true;

    }


    container pack()

    {

        //

        // If the query has yet to be initialized at this point, we need to do so

        // so that the pack won't fail.

        //

        if (queryRun == null)

        {

            this.initQuery();

        }

    

        return [#CurrentVersion, #CurrentList, queryRun.pack()];

    }


    /// <summary>

    ///

    /// </summary>

    /// <returns></returns>

    public boolean showQuerySelectButton()

    {

        boolean ret;

    

        ret = super();

        ret = true;

    

        return ret;

    }


    /// <summary>

    ///

    /// </summary>

    /// <returns></returns>

    public boolean showQueryValues()

    {

        boolean ret;

    

        ret = super();

        ret = true;

    

        return ret;

    }


    /// <summary>

    ///

    /// </summary>

    static void main(Args args)

    {

        CMCTimeSheetGenerateInquiryDataService dataService = new CMCTimeSheetGenerateInquiryDataService();

    

        if (dataService.prompt())

        {

            // Run from menu item and may be schedulable as a batch, so don't wait for results

            dataService.run();

        }

    }


}

Comments

Popular posts from this blog

Logistics address, postal address, address phone fax contact information

Ledger dimensions and financial Dimensions X++

Prepay posting vendor invoice with amounts