Receivables Endpoint
The examples in this section are related to the Receivables Endpoint (see in Swagger).

Document Structure:
Every payables/receivables invoice might hold a document, which is located in a DMS. A document can be delete from an invoice.
This will only remove the document, but not the invoice it has been attached to.
This will only remove the document, but not the invoice it has been attached to.
#Code reference - GET.party_by_id
#Code reference - Create.receivable_invoice
#Code reference - POST.receivable_invoice
#Code reference - POST.dms_link_document
#Code reference - DELETE.receivable_invoice
#Code reference - GET.receivables_invoice_by_freeinvoicenum
[TestMethod]
public void REST_Receivables_document_DELETE()
{
state = new ErrorState { passed = false };
#region create_invoice
state = new ErrorState();
decimal payment_amount = 1000.0m;
Party party = GET.party_by_name("Bucherer AG", manager);
party = GET.party_by_id(party.id, manager);
List postings = new List();
postings.Add(payment_amount);
Invoice_DTO invoice_dto = new Invoice_DTO();
invoice_dto.party = party;
invoice_dto.manager = manager;
invoice_dto.payment_amount = payment_amount;
invoice_dto.payment_fc_amount = invoice_dto.payment_amount;
invoice_dto.date = DateTime.Today;
invoice_dto.posting_amounts = postings;
invoice_dto.exchange_rate = 1;
invoice_dto.text = "Recivables Invoice";
invoice_dto.free_inv_num = "REC_2000";
invoice_dto.pay_method = "LSV-CHF";
invoice_dto.contra_account = "3200";
invoice_dto.cost_center_code = "";
invoice_dto.isDebit = true;
Invoice invoice = Create.receivables_invoice(invoice_dto);
state.passed = POST.receivables_invoice(invoice, manager);
Assert.AreEqual(true, state.passed, state.message);
#endregion create_invoice
invoice = GET.receivables_invoice_by_freeinvoicenum(invoice_dto.free_inv_num, manager);
if (invoice != null)
{
string path = "../../data/invoices/QR_QRR_CHF_3003.pdf";
state.passed = POST.dms_link_document(path, "receivables", invoice.id, manager);
}
Assert.AreEqual(true, state.passed, state.message);
invoice = GET.receivables_invoice_by_freeinvoicenum(invoice_dto.free_inv_num, manager);
if (invoice != null)
{
state.passed = false;
state.passed = DELETE.dms_document("receivables", invoice.id, manager);
Assert.AreEqual(true, state.passed, state.message);
state.passed = false;
state.passed = DELETE.receivables_invoice(invoice, manager);
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;
}
}
UNDER CONSTRUCTION
Link a document to an invoice in the DMS. Link document does also perform the upload procedure.
#Code reference - GET.party_by_id
#Code reference - Create.receivable_invoice
#Code reference - POST.receivable_invoice
#Code reference - POST.link_document
#Code reference - DELETE.receivable_invoice
#Code reference - GET.receivables_invoice_by_freeinvoicenum
[TestMethod]
public void REST_Receivables_document_upload_and_link()
{
state = new ErrorState { passed = false };
#region create_invoice
state = new ErrorState();
decimal payment_amount = 1000.0m;
Party party = GET.party_by_name("Bucherer AG", manager);
party = GET.party_by_id(party.id, manager);
List postings = new List();
postings.Add(payment_amount);
Invoice_DTO invoice_dto = new Invoice_DTO();
invoice_dto.party = party;
invoice_dto.manager = manager;
invoice_dto.payment_amount = payment_amount;
invoice_dto.payment_fc_amount = invoice_dto.payment_amount;
invoice_dto.date = DateTime.Today;
invoice_dto.posting_amounts = postings;
invoice_dto.exchange_rate = 1;
invoice_dto.text = "Recivables Invoice";
invoice_dto.free_inv_num = "REC_2000";
invoice_dto.pay_method = "LSV-CHF";
invoice_dto.contra_account = "3200";
invoice_dto.cost_center_code = "";
invoice_dto.isDebit = true;
Invoice invoice = Create.receivables_invoice(invoice_dto);
state.passed = POST.receivables_invoice(invoice, manager);
Assert.AreEqual(true, state.passed, state.message);
#endregion create_invoice
invoice = GET.receivables_invoice_by_freeinvoicenum(invoice_dto.free_inv_num, manager);
if (invoice != null)
{
string path = "../../data/invoices/QR_QRR_CHF_3003.pdf";
state.passed = POST.dms_link_document(path, "receivables", invoice.id, manager);
}
Assert.AreEqual(true, state.passed, state.message);
invoice = GET.receivables_invoice_by_freeinvoicenum(invoice_dto.free_inv_num, manager);
if (invoice != null)
{
state.passed = false;
state.passed = DELETE.dms_document("receivables", invoice.id, manager);
Assert.AreEqual(true, state.passed, state.message);
state.passed = false;
state.passed = DELETE.receivables_invoice(invoice, manager);
Assert.AreEqual(true, state.passed, state.message);
}
}
class POST{
public static bool dms_link_document(string path, string area, Guid id, 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}/{id}/dms_document";
var response = manager.httpClient.PostAsync(string.Format(request), content).Result;
if (response.StatusCode != HttpStatusCode.OK)
{
ResponseDetails details = new ResponseDetails(response);
}
return response.IsSuccessStatusCode;
}
}
UNDER CONSTRUCTION
Submission of a file stream
Download and store a document from DMS on he local file system.
#Code reference - GET.party_by_id
#Code reference - Create.payables_invoice
#Code reference - POST.payables_invoice
#Code reference - POST.link_document
#Code reference - DELETE.payables_document
#Code reference - DELETE.payables_invoice
#Code reference - GET.receivables_invoice_by_freeinvoicenum
[TestMethod]
public void REST_Payables_document_download_GET()
{
state = new ErrorState { passed = false };
decimal payment_amount = 4000.0m;
Party party = GET.party_by_name("Tamedia AG", manager);
party = GET.party_by_id(party.id, manager);
#region create_invoice
List postings = new List();
postings.Add(payment_amount);
Invoice_TO invoice_DTO = new Invoice_TO
{
party = party,
manager = manager,
payment_amount = payment_amount,
free_inv_num = "odyssey_2001",
vat_code = "",
hasDocument = 0,
isDebit = true,
isAuthorized = false,
text = "New Invoice",
date = DateTime.Today,
pay_method = "IBAN-CHF",
posting_amounts = postings
};
Invoice invoice = Create.payables_invoice(invoice_DTO);
state.passed = POST.payables_invoice(invoice, manager);
Assert.AreEqual(true, state.passed, state.message);
#endregion create_invoice
state.passed = false;
invoice = GET.payables_invoice_by_freeinvoicenum(invoice_DTO.free_inv_num, manager);
if (invoice != null)
{
string path = "../../data/invoices/QR_QRR_CHF_3003.pdf";
state.passed = POST.dms_link_document(path, "payables", invoice.id, manager);
}
Assert.AreEqual(true, state.passed, state.message);
state.passed = false;
invoice = GET.payables_invoice_by_freeinvoicenum(invoice_DTO.free_inv_num, manager);
if (invoice != null)
{
state.passed = false;
state.passed = GET.dms_document_download_store("payables", invoice.id, manager);
Assert.AreEqual(true, state.passed, state.message);
}
if (invoice != null)
{
state.passed = false;
state.passed = DELETE.payables_document(invoice, manager);
Assert.AreEqual(true, state.passed, state.message);
state.passed = false;
state.passed = DELETE.payables_invoice(invoice, 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;
}
}
UNDER CONSTRUCTION
UNDER CONSTRUCTION