summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/administration.cpp113
-rw-r--r--src/administration_reader.cpp11
-rw-r--r--src/administration_writer.cpp12
-rw-r--r--src/countries/nl.cpp24
-rw-r--r--src/ui/imgui_extensions.cpp34
-rw-r--r--src/ui/ui_expenses.cpp4
-rw-r--r--src/ui/ui_invoices.cpp6
7 files changed, 50 insertions, 154 deletions
diff --git a/src/administration.cpp b/src/administration.cpp
index 93af778..7a10ac0 100644
--- a/src/administration.cpp
+++ b/src/administration.cpp
@@ -1040,8 +1040,6 @@ tax_rate administration::tax_rate_create_empty()
{
tax_rate result;
memops::zero(&result, sizeof(tax_rate));
- strops::format(result.id, sizeof(result.id), "T/%d", create_id());
- strops::format(result.category_code, sizeof(result.category_code), "S"); // S = standard rate.
return result;
}
@@ -1084,43 +1082,14 @@ a_err administration::tax_rate_exists(tax_rate data)
return A_ERR_NOT_FOUND;
}
-a_err administration::tax_rate_get_by_shorthandle(tax_rate* buffer, char* handle)
+a_err administration::tax_rate_get_by_internal_code(tax_rate* buffer, char* id)
{
assert(buffer);
list_iterator_start(&g_administration.tax_rates);
while (list_iterator_hasnext(&g_administration.tax_rates)) {
tax_rate c = *(tax_rate *)list_iterator_next(&g_administration.tax_rates);
-
- char compare_str[20];
- strops::format(compare_str, 20, "%s/%.2f", c.country_code, c.rate);
- if (strcmp(compare_str, handle) == 0)
- {
- *buffer = c;
- list_iterator_stop(&g_administration.tax_rates);
- return A_ERR_SUCCESS;
- }
- strops::format(compare_str, 20, "%s/%s", c.country_code, c.category_code);
- if (strcmp(compare_str, handle) == 0)
- {
- *buffer = c;
- list_iterator_stop(&g_administration.tax_rates);
- return A_ERR_SUCCESS;
- }
- }
- list_iterator_stop(&g_administration.tax_rates);
-
- return A_ERR_NOT_FOUND;
-}
-
-a_err administration::tax_rate_get_by_id(tax_rate* buffer, char* id)
-{
- assert(buffer);
-
- list_iterator_start(&g_administration.tax_rates);
- while (list_iterator_hasnext(&g_administration.tax_rates)) {
- tax_rate c = *(tax_rate *)list_iterator_next(&g_administration.tax_rates);
- if (strcmp(c.id, id) == 0)
+ if (strcmp(c.internal_code, id) == 0)
{
*buffer = c;
list_iterator_stop(&g_administration.tax_rates);
@@ -1168,34 +1137,7 @@ a_err administration::tax_rate_add(tax_rate data)
return A_ERR_SUCCESS;
}
-u32 administration::tax_rate_get_by_country(tax_rate* buffer, u32 code_count, char** tax_country_codes)
-{
- assert(buffer);
-
- u32 write_cursor = 0;
-
- list_iterator_start(&g_administration.tax_rates);
- while (list_iterator_hasnext(&g_administration.tax_rates)) {
- tax_rate c = *(tax_rate *)list_iterator_next(&g_administration.tax_rates);
-
- if (strcmp(c.country_code, "00") == 0) {
- buffer[write_cursor++] = c;
- continue;
- }
-
- for (u32 x = 0; x < code_count; x++) {
- if (strcmp(c.country_code, tax_country_codes[x]) == 0) {
- buffer[write_cursor++] = c;
- continue;
- }
- }
- }
- list_iterator_stop(&g_administration.tax_rates);
-
- return write_cursor;
-}
-
-u32 administration::tax_rate_get_all(tax_rate* buffer)
+u32 administration::tax_rate_get_all(tax_rate* buffer, tax_rate_type type)
{
assert(buffer);
@@ -1204,34 +1146,13 @@ u32 administration::tax_rate_get_all(tax_rate* buffer)
list_iterator_start(&g_administration.tax_rates);
while (list_iterator_hasnext(&g_administration.tax_rates)) {
tax_rate c = *(tax_rate *)list_iterator_next(&g_administration.tax_rates);
- buffer[write_cursor++] = c;
+ if (c.type == type) buffer[write_cursor++] = c;
}
list_iterator_stop(&g_administration.tax_rates);
return write_cursor;
}
-a_err administration::tax_rate_update(tax_rate data)
-{
- list_iterator_start(&g_administration.tax_rates);
- while (list_iterator_hasnext(&g_administration.tax_rates)) {
- tax_rate* c = (tax_rate *)list_iterator_next(&g_administration.tax_rates);
-
- if (strcmp(c->id, data.id) == 0) {
- memops::copy(c, &data, sizeof(data));
- list_iterator_stop(&g_administration.tax_rates);
-
- if (taxrate_changed_event_callback) taxrate_changed_event_callback(c);
- if (data_changed_event_callback) data_changed_event_callback();
-
- return A_ERR_SUCCESS;
- }
- }
- list_iterator_stop(&g_administration.tax_rates);
-
- return A_ERR_NOT_FOUND;
-}
-
// Cost center functions.
// =======================
u32 administration::cost_center_count()
@@ -1412,21 +1333,7 @@ static char* get_default_currency_for_country(char* country_code)
bool administration::invoice_has_intra_community_services(invoice* invoice)
{
- list_iterator_start(&invoice->billing_items);
- while (list_iterator_hasnext(&invoice->billing_items)) {
- billing_item* c = (billing_item *)list_iterator_next(&invoice->billing_items);
-
- tax_rate rate;
- a_err found = administration::tax_rate_get_by_id(&rate, c->tax_rate_id);
- if (found == A_ERR_SUCCESS) {
- if (strops::equals(rate.category_code, "K#S")) {
- list_iterator_stop(&invoice->billing_items);
- return true;
- }
- }
- }
- list_iterator_stop(&invoice->billing_items);
-
+ // TODO
return false;
}
@@ -1711,7 +1618,7 @@ bool administration::invoice_get_subtotal_for_tax_rate(invoice* invoice, tax_rat
while (list_iterator_hasnext(&invoice->billing_items)) {
billing_item* c = (billing_item *)list_iterator_next(&invoice->billing_items);
- if (strcmp(c->tax_rate_id, rate.id) == 0)
+ if (strcmp(c->tax_internal_code, rate.internal_code) == 0)
{
result = true;
buffer->tax += c->tax;
@@ -1734,12 +1641,12 @@ u32 administration::invoice_get_tax_rates(invoice* invoice, tax_rate* buffer)
billing_item c = *(billing_item *)list_iterator_next(&invoice->billing_items);
tax_rate rate;
- a_err found = administration::tax_rate_get_by_id(&rate, c.tax_rate_id);
+ a_err found = administration::tax_rate_get_by_internal_code(&rate, c.tax_internal_code);
if (found == A_ERR_SUCCESS) {
bool exists = false;
for (u32 i = 0; i < write_cursor; i++) {
- if (strcmp(buffer[i].id, c.tax_rate_id) == 0) {
+ if (strcmp(buffer[i].internal_code, c.tax_internal_code) == 0) {
exists = true;
break;
}
@@ -1835,7 +1742,7 @@ static void administration_recalculate_billing_item_totals(billing_item* item)
}
tax_rate rate;
- if (administration::tax_rate_get_by_id(&rate, item->tax_rate_id) == A_ERR_SUCCESS)
+ if (administration::tax_rate_get_by_internal_code(&rate, item->tax_internal_code) == A_ERR_SUCCESS)
{
item->tax = item->net * (rate.rate/100.0f);
}
@@ -1915,7 +1822,7 @@ a_err administration::billing_item_is_valid(billing_item item)
{
a_err result = A_ERR_SUCCESS;
if (strlen(item.description) == 0) result |= A_ERR_MISSING_DESCRIPTION;
- if (strlen(item.tax_rate_id) == 0) result |= A_ERR_MISSING_TAX_RATE;
+ if (strlen(item.tax_internal_code) == 0) result |= A_ERR_MISSING_TAX_RATE;
return result;
}
diff --git a/src/administration_reader.cpp b/src/administration_reader.cpp
index 976c533..6a79b57 100644
--- a/src/administration_reader.cpp
+++ b/src/administration_reader.cpp
@@ -212,7 +212,7 @@ bool administration_reader::read_invoice_from_xml(invoice* result, char* buffer,
billing_item bi = {0};
xml_get_str_x(child, bi.id, MAX_LEN_ID, "cbc:ID", 0);
- xml_get_str_x(child, bi.tax_rate_id, MAX_LEN_ID, "cac:Item", "cac:AdditionalItemProperty", "cbc:Value", 0);
+ xml_get_str_x(child, bi.tax_internal_code, MAX_LEN_ID, "cac:Item", "cac:AdditionalItemProperty", "cbc:Value", 0);
bi.amount = xml_get_float_x(child, "cbc:InvoicedQuantity", 0);
bi.net_per_item = xml_get_float_x(child, "cac:Price", "cbc:PriceAmount", 0);
bi.net = xml_get_float_x(child, "cbc:LineExtensionAmount", 0);
@@ -231,13 +231,8 @@ bool administration_reader::read_invoice_from_xml(invoice* result, char* buffer,
// Import service could set tax rate id to shorthandle.
tax_rate tax_rate;
- if (administration::tax_rate_get_by_id(&tax_rate, bi.tax_rate_id) == A_ERR_NOT_FOUND) {
- if (administration::tax_rate_get_by_shorthandle(&tax_rate, bi.tax_rate_id) == A_ERR_SUCCESS) {
- strops::copy(bi.tax_rate_id, tax_rate.id, MAX_LEN_ID);
- }
- else {
- strops::copy(bi.tax_rate_id, "", MAX_LEN_ID);
- }
+ if (administration::tax_rate_get_by_internal_code(&tax_rate, bi.tax_internal_code) == A_ERR_NOT_FOUND) {
+ strops::copy(bi.tax_internal_code, "", MAX_LEN_SHORT_DESC);
}
administration::billing_item_import_to_invoice(&data, bi);
diff --git a/src/administration_writer.cpp b/src/administration_writer.cpp
index ee22022..ebc0056 100644
--- a/src/administration_writer.cpp
+++ b/src/administration_writer.cpp
@@ -428,8 +428,7 @@ bool administration_writer::save_invoice_blocking(invoice inv)
strops::replace_float(tax_entry_file_content, tax_entry_buf_length, "{{TAX_AMOUNT}}", subtotal.tax, 2);
char tax_category[10];
- strops::copy(tax_category, tax_rate_buffer[i].category_code, sizeof(tax_category));
- strops::tokenize(tax_category, "#");
+ tax_category[0] = 0; // TODO get tax category
strops::replace(tax_entry_file_content, tax_entry_buf_length, "{{TAX_CATEGORY}}", tax_category);
strops::replace_float(tax_entry_file_content, tax_entry_buf_length, "{{TAX_PERCENT}}", tax_rate_buffer[i].rate, 2);
@@ -470,13 +469,13 @@ bool administration_writer::save_invoice_blocking(invoice inv)
billing_item bi = billing_item_buffer[i];
tax_rate rate;
- administration::tax_rate_get_by_id(&rate, bi.tax_rate_id);
+ administration::tax_rate_get_by_internal_code(&rate, bi.tax_internal_code);
strops::replace(billing_item_file_content, billing_item_buf_length, "{{CURRENCY}}", bi.currency);
strops::replace(billing_item_file_content, billing_item_buf_length, "{{LINE_ID}}", bi.id);
- strops::replace(billing_item_file_content, billing_item_buf_length, "{{LINE_TAX_ID}}", bi.tax_rate_id);
+ strops::replace(billing_item_file_content, billing_item_buf_length, "{{LINE_TAX_ID}}", bi.tax_internal_code);
strops::replace(billing_item_file_content, billing_item_buf_length, "{{ITEM_NAME}}", bi.description);
- strops::replace(billing_item_file_content, billing_item_buf_length, "{{LINE_TAX_CATEGORY}}", rate.category_code);
+ strops::replace(billing_item_file_content, billing_item_buf_length, "{{LINE_TAX_CATEGORY}}", "S"); // TODO get from tax code
strops::replace_float(billing_item_file_content, billing_item_buf_length, "{{LINE_TAX_PERCENT}}", rate.rate, 2);
strops::replace_float(billing_item_file_content, billing_item_buf_length, "{{LINE_AMOUNT}}", bi.net, 2); // line amount = net_per_item * items_count - discount
strops::replace_float(billing_item_file_content, billing_item_buf_length, "{{QUANTITY}}", bi.amount, 2);
@@ -699,6 +698,7 @@ bool administration_writer::save_tax_rate_blocking(tax_rate rate)
bool administration_writer::save_all_tax_rates_blocking()
{
+ /*
//// Get all data.
u32 num_rates = administration::tax_rate_count();
u32 buffer_size = sizeof(tax_rate) * num_rates;
@@ -714,6 +714,8 @@ bool administration_writer::save_all_tax_rates_blocking()
memops::unalloc(rate_buffer);
return result;
+ */
+ return 1;
}
/////////////////////////////
diff --git a/src/countries/nl.cpp b/src/countries/nl.cpp
index 4d507f4..795aff6 100644
--- a/src/countries/nl.cpp
+++ b/src/countries/nl.cpp
@@ -65,7 +65,7 @@ bool _nl_add_billing_item_to_tax_report(tax_report* report, invoice* inv, billin
// https://goedestartbelastingdienst.nl/wiki/view/7494ecb4-f6d2-4f85-a200-5a3ee5d45b75/btw-aangifte-het-invullen-van-de-verschillende-rubrieken
tax_rate rate;
- a_err err = administration::tax_rate_get_by_id(&rate, item->tax_rate_id);
+ a_err err = administration::tax_rate_get_by_internal_code(&rate, item->tax_internal_code);
if (err != A_ERR_SUCCESS) return 0;
tax_subtotal totals = administration::billing_item_convert_to_default_currency(inv, *item);
@@ -127,17 +127,17 @@ bool _nl_add_billing_item_to_tax_report(tax_report* report, invoice* inv, billin
if (strops::equals(inv->supplier.address.country_code, "NL")) {
- if (strops::equals(rate.category_code, "AE")) { // NL reverse charge.
- tax_line* tl = administration::get_tax_line_from_report(report, "2a");
- tl->total_net += totals.net;
- tl->total_tax += totals.net * 0.21f; // TODO fr?
-
- a5->total_tax += totals.net * 0.21f;
- b5->total_tax += totals.net * 0.21f;
- }
- else {
- b5->total_tax += totals.tax;
- }
+ // if (strops::equals(rate., "AE")) { // NL reverse charge.
+ // tax_line* tl = administration::get_tax_line_from_report(report, "2a");
+ // tl->total_net += totals.net;
+ // tl->total_tax += totals.net * 0.21f; // TODO fr?
+
+ // a5->total_tax += totals.net * 0.21f;
+ // b5->total_tax += totals.net * 0.21f;
+ // }
+ // else {
+ // b5->total_tax += totals.tax;
+ // }
}
else if (!country::is_EU(inv->supplier.address.country_code)) {
tax_line* tl = administration::get_tax_line_from_report(report, "4a");
diff --git a/src/ui/imgui_extensions.cpp b/src/ui/imgui_extensions.cpp
index 797da9d..63e8eeb 100644
--- a/src/ui/imgui_extensions.cpp
+++ b/src/ui/imgui_extensions.cpp
@@ -325,21 +325,20 @@ namespace ImGui
memops::unalloc(buffer);
}
- void FormTaxRateCombo(char* tax_rate_id, char* orig_country, char* dest_country, bool has_error)
+ void FormTaxRateCombo(char* tax_internal_code, bool outgoing, bool has_error)
{
u32 tax_rate_count = administration::tax_rate_count();
tax_rate* buffer = (tax_rate*) memops::alloc(sizeof(tax_rate) * tax_rate_count);
tax_rate* selected_tax_rate = NULL;
- char* tax_country_codes[2] = {orig_country, dest_country};
- tax_rate_count = administration::tax_rate_get_by_country(buffer, strcmp(orig_country, dest_country) == 0 ? 1 : 2, tax_country_codes);
+ tax_rate_count = administration::tax_rate_get_all(buffer, outgoing ? tax_rate_type::TAX_RATE_OUTGOING_INVOICE : tax_rate_type::TAX_RATE_INCOMMING_INVOICE);
// Select tax rate by given id.
- if (strlen(tax_rate_id) > 0)
+ if (strlen(tax_internal_code) > 0)
{
for (u32 i = 0; i < tax_rate_count; i++)
{
- if (strcmp(buffer[i].id, tax_rate_id) == 0)
+ if (strcmp(buffer[i].internal_code, tax_internal_code) == 0)
{
selected_tax_rate = &buffer[i];
break;
@@ -348,16 +347,12 @@ namespace ImGui
}
int selected_tax_rate_index = -1;
- char rate_str_buf[40];
- rate_str_buf[0] = 0;
+ char rate_str_buf[MAX_LEN_LONG_DESC];
if (selected_tax_rate)
{
- if (strcmp(selected_tax_rate->country_code, "00") == 0) {
- char category_code_desc[MAX_LEN_LONG_DESC];
- strops::format(category_code_desc, MAX_LEN_LONG_DESC, "taxcategory.%s", selected_tax_rate->category_code);
- strops::format(rate_str_buf, 40, "%s", locale::get(category_code_desc));
- }
- else strops::format(rate_str_buf, 40, "%s/%.1f%%", selected_tax_rate->country_code, selected_tax_rate->rate);
+ char category_code_desc[MAX_LEN_LONG_DESC];
+ strops::format(category_code_desc, MAX_LEN_LONG_DESC, "taxrate.code.%s", selected_tax_rate->internal_code);
+ strops::format(rate_str_buf, MAX_LEN_LONG_DESC, "%s", locale::get(category_code_desc));
}
if (has_error) {
@@ -369,14 +364,11 @@ namespace ImGui
{
for (u32 n = 0; n < tax_rate_count; n++)
{
- bool is_selected = selected_tax_rate && strcmp(selected_tax_rate->id, buffer[n].id) == 0;
+ bool is_selected = selected_tax_rate && strcmp(selected_tax_rate->internal_code, buffer[n].internal_code) == 0;
- if (strcmp(buffer[n].country_code, "00") == 0) {
- char category_code_desc[MAX_LEN_LONG_DESC];
- strops::format(category_code_desc, MAX_LEN_LONG_DESC, "taxcategory.%s", buffer[n].category_code);
- strops::format(rate_str_buf, 40, "%s", locale::get(category_code_desc));
- }
- else strops::format(rate_str_buf, 40, "%s/%.1f%%", buffer[n].country_code, buffer[n].rate);
+ char category_code_desc[MAX_LEN_LONG_DESC];
+ strops::format(category_code_desc, MAX_LEN_LONG_DESC, "taxrate.code.%s", buffer[n].internal_code);
+ strops::format(rate_str_buf, MAX_LEN_LONG_DESC, "%s", locale::get(category_code_desc));
if (ImGui::Selectable(rate_str_buf, is_selected)) {
selected_tax_rate_index = n;
@@ -391,7 +383,7 @@ namespace ImGui
}
if (selected_tax_rate_index != -1) {
- strops::copy(tax_rate_id, buffer[selected_tax_rate_index].id, MAX_LEN_ID);
+ strops::copy(tax_internal_code, buffer[selected_tax_rate_index].internal_code, MAX_LEN_SHORT_DESC);
}
memops::unalloc(buffer);
diff --git a/src/ui/ui_expenses.cpp b/src/ui/ui_expenses.cpp
index b3c878a..6aa6e96 100644
--- a/src/ui/ui_expenses.cpp
+++ b/src/ui/ui_expenses.cpp
@@ -36,7 +36,7 @@ static billing_item* invoice_items_buffer = 0;
void draw_addressee_form_ex(delivery_info* buffer, bool viewing_only = false);
void draw_contact_form_ex(contact* buffer, bool viewing_only = false, bool with_autocomplete = false);
-void draw_invoice_items_form(invoice* invoice);
+void draw_invoice_items_form(invoice* invoice, bool outgoing = true);
void ui::destroy_expenses()
{
@@ -134,7 +134,7 @@ static void draw_expense_form(invoice* buffer, bool viewing_only = false)
administration::invoice_set_currency(buffer, buffer->currency);
}
- draw_invoice_items_form(buffer);
+ draw_invoice_items_form(buffer, false);
if (viewing_only) ImGui::EndDisabled();
}
diff --git a/src/ui/ui_invoices.cpp b/src/ui/ui_invoices.cpp
index fbc6eb0..4ae1669 100644
--- a/src/ui/ui_invoices.cpp
+++ b/src/ui/ui_invoices.cpp
@@ -49,7 +49,7 @@ void ui::setup_invoices()
invoice_items_buffer = (billing_item*)memops::alloc(sizeof(billing_item) * invoice_items_count);
}
-void draw_invoice_items_form(invoice* invoice)
+void draw_invoice_items_form(invoice* invoice, bool outgoing)
{
billing_item* buffer = invoice_items_buffer;
u32 invoice_items = administration::billing_item_get_all_for_invoice(invoice, buffer);
@@ -110,7 +110,7 @@ void draw_invoice_items_form(invoice* invoice)
ImGui::TableSetColumnIndex(6);
ImGui::PushItemWidth(-1);
- ImGui::FormTaxRateCombo(item.tax_rate_id, invoice->customer.address.country_code, invoice->supplier.address.country_code, valid & A_ERR_MISSING_TAX_RATE);
+ ImGui::FormTaxRateCombo(item.tax_internal_code, outgoing, valid & A_ERR_MISSING_TAX_RATE);
ImGui::PopItemWidth();
@@ -243,7 +243,7 @@ static void draw_invoice_form(invoice* buffer, bool viewing_only = false)
administration::invoice_set_currency(buffer, buffer->currency);
}
- draw_invoice_items_form(buffer);
+ draw_invoice_items_form(buffer, true);
if (viewing_only) ImGui::EndDisabled();
}