diff options
Diffstat (limited to 'src/ui/ui_expenses.cpp')
| -rw-r--r-- | src/ui/ui_expenses.cpp | 123 |
1 files changed, 8 insertions, 115 deletions
diff --git a/src/ui/ui_expenses.cpp b/src/ui/ui_expenses.cpp index b195442..7d94eaf 100644 --- a/src/ui/ui_expenses.cpp +++ b/src/ui/ui_expenses.cpp @@ -32,94 +32,13 @@ static view_state current_view_state = view_state::LIST; static invoice active_invoice = {0}; static invoice selected_for_removal = {0}; -static cost_center* cost_center_list_buffer = 0; -static tax_rate* tax_rate_list_buffer = 0; -static project* project_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 draw_tax_rate_selector(char* tax_rate_id, tax_rate* buffer, char* orig_country, char* dest_country); -bool draw_currency_selector(char* currency); -void draw_invoice_items_form(invoice* invoice, bool is_outgoing); - -void draw_costcenter_selector(char* costcenter_id, cost_center* buffer) -{ - cost_center* selected_costcenter = NULL; - 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* buffer) -{ - project* selected_project = NULL; - 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); - } -} +void draw_contact_form_ex(contact* buffer, bool viewing_only = false, bool with_autocomplete = false); +void draw_invoice_items_form(invoice* invoice); void ui_destroy_expenses() { - free(cost_center_list_buffer); - free(tax_rate_list_buffer); - free(project_list_buffer); free(invoice_items_buffer); } @@ -128,15 +47,6 @@ void ui_setup_expenses() 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_rate_count = administration_tax_rate_count(); - tax_rate_list_buffer = (tax_rate*) malloc(sizeof(tax_rate) * tax_rate_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); } @@ -145,17 +55,9 @@ static void draw_expense_form(invoice* buffer, bool viewing_only = false) { if (viewing_only) ImGui::BeginDisabled(); - // 1. Identifier - //ImGui::SetNextItemWidth(widthAvailable*0.2f); - //ImGui::InputText(localize("contact.form.identifier"), buffer->id, IM_ARRAYSIZE(buffer->id)); - - // 2. Sequential number ImGui::Text("%s: %s", localize("invoice.form.invoicenumber"), buffer->sequential_number); - - // 3. Billed to (you) ImGui::Text("%s: %s", localize("invoice.form.billedTo"), buffer->customer.name); - // 4. Invoice issued at tm issued_at_date = *gmtime(&buffer->issued_at); if (ImGui::DatePicker("##issuedAt", issued_at_date)) { @@ -164,7 +66,6 @@ static void draw_expense_form(invoice* buffer, bool viewing_only = false) ImGui::SameLine(); ImGui::Text(localize("invoice.form.issuedat")); - // 5. Invoice expires at tm expires_at_date = *gmtime(&buffer->expires_at); if (ImGui::DatePicker("##expiresAt", expires_at_date)) { @@ -173,7 +74,6 @@ static void draw_expense_form(invoice* buffer, bool viewing_only = false) ImGui::SameLine(); ImGui::Text(localize("invoice.form.expiresat")); - // 6. Product/service delivered at tm delivered_at_date = *gmtime(&buffer->delivered_at); if (ImGui::DatePicker("##deliveredAt", delivered_at_date)) { @@ -184,31 +84,26 @@ static void draw_expense_form(invoice* buffer, bool viewing_only = false) ImGui::Separator(); - // 7. Supplier information ImGui::Text(localize("invoice.form.supplier")); - draw_contact_form_ex(&buffer->supplier, false, true, 0); + draw_contact_form_ex(&buffer->supplier, false, true); - // 8. (optional) shipping address. ImGui::Checkbox(localize("invoice.form.triangulation"), &buffer->is_triangulation); if (buffer->is_triangulation) { ImGui::Spacing(); ImGui::Text(localize("invoice.form.shippinginformation")); - draw_contact_form_ex(&buffer->addressee, 0,0,0); + draw_contact_form_ex(&buffer->addressee, 0,0); } ImGui::Separator(); - // 9. Project selection - draw_project_selector(buffer->project_id, project_list_buffer); + ImGui::FormProjectCombo(buffer->project_id); + ImGui::FormCostCenterCombo(buffer->cost_center_id); - // 10. Cost center selection - draw_costcenter_selector(buffer->cost_center_id, cost_center_list_buffer); ImGui::Separator(); ImGui::Spacing(); ImGui::Spacing(); ImGui::Spacing(); - // 11. New billing item button. bool max_items_reached = administration_billing_item_count(buffer) >= MAX_BILLING_ITEMS; if (max_items_reached) ImGui::BeginDisabled(); if (ImGui::Button(localize(localize("invoice.form.add")))) @@ -218,17 +113,15 @@ static void draw_expense_form(invoice* buffer, bool viewing_only = false) } if (max_items_reached) ImGui::EndDisabled(); - // 12. Dropdown for invoice currency. ImGui::SameLine(); ImGui::Text("| %s: ", localize("invoice.form.currency")); ImGui::SameLine(); - if (draw_currency_selector(buffer->currency)) + if (ImGui::FormCurrencyCombo(buffer->currency)) { administration_invoice_set_currency(buffer, buffer->currency); } - // 13. Invoice items form - draw_invoice_items_form(buffer, false); + draw_invoice_items_form(buffer); if (viewing_only) ImGui::EndDisabled(); } |
