Payables/Receivables invoices
In the following you will find some DELETE examples related to invoices.
Example Code
Delete a payable invoice. An invoice can only be deleted if the invoice is not in a payment run or has been paid.
#Code reference - GET.party_by_id
#Code reference - Create.payables_invoice
#Code reference - POST.payables_invoice
#Code reference - GET.payables_invoice_by_freeinvoicenum
[TestMethod]
public void REST_Payables_invoice_DELETE()
{
state = new ErrorState { passed = false };
decimal payment_amount = 5000m;
List invoices = GET.payables_invoices(manager);
Party party = GET.party_by_name("Tamedia AG", manager);
party = GET.party_by_id(party.id, manager);
List postings = new List();
postings.Add(payment_amount);
Invoice_TO invoice_DTO = new Invoice_TO
{
party = party,
manager = manager,
date = DateTime.Today,
posting_amounts = postings,
payment_amount = payment_amount,
free_inv_num = "invoice_1000",
vat_code = "",
text = "",
exchange_rate = 1.0m,
payslip_code = "",
hasDocument = 0,
isDebit = true
};
Invoice invoice = Create.payables_invoice(invoice_DTO);
state.passed = POST.payables_invoice(invoice, manager);
Assert.AreEqual(true, state.passed, state.message);
invoice = GET.payables_invoice_by_freeinvoicenum(invoice_DTO.free_inv_num, manager);
if (invoice != null)
{
state.passed = DELETE.payables_invoice(invoice, manager);
Assert.AreEqual(true, state.passed, state.message);
}
}
class DELETE
{
public static bool payables_invoice(Invoice invoice, Manager manager)
{
var currentClient = manager.getCurrentClient();
var currentFiscalYear = manager.getCurrentFiscalYear();
ErrorState state = new ErrorState { passed = false };
if (invoice != null)
{
string request = "clients/{0}/fiscalYears/{1}/payables/invoices/{2}";
var response = manager.httpClient.DeleteAsync(string.Format(request, currentClient.id, currentFiscalYear.id, invoice.id)).Result;
if (response.StatusCode != HttpStatusCode.OK)
{
ResponseDetails details = new ResponseDetails();
string message = details.responseDetails(response);
}
state.passed = response.IsSuccessStatusCode;
}
return state.passed;
}
}
UNDER CONSTRUCTION
Delete a receivable invoice. An invoice can only be deleted if the invoice is not in a payment run or has been paid.
#Code reference - GET.party_by_id
#Code reference - Create.receivables_invoice
#Code reference - POST.receivables_invoice
#Code reference - GET.receivables_invoices
[TestMethod]
public void REST_Receivables_invoice_DELETE()
{
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_TO invoice_to = new Invoice_TO
{
party = party,
manager = manager,
date = DateTime.Today,
posting_amounts = postings,
payment_amount = payment_amount,
exchange_rate = 1,
text = "New Recivables Invoice",
pay_method = "Method_1",
contra_account = "3200",
invoiceType = Convert.ToBoolean(InvoiceType.INCLUSIVE)
};
Invoice invoice = Create.receivables_invoice(invoice_to);
state.passed = POST.receivables_invoice(invoice, manager);
Assert.AreEqual(true, state.passed, state.message);
List invoices = GET.receivables_invoices(manager);
foreach (Invoice _invoice in invoices)
{
state.passed = DELETE.receivables_invoice(_invoice, manager);
Assert.AreEqual(true, state.passed, state.message);
}
}
class DELETE
{
public static bool receivables_invoice(Invoice invoice, Manager manager)
{
var currentClient = manager.getCurrentClient();
var currentFiscalYear = manager.getCurrentFiscalYear();
ErrorState state = new ErrorState { passed = false };
if (invoice != null)
{
string request = "clients/{0}/fiscalYears/{1}/receivables/invoices/{2}";
var response = manager.httpClient.DeleteAsync(string.Format(request, currentClient.id, currentFiscalYear.id, invoice.id)).Result;
state.passed = response.IsSuccessStatusCode;
}
return state.passed;
}
}
UNDER CONSTRUCTION
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. The method is the same for both areas. The difference is the
area name payables resp. receivables.
This will only remove the document, but not the invoice it has been attached to. The method is the same for both areas. The difference is the
area name payables resp. receivables.
#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_invoice
#Code reference - GET.payables_invoice_by_freeinvoicenum
[TestMethod]
public void REST_Payables_document_DELETE()
{
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.payables_link_document(path, "payables", invoice, 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 = DELETE.dms_document(invoice.id , "payables", 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 DELETE{
public static bool dms_document(Invoice invoice, string area, Manager manager)
{
string request = $"clients/{manager.getCurrentClient().id}/fiscalYears/{manager.getCurrentFiscalYear().id}/{area}/{invoice.id}/document";
var response = manager.httpClient.DeleteAsync(request).Result;
if (response.StatusCode != HttpStatusCode.OK)
{
ResponseDetails details = new ResponseDetails();
}
return response.IsSuccessStatusCode;
}
}
UNDER CONSTRUCTION