diff options
Diffstat (limited to 'src/ui/ui_invoices.cpp')
| -rw-r--r-- | src/ui/ui_invoices.cpp | 135 |
1 files changed, 117 insertions, 18 deletions
diff --git a/src/ui/ui_invoices.cpp b/src/ui/ui_invoices.cpp index 8ee099c..2b5a834 100644 --- a/src/ui/ui_invoices.cpp +++ b/src/ui/ui_invoices.cpp @@ -1,7 +1,9 @@ +#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <time.h> #include "ImGuiDatePicker/ImGuiDatePicker.hpp" +//#include "tinyfiledialogs/tinyfiledialogs.h" #include "strops.hpp" #include "ui.hpp" @@ -9,8 +11,10 @@ #include "administration.hpp" #include "locales.hpp" +void ui_draw_address_form(address* buffer); + static view_state current_view_state = view_state::LIST; -static invoice active_invoice; +static invoice active_invoice = {0}; void draw_contact_form_ex(contact* buffer, bool viewing_only = false, bool with_autocomplete = false, bool* on_autocomplete = 0); @@ -20,6 +24,88 @@ void ui_setup_invoices() active_invoice = administration_create_empty_invoice(); } +void draw_costcenter_selector(char* costcenter_id) +{ + cost_center* selected_costcenter = NULL; + + u32 costcenter_count = administration_get_cost_center_count(); + cost_center* buffer = (cost_center*) malloc(sizeof(cost_center) * costcenter_count); + costcenter_count = administration_get_cost_centers(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("Cost center", 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, 16); + } + + free(buffer); +} + +void draw_project_selector(char* project_id) +{ + project* selected_project = NULL; + + u32 project_count = administration_get_project_count(); + project* buffer = (project*) malloc(sizeof(project) * project_count); + project_count = administration_get_all_projects(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("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, 16); + } + + free(buffer); +} + void draw_invoice_form(invoice* buffer, bool viewing_only = false) { //float widthAvailable = ImGui::GetContentRegionAvail().x; @@ -36,20 +122,7 @@ void draw_invoice_form(invoice* buffer, bool viewing_only = false) // 3. Supplier (you) ImGui::Text("Supplier: %s", buffer->supplier.name); - ImGui::Separator(); - - // 4. Customer information - ImGui::Text("Customer information"); - bool on_autocomplete; - draw_contact_form_ex(&buffer->customer, false, true, &on_autocomplete); - - if (on_autocomplete) { - strops_copy(buffer->customer_id, buffer->customer.id, sizeof(buffer->customer_id)); - } - - ImGui::Separator(); - - // 5. Invoice issued at + // 6. Invoice issued at ImGui::BeginDisabled(); tm issued_at_date = *gmtime(&buffer->issued_at); if (ImGui::DatePicker("##issuedAt", issued_at_date)) @@ -60,7 +133,7 @@ void draw_invoice_form(invoice* buffer, bool viewing_only = false) ImGui::Text("Invoice issued at"); ImGui::EndDisabled(); - // 6. Invoice expires at + // 7. Invoice expires at ImGui::BeginDisabled(); tm expires_at_date = *gmtime(&buffer->expires_at); if (ImGui::DatePicker("##expiresAt", expires_at_date)) @@ -71,7 +144,7 @@ void draw_invoice_form(invoice* buffer, bool viewing_only = false) ImGui::Text("Invoice expires at"); ImGui::EndDisabled(); - // 7. Product/service delivered at + // 8. Product/service delivered at tm delivered_at_date = *gmtime(&buffer->delivered_at); if (ImGui::DatePicker("##deliveredAt", delivered_at_date)) { @@ -80,11 +153,37 @@ void draw_invoice_form(invoice* buffer, bool viewing_only = false) ImGui::SameLine(); ImGui::Text("Product/service delivered at"); + ImGui::Separator(); + + // 4. Customer information + ImGui::Text("Billing information"); + bool on_autocomplete; + draw_contact_form_ex(&buffer->customer, false, true, &on_autocomplete); + + if (on_autocomplete) { + strops_copy(buffer->customer_id, buffer->customer.id, sizeof(buffer->customer_id)); + } + + // 5. (optional) shipping address. + static bool shipping_is_billing_addr = true; + ImGui::Checkbox("Shipping information is billing information", &shipping_is_billing_addr); + if (!shipping_is_billing_addr) { + ImGui::Spacing(); + ImGui::Text("Shipping information"); + ui_draw_address_form(&buffer->shipping_address); + } + ImGui::Separator(); + + // 9. Project selection + draw_project_selector(buffer->project_id); + + // 10. Cost center selection + draw_costcenter_selector(buffer->cost_center_id); + //ImGui::SetNextItemWidth(widthAvailable*0.5f); //ImGui::InputTextWithHint("Invoice number", "Invoice number", buffer->sequential_number, IM_ARRAYSIZE(buffer->sequential_number)); //ImGui::SameLine();ui_helper_draw_required_tag(); - if (viewing_only) ImGui::EndDisabled(); } |
