summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2025-08-16 15:22:36 +0200
committerAldrik Ramaekers <aldrikboy@gmail.com>2025-08-16 15:22:36 +0200
commitb2a5ae0b5b628cca712bb80d485393800de34172 (patch)
treeb7e2e5afe7bbca1d6985762c7244ff9af5cc46c4
parentf0fc9fa21ad9efa47556d7a03aa2b13081028ac6 (diff)
refactor of administration api
-rw-r--r--include/administration.hpp89
-rw-r--r--src/ui/ui_contacts.cpp2
-rw-r--r--src/ui/ui_invoices.cpp6
-rw-r--r--src/ui/ui_settings.cpp2
4 files changed, 57 insertions, 42 deletions
diff --git a/include/administration.hpp b/include/administration.hpp
index e7cb9b0..e617166 100644
--- a/include/administration.hpp
+++ b/include/administration.hpp
@@ -3,26 +3,43 @@
#include "config.hpp"
#include "simclist.h"
+#define MAX_LEN_SEQ_NUM 16
+#define MAX_LEN_ID 16
+#define MAX_LEN_COUNTRY_CODE 3
+#define MAX_LEN_CODE 5
+#define MAX_LEN_ADDRESS 128
+#define MAX_LEN_FILENAME 255
+#define MAX_LEN_PATH 4096
+#define MAX_LEN_CURRENCY 8
+#define MAX_LEN_SHORT_DESC 32
+#define MAX_LEN_LONG_DESC 64
+#define MAX_LEN_EMAIL 64
+#define MAX_LEN_PHONE 16
+#define MAX_LEN_BANK 32
+#define MAX_LEN_TAXID 32
+#define MAX_LEN_BUSINESSID 32
+#define MAX_LEN_TAX_SECTION 16
+
typedef struct
{
- char id[16];
- char country_code[3];
+ char id[MAX_LEN_ID];
+ char country_code[MAX_LEN_COUNTRY_CODE];
float rate; // 0-100
- char description[32];
+ char description[MAX_LEN_SHORT_DESC];
} country_tax_bracket;
typedef struct
{
- char id[16];
- char code[5];
- char description[64];
+ char id[MAX_LEN_ID];
+ char code[MAX_LEN_CODE];
+ char description[MAX_LEN_LONG_DESC];
} cost_center;
typedef struct
{
- char address1[128];
- char address2[128];
- char country_code[3]; // 2 letter country code.
+ char address1[MAX_LEN_ADDRESS];
+ char address2[MAX_LEN_ADDRESS];
+ char country_code[MAX_LEN_COUNTRY_CODE]; // 2 letter country code.
} address;
typedef enum
@@ -33,15 +50,15 @@ typedef enum
typedef struct
{
- char id[16];
- char name[64];
+ char id[MAX_LEN_ID];
+ char name[MAX_LEN_LONG_DESC];
address address;
contact_type type;
- char taxid[32];
- char businessid[32];
- char email[64];
- char phone_number[16];
- char bank_account[32];
+ char taxid[MAX_LEN_TAXID];
+ char businessid[MAX_LEN_TAXID];
+ char email[MAX_LEN_EMAIL];
+ char phone_number[MAX_LEN_PHONE];
+ char bank_account[MAX_LEN_BANK];
} contact;
typedef enum
@@ -53,8 +70,8 @@ typedef enum
typedef struct
{
- char id[16];
- char description[64];
+ char id[MAX_LEN_ID];
+ char description[MAX_LEN_LONG_DESC];
project_state state;
time_t start_date;
time_t end_date;
@@ -72,53 +89,51 @@ typedef enum
INVOICE_CORRECTED,
} invoice_status;
-#define CURRENCY_LENGTH 8
-
typedef struct
{
- char id[16];
- char invoice_id[16];
+ char id[MAX_LEN_ID];
+ char invoice_id[MAX_LEN_ID];
float amount;
bool amount_is_percentage;
- char description[128];
+ char description[MAX_LEN_LONG_DESC];
float net_per_item;
float discount;
bool discount_is_percentage;
float net;
- char currency[CURRENCY_LENGTH];
- char tax_bracket_id[16];
+ char currency[MAX_LEN_CURRENCY];
+ char tax_bracket_id[MAX_LEN_ID];
float tax;
float total;
// todo
- char tax_section[16];
+ char tax_section[MAX_LEN_TAX_SECTION];
} billing_item;
typedef struct
{
- char id[16];
- char sequential_number[16]; // INV0000000000 - INV9999999999
- char customer_id[16];
- char supplier_id[16];
+ char id[MAX_LEN_ID];
+ char sequential_number[MAX_LEN_SEQ_NUM]; // INV0000000000 - INV9999999999
+ char customer_id[MAX_LEN_ID];
+ char supplier_id[MAX_LEN_ID];
contact addressee;
time_t issued_at;
time_t expires_at;
time_t delivered_at;
- char document[255]; // path to copy of document for incomming invoice.
- char project_id[16];
- char cost_center_id[16];
+ char document[MAX_LEN_PATH]; // path to copy of document for incomming invoice.
+ char project_id[MAX_LEN_ID];
+ char cost_center_id[MAX_LEN_ID];
list_t billing_items;
float total;
float tax;
float net;
- char currency[CURRENCY_LENGTH];
+ char currency[MAX_LEN_CURRENCY];
bool is_triangulation;
bool is_intra_community; // TODO
invoice_status status; // TODO
time_t payment_on_account_date; // TODO
- char tax_representative[64]; // TODO
- char corrected_sequential_number[16]; // TODO
+ char tax_representative[MAX_LEN_LONG_DESC]; // TODO
+ char corrected_sequential_number[MAX_LEN_ID]; // TODO
// Used for forms, not stored on disk. Filled when retrieved.
contact supplier;
@@ -132,7 +147,7 @@ typedef struct
s32 next_id; // Shared across all objects that have an ID.
s32 next_sequence_number; // Sequence number for generating invoice numbers.
- char path[4096];
+ char path[MAX_LEN_PATH];
char program_version[10];
list_t contacts;
list_t projects;
diff --git a/src/ui/ui_contacts.cpp b/src/ui/ui_contacts.cpp
index 87c021d..4db726d 100644
--- a/src/ui/ui_contacts.cpp
+++ b/src/ui/ui_contacts.cpp
@@ -16,7 +16,7 @@ void ui_draw_address_form(address* buffer)
const char* selected_country = NULL;
float widthAvailable = ImGui::GetContentRegionAvail().x;
- char id[128];
+ char id[MAX_LEN_ADDRESS];
ImGui::SetNextItemWidth(widthAvailable*0.5f);
snprintf(id, sizeof(id), "%s##%p", localize("contact.form.address1"), buffer);
diff --git a/src/ui/ui_invoices.cpp b/src/ui/ui_invoices.cpp
index acf0de7..0256fbd 100644
--- a/src/ui/ui_invoices.cpp
+++ b/src/ui/ui_invoices.cpp
@@ -87,7 +87,7 @@ void draw_tax_bracket_selector(char* tax_bracket_id)
}
if (selected_tax_bracket_index != -1) {
- strops_copy(tax_bracket_id, buffer[selected_tax_bracket_index].id, 16);
+ strops_copy(tax_bracket_id, buffer[selected_tax_bracket_index].id, MAX_LEN_ID);
}
}
@@ -180,7 +180,7 @@ void draw_costcenter_selector(char* costcenter_id)
}
if (selected_costcenter_index != -1) {
- strops_copy(costcenter_id, buffer[selected_costcenter_index].id, 16);
+ strops_copy(costcenter_id, buffer[selected_costcenter_index].id, MAX_LEN_ID);
}
}
@@ -219,7 +219,7 @@ void draw_project_selector(char* project_id)
}
if (selected_project_index != -1) {
- strops_copy(project_id, buffer[selected_project_index].id, 16);
+ strops_copy(project_id, buffer[selected_project_index].id, MAX_LEN_ID);
}
free(buffer);
diff --git a/src/ui/ui_settings.cpp b/src/ui/ui_settings.cpp
index a7759aa..69c4f54 100644
--- a/src/ui/ui_settings.cpp
+++ b/src/ui/ui_settings.cpp
@@ -50,7 +50,7 @@ static void ui_draw_vat_rates()
ImGui::TableSetupColumn(localize("settings.vat.table.rates"));
// Used to generate headers for each individual country.
- char prev_country[3];
+ char prev_country[MAX_LEN_COUNTRY_CODE];
prev_country[0] = 0;
for (u32 i = 0; i < tax_bracket_count; i++) {