summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/CHANGES.rst4
-rw-r--r--include/administration.hpp4
-rw-r--r--include/log.hpp1
-rw-r--r--src/administration.cpp84
-rw-r--r--src/administration_reader.cpp2
-rw-r--r--src/log.cpp6
-rw-r--r--tests/administration_rw_tests.cpp2
7 files changed, 18 insertions, 85 deletions
diff --git a/docs/CHANGES.rst b/docs/CHANGES.rst
index 630f0b9..ad9359b 100644
--- a/docs/CHANGES.rst
+++ b/docs/CHANGES.rst
@@ -5,10 +5,6 @@ TODO:
- write tests that check error handling for corrupt files. (e.g. references to tax rates, project and cost center that failed to load)
- it is possible a referenced tax rate is loaded after an invoice is loaded. This means all invoices need to be recalculated after file load. (try to write a test for this).
-- get rid of customer_id and supplier_id.
-This also means we can get rid of administration_invoice_set_refs which simplifies things alot. Contacts should just be a list of possible contacts
-that the user can select from and create manually if they want. They should not be automatically created.
-
- project start and end date should be stored as YYYY-MM-DD
- Send invoice by email
- create invoice from PDF file
diff --git a/include/administration.hpp b/include/administration.hpp
index 130993f..a91a4e3 100644
--- a/include/administration.hpp
+++ b/include/administration.hpp
@@ -247,9 +247,6 @@ typedef struct
{
char id[MAX_LEN_ID]; // I/[id]
char sequential_number[MAX_LEN_SEQ_NUM]; // INV0000000000 - INV9999999999
- char customer_id[MAX_LEN_ID]; // C/[id]
- char supplier_id[MAX_LEN_ID]; // C/[id]
- contact addressee;
time_t issued_at;
time_t expires_at;
time_t delivered_at;
@@ -272,6 +269,7 @@ typedef struct
contact supplier;
contact customer;
+ contact addressee;
} invoice;
typedef struct
diff --git a/include/log.hpp b/include/log.hpp
index 4e3f4f5..cdb6a9f 100644
--- a/include/log.hpp
+++ b/include/log.hpp
@@ -36,6 +36,7 @@ typedef struct {
log* get_log();
+void log_clear();
void log_aerr(a_err errors);
void log_info(const char* fmt, ...) IM_FMTARGS(2);
void log_error(const char* fmt, ...) IM_FMTARGS(2); \ No newline at end of file
diff --git a/src/administration.cpp b/src/administration.cpp
index a724892..b6dfcbb 100644
--- a/src/administration.cpp
+++ b/src/administration.cpp
@@ -294,8 +294,9 @@ static bool is_initialized = false;
void administration_create()
{
- is_initialized = true;
STOPWATCH_START;
+ log_clear();
+ is_initialized = true;
list_init(&g_administration.invoices);
list_init(&g_administration.contacts);
@@ -1499,85 +1500,16 @@ a_err administration_invoice_remove(invoice* inv)
return A_ERR_NOT_FOUND;
}
-static void administration_invoice_set_refs(invoice* inv)
+a_err administration_invoice_update(invoice* inv)
{
- // This function makes sure that contact info referenced in the IDs actually
- // matches the contact info stored in administration, if not we make new contacts.
-
- // Check if supplier info is equal to contact stored in supplier id, in case we autocomplete and edit data after,
- // this should be handled as a new contact.
- contact lookup_buffer;
- if (administration_contact_get_by_id(&lookup_buffer, inv->supplier.id) == A_ERR_SUCCESS)
- {
- if (!administration_contact_equals(lookup_buffer, inv->supplier))
- {
- // Zero id so new contact is created for supplier.
- inv->supplier_id[0] = '\0';
- inv->supplier.id[0] = '\0';
- }
- else
- {
- // Store supplier id in invoice, (only id is stored to disk, supplier field is filled on load).
- strops_copy(inv->supplier_id, inv->supplier.id, sizeof(inv->supplier_id));
- }
- }
-
- // Supplier is valid but supplier id is unset means we need to register a new contact.
- if (strcmp(inv->supplier_id, "") == 0)
- {
- contact new_contact = administration_contact_create_empty();
- strops_copy(inv->supplier_id, new_contact.id, sizeof(new_contact.id));
- strops_copy(inv->supplier.id, new_contact.id, sizeof(new_contact.id));
-
- memcpy(&new_contact, &inv->supplier, sizeof(contact));
- administration_contact_add(new_contact);
-
- inv->supplier = new_contact;
- }
-
- // Check if customer info is equal to contact stored in customer id, in case we autocomplete and edit data after,
- // this should be handled as a new contact.
- if (administration_contact_get_by_id(&lookup_buffer, inv->customer.id) == A_ERR_SUCCESS)
- {
- if (!administration_contact_equals(lookup_buffer, inv->customer))
- {
- // Zero id so new contact is created for supplier.
- inv->customer_id[0] = '\0';
- inv->customer.id[0] = '\0';
- }
- else
- {
- // Store customer id in invoice.
- strops_copy(inv->customer_id, inv->customer.id, sizeof(inv->customer_id));
- }
- }
-
- // Invoice is valid but customer id is unset means we need to register a new contact.
- if (strcmp(inv->customer_id, "") == 0)
- {
- contact new_contact = administration_contact_create_empty();
- strops_copy(inv->customer_id, new_contact.id, sizeof(new_contact.id));
- strops_copy(inv->customer.id, new_contact.id, sizeof(new_contact.id));
-
- memcpy(&new_contact, &inv->customer, sizeof(contact));
- administration_contact_add(new_contact);
-
- inv->customer = new_contact;
- }
+ a_err result = administration_invoice_is_valid(inv);
+ if (result != A_ERR_SUCCESS) return result;
// Addressee is same as customer.
if (!inv->is_triangulation)
{
memcpy(&inv->addressee, &inv->customer, sizeof(contact));
}
-}
-
-a_err administration_invoice_update(invoice* inv)
-{
- a_err result = administration_invoice_is_valid(inv);
- if (result != A_ERR_SUCCESS) return result;
-
- administration_invoice_set_refs(inv);
list_iterator_start(&g_administration.invoices);
while (list_iterator_hasnext(&g_administration.invoices)) {
@@ -1631,7 +1563,11 @@ a_err administration_invoice_add(invoice* inv)
a_err result = administration_invoice_is_valid(inv);
if (result != A_ERR_SUCCESS) return result;
- administration_invoice_set_refs(inv);
+ // Addressee is same as customer.
+ if (!inv->is_triangulation)
+ {
+ memcpy(&inv->addressee, &inv->customer, sizeof(contact));
+ }
inv->issued_at -= (inv->issued_at % 86400);
inv->delivered_at -= (inv->delivered_at % 86400);
diff --git a/src/administration_reader.cpp b/src/administration_reader.cpp
index fb2fbf0..09a4a0a 100644
--- a/src/administration_reader.cpp
+++ b/src/administration_reader.cpp
@@ -163,7 +163,6 @@ bool administration_reader_import_invoice(char* buffer, size_t buffer_size)
// Supplier
xml_get_str_x(root, data.supplier.id, MAX_LEN_ID, "cac:AccountingSupplierParty", "cac:Party", "cac:Contact", "cbc:Name", 0);
- strops_copy(data.supplier_id, data.supplier.id, MAX_LEN_ID);
strops_copy(data.supplier.bank_account, data.payment_means.payee_bank_account, MAX_LEN_BANK);
xml_get_str_x(root, data.supplier.name, MAX_LEN_LONG_DESC, "cac:AccountingSupplierParty", "cac:Party", "cac:PartyName", "cbc:Name", 0);
xml_get_str_x(root, data.supplier.address.address1, MAX_LEN_ADDRESS, "cac:AccountingSupplierParty", "cac:Party", "cac:PostalAddress", "cbc:StreetName", 0);
@@ -179,7 +178,6 @@ bool administration_reader_import_invoice(char* buffer, size_t buffer_size)
// Customer
xml_get_str_x(root, data.customer.id, MAX_LEN_ID, "cac:AccountingCustomerParty", "cac:Party", "cac:Contact", "cbc:Name", 0);
- strops_copy(data.customer_id, data.customer.id, MAX_LEN_ID);
strops_copy(data.customer.bank_account, data.payment_means.payer_bank_account, MAX_LEN_BANK);
xml_get_str_x(root, data.customer.name, MAX_LEN_LONG_DESC, "cac:AccountingCustomerParty", "cac:Party", "cac:PartyName", "cbc:Name", 0);
xml_get_str_x(root, data.customer.address.address1, MAX_LEN_ADDRESS, "cac:AccountingCustomerParty", "cac:Party", "cac:PostalAddress", "cbc:StreetName", 0);
diff --git a/src/log.cpp b/src/log.cpp
index 839ebbe..5180705 100644
--- a/src/log.cpp
+++ b/src/log.cpp
@@ -27,6 +27,12 @@ log* get_log()
return &g_log;
}
+void log_clear()
+{
+ g_log.write_cursor = 0;
+ g_log.history_length = 0;
+}
+
static void log_message(const char* fmt, ImVec4 color, va_list args)
{
vsnprintf(g_log.history[g_log.write_cursor], MAX_LEN_LOG_TXT, fmt, args);
diff --git a/tests/administration_rw_tests.cpp b/tests/administration_rw_tests.cpp
index aea9625..9cb199a 100644
--- a/tests/administration_rw_tests.cpp
+++ b/tests/administration_rw_tests.cpp
@@ -163,8 +163,6 @@ TEST _assert_invoices_are_equal(invoice inv, invoice invr)
{
ASSERT_STR_EQ(invr.id, inv.id);
ASSERT_STR_EQ(invr.sequential_number, inv.sequential_number);
- ASSERT_STR_EQ(invr.customer_id, inv.customer_id);
- ASSERT_STR_EQ(invr.supplier_id, inv.supplier_id);
ASSERT_EQ(invr.issued_at, inv.issued_at);
ASSERT_EQ(invr.expires_at, inv.expires_at);