From 7a29dfbc37f2440b7e5461e905651b25615d2d02 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Sat, 9 Aug 2025 17:40:03 +0200 Subject: editing and adding of tax brackets and cost centers --- src/administration.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 9 deletions(-) (limited to 'src/administration.cpp') diff --git a/src/administration.cpp b/src/administration.cpp index e41942e..8a0b104 100644 --- a/src/administration.cpp +++ b/src/administration.cpp @@ -9,17 +9,27 @@ administration g_administration; -static void administration_create_default_tax_brackets() +#define ADD_BRACKET(_country, _rate, _description)\ +{\ + 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));\ + list_append(&g_administration.tax_brackets, tb);\ + g_administration.next_id++;\ +} + +static int compare_tax_countries(const void *a, const void *b) { - #define ADD_BRACKET(_country, _rate, _description)\ - {\ - country_tax_bracket* tb = (country_tax_bracket*)malloc(sizeof(country_tax_bracket));\ - memcpy(tb->country_code, _country, sizeof(tb->country_code));\ - tb->rate = _rate;\ - memcpy(tb->description, _description, sizeof(tb->description));\ - list_append(&g_administration.tax_brackets, tb);\ - } + country_tax_bracket *objA = (country_tax_bracket *)a; + country_tax_bracket *objB = (country_tax_bracket *)b; + return strcmp(objA->country_code, objB->country_code); +} + +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"); @@ -155,6 +165,9 @@ static void administration_create_default_tax_brackets() ADD_BRACKET("SE", 25.0f, "tax.standard"); ADD_BRACKET("SE", 6.0f, "tax.reduced"); ADD_BRACKET("SE", 12.0f, "tax.reduced"); + + list_attributes_comparator(&g_administration.tax_brackets, compare_tax_countries); + list_sort(&g_administration.tax_brackets, -1); } static void administration_create_default_cost_centers() @@ -400,6 +413,14 @@ u32 administration_get_tax_bracket_count() return list_size(&g_administration.tax_brackets); } +bool administration_add_tax_bracket(country_tax_bracket data) +{ + ADD_BRACKET(data.country_code, data.rate, ""); + list_attributes_comparator(&g_administration.tax_brackets, compare_tax_countries); + list_sort(&g_administration.tax_brackets, -1); + return true; +} + u32 administration_get_tax_brackets(country_tax_bracket* buffer) { assert(buffer); @@ -416,6 +437,25 @@ u32 administration_get_tax_brackets(country_tax_bracket* buffer) return write_cursor; } +bool administration_update_tax_bracket(country_tax_bracket data) +{ + list_iterator_start(&g_administration.tax_brackets); + while (list_iterator_hasnext(&g_administration.tax_brackets)) { + country_tax_bracket* c = (country_tax_bracket *)list_iterator_next(&g_administration.tax_brackets); + + if (strcmp(c->id, data.id) == 0) { + memcpy(c, &data, sizeof(data)); + list_iterator_stop(&g_administration.tax_brackets); + return true; + } + } + list_iterator_stop(&g_administration.tax_brackets); + + return false; +} + + + u32 administration_get_cost_center_count() { return list_size(&g_administration.cost_centers); -- cgit v1.2.3-70-g09d2