Transaction Management

Topal Financial Accounting Interface provides the possibility to transfer general ledger transactions from a 3rd. Party Application to Topal.
The following examples give an idea how general ledger transactions need to be prepared in order to be created in Topal.
 
Document Structure:
  • General ledger simple transaction
  • General ledger compound transaction
 
Create a general ledger simple transaction
Example Code in this section
REST_Transaction_simple_create()

External references to methods used in examples
#Code reference - Load.account_id_by_account_code

    
        [TestMethod]
        public void REST_Transactions_simple_create()
        {
            state = new ErrorState();

            decimal amount = 5000m;
            Transaction transaction = Create.transaction_simple(amount, manager);
            state.passed = Save.transaction(transaction, manager);
            Assert.AreEqual(true, state.passed, state.message);
        }

        class Create{
        public static Transaction transaction_simple(decimal payment_amount, Manager manager)
        {
            // Create a transaction instance
            Transaction transaction = new Transaction();
            transaction.numRangeFID = Load.defaults(manager).defSimpleNumRangeFID;
            transaction.transactionTypeFID = (int)InternalTypes.TransactionType.Simple;
            transaction.docNum = Load.defaults(manager).defSimpleCurrNum;

            transaction.docType = "XX";
            DateTime date = DateTime.Today;
            transaction.docDate = new DateTime(date.Year, date.Month, date.Day);

            Posting posting1 = new Posting();
            posting1.accountFID = Load.account_id_by_account_code("1020", manager);

            posting1.text = "Test Case Simple Transaction Posting #1";
            posting1.freeCode = "SimpleTransaction free 1";
            posting1.amount = payment_amount;
            posting1.fcAmount = payment_amount;
            posting1.exchangeRate = 1;
            posting1.isDebit = true;
            posting1.isInclusive = false;
            posting1.costCenterFID = -1;

            Posting posting2 = new Posting();
            posting2.accountFID = Load.account_id_by_account_code("3200", manager);
            posting2.text = "Test Case Simple Transaction Posting #2";
            posting2.freeCode = "SimpleTransaction free 2";
            posting2.amount = payment_amount;
            posting2.fcAmount = payment_amount;
            posting2.exchangeRate = 1;
            posting2.isDebit = false;
            posting2.isInclusive = false;
            posting2.costCenterFID = -1;

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

            transaction.isConfirmed = true;

            return transaction;
        }
        }
        class Save{
        public static bool transaction(Transaction transaction, Manager manager)
        {
            var currentClient = manager.getCurrentClient();
            var currentFiscalYear = manager.getCurrentFiscalYear();
            ErrorState state = new ErrorState();

            state.passed = false;
            if (transaction != null)
            {
                var serialized = JsonConvert.SerializeObject(transaction);
                var _cont = new StringContent(serialized, Encoding.UTF8, "application/json");

                string request = "clients/{0}/fiscalYears/{1}/transactions";
                var response = manager.httpClient.PostAsync(string.Format(request, currentClient.id, currentFiscalYear.id), _cont).Result;

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    ResponseDetails details = new ResponseDetails(response);
                }
                state.passed = response.IsSuccessStatusCode;
            }
            return state.passed;
        }
   }

    
  
Create simple transaction
    
    UNDER CONSTRUCTION
    
  
Create simple transaction
    
    UNDER CONSTRUCTION
    
  
JSON representation of a simple transaction
    
{
"id":"00000000-0000-0000-0000-000000000000",
"fiscalYearFID":-1,
"userFID":-1,
"transactionTypeFID":1,
"docType":"XX",
"docNum":4,
"docDate":"2020-03-25T00:00:00",
"modifyDate":"0001-01-01T00:00:00",
"isConfirmed":true,
"numRangeFID":571,
"hasDocument":false,
"postings":[
			{
			"id":"00000000-0000-0000-0000-000000000000",
			"transactionFID":"00000000-0000-0000-0000-000000000000",
			"invoiceFID":"00000000-0000-0000-0000-000000000000",
			"accountFID":10,"contraAccountFID":-1,
			"vatFID":-1,
			"vatAccountFID":-1,
			"costCenterFID":-1,
			"postingTypeFID":1,
			"amount":5000.0,
			"fcAmount":5000.0,
			"exchangeRate":1.0,
			"vatAmount":0.0,
			"vatFcAmount":0.0,
			"vatPercent":0.0,
			"vatQuote":0.0,
			"text":"Test Case Simple Transaction Posting #1",
			"freeCode":"SimpleTransaction free 1",
			"isDebit":true,
			"isInclusive":false,
			"isInvisible":false,
			"postingIndex":0,
			"partyNum":0,
			"freepartyNum":null,
			"partyName":null,
			"invoiceNum":0,
			"freeInvoiceNum":null,
			"invoiceDate":"0001-01-01T00:00:00"
			},
			{
			"id":"00000000-0000-0000-0000-000000000000",
			"transactionFID":"00000000-0000-0000-0000-000000000000",
			"invoiceFID":"00000000-0000-0000-0000-000000000000",
			"accountFID":71,
			"contraAccountFID":-1,
			"vatFID":-1,
			"vatAccountFID":-1,
			"costCenterFID":-1,
			"postingTypeFID":1,
			"amount":5000.0,
			"fcAmount":5000.0,
			"exchangeRate":1.0,
			"vatAmount":0.0,
			"vatFcAmount":0.0,
			"vatPercent":0.0,
			"vatQuote":0.0,"text":
			"Test Case Simple Transaction Posting #2",
			"freeCode":"SimpleTransaction free 2",
			"isDebit":false,
			"isInclusive":false,
			"isInvisible":false,
			"postingIndex":0,
			"partyNum":0,
			"freepartyNum":null,
			"partyName":null,
			"invoiceNum":0,
			"freeInvoiceNum":null,
			"invoiceDate":"0001-01-01T00:00:00"
			}
		  ]
		}

    
  
 
Create a general ledger simple transaction incl. vat
Example Code in this section
REST_Transaction_simple_incl_vat_create()

External references to methods used in examples
#Code reference - Load.account_id_by_account_code
#Code reference - Load.defaults(manager).defSimpleNumRangeFID
#Code reference - Load.defaults(manager).defSimpleCurrNum
#Code reference - Load.vatposting(vatposting_to)
#Code reference - (int)InternalTypes.TransactionType.Simple

    
        [TestMethod]
        public void REST_Transaction_simple_inc_vat_create()
        {
            state = new ErrorState();
            string vat_code = "UStn";

            decimal amount = 1000m;
            Transaction transaction = Create.transaction_simple_inc_vat(amount, vat_code, manager);
            state.passed = Save.transaction(transaction, manager);
            Assert.AreEqual(true, state.passed, state.message);
        }

        class Create{
        public static Transaction transaction_simple_inc_vat(decimal payment_amount, string vat_code, Manager manager)
        {
            // Create a transaction instance
            Transaction transaction = new Transaction();
            transaction.numRangeFID = Load.defaults(manager).defSimpleNumRangeFID;
            transaction.transactionTypeFID = (int)InternalTypes.TransactionType.Simple;
            transaction.docNum = Load.defaults(manager).defSimpleCurrNum;

            transaction.docType = "XX";
            DateTime date = DateTime.Today;
            transaction.docDate = new DateTime(date.Year, date.Month, date.Day);

            Posting posting1 = new Posting();
            posting1.accountFID = Load.account_id_by_account_code("1020", manager);

            posting1.text = "Test Case Simple Transaction Posting #1";
            posting1.freeCode = "SimpleTransaction free 1";
            posting1.amount = payment_amount;
            posting1.fcAmount = payment_amount;
            posting1.exchangeRate = 1;
            posting1.isDebit = true;
            posting1.isInclusive = false;
            posting1.costCenterFID = -1;

            // Create posting 2 with VAT

            VATPosting_TO vatposting_to = new VATPosting_TO();
            vatposting_to.is_inclusive = true;
            vatposting_to.vat_code = vat_code;
            vatposting_to.payment_amount = payment_amount;
            vatposting_to.payment_fc_amount = vatposting_to.payment_amount;
            vatposting_to.manager = manager;

            Posting posting2 = Load.vatposting(vatposting_to);

            posting2.accountFID = Load.account_id_by_account_code("3200", manager);
            posting2.text = "Test Case Simple Transaction Posting #2";
            posting2.freeCode = "SimpleTransaction free 2";
            posting2.exchangeRate = 1;
            posting2.isDebit = false;
            posting2.isInclusive = false;
            posting2.costCenterFID = -1;

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

            transaction.isConfirmed = true;

            return transaction;
        }
        }
        class Save{
        public static bool transaction(Transaction transaction, Manager manager)
        {
            var currentClient = manager.getCurrentClient();
            var currentFiscalYear = manager.getCurrentFiscalYear();
            ErrorState state = new ErrorState();

            state.passed = false;
            if (transaction != null)
            {
                var serialized = JsonConvert.SerializeObject(transaction);
                var _cont = new StringContent(serialized, Encoding.UTF8, "application/json");

                string request = "clients/{0}/fiscalYears/{1}/transactions";
                var response = manager.httpClient.PostAsync(string.Format(request, currentClient.id, currentFiscalYear.id), _cont).Result;

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    ResponseDetails details = new ResponseDetails(response);
                }
                state.passed = response.IsSuccessStatusCode;
            }
            return state.passed;
        }
   }

    
  
Create payables invoice
    
    UNDER CONSTRUCTION
    
  
Create payables invoice
    
    UNDER CONSTRUCTION
    
  
JSON representation of a simple transaction including vat
    
{
"id":"00000000-0000-0000-0000-000000000000",
"fiscalYearFID":-1,
"userFID":-1,
"transactionTypeFID":1,
"docType":"XX",
"docNum":4,
"docDate":"2020-03-25T00:00:00",
"modifyDate":"0001-01-01T00:00:00",
"isConfirmed":true,
"numRangeFID":571,
"hasDocument":false,
"postings":[
			{
			"id":"00000000-0000-0000-0000-000000000000",
			"transactionFID":"00000000-0000-0000-0000-000000000000",
			"invoiceFID":"00000000-0000-0000-0000-000000000000",
			"accountFID":10,
			"contraAccountFID":-1,
			"vatFID":-1,
			"vatAccountFID":-1,
			"costCenterFID":-1,
			"postingTypeFID":1,
			"amount":1000.0,
			"fcAmount":1000.0,
			"exchangeRate":1.0,
			"vatAmount":0.0,
			"vatFcAmount":0.0,
			"vatPercent":0.0,
			"vatQuote":0.0,
			"text":"Test Case Simple Transaction Posting #1",
			"freeCode":"SimpleTransaction free 1",
			"isDebit":true,"isInclusive":false,
			"isInvisible":false,
			"postingIndex":0,
			"partyNum":0,
			"freepartyNum":null,
			"partyName":null,
			"invoiceNum":0,
			"freeInvoiceNum":null,
			"invoiceDate":"0001-01-01T00:00:00"
			},
			{
			"id":"00000000-0000-0000-0000-000000000000",
			"transactionFID":"00000000-0000-0000-0000-000000000000",
			"invoiceFID":"00000000-0000-0000-0000-000000000000",
			"accountFID":71,
			"contraAccountFID":-1,
			"vatFID":9,
			"vatAccountFID":51,
			"costCenterFID":-1,
			"postingTypeFID":-1,
			"amount":928.5,
			"fcAmount":928.5,
			"exchangeRate":1.0,
			"vatAmount":71.5,
			"vatFcAmount":71.5,
			"vatPercent":7.7000,
			"vatQuote":100.0000,
			"text":"Test Case Simple Transaction Posting #2",
			"freeCode":"SimpleTransaction free 2",
			"isDebit":false,
			"isInclusive":false,
			"isInvisible":false,
			"postingIndex":0,
			"partyNum":0,
			"freepartyNum":null,
			"partyName":null,
			"invoiceNum":0,
			"freeInvoiceNum":null,
			"invoiceDate":"0001-01-01T00:00:00"
			}
		  ]
		}

    
  

Create a general ledger compound transaction
 
Create a general ledger compound transaction incl. vat