diff options
Diffstat (limited to 'src/administration.cpp')
| -rw-r--r-- | src/administration.cpp | 142 |
1 files changed, 71 insertions, 71 deletions
diff --git a/src/administration.cpp b/src/administration.cpp index 955e377..41dbf90 100644 --- a/src/administration.cpp +++ b/src/administration.cpp @@ -17,7 +17,7 @@ data_changed_event data_changed_event_callback = 0; data_deleted_event data_deleted_event_callback = 0; invoice_changed_event invoice_changed_event_callback = 0; contact_changed_event contact_changed_event_callback = 0; -taxbracket_changed_event taxbracket_changed_event_callback = 0; +taxrate_changed_event taxrate_changed_event_callback = 0; costcenter_changed_event costcenter_changed_event_callback = 0; project_changed_event project_changed_event_callback = 0; @@ -28,21 +28,21 @@ static s32 administration_create_id() #define ADD_BRACKET(_country, _rate, _code)\ {\ - country_tax_bracket* tb = (country_tax_bracket*)malloc(sizeof(country_tax_bracket));\ + tax_rate* tb = (tax_rate*)malloc(sizeof(tax_rate));\ 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->category_code, _code, sizeof(tb->category_code));\ - list_append(&g_administration.tax_brackets, tb);\ + list_append(&g_administration.tax_rates, tb);\ g_administration.next_id++;\ - if (taxbracket_changed_event_callback) taxbracket_changed_event_callback(tb);\ + if (taxrate_changed_event_callback) taxrate_changed_event_callback(tb);\ if (data_changed_event_callback) data_changed_event_callback();\ } static int compare_tax_countries(const void *a, const void *b) { - country_tax_bracket *objA = (country_tax_bracket *)a; - country_tax_bracket *objB = (country_tax_bracket *)b; + tax_rate *objA = (tax_rate *)a; + tax_rate *objB = (tax_rate *)b; return strcmp(objA->country_code, objB->country_code); } @@ -108,18 +108,18 @@ static void administration_get_random_billing_items(invoice* inv) if (item.net < item.discount) item.discount = 0.0f; - country_tax_bracket buffer[20]; - u32 bracket_count = administration_tax_bracket_get_by_country(buffer, inv->supplier.address.country_code); - country_tax_bracket rand_bracket = buffer[rand() % bracket_count]; - strops_copy(item.tax_bracket_id, rand_bracket.id, MAX_LEN_ID); + tax_rate buffer[20]; + u32 rate_count = administration_tax_rate_get_by_country(buffer, inv->supplier.address.country_code); + tax_rate rand_rate = buffer[rand() % rate_count]; + strops_copy(item.tax_rate_id, rand_rate.id, MAX_LEN_ID); administration_billing_item_add_to_invoice(inv, item); } } -static void administration_create_default_tax_brackets() +static void administration_create_default_tax_rates() { - // General brackets shared between countries. + // General rates shared between countries. // Category options: https://docs.peppol.eu/poacc/billing/3.0/codelist/UNCL5305/ // TODO unimplemented category L, M, B @@ -263,8 +263,8 @@ static void administration_create_default_tax_brackets() 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); + list_attributes_comparator(&g_administration.tax_rates, compare_tax_countries); + list_sort(&g_administration.tax_rates, -1); } static void administration_create_default_cost_centers() @@ -426,9 +426,9 @@ void administration_set_contact_changed_event_callback(contact_changed_event ev) contact_changed_event_callback = ev; } -void administration_set_taxbracket_changed_event_callback(taxbracket_changed_event ev) +void administration_set_taxrate_changed_event_callback(taxrate_changed_event ev) { - taxbracket_changed_event_callback = ev; + taxrate_changed_event_callback = ev; } void administration_set_costcenter_changed_event_callback(costcenter_changed_event ev) @@ -453,7 +453,7 @@ void administration_create() list_init(&g_administration.invoices); list_init(&g_administration.contacts); list_init(&g_administration.projects); - list_init(&g_administration.tax_brackets); + list_init(&g_administration.tax_rates); list_init(&g_administration.cost_centers); strops_copy(g_administration.path, "", sizeof(g_administration.path)); @@ -477,7 +477,7 @@ void administration_destroy() administration_destroy_list(&g_administration.invoices); administration_destroy_list(&g_administration.contacts); administration_destroy_list(&g_administration.projects); - administration_destroy_list(&g_administration.tax_brackets); + administration_destroy_list(&g_administration.tax_rates); administration_destroy_list(&g_administration.cost_centers); } @@ -506,7 +506,7 @@ void administration_create_empty(char* save_file) void administration_create_default(char* save_file) { administration_create_empty(save_file); - administration_create_default_tax_brackets(); + administration_create_default_tax_rates(); administration_create_default_cost_centers(); //administration_create_debug_data(); } @@ -1217,128 +1217,128 @@ project administration_project_create_empty() return result; } -// Tax bracket functions. +// Tax rate functions. // ======================= -country_tax_bracket administration_tax_bracket_create_empty() +tax_rate administration_tax_rate_create_empty() { - country_tax_bracket result; - memset(&result, 0, sizeof(country_tax_bracket)); + tax_rate result; + memset(&result, 0, sizeof(tax_rate)); snprintf(result.id, sizeof(result.id), "T/%d", administration_create_id()); snprintf(result.category_code, sizeof(result.category_code), "S"); // S = standard rate. return result; } -a_err administration_tax_bracket_get_by_id(country_tax_bracket* buffer, char* id) +a_err administration_tax_rate_get_by_id(tax_rate* buffer, char* id) { assert(buffer); - 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); + list_iterator_start(&g_administration.tax_rates); + while (list_iterator_hasnext(&g_administration.tax_rates)) { + tax_rate c = *(tax_rate *)list_iterator_next(&g_administration.tax_rates); if (strcmp(c.id, id) == 0) { *buffer = c; - list_iterator_stop(&g_administration.tax_brackets); + list_iterator_stop(&g_administration.tax_rates); return a_err::A_ERR_SUCCESS; } } - list_iterator_stop(&g_administration.tax_brackets); + list_iterator_stop(&g_administration.tax_rates); return a_err::A_ERR_NOT_FOUND; } -u32 administration_tax_bracket_count() +u32 administration_tax_rate_count() { - return list_size(&g_administration.tax_brackets); + return list_size(&g_administration.tax_rates); } -a_err administration_tax_bracket_import(country_tax_bracket data) +a_err administration_tax_rate_import(tax_rate data) { - country_tax_bracket* tb = (country_tax_bracket*)malloc(sizeof(country_tax_bracket)); + tax_rate* tb = (tax_rate*)malloc(sizeof(tax_rate)); if (!tb) return a_err::A_ERR_GENERIC; - memcpy((void*)tb, (void*)&data, sizeof(country_tax_bracket)); - if (!list_append(&g_administration.tax_brackets, tb)) { + memcpy((void*)tb, (void*)&data, sizeof(tax_rate)); + if (!list_append(&g_administration.tax_rates, tb)) { return a_err::A_ERR_GENERIC; } - list_attributes_comparator(&g_administration.tax_brackets, compare_tax_countries); - list_sort(&g_administration.tax_brackets, -1); + list_attributes_comparator(&g_administration.tax_rates, compare_tax_countries); + list_sort(&g_administration.tax_rates, -1); return a_err::A_ERR_SUCCESS; } -a_err administration_tax_bracket_add(country_tax_bracket data) +a_err administration_tax_rate_add(tax_rate data) { - country_tax_bracket* tb = (country_tax_bracket*)malloc(sizeof(country_tax_bracket)); + tax_rate* tb = (tax_rate*)malloc(sizeof(tax_rate)); if (!tb) return a_err::A_ERR_GENERIC; - memcpy((void*)tb, (void*)&data, sizeof(country_tax_bracket)); - if (!list_append(&g_administration.tax_brackets, tb)) { + memcpy((void*)tb, (void*)&data, sizeof(tax_rate)); + if (!list_append(&g_administration.tax_rates, tb)) { return a_err::A_ERR_GENERIC; } g_administration.next_id++; - list_attributes_comparator(&g_administration.tax_brackets, compare_tax_countries); - list_sort(&g_administration.tax_brackets, -1); + list_attributes_comparator(&g_administration.tax_rates, compare_tax_countries); + list_sort(&g_administration.tax_rates, -1); - if (taxbracket_changed_event_callback) taxbracket_changed_event_callback(&data); + if (taxrate_changed_event_callback) taxrate_changed_event_callback(&data); if (data_changed_event_callback) data_changed_event_callback(); return a_err::A_ERR_SUCCESS; } -u32 administration_tax_bracket_get_by_country(country_tax_bracket* buffer, char* country_code) +u32 administration_tax_rate_get_by_country(tax_rate* buffer, char* country_code) { assert(buffer); u32 write_cursor = 0; - 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); + list_iterator_start(&g_administration.tax_rates); + while (list_iterator_hasnext(&g_administration.tax_rates)) { + tax_rate c = *(tax_rate *)list_iterator_next(&g_administration.tax_rates); if (strcmp(c.country_code, country_code) == 0 || strcmp(c.country_code, "00") == 0) buffer[write_cursor++] = c; } - list_iterator_stop(&g_administration.tax_brackets); + list_iterator_stop(&g_administration.tax_rates); return write_cursor; } -u32 administration_tax_bracket_get_all(country_tax_bracket* buffer) +u32 administration_tax_rate_get_all(tax_rate* buffer) { assert(buffer); u32 write_cursor = 0; - 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); + list_iterator_start(&g_administration.tax_rates); + while (list_iterator_hasnext(&g_administration.tax_rates)) { + tax_rate c = *(tax_rate *)list_iterator_next(&g_administration.tax_rates); buffer[write_cursor++] = c; } - list_iterator_stop(&g_administration.tax_brackets); + list_iterator_stop(&g_administration.tax_rates); return write_cursor; } -a_err administration_tax_bracket_update(country_tax_bracket data) +a_err administration_tax_rate_update(tax_rate 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); + list_iterator_start(&g_administration.tax_rates); + while (list_iterator_hasnext(&g_administration.tax_rates)) { + tax_rate* c = (tax_rate *)list_iterator_next(&g_administration.tax_rates); if (strcmp(c->id, data.id) == 0) { memcpy(c, &data, sizeof(data)); - list_iterator_stop(&g_administration.tax_brackets); + list_iterator_stop(&g_administration.tax_rates); - if (taxbracket_changed_event_callback) taxbracket_changed_event_callback(c); + if (taxrate_changed_event_callback) taxrate_changed_event_callback(c); if (data_changed_event_callback) data_changed_event_callback(); return a_err::A_ERR_SUCCESS; } } - list_iterator_stop(&g_administration.tax_brackets); + list_iterator_stop(&g_administration.tax_rates); return a_err::A_ERR_NOT_FOUND; } @@ -1777,7 +1777,7 @@ u32 administration_invoice_get_all(invoice* buffer) return write_cursor; } -bool administration_invoice_get_subtotal_for_tax_bracket(invoice* invoice, country_tax_bracket bracket, tax_subtotal* buffer) +bool administration_invoice_get_subtotal_for_tax_rate(invoice* invoice, tax_rate rate, tax_subtotal* buffer) { bool result = false; @@ -1790,7 +1790,7 @@ bool administration_invoice_get_subtotal_for_tax_bracket(invoice* invoice, count while (list_iterator_hasnext(&invoice->billing_items)) { billing_item* c = (billing_item *)list_iterator_next(&invoice->billing_items); - if (strcmp(c->tax_bracket_id, bracket.id) == 0) + if (strcmp(c->tax_rate_id, rate.id) == 0) { result = true; buffer->tax += c->tax; @@ -1804,7 +1804,7 @@ bool administration_invoice_get_subtotal_for_tax_bracket(invoice* invoice, count return result; } -u32 administration_invoice_get_tax_brackets(invoice* invoice, country_tax_bracket* buffer) +u32 administration_invoice_get_tax_rates(invoice* invoice, tax_rate* buffer) { u32 write_cursor = 0; @@ -1812,20 +1812,20 @@ u32 administration_invoice_get_tax_brackets(invoice* invoice, country_tax_bracke while (list_iterator_hasnext(&invoice->billing_items)) { billing_item c = *(billing_item *)list_iterator_next(&invoice->billing_items); - country_tax_bracket bracket; - a_err found = administration_tax_bracket_get_by_id(&bracket, c.tax_bracket_id); + tax_rate rate; + a_err found = administration_tax_rate_get_by_id(&rate, c.tax_rate_id); if (found == a_err::A_ERR_SUCCESS) { bool exists = false; for (u32 i = 0; i < write_cursor; i++) { - if (strcmp(buffer[i].id, c.tax_bracket_id) == 0) { + if (strcmp(buffer[i].id, c.tax_rate_id) == 0) { exists = true; break; } } if (!exists) { - buffer[write_cursor++] = bracket; + buffer[write_cursor++] = rate; } } } @@ -1913,10 +1913,10 @@ static void administration_recalculate_billing_item_totals(billing_item* item) } } - country_tax_bracket bracket; - if (administration_tax_bracket_get_by_id(&bracket, item->tax_bracket_id) == a_err::A_ERR_SUCCESS) + tax_rate rate; + if (administration_tax_rate_get_by_id(&rate, item->tax_rate_id) == a_err::A_ERR_SUCCESS) { - item->tax = item->net * (bracket.rate/100.0f); + item->tax = item->net * (rate.rate/100.0f); } item->total = item->net + item->tax; |
