Transactions Endpoint

The examples in this section are related to the Transactions Endpoint (see in Swagger).
 
 
Document Structure:
 
DELETE a document linked to a transaction
Delete a document in the DMS and remove link to the transaction.
 
External references to methods used in examples
#Code reference - Create.simple_transaction
#Code reference - POST.transaction
#Code reference - GET.transactions
#Code reference - POST.dms_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 path = 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);

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

                if (transaction != null)
                {
                    state.passed = POST.dms_link_document(path, "transactions", transaction.id, manager);
                    Assert.AreEqual(true, state.passed, state.message);
                }
            }

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

            if (transaction != null)
            {
                state.passed = false;
                state.passed = DELETE.dms_document("transactions", transaction.id, manager);
                Assert.AreEqual(true, state.passed, state.message);

                if (GET.transaction_by_id(transaction.id, manager).hasDocument == false)
                {
                    state.passed = true;
                }
            }
            Assert.AreEqual(true, state.passed, state.message);
        }

        class Delete{
            public static bool dms_document(string area, Guid id, Manager manager)
            {
                string request = $"clients/{manager.getCurrentClient().id}/fiscalYears/{manager.getCurrentFiscalYear().id}/{area}/{id}/document";
                var response = manager.httpClient.DeleteAsync(request).Result;

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

    
  
Delete document
    
    UNDER CONSTRUCTION
    
  
JSON representation of a document to delete
    
    UNDER CONSTRUCTION
    
  
 
Upload and link a document in DMS with a transaction
Upload a document to the DMS and link the document to a transaction.
 
 
Download and store a document from DMS
Download a document linked to a transaction and store the document on the file system.
 
External references to methods used in examples
#Code reference - Create.simple_transaction
#Code reference - POST.transaction
#Code reference - GET.transactions
    
        [TestMethod]
        public void REST_Transaction_document_download_and_store_GET()
            {
                state = new ErrorState { passed = false };
                var transactions = GET.transactions(manager);
                var transaction = transactions.FirstOrDefault(t => t.hasDocument);

                if (transaction == null)
                {
                    string path = 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);

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

                    if (transaction != null)
                    {
                        state.passed = POST.dms_link_document(path, "transactions", transaction.id, manager);
                        Assert.AreEqual(true, state.passed, state.message);
                    }
                }

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

                if (transaction != null)
                {
                    state.passed = GET.dms_document_download_store("transactions", transaction.id, manager);
                    Assert.AreEqual(true, state.passed, state.message);
                }
            }

        class GET{
            public static bool dms_document_download_store(string area, Guid id, Manager manager)
            {
                string request = $"clients/{manager.getCurrentClient().id}/fiscalYears/{manager.getCurrentFiscalYear().id}/{area}/{id}/document";
                var response = manager.httpClient.GetAsync(request).Result;

                if (!response.IsSuccessStatusCode)
                    throw new Exception($"{(int)response.StatusCode} {response.ReasonPhrase}");

                Stream _stream = null;
                try
                {
                    _stream = response.Content.ReadAsStreamAsync().Result;
                }
                catch (SystemException ex)
                {
                    string message = "" + ex;
                }

                var fileName = response.Content.Headers.ContentDisposition.FileName;
                fileName = Path.Combine("C:/temp/", fileName);

                using (Stream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write),
                      contentStream = response.Content.ReadAsStreamAsync().Result)
                {
                    contentStream.CopyToAsync(stream).Wait();
                }
                return response.IsSuccessStatusCode;
            }
      }

    
  
Download document and store in file system
    
    UNDER CONSTRUCTION
    
  
JSON representation of a document to upload
    
{

}

    
  
 
POST a document to DMS as unprocessed transaction
Save a document to the DMS.
 
    
        [TestMethod]
        public void REST_Transaction_unprocesssed_documents_POST()
        {
            ErrorState state = new ErrorState { passed = false };
            string path = "../../data/invoices/QR_QRR_CHF_3003.pdf";

            bool passed = POST.dms_upload_document(path, "transactions", manager);
            Assert.AreEqual(true, passed, state.message);
        }

        class POST{
            public static bool dms_upload_document(string path, string area, Manager manager)
            {
                 var content = new MultipartFormDataContent($"Upload----{path}");
            
                FileStream fs = File.OpenRead(path);
                content.Add(new StreamContent(fs), $"{area}_document", Path.GetFileName(path));

                string request = $"clients/{manager.getCurrentClient().id}/fiscalyears/{manager.getCurrentFiscalYear().id}/{area}/documents";
                var response = manager.httpClient.PostAsync(string.Format(request), content).Result;

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    ResponseDetails details = new ResponseDetails(response);
                }
                return response.IsSuccessStatusCode;
            }
        }
    
  
Upload and save a document to dms
    
    UNDER CONSTRUCTION
    
  
 
GET Pending DMS Documents
Load pending documents. A pending document is a document stored in dms or archive, which has not yet been attached to a transaction.
 
    
        [TestMethod]
        public void REST_Transaction_pending_documents_GET()
        {
            state = new ErrorState { passed = false };
            string path = "../../data/invoices/QR_QRR_CHF_3003.pdf";

            bool passed = POST.dms_upload_document(path, "transactions", manager);
            Assert.AreEqual(true, passed, state.message);

             List<Document> documents = GET.dms_pending_documents("transactions", manager);
            state.passed = false;
            if (documents.Count >= 1) {
                state.passed = true;
            }
            Assert.AreEqual(true, state.passed, state.message);
        }

        class GET{
            public static List<Document> dms_pending_documents(string area, Manager manager)
            {
                List docs = new List();
                string request = $"clients/{manager.getCurrentClient().id}/fiscalyears/{manager.getCurrentFiscalYear().id}/{area}/documents/pending";
                var response = manager.httpClient.GetAsync(request).Result;

                if (response.IsSuccessStatusCode) {
                    var documents = JsonConvert.DeserializeObject>(response.Content.ReadAsStringAsync().Result);

                    foreach (var document in documents) {
                        docs.Add(document);
                    }
                }
                return docs;
            }
        }

    
  
Upload and link a document to a transaction
    
    UNDER CONSTRUCTION
    
  
JSON representation of a document to upload and link to a transaction
    
{

}