Wednesday, 26 April 2017

Fx currency Report

[
    SRSReportParameterAttribute(classStr(FxCurrencyContract)),
    SRSReportQueryAttribute(queryStr(FxCurrency))
]
class FxCurrencyDP extends SRSReportDataProviderBase
{
    FxCurrencyTmp            fxCurrencyTmp;
}



[SRSReportDataSetAttribute('FxCurrencyTmp')]
public FxCurrencyTmp getFxCurrencyTmp()
{
    select  fxCurrencyTmp;
    return  fxCurrencyTmp;
}

[SysEntryPointAttribute]
public void processReport()
{
    AEIFxCurrencyContract       contract;
    TransDate                   fromDate;
    TransDate                   toDate;
    String255                   rateType;
    CurrencyCode                fromCurrencyCode;
    Query                       query;
    QueryRun                    queryRun;

    ExchangeRate                queryExchangeRate;
    ExchangeRateCurrencyPair    queryExchangeRateCurrencyPair;

    contract                    = this.parmDataContract();

    fromDate                    = contract.parmFromDate();
    toDate                      = contract.parmToDate();
    rateType                    = contract.parmExchangeRateType();
    fromCurrencyCode            = contract.parmFromCurrencyCode();

    query                       = this.parmQuery();

    query.validTimeStateDateTimeRange(DateTimeUtil::minValue(), DateTimeUtil::maxValue());

    query.dataSourceTable(tableNum(ExchangeRate)).addRange(fieldNum(ExchangeRate, ValidFrom)).value(queryRange(fromDate, toDate));
    query.dataSourceTable(tableNum(ExchangeRateType)).addRange(fieldNum(ExchangeRateType, Name)).value(rateType);
    query.dataSourceTable(tableNum(ExchangeRateCurrencyPair)).addRange(fieldNum(ExchangeRateCurrencyPair, FromCurrencyCode)).value(fromCurrencyCode);

    queryRun                    = new QueryRun(query);

    while(queryRun.next())
    {
        fxCurrencyTmp.clear();

        queryExchangeRate                   = queryRun.get(tableNum(ExchangeRate));
        queryExchangeRateCurrencyPair       = queryRun.get(tableNum(ExchangeRateCurrencyPair));

        fxCurrencyTmp.Currency              = queryExchangeRateCurrencyPair.ToCurrencyCode;
        fxCurrencyTmp.Date                  = queryExchangeRate.ValidFrom;

        if(enum2str(queryExchangeRateCurrencyPair.ExchangeRateDisplayFactor) == '' && queryExchangeRateCurrencyPair.FromCurrencyCode == queryExchangeRateCurrencyPair.ToCurrencyCode)
        {
            fxCurrencyTmp.ExchangeRate      = 1;
        }
        else
        {
            fxCurrencyTmp.ExchangeRate      = ExchangeRateHelper::displayStoredExchangeRate_Static(queryExchangeRate.ExchangeRate, queryExchangeRateCurrencyPair.ExchangeRateDisplayFactor);
        }

        fxCurrencyTmp.insert();
    }

}









Contract CLass



[
    DataContractAttribute,
    SysOperationContractProcessingAttribute(classStr(FxCurrencyUIBuilder))
]
class AeiFxCurrencyContract implements SysOperationValidatable
{
    TransDate       fromDate;
    TransDate       toDate;
    String255       rateType;
    CurrencyCode    fromCurrencyCode;
    ExchangeRateTypeName exchangeRateTypeName;
}

[
    DataMemberAttribute('Exchange rate type'),
    SysOperationLabelAttribute(literalStr("@SYS312339")),
    SysOperationDisplayOrderAttribute('3')
]
public ExchangeRateTypeName parmExchangeRateType(ExchangeRateTypeName _exchangeRateTypeName = exchangeRateTypeName)
{
    exchangeRateTypeName = _exchangeRateTypeName;
    return exchangeRateTypeName;
}



[
    DataMemberAttribute('From currency code'),
    SysOperationLabelAttribute(literalStr("@SYS315108")),
    SysOperationDisplayOrderAttribute('4')
]
public CurrencyCode parmFromCurrencyCode(CurrencyCode _fromCurrencyCode = fromCurrencyCode)
{
    fromCurrencyCode = _fromCurrencyCode;
    return fromCurrencyCode;
}

[
    DataMemberAttribute('ValidFrom'),
    SysOperationLabelAttribute(literalStr("@SYS24050")),
    SysOperationDisplayOrderAttribute('1')
]
public TransDate parmFromDate(TransDate _fromDate = fromDate)
{
    fromDate = _fromDate;
    return fromDate;
}


[
    DataMemberAttribute('ValidTo'),
    SysOperationLabelAttribute(literalStr("@SYS35904")),
    SysOperationDisplayOrderAttribute('2')
]
public TransDate parmToDate(TransDate _toDate = toDate)
{
    toDate = _toDate;
    return toDate;
}


/// Determines whether the parameters are valid.
/// </summary>
/// <returns>
/// true when the parameters are valid; otherwise, false.
/// </returns>
public boolean validate()
{
    boolean isValid = true;
    if (!fromDate)
    {
        isValid = checkFailed(strFmt("@SYS84753", "@SYS24050"));
    }
    if (!toDate)
    {
        isValid = checkFailed(strFmt("@SYS84753", "@SYS35904"));
    }
    if (fromDate > toDate)
    {
        isValid = checkFailed(strFmt("@SYS103965", date2StrUsr(fromDate, DateFlags::FormatAll), date2StrUsr(toDate, DateFlags::FormatAll)));
    }
    if (!fromCurrencyCode)
    {
        isValid = checkFailed(strFmt("@SYS84753","@SYS3392"));
    }
    if (!exchangeRateTypeName)
    {
        isValid = checkFailed(strFmt("@SYS84753","@SYS312339"));
    }
    return isValid;
}



UIBuilder Class



public class FxCurrencyUIBuilder extends SrsReportDataContractUIBuilder
{
    FxCurrencyContract   contract;
}

public void build()
{
    contract = this.dataContractObject();

    this.addDialogField(methodStr(FxCurrencyContract, parmFromDate), contract);
    this.addDialogField(methodStr(FxCurrencyContract, parmToDate), contract);
    this.addDialogField(methodStr(FxCurrencyContract, parmFromCurrencyCode), contract);
    this.addDialogField(methodStr(FxCurrencyContract, parmExchangeRateType), contract);
}

public void lookupExchRateName(FormStringControl _exchangeRateTypeControl)
{
    Query q = new Query();
    SysTableLookup  sysTableLookup;

    sysTableLookup = SysTableLookup::newParameters(tableNum(ExchangeRateType), _exchangeRateTypeControl);
    sysTableLookup.addLookupfield(fieldNum(ExchangeRateType, Name));

    q.addDataSource(tableNum(ExchangeRateType));

    sysTableLookup.parmQuery(q);
    sysTableLookup.performFormLookup();
}

public void postBuild()
{
    DialogField     exchangeRateTypeDialog;

    super();

    exchangeRateTypeDialog = this.bindInfo().getDialogField(this.dataContractObject(),
                methodStr(FxCurrencyContract,parmExchangeRateType));

    exchangeRateTypeDialog.registerOverrideMethod(
          methodStr(FormStringControl, lookup),
          methodStr(AEIFxCurrencyUIBuilder,lookupExchRateName),
          this);
}


No comments:

Post a Comment