24 Ocak 2019 Perşembe

AX 2012 - Kur girişi, hesaplama, kurdan TL tutar hesaplama

Kur hesaplama:

ExchangeRateCurrencyPair    pair;

//TCMB : Döviz kur tipi (ExchangeRateType) tablosu Name anahtar alanı
select firstOnly pair
                    where pair.ExchangeRateType == ExchangeRateType::findByName("TCMB").RecId &&
                        pair.FromCurrencyCode == "USD" &&
                        pair.ToCurrencyCode == Ledger::accountingCurrency(CompanyInfo::current());


this.ExchangeRate = ExchangeRate::findByDate(pair.RecId,systemDateGet()).ExchangeRate;

Kur girişi için edit metod ( SalesTable gibi bir çok formda örneği var ):

public edit CurrencyExchangeRate editExchRate(boolean set, CurrencyExchangeRate _exchRate)
{
    ExchangeRateHelper exchangeRateHelper = ExchangeRateHelper::newCurrency(Ledger::primaryLedger(CompanyInfo::findDataArea(curext()).RecId), this.Currency);

    if (set)
    {
        this.ExchangeRate = exchangeRateHelper.prepareExchangeRateForStorage(_exchRate);
    }
    else
    {
        _exchRate = exchangeRateHelper.displayStoredExchangeRate(this.ExchangeRate);
    }

    return _exchRate;
}

Girilen kur değerinden TL tutar hesaplama:
ExchangeRateHelper exchangeRateHelper = ExchangeRateHelper::newCurrency(Ledger::primaryLedger(CompanyInfo::findDataArea(curext()).RecId), Ledger::accountingCurrency(CompanyInfo::current()));
 CurrencyExchangeHelper  cur = CurrencyExchangeHelper::construct();
   
 cur.parmLedgerRecId(Ledger::primaryLedger(CompanyInfo::current()));
 cur.parmExchangeDate(today());
//Eğer bugünün kurunu otomatik bulmasını istiyorsanız aşağıdaki iki satırı silin
     cur.parmExchangeRate1(exchangeRateHelper.prepareExchangeRateForStorage(1));
cur.parmExchangeRate2(this.ExchangeRate);
    this.BudgetAmountMST = cur.calculateTransactionToAccounting(this.Currency,this.BudgetAmount,true);

veya yukarıdaki işlemin kısa hali:

info(strFmt("%1", Currency::curAmount(100,"usd",today(),UnknownNoYes::Yes,500,100)));
    info(strFmt("%1", Currency::curAmount2CurAmount(100,"usd","try",today())));

Hiç yorum yok:

Yorum Gönderme