summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2025-09-20 20:25:14 +0200
committerAldrik Ramaekers <aldrikboy@gmail.com>2025-09-20 20:25:14 +0200
commit946a0c939c0cb7c28c9af9b7e4e2b20c45dd3702 (patch)
treec0d33801ecff3edb15f2e369e7aeeb2514dd73eb /src/ui
parent9a16fd2cf0bca13d8a3015da89833db2230b391f (diff)
billing item validation
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/imgui_extensions.cpp30
-rw-r--r--src/ui/ui_expenses.cpp2
-rw-r--r--src/ui/ui_invoices.cpp7
3 files changed, 33 insertions, 6 deletions
diff --git a/src/ui/imgui_extensions.cpp b/src/ui/imgui_extensions.cpp
index 1875c22..8485dbf 100644
--- a/src/ui/imgui_extensions.cpp
+++ b/src/ui/imgui_extensions.cpp
@@ -9,6 +9,19 @@
namespace ImGui
{
+ void InputTextWithError(const char* text, char* buffer, size_t buf_size, bool has_error)
+ {
+ if (has_error) {
+ ImGui::PushStyleColor(ImGuiCol_Border, COLOR_ERROR_OUTLINE);
+ ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.5f);
+ }
+ ImGui::InputText(text, buffer, buf_size);
+ if (has_error) {
+ ImGui::PopStyleVar();
+ ImGui::PopStyleColor();
+ }
+ }
+
void FormInputTextWithErrorHint(const char* hint, char* buffer, size_t buf_size, bool has_error)
{
float widthAvailable = ImGui::GetContentRegionAvail().x;
@@ -272,7 +285,7 @@ namespace ImGui
free(buffer);
}
- void FormTaxRateCombo(char* tax_rate_id, char* orig_country, char* dest_country)
+ void FormTaxRateCombo(char* tax_rate_id, char* orig_country, char* dest_country, bool has_error)
{
u32 tax_rate_count = administration_tax_rate_count();
tax_rate* buffer = (tax_rate*) malloc(sizeof(tax_rate) * tax_rate_count);
@@ -307,6 +320,11 @@ namespace ImGui
else snprintf(rate_str_buf, 40, "%s/%.1f%%", selected_tax_rate->country_code, selected_tax_rate->rate);
}
+ if (has_error) {
+ ImGui::PushStyleColor(ImGuiCol_Border, COLOR_ERROR_OUTLINE);
+ ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.5f);
+ }
+
if (ImGui::BeginCombo("##Tax Bracket", rate_str_buf))
{
for (u32 n = 0; n < tax_rate_count; n++)
@@ -326,6 +344,11 @@ namespace ImGui
}
ImGui::EndCombo();
}
+
+ if (has_error) {
+ ImGui::PopStyleVar();
+ ImGui::PopStyleColor();
+ }
if (selected_tax_rate_index != -1) {
strops_copy(tax_rate_id, buffer[selected_tax_rate_index].id, MAX_LEN_ID);
@@ -392,7 +415,10 @@ namespace ImGui
void FormToggleCombo(bool *buffer, char* option1, char* option2)
{
const char* items[] = { option1, option2 };
- if (ImGui::BeginCombo("Mode", items[*buffer])) {
+
+ char ID[MAX_LEN_LONG_DESC];
+ snprintf(ID, MAX_LEN_LONG_DESC, "Mode##%p", buffer);
+ if (ImGui::BeginCombo(ID, items[*buffer])) {
for (int n = 0; n < 2; n++) {
bool is_selected = (n == (int)*buffer);
if (ImGui::Selectable(items[n], is_selected)) {
diff --git a/src/ui/ui_expenses.cpp b/src/ui/ui_expenses.cpp
index 7d94eaf..7dd5add 100644
--- a/src/ui/ui_expenses.cpp
+++ b/src/ui/ui_expenses.cpp
@@ -204,7 +204,7 @@ static void ui_draw_expenses_list()
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0); ImGui::Text(c.sequential_number);
ImGui::TableSetColumnIndex(1); ImGui::Text(c.supplier.name);
- ImGui::TableSetColumnIndex(2); ImGui::Text(c.addressee.name);
+ ImGui::TableSetColumnIndex(2); ImGui::Text(c.customer.name);
struct tm *lt = localtime(&c.issued_at);
char buf[80];
diff --git a/src/ui/ui_invoices.cpp b/src/ui/ui_invoices.cpp
index f061e3f..6c3e229 100644
--- a/src/ui/ui_invoices.cpp
+++ b/src/ui/ui_invoices.cpp
@@ -73,6 +73,7 @@ void draw_invoice_items_form(invoice* invoice)
for (u32 i = 0; i < invoice_items; i++)
{
billing_item item = buffer[i];
+ a_err valid = administration_billing_item_is_valid(item);
ImGui::TableNextRow();
@@ -92,7 +93,7 @@ void draw_invoice_items_form(invoice* invoice)
ImGui::TableSetColumnIndex(2);
ImGui::PushItemWidth(-1);
- ImGui::InputText("##desc", item.description, IM_ARRAYSIZE(item.description));
+ ImGui::InputTextWithError("##desc", item.description, IM_ARRAYSIZE(item.description), valid & A_ERR_MISSING_DESCRIPTION);
ImGui::PopItemWidth();
ImGui::TableSetColumnIndex(3);
@@ -104,14 +105,14 @@ void draw_invoice_items_form(invoice* invoice)
ImGui::InputFloat("##discount", &item.discount, 0.0f, 0.0f, "%.2f");
ImGui::SameLine();
- ImGui::FormToggleCombo(&item.amount_is_percentage, item.currency, "%");
+ ImGui::FormToggleCombo(&item.discount_is_percentage, item.currency, "%");
ImGui::TableSetColumnIndex(5);
ImGui::Text("%.2f %s", item.net, item.currency);
ImGui::TableSetColumnIndex(6);
ImGui::PushItemWidth(-1);
- ImGui::FormTaxRateCombo(item.tax_rate_id, invoice->customer.address.country_code, invoice->supplier.address.country_code);
+ ImGui::FormTaxRateCombo(item.tax_rate_id, invoice->customer.address.country_code, invoice->supplier.address.country_code, valid & A_ERR_MISSING_TAX_RATE);
ImGui::PopItemWidth();