summaryrefslogtreecommitdiff
path: root/src/administration.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/administration.cpp')
-rw-r--r--src/administration.cpp132
1 files changed, 127 insertions, 5 deletions
diff --git a/src/administration.cpp b/src/administration.cpp
index 0353276..e41942e 100644
--- a/src/administration.cpp
+++ b/src/administration.cpp
@@ -2,6 +2,7 @@
#include <stdlib.h>
#include <assert.h>
#include <time.h>
+#include <stdio.h>
#include "strops.hpp"
#include "administration.hpp"
@@ -156,14 +157,41 @@ static void administration_create_default_tax_brackets()
ADD_BRACKET("SE", 12.0f, "tax.reduced");
}
+static void administration_create_default_cost_centers()
+{
+ #define ADD_COSTCENTER(_description, _code)\
+ {\
+ cost_center* tb = (cost_center*)malloc(sizeof(cost_center));\
+ snprintf(tb->id, sizeof(tb->id), "E/%d", administration_create_id());\
+ memcpy(tb->description, _description, sizeof(tb->description));\
+ memcpy(tb->code, _code, sizeof(tb->code));\
+ list_append(&g_administration.cost_centers, tb);\
+ g_administration.next_id++;\
+ }
+
+ ADD_COSTCENTER("costcenter.general_expenses", "GENE");
+ ADD_COSTCENTER("costcenter.administration_general_management", "ADMN");
+ ADD_COSTCENTER("costcenter.finance_accounting", "FINC");
+ ADD_COSTCENTER("costcenter.information_technology", "INFO");
+ ADD_COSTCENTER("costcenter.sales_marketing", "SALE");
+ ADD_COSTCENTER("costcenter.operations_production", "OPER");
+ ADD_COSTCENTER("costcenter.supply_chain_logistics", "SUPP");
+ ADD_COSTCENTER("costcenter.research_development", "RDEV");
+ ADD_COSTCENTER("costcenter.facilities_maintenance", "FACL");
+ ADD_COSTCENTER("costcenter.customer_service_support", "CUST");
+ ADD_COSTCENTER("costcenter.other_specialized", "OTHR");
+}
+
void administration_create()
{
list_init(&g_administration.contacts);
list_init(&g_administration.projects);
list_init(&g_administration.tax_brackets);
+ list_init(&g_administration.cost_centers);
strops_copy(g_administration.path, "", sizeof(g_administration.path));
administration_create_default_tax_brackets();
+ administration_create_default_cost_centers();
}
void administration_destroy()
@@ -171,6 +199,7 @@ void administration_destroy()
list_destroy(&g_administration.contacts);
list_destroy(&g_administration.projects);
list_destroy(&g_administration.tax_brackets);
+ list_destroy(&g_administration.cost_centers);
}
bool administration_create_contact(contact data)
@@ -184,6 +213,13 @@ bool administration_create_contact(contact data)
return true;
}
+bool administration_can_contact_be_deleted(contact data)
+{
+ (void)data;
+ // TODO
+ return true;
+}
+
bool administration_update_contact(contact data)
{
list_iterator_start(&g_administration.contacts);
@@ -285,7 +321,7 @@ u32 administration_get_projects(u32 page_index, u32 page_size, project* buffer)
void administration_cancel_project(project data)
{
data.end_date = time(NULL);
- data.state = project_state::CANCELLED;
+ data.state = project_state::PROJECT_CANCELLED;
administration_update_project(data);
}
@@ -293,9 +329,9 @@ char* administration_project_get_status_string(project data)
{
switch(data.state)
{
- case project_state::RUNNING: return "project.state.running";
- case project_state::PAUSED: return "project.state.paused";
- case project_state::CANCELLED: return "project.state.cancelled";
+ case project_state::PROJECT_RUNNING: return "project.state.running";
+ case project_state::PROJECT_PAUSED: return "project.state.paused";
+ case project_state::PROJECT_CANCELLED: return "project.state.cancelled";
default: assert(0); break;
}
return "";
@@ -303,7 +339,7 @@ char* administration_project_get_status_string(project data)
bool administration_create_project(project data)
{
- data.state = project_state::RUNNING;
+ data.state = project_state::PROJECT_RUNNING;
data.start_date = time(NULL);
data.end_date = 0;
project* new_project = (project*)malloc(sizeof(project));
@@ -378,4 +414,90 @@ u32 administration_get_tax_brackets(country_tax_bracket* buffer)
list_iterator_stop(&g_administration.tax_brackets);
return write_cursor;
+}
+
+u32 administration_get_cost_center_count()
+{
+ return list_size(&g_administration.cost_centers);
+}
+
+u32 administration_get_cost_centers(cost_center* buffer)
+{
+ assert(buffer);
+
+ u32 write_cursor = 0;
+
+ list_iterator_start(&g_administration.cost_centers);
+ while (list_iterator_hasnext(&g_administration.cost_centers)) {
+ cost_center c = *(cost_center *)list_iterator_next(&g_administration.cost_centers);
+ buffer[write_cursor++] = c;
+ }
+ list_iterator_stop(&g_administration.cost_centers);
+
+ return write_cursor;
+}
+
+static bool administration_get_cost_center_by_code(char* code, cost_center* buffer)
+{
+ bool result = false;
+ list_iterator_start(&g_administration.cost_centers);
+ while (list_iterator_hasnext(&g_administration.cost_centers)) {
+ cost_center c = *(cost_center *)list_iterator_next(&g_administration.cost_centers);
+ *buffer = c;
+ if (strcmp(code, c.code) == 0) {
+ result = true;
+ break;
+ }
+ }
+ list_iterator_stop(&g_administration.cost_centers);
+
+ return result;
+}
+
+bool administration_verify_cost_center_description(char* text)
+{
+ return strlen(text) != 0;
+}
+
+bool administration_verify_cost_center_code(char* code)
+{
+ if (strlen(code) == 0) return false;
+
+ cost_center cost_center;
+ bool found = administration_get_cost_center_by_code(code, &cost_center);
+ return !found;
+}
+
+bool administration_add_cost_center(cost_center data)
+{
+ cost_center cs;
+ bool found = administration_get_cost_center_by_code(data.code, &cs);
+ if (found) return false;
+
+ cost_center* tb = (cost_center*)malloc(sizeof(cost_center));
+ snprintf(tb->id, sizeof(tb->id), "E/%d", administration_create_id());
+ memcpy(tb->description, data.description, sizeof(tb->description));
+ memcpy(tb->code, data.code, sizeof(tb->code));
+ list_append(&g_administration.cost_centers, tb);
+
+ g_administration.next_id++;
+
+ return true;
+}
+
+bool administration_update_cost_center(cost_center data)
+{
+ list_iterator_start(&g_administration.cost_centers);
+ while (list_iterator_hasnext(&g_administration.cost_centers)) {
+ cost_center* c = (cost_center *)list_iterator_next(&g_administration.cost_centers);
+
+ if (strcmp(c->id, data.id) == 0) {
+ memcpy(c, &data, sizeof(data));
+ list_iterator_stop(&g_administration.cost_centers);
+ return true;
+ }
+ }
+ list_iterator_stop(&g_administration.cost_centers);
+
+ return false;
} \ No newline at end of file