diff options
Diffstat (limited to 'src/ui/ui_invoices.cpp')
| -rw-r--r-- | src/ui/ui_invoices.cpp | 104 |
1 files changed, 5 insertions, 99 deletions
diff --git a/src/ui/ui_invoices.cpp b/src/ui/ui_invoices.cpp index 5dd2286..04b0da4 100644 --- a/src/ui/ui_invoices.cpp +++ b/src/ui/ui_invoices.cpp @@ -16,19 +16,15 @@ static view_state current_view_state = view_state::LIST; static invoice active_invoice = {0}; static invoice selected_for_removal = {0}; -cost_center* cost_center_list_buffer = 0; -country_tax_bracket* tax_bracket_list_buffer = 0; -project* project_list_buffer = 0; -billing_item* invoice_items_buffer = 0; +static country_tax_bracket* tax_bracket_list_buffer = 0; +static billing_item* invoice_items_buffer = 0; void ui_draw_address_form(address* buffer); void draw_contact_form_ex(contact* buffer, bool viewing_only = false, bool with_autocomplete = false, bool* on_autocomplete = 0); void ui_destroy_invoices() { - free(cost_center_list_buffer); free(tax_bracket_list_buffer); - free(project_list_buffer); free(invoice_items_buffer); } @@ -37,25 +33,17 @@ void ui_setup_invoices() current_view_state = view_state::LIST; active_invoice = administration_invoice_create_empty(); - u32 costcenter_count = administration_cost_center_count(); - cost_center_list_buffer = (cost_center*) malloc(sizeof(cost_center) * costcenter_count); - u32 tax_bracket_count = administration_tax_bracket_count(); tax_bracket_list_buffer = (country_tax_bracket*) malloc(sizeof(country_tax_bracket) * tax_bracket_count); - u32 project_count = administration_project_count(); - project_list_buffer = (project*) malloc(sizeof(project) * project_count); - u32 invoice_items_count = MAX_BILLING_ITEMS; invoice_items_buffer = (billing_item*)malloc(sizeof(billing_item) * invoice_items_count); } -void draw_tax_bracket_selector(char* tax_bracket_id) +void draw_tax_bracket_selector(char* tax_bracket_id, country_tax_bracket* buffer, char* country_code) { country_tax_bracket* selected_tax_bracket = NULL; - - country_tax_bracket* buffer = tax_bracket_list_buffer; - u32 tax_bracket_count = administration_tax_bracket_get_by_country(buffer, administration_company_info_get().address.country_code); + u32 tax_bracket_count = administration_tax_bracket_get_by_country(buffer, country_code); // Select tax bracket by given id. if (strlen(tax_bracket_id) > 0) @@ -155,81 +143,6 @@ bool draw_currency_selector(char* currency) return result; } -void draw_costcenter_selector(char* costcenter_id) -{ - cost_center* selected_costcenter = NULL; - - cost_center* buffer = cost_center_list_buffer; - u32 costcenter_count = administration_cost_center_get_all(buffer); - - // Select cost center by given id. - if (strlen(costcenter_id) > 0) - { - for (u32 i = 0; i < costcenter_count; i++) - { - if (strcmp(buffer[i].id, costcenter_id) == 0) - { - selected_costcenter = &buffer[i]; - break; - } - } - } - - int selected_costcenter_index = -1; - if (ImGui::BeginCombo(localize("invoice.form.costcenter"), selected_costcenter == NULL ? NULL : localize(selected_costcenter->description))) - { - for (u32 n = 0; n < costcenter_count; n++) - { - bool is_selected = selected_costcenter && strcmp(selected_costcenter->id, buffer[n].id) == 0; - if (ImGui::Selectable(localize(buffer[n].description), is_selected)) { - selected_costcenter_index = n; - } - } - ImGui::EndCombo(); - } - - if (selected_costcenter_index != -1) { - strops_copy(costcenter_id, buffer[selected_costcenter_index].id, MAX_LEN_ID); - } -} - -void draw_project_selector(char* project_id) -{ - project* selected_project = NULL; - project* buffer = project_list_buffer; - u32 project_count = administration_project_get_all(buffer); - - // Select project by given id. - if (strlen(project_id) > 0) - { - for (u32 i = 0; i < project_count; i++) - { - if (strcmp(buffer[i].id, project_id) == 0) - { - selected_project = &buffer[i]; - break; - } - } - } - - int selected_project_index = -1; - if (ImGui::BeginCombo(localize("invoice.form.project"), selected_project == NULL ? NULL : selected_project->description)) - { - for (u32 n = 0; n < project_count; n++) - { - bool is_selected = selected_project && strcmp(selected_project->id, buffer[n].id) == 0; - if (ImGui::Selectable(buffer[n].description, is_selected)) { - selected_project_index = n; - } - } - ImGui::EndCombo(); - } - - if (selected_project_index != -1) { - strops_copy(project_id, buffer[selected_project_index].id, MAX_LEN_ID); - } -} - static void draw_invoice_items_form(invoice* invoice) { billing_item* buffer = invoice_items_buffer; @@ -320,7 +233,7 @@ static void draw_invoice_items_form(invoice* invoice) ImGui::TableSetColumnIndex(6); ImGui::PushItemWidth(-1); - draw_tax_bracket_selector(item.tax_bracket_id); + draw_tax_bracket_selector(item.tax_bracket_id, tax_bracket_list_buffer, administration_company_info_get().address.country_code); ImGui::PopItemWidth(); ImGui::TableSetColumnIndex(7); @@ -423,13 +336,6 @@ static void draw_invoice_form(invoice* buffer, bool viewing_only = false) } ImGui::Separator(); - // 9. Project selection - //draw_project_selector(buffer->project_id); - - // 10. Cost center selection - //draw_costcenter_selector(buffer->cost_center_id); - //ImGui::Separator(); - ImGui::Spacing(); ImGui::Spacing(); ImGui::Spacing(); |
