summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/administration.cpp37
-rw-r--r--src/administration_reader.cpp18
-rw-r--r--src/administration_writer.cpp17
-rw-r--r--src/ui/ui_earnings.cpp2
-rw-r--r--src/ui/ui_main.cpp6
5 files changed, 43 insertions, 37 deletions
diff --git a/src/administration.cpp b/src/administration.cpp
index 30fbd76..90fc60a 100644
--- a/src/administration.cpp
+++ b/src/administration.cpp
@@ -513,9 +513,24 @@ void administration_create_default(char* save_file)
// Other functions.
// =======================
-bool administration_has_save_path()
+void administration_set_next_id(s32 nr)
{
- return strcmp(g_administration.path, "") != 0;
+ g_administration.next_id = nr;
+}
+
+void administration_set_next_sequence_number(s32 nr)
+{
+ g_administration.next_sequence_number = nr;
+}
+
+s32 administration_get_next_id()
+{
+ return g_administration.next_id;
+}
+
+s32 administration_get_next_sequence_number()
+{
+ return g_administration.next_sequence_number;
}
bool administration_can_create_invoices()
@@ -528,7 +543,7 @@ char* administration_get_default_currency()
return g_administration.default_currency;
}
-char* administration_get_currency_symbol_from_currency(char* code)
+char* administration_get_currency_symbol_for_currency(char* code)
{
// Major European currencies
if (strcmp(code, "EUR") == 0) return "€"; // Euro
@@ -794,9 +809,9 @@ void administration_create_income_statement(income_statement* statement)
log_add("Created income statement in %.3fms.", STOPWATCH_TIME);
}
-char* administration_file_path_get()
+char* administration_get_file_path()
{
- return g_administration.path;
+ return strlen(g_administration.path) == 0 ? NULL : g_administration.path;
}
contact administration_company_info_get()
@@ -820,11 +835,6 @@ void administration_company_info_set(contact data)
if (data_changed_event_callback) data_changed_event_callback();
}
-administration* administration_get()
-{
- return &g_administration;
-}
-
// Contact functions.
// =======================
bool administration_contact_import(contact data)
@@ -1124,10 +1134,6 @@ bool administration_project_import(project data)
bool administration_project_add(project data)
{
if (!administration_project_is_valid(data)) return false;
-
- data.state = project_state::PROJECT_RUNNING;
- data.start_date = time(NULL);
- data.end_date = 0;
project* new_project = (project*)malloc(sizeof(project));
memcpy((void*)new_project, (void*)&data, sizeof(project));
list_append(&g_administration.projects, new_project);
@@ -1188,6 +1194,9 @@ project administration_project_create_empty()
{
project result;
memset(&result, 0, sizeof(project));
+ result.state = project_state::PROJECT_RUNNING;
+ result.start_date = time(NULL);
+ result.end_date = 0;
snprintf(result.id, sizeof(result.id), "P/%d", administration_create_id());
return result;
}
diff --git a/src/administration_reader.cpp b/src/administration_reader.cpp
index 4fd1247..b7dfa8f 100644
--- a/src/administration_reader.cpp
+++ b/src/administration_reader.cpp
@@ -153,7 +153,7 @@ bool administration_reader_import_contact(char* buffer, size_t buffer_size)
struct xml_node* root = xml_document_root(document);
- contact data;
+ contact data = {0};
_get_xml_str(root, data.id, MAX_LEN_ID, "Id");
_get_xml_str(root, data.name, MAX_LEN_LONG_DESC, "Name");
data.type = (contact_type)_get_xml_s32(root, "Type");
@@ -186,7 +186,7 @@ bool administration_reader_import_project(char* buffer, size_t buffer_size)
struct xml_node* root = xml_document_root(document);
- project data;
+ project data = {0};
_get_xml_str(root, data.id, MAX_LEN_ID, "Id");
_get_xml_str(root, data.description, MAX_LEN_LONG_DESC, "Description");
data.state = (project_state)_get_xml_s32(root, "State");
@@ -209,7 +209,7 @@ bool administration_reader_import_cost_center(char* buffer, size_t buffer_size)
struct xml_node* root = xml_document_root(document);
- cost_center data;
+ cost_center data = {0};
_get_xml_str(root, data.id, MAX_LEN_ID, "Id");
_get_xml_str(root, data.code, MAX_LEN_CODE, "Code");
_get_xml_str(root, data.description, MAX_LEN_LONG_DESC, "Description");
@@ -230,7 +230,7 @@ bool administration_reader_import_tax_bracket(char* buffer, size_t buffer_size)
struct xml_node* root = xml_document_root(document);
- country_tax_bracket data;
+ country_tax_bracket data = {0};
_get_xml_str(root, data.id, MAX_LEN_ID, "Id");
_get_xml_str(root, data.country_code, MAX_LEN_COUNTRY_CODE, "CountryCode");
_get_xml_str(root, data.category_code, MAX_LEN_CODE, "Category");
@@ -252,13 +252,11 @@ bool administration_reader_import_administration_info(char* buffer, size_t buffe
struct xml_node* root = xml_document_root(document);
- administration* ad = administration_get();
- ad->next_id = _get_xml_s32(root, "NextId");
- ad->next_sequence_number = _get_xml_s32(root, "NextSequenceNumber");
- _get_xml_str(root, ad->company_info.id, MAX_LEN_ID, "CompanyInfoId");
+ administration_set_next_id(_get_xml_s32(root, "NextId"));
+ administration_set_next_sequence_number(_get_xml_s32(root, "NextSequenceNumber"));
- log_add("Loaded administration info in %.3fms. next_id=%d next_sequence_number=%d company_id=%s",
- STOPWATCH_TIME, ad->next_id, ad->next_sequence_number, ad->company_info.id);
+ log_add("Loaded administration info in %.3fms. next_id=%d next_sequence_number=%d",
+ STOPWATCH_TIME, administration_get_next_id(), administration_get_next_sequence_number());
return true;
} \ No newline at end of file
diff --git a/src/administration_writer.cpp b/src/administration_writer.cpp
index 618b36e..d19fb51 100644
--- a/src/administration_writer.cpp
+++ b/src/administration_writer.cpp
@@ -80,7 +80,7 @@ static char* administration_writer_copy_template(const char* template_str, int*
static bool administration_writer_entry_exists(char* entry)
{
- struct zip_t *zip_read = zip_open(administration_file_path_get(), 0, 'r');
+ struct zip_t *zip_read = zip_open(administration_get_file_path(), 0, 'r');
int result = zip_entry_open(zip_read, entry);
zip_close(zip_read);
@@ -92,8 +92,8 @@ static bool _administration_writer_delete_entry_by_name(char* entry)
STOPWATCH_START;
bool result = 1;
- struct zip_t *zip_write = zip_open(administration_file_path_get(), 0, 'a');
- if (!zip_write) zip_write = zip_open(administration_file_path_get(), 0, 'w');
+ struct zip_t *zip_write = zip_open(administration_get_file_path(), 0, 'a');
+ if (!zip_write) zip_write = zip_open(administration_get_file_path(), 0, 'w');
char* indices[1] = {entry};
if (zip_entries_delete(zip_write, indices, 1) < 0) result = 0;
@@ -118,8 +118,8 @@ static bool administration_writer_write_to_zip(char* entry_to_replace, char* ori
bool entry_exists = administration_writer_entry_exists(entry_to_replace);
if (entry_exists) _administration_writer_delete_entry_by_name(entry_to_replace);
- struct zip_t *zip_write = zip_open(administration_file_path_get(), 0, 'a');
- if (!zip_write) zip_write = zip_open(administration_file_path_get(), 0, 'w');
+ struct zip_t *zip_write = zip_open(administration_get_file_path(), 0, 'a');
+ if (!zip_write) zip_write = zip_open(administration_get_file_path(), 0, 'w');
zip_entry_open(zip_write, entry_to_replace);
if (zip_entry_write(zip_write, orig_content, final_length) < 0) result = 0;
@@ -644,10 +644,9 @@ bool administration_writer_save_all_administration_info_blocking()
int buf_length = 0;
char* file_content = administration_writer_copy_template(administration_save_template, &buf_length);
- strops_replace(file_content, buf_length, "{{COMPANY_ID}}", administration_company_info_get().id);
- strops_replace_int32(file_content, buf_length, "{{NEXT_ID}}", administration_get()->next_id);
- strops_replace_int32(file_content, buf_length, "{{NEXT_SEQUENCE_NUMBER}}", administration_get()->next_sequence_number);
- strops_replace(file_content, buf_length, "{{PROGRAM_VERSION}}", administration_get()->program_version);
+ strops_replace_int32(file_content, buf_length, "{{NEXT_ID}}", administration_get_next_id());
+ strops_replace_int32(file_content, buf_length, "{{NEXT_SEQUENCE_NUMBER}}", administration_get_next_sequence_number());
+ strops_replace(file_content, buf_length, "{{PROGRAM_VERSION}}", PROGRAM_VERSION);
//// Write to Disk.
int final_length = (int)strlen(file_content);
diff --git a/src/ui/ui_earnings.cpp b/src/ui/ui_earnings.cpp
index f85a54c..002b2bc 100644
--- a/src/ui/ui_earnings.cpp
+++ b/src/ui/ui_earnings.cpp
@@ -43,7 +43,7 @@ void ui_draw_earnings()
ImGui::Spacing();
- char* currency_symbol = administration_get_currency_symbol_from_currency(administration_get_default_currency());
+ char* currency_symbol = administration_get_currency_symbol_for_currency(administration_get_default_currency());
if (ImGui::BeginTable("QuarterlyResultsTable", 5, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Hideable))
{
diff --git a/src/ui/ui_main.cpp b/src/ui/ui_main.cpp
index 59c4156..3405a7e 100644
--- a/src/ui/ui_main.cpp
+++ b/src/ui/ui_main.cpp
@@ -144,12 +144,12 @@ void ui_draw_main()
ImGuiWindowFlags_NoBringToFrontOnFocus |
ImGuiWindowFlags_NoCollapse);
- char* path = administration_file_path_get();
- if (strlen(path) == 0) {
+ char* path = administration_get_file_path();
+ if (path == NULL) {
ImGui::Text("%s: %s", localize("ui.workingOn"), localize("ui.unsavedProject"));
}
else {
- ImGui::Text("%s: %s", localize("ui.workingOn"), administration_file_path_get());
+ ImGui::Text("%s: %s", localize("ui.workingOn"), path);
}
ImGui::SameLine();