summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/administration.cpp197
1 files changed, 13 insertions, 184 deletions
diff --git a/src/administration.cpp b/src/administration.cpp
index 51a47b4..a724892 100644
--- a/src/administration.cpp
+++ b/src/administration.cpp
@@ -33,7 +33,7 @@ data_changed_event data_changed_event_callback = 0;
data_deleted_event data_deleted_event_callback = 0;
invoice_changed_event invoice_changed_event_callback = 0;
contact_changed_event contact_changed_event_callback = 0;
-taxrate_changed_event taxrate_changed_event_callback = 0;
+taxrate_changed_event taxrate_changed_event_callback = 0;
costcenter_changed_event costcenter_changed_event_callback = 0;
project_changed_event project_changed_event_callback = 0;
@@ -42,19 +42,6 @@ static s32 administration_create_id()
return g_administration.next_id;
}
-#define ADD_BRACKET(_country, _rate, _code)\
-{\
- tax_rate* tb = (tax_rate*)malloc(sizeof(tax_rate));\
- snprintf(tb->id, sizeof(tb->id), "T/%d", administration_create_id());\
- memcpy(tb->country_code, _country, sizeof(tb->country_code));\
- tb->rate = _rate;\
- memcpy(tb->category_code, _code, sizeof(tb->category_code));\
- list_append(&g_administration.tax_rates, tb);\
- g_administration.next_id++;\
- if (taxrate_changed_event_callback) taxrate_changed_event_callback(tb);\
- if (data_changed_event_callback) data_changed_event_callback();\
-}
-
static int compare_tax_countries(const void *a, const void *b)
{
tax_rate *objA = (tax_rate *)a;
@@ -62,81 +49,28 @@ static int compare_tax_countries(const void *a, const void *b)
return strcmp(objA->country_code, objB->country_code);
}
-static invoice_status administration_get_random_invoice_status()
-{
- return (invoice_status)(rand() % invoice_status::INVOICE_END);
-}
-
-static void administration_get_random_project(char* project_id)
-{
- int size = list_size(&g_administration.projects);
- if (size > 0) {
- int index = rand() % size;
- project *val = (project *) list_get_at(&g_administration.projects, index);
- strops_copy(project_id, val->id, MAX_LEN_ID);
- }
-}
-
-static void administration_get_random_cost_center(char* cost_center_id)
-{
- int size = list_size(&g_administration.cost_centers);
- if (size > 0) {
- int index = rand() % size;
- cost_center *val = (cost_center *) list_get_at(&g_administration.cost_centers, index);
- strops_copy(cost_center_id, val->id, MAX_LEN_ID);
- }
-}
-
-static contact* administration_get_random_contact()
-{
- int size = list_size(&g_administration.contacts);
- if (size > 0) {
- int index = rand() % size;
- contact *val = (contact *) list_get_at(&g_administration.contacts, index);
- return val;
- }
- return 0;
-}
-
static time_t administration_get_default_invoice_expire_duration()
{
return (30 * 24 * 60 * 60); // 30 days
}
-static void administration_recalculate_billing_item_totals(billing_item* item);
static char* administration_get_default_currency_for_country(char* country_code);
-static void administration_get_random_billing_items(invoice* inv)
+static void administration_create_default_tax_rates()
{
- int amount = 1 + rand() % 20;
-
- for (int i = 0; i < amount; i++)
- {
- billing_item item = administration_billing_item_create_empty();
- item.amount = 1 + (float)(rand() % 5);
- item.amount_is_percentage = (float)(rand() % 2);
- item.description[MAX_LEN_LONG_DESC];
- item.net_per_item = (float)(rand() % 100);
- item.discount = (float)(rand() % 30);
- item.discount_is_percentage = (float)(rand() % 2);
-
- administration_recalculate_billing_item_totals(&item);
-
- if (item.net < item.discount) item.discount = 0.0f;
-
- tax_rate buffer[20];
-
- char* tax_country_codes[1] = {inv->supplier.address.country_code};
- u32 rate_count = administration_tax_rate_get_by_country(buffer, 1, tax_country_codes);
- tax_rate rand_rate = buffer[rand() % rate_count];
- strops_copy(item.tax_rate_id, rand_rate.id, MAX_LEN_ID);
-
- administration_billing_item_add_to_invoice(inv, item);
+ #define ADD_BRACKET(_country, _rate, _code)\
+ {\
+ tax_rate* tb = (tax_rate*)malloc(sizeof(tax_rate));\
+ snprintf(tb->id, sizeof(tb->id), "T/%d", administration_create_id());\
+ memcpy(tb->country_code, _country, sizeof(tb->country_code));\
+ tb->rate = _rate;\
+ memcpy(tb->category_code, _code, sizeof(tb->category_code));\
+ list_append(&g_administration.tax_rates, tb);\
+ g_administration.next_id++;\
+ if (taxrate_changed_event_callback) taxrate_changed_event_callback(tb);\
+ if (data_changed_event_callback) data_changed_event_callback();\
}
-}
-static void administration_create_default_tax_rates()
-{
// General rates shared between countries.
// Category options: https://docs.peppol.eu/poacc/billing/3.0/codelist/UNCL5305/
@@ -312,111 +246,6 @@ static void administration_create_default_cost_centers()
ADD_COSTCENTER("costcenter.other_specialized", "OTHR");
}
-static void administration_create_debug_data()
-{
- srand((unsigned) time(NULL));
-
- #define ADD_CONSUMER(_name, _addr1, _cc, _city, _postal)\
- {contact _c = administration_contact_create_empty();\
- strops_copy(_c.name, _name, sizeof(_c.name));\
- strops_copy(_c.address.address1, _addr1, sizeof(_c.address.address1));\
- strops_copy(_c.address.country_code, _cc, sizeof(_c.address.country_code));\
- strops_copy(_c.address.city, _city, sizeof(_c.address.city));\
- strops_copy(_c.address.postal, _postal, sizeof(_c.address.postal));\
- _c.type = contact_type::CONTACT_CONSUMER;\
- administration_contact_add(_c);};
-
- #define ADD_BUSINESS(_name, _addr1, _cc, _tc, _bc, _city, _postal)\
- {contact _c = administration_contact_create_empty();\
- strops_copy(_c.name, _name, sizeof(_c.name));\
- strops_copy(_c.address.address1, _addr1, sizeof(_c.address.address1));\
- strops_copy(_c.address.country_code, _cc, sizeof(_c.address.country_code));\
- strops_copy(_c.taxid, _tc, sizeof(_c.taxid));\
- strops_copy(_c.businessid, _bc, sizeof(_c.businessid));\
- strops_copy(_c.address.city, _city, sizeof(_c.address.city));\
- strops_copy(_c.address.postal, _postal, sizeof(_c.address.postal));\
- _c.type = contact_type::CONTACT_BUSINESS;\
- administration_contact_add(_c);};
-
- #define ADD_PROJECT(_name)\
- {project _c = administration_project_create_empty();\
- strops_copy(_c.description, _name, sizeof(_c.description));\
- administration_project_add(_c);};
-
- strops_copy(g_administration.path, "C:\\Users\\aldri\\Downloads\\test.openbooks", sizeof(g_administration.path));
-
- ADD_CONSUMER("Emma Müller", "Hauptstraße 12", "DE", "Hamburg", "20095");
- ADD_CONSUMER("Luca Rossi", "Via Roma 45", "IT", "Torino", "10121");
- ADD_CONSUMER("Sofia Garcia", "Calle Mayor 7", "ES", "Valencia", "46001");
- ADD_CONSUMER("Jean Dupont", "10 Rue de la Paix", "FR", "Lyon", "69001");
- ADD_CONSUMER("Anna Nowak", "ul. Kwiatowa 3", "PL", "Kraków", "30-001");
- ADD_CONSUMER("Mikkel Jensen", "Østergade 8", "DK", "Odense", "5000");
- ADD_CONSUMER("Maria Svensson", "Kungsgatan 15", "SE", "Gothenburg", "411 01");
- ADD_CONSUMER("Péter Kovács", "Fő utca 25", "HU", "Debrecen", "4025");
- ADD_CONSUMER("Lucas Silva", "Rua Augusta 100", "PT", "Porto", "4000-123");
- ADD_CONSUMER("Isabelle Lefevre", "5 Place Stanislas", "FR", "Marseille", "13001");
-
- ADD_BUSINESS("Schmidt & Co GmbH", "Friedrichstraße 45", "DE", "DE123456789", "HRB123456", "Stuttgart", "70173");
- ADD_BUSINESS("Bianchi Srl", "Corso Venezia 12", "IT", "IT987654321", "MI1234567", "Napoli", "80100");
- ADD_BUSINESS("Fernández y Asociados", "Gran Vía 20", "ES", "ES456789123", "CIFB123456", "Sevilla", "41001");
- ADD_BUSINESS("Martin & Partners", "12 Avenue Victor Hugo", "FR", "FR321654987", "SIRET123456", "Nice", "06000");
- ADD_BUSINESS("Zielińska Consulting", "ul. Marszałkowska 10", "PL", "PL789123456", "REGON123456", "Gdańsk", "80-001");
- ADD_BUSINESS("Sørensen ApS", "Strøget 3", "DK", "DK654321789", "CVR12345678", "Aalborg", "9000");
- ADD_BUSINESS("Johansson AB", "Drottninggatan 22", "SE", "SE987654321", "OrgNr1234567", "Malmö", "211 01");
- ADD_BUSINESS("Nagy Kft.", "Andrássy út 60", "HU", "HU123987654", "Cégjegyzékszám123", "Szeged", "6720");
- ADD_BUSINESS("Santos Lda.", "Avenida da Liberdade 50", "PT", "PT321789654", "NIPC123456789", "Coimbra", "3000-132");
- ADD_BUSINESS("Dupuis SARL", "8 Rue Saint-Denis", "FR", "FR456123789", "SIREN123456", "Toulouse", "31000");
- ADD_BUSINESS("Müller & Söhne GmbH", "Leipziger Platz 8", "DE", "DE654987321", "HRB987654", "Dresden", "01067");
- ADD_BUSINESS("Romano Srl", "Via Garibaldi 14", "IT", "IT321654987", "GE1239876", "Firenze", "50123");
- ADD_BUSINESS("López Asociados", "Plaza del Pilar 6", "ES", "ES789321654", "CIFC654321", "Bilbao", "48001");
- ADD_BUSINESS("Laurent & Fils", "15 Boulevard Haussmann", "FR", "FR987321654", "SIRET654987", "Bordeaux", "33000");
- ADD_BUSINESS("Kowalczyk Sp. z o.o.", "ul. Piotrkowska 55", "PL", "PL123456789", "REGON654321", "Poznań", "60-101");
- ADD_BUSINESS("Nielsen ApS", "Nørregade 12", "DK", "DK789456123", "CVR87654321", "Esbjerg", "6700");
- ADD_BUSINESS("Lindberg AB", "Vasagatan 18", "SE", "SE456789123", "OrgNr7654321", "Uppsala", "753 10");
- ADD_BUSINESS("Szabó Kft.", "Kossuth Lajos tér 1", "HU", "HU987123654", "Cégjegyzékszám654321", "Pécs", "7621");
- ADD_BUSINESS("Costa Lda.", "Rua do Ouro 24", "PT", "PT654123987", "NIPC987654321", "Braga", "4700-001");
- ADD_BUSINESS("Moreau SARL", "3 Place de la République", "FR", "FR321456987", "SIREN789123", "Lille", "59000");
-
- ADD_PROJECT("eCommerce");
- ADD_PROJECT("Retail store #1");
- ADD_PROJECT("Retail store #2");
- ADD_PROJECT("Kayak rental");
-
- // Company info.
- 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));
- strops_copy(g_administration.company_info.address.city, "Maastricht", sizeof(g_administration.company_info.address.city));
- strops_copy(g_administration.company_info.address.postal, "6226XW", sizeof(g_administration.company_info.address.postal));
- strops_copy(g_administration.company_info.address.country_code, "NL", sizeof(g_administration.company_info.address.country_code));
- strops_copy(g_administration.company_info.taxid, "123", sizeof(g_administration.company_info.taxid));
- strops_copy(g_administration.company_info.businessid, "123", sizeof(g_administration.company_info.businessid));
- administration_company_info_set(g_administration.company_info);
- g_administration.next_id++;
-
- // Invoices
- #define ADD_INVOICE(_outgoing)\
- {\
- invoice inv = administration_invoice_create_empty();\
- if (_outgoing) inv.supplier = administration_company_info_get(); else inv.supplier = *administration_get_random_contact();\
- if (_outgoing) inv.customer = *administration_get_random_contact(); else inv.customer = administration_company_info_get();\
- administration_get_random_project(inv.project_id);\
- if (!_outgoing) administration_get_random_cost_center(inv.cost_center_id);\
- inv.is_outgoing = _outgoing;\
- inv.status = administration_get_random_invoice_status();\
- inv.issued_at = time(NULL) - (86400 * (rand() % 720));\
- inv.delivered_at = inv.issued_at;\
- inv.expires_at = inv.issued_at + administration_get_default_invoice_expire_duration();\
- administration_get_random_billing_items(&inv);\
- administration_invoice_add(&inv);\
- }
-
- // Create about 2 years of random data.
- for (int i = 0; i < 600; i++) { ADD_INVOICE(1); }
- for (int i = 0; i < 600; i++) { ADD_INVOICE(0); }
-}
-
static s32 administration_create_sequence_number()
{
return g_administration.next_sequence_number;