diff options
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/imgui_extensions.cpp | 34 | ||||
| -rw-r--r-- | src/ui/ui_expenses.cpp | 4 | ||||
| -rw-r--r-- | src/ui/ui_invoices.cpp | 6 |
3 files changed, 18 insertions, 26 deletions
diff --git a/src/ui/imgui_extensions.cpp b/src/ui/imgui_extensions.cpp index 797da9d..63e8eeb 100644 --- a/src/ui/imgui_extensions.cpp +++ b/src/ui/imgui_extensions.cpp @@ -325,21 +325,20 @@ namespace ImGui memops::unalloc(buffer); } - void FormTaxRateCombo(char* tax_rate_id, char* orig_country, char* dest_country, bool has_error) + void FormTaxRateCombo(char* tax_internal_code, bool outgoing, bool has_error) { u32 tax_rate_count = administration::tax_rate_count(); tax_rate* buffer = (tax_rate*) memops::alloc(sizeof(tax_rate) * tax_rate_count); tax_rate* selected_tax_rate = NULL; - char* tax_country_codes[2] = {orig_country, dest_country}; - tax_rate_count = administration::tax_rate_get_by_country(buffer, strcmp(orig_country, dest_country) == 0 ? 1 : 2, tax_country_codes); + tax_rate_count = administration::tax_rate_get_all(buffer, outgoing ? tax_rate_type::TAX_RATE_OUTGOING_INVOICE : tax_rate_type::TAX_RATE_INCOMMING_INVOICE); // Select tax rate by given id. - if (strlen(tax_rate_id) > 0) + if (strlen(tax_internal_code) > 0) { for (u32 i = 0; i < tax_rate_count; i++) { - if (strcmp(buffer[i].id, tax_rate_id) == 0) + if (strcmp(buffer[i].internal_code, tax_internal_code) == 0) { selected_tax_rate = &buffer[i]; break; @@ -348,16 +347,12 @@ namespace ImGui } int selected_tax_rate_index = -1; - char rate_str_buf[40]; - rate_str_buf[0] = 0; + char rate_str_buf[MAX_LEN_LONG_DESC]; if (selected_tax_rate) { - if (strcmp(selected_tax_rate->country_code, "00") == 0) { - char category_code_desc[MAX_LEN_LONG_DESC]; - strops::format(category_code_desc, MAX_LEN_LONG_DESC, "taxcategory.%s", selected_tax_rate->category_code); - strops::format(rate_str_buf, 40, "%s", locale::get(category_code_desc)); - } - else strops::format(rate_str_buf, 40, "%s/%.1f%%", selected_tax_rate->country_code, selected_tax_rate->rate); + char category_code_desc[MAX_LEN_LONG_DESC]; + strops::format(category_code_desc, MAX_LEN_LONG_DESC, "taxrate.code.%s", selected_tax_rate->internal_code); + strops::format(rate_str_buf, MAX_LEN_LONG_DESC, "%s", locale::get(category_code_desc)); } if (has_error) { @@ -369,14 +364,11 @@ namespace ImGui { for (u32 n = 0; n < tax_rate_count; n++) { - bool is_selected = selected_tax_rate && strcmp(selected_tax_rate->id, buffer[n].id) == 0; + bool is_selected = selected_tax_rate && strcmp(selected_tax_rate->internal_code, buffer[n].internal_code) == 0; - if (strcmp(buffer[n].country_code, "00") == 0) { - char category_code_desc[MAX_LEN_LONG_DESC]; - strops::format(category_code_desc, MAX_LEN_LONG_DESC, "taxcategory.%s", buffer[n].category_code); - strops::format(rate_str_buf, 40, "%s", locale::get(category_code_desc)); - } - else strops::format(rate_str_buf, 40, "%s/%.1f%%", buffer[n].country_code, buffer[n].rate); + char category_code_desc[MAX_LEN_LONG_DESC]; + strops::format(category_code_desc, MAX_LEN_LONG_DESC, "taxrate.code.%s", buffer[n].internal_code); + strops::format(rate_str_buf, MAX_LEN_LONG_DESC, "%s", locale::get(category_code_desc)); if (ImGui::Selectable(rate_str_buf, is_selected)) { selected_tax_rate_index = n; @@ -391,7 +383,7 @@ namespace ImGui } if (selected_tax_rate_index != -1) { - strops::copy(tax_rate_id, buffer[selected_tax_rate_index].id, MAX_LEN_ID); + strops::copy(tax_internal_code, buffer[selected_tax_rate_index].internal_code, MAX_LEN_SHORT_DESC); } memops::unalloc(buffer); diff --git a/src/ui/ui_expenses.cpp b/src/ui/ui_expenses.cpp index b3c878a..6aa6e96 100644 --- a/src/ui/ui_expenses.cpp +++ b/src/ui/ui_expenses.cpp @@ -36,7 +36,7 @@ static billing_item* invoice_items_buffer = 0; void draw_addressee_form_ex(delivery_info* buffer, bool viewing_only = false); void draw_contact_form_ex(contact* buffer, bool viewing_only = false, bool with_autocomplete = false); -void draw_invoice_items_form(invoice* invoice); +void draw_invoice_items_form(invoice* invoice, bool outgoing = true); void ui::destroy_expenses() { @@ -134,7 +134,7 @@ static void draw_expense_form(invoice* buffer, bool viewing_only = false) administration::invoice_set_currency(buffer, buffer->currency); } - draw_invoice_items_form(buffer); + draw_invoice_items_form(buffer, false); if (viewing_only) ImGui::EndDisabled(); } diff --git a/src/ui/ui_invoices.cpp b/src/ui/ui_invoices.cpp index fbc6eb0..4ae1669 100644 --- a/src/ui/ui_invoices.cpp +++ b/src/ui/ui_invoices.cpp @@ -49,7 +49,7 @@ void ui::setup_invoices() invoice_items_buffer = (billing_item*)memops::alloc(sizeof(billing_item) * invoice_items_count); } -void draw_invoice_items_form(invoice* invoice) +void draw_invoice_items_form(invoice* invoice, bool outgoing) { billing_item* buffer = invoice_items_buffer; u32 invoice_items = administration::billing_item_get_all_for_invoice(invoice, buffer); @@ -110,7 +110,7 @@ void draw_invoice_items_form(invoice* invoice) ImGui::TableSetColumnIndex(6); ImGui::PushItemWidth(-1); - ImGui::FormTaxRateCombo(item.tax_rate_id, invoice->customer.address.country_code, invoice->supplier.address.country_code, valid & A_ERR_MISSING_TAX_RATE); + ImGui::FormTaxRateCombo(item.tax_internal_code, outgoing, valid & A_ERR_MISSING_TAX_RATE); ImGui::PopItemWidth(); @@ -243,7 +243,7 @@ static void draw_invoice_form(invoice* buffer, bool viewing_only = false) administration::invoice_set_currency(buffer, buffer->currency); } - draw_invoice_items_form(buffer); + draw_invoice_items_form(buffer, true); if (viewing_only) ImGui::EndDisabled(); } |
