×

Simple Transaction with key and foreign currency

The following section describes how a simple transactions either with key currency or foreign currencies have to be established.
 
Example code
 
Create a simple transaction with Key Currency
 
Create Transaction in Key Currency
    
        public void CreateSimpleTransaction_KC()
        {
            IManager manager = new Manager();
            decimal paymentAmount = 1000.0M;

            // Load transactions via LoadTransactions()
            errorcode = manager.LoadTransactions();

            // Add some error handling here

            // Create a transaction instance
            ITransaction transaction = new Transaction();
            transaction.NumRangeFID = manager.Defaults.DefSimpleNumRangeFID;
            transaction.TransactionTypeFID = (int)TransactionType.Simple;
            transaction.DocNum = manager.Defaults.DefSimpleCurrNum;

            transaction.DocType = "RR";
            DateTime date = DateTime.Today;
            transaction.DocDate = new DateTime(date.Year, date.Month, date.Day);

            manager.LoadAccounts();
            IPosting posting1 = new Posting();
            posting1.AccountFID = manager.FindAccountID("1020");

            posting1.Text = "Test Case Single Transaction Posting #1";
            posting1.FreeCode = "SN_1002";
            posting1.Amount = paymentAmount;
            posting1.FcAmount = paymentAmount;
            posting1.ExchangeRate = 1;
            posting1.IsDebit = true;
            posting1.IsInclusive = false;

            IPosting posting2 = new Posting();
            posting2.AccountFID = manager.FindAccountID("3200");
            posting2.Text = "TestCase Single Transaction Posting #2";
            posting2.FreeCode = "Free 2";
            posting2.Amount = paymentAmount;
            posting2.FcAmount = paymentAmount;
            posting2.ExchangeRate = 1;
            posting2.IsDebit = false;
            posting2.IsInclusive = false;

            transaction.Postings.Add(posting1);
            transaction.Postings.Add(posting2);

            errorcode = manager.SaveTransaction(transaction);

            // Add some error handling here

            manager.Close();
        }
    
  
Create Transaction in Key Currency
    
UNDER CONSTRUCTION
    
  
 
Create a simple transaction with Foreign Currency
 
Create Transaction in Foreign Currency
    
        public void CreateSimpleTransaction_FC()
        {
            IManager manager = new Manager();

            // set the amount of the payment 
            decimal paymentAmount = 1000.0M;

            IFiscalYear fiscalyear = new FiscalYear();
            fiscalyear.Name = "2017";
            manager.SetGlobalFiscalYear(fiscalyear);

            // Load transactions via LoadTransactions()
            errorcode = manager.LoadTransactions();

            // Add some error handling here

            ITransaction transaction = new Transaction();
            transaction.NumRangeFID = manager.Defaults.DefSimpleNumRangeFID;
            transaction.TransactionTypeFID = (int)TransactionType.Simple;
            transaction.DocNum = manager.Defaults.DefSimpleCurrNum;

            transaction.DocType = "RR";
            DateTime date = DateTime.Today;
            transaction.DocDate = new DateTime(date.Year, date.Month, date.Day);

            errorcode = manager.LoadCurrencies();
            state = Helper.ViewErrorMessage(errorcode, manager);

            ICurrency currency = manager.FindCurrency("EUR");
            IData currencyDaily = currency.DailyRates;
            decimal exchangerate = currency.Rate;

            manager.LoadAccounts();
            IPosting posting1 = new Posting();
            posting1.AccountFID = manager.FindAccountID("1023");

            posting1.Text = "TestCase Single Transaction Posting #1";
            posting1.FreeCode = "Free 1";
            posting1.Amount = paymentAmount;
            posting1.ExchangeRate = exchangerate;
            decimal fcAmount = Helper.CalcFCAmount(posting1.Amount, posting1.ExchangeRate);
            posting1.FcAmount = fcAmount;
            posting1.IsDebit = true;

            IPosting posting2 = new Posting();
            posting2.AccountFID = manager.FindAccountID("3200");
            posting2.Text = "TestCase Single Transaction Posting #2";
            posting2.FreeCode = "Free 2";

            posting2.Amount = paymentAmount;
            posting2.ExchangeRate = exchangerate;
            fcAmount = Helper.CalcFCAmount(posting2.Amount, posting2.ExchangeRate);
            posting2.FcAmount = fcAmount;
            posting2.IsDebit = false;

            transaction.Postings.Add(posting1);
            transaction.Postings.Add(posting2);

            errorcode = manager.SaveTransaction(transaction);

            // Add some error handling here

            manager.Close();
        }
    
  
Create Transaction in Foreign Currency
    
UNDER CONSTRUCTION