Currency Conversion X++ AX7, D365FO and AX-2012


Currency Conversion X++ AX7, D365FO and AX-2012


Convert currency to currency.


Static void main(Args args)
{
    CurrencyExchangeHelper currencyExchangeHelper;
    AmountMst amountMST;
    CurrencyCode toCurrency =  ‘AED’;
    CurrencyCode FromCurrency =  ‘USD’;

    AmountCur amountCur = 5000;



        currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), systemDateGet());
        amountMST =  currencyExchangeHelper.calculateCurrencyToCurrency(toCurrency, fromCurrency,amountCur,true);

  
info(strFmt(“%1”, amountMST))


}



Convert Transaction currency to company ledger currency.
The method will convert the transaction currency into accounting currency defined in the ledger.

static void Main(Args _args)
{
    CurrencyExchangeHelper currencyExchangeHelper;
    CurrencyCode transCurrency = ‘EUR’;
    AmountCur amountCur = 5500.00;
    AmountMst amountMST;
   
    currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), systemDateGet());
    amountMST = currencyExchangeHelper.calculateTransactionToAccounting(transCurrency, amountCur ,true);
    info(strFmt(‘%1’,amountMST));
}





Convert Company currency to transaction currency.

The method calculates the transaction currency amount from an accounting currency given.

static void  main(Args _args)
{
    CurrencyExchangeHelper currencyExchangeHelper;
    CurrencyCode transCurrency = ‘AED’;
    AmountCur amountCur;
    AmountMst amountMST = 5500.00;
   
    currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::primaryLedger(CompanyInfo::findDataArea("DUM").RecId), systemDateGet());
    amountCur = currencyExchangeHelper.calculateAccountingToTransaction(transCurrency, amountMST ,true);
    info(strFmt(‘%1’,amountcur));
}

Project Journal D365FO


Project-Hour Journal D365FO


By using the following code sample, You can create the Project journal easily.



  public void createProjectHourJournal(ProjectJournalContract    _projectJournal) // project hour journal
    {
        ProjJournalTableData    JournalTableData;
        ProjJournalTransData    journalTransData;
        ProjJournalTable        journalTable, journalTableUpdate;
        ProjJournalTrans        journalTrans;
        ProjTable               projTable;
        ProjInvoiceTable        projInvoiceTable;
        NumberSeq               numberSeq;
        ProjJournalCheckPost    jourPost;
        ProjQtyEmpl             qty;
        JournalNumOfLines       numOfLines;
        ProjCategory            projCategory;
        LedgerJournalName       ledgerJournalName;
        ProjectJournalTransContract     projecJournalTrans;
       // ProjLinePropertySetup       projLinePropertySetup;
        ProjJournalName         projJournalName;

        if(_projectJournal!=null)
        {

            select projJournalName
                where projJournalName.isFSJournal==NoYes::Yes;

            projecJournalTrans=_projectJournal.getProjectJournalTrans(0);
           
            ttsBegin;
            journalTableData =          JournalTableData::newTable(journalTable);


            journalTransData =            journalTableData.journalStatic().newJournalTransData(journalTrans,  journalTableData);


            //select projLinePropertySetup
            //    where projLinePropertySetup.ProjCode==TableGroupAll::All
            //    && projLinePropertySetup.ProjRelation==projTable.ProjId;

            projTable           = ProjTable::find(projecJournalTrans.ProjectId);
            // Init        JournalTable
            projCategory=ProjCategory::find(projecJournalTrans.ProjectCateId);
      
            journalTable.JournalId      = journalTableData.nextJournalId();

            journalTable.JournalType    = ProjJournalType::Hour;

            journalTable.ProjId=projecJournalTrans.ProjectId;
            journalTable.ProjQty=projecJournalTrans.QtyUsed;
            journalTable.CategoryId=projecJournalTrans.ProjectCateId;
            journalTable.ProjTransDate=systemDateGet();
            //journalTable.LinePropertyId
            journalTable.initFromProjJournalName(projJournalName);
            journalTable.insert();

          
            journalTableData.initFromJournalName(journalTableData.journalStatic().findJournalName(journalTable.JournalNameId));

            journalTrans.clear();
            journalTransData.initFromJournalTable();
    
            projInvoiceTable    = projTable.projInvoice();
           
          

            journalTrans.setTransDate();
          //  journalTrans.TransDate      = systemDateGet();
            journalTrans.ProjTransDate  = systemDateGet();
            journalTrans.ProjId         = projTable.ProjId;
            journalTrans.Qty            = projecJournalTrans.QtyUsed;
            journalTrans.CategoryId     = projCategory.CategoryId;
         //   journalTrans.LinePropertyId = projLinePropertySetup.LinePropertyId;
            journalTrans.Worker         = HcmWorkerLookup::currentWorker();
            journalTrans.ActivityNumber = projecJournalTrans.ActivityId;
            journalTrans.Txt            = _projectJournal.FreeTxt;

           
           

            if(projInvoiceTable.CurrencyId)
            {
                journalTrans.CurrencyId =            projInvoiceTable.CurrencyId;
            }

            else
            {
                journalTrans.CurrencyId =           Ledger::accountingCurrency(CompanyInfo::current());

            }


            journalTrans.DefaultDimension   = projTable.DefaultDimension;
            journalTrans.TaxGroupId         =           ProjParameters::taxGroupInvoice(projTable.ProjId);

            if  (journalTrans.Worker)
            {
                journalTrans.setHourPrices();
                journalTrans.setPeriodDate();
            }

            numberSeq =            NumberSeq::newGetVoucherFromId(journalTable.VoucherNumberSequenceTable, false);
            journalTrans.Voucher        = numberSeq.voucher();
            journalTransData.create();

            ttsCommit;
       

        }

    }

Virtual Fields Vs Computed Fields

  Virtual Field: A virtual field in D365FO is a field that doesn't have a direct representation in the database. It's a field that y...