summaryrefslogtreecommitdiff
path: root/src/administration.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/administration.cpp')
-rw-r--r--src/administration.cpp58
1 files changed, 49 insertions, 9 deletions
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);