diff options
| author | Aldrik Ramaekers <aldrikboy@gmail.com> | 2025-10-05 20:28:18 +0200 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrikboy@gmail.com> | 2025-10-05 20:28:18 +0200 |
| commit | 1c53bd3ac83cc7a985983ac656bc2599276808a4 (patch) | |
| tree | 47b890b696649fcf85462d71058fb66c078bdca0 /src/countries.cpp | |
| parent | 8aa66a6c6c0d8984b7d2668c03bad5a3b29e3a33 (diff) | |
country data, working on tax reports
Diffstat (limited to 'src/countries.cpp')
| -rw-r--r-- | src/countries.cpp | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/src/countries.cpp b/src/countries.cpp new file mode 100644 index 0000000..d4bcae1 --- /dev/null +++ b/src/countries.cpp @@ -0,0 +1,88 @@ +/* +* Copyright (c) 2025 Aldrik Ramaekers <aldrik.ramaekers@gmail.com> +* +* Permission to use, copy, modify, and/or distribute this software for any +* purpose with or without fee is hereby granted, provided that the above +* copyright notice and this permission notice appear in all copies. +* +* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include "strops.hpp" +#include "countries.hpp" + +#include "countries/nl.cpp" + +static country_impl country_map[] = { + _nl_country_impl, + // Add new locales here. +}; +static const u32 country_map_count = sizeof(country_map) / sizeof(country_map[0]); + +s32 country::get_count() +{ + return country_map_count; +} + +char* country::get_code_by_index(s32 index) +{ + return country_map[index].country_code; +} + +static s32 get_index_by_country_code(char* country_code) +{ + for (u32 i = 0; i < country_map_count; i++) + { + if (strops::equals(country_map[i].country_code, country_code)) { + return i; + } + } + return -1; +} + +bool country::is_EU(char* country_code) +{ + s32 index = get_index_by_country_code(country_code); + if (index == -1) return 0; + + return country_map[index].is_EU; +} + +time_t country::get_default_invoice_expire_duration(char* country_code) +{ + s32 index = get_index_by_country_code(country_code); + if (index == -1) return 0; + + return country_map[index].get_default_invoice_expire_duration(); +} + +bool country::tax_is_implemented(char* country_code) +{ + s32 index = get_index_by_country_code(country_code); + if (index == -1) return false; + + return country_map[index].fill_tax_report_with_categories && + country_map[index].get_tax_category_for_billing_item; +} + +void country::fill_tax_report_with_categories(char* country_code, tax_report* report) +{ + s32 index = get_index_by_country_code(country_code); + assert(index != -1); + + country_map[index].fill_tax_report_with_categories(report); +} + +char* country::get_tax_category_for_billing_item(char* country_code, invoice* inv, billing_item* item) +{ + s32 index = get_index_by_country_code(country_code); + assert(index != -1); + + return country_map[index].get_tax_category_for_billing_item(inv, item); +}
\ No newline at end of file |
