diff options
| -rw-r--r-- | include/ui.hpp | 4 | ||||
| -rw-r--r-- | src/ui/imgui_extensions.cpp | 14 | ||||
| -rw-r--r-- | src/ui/ui_contacts.cpp | 24 | ||||
| -rw-r--r-- | src/ui/ui_projects.cpp | 2 | ||||
| -rw-r--r-- | tests/administration_rw_tests.cpp | 1 | ||||
| -rw-r--r-- | tests/administration_validation_tests.cpp | 43 | ||||
| -rw-r--r-- | tests/peppol_write_tests.cpp | 37 |
7 files changed, 60 insertions, 65 deletions
diff --git a/include/ui.hpp b/include/ui.hpp index d6c5fad..3a8ce66 100644 --- a/include/ui.hpp +++ b/include/ui.hpp @@ -98,8 +98,8 @@ namespace ImGui int TextInputWithAutocomplete(const char* hint, char* buffer, size_t buf_size, char** suggestions, int suggestion_count, bool has_error); void FormContactAutocomplete(contact* buffer, bool has_error); - void FormInputTextWithErrorHint(const char* hint, void* data, char* buffer, size_t buf_size, bool has_error); - void FormCountryCombo(void* data, char* buffer, size_t buf_size); + void FormInputTextWithErrorHint(const char* hint, char* buffer, size_t buf_size, bool has_error); + void FormCountryCombo(char* buffer, size_t buf_size); void FormContactTypeCombo(contact_type* type); void FormCostCenterCombo(char* costcenter_id); void FormProjectCombo(char* project_id); diff --git a/src/ui/imgui_extensions.cpp b/src/ui/imgui_extensions.cpp index 5fdc3a7..1875c22 100644 --- a/src/ui/imgui_extensions.cpp +++ b/src/ui/imgui_extensions.cpp @@ -9,19 +9,16 @@ namespace ImGui { - void FormInputTextWithErrorHint(const char* hint, void* data, char* buffer, size_t buf_size, bool has_error) + void FormInputTextWithErrorHint(const char* hint, char* buffer, size_t buf_size, bool has_error) { float widthAvailable = ImGui::GetContentRegionAvail().x; ImGui::SetNextItemWidth(widthAvailable*0.5f); - char id[MAX_LEN_LONG_DESC]; - snprintf(id, sizeof(id), "%s##%p", hint, data); - if (has_error) { ImGui::PushStyleColor(ImGuiCol_Border, COLOR_ERROR_OUTLINE); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.5f); } - ImGui::InputTextWithHint(id, hint, buffer, buf_size); + ImGui::InputTextWithHint(hint, hint, buffer, buf_size); if (has_error) { ImGui::PopStyleVar(); ImGui::PopStyleColor(); @@ -32,10 +29,9 @@ namespace ImGui } } - void FormCountryCombo(void* data, char* buffer, size_t buf_size) + void FormCountryCombo(char* buffer, size_t buf_size) { const char* selected_country = 0; - char id[MAX_LEN_LONG_DESC]; float widthAvailable = ImGui::GetContentRegionAvail().x; ImGui::SetNextItemWidth(widthAvailable*0.5f); @@ -58,14 +54,12 @@ namespace ImGui bool has_a_selection = selected_country != 0; int selected_country_index = -1; - snprintf(id, sizeof(id), "%s##%p", localize("contact.form.country"), data); - if (!has_a_selection) { ImGui::PushStyleColor(ImGuiCol_Border, COLOR_ERROR_OUTLINE); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.5f); } - if (ImGui::BeginCombo(id, selected_country)) + if (ImGui::BeginCombo(localize("contact.form.country"), selected_country)) { for (int n = 0; n < country_count; n++) { diff --git a/src/ui/ui_contacts.cpp b/src/ui/ui_contacts.cpp index b471f58..549273d 100644 --- a/src/ui/ui_contacts.cpp +++ b/src/ui/ui_contacts.cpp @@ -32,13 +32,13 @@ static contact active_contact; void ui_draw_address_form(address* buffer, a_err last_err) { - ImGui::FormInputTextWithErrorHint(localize("contact.form.address1"), buffer, buffer->address1, IM_ARRAYSIZE(buffer->address1), last_err & A_ERR_MISSING_ADDRESS1); - ImGui::FormInputTextWithErrorHint(localize("contact.form.address2"), buffer, buffer->address2, IM_ARRAYSIZE(buffer->address2), 0); - ImGui::FormInputTextWithErrorHint(localize("contact.form.city"), buffer, buffer->city, IM_ARRAYSIZE(buffer->city), last_err & A_ERR_MISSING_CITY); - ImGui::FormInputTextWithErrorHint(localize("contact.form.postal"), buffer, buffer->postal, IM_ARRAYSIZE(buffer->postal), last_err & A_ERR_MISSING_POSTAL); - ImGui::FormInputTextWithErrorHint(localize("contact.form.region"), buffer, buffer->region, IM_ARRAYSIZE(buffer->region), 0); + ImGui::FormInputTextWithErrorHint(localize("contact.form.address1"), buffer->address1, IM_ARRAYSIZE(buffer->address1), last_err & A_ERR_MISSING_ADDRESS1); + ImGui::FormInputTextWithErrorHint(localize("contact.form.address2"), buffer->address2, IM_ARRAYSIZE(buffer->address2), 0); + ImGui::FormInputTextWithErrorHint(localize("contact.form.city"), buffer->city, IM_ARRAYSIZE(buffer->city), last_err & A_ERR_MISSING_CITY); + ImGui::FormInputTextWithErrorHint(localize("contact.form.postal"), buffer->postal, IM_ARRAYSIZE(buffer->postal), last_err & A_ERR_MISSING_POSTAL); + ImGui::FormInputTextWithErrorHint(localize("contact.form.region"), buffer->region, IM_ARRAYSIZE(buffer->region), 0); - ImGui::FormCountryCombo(buffer, buffer->country_code, IM_ARRAYSIZE(buffer->country_code)); + ImGui::FormCountryCombo(buffer->country_code, IM_ARRAYSIZE(buffer->country_code)); } void ui_setup_contacts() @@ -60,7 +60,7 @@ void draw_contact_form_ex(contact* buffer, bool viewing_only = false, bool with_ if (!viewing_only) ImGui::EndDisabled(); if (with_autocomplete) ImGui::FormContactAutocomplete(buffer, last_err & A_ERR_MISSING_NAME); - else ImGui::FormInputTextWithErrorHint(localize("contact.form.fullname"), buffer, buffer->name, IM_ARRAYSIZE(buffer->name), last_err & A_ERR_MISSING_NAME); + else ImGui::FormInputTextWithErrorHint(localize("contact.form.fullname"), buffer->name, IM_ARRAYSIZE(buffer->name), last_err & A_ERR_MISSING_NAME); ui_draw_address_form(&buffer->address, last_err); @@ -69,13 +69,13 @@ void draw_contact_form_ex(contact* buffer, bool viewing_only = false, bool with_ // Fields only required for businesses. if (buffer->type == contact_type::CONTACT_BUSINESS) { - ImGui::FormInputTextWithErrorHint(localize("contact.form.taxnumber"), buffer, buffer->taxid, IM_ARRAYSIZE(buffer->taxid), last_err & A_ERR_MISSING_TAXID); - ImGui::FormInputTextWithErrorHint(localize("contact.form.businessnumber"), buffer, buffer->businessid, IM_ARRAYSIZE(buffer->businessid), last_err & A_ERR_MISSING_BUSINESSID); + ImGui::FormInputTextWithErrorHint(localize("contact.form.taxnumber"), buffer->taxid, IM_ARRAYSIZE(buffer->taxid), last_err & A_ERR_MISSING_TAXID); + ImGui::FormInputTextWithErrorHint(localize("contact.form.businessnumber"), buffer->businessid, IM_ARRAYSIZE(buffer->businessid), last_err & A_ERR_MISSING_BUSINESSID); } - ImGui::FormInputTextWithErrorHint(localize("contact.form.email"), buffer, buffer->email, IM_ARRAYSIZE(buffer->email), last_err & A_ERR_MISSING_EMAIL); - ImGui::FormInputTextWithErrorHint(localize("contact.form.phonenumber"), buffer, buffer->phone_number, IM_ARRAYSIZE(buffer->phone_number), 0); - ImGui::FormInputTextWithErrorHint(localize("contact.form.bankaccount"), buffer, buffer->bank_account, IM_ARRAYSIZE(buffer->bank_account), 0); + ImGui::FormInputTextWithErrorHint(localize("contact.form.email"), buffer->email, IM_ARRAYSIZE(buffer->email), last_err & A_ERR_MISSING_EMAIL); + ImGui::FormInputTextWithErrorHint(localize("contact.form.phonenumber"), buffer->phone_number, IM_ARRAYSIZE(buffer->phone_number), 0); + ImGui::FormInputTextWithErrorHint(localize("contact.form.bankaccount"), buffer->bank_account, IM_ARRAYSIZE(buffer->bank_account), 0); if (viewing_only) ImGui::EndDisabled(); ImGui::PopID(); diff --git a/src/ui/ui_projects.cpp b/src/ui/ui_projects.cpp index 37cf5d8..e7fa86f 100644 --- a/src/ui/ui_projects.cpp +++ b/src/ui/ui_projects.cpp @@ -54,7 +54,7 @@ static void draw_project_form() ImGui::InputText(localize("project.form.identifier"), active_project.id, IM_ARRAYSIZE(active_project.id)); if (!viewing_only) ImGui::EndDisabled(); - ImGui::FormInputTextWithErrorHint(localize("project.form.description"), &active_project, active_project.description, IM_ARRAYSIZE(active_project.description), last_err & A_ERR_MISSING_DESCRIPTION); + ImGui::FormInputTextWithErrorHint(localize("project.form.description"), active_project.description, IM_ARRAYSIZE(active_project.description), last_err & A_ERR_MISSING_DESCRIPTION); if (viewing_only) ImGui::EndDisabled(); diff --git a/tests/administration_rw_tests.cpp b/tests/administration_rw_tests.cpp index aed3c52..ba5507e 100644 --- a/tests/administration_rw_tests.cpp +++ b/tests/administration_rw_tests.cpp @@ -135,6 +135,7 @@ TEST _administration_rw_contact(void) strops_copy(pw.address.country_code, "FR", sizeof(pw.address.country_code)); strops_copy(pw.address.city, "Paris", sizeof(pw.address.city)); strops_copy(pw.address.postal, "12345", sizeof(pw.address.postal)); + strops_copy(pw.email, "test@test.com", sizeof(pw.email)); pw.type = contact_type::CONTACT_CONSUMER; count = administration_contact_count(); diff --git a/tests/administration_validation_tests.cpp b/tests/administration_validation_tests.cpp index 4b88e37..f307d2d 100644 --- a/tests/administration_validation_tests.cpp +++ b/tests/administration_validation_tests.cpp @@ -208,16 +208,23 @@ TEST _administration_validate_costcenter_isvalid(void) // Contact ////////////////// -TEST _administration_validate_contact_add(void) +contact _create_test_contact() { - administration_create_empty(""); contact p1 = administration_contact_create_empty(); strops_copy(p1.name, "John Johnsson", sizeof(p1.name)); strops_copy(p1.address.address1, "Address 1", sizeof(p1.address.address1)); strops_copy(p1.address.country_code, "FR", sizeof(p1.address.country_code)); strops_copy(p1.address.city, "Paris", sizeof(p1.address.city)); strops_copy(p1.address.postal, "12345", sizeof(p1.address.postal)); + strops_copy(p1.email, "test@test.com", sizeof(p1.email)); p1.type = contact_type::CONTACT_CONSUMER; + return p1; +} + +TEST _administration_validate_contact_add(void) +{ + administration_create_empty(""); + contact p1 = _create_test_contact(); ASSERT_EQ(administration_contact_add(p1), A_ERR_SUCCESS); @@ -243,13 +250,7 @@ TEST _administration_validate_contact_import(void) { administration_create_empty(""); - contact p1 = administration_contact_create_empty(); - strops_copy(p1.name, "John Johnsson", sizeof(p1.name)); - strops_copy(p1.address.address1, "Address 1", sizeof(p1.address.address1)); - strops_copy(p1.address.country_code, "FR", sizeof(p1.address.country_code)); - strops_copy(p1.address.city, "Paris", sizeof(p1.address.city)); - strops_copy(p1.address.postal, "12345", sizeof(p1.address.postal)); - p1.type = contact_type::CONTACT_CONSUMER; + contact p1 = _create_test_contact(); ASSERT_EQ(administration_contact_import(p1), A_ERR_SUCCESS); @@ -275,13 +276,7 @@ TEST _administration_validate_contact_import(void) TEST _administration_validate_contact_update(void) { administration_create_empty(""); - contact p1 = administration_contact_create_empty(); - strops_copy(p1.name, "John Johnsson", sizeof(p1.name)); - strops_copy(p1.address.address1, "Address 1", sizeof(p1.address.address1)); - strops_copy(p1.address.country_code, "FR", sizeof(p1.address.country_code)); - strops_copy(p1.address.city, "Paris", sizeof(p1.address.city)); - strops_copy(p1.address.postal, "12345", sizeof(p1.address.postal)); - p1.type = contact_type::CONTACT_CONSUMER; + contact p1 = _create_test_contact(); ASSERT_EQ(administration_contact_add(p1), A_ERR_SUCCESS); ASSERT_EQ(administration_contact_update(p1), A_ERR_SUCCESS); @@ -316,13 +311,7 @@ TEST _administration_validate_contact_update(void) TEST _administration_validate_contact_remove(void) { administration_create_empty(""); - contact p1 = administration_contact_create_empty(); - strops_copy(p1.name, "John Johnsson", sizeof(p1.name)); - strops_copy(p1.address.address1, "Address 1", sizeof(p1.address.address1)); - strops_copy(p1.address.country_code, "FR", sizeof(p1.address.country_code)); - strops_copy(p1.address.city, "Paris", sizeof(p1.address.city)); - strops_copy(p1.address.postal, "12345", sizeof(p1.address.postal)); - p1.type = contact_type::CONTACT_CONSUMER; + contact p1 = _create_test_contact(); ASSERT_EQ(administration_contact_add(p1), A_ERR_SUCCESS); @@ -338,13 +327,7 @@ TEST _administration_validate_contact_remove(void) TEST _administration_validate_contact_isvalid(void) { administration_create_empty(""); - contact p1 = administration_contact_create_empty(); - strops_copy(p1.name, "John Johnsson", sizeof(p1.name)); - strops_copy(p1.address.address1, "Address 1", sizeof(p1.address.address1)); - strops_copy(p1.address.country_code, "FR", sizeof(p1.address.country_code)); - strops_copy(p1.address.city, "Paris", sizeof(p1.address.city)); - strops_copy(p1.address.postal, "12345", sizeof(p1.address.postal)); - p1.type = contact_type::CONTACT_CONSUMER; + contact p1 = _create_test_contact(); ASSERT_EQ(administration_contact_is_valid(p1), A_ERR_SUCCESS); ASSERT_EQ(administration_contact_is_valid(p1), A_ERR_SUCCESS); diff --git a/tests/peppol_write_tests.cpp b/tests/peppol_write_tests.cpp index e77f128..c00b53b 100644 --- a/tests/peppol_write_tests.cpp +++ b/tests/peppol_write_tests.cpp @@ -10,25 +10,21 @@ char* extract_dir = "build\\extracted"; static contact _create_nl_business() { contact pw = administration_contact_create_empty(); - strops_copy(pw.name, "John Johnsson", sizeof(pw.name)); + strops_copy(pw.name, "Piet Pinda", sizeof(pw.name)); strops_copy(pw.address.address1, "Address 1", sizeof(pw.address.address1)); strops_copy(pw.address.country_code, "NL", sizeof(pw.address.country_code)); strops_copy(pw.address.city, "Amsterdam", sizeof(pw.address.city)); strops_copy(pw.address.postal, "1234AA", sizeof(pw.address.postal)); strops_copy(pw.taxid, "T123", sizeof(pw.taxid)); strops_copy(pw.businessid, "B321", sizeof(pw.businessid)); + strops_copy(pw.email, "test@test.com", sizeof(pw.email)); pw.type = contact_type::CONTACT_BUSINESS; return pw; } static contact _create_nl_consumer() { - contact pw = administration_contact_create_empty(); - strops_copy(pw.name, "Hans Klok", sizeof(pw.name)); - strops_copy(pw.address.address1, "Address 2", sizeof(pw.address.address1)); - strops_copy(pw.address.country_code, "NL", sizeof(pw.address.country_code)); - strops_copy(pw.address.city, "Amsterdam", sizeof(pw.address.city)); - strops_copy(pw.address.postal, "4321AA", sizeof(pw.address.postal)); + contact pw = _create_nl_business(); pw.type = contact_type::CONTACT_CONSUMER; return pw; } @@ -44,9 +40,28 @@ static billing_item _create_bi1(invoice *inv) item.discount_is_percentage = 0; tax_rate buffer[20]; - char* country_codes[2] = {inv->supplier.address.country_code, inv->customer.address.country_code}; - administration_tax_rate_get_by_country(buffer, 2, country_codes); - tax_rate rand_rate = buffer[0]; + char* _country_codes[2] = {inv->supplier.address.country_code, inv->customer.address.country_code}; + u32 tax_rate_count = administration_tax_rate_get_by_country(buffer, 2, _country_codes); + tax_rate rand_rate = buffer[tax_rate_count-1]; + strops_copy(item.tax_rate_id, rand_rate.id, MAX_LEN_ID); + + return item; +} + +static billing_item _create_bi2(invoice *inv) +{ + billing_item item = administration_billing_item_create_empty(); + item.amount = 2; + item.amount_is_percentage = 0; + strops_copy(item.description, "Soap", MAX_LEN_LONG_DESC); + item.net_per_item = 5.00f; + item.discount = 5.0f; + item.discount_is_percentage = 1; + + tax_rate buffer[20]; + char* _country_codes[2] = {inv->supplier.address.country_code, inv->customer.address.country_code}; + u32 tax_rate_count = administration_tax_rate_get_by_country(buffer, 2, _country_codes); + tax_rate rand_rate = buffer[tax_rate_count-1]; strops_copy(item.tax_rate_id, rand_rate.id, MAX_LEN_ID); return item; @@ -125,6 +140,7 @@ TEST _peppol_write_nl2nl_b2b(void) inv.expires_at = inv.issued_at + 1000; administration_billing_item_add_to_invoice(&inv, _create_bi1(&inv)); + administration_billing_item_add_to_invoice(&inv, _create_bi2(&inv)); ASSERT_EQ(administration_invoice_add(&inv), A_ERR_SUCCESS); if (_test_peppol_file(inv.id)) { PASS(); } else { FAIL(); } @@ -145,6 +161,7 @@ TEST _peppol_write_nl2nl_b2c(void) inv.expires_at = inv.issued_at + 1000; administration_billing_item_add_to_invoice(&inv, _create_bi1(&inv)); + administration_billing_item_add_to_invoice(&inv, _create_bi2(&inv)); ASSERT_EQ(administration_invoice_add(&inv), A_ERR_SUCCESS); if (_test_peppol_file(inv.id)) { PASS(); } else { FAIL(); } |
