diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/administration.cpp | 188 | ||||
| -rw-r--r-- | src/administration_writer.cpp | 78 | ||||
| -rw-r--r-- | src/locales/en.cpp | 14 | ||||
| -rw-r--r-- | src/ui/ui_invoices.cpp | 18 | ||||
| -rw-r--r-- | src/ui/ui_settings.cpp | 5 |
5 files changed, 196 insertions, 107 deletions
diff --git a/src/administration.cpp b/src/administration.cpp index b938271..e6c9821 100644 --- a/src/administration.cpp +++ b/src/administration.cpp @@ -15,13 +15,13 @@ static s32 administration_create_id() return g_administration.next_id; } -#define ADD_BRACKET(_country, _rate, _description)\ +#define ADD_BRACKET(_country, _rate, _code)\ {\ 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));\ + memcpy(tb->category_code, _code, sizeof(tb->category_code));\ list_append(&g_administration.tax_brackets, tb);\ g_administration.next_id++;\ } @@ -106,140 +106,148 @@ static void administation_get_random_billing_items(invoice* inv) 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"); + // Category options: https://docs.peppol.eu/poacc/billing/3.0/codelist/UNCL5305/ + + // TODO unimplemented category L, M, B + + ADD_BRACKET("00", 0.0f, "AE"); // Vat Reverse Charge + ADD_BRACKET("00", 0.0f, "E"); // Exempt from Tax + ADD_BRACKET("00", 0.0f, "Z"); // Zero rated goods + ADD_BRACKET("00", 0.0f, "G"); // Free export item, VAT not charged + ADD_BRACKET("00", 0.0f, "O"); // Services outside scope of tax + ADD_BRACKET("00", 0.0f, "K"); // VAT exempt for EEA intra-community supply of goods and services // Austria - ADD_BRACKET("AT", 20.0f, "tax.standard"); - ADD_BRACKET("AT", 10.0f, "tax.reduced"); - ADD_BRACKET("AT", 13.0f, "tax.reduced"); + ADD_BRACKET("AT", 20.0f, "S"); + ADD_BRACKET("AT", 10.0f, "S"); + ADD_BRACKET("AT", 13.0f, "S"); // Belgium - ADD_BRACKET("BE", 21.0f, "tax.standard"); - ADD_BRACKET("BE", 6.0f, "tax.reduced"); - ADD_BRACKET("BE", 12.0f, "tax.reduced"); + ADD_BRACKET("BE", 21.0f, "S"); + ADD_BRACKET("BE", 6.0f, "S"); + ADD_BRACKET("BE", 12.0f, "S"); // Bulgaria - ADD_BRACKET("BG", 20.0f, "tax.standard"); - ADD_BRACKET("BG", 9.0f, "tax.reduced"); + ADD_BRACKET("BG", 20.0f, "S"); + ADD_BRACKET("BG", 9.0f, "S"); // Cyprus - ADD_BRACKET("CY", 19.0f, "tax.standard"); - ADD_BRACKET("CY", 5.0f, "tax.reduced"); - ADD_BRACKET("CY", 9.0f, "tax.reduced"); + ADD_BRACKET("CY", 19.0f, "S"); + ADD_BRACKET("CY", 5.0f, "S"); + ADD_BRACKET("CY", 9.0f, "S"); // Czechia - ADD_BRACKET("CZ", 21.0f, "tax.standard"); - ADD_BRACKET("CZ", 12.0f, "tax.reduced"); + ADD_BRACKET("CZ", 21.0f, "S"); + ADD_BRACKET("CZ", 12.0f, "S"); // Croatia - ADD_BRACKET("HR", 25.0f, "tax.standard"); - ADD_BRACKET("HR", 5.0f, "tax.reduced"); - ADD_BRACKET("HR", 13.0f, "tax.reduced"); + ADD_BRACKET("HR", 25.0f, "S"); + ADD_BRACKET("HR", 5.0f, "S"); + ADD_BRACKET("HR", 13.0f, "S"); // Denmark - ADD_BRACKET("DK", 25.0f, "tax.standard"); + ADD_BRACKET("DK", 25.0f, "S"); // Estonia - ADD_BRACKET("EE", 22.0f, "tax.standard"); - ADD_BRACKET("EE", 9.0f, "tax.reduced"); + ADD_BRACKET("EE", 22.0f, "S"); + ADD_BRACKET("EE", 9.0f, "S"); // Finland - ADD_BRACKET("FI", 25.5f, "tax.standard"); - ADD_BRACKET("FI", 10.0f, "tax.reduced"); - ADD_BRACKET("FI", 14.0f, "tax.reduced"); + ADD_BRACKET("FI", 25.5f, "S"); + ADD_BRACKET("FI", 10.0f, "S"); + ADD_BRACKET("FI", 14.0f, "S"); // France - ADD_BRACKET("FR", 20.0f, "tax.standard"); - ADD_BRACKET("FR", 5.5f, "tax.reduced"); - ADD_BRACKET("FR", 10.0f, "tax.reduced"); - ADD_BRACKET("FR", 2.1f, "tax.superReduced"); + ADD_BRACKET("FR", 20.0f, "S"); + ADD_BRACKET("FR", 5.5f, "S"); + ADD_BRACKET("FR", 10.0f, "S"); + ADD_BRACKET("FR", 2.1f, "S"); // Germany - ADD_BRACKET("DE", 19.0f, "tax.standard"); - ADD_BRACKET("DE", 7.0f, "tax.reduced"); + ADD_BRACKET("DE", 19.0f, "S"); + ADD_BRACKET("DE", 7.0f, "S"); // Greece - ADD_BRACKET("GR", 24.0f, "tax.standard"); - ADD_BRACKET("GR", 6.0f, "tax.reduced"); - ADD_BRACKET("GR", 13.0f, "tax.reduced"); + ADD_BRACKET("GR", 24.0f, "S"); + ADD_BRACKET("GR", 6.0f, "S"); + ADD_BRACKET("GR", 13.0f, "S"); // Hungary - ADD_BRACKET("HU", 27.0f, "tax.standard"); - ADD_BRACKET("HU", 5.0f, "tax.reduced"); - ADD_BRACKET("HU", 18.0f, "tax.reduced"); + ADD_BRACKET("HU", 27.0f, "S"); + ADD_BRACKET("HU", 5.0f, "S"); + ADD_BRACKET("HU", 18.0f, "S"); // Ireland - ADD_BRACKET("IE", 23.0f, "tax.standard"); - ADD_BRACKET("IE", 9.0f, "tax.reduced"); - ADD_BRACKET("IE", 13.5f, "tax.reduced"); - ADD_BRACKET("IE", 4.8f, "tax.superReduced"); + ADD_BRACKET("IE", 23.0f, "S"); + ADD_BRACKET("IE", 9.0f, "S"); + ADD_BRACKET("IE", 13.5f, "S"); + ADD_BRACKET("IE", 4.8f, "S"); // Italy - ADD_BRACKET("IT", 22.0f, "tax.standard"); - ADD_BRACKET("IT", 5.0f, "tax.reduced"); - ADD_BRACKET("IT", 10.0f, "tax.reduced"); - ADD_BRACKET("IT", 4.0f, "tax.superReduced"); + ADD_BRACKET("IT", 22.0f, "S"); + ADD_BRACKET("IT", 5.0f, "S"); + ADD_BRACKET("IT", 10.0f, "S"); + ADD_BRACKET("IT", 4.0f, "S"); // Latvia - ADD_BRACKET("LV", 21.0f, "tax.standard"); - ADD_BRACKET("LV", 5.0f, "tax.reduced"); - ADD_BRACKET("LV", 12.0f, "tax.reduced"); + ADD_BRACKET("LV", 21.0f, "S"); + ADD_BRACKET("LV", 5.0f, "S"); + ADD_BRACKET("LV", 12.0f, "S"); // Lithuania - ADD_BRACKET("LT", 21.0f, "tax.standard"); - ADD_BRACKET("LT", 5.0f, "tax.reduced"); - ADD_BRACKET("LT", 9.0f, "tax.reduced"); + ADD_BRACKET("LT", 21.0f, "S"); + ADD_BRACKET("LT", 5.0f, "S"); + ADD_BRACKET("LT", 9.0f, "S"); // Luxembourg - ADD_BRACKET("LU", 17.0f, "tax.standard"); - ADD_BRACKET("LU", 8.0f, "tax.reduced"); - ADD_BRACKET("LU", 14.0f, "tax.reduced"); - ADD_BRACKET("LU", 3.0f, "tax.superReduced"); + ADD_BRACKET("LU", 17.0f, "S"); + ADD_BRACKET("LU", 8.0f, "S"); + ADD_BRACKET("LU", 14.0f, "S"); + ADD_BRACKET("LU", 3.0f, "S"); // Malta - ADD_BRACKET("MT", 18.0f, "tax.standard"); - ADD_BRACKET("MT", 5.0f, "tax.reduced"); - ADD_BRACKET("MT", 7.0f, "tax.reduced"); + ADD_BRACKET("MT", 18.0f, "S"); + ADD_BRACKET("MT", 5.0f, "S"); + ADD_BRACKET("MT", 7.0f, "S"); // Netherlands - ADD_BRACKET("NL", 21.0f, "tax.standard"); - ADD_BRACKET("NL", 9.0f, "tax.reduced"); + ADD_BRACKET("NL", 21.0f, "S"); + ADD_BRACKET("NL", 9.0f, "S"); // Poland - ADD_BRACKET("PL", 23.0f, "tax.standard"); - ADD_BRACKET("PL", 5.0f, "tax.reduced"); - ADD_BRACKET("PL", 8.0f, "tax.reduced"); + ADD_BRACKET("PL", 23.0f, "S"); + ADD_BRACKET("PL", 5.0f, "S"); + ADD_BRACKET("PL", 8.0f, "S"); // Portugal - ADD_BRACKET("PT", 23.0f, "tax.standard"); - ADD_BRACKET("PT", 6.0f, "tax.reduced"); - ADD_BRACKET("PT", 13.0f, "tax.reduced"); + ADD_BRACKET("PT", 23.0f, "S"); + ADD_BRACKET("PT", 6.0f, "S"); + ADD_BRACKET("PT", 13.0f, "S"); // Romania - ADD_BRACKET("RO", 19.0f, "tax.standard"); - ADD_BRACKET("RO", 5.0f, "tax.reduced"); - ADD_BRACKET("RO", 9.0f, "tax.reduced"); + ADD_BRACKET("RO", 19.0f, "S"); + ADD_BRACKET("RO", 5.0f, "S"); + ADD_BRACKET("RO", 9.0f, "S"); // Slovakia - ADD_BRACKET("SK", 23.0f, "tax.standard"); - ADD_BRACKET("SK", 5.0f, "tax.reduced"); - ADD_BRACKET("SK", 19.0f, "tax.reduced"); + ADD_BRACKET("SK", 23.0f, "S"); + ADD_BRACKET("SK", 5.0f, "S"); + ADD_BRACKET("SK", 19.0f, "S"); // Slovenia - ADD_BRACKET("SI", 22.0f, "tax.standard"); - ADD_BRACKET("SI", 5.0f, "tax.reduced"); - ADD_BRACKET("SI", 9.5f, "tax.reduced"); + ADD_BRACKET("SI", 22.0f, "S"); + ADD_BRACKET("SI", 5.0f, "S"); + ADD_BRACKET("SI", 9.5f, "S"); // Spain - ADD_BRACKET("ES", 21.0f, "tax.standard"); - ADD_BRACKET("ES", 10.0f, "tax.reduced"); - ADD_BRACKET("ES", 4.0f, "tax.superReduced"); + ADD_BRACKET("ES", 21.0f, "S"); + ADD_BRACKET("ES", 10.0f, "S"); + ADD_BRACKET("ES", 4.0f, "S"); // Sweden - ADD_BRACKET("SE", 25.0f, "tax.standard"); - ADD_BRACKET("SE", 6.0f, "tax.reduced"); - ADD_BRACKET("SE", 12.0f, "tax.reduced"); + ADD_BRACKET("SE", 25.0f, "S"); + 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); @@ -769,6 +777,12 @@ static bool administration_get_tax_bracket_by_id(country_tax_bracket* buffer, ch return false; } +// TODO refactor +bool administration_tax_bracket_get_by_id(char* id, country_tax_bracket* buffer) +{ + return administration_get_tax_bracket_by_id(buffer, id); +} + u32 administration_tax_bracket_count() { return list_size(&g_administration.tax_brackets); @@ -982,6 +996,7 @@ static void administration_recalculate_invoice_totals(invoice* invoice) invoice->tax = 0.0f; invoice->total = 0.0f; invoice->net = 0.0f; + invoice->allowance = 0.0f; list_iterator_start(&invoice->billing_items); while (list_iterator_hasnext(&invoice->billing_items)) { @@ -990,6 +1005,7 @@ static void administration_recalculate_invoice_totals(invoice* invoice) invoice->tax += c->tax; invoice->total += c->total; invoice->net += c->net; + invoice->allowance += c->allowance; } list_iterator_stop(&invoice->billing_items); } @@ -1220,6 +1236,7 @@ bool administration_invoice_get_subtotal_for_tax_bracket(invoice* invoice, count buffer->tax = 0.0f; buffer->total = 0.0f; buffer->net = 0.0f; + buffer->allowance = 0.0f; list_iterator_start(&invoice->billing_items); while (list_iterator_hasnext(&invoice->billing_items)) { @@ -1231,6 +1248,7 @@ bool administration_invoice_get_subtotal_for_tax_bracket(invoice* invoice, count buffer->tax += c->tax; buffer->total += c->total; buffer->net += c->net; + buffer->allowance += c->allowance; } } list_iterator_stop(&invoice->billing_items); @@ -1337,11 +1355,13 @@ static void administration_recalculate_billing_item_totals(billing_item* item) { if (item->discount_is_percentage) { - item->net -= item->net * (item->discount / 100.0f); + item->allowance = item->net * (item->discount / 100.0f); + item->net -= item->allowance; } else { - item->net -= item->discount; + item->allowance = item->discount; + item->net -= item->allowance; } } diff --git a/src/administration_writer.cpp b/src/administration_writer.cpp index e00921d..0176d97 100644 --- a/src/administration_writer.cpp +++ b/src/administration_writer.cpp @@ -25,7 +25,7 @@ void administration_writer_destroy() static char* administration_writer_copy_template(const char* template_str, int* buf_size) { size_t template_size = strlen(template_str); - size_t buf_length = template_size*2; // Ballpark file content size. + size_t buf_length = template_size*5; // Ballpark file content size. char* file_content = (char*)malloc(buf_length); memset(file_content, 0, buf_length); memcpy(file_content, template_str, template_size); @@ -206,18 +206,19 @@ bool administration_writer_save_invoice_blocking(invoice inv) strops_replace(file_content, buf_length, "{{CUSTOMER_VAT_ID}}", inv.customer.taxid); // Payment means - strops_replace_int32(file_content, buf_length, "{{PAYMENT_TYPE}}", inv.payment_means.payment_method); - strops_replace(file_content, buf_length, "{{SUPPLIER_IBAN}}", inv.payment_means.payee_bank_account); - strops_replace(file_content, buf_length, "{{SUPPLIER_BIC}}", inv.payment_means.service_provider_id); + strops_replace_int32(file_content, buf_length, "{{PAYMENT_TYPE}}", inv.payment_means.payment_method); + strops_replace(file_content, buf_length, "{{SUPPLIER_IBAN}}", inv.payment_means.payee_bank_account); + strops_replace(file_content, buf_length, "{{SUPPLIER_BIC}}", inv.payment_means.service_provider_id); // Tax breakdown - strops_replace_float(file_content, buf_length, "{{TOTAL_TAX_AMOUNT}}", inv.total, 2); - + strops_replace_float(file_content, buf_length, "{{TOTAL_TAX_AMOUNT}}", inv.total, 2); { // Create tax subtotal list. country_tax_bracket* tax_bracket_buffer = (country_tax_bracket*)malloc(sizeof(country_tax_bracket)*administration_billing_item_count(&inv)); u32 tax_bracket_count = administration_invoice_get_tax_brackets(&inv, tax_bracket_buffer); - //int tax_list_buf_length = 0; - //char* tax_list_file_content = administration_writer_copy_template(peppol_invoice_tax_subtotal_template, &tax_list_buf_length); + + u32 tax_subtotal_list_buffer_size = (u32)strlen(peppol_invoice_tax_subtotal_template) * 2 * tax_bracket_count; // Ballpark list size. + char* tax_subtotal_list_buffer = (char*)malloc(tax_subtotal_list_buffer_size); + u32 tax_subtotal_list_buffer_cursor = 0; for (u32 i = 0; i < tax_bracket_count; i++) { @@ -230,15 +231,69 @@ bool administration_writer_save_invoice_blocking(invoice inv) strops_replace(tax_entry_file_content, tax_entry_buf_length, "{{CURRENCY}}", inv.currency); strops_replace_float(tax_entry_file_content, tax_entry_buf_length, "{{TAXABLE_AMOUNT}}", subtotal.net, 2); strops_replace_float(tax_entry_file_content, tax_entry_buf_length, "{{TAX_AMOUNT}}", subtotal.tax, 2); - //strops_replace(tax_entry_file_content, tax_entry_buf_length, "{{TAX_CATEGORY}}", inv.currency); + strops_replace(tax_entry_file_content, tax_entry_buf_length, "{{TAX_CATEGORY}}", tax_bracket_buffer[i].category_code); strops_replace_float(tax_entry_file_content, tax_entry_buf_length, "{{TAX_PERCENT}}", tax_bracket_buffer[i].rate, 2); - printf("%s\n", tax_entry_file_content); + u32 content_len = (u32)strlen(tax_entry_file_content); + memcpy(tax_subtotal_list_buffer+tax_subtotal_list_buffer_cursor, tax_entry_file_content, content_len); + + tax_subtotal_list_buffer_cursor += content_len; } + tax_subtotal_list_buffer[tax_subtotal_list_buffer_cursor] = 0; + strops_replace(file_content, buf_length, "{{TAX_SUBTOTAL_LIST}}", tax_subtotal_list_buffer); + + free(tax_subtotal_list_buffer); free(tax_bracket_buffer); } + // Totals + strops_replace_float(file_content, buf_length, "{{LINE_EXTENSION_AMOUNT}}", inv.net - inv.allowance, 2); + strops_replace_float(file_content, buf_length, "{{TAX_EXCLUSIVE_AMOUNT}}", inv.net, 2); + strops_replace_float(file_content, buf_length, "{{TAX_INCLUSIVE_AMOUNT}}", inv.total, 2); + strops_replace_float(file_content, buf_length, "{{PAYABLE_AMOUNT}}", inv.total, 2); + + // Invoice lines + { + billing_item* billing_item_buffer = (billing_item*)malloc(sizeof(billing_item) * administration_billing_item_count(&inv)); + u32 billing_item_count = administration_billing_item_get_all_for_invoice(&inv, billing_item_buffer); + + u32 billing_item_list_buffer_size = (u32)strlen(peppol_invoice_line_template) * 2 * billing_item_count; // Ballpark list size. + char* billing_item_list_buffer = (char*)malloc(billing_item_list_buffer_size); + u32 billing_item_list_buffer_cursor = 0; + + for (u32 i = 0; i < billing_item_count; i++) + { + int billing_item_buf_length = 0; + char* billing_item_file_content = administration_writer_copy_template(peppol_invoice_line_template, &billing_item_buf_length); + + billing_item bi = billing_item_buffer[i]; + country_tax_bracket bracket; + administration_tax_bracket_get_by_id(bi.tax_bracket_id, &bracket); + + strops_replace(billing_item_file_content, billing_item_buf_length, "{{CURRENCY}}", inv.currency); + strops_replace(billing_item_file_content, billing_item_buf_length, "{{LINE_ID}}", bi.id); + strops_replace(billing_item_file_content, billing_item_buf_length, "{{ITEM_NAME}}", "XD"); + strops_replace(billing_item_file_content, billing_item_buf_length, "{{LINE_TAX_CATEGORY}}", bracket.category_code); + strops_replace_float(billing_item_file_content, billing_item_buf_length, "{{LINE_TAX_PERCENT}}", bracket.rate, 2); + strops_replace_float(billing_item_file_content, billing_item_buf_length, "{{LINE_AMOUNT}}", bi.net, 2); + strops_replace_float(billing_item_file_content, billing_item_buf_length, "{{QUANTITY}}", bi.amount, 2); + strops_replace_float(billing_item_file_content, billing_item_buf_length, "{{UNIT_PRICE}}", bi.net_per_item, 2); + strops_replace(billing_item_file_content, billing_item_buf_length, "{{UNIT_CODE}}", bi.amount_is_percentage ? "%" : "X"); + + u32 content_len = (u32)strlen(billing_item_file_content); + memcpy(billing_item_list_buffer+billing_item_list_buffer_cursor, billing_item_file_content, content_len); + + billing_item_list_buffer_cursor += content_len; + } + + billing_item_list_buffer[billing_item_list_buffer_cursor] = 0; + strops_replace(file_content, buf_length, "{{INVOICE_LINE_LIST}}", billing_item_list_buffer); + + free(billing_item_list_buffer); + free(billing_item_buffer); + } + // Dates tm_info = localtime(&inv.issued_at); strftime(date_buffer, sizeof(date_buffer), "%Y-%m-%d", tm_info); @@ -249,6 +304,7 @@ bool administration_writer_save_invoice_blocking(invoice inv) snprintf(final_path, 50, "%s.xml", inv.id); int final_length = (int)strlen(file_content); + printf(file_content); if (!xml_parse_document((uint8_t*)file_content, final_length)) result = 0; else if (!administration_writer_write_to_zip(final_path, file_content, final_length)) result = 0; @@ -371,7 +427,7 @@ bool administration_writer_save_tax_bracket_blocking(country_tax_bracket bracket strops_replace(file_content, buf_length, "{{TAXBRACKET_ID}}", bracket.id); strops_replace(file_content, buf_length, "{{TAXBRACKET_COUNTRY}}", bracket.country_code); strops_replace_float(file_content, buf_length, "{{TAXBRACKET_RATE}}", bracket.rate, 2); - strops_replace(file_content, buf_length, "{{TAXBRACKET_DESCRIPTION}}", bracket.description); + strops_replace(file_content, buf_length, "{{TAXBRACKET_CATEGORY}}", bracket.category_code); //// Write to Disk. char final_path[50]; diff --git a/src/locales/en.cpp b/src/locales/en.cpp index b528088..03e5940 100644 --- a/src/locales/en.cpp +++ b/src/locales/en.cpp @@ -36,12 +36,14 @@ locale_entry en_locales[] = { {"costcenter.customer_service_support", "Customer Service & Support"}, {"costcenter.other_specialized", "Other / Specialized"}, - // Tax strings. - {"tax.reverse_charge", "Reverse tax"}, - {"tax.exempt", "Tax exempt"}, - {"tax.standard", "Standard Rate"}, - {"tax.reduced", "Reduced Rate"}, - {"tax.superReduced", "Super Reduced Rate"}, + // Tax category strings. + {"taxcategory.AE", "VAT Reverse Charge"}, + {"taxcategory.E", "Exempt from Tax"}, + {"taxcategory.S", "Standard rate"}, + {"taxcategory.Z", "Zero rated goods"}, + {"taxcategory.G", "Free export item, VAT not charged"}, + {"taxcategory.O", "Services outside scope of tax"}, + {"taxcategory.K", "Intra-community supply of goods and services"}, // Countries { "country.AT", "Austria" }, diff --git a/src/ui/ui_invoices.cpp b/src/ui/ui_invoices.cpp index d6bb157..8cdf959 100644 --- a/src/ui/ui_invoices.cpp +++ b/src/ui/ui_invoices.cpp @@ -59,12 +59,16 @@ void draw_tax_bracket_selector(char* tax_bracket_id, country_tax_bracket* buffer } int selected_tax_bracket_index = -1; - char rate_str_buf[20]; + char rate_str_buf[40]; rate_str_buf[0] = 0; if (selected_tax_bracket) { - if (strcmp(selected_tax_bracket->country_code, "00") == 0) snprintf(rate_str_buf, 20, "%s", localize(selected_tax_bracket->description)); - else snprintf(rate_str_buf, 20, "%s/%.1f%%", selected_tax_bracket->country_code, selected_tax_bracket->rate); + if (strcmp(selected_tax_bracket->country_code, "00") == 0) { + char category_code_desc[MAX_LEN_LONG_DESC]; + snprintf(category_code_desc, MAX_LEN_LONG_DESC, "taxcategory.%s", selected_tax_bracket->category_code); + snprintf(rate_str_buf, 40, "%s", localize(category_code_desc)); + } + else snprintf(rate_str_buf, 40, "%s/%.1f%%", selected_tax_bracket->country_code, selected_tax_bracket->rate); } if (ImGui::BeginCombo("##Tax Bracket", rate_str_buf)) @@ -73,8 +77,12 @@ void draw_tax_bracket_selector(char* tax_bracket_id, country_tax_bracket* buffer { bool is_selected = selected_tax_bracket && strcmp(selected_tax_bracket->id, buffer[n].id) == 0; - if (strcmp(buffer[n].country_code, "00") == 0) snprintf(rate_str_buf, 20, "%s", localize(buffer[n].description)); - else snprintf(rate_str_buf, 20, "%s/%.1f%%", buffer[n].country_code, buffer[n].rate); + if (strcmp(buffer[n].country_code, "00") == 0) { + char category_code_desc[MAX_LEN_LONG_DESC]; + snprintf(category_code_desc, MAX_LEN_LONG_DESC, "taxcategory.%s", buffer[n].category_code); + snprintf(rate_str_buf, 40, "%s", localize(category_code_desc)); + } + else snprintf(rate_str_buf, 40, "%s/%.1f%%", buffer[n].country_code, buffer[n].rate); if (ImGui::Selectable(rate_str_buf, is_selected)) { selected_tax_bracket_index = n; diff --git a/src/ui/ui_settings.cpp b/src/ui/ui_settings.cpp index 1d6a5f4..dea58ec 100644 --- a/src/ui/ui_settings.cpp +++ b/src/ui/ui_settings.cpp @@ -107,7 +107,10 @@ static void ui_draw_vat_rates() // Column 1: description of tax bracket. Is only displayed on shared tax brackets for clarity. ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); - ImGui::Text(can_be_modified ? "" : localize(c.description)); + + char category_code_desc[MAX_LEN_LONG_DESC]; + snprintf(category_code_desc, MAX_LEN_LONG_DESC, "taxcategory.%s", c.category_code); + ImGui::Text(can_be_modified ? "" : localize(category_code_desc)); // Column 2: When editing, show input for new rate. Else we display the stored rate and check for modify request. |
