diff options
Diffstat (limited to 'src/administration.cpp')
| -rw-r--r-- | src/administration.cpp | 67 |
1 files changed, 63 insertions, 4 deletions
diff --git a/src/administration.cpp b/src/administration.cpp index 1684442..49b2559 100644 --- a/src/administration.cpp +++ b/src/administration.cpp @@ -365,7 +365,7 @@ static void administration_create_debug_data() ADD_PROJECT("Kayak rental"); // Company info. - snprintf(g_administration.company_info.id, sizeof(g_administration.company_info.id), "C/%d", administration_create_id()); + snprintf(g_administration.company_info.id, sizeof(g_administration.company_info.id), "%s", MY_COMPANY_ID); strops_copy(g_administration.company_info.name, "Aldrik Ramaekers", sizeof(g_administration.company_info.name)); strops_copy(g_administration.company_info.address.address1, "Keerderstraat 81", sizeof(g_administration.company_info.address.address1)); strops_copy(g_administration.company_info.address.address2, "", sizeof(g_administration.company_info.address.address2)); @@ -443,8 +443,17 @@ void administration_set_project_changed_event_callback(project_changed_event ev) // Setup functions. // ======================= +void administration_create_from_file(char* save_file) +{ + strops_copy(g_administration.path, save_file, sizeof(g_administration.path)); + strops_copy(g_administration.program_version, PROGRAM_VERSION, sizeof(g_administration.program_version)); +} + void administration_create_empty(char* save_file) { + g_administration.next_id = 2; + g_administration.next_sequence_number = 1; + strops_copy(g_administration.path, save_file, sizeof(g_administration.path)); strops_copy(g_administration.program_version, PROGRAM_VERSION, sizeof(g_administration.program_version)); administration_company_info_set(administration_contact_create_empty()); @@ -459,9 +468,6 @@ void administration_create() { STOPWATCH_START; - g_administration.next_id = 1; - g_administration.next_sequence_number = 1; - list_init(&g_administration.invoices); list_init(&g_administration.contacts); list_init(&g_administration.projects); @@ -592,6 +598,7 @@ void administration_create_income_statement(income_statement* statement) statement->quarter_count = 0; u32 invoice_count = administration_invoice_count(); + if (invoice_count == 0) return; invoice* invoice_buffer = (invoice*)malloc(sizeof(invoice)*invoice_count); invoice_count = administration_invoice_get_all(invoice_buffer); @@ -784,6 +791,12 @@ contact administration_company_info_get() return g_administration.company_info; } +void administration_company_info_import(contact data) +{ + g_administration.company_info = data; + strops_copy(g_administration.default_currency, administration_get_default_currency_for_country(g_administration.company_info.address.country_code), MAX_LEN_CURRENCY); +} + void administration_company_info_set(contact data) { g_administration.company_info = data; @@ -800,6 +813,21 @@ administration* administration_get() // Contact functions. // ======================= +bool administration_contact_import(contact data) +{ + if (strcmp(data.id, MY_COMPANY_ID) == 0) + { + administration_company_info_import(data); + return true; + } + + contact* new_contact = (contact*)malloc(sizeof(contact)); + memcpy((void*)new_contact, (void*)&data, sizeof(contact)); + list_append(&g_administration.contacts, new_contact); + + return true; +} + bool administration_contact_add(contact data) { if (!administration_contact_is_valid(data)) return false; @@ -1070,6 +1098,15 @@ char* administration_project_get_status_string(project data) return ""; } +bool administration_project_import(project data) +{ + project* new_project = (project*)malloc(sizeof(project)); + memcpy((void*)new_project, (void*)&data, sizeof(project)); + list_append(&g_administration.projects, new_project); + + return true; +} + bool administration_project_add(project data) { if (!administration_project_is_valid(data)) return false; @@ -1173,12 +1210,26 @@ u32 administration_tax_bracket_count() return list_size(&g_administration.tax_brackets); } +bool administration_tax_bracket_import(country_tax_bracket data) +{ + country_tax_bracket* tb = (country_tax_bracket*)malloc(sizeof(country_tax_bracket)); + memcpy((void*)tb, (void*)&data, sizeof(country_tax_bracket)); + + list_append(&g_administration.tax_brackets, tb); + + list_attributes_comparator(&g_administration.tax_brackets, compare_tax_countries); + list_sort(&g_administration.tax_brackets, -1); + return true; +} + bool administration_tax_bracket_add(country_tax_bracket data) { country_tax_bracket* tb = (country_tax_bracket*)malloc(sizeof(country_tax_bracket)); memcpy((void*)tb, (void*)&data, sizeof(country_tax_bracket)); snprintf(tb->id, sizeof(tb->id), "T/%d", administration_create_id()); + list_append(&g_administration.tax_brackets, tb); + g_administration.next_id++; list_attributes_comparator(&g_administration.tax_brackets, compare_tax_countries); @@ -1317,6 +1368,14 @@ bool administration_cost_center_verify_code(char* code) return !found; } +bool administration_cost_center_import(cost_center data) +{ + cost_center* tb = (cost_center*)malloc(sizeof(cost_center)); + memcpy(tb, &data, sizeof(cost_center)); + list_append(&g_administration.cost_centers, tb); + return true; +} + bool administration_cost_center_add(cost_center data) { cost_center cs; |
