summaryrefslogtreecommitdiff
path: root/src/administration.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/administration.cpp')
-rw-r--r--src/administration.cpp188
1 files changed, 104 insertions, 84 deletions
diff --git a/src/administration.cpp b/src/administration.cpp
index b938271..e6c9821 100644
--- a/src/administration.cpp
+++ b/src/administration.cpp
@@ -15,13 +15,13 @@ static s32 administration_create_id()
return g_administration.next_id;
}
-#define ADD_BRACKET(_country, _rate, _description)\
+#define ADD_BRACKET(_country, _rate, _code)\
{\
country_tax_bracket* tb = (country_tax_bracket*)malloc(sizeof(country_tax_bracket));\
snprintf(tb->id, sizeof(tb->id), "T/%d", administration_create_id());\
memcpy(tb->country_code, _country, sizeof(tb->country_code));\
tb->rate = _rate;\
- memcpy(tb->description, _description, sizeof(tb->description));\
+ memcpy(tb->category_code, _code, sizeof(tb->category_code));\
list_append(&g_administration.tax_brackets, tb);\
g_administration.next_id++;\
}
@@ -106,140 +106,148 @@ static void administation_get_random_billing_items(invoice* inv)
static void administration_create_default_tax_brackets()
{
// General brackets shared between countries.
- ADD_BRACKET("00", 0.0f, "tax.reverse_charge");
- ADD_BRACKET("00", 0.0f, "tax.exempt");
+ // Category options: https://docs.peppol.eu/poacc/billing/3.0/codelist/UNCL5305/
+
+ // TODO unimplemented category L, M, B
+
+ ADD_BRACKET("00", 0.0f, "AE"); // Vat Reverse Charge
+ ADD_BRACKET("00", 0.0f, "E"); // Exempt from Tax
+ ADD_BRACKET("00", 0.0f, "Z"); // Zero rated goods
+ ADD_BRACKET("00", 0.0f, "G"); // Free export item, VAT not charged
+ ADD_BRACKET("00", 0.0f, "O"); // Services outside scope of tax
+ ADD_BRACKET("00", 0.0f, "K"); // VAT exempt for EEA intra-community supply of goods and services
// Austria
- ADD_BRACKET("AT", 20.0f, "tax.standard");
- ADD_BRACKET("AT", 10.0f, "tax.reduced");
- ADD_BRACKET("AT", 13.0f, "tax.reduced");
+ ADD_BRACKET("AT", 20.0f, "S");
+ ADD_BRACKET("AT", 10.0f, "S");
+ ADD_BRACKET("AT", 13.0f, "S");
// Belgium
- ADD_BRACKET("BE", 21.0f, "tax.standard");
- ADD_BRACKET("BE", 6.0f, "tax.reduced");
- ADD_BRACKET("BE", 12.0f, "tax.reduced");
+ ADD_BRACKET("BE", 21.0f, "S");
+ ADD_BRACKET("BE", 6.0f, "S");
+ ADD_BRACKET("BE", 12.0f, "S");
// Bulgaria
- ADD_BRACKET("BG", 20.0f, "tax.standard");
- ADD_BRACKET("BG", 9.0f, "tax.reduced");
+ ADD_BRACKET("BG", 20.0f, "S");
+ ADD_BRACKET("BG", 9.0f, "S");
// Cyprus
- ADD_BRACKET("CY", 19.0f, "tax.standard");
- ADD_BRACKET("CY", 5.0f, "tax.reduced");
- ADD_BRACKET("CY", 9.0f, "tax.reduced");
+ ADD_BRACKET("CY", 19.0f, "S");
+ ADD_BRACKET("CY", 5.0f, "S");
+ ADD_BRACKET("CY", 9.0f, "S");
// Czechia
- ADD_BRACKET("CZ", 21.0f, "tax.standard");
- ADD_BRACKET("CZ", 12.0f, "tax.reduced");
+ ADD_BRACKET("CZ", 21.0f, "S");
+ ADD_BRACKET("CZ", 12.0f, "S");
// Croatia
- ADD_BRACKET("HR", 25.0f, "tax.standard");
- ADD_BRACKET("HR", 5.0f, "tax.reduced");
- ADD_BRACKET("HR", 13.0f, "tax.reduced");
+ ADD_BRACKET("HR", 25.0f, "S");
+ ADD_BRACKET("HR", 5.0f, "S");
+ ADD_BRACKET("HR", 13.0f, "S");
// Denmark
- ADD_BRACKET("DK", 25.0f, "tax.standard");
+ ADD_BRACKET("DK", 25.0f, "S");
// Estonia
- ADD_BRACKET("EE", 22.0f, "tax.standard");
- ADD_BRACKET("EE", 9.0f, "tax.reduced");
+ ADD_BRACKET("EE", 22.0f, "S");
+ ADD_BRACKET("EE", 9.0f, "S");
// Finland
- ADD_BRACKET("FI", 25.5f, "tax.standard");
- ADD_BRACKET("FI", 10.0f, "tax.reduced");
- ADD_BRACKET("FI", 14.0f, "tax.reduced");
+ ADD_BRACKET("FI", 25.5f, "S");
+ ADD_BRACKET("FI", 10.0f, "S");
+ ADD_BRACKET("FI", 14.0f, "S");
// France
- ADD_BRACKET("FR", 20.0f, "tax.standard");
- ADD_BRACKET("FR", 5.5f, "tax.reduced");
- ADD_BRACKET("FR", 10.0f, "tax.reduced");
- ADD_BRACKET("FR", 2.1f, "tax.superReduced");
+ ADD_BRACKET("FR", 20.0f, "S");
+ ADD_BRACKET("FR", 5.5f, "S");
+ ADD_BRACKET("FR", 10.0f, "S");
+ ADD_BRACKET("FR", 2.1f, "S");
// Germany
- ADD_BRACKET("DE", 19.0f, "tax.standard");
- ADD_BRACKET("DE", 7.0f, "tax.reduced");
+ ADD_BRACKET("DE", 19.0f, "S");
+ ADD_BRACKET("DE", 7.0f, "S");
// Greece
- ADD_BRACKET("GR", 24.0f, "tax.standard");
- ADD_BRACKET("GR", 6.0f, "tax.reduced");
- ADD_BRACKET("GR", 13.0f, "tax.reduced");
+ ADD_BRACKET("GR", 24.0f, "S");
+ ADD_BRACKET("GR", 6.0f, "S");
+ ADD_BRACKET("GR", 13.0f, "S");
// Hungary
- ADD_BRACKET("HU", 27.0f, "tax.standard");
- ADD_BRACKET("HU", 5.0f, "tax.reduced");
- ADD_BRACKET("HU", 18.0f, "tax.reduced");
+ ADD_BRACKET("HU", 27.0f, "S");
+ ADD_BRACKET("HU", 5.0f, "S");
+ ADD_BRACKET("HU", 18.0f, "S");
// Ireland
- ADD_BRACKET("IE", 23.0f, "tax.standard");
- ADD_BRACKET("IE", 9.0f, "tax.reduced");
- ADD_BRACKET("IE", 13.5f, "tax.reduced");
- ADD_BRACKET("IE", 4.8f, "tax.superReduced");
+ ADD_BRACKET("IE", 23.0f, "S");
+ ADD_BRACKET("IE", 9.0f, "S");
+ ADD_BRACKET("IE", 13.5f, "S");
+ ADD_BRACKET("IE", 4.8f, "S");
// Italy
- ADD_BRACKET("IT", 22.0f, "tax.standard");
- ADD_BRACKET("IT", 5.0f, "tax.reduced");
- ADD_BRACKET("IT", 10.0f, "tax.reduced");
- ADD_BRACKET("IT", 4.0f, "tax.superReduced");
+ ADD_BRACKET("IT", 22.0f, "S");
+ ADD_BRACKET("IT", 5.0f, "S");
+ ADD_BRACKET("IT", 10.0f, "S");
+ ADD_BRACKET("IT", 4.0f, "S");
// Latvia
- ADD_BRACKET("LV", 21.0f, "tax.standard");
- ADD_BRACKET("LV", 5.0f, "tax.reduced");
- ADD_BRACKET("LV", 12.0f, "tax.reduced");
+ ADD_BRACKET("LV", 21.0f, "S");
+ ADD_BRACKET("LV", 5.0f, "S");
+ ADD_BRACKET("LV", 12.0f, "S");
// Lithuania
- ADD_BRACKET("LT", 21.0f, "tax.standard");
- ADD_BRACKET("LT", 5.0f, "tax.reduced");
- ADD_BRACKET("LT", 9.0f, "tax.reduced");
+ ADD_BRACKET("LT", 21.0f, "S");
+ ADD_BRACKET("LT", 5.0f, "S");
+ ADD_BRACKET("LT", 9.0f, "S");
// Luxembourg
- ADD_BRACKET("LU", 17.0f, "tax.standard");
- ADD_BRACKET("LU", 8.0f, "tax.reduced");
- ADD_BRACKET("LU", 14.0f, "tax.reduced");
- ADD_BRACKET("LU", 3.0f, "tax.superReduced");
+ ADD_BRACKET("LU", 17.0f, "S");
+ ADD_BRACKET("LU", 8.0f, "S");
+ ADD_BRACKET("LU", 14.0f, "S");
+ ADD_BRACKET("LU", 3.0f, "S");
// Malta
- ADD_BRACKET("MT", 18.0f, "tax.standard");
- ADD_BRACKET("MT", 5.0f, "tax.reduced");
- ADD_BRACKET("MT", 7.0f, "tax.reduced");
+ ADD_BRACKET("MT", 18.0f, "S");
+ ADD_BRACKET("MT", 5.0f, "S");
+ ADD_BRACKET("MT", 7.0f, "S");
// Netherlands
- ADD_BRACKET("NL", 21.0f, "tax.standard");
- ADD_BRACKET("NL", 9.0f, "tax.reduced");
+ ADD_BRACKET("NL", 21.0f, "S");
+ ADD_BRACKET("NL", 9.0f, "S");
// Poland
- ADD_BRACKET("PL", 23.0f, "tax.standard");
- ADD_BRACKET("PL", 5.0f, "tax.reduced");
- ADD_BRACKET("PL", 8.0f, "tax.reduced");
+ ADD_BRACKET("PL", 23.0f, "S");
+ ADD_BRACKET("PL", 5.0f, "S");
+ ADD_BRACKET("PL", 8.0f, "S");
// Portugal
- ADD_BRACKET("PT", 23.0f, "tax.standard");
- ADD_BRACKET("PT", 6.0f, "tax.reduced");
- ADD_BRACKET("PT", 13.0f, "tax.reduced");
+ ADD_BRACKET("PT", 23.0f, "S");
+ ADD_BRACKET("PT", 6.0f, "S");
+ ADD_BRACKET("PT", 13.0f, "S");
// Romania
- ADD_BRACKET("RO", 19.0f, "tax.standard");
- ADD_BRACKET("RO", 5.0f, "tax.reduced");
- ADD_BRACKET("RO", 9.0f, "tax.reduced");
+ ADD_BRACKET("RO", 19.0f, "S");
+ ADD_BRACKET("RO", 5.0f, "S");
+ ADD_BRACKET("RO", 9.0f, "S");
// Slovakia
- ADD_BRACKET("SK", 23.0f, "tax.standard");
- ADD_BRACKET("SK", 5.0f, "tax.reduced");
- ADD_BRACKET("SK", 19.0f, "tax.reduced");
+ ADD_BRACKET("SK", 23.0f, "S");
+ ADD_BRACKET("SK", 5.0f, "S");
+ ADD_BRACKET("SK", 19.0f, "S");
// Slovenia
- ADD_BRACKET("SI", 22.0f, "tax.standard");
- ADD_BRACKET("SI", 5.0f, "tax.reduced");
- ADD_BRACKET("SI", 9.5f, "tax.reduced");
+ ADD_BRACKET("SI", 22.0f, "S");
+ ADD_BRACKET("SI", 5.0f, "S");
+ ADD_BRACKET("SI", 9.5f, "S");
// Spain
- ADD_BRACKET("ES", 21.0f, "tax.standard");
- ADD_BRACKET("ES", 10.0f, "tax.reduced");
- ADD_BRACKET("ES", 4.0f, "tax.superReduced");
+ ADD_BRACKET("ES", 21.0f, "S");
+ ADD_BRACKET("ES", 10.0f, "S");
+ ADD_BRACKET("ES", 4.0f, "S");
// Sweden
- ADD_BRACKET("SE", 25.0f, "tax.standard");
- ADD_BRACKET("SE", 6.0f, "tax.reduced");
- ADD_BRACKET("SE", 12.0f, "tax.reduced");
+ ADD_BRACKET("SE", 25.0f, "S");
+ ADD_BRACKET("SE", 6.0f, "S");
+ ADD_BRACKET("SE", 12.0f, "S");
list_attributes_comparator(&g_administration.tax_brackets, compare_tax_countries);
list_sort(&g_administration.tax_brackets, -1);
@@ -769,6 +777,12 @@ static bool administration_get_tax_bracket_by_id(country_tax_bracket* buffer, ch
return false;
}
+// TODO refactor
+bool administration_tax_bracket_get_by_id(char* id, country_tax_bracket* buffer)
+{
+ return administration_get_tax_bracket_by_id(buffer, id);
+}
+
u32 administration_tax_bracket_count()
{
return list_size(&g_administration.tax_brackets);
@@ -982,6 +996,7 @@ static void administration_recalculate_invoice_totals(invoice* invoice)
invoice->tax = 0.0f;
invoice->total = 0.0f;
invoice->net = 0.0f;
+ invoice->allowance = 0.0f;
list_iterator_start(&invoice->billing_items);
while (list_iterator_hasnext(&invoice->billing_items)) {
@@ -990,6 +1005,7 @@ static void administration_recalculate_invoice_totals(invoice* invoice)
invoice->tax += c->tax;
invoice->total += c->total;
invoice->net += c->net;
+ invoice->allowance += c->allowance;
}
list_iterator_stop(&invoice->billing_items);
}
@@ -1220,6 +1236,7 @@ bool administration_invoice_get_subtotal_for_tax_bracket(invoice* invoice, count
buffer->tax = 0.0f;
buffer->total = 0.0f;
buffer->net = 0.0f;
+ buffer->allowance = 0.0f;
list_iterator_start(&invoice->billing_items);
while (list_iterator_hasnext(&invoice->billing_items)) {
@@ -1231,6 +1248,7 @@ bool administration_invoice_get_subtotal_for_tax_bracket(invoice* invoice, count
buffer->tax += c->tax;
buffer->total += c->total;
buffer->net += c->net;
+ buffer->allowance += c->allowance;
}
}
list_iterator_stop(&invoice->billing_items);
@@ -1337,11 +1355,13 @@ static void administration_recalculate_billing_item_totals(billing_item* item)
{
if (item->discount_is_percentage)
{
- item->net -= item->net * (item->discount / 100.0f);
+ item->allowance = item->net * (item->discount / 100.0f);
+ item->net -= item->allowance;
}
else
{
- item->net -= item->discount;
+ item->allowance = item->discount;
+ item->net -= item->allowance;
}
}