#pragma once #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[MAX_LEN_ID]; char country_code[MAX_LEN_COUNTRY_CODE]; float rate; // 0-100 char description[MAX_LEN_SHORT_DESC]; } country_tax_bracket; typedef struct { char id[MAX_LEN_ID]; char code[MAX_LEN_CODE]; char description[MAX_LEN_LONG_DESC]; } cost_center; typedef struct { char address1[MAX_LEN_ADDRESS]; char address2[MAX_LEN_ADDRESS]; char country_code[MAX_LEN_COUNTRY_CODE]; // 2 letter country code. } address; typedef enum { CONTACT_BUSINESS, CONTACT_CONSUMER, } contact_type; typedef struct { char id[MAX_LEN_ID]; char name[MAX_LEN_LONG_DESC]; address address; contact_type type; 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 { PROJECT_RUNNING, PROJECT_PAUSED, PROJECT_CANCELLED, } project_state; typedef struct { char id[MAX_LEN_ID]; char description[MAX_LEN_LONG_DESC]; project_state state; time_t start_date; time_t end_date; } project; typedef enum { INVOICE_CONCEPT, INVOICE_SENT, INVOICE_REMINDED, INVOICE_PAID, INVOICE_EXPIRED, INVOICE_CANCELLED, INVOICE_REFUNDED, INVOICE_CORRECTED, } invoice_status; typedef struct { char id[MAX_LEN_ID]; char invoice_id[MAX_LEN_ID]; float amount; bool amount_is_percentage; char description[MAX_LEN_LONG_DESC]; float net_per_item; float discount; bool discount_is_percentage; float net; char currency[MAX_LEN_CURRENCY]; char tax_bracket_id[MAX_LEN_ID]; float tax; float total; // todo char tax_section[MAX_LEN_TAX_SECTION]; } billing_item; typedef struct { 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[MAX_LEN_PATH]; // path to copy of document for incomming invoice. char project_id[MAX_LEN_ID]; // For incomming invoices. optional. char cost_center_id[MAX_LEN_ID]; // For incomming invoices. optional. list_t billing_items; // Total, tax and net are calculated from billing items. float total; float tax; float net; char currency[MAX_LEN_CURRENCY]; bool is_triangulation; // True of addressee != customer invoice_status status; bool is_intra_community; // TODO time_t payment_on_account_date; // 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; contact customer; } invoice; typedef struct { contact company_info; // Company info used for invoices. User cannot create invoices when this is empty/invalid. s32 next_id; // Id increment shared across all objects that have an ID. s32 next_sequence_number; // Sequence number for generating invoice numbers. char path[MAX_LEN_PATH]; // Full path to save file of current administration file. char program_version[10]; // Program version of exe that stored the save path file. list_t contacts; list_t projects; list_t invoices; list_t tax_brackets; list_t cost_centers; } administration; // Setup functions. // ======================= void administration_create(); void administration_destroy(); // General functions. // ======================= char* administration_file_path_get(); contact administration_company_info_get(); void administration_company_info_set(contact data); // Contact functions. // ======================= u32 administration_contact_count(); contact administration_contact_create_empty(); bool administration_contact_add(contact data); bool administration_contact_update(contact data); bool administration_contact_remove(contact data); bool administration_contact_is_valid(contact data); bool administration_contact_can_be_deleted(contact data); int administration_contact_get_autocompletions(contact* buffer, int buf_size, char* name); u32 administration_contact_get_partial_list(u32 page_index, u32 page_size, contact* buffer); // Project functions. // ======================= u32 administration_project_count(); project administration_project_create_empty(); bool administration_project_add(project data); bool administration_project_update(project data); bool administration_project_remove(project data); void administration_project_cancel(project data); bool administration_project_is_valid(project data); char* administration_project_get_status_string(project data); u32 administration_project_get_all(project* buffer); u32 administration_project_get_partial_list(u32 page_index, u32 page_size, project* buffer); // Tax bracket functions. // ======================= u32 administration_tax_bracket_count(); bool administration_tax_bracket_add(country_tax_bracket data); bool administration_tax_bracket_update(country_tax_bracket data); u32 administration_tax_bracket_get_all(country_tax_bracket* buffer); u32 administration_tax_bracket_get_by_country(country_tax_bracket* buffer, char* country_code); // Cost center functions. // ======================= u32 administration_cost_center_count(); bool administration_cost_center_add(cost_center data); bool administration_cost_center_update(cost_center data); bool administration_cost_center_verify_code(char* code); bool administration_cost_center_verify_description(char* text); u32 administration_cost_center_get_all(cost_center* buffer); // Invoice functions. // ======================= u32 administration_invoice_count(); invoice administration_invoice_create_empty(); bool administration_invoice_add(invoice* invoice); bool administration_invoice_update(invoice* invoice); void administration_invoice_set_currency(invoice* invoice, char* currency); invoice administration_invoice_create_copy(invoice* invoice); bool administration_invoice_is_valid(invoice* invoice); char* administration_invoice_get_status_string(invoice* invoice); u32 administration_invoice_get_partial_list(u32 page_index, u32 page_size, invoice* buffer); // Billing item functions. // ======================= u32 administration_billing_items_count(invoice* invoice); billing_item administration_billing_item_create_empty(); bool administration_billing_item_add_to_invoice(invoice* invoice, billing_item item); bool administration_billing_item_update_in_invoice(invoice* invoice, billing_item item); bool administration_billing_item_remove_from_invoice(invoice* invoice, billing_item item); u32 administration_billing_item_get_all_for_invoice(invoice* invoice, billing_item* buffer);