Tuesday 9 July 2019

Export voucher transactions/ split dimensions query

Query

class ALE_ExportVoucherTransToExcel extends RunBase
{
    QueryRun qr;

    DialogField dlgFromDate,dlgToDate;
    TransDate fromDate, toDate;

    #define.CurrentVersion(1)
    #localmacro.CurrentList

    #endmacro
}

......................................................................
public boolean canGoBatch()
{
    return true;
}

...........................................................
protected boolean canGoBatchJournal()
{
    return true;
}
/////////////////////////////////////////////

protected Object dialog()
{
    Dialog dialog;

    dialog = super();
    dialog.caption('Export voucher transactions to excel');

    return dialog;
}
--------------------------------------------------------------------

public boolean getFromDialog()
{
    boolean ret;

    ret = super();

    return ret;
}
--------------------------------------------------------------------
public void initParmDefault()
{
    Query query = new Query();
    QueryBuildRange queryBuildRange;
    QueryBuildDataSource queryBuildDataSource;
    ;
    queryBuildDataSource = query.addDataSource(tableNum(GeneralJournalEntry));
    queryBuildRange = queryBuildDataSource.addRange(FieldNum(GeneralJournalEntry,AccountingDate));

    qr = new SysQueryRun(query);

    super();
}
----------------------------------------------------------------------
public container pack()
{
    container pack = conNull();

    if (qr)
    {
        pack = qr.pack();
    }
    return [#CurrentVersion] + [pack];
}
-----------------------------------------------------------
public QueryRun queryRun()
{
    return qr;
}
--------------------------------------------------------
public void run()
{
    #AviFiles
    Args                                args;
    FormRun                             formRun;
    DimensionAttributeValueSetStorage    dimStorage;
    Counter                              i;
    DimensionAttributeLevelValueAllView dimAttrView; //View that will display all values for ledger dimensions
    DimensionAttribute                  dimAttr;
    GeneralJournalEntry                 generalJournalEntry;
    GeneralJournalEntry                 generalJournalEntryExcel;
    GeneralJournalAccountEntry          generalJournalAccountEntry;
    ALE_GeneralJournalAccountEntryExcel generalJournalAccountEntryExcel;
    DimensionValue                      bl,dept,project,worker,vehicle;


    SysOperationProgress    progressBar = new SysOperationProgress();
    args = new Args();

    delete_from generalJournalAccountEntryExcel;
    startLengthyOperation();
    while (qr.next())
    {
        generalJournalEntry = qr.get(tableNum(GeneralJournalEntry));
        try
        {
            while select generalJournalAccountEntry
                where generalJournalAccountEntry.GeneralJournalEntry == generalJournalEntry.RecId
            {
                bl = '';
                dept = '';
                project = '';
                vehicle ='';
                worker = '';

                while select DisplayValue from dimAttrView
                    where dimAttrView.ValueCombinationRecId == generalJournalAccountEntry.LedgerDimension
                    join BackingEntityType,Name from dimAttr
                        where dimAttr.RecId == dimAttrView.DimensionAttribute
                {
                    switch (dimAttr.Name)
                    {
                        case 'BusinessLine':
                            bl = dimAttrView.DisplayValue;
                            break;

                        case 'Department':
                            dept =  dimAttrView.DisplayValue;
                            break;

                        case 'Project':
                            project = dimAttrView.DisplayValue;
                            break;

                        case 'Vehicle':
                            vehicle = dimAttrView.DisplayValue;
                            break;

                        case 'Worker':
                            worker =  dimAttrView.DisplayValue;
                            break;
                    }
                }

                generalJournalAccountEntryExcel.JournalNumber       = generalJournalEntry.JournalNumber;
                generalJournalAccountEntryExcel.AccountingDate      = generalJournalEntry.AccountingDate;
                generalJournalAccountEntryExcel.SubledgerVoucher    = generalJournalEntry.SubledgerVoucher;
                generalJournalAccountEntryExcel.LedgerAccount       = generalJournalAccountEntry.LedgerAccount;

                generalJournalAccountEntryExcel.TransactionCurrencyCode     = generalJournalAccountEntry.TransactionCurrencyCode;
                generalJournalAccountEntryExcel.TransactionCurrencyAmount   = generalJournalAccountEntry.TransactionCurrencyAmount;
                generalJournalAccountEntryExcel.ReportingCurrencyAmount     = generalJournalAccountEntry.ReportingCurrencyAmount;
                generalJournalAccountEntryExcel.AccountingCurrencyAmount    = generalJournalAccountEntry.AccountingCurrencyAmount;
                generalJournalAccountEntryExcel.PostingType                 = generalJournalAccountEntry.PostingType;

                generalJournalAccountEntryExcel.BusinessLine    = bl;
                generalJournalAccountEntryExcel.Department      = dept;
                generalJournalAccountEntryExcel.Project         = project;
                generalJournalAccountEntryExcel.Vehicle         = vehicle;
                generalJournalAccountEntryExcel.Worker          = worker;
                generalJournalAccountEntryExcel.insert();

                progressBar.setCaption(strfmt("Exporting the voucher transactions"));
                progressBar.setAnimation(#AviUpdate);
                progressBar.setText(strfmt("Processing"));
            }

        }
        catch(Exception::Deadlock)
        {
            error('Caught an exception');
            retry;
        }
    }

    endLengthyOperation();
    args.name(formstr(ALE_VoucherTransExportToExcel));
    formRun = new FormRun(args);
    formRun.run();
    formRun.wait();
}
-------------------------------------------------------------------
public boolean runsImpersonated()
{
    return true;
}
------------------------------------------------------
public boolean showQueryValues()
{
    return true;
}
-----------------------------------
public boolean unpack(container _packedClass)
{
    boolean     ret         = false;
    int         version     = RunBase::getVersion(_packedClass);
    container   packedQuery = conNull();

    switch (version)
    {
        case #CurrentVersion:
            [version, packedQuery] = _packedClass;

            if (SysQuery::isPackedOk(packedQuery))
            {
                qr   = new QueryRun(packedQuery);
                ret         = true;
            }
            break;

        default:
            ret = false;
    }
    return ret;
}
---------------------------------------------------
static ClassDescription description()
{
    return "Export to excel";
}
-----------------------------------------------------------
public static void main(Args args)
{
    ALE_ExportVoucherTransToExcel exportVoucherTransToExcel = new ALE_ExportVoucherTransToExcel();

    if (exportVoucherTransToExcel.prompt())
    {
        exportVoucherTransToExcel.run();
    }
}

No comments:

Post a Comment