Transaction

In the following you will find some DELETE examples related to transactions.
 
Example Code
 
Delete a transaction
Delete a general ledger transaction.
 
External references to methods used in examples
#Code reference - Create.simple_transaction
#Code reference - POST.transaction
#Code reference - GET.transactions

    
    [TestMethod]
    public void REST_Transactions_simple_DELETE()
    {
        state = new ErrorState { passed = false };
        decimal amount = 3300m;

        Transaction transaction = Create.transaction_simple(amount, manager);
        state.passed = POST.transaction(transaction, manager);
        Assert.AreEqual(true, state.passed, state.message);

        var transactions = GET.transactions(manager);
        Transaction _transaction = transactions.SingleOrDefault(t => t.docType.Equals("A"));

        if (_transaction != null)
        {
            state.passed = DELETE.transaction(_transaction, manager);
            Assert.AreEqual(true, state.passed, state.message);
        }
    }    

    class DELETE
    {
        public static bool transaction(Transaction transaction, Manager manager)
        {
            string request = "clients/{0}/fiscalYears/{1}/transactions/{2}";
            var response = manager.httpClient.DeleteAsync(string.Format(request, manager.getCurrentClient().id, manager.getCurrentFiscalYear().id, transaction.id)).Result;

            if (response.StatusCode != HttpStatusCode.OK)
            {
                ResponseDetails details = new ResponseDetails();
                string message = details.responseDetails(response);
            }
            return response.IsSuccessStatusCode;
        }
    }
    
  
Delete transaction
    
UNDER CONSTRUCTION
    
  
 
Delete a document of a transaction
Every transaction might hold a document, which is located in a DMS. A document can be delete from an transaction.
This will only remove the document, but not the general ledger transaction it has been attached to.
 
External references to methods used in examples
#Code reference - Create.simple_transaction
#Code reference - POST.simple_transaction
#Code reference - GET.transactions
#Code reference - GET.transaction_by_id
#Code reference - POST.link_document
    
    [TestMethod]
    public void REST_Transaction_document_delete()
    {
        state = new ErrorState { passed = false };

        var transactions = GET.transactions(manager);
        var transaction  = transactions.FirstOrDefault(t => t.hasDocument);

        if (transaction == null) {
            string filePath = Helper.get_random_invoice("../../data/invoices/");

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

            transaction = transactions.FirstOrDefault(t => t.hasDocument == false);

            if (transaction != null)
            {
                state.passed = POST.link_document(filePath, "transactions", transaction.id, manager);
            }
        }
            
        transactions = GET.transactions(manager);
        transaction = transactions.FirstOrDefault(t => t.hasDocument);

        if (transaction != null) {
            state.passed = DELETE.document(transaction, manager);
        }
        Assert.AreEqual(true, state.passed, state.message);

        state.passed = false;
        Transaction _transaction = GET.transaction_by_id(transaction.id, manager);
        if (_transaction.hasDocument == false) {
            state.passed = true;
        }

        Assert.AreEqual(true, state.passed, state.message);
    }

    class DELETE
    {
        public static bool document(Transaction transaction, Manager manager)
        {
            var currentClient = manager.getCurrentClient();
            var currentFiscalYear = manager.getCurrentFiscalYear();
            string request = $"clients/{currentClient.id}/fiscalYears/{currentFiscalYear.id}/transactions/{transaction.id}/document";
            var response = manager.httpClient.DeleteAsync(request).Result;

            return response.StatusCode;
        }
    }
    
  
Delete document
    
UNDER CONSTRUCTION