Payables/Receivables invoices
In the following you will find examples to create invoices.
Example Code
Invoices are a part of our everyday life. Every purchase we make generates an invoice. Whether we go to a grocery shop, a retail outlet,
or even for a medical checkup, we are given an invoice when we pay for the product/service.
or even for a medical checkup, we are given an invoice when we pay for the product/service.
#Code reference - GET.party_by_id
#Code reference - GET.account_by_account_code
#Code reference - InternalTypes
#Code reference - POST.payables_invoice
#Code reference - GET.payables_invoice_by_freeinvoicenum
[TestMethod]
public void REST_Payables_invoice_POST()
{
state = new ErrorState { passed = false };
decimal payment_amount = 4000m;
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,
pay_method = "IBAN-CHF",
free_inv_num = "",
vat_code = "",
hasDocument = 0,
isDebit = true,
text = ""
};
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.freeInvoiceNum, manager);
if (invoice != null) {
state.passed = DELETE.payables_invoice(invoice, manager);
Assert.AreEqual(true, state.passed, state.message);
}
}
class Create
{
public static Invoice payables_invoice(Invoice_TO invoice_to)
{
Invoice invoice = new Invoice();
invoice.text = "New Payables Invoice";
DateTime date = invoice_to.date;
invoice.freeInvoiceNum = invoice_to.free_inv_num.Equals("") ? "Payables." + Convert.ToString(invoice_to.payment_amount) : invoice_to.free_inv_num;
date = invoice_to.date == null ? DateTime.Today : invoice_to.date;
invoice.invoiceDate = new DateTime(date.Year, date.Month, date.Day);
invoice.dueDate = date.AddDays(30);
invoice.totalAmount = invoice_to.payment_amount;
invoice.PayslipCode = invoice_to.payslip_code;
invoice.Remarks = "";
invoice.exchangeRate = 1;
invoice.hasDocument = invoice_to.hasDocument;
invoice.IsAuthorized = invoice_to.isAuthorized;
invoice.partyFID = invoice_to.party.id;
invoice.personRoleFID = (int)InternalTypes.PersonRole.Creditor;
var pay_methods = invoice_to.party.creditor.payMethods;
invoice.payMethodFID = pay_methods.SingleOrDefault(p => p.name.Equals(invoice_to.pay_method)).id;
invoice.payTermFID = invoice_to.party.creditor.payTermFID;
invoice.transaction.docDate = new DateTime(date.Year, date.Month, date.Day);
// Create posting 1
// Invoice paymethod_IBAN and paymethod_IBAN of first posting must
// always be the same
Posting posting1 = new Posting
{
accountFID = invoice_to.party.creditor.payMethods[0].accountFID,
text = invoice_to.text.Equals("") ? "Posting text" : invoice_to.text,
freeCode = "Posting Free 1",
amount = invoice_to.payment_amount, // mandatory
isDebit = !invoice_to.isDebit,
postingTypeFID = (int)InternalTypes.PostingType.Invoice,
isInclusive = false,
costCenterFID = -1
};
invoice.transaction.postings.Add(posting1);
// create posting 2
Posting posting2 = new Posting
{
accountFID = GET.account_by_account_code("3200", invoice_to.manager).id,
amount = invoice_to.posting_amounts[0],
text = invoice_to.text.Equals("") ? "Posting text" : invoice_to.text,
isDebit = invoice_to.isDebit,
isInclusive = invoice_to.isInclusive
};
invoice.transaction.postings.Add(posting2);
invoice.transaction.transactionTypeFID = (int)InternalTypes.TransactionType.Invoice;
return invoice;
}
}
UNDER CONSTRUCTION
POST Request:
{
"id": "00000000-0000-0000-0000-000000000000",
"authorizerFID": -1,
"partyFID": 33,
"payMethodFID": 35,
"payTermFID": 9,
"vatFID": -1,
"personRoleFID": 3,
"invoiceDate": "2022-05-09T00:00:00",
"dueDate": "2022-06-08T00:00:00+02:00",
"modifyDate": "0001-01-01T00:00:00",
"invoiceNum": -1,
"reminderLevel": 0,
"freeInvoiceNum": "RI_2222",
"text": "New Payables Invoice",
"PayslipCode": null,
"totalAmount": 1000.0,
"totalAmountFC": 0.0,
"exchangeRate": 1.0,
"IsAuthorized": false,
"noReminders": false,
"Remarks": "",
"partyNum": 0,
"partyName": null,
"partyShortName": null,
"payTermCode": null,
"accountCode": null,
"currencyCode": null,
"balance": 0.0,
"balanceFC": 0.0,
"barCode": null,
"currentReminderLevel": 0,
"hasDocument": 0,
"currentReminderDate": "0001-01-01T00:00:00",
"paymentPostings": [],
"transaction": {
"id": "00000000-0000-0000-0000-000000000000",
"fiscalYearFID": -1,
"userFID": -1,
"transactionTypeFID": 3,
"docType": null,
"docNum": -1,
"docDate": "2022-05-09T00:00:00",
"modifyDate": "0001-01-01T00:00:00",
"isConfirmed": true,
"numRangeFID": -1,
"hasDocument": false,
"postings": [
{
"id": "00000000-0000-0000-0000-000000000000",
"transactionFID": "00000000-0000-0000-0000-000000000000",
"invoiceFID": "00000000-0000-0000-0000-000000000000",
"accountFID": 46,
"contraAccountFID": -1,
"vatFID": -1,
"vatAccountFID": -1,
"costCenterFID": -1,
"postingTypeFID": 2,
"amount": 1000.0,
"fcAmount": 0.0,
"exchangeRate": 1.0,
"vatAmount": 0.0,
"vatFcAmount": 0.0,
"vatPercent": 0.0,
"vatQuote": 0.0,
"text": "Posting text",
"freeCode": "Posting Free 1",
"isDebit": false,
"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": 1000.0,
"fcAmount": 0.0,
"exchangeRate": 1.0,
"vatAmount": 0.0,
"vatFcAmount": 0.0,
"vatPercent": 0.0,
"vatQuote": 0.0,
"text": "Posting text",
"freeCode": null,
"isDebit": true,
"isInclusive": false,
"isInvisible": false,
"postingIndex": 0,
"partyNum": 0,
"freepartyNum": null,
"partyName": null,
"invoiceNum": 0,
"freeInvoiceNum": null,
"invoiceDate": "0001-01-01T00:00:00"
}
]
}
}
Invoices are a part of our everyday life. Every purchase we make generates an invoice. Whether we go to a grocery shop, a retail outlet,
or even for a medical checkup, we are given an invoice when we pay for the product/service.
or even for a medical checkup, we are given an invoice when we pay for the product/service.
#Code reference - GET.party_by_id
#Code reference - GET.account_by_account_code
#Code reference - InternalTypes
#Code reference - POST.receivable_invoice
#Code reference - GET.receivable_invoice_by_freeinvoicenum
#Code reference - DELETE.receivables_invoice
[TestMethod]
public void REST_Receivables_invoice_POST()
{
state = new ErrorState { passed = false };
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",
free_inv_num = "receivable_1000",
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);
invoice = GET.receivables_invoice_by_freeinvoicenum(invoice_to.free_inv_num, manager);
if (invoice != null)
{
state.passed = DELETE.receivables_invoice(invoice, manager);
Assert.AreEqual(true, state.passed, state.message);
}
}
class Create
{
public static Invoice receivables_invoice(Invoice_TO invoice_to)
{
Invoice invoice = new Invoice();
invoice.text = invoice_to.text;
invoice.freeInvoiceNum = invoice_to.free_inv_num;
DateTime date = new DateTime();
date = invoice_to.date == null ? DateTime.Today : invoice_to.date;
invoice.invoiceDate = new DateTime(date.Year, date.Month, date.Day);
invoice.dueDate = date.AddDays(30);
invoice.totalAmount = invoice_to.payment_amount;
invoice.partyFID = invoice_to.party.id;
invoice.personRoleFID = (int)InternalTypes.PersonRole.Debtor;
IList pay_methods = invoice_to.party.debtor.payMethods;
invoice.payMethodFID = pay_methods.SingleOrDefault(m => m.name.Equals(invoice_to.pay_method)).id;
invoice.payTermFID = invoice_to.party.debtor.payTermFID;
invoice.transaction.docDate = new DateTime(date.Year, date.Month, date.Day);
// Create first posting
// Invoice paymentod and paymethod_IBAN of first posting must always be the same
Posting posting1 = new Posting
{
accountFID = pay_methods.SingleOrDefault(m => m.name.Equals(invoice_to.pay_method)).accountFID,
text =invoice_to.text.Equals("") ? "Posting text" : invoice_to.text,
freeCode = "Posting Free 1"
};
if (invoice_to.payment_amount != invoice_to.payment_fc_amount)
{
decimal key_currency_amount = invoice_to.exchange_rate * invoice_to.payment_fc_amount;
posting1.amount = key_currency_amount; // mandatory
posting1.fcAmount = invoice_to.payment_fc_amount; // mandatory
posting1.exchangeRate = invoice_to.exchange_rate;
}
else
{
posting1.amount = invoice_to.posting_amounts[0]; // mandatory
posting1.fcAmount = invoice_to.posting_amounts[0]; // mandatory
posting1.exchangeRate = invoice_to.exchange_rate;
}
posting1.isDebit = invoice_to.isDebit;
posting1.postingTypeFID = (int)InternalTypes.PostingType.Invoice;
posting1.isInclusive = invoice_to.invoiceType;
posting1.costCenterFID = -1;
invoice.transaction.postings.Add(posting1);
/* create posting without VAT */
foreach (decimal amount in invoice_to.posting_amounts)
{
Posting posting = new Posting();
posting.accountFID = GET.account_by_account_code(invoice_to.contra_account, invoice_to.manager).id;
posting.text = invoice_to.text.Equals("") ? "Posting text" : invoice_to.text;
posting.isDebit = !invoice_to.isDebit;
posting.amount = invoice_to.payment_amount;
posting.fcAmount = invoice_to.payment_fc_amount;
posting.exchangeRate = invoice_to.exchange_rate;
posting.postingTypeFID = (int)InternalTypes.PostingType.Invoice;
posting.isInclusive = invoice_to.invoiceType;
posting.costCenterFID = !invoice_to.cost_center_code.Equals("") ? GET.costcenter_by_code(invoice_to.cost_center_code, invoice_to.manager).id : -1;
invoice.transaction.postings.Add(posting);
}
invoice.transaction.transactionTypeFID = (int)InternalTypes.TransactionType.Invoice;
return invoice;
}
}
UNDER CONSTRUCTION
POST Request:
{
"id": "00000000-0000-0000-0000-000000000000",
"authorizerFID": -1,
"partyFID": 1,
"payMethodFID": 1,
"payTermFID": 9,
"vatFID": -1,
"personRoleFID": 2,
"invoiceDate": "2022-05-09T00:00:00",
"dueDate": "2022-06-08T00:00:00+02:00",
"modifyDate": "0001-01-01T00:00:00",
"invoiceNum": -1,
"reminderLevel": 0,
"freeInvoiceNum": null,
"text": "New Recivables Invoice",
"PayslipCode": null,
"totalAmount": 1000.0,
"totalAmountFC": 0.0,
"exchangeRate": 0.0,
"IsAuthorized": true,
"noReminders": false,
"Remarks": null,
"partyNum": 0,
"partyName": null,
"partyShortName": null,
"payTermCode": null,
"accountCode": null,
"currencyCode": null,
"balance": 0.0,
"balanceFC": 0.0,
"barCode": null,
"currentReminderLevel": 0,
"hasDocument": 0,
"currentReminderDate": "0001-01-01T00:00:00",
"paymentPostings": [],
"transaction": {
"id": "00000000-0000-0000-0000-000000000000",
"fiscalYearFID": -1,
"userFID": -1,
"transactionTypeFID": 3,
"docType": null,
"docNum": -1,
"docDate": "2022-05-09T00:00:00",
"modifyDate": "0001-01-01T00:00:00",
"isConfirmed": true,
"numRangeFID": -1,
"hasDocument": false,
"postings": [
{
"id": "00000000-0000-0000-0000-000000000000",
"transactionFID": "00000000-0000-0000-0000-000000000000",
"invoiceFID": "00000000-0000-0000-0000-000000000000",
"accountFID": 20,
"contraAccountFID": -1,
"vatFID": -1,
"vatAccountFID": -1,
"costCenterFID": -1,
"postingTypeFID": 2,
"amount": 1000.0,
"fcAmount": 1000.0,
"exchangeRate": 1.0,
"vatAmount": 0.0,
"vatFcAmount": 0.0,
"vatPercent": 0.0,
"vatQuote": 0.0,
"text": "New Recivables Invoice",
"freeCode": "Posting 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": 2,
"amount": 1000.0,
"fcAmount": 1000.0,
"exchangeRate": 1.0,
"vatAmount": 0.0,
"vatFcAmount": 0.0,
"vatPercent": 0.0,
"vatQuote": 0.0,
"text": "New Recivables Invoice",
"freeCode": null,
"isDebit": false,
"isInclusive": false,
"isInvisible": false,
"postingIndex": 0,
"partyNum": 0,
"freepartyNum": null,
"partyName": null,
"invoiceNum": 0,
"freeInvoiceNum": null,
"invoiceDate": "0001-01-01T00:00:00"
}
]
}
}
Credit posting and debit posting is the recording of transactions in a bank account. Each credit is an addition to the account, while a debit is a
reduction from the account.
reduction from the account.
#Code reference - InternalTypes
class Create
{
public static Posting create_posting(Posting_TO posting_to)
{
Posting posting = new Posting();
posting.accountFID = GET.account_by_account_code(posting_to.accountcode, posting_to.manager).id;
posting.text = posting_to.postingtext;
posting.isDebit = posting_to.isDebit; // true or false
posting.amount = posting_to.paymentAmountPosting;
posting.postingTypeFID = (int)InternalTypes.PostingType.Invoice;
posting.isInclusive = posting_to.isInclusive;
posting.costCenterFID = -1;
return posting;
}
}
public class Posting_TO
{
public Invoice_TO invoice_to { get; set; }
public Manager manager { get; set; }
public string accountcode { get; set; }
public decimal paymentAmountPosting { get; set; }
public string postingtext { get; set; }
public bool isInclusive { get; set; }
public bool isDebit { get; set; }
}
UNDER CONSTRUCTION
VAT Posting is a convenience function. Topal provides a REST Endpoint to calculate VAT amounts on the server. The amounts returned
can then be applied to a respective invoice.
can then be applied to a respective invoice.
#Code reference - InternalTypes
class Create
{
public static Posting vat_posting(VATPosting_TO vatposting_to)
{
Posting calculatedVatPosting = GET.vatposting(vatposting_to);
Posting posting = calculatedVatPosting;
posting.accountFID = GET.account_by_account_code(vatposting_to.accountcode, vatposting_to.manager).id;
posting.text = vatposting_to.postingtext;
posting.isDebit = vatposting_to.isDebit;
posting.postingTypeFID = (int)InternalTypes.PostingType.Invoice;
posting.isInclusive = vatposting_to.isInclusive;
posting.costCenterFID = -1;
return posting;
}
}
public class VATPosting_TO
{
public Manager manager { get; set; }
public string vatcode { get; set; }
public decimal vatRate { get; set; }
public string accountcode { get; set; }
public decimal paymentAmount { get; set; }
public decimal paymentFCAmount { get; set; }
public string postingtext { get; set; }
public bool isInclusive { get; set; }
public bool isDebit { get; set; }
}
UNDER CONSTRUCTION