/* * Copyright (c) 2025 Aldrik Ramaekers * * 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" #include "countries/_unimplemented.cpp" country_impl country_map[] = { _af_country_impl, // Afghanistan _al_country_impl, // Albania _dz_country_impl, // Algeria _ad_country_impl, // Andorra _ao_country_impl, // Angola _ag_country_impl, // Antigua and Barbuda _ar_country_impl, // Argentina _am_country_impl, // Armenia _au_country_impl, // Australia _at_country_impl, // Austria _az_country_impl, // Azerbaijan _bs_country_impl, // Bahamas _bh_country_impl, // Bahrain _bd_country_impl, // Bangladesh _bb_country_impl, // Barbados _by_country_impl, // Belarus _be_country_impl, // Belgium _bz_country_impl, // Belize _bj_country_impl, // Benin _bt_country_impl, // Bhutan _bo_country_impl, // Bolivia _ba_country_impl, // Bosnia and Herzegovina _bw_country_impl, // Botswana _br_country_impl, // Brazil _bn_country_impl, // Brunei _bg_country_impl, // Bulgaria _bf_country_impl, // Burkina Faso _bi_country_impl, // Burundi _cv_country_impl, // Cabo Verde _kh_country_impl, // Cambodia _cm_country_impl, // Cameroon _ca_country_impl, // Canada _cf_country_impl, // Central African Republic _td_country_impl, // Chad _cl_country_impl, // Chile _cn_country_impl, // China _co_country_impl, // Colombia _km_country_impl, // Comoros _cg_country_impl, // Congo _cd_country_impl, // Democratic Republic of the Congo _cr_country_impl, // Costa Rica _ci_country_impl, // Côte d’Ivoire _hr_country_impl, // Croatia _cu_country_impl, // Cuba _cy_country_impl, // Cyprus _cz_country_impl, // Czechia _dk_country_impl, // Denmark _dj_country_impl, // Djibouti _dm_country_impl, // Dominica _do_country_impl, // Dominican Republic _ec_country_impl, // Ecuador _eg_country_impl, // Egypt _sv_country_impl, // El Salvador _gq_country_impl, // Equatorial Guinea _er_country_impl, // Eritrea _ee_country_impl, // Estonia _sz_country_impl, // Eswatini _et_country_impl, // Ethiopia _fj_country_impl, // Fiji _fi_country_impl, // Finland _fr_country_impl, // France _ga_country_impl, // Gabon _gm_country_impl, // Gambia _ge_country_impl, // Georgia _de_country_impl, // Germany _gh_country_impl, // Ghana _gr_country_impl, // Greece _gd_country_impl, // Grenada _gt_country_impl, // Guatemala _gn_country_impl, // Guinea _gw_country_impl, // Guinea-Bissau _gy_country_impl, // Guyana _ht_country_impl, // Haiti _hn_country_impl, // Honduras _hu_country_impl, // Hungary _is_country_impl, // Iceland _in_country_impl, // India _id_country_impl, // Indonesia _ir_country_impl, // Iran _iq_country_impl, // Iraq _ie_country_impl, // Ireland _il_country_impl, // Israel _it_country_impl, // Italy _jm_country_impl, // Jamaica _jp_country_impl, // Japan _jo_country_impl, // Jordan _kz_country_impl, // Kazakhstan _ke_country_impl, // Kenya _ki_country_impl, // Kiribati _kp_country_impl, // North Korea _kr_country_impl, // South Korea _kw_country_impl, // Kuwait _kg_country_impl, // Kyrgyzstan _la_country_impl, // Laos _lv_country_impl, // Latvia _lb_country_impl, // Lebanon _ls_country_impl, // Lesotho _lr_country_impl, // Liberia _ly_country_impl, // Libya _li_country_impl, // Liechtenstein _lt_country_impl, // Lithuania _lu_country_impl, // Luxembourg _mg_country_impl, // Madagascar _mw_country_impl, // Malawi _my_country_impl, // Malaysia _mv_country_impl, // Maldives _ml_country_impl, // Mali _mt_country_impl, // Malta _mh_country_impl, // Marshall Islands _mr_country_impl, // Mauritania _mu_country_impl, // Mauritius _mx_country_impl, // Mexico _fm_country_impl, // Micronesia _md_country_impl, // Moldova _mc_country_impl, // Monaco _mn_country_impl, // Mongolia _me_country_impl, // Montenegro _ma_country_impl, // Morocco _mz_country_impl, // Mozambique _mm_country_impl, // Myanmar _na_country_impl, // Namibia _nr_country_impl, // Nauru _np_country_impl, // Nepal _nl_country_impl, // Netherlands _nz_country_impl, // New Zealand _ni_country_impl, // Nicaragua _ne_country_impl, // Niger _ng_country_impl, // Nigeria _mk_country_impl, // North Macedonia _no_country_impl, // Norway _om_country_impl, // Oman _pk_country_impl, // Pakistan _pw_country_impl, // Palau _ps_country_impl, // Palestine _pa_country_impl, // Panama _pg_country_impl, // Papua New Guinea _py_country_impl, // Paraguay _pe_country_impl, // Peru _ph_country_impl, // Philippines _pl_country_impl, // Poland _pt_country_impl, // Portugal _qa_country_impl, // Qatar _ro_country_impl, // Romania _ru_country_impl, // Russia _rw_country_impl, // Rwanda _kn_country_impl, // Saint Kitts and Nevis _lc_country_impl, // Saint Lucia _vc_country_impl, // Saint Vincent and the Grenadines _ws_country_impl, // Samoa _sm_country_impl, // San Marino _st_country_impl, // São Tomé and Príncipe _sa_country_impl, // Saudi Arabia _sn_country_impl, // Senegal _rs_country_impl, // Serbia _sc_country_impl, // Seychelles _sl_country_impl, // Sierra Leone _sg_country_impl, // Singapore _sk_country_impl, // Slovakia _si_country_impl, // Slovenia _sb_country_impl, // Solomon Islands _so_country_impl, // Somalia _za_country_impl, // South Africa _ss_country_impl, // South Sudan _es_country_impl, // Spain _lk_country_impl, // Sri Lanka _sd_country_impl, // Sudan _sr_country_impl, // Suriname _se_country_impl, // Sweden _ch_country_impl, // Switzerland _sy_country_impl, // Syria _tw_country_impl, // Taiwan _tj_country_impl, // Tajikistan _tz_country_impl, // Tanzania _th_country_impl, // Thailand _tl_country_impl, // Timor-Leste _tg_country_impl, // Togo _to_country_impl, // Tonga _tt_country_impl, // Trinidad and Tobago _tn_country_impl, // Tunisia _tr_country_impl, // Türkiye _tm_country_impl, // Turkmenistan _tv_country_impl, // Tuvalu _ug_country_impl, // Uganda _ua_country_impl, // Ukraine _ae_country_impl, // United Arab Emirates _gb_country_impl, // United Kingdom _us_country_impl, // United States _uy_country_impl, // Uruguay _uz_country_impl, // Uzbekistan _vu_country_impl, // Vanuatu _va_country_impl, // Vatican City _ve_country_impl, // Venezuela _vn_country_impl, // Vietnam _ye_country_impl, // Yemen _zm_country_impl, // Zambia _zw_country_impl // Zimbabwe }; 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].add_billing_item_to_tax_report && country_map[index].get_available_tax_rates; } 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); } bool country::add_billing_item_to_tax_report(char* country_code, tax_report* report, invoice* inv, billing_item* item) { s32 index = get_index_by_country_code(country_code); assert(index != -1); return country_map[index].add_billing_item_to_tax_report(report, inv, item); } float country::calculate_tax_report_final(char* country_code, tax_report* report) { s32 index = get_index_by_country_code(country_code); assert(index != -1); return country_map[index].calculate_tax_report_final(report); } time_t country::get_invoice_date_to_use_for_tax_report(char* country_code, invoice* inv) { s32 index = get_index_by_country_code(country_code); assert(index != -1); return country_map[index].get_invoice_date_to_use_for_tax_report(inv); } u32 country::get_available_tax_rates(char* country_code, tax_rate* buffer, u32 buffer_size) { s32 index = get_index_by_country_code(country_code); assert(index != -1); return country_map[index].get_available_tax_rates(buffer, buffer_size); }