Payables Invoices
Topal Financial Accounting Interface provides the possibility to to transfer Invoices from a 3rd. Party Application to Topal.
The following examples give an idea how Invoices need to be prepared in order to be created in Topal.
Example Code
Create a payable invoice.
#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_create()
{
state = new ErrorState();
decimal payment_amount = 4000.0m;
var 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_DTO invoice_DTO = new Invoice_DTO
{
party = party,
manager = manager,
payment_amount = payment_amount,
free_inv_num = "",
vat_code = "",
hasDocument = 0,
isDebit = true,
isAuthorized = false,
text = "New Invoice",
date = DateTime.Today,
posting_amounts = postings
};
Invoice invoice = Create.payables_invoice(invoice_DTO);
state.passed = POST.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;
}
}
class POST
{
public static bool payables_invoice(Invoice invoice, Manager manager)
{
ErrorState state = new ErrorState { passed = false };
if (invoice != null) {
var invoiceContent = JsonConvert.SerializeObject(invoice);
var content = new StringContent(invoiceContent, Encoding.UTF8, "application/json");
string request = "clients/{0}/fiscalYears/{1}/payables/invoices";
var response = manager.httpClient.PostAsync(string.Format(request, manager.getCurrentClient().id, manager.getCurrentFiscalYear().id), content).Result;
if (response.StatusCode != HttpStatusCode.OK)
{
ResponseDetails details = new ResponseDetails(response);
}
state.passed = response.IsSuccessStatusCode;
}
return state.passed;
}
}
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"
}
]
}
}
Create a payables invoice with multi postings.
#Code reference - GET.party_by_id
#Code reference - InternalTypes
#Code reference - POST.payables_invoice
#Code reference - GET.payables_invoice_by_freeinvoicenum
[TestMethod]
public void REST_Payables_invoice_multi_posting_create()
{
state = new ErrorState { passed = false };
decimal paymentAmount = 10000.0m;
string partyname = "Tamedia AG";
Party party = GET.party_by_name(partyname, manager);
party = GET.party_by_id(party.id, manager);
Invoice invoice = Create.payables_invoice_multi_posting(paymentAmount, party, manager);
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 = false;
state.passed = DELETE.payables_invoice(invoice, manager);
Assert.AreEqual(true, state.passed, state.message);
}
}
class Create()
{
public static Invoice payables_invoice_multi_posting(decimal paymentAmount, Party party, Manager manager)
{
DateTime date = DateTime.Today;
Invoice invoice = new Invoice
{
text = "Payables Invoice",
freeInvoiceNum = $"Payables_{Convert.ToString(paymentAmount)}",
invoiceDate = new DateTime(date.Year, date.Month, date.Day),
dueDate = date.AddDays(30),
totalAmount = paymentAmount,
PayslipCode = "",
Remarks = "",
exchangeRate = 1,
partyFID = party.id,
personRoleFID = (int)InternalTypes.PersonRole.Creditor,
payMethodFID = party.creditor.payMethods[0].id,
payTermFID = party.creditor.payTermFID,
IsAuthorized = true,
};
invoice.transaction.docDate = new DateTime(date.Year, date.Month, date.Day);
// Create posting 1
// Invoice paymentod and paymethod_IBAN of first posting must always be the same
Posting posting1 = new Posting
{
accountFID = party.creditor.payMethods[0].accountFID,
text = "Posting #1",
freeCode = "Posting Free1",
amount = paymentAmount, // mandatory
isDebit = false,
postingTypeFID = (int)InternalTypes.PostingType.Invoice,
isInclusive = false,
costCenterFID = -1
};
invoice.transaction.postings.Add(posting1);
Posting posting2 = new Posting
{
accountFID = GET.account_by_account_code("3200", manager).id,
text = "Posting #2",
amount = 3000.0m,
postingTypeFID = (int)InternalTypes.PostingType.Invoice,
isDebit = true,
isInclusive = true,
costCenterFID = -1
};
invoice.transaction.postings.Add(posting2);
Posting posting3 = new Posting
{
accountFID = GET.account_by_account_code("3200", manager).id,
text = "Posting #3",
amount = 7000.0m,
postingTypeFID = (int)InternalTypes.PostingType.Invoice,
isDebit = true,
isInclusive = true,
costCenterFID = -1
};
invoice.transaction.postings.Add(posting3);
invoice.transaction.transactionTypeFID = (int)InternalTypes.TransactionType.Invoice;
return invoice;
}
}
UNDER CONSTRUCTION
UNDER CONSTRUCTION
add JSON here
Create a payables invoice inclusive VAT
#Code reference - GET.party_by_id
#Code reference - InternalTypes
#Code reference - POST.payables_invoice
#Code reference - GET.payables_invoice_by_freeinvoicenum
#Code reference - DELETE.payables_invoice
[TestMethod]
public void REST_Payables_invoice_inc_vat_create()
{
state = new ErrorState { passed = false };
decimal payment_amount = 4000.0m;
string partyname = "Tamedia AG";
Party party = GET.party_by_name(partyname, manager);
party = GET.party_by_id(party.id, manager);
List postings = new List();
postings.Add(payment_amount);
Invoice_DTO invoice_DTO = new Invoice_DTO
{
party = party,
manager = manager,
date = DateTime.Today,
posting_amounts = postings,
payment_amount = payment_amount,
vat_code = "USTn",
free_inv_num = "PI_2704",
contra_account = "3200",
payslip_code = "",
text = "",
invoiceType = Convert.ToBoolean(InvoiceType.INCLUSIVE),
payment_fc_amount = payment_amount
};
Invoice invoice = Create.payables_invoice_vat(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 = false;
state.passed = DELETE.payables_invoice(invoice, manager);
Assert.AreEqual(true, state.passed, state.message);
}
}
class Create {
public static Invoice payables_invoice_vat(Invoice_DTO invoice_to)
{
DateTime date = invoice_to.date;
Invoice invoice = new Invoice
{
text = "New Payables Invoice",
freeInvoiceNum = invoice_to.free_inv_num.Equals("") ? $"Payables_{Convert.ToString(invoice_to.payment_amount)}" : invoice_to.free_inv_num,
invoiceDate = new DateTime(date.Year, date.Month, date.Day),
dueDate = date.AddDays(30),
totalAmount = invoice_to.payment_amount,
PayslipCode = "",
Remarks = "",
exchangeRate = 1,
partyFID = invoice_to.party.id,
personRoleFID = (int)InternalTypes.PersonRole.Creditor,
payMethodFID = invoice_to.party.creditor.payMethods[0].id,
payTermFID = invoice_to.party.creditor.payTermFID
};
invoice.transaction.docDate = new DateTime(date.Year, date.Month, date.Day);
Posting posting1 = new Posting
{
/* Invoice paymentod and paymethod_IBAN of first posting must always be the same */
accountFID = invoice_to.party.creditor.payMethods[0].accountFID,
text = "Payables Invoice Posting #1",
freeCode = "PI_2223",
amount = invoice_to.payment_amount, // mandatory
isDebit = false,
postingTypeFID = (int)InternalTypes.PostingType.Invoice,
isInclusive = false,
costCenterFID = -1
};
invoice.transaction.postings.Add(posting1);
foreach (decimal amount in invoice_to.posting_amounts)
{
VATPosting_DTO vatposting_dto = new VATPosting_DTO
{
is_inclusive = invoice_to.invoiceType,
vat_code = invoice_to.vat_code,
date = invoice_to.date,
amount = amount,
manager = invoice_to.manager,
exchangeRate = 1,
};
vatposting_dto.fc_amount = vatposting_dto.amount;
Posting posting = GET.posting(vatposting_dto);
posting.accountFID = GET.account_by_account_code("6510", invoice_to.manager).id;
posting.text = "Payables Posting #";
posting.isDebit = true;
posting.postingTypeFID = (int)InternalTypes.PostingType.Invoice;
posting.isInclusive = vatposting_dto.is_inclusive;
posting.costCenterFID = -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": 33,
"payMethodFID": 35,
"payTermFID": 9,
"vatFID": -1,
"personRoleFID": 3,
"invoiceDate": "2022-05-12T00:00:00",
"dueDate": "2022-06-11T00:00:00+02:00",
"modifyDate": "0001-01-01T00:00:00",
"invoiceNum": -1,
"reminderLevel": 0,
"freeInvoiceNum": "PI_2704",
"text": "New Payables Invoice",
"PayslipCode": "",
"totalAmount": 4000.0,
"totalAmountFC": 0.0,
"exchangeRate": 1.0,
"IsAuthorized": true,
"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-12T00: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": 4000.0,
"fcAmount": 0.0,
"exchangeRate": 1.0,
"vatAmount": 0.0,
"vatFcAmount": 0.0,
"vatPercent": 0.0,
"vatQuote": 0.0,
"text": "Payables Invoice Posting #1",
"freeCode": "PI_2223",
"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": 155,
"contraAccountFID": -1,
"vatFID": 9,
"vatAccountFID": 51,
"costCenterFID": -1,
"postingTypeFID": 2,
"amount": 3714.02,
"fcAmount": 3714.02,
"exchangeRate": 1.0,
"vatAmount": 285.98,
"vatFcAmount": 285.98,
"vatPercent": 7.7,
"vatQuote": 100.0,
"text": "Payables Posting #",
"freeCode": "",
"isDebit": true,
"isInclusive": true,
"isInvisible": false,
"postingIndex": 0,
"partyNum": -1,
"freepartyNum": "",
"partyName": "",
"invoiceNum": -1,
"freeInvoiceNum": "",
"invoiceDate": "2022-05-12T00:00:00"
}
]
}
}
Create a payables invoice multi posting inclusive VAT.
#Code reference - GET.party_by_id
#Code reference - InternalTypes
#Code reference - POST.payables_invoice
#Code reference - GET.payables_invoice_by_freeinvoicenum
#Code reference - DELETE.payables_invoice
[TestMethod]
public void REST_Payables_invoice_multi_posting_inc_vat_create()
{
state = new ErrorState { passed = false };
decimal payment_amount = 1000.0m;
Party party = GET.party_by_name("Tamedia AG", manager);
party = GET.party_by_id(party.id, manager);
List postings = new List();
postings.Add(200m);
postings.Add(300m);
postings.Add(500m);
Invoice_DTO invoice_DTO = new Invoice_DTO
{
party = party,
manager = manager,
date = DateTime.Today,
posting_amounts = postings,
payment_amount = payment_amount,
vat_code = "UStn",
payslip_code = "",
free_inv_num = "PI_2223",
text = "Invoice incl. VAT",
invoiceType = Convert.ToBoolean(InvoiceType.INCLUSIVE)
};
invoice_DTO.payment_fc_amount = invoice_DTO.payment_amount;
Invoice invoice = Create.payables_invoice_vat(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 = false;
state.passed = DELETE.payables_invoice(invoice, manager);
Assert.AreEqual(true, state.passed, state.message);
}
}
class Create {
public static Invoice payables_invoice_vat(Invoice_DTO invoice_to)
{
DateTime date = invoice_to.date;
Invoice invoice = new Invoice
{
text = "New Payables Invoice",
freeInvoiceNum = invoice_to.free_inv_num.Equals("") ? $"Payables_{Convert.ToString(invoice_to.payment_amount)}" : invoice_to.free_inv_num,
invoiceDate = new DateTime(date.Year, date.Month, date.Day),
dueDate = date.AddDays(30),
totalAmount = invoice_to.payment_amount,
PayslipCode = "",
Remarks = "",
exchangeRate = 1,
partyFID = invoice_to.party.id,
personRoleFID = (int)InternalTypes.PersonRole.Creditor,
payMethodFID = invoice_to.party.creditor.payMethods[0].id,
payTermFID = invoice_to.party.creditor.payTermFID
};
invoice.transaction.docDate = new DateTime(date.Year, date.Month, date.Day);
Posting posting1 = new Posting
{
/* Invoice paymentod and paymethod_IBAN of first posting must always be the same */
accountFID = invoice_to.party.creditor.payMethods[0].accountFID,
text = "Payables Invoice Posting #1",
freeCode = "PI_2223",
amount = invoice_to.payment_amount, // mandatory
isDebit = false,
postingTypeFID = (int)InternalTypes.PostingType.Invoice,
isInclusive = false,
costCenterFID = -1
};
invoice.transaction.postings.Add(posting1);
foreach (decimal amount in invoice_to.posting_amounts)
{
VATPosting_DTO vatposting_dto = new VATPosting_DTO
{
is_inclusive = invoice_to.invoiceType,
vat_code = invoice_to.vat_code,
date = invoice_to.date,
amount = amount,
manager = invoice_to.manager,
exchangeRate = 1,
};
vatposting_dto.fc_amount = vatposting_dto.amount;
Posting posting = GET.posting(vatposting_dto);
posting.accountFID = GET.account_by_account_code("6510", invoice_to.manager).id;
posting.text = "Payables Posting #";
posting.isDebit = true;
posting.postingTypeFID = (int)InternalTypes.PostingType.Invoice;
posting.isInclusive = vatposting_dto.is_inclusive;
posting.costCenterFID = -1;
invoice.transaction.postings.Add(posting);
}
invoice.transaction.transactionTypeFID = (int)InternalTypes.TransactionType.Invoice;
return invoice;
}
}
create GET {
public static Posting posting(VATPosting_DTO vat_posting_to)
{
VAT vat = GET.vat_by_vatcode(vat_posting_to.vat_code, vat_posting_to.manager);
string param = "&amount=" + vat_posting_to.amount + "&fcAmount=" + vat_posting_to.fc_amount + "&exchangeRate=" + vat_posting_to.exchangeRate + "&vatCode=" + vat_posting_to.vat_code + "&isInclusive=" + vat_posting_to.is_inclusive.ToString().ToLower();
string request = string.Format("clients/{0}/fiscalYears/{1}/posting", vat_posting_to.manager.getCurrentClient().id, vat_posting_to.manager.getCurrentFiscalYear().id);
request = request + "?" + param;
var response = vat_posting_to.manager.httpClient.GetAsync(string.Format(request, vat_posting_to.manager.getCurrentClient().id, vat_posting_to.manager.getCurrentFiscalYear().id)).Result;
var posting = JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result);
return posting;
}
}
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-12T00:00:00",
"dueDate": "2022-06-11T00:00:00+02:00",
"modifyDate": "0001-01-01T00:00:00",
"invoiceNum": -1,
"reminderLevel": 0,
"freeInvoiceNum": "PI_2223",
"text": "New Payables Invoice",
"PayslipCode": "",
"totalAmount": 1000.0,
"totalAmountFC": 0.0,
"exchangeRate": 1.0,
"IsAuthorized": true,
"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-12T00: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": "Payables Invoice Posting #1",
"freeCode": "PI_2223",
"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": 155,
"contraAccountFID": -1,
"vatFID": 9,
"vatAccountFID": 51,
"costCenterFID": -1,
"postingTypeFID": 2,
"amount": 185.7,
"fcAmount": 185.7,
"exchangeRate": 1.0,
"vatAmount": 14.3,
"vatFcAmount": 14.3,
"vatPercent": 7.7,
"vatQuote": 100.0,
"text": "Payables Posting #",
"freeCode": "",
"isDebit": true,
"isInclusive": true,
"isInvisible": false,
"postingIndex": 0,
"partyNum": -1,
"freepartyNum": "",
"partyName": "",
"invoiceNum": -1,
"freeInvoiceNum": "",
"invoiceDate": "2022-05-12T00:00:00"
},
{
"id": "00000000-0000-0000-0000-000000000000",
"transactionFID": "00000000-0000-0000-0000-000000000000",
"invoiceFID": "00000000-0000-0000-0000-000000000000",
"accountFID": 155,
"contraAccountFID": -1,
"vatFID": 9,
"vatAccountFID": 51,
"costCenterFID": -1,
"postingTypeFID": 2,
"amount": 278.55,
"fcAmount": 278.55,
"exchangeRate": 1.0,
"vatAmount": 21.45,
"vatFcAmount": 21.45,
"vatPercent": 7.7,
"vatQuote": 100.0,
"text": "Payables Posting #",
"freeCode": "",
"isDebit": true,
"isInclusive": true,
"isInvisible": false,
"postingIndex": 0,
"partyNum": -1,
"freepartyNum": "",
"partyName": "",
"invoiceNum": -1,
"freeInvoiceNum": "",
"invoiceDate": "2022-05-12T00:00:00"
},
{
"id": "00000000-0000-0000-0000-000000000000",
"transactionFID": "00000000-0000-0000-0000-000000000000",
"invoiceFID": "00000000-0000-0000-0000-000000000000",
"accountFID": 155,
"contraAccountFID": -1,
"vatFID": 9,
"vatAccountFID": 51,
"costCenterFID": -1,
"postingTypeFID": 2,
"amount": 464.25,
"fcAmount": 464.25,
"exchangeRate": 1.0,
"vatAmount": 35.75,
"vatFcAmount": 35.75,
"vatPercent": 7.7,
"vatQuote": 100.0,
"text": "Payables Posting #",
"freeCode": "",
"isDebit": true,
"isInclusive": true,
"isInvisible": false,
"postingIndex": 0,
"partyNum": -1,
"freepartyNum": "",
"partyName": "",
"invoiceNum": -1,
"freeInvoiceNum": "",
"invoiceDate": "2022-05-12T00:00:00"
}
]
}
}
Create a payables invoice exclusive VAT.
#Code reference - GET.party_by_id
#Code reference - InternalTypes
#Code reference - POST.payables_invoice
#Code reference - GET.payables_invoice_by_freeinvoicenum
#Code reference - DELETE.payables_invoice
[TestMethod]
public void REST_Payables_invoice_exc_vat_create()
{
state = new ErrorState { passed = false };
decimal payment_amount = 10770.0m;
Party party = GET.party_by_name("Tamedia AG", manager);
party = GET.party_by_id(party.id, manager);
List postings = new List();
postings.Add(10000m);
Invoice_DTO invoice_DTO = new Invoice_DTO
{
party = party,
manager = manager,
date = DateTime.Today,
posting_amounts = postings,
payment_amount = payment_amount,
vat_code = "USTn",
free_inv_num = "PI_2704",
payslip_code = "",
text = "",
invoiceType = Convert.ToBoolean(InvoiceType.EXCLUSIVE)
};
invoice_DTO.payment_fc_amount = invoice_DTO.payment_amount;
Invoice invoice = Create.payables_invoice_vat(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 = false;
state.passed = DELETE.payables_invoice(invoice, manager);
Assert.AreEqual(true, state.passed, state.message);
}
}
class Create {
public static Invoice payables_invoice_vat(Invoice_DTO invoice_to)
{
DateTime date = invoice_to.date;
Invoice invoice = new Invoice
{
text = "New Payables Invoice",
freeInvoiceNum = invoice_to.free_inv_num.Equals("") ? $"Payables_{Convert.ToString(invoice_to.payment_amount)}" : invoice_to.free_inv_num,
invoiceDate = new DateTime(date.Year, date.Month, date.Day),
dueDate = date.AddDays(30),
totalAmount = invoice_to.payment_amount,
PayslipCode = "",
Remarks = "",
exchangeRate = 1,
partyFID = invoice_to.party.id,
personRoleFID = (int)InternalTypes.PersonRole.Creditor,
payMethodFID = invoice_to.party.creditor.payMethods[0].id,
payTermFID = invoice_to.party.creditor.payTermFID
};
invoice.transaction.docDate = new DateTime(date.Year, date.Month, date.Day);
Posting posting1 = new Posting
{
/* Invoice paymentod and paymethod_IBAN of first posting must always be the same */
accountFID = invoice_to.party.creditor.payMethods[0].accountFID,
text = "Payables Invoice Posting #1",
freeCode = "PI_2223",
amount = invoice_to.payment_amount, // mandatory
isDebit = false,
postingTypeFID = (int)InternalTypes.PostingType.Invoice,
isInclusive = false,
costCenterFID = -1
};
invoice.transaction.postings.Add(posting1);
foreach (decimal amount in invoice_to.posting_amounts)
{
VATPosting_DTO vatposting_dto = new VATPosting_DTO
{
is_inclusive = invoice_to.invoiceType,
vat_code = invoice_to.vat_code,
date = invoice_to.date,
amount = amount,
manager = invoice_to.manager,
exchangeRate = 1,
};
vatposting_dto.fc_amount = vatposting_dto.amount;
Posting posting = GET.posting(vatposting_dto);
posting.accountFID = GET.account_by_account_code("6510", invoice_to.manager).id;
posting.text = "Payables Posting #";
posting.isDebit = true;
posting.postingTypeFID = (int)InternalTypes.PostingType.Invoice;
posting.isInclusive = vatposting_dto.is_inclusive;
posting.costCenterFID = -1;
invoice.transaction.postings.Add(posting);
}
invoice.transaction.transactionTypeFID = (int)InternalTypes.TransactionType.Invoice;
return invoice;
}
}
create GET {
public static Posting posting(VATPosting_DTO vat_posting_to)
{
VAT vat = GET.vat_by_vatcode(vat_posting_to.vat_code, vat_posting_to.manager);
string param = "&amount=" + vat_posting_to.amount + "&fcAmount=" + vat_posting_to.fc_amount + "&exchangeRate=" + vat_posting_to.exchangeRate + "&vatCode=" + vat_posting_to.vat_code + "&isInclusive=" + vat_posting_to.is_inclusive.ToString().ToLower();
string request = string.Format("clients/{0}/fiscalYears/{1}/posting", vat_posting_to.manager.getCurrentClient().id, vat_posting_to.manager.getCurrentFiscalYear().id);
request = request + "?" + param;
var response = vat_posting_to.manager.httpClient.GetAsync(string.Format(request, vat_posting_to.manager.getCurrentClient().id, vat_posting_to.manager.getCurrentFiscalYear().id)).Result;
var posting = JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result);
return posting;
}
}
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-12T00:00:00",
"dueDate": "2022-06-11T00:00:00+02:00",
"modifyDate": "0001-01-01T00:00:00",
"invoiceNum": -1,
"reminderLevel": 0,
"freeInvoiceNum": "PI_2704",
"text": "New Payables Invoice",
"PayslipCode": "",
"totalAmount": 10770.0,
"totalAmountFC": 0.0,
"exchangeRate": 1.0,
"IsAuthorized": true,
"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-12T00: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": 10770.0,
"fcAmount": 0.0,
"exchangeRate": 1.0,
"vatAmount": 0.0,
"vatFcAmount": 0.0,
"vatPercent": 0.0,
"vatQuote": 0.0,
"text": "Payables Invoice Posting #1",
"freeCode": "PI_2223",
"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": 155,
"contraAccountFID": -1,
"vatFID": 9,
"vatAccountFID": 51,
"costCenterFID": -1,
"postingTypeFID": 2,
"amount": 10000.0,
"fcAmount": 10000.0,
"exchangeRate": 1.0,
"vatAmount": 770.0,
"vatFcAmount": 770.0,
"vatPercent": 7.7,
"vatQuote": 100.0,
"text": "Payables Posting #",
"freeCode": "",
"isDebit": true,
"isInclusive": false,
"isInvisible": false,
"postingIndex": 0,
"partyNum": -1,
"freepartyNum": "",
"partyName": "",
"invoiceNum": -1,
"freeInvoiceNum": "",
"invoiceDate": "2022-05-12T00:00:00"
}
]
}
}
Create a payables invoice multi posting exclusive VAT.
#Code reference - GET.party_by_id
#Code reference - InternalTypes
#Code reference - POST.payables_invoice
#Code reference - GET.payables_invoice_by_freeinvoicenum
#Code reference - DELETE.payables_invoice
[TestMethod]
public void REST_Payables_invoice_multi_posting_exc_vat_create()
{
state = new ErrorState { passed = false };
decimal payment_amount = 1077.0m;
Party party = GET.party_by_name("Tamedia AG", manager);
party = GET.party_by_id(party.id, manager);
List postings = new List();
postings.Add(200m);
postings.Add(300m);
postings.Add(500m);
Invoice_DTO invoice_DTO = new Invoice_DTO
{
party = party,
manager = manager,
date = DateTime.Today,
posting_amounts = postings,
payment_amount = payment_amount,
vat_code = "UStn",
free_inv_num = "PI_3334",
payslip_code = "",
text = "",
invoiceType = Convert.ToBoolean(InvoiceType.EXCLUSIVE)
};
invoice_DTO.payment_fc_amount = invoice_DTO.payment_amount;
Invoice invoice = Create.payables_invoice_vat(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 = false;
state.passed = DELETE.payables_invoice(invoice, manager);
Assert.AreEqual(true, state.passed, state.message);
}
}
class Create {
public static Invoice payables_invoice_vat(Invoice_DTO invoice_to)
{
DateTime date = invoice_to.date;
Invoice invoice = new Invoice
{
text = "New Payables Invoice",
freeInvoiceNum = invoice_to.free_inv_num.Equals("") ? $"Payables_{Convert.ToString(invoice_to.payment_amount)}" : invoice_to.free_inv_num,
invoiceDate = new DateTime(date.Year, date.Month, date.Day),
dueDate = date.AddDays(30),
totalAmount = invoice_to.payment_amount,
PayslipCode = "",
Remarks = "",
exchangeRate = 1,
partyFID = invoice_to.party.id,
personRoleFID = (int)InternalTypes.PersonRole.Creditor,
payMethodFID = invoice_to.party.creditor.payMethods[0].id,
payTermFID = invoice_to.party.creditor.payTermFID
};
invoice.transaction.docDate = new DateTime(date.Year, date.Month, date.Day);
Posting posting1 = new Posting
{
/* Invoice paymentod and paymethod_IBAN of first posting must always be the same */
accountFID = invoice_to.party.creditor.payMethods[0].accountFID,
text = "Payables Invoice Posting #1",
freeCode = "PI_2223",
amount = invoice_to.payment_amount, // mandatory
isDebit = false,
postingTypeFID = (int)InternalTypes.PostingType.Invoice,
isInclusive = false,
costCenterFID = -1
};
invoice.transaction.postings.Add(posting1);
foreach (decimal amount in invoice_to.posting_amounts)
{
VATPosting_DTO vatposting_dto = new VATPosting_DTO
{
is_inclusive = invoice_to.invoiceType,
vat_code = invoice_to.vat_code,
date = invoice_to.date,
amount = amount,
manager = invoice_to.manager,
exchangeRate = 1,
};
vatposting_dto.fc_amount = vatposting_dto.amount;
Posting posting = GET.posting(vatposting_dto);
posting.accountFID = GET.account_by_account_code("6510", invoice_to.manager).id;
posting.text = "Payables Posting #";
posting.isDebit = true;
posting.postingTypeFID = (int)InternalTypes.PostingType.Invoice;
posting.isInclusive = vatposting_dto.is_inclusive;
posting.costCenterFID = -1;
invoice.transaction.postings.Add(posting);
}
invoice.transaction.transactionTypeFID = (int)InternalTypes.TransactionType.Invoice;
return invoice;
}
}
create GET {
public static Posting posting(VATPosting_DTO vat_posting_to)
{
VAT vat = GET.vat_by_vatcode(vat_posting_to.vat_code, vat_posting_to.manager);
string param = "&amount=" + vat_posting_to.amount + "&fcAmount=" + vat_posting_to.fc_amount + "&exchangeRate=" + vat_posting_to.exchangeRate + "&vatCode=" + vat_posting_to.vat_code + "&isInclusive=" + vat_posting_to.is_inclusive.ToString().ToLower();
string request = string.Format("clients/{0}/fiscalYears/{1}/posting", vat_posting_to.manager.getCurrentClient().id, vat_posting_to.manager.getCurrentFiscalYear().id);
request = request + "?" + param;
var response = vat_posting_to.manager.httpClient.GetAsync(string.Format(request, vat_posting_to.manager.getCurrentClient().id, vat_posting_to.manager.getCurrentFiscalYear().id)).Result;
var posting = JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result);
return posting;
}
}
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-12T00:00:00",
"dueDate": "2022-06-11T00:00:00+02:00",
"modifyDate": "0001-01-01T00:00:00",
"invoiceNum": -1,
"reminderLevel": 0,
"freeInvoiceNum": "PI_3334",
"text": "New Payables Invoice",
"PayslipCode": "",
"totalAmount": 1077.0,
"totalAmountFC": 0.0,
"exchangeRate": 1.0,
"IsAuthorized": true,
"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-12T00: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": 1077.0,
"fcAmount": 0.0,
"exchangeRate": 1.0,
"vatAmount": 0.0,
"vatFcAmount": 0.0,
"vatPercent": 0.0,
"vatQuote": 0.0,
"text": "Payables Invoice Posting #1",
"freeCode": "PI_2223",
"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": 155,
"contraAccountFID": -1,
"vatFID": 9,
"vatAccountFID": 51,
"costCenterFID": -1,
"postingTypeFID": 2,
"amount": 200.0,
"fcAmount": 200.0,
"exchangeRate": 1.0,
"vatAmount": 15.4,
"vatFcAmount": 15.4,
"vatPercent": 7.7,
"vatQuote": 100.0,
"text": "Payables Posting #",
"freeCode": "",
"isDebit": true,
"isInclusive": false,
"isInvisible": false,
"postingIndex": 0,
"partyNum": -1,
"freepartyNum": "",
"partyName": "",
"invoiceNum": -1,
"freeInvoiceNum": "",
"invoiceDate": "2022-05-12T00:00:00"
},
{
"id": "00000000-0000-0000-0000-000000000000",
"transactionFID": "00000000-0000-0000-0000-000000000000",
"invoiceFID": "00000000-0000-0000-0000-000000000000",
"accountFID": 155,
"contraAccountFID": -1,
"vatFID": 9,
"vatAccountFID": 51,
"costCenterFID": -1,
"postingTypeFID": 2,
"amount": 300.0,
"fcAmount": 300.0,
"exchangeRate": 1.0,
"vatAmount": 23.1,
"vatFcAmount": 23.1,
"vatPercent": 7.7,
"vatQuote": 100.0,
"text": "Payables Posting #",
"freeCode": "",
"isDebit": true,
"isInclusive": false,
"isInvisible": false,
"postingIndex": 0,
"partyNum": -1,
"freepartyNum": "",
"partyName": "",
"invoiceNum": -1,
"freeInvoiceNum": "",
"invoiceDate": "2022-05-12T00:00:00"
},
{
"id": "00000000-0000-0000-0000-000000000000",
"transactionFID": "00000000-0000-0000-0000-000000000000",
"invoiceFID": "00000000-0000-0000-0000-000000000000",
"accountFID": 155,
"contraAccountFID": -1,
"vatFID": 9,
"vatAccountFID": 51,
"costCenterFID": -1,
"postingTypeFID": 2,
"amount": 500.0,
"fcAmount": 500.0,
"exchangeRate": 1.0,
"vatAmount": 38.5,
"vatFcAmount": 38.5,
"vatPercent": 7.7,
"vatQuote": 100.0,
"text": "Payables Posting #",
"freeCode": "",
"isDebit": true,
"isInclusive": false,
"isInvisible": false,
"postingIndex": 0,
"partyNum": -1,
"freepartyNum": "",
"partyName": "",
"invoiceNum": -1,
"freeInvoiceNum": "",
"invoiceDate": "2022-05-12T00:00:00"
}
]
}
}