diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/administration.cpp | 11 | ||||
| -rw-r--r-- | src/countries/nl.cpp | 115 | ||||
| -rw-r--r-- | src/ui/ui_tax.cpp | 28 |
3 files changed, 94 insertions, 60 deletions
diff --git a/src/administration.cpp b/src/administration.cpp index 5675cb4..495f847 100644 --- a/src/administration.cpp +++ b/src/administration.cpp @@ -2036,6 +2036,17 @@ a_err administration::billing_item_update_in_invoice(invoice* invoice, billing_i return A_ERR_NOT_FOUND; } +tax_subtotal administration::billing_item_convert_to_default_currency(invoice* invoice, billing_item item) +{ + tax_subtotal result = {0}; + if (invoice->net != 0.0f) result.net = item.net / (invoice->orig_net / invoice->net); + if (invoice->tax != 0.0f) result.tax = item.tax / (invoice->orig_tax / invoice->tax); + if (invoice->total != 0.0f) result.total = item.total / (invoice->orig_total / invoice->total); + if (invoice->allowance != 0.0f) result.allowance = item.allowance / (invoice->orig_allowance / invoice->allowance); + + return result; +} + a_err administration::billing_item_is_valid(billing_item item) { a_err result = A_ERR_SUCCESS; diff --git a/src/countries/nl.cpp b/src/countries/nl.cpp index bc45b59..cf79ee2 100644 --- a/src/countries/nl.cpp +++ b/src/countries/nl.cpp @@ -26,30 +26,30 @@ time_t _nl_get_default_invoice_expire_duration() void _nl_fill_tax_report_with_categories(tax_report* report) { - report->lines[report->line_count++] = tax_line {"taxes.nl.1", "", 0.0f, 0.0f}; - report->lines[report->line_count++] = tax_line {"taxes.nl.1a", "1a", 0.0f, 0.0f}; - report->lines[report->line_count++] = tax_line {"taxes.nl.1b", "1b", 0.0f, 0.0f}; - report->lines[report->line_count++] = tax_line {"taxes.nl.1c", "1c", 0.0f, 0.0f}; - report->lines[report->line_count++] = tax_line {"taxes.nl.1d", "1d", 0.0f, 0.0f}; - report->lines[report->line_count++] = tax_line {"taxes.nl.1e", "1e", 0.0f, 0.0f}; - - report->lines[report->line_count++] = tax_line {"taxes.nl.2", "", 0.0f, 0.0f}; - report->lines[report->line_count++] = tax_line {"taxes.nl.2a", "2a", 0.0f, 0.0f}; - - report->lines[report->line_count++] = tax_line {"taxes.nl.3", "", 0.0f, 0.0f}; - report->lines[report->line_count++] = tax_line {"taxes.nl.3a", "3a", 0.0f, 0.0f}; - report->lines[report->line_count++] = tax_line {"taxes.nl.3b", "3b", 0.0f, 0.0f}; - report->lines[report->line_count++] = tax_line {"taxes.nl.3c", "3c", 0.0f, 0.0f}; - - report->lines[report->line_count++] = tax_line {"taxes.nl.4", "", 0.0f, 0.0f}; - report->lines[report->line_count++] = tax_line {"taxes.nl.4a", "4a", 0.0f, 0.0f}; - report->lines[report->line_count++] = tax_line {"taxes.nl.4b", "4b", 0.0f, 0.0f}; - - report->lines[report->line_count++] = tax_line {"taxes.nl.5", "", 0.0f, 0.0f}; - report->lines[report->line_count++] = tax_line {"taxes.nl.5a", "5a", 0.0f, 0.0f}; - report->lines[report->line_count++] = tax_line {"taxes.nl.5b", "5b", 0.0f, 0.0f}; - - report->lines[report->line_count++] = tax_line {"taxes.total", "5c", 0.0f, 0.0f}; + report->lines[report->line_count++] = tax_line {"taxes.nl.1", "", 0.0f, 0.0f, false, false}; + report->lines[report->line_count++] = tax_line {"taxes.nl.1a", "1a", 0.0f, 0.0f, true, true}; + report->lines[report->line_count++] = tax_line {"taxes.nl.1b", "1b", 0.0f, 0.0f, true, true}; + report->lines[report->line_count++] = tax_line {"taxes.nl.1c", "1c", 0.0f, 0.0f, true, true}; + report->lines[report->line_count++] = tax_line {"taxes.nl.1d", "1d", 0.0f, 0.0f, true, true}; + report->lines[report->line_count++] = tax_line {"taxes.nl.1e", "1e", 0.0f, 0.0f, true, false}; + + report->lines[report->line_count++] = tax_line {"taxes.nl.2", "", 0.0f, 0.0f, false, false}; + report->lines[report->line_count++] = tax_line {"taxes.nl.2a", "2a", 0.0f, 0.0f, true, true}; + + report->lines[report->line_count++] = tax_line {"taxes.nl.3", "", 0.0f, 0.0f, false, false}; + report->lines[report->line_count++] = tax_line {"taxes.nl.3a", "3a", 0.0f, 0.0f, true, false}; + report->lines[report->line_count++] = tax_line {"taxes.nl.3b", "3b", 0.0f, 0.0f, true, false}; + report->lines[report->line_count++] = tax_line {"taxes.nl.3c", "3c", 0.0f, 0.0f, true, false}; + + report->lines[report->line_count++] = tax_line {"taxes.nl.4", "", 0.0f, 0.0f, false, false}; + report->lines[report->line_count++] = tax_line {"taxes.nl.4a", "4a", 0.0f, 0.0f, true, true}; + report->lines[report->line_count++] = tax_line {"taxes.nl.4b", "4b", 0.0f, 0.0f, true, true}; + + report->lines[report->line_count++] = tax_line {"taxes.nl.5", "", 0.0f, 0.0f, false, false}; + report->lines[report->line_count++] = tax_line {"taxes.nl.5a", "5a", 0.0f, 0.0f, false, true}; + report->lines[report->line_count++] = tax_line {"taxes.nl.5b", "5b", 0.0f, 0.0f, false, true}; + + report->lines[report->line_count++] = tax_line {"taxes.total", "5c", 0.0f, 0.0f, false, true}; } bool _nl_add_billing_item_to_tax_report(tax_report* report, invoice* inv, billing_item* item) @@ -60,6 +60,8 @@ bool _nl_add_billing_item_to_tax_report(tax_report* report, invoice* inv, billin a_err err = administration::tax_rate_get_by_id(&rate, item->tax_rate_id); if (err != A_ERR_SUCCESS) return 0; + tax_subtotal totals = administration::billing_item_convert_to_default_currency(inv, *item); + if (inv->is_outgoing) { tax_line* a5 = administration::get_tax_line_from_report(report, "5a"); // Total owed. @@ -68,42 +70,42 @@ bool _nl_add_billing_item_to_tax_report(tax_report* report, invoice* inv, billin { if (rate.rate == 21.0f) { tax_line* tl = administration::get_tax_line_from_report(report, "1a"); - tl->total_net += item->net; - tl->total_tax += item->tax; + tl->total_net += totals.net; + tl->total_tax += totals.tax; - a5->total_tax += item->tax; + a5->total_tax += totals.tax; } else if (rate.rate == 9.0f) { - tax_line* tl = administration::get_tax_line_from_report(report, "1b"); - tl->total_net += item->net; - tl->total_tax += item->tax; + tax_line* tl = administration::get_tax_line_from_report(report, "1b"); + tl->total_net += totals.net; + tl->total_tax += totals.tax; - a5->total_tax += item->tax; + a5->total_tax += totals.tax; } // TODO 1c else if (rate.rate > 0.0f) { tax_line* tl = administration::get_tax_line_from_report(report, "1d"); - tl->total_net += item->net; - tl->total_tax += item->tax; + tl->total_net += totals.net; + tl->total_tax += totals.tax; - a5->total_tax += item->tax; + a5->total_tax += totals.tax; } else if (rate.rate == 0.0f) { - tax_line* tl = administration::get_tax_line_from_report(report, "1e"); - tl->total_net += item->net; - tl->total_tax += item->tax; + tax_line* tl = administration::get_tax_line_from_report(report, "1e"); + tl->total_net += totals.net; + tl->total_tax += totals.tax; - a5->total_tax += item->tax; + a5->total_tax += totals.tax; } } else if (!country::is_EU(inv->customer.address.country_code)) { tax_line* tl = administration::get_tax_line_from_report(report, "3a"); - tl->total_net += item->net; + tl->total_net += totals.net; // Tax is paid to country of customer. } else { tax_line* tl = administration::get_tax_line_from_report(report, "3b"); - tl->total_net += item->net; + tl->total_net += totals.net; // Tax is paid to country of customer. } // TODO 3c @@ -117,34 +119,31 @@ bool _nl_add_billing_item_to_tax_report(tax_report* report, invoice* inv, billin 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? - tl->total_net += item->net; - tl->total_tax += item->net * 0.21f; // TODO fr? - - a5->total_tax += item->net * 0.21f; - b5->total_tax += item->net * 0.21f; + a5->total_tax += totals.net * 0.21f; + b5->total_tax += totals.net * 0.21f; } else { - b5->total_tax += item->tax; + 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"); + tl->total_net += totals.net; + tl->total_tax += totals.net * 0.21f; - tl->total_net += item->net; - tl->total_tax += item->net * 0.21f; - - a5->total_tax += item->net * 0.21f; - b5->total_tax += item->net * 0.21f; + a5->total_tax += totals.net * 0.21f; + b5->total_tax += totals.net * 0.21f; } else { tax_line* tl = administration::get_tax_line_from_report(report, "4b"); + tl->total_net += totals.net; + tl->total_tax += totals.net * 0.21f; - tl->total_net += item->net; - tl->total_tax += item->net * 0.21f; - - a5->total_tax += item->net * 0.21f; - b5->total_tax += item->net * 0.21f; + a5->total_tax += totals.net * 0.21f; + b5->total_tax += totals.net * 0.21f; } } @@ -158,7 +157,9 @@ float _nl_calculate_tax_report_final(tax_report* report) tax_line* total = administration::get_tax_line_from_report(report, "5c"); total->total_tax = a5->total_tax - b5->total_tax; - return (float)ceil(total->total_tax); + if (total->total_tax < 0.0f) total->total_tax = (float)ceil(total->total_tax); + else total->total_tax = (float)floor(total->total_tax); + return total->total_tax; } time_t _nl_get_invoice_date_to_use_for_tax_report(invoice* inv) diff --git a/src/ui/ui_tax.cpp b/src/ui/ui_tax.cpp index 37eeaee..8a119e4 100644 --- a/src/ui/ui_tax.cpp +++ b/src/ui/ui_tax.cpp @@ -66,9 +66,9 @@ void ui::draw_tax_report() { ImGui::PushFont(fontBold); ImGui::TableSetupColumn("##desc", ImGuiTableColumnFlags_WidthStretch); - ImGui::TableSetupColumn("##names", ImGuiTableColumnFlags_WidthFixed, 150); - ImGui::TableSetupColumn(report.quarter_str, ImGuiTableColumnFlags_WidthFixed, 150); - ImGui::TableSetupColumn("##tax", ImGuiTableColumnFlags_WidthFixed, 150); + ImGui::TableSetupColumn("##names", ImGuiTableColumnFlags_WidthFixed, 60); + ImGui::TableSetupColumn(report.quarter_str, ImGuiTableColumnFlags_WidthFixed, 120); + ImGui::TableSetupColumn("##tax", ImGuiTableColumnFlags_WidthFixed, 120); ImGui::TableHeadersRow(); ImGui::PopFont(); @@ -85,6 +85,7 @@ void ui::draw_tax_report() ImGui::TableSetColumnIndex(0); ImGui::Text("%s", locale::get(line.tax_description)); ImGui::TableSetColumnIndex(1); ImGui::Text("%s", locale::get(line.tax_category)); + #if 0 if (!strops::equals(line.tax_category, "")) { ImGui::TableSetColumnIndex(2); ImGui::Text("%.2f %s", line.total_net, currency_symbol); @@ -102,6 +103,27 @@ void ui::draw_tax_report() } } } + #else + ImGui::TableSetColumnIndex(2); + if (line.show_net) ImGui::Text("%.2f %s", line.total_net, currency_symbol); + else ImGui::Text(""); + + ImGui::TableSetColumnIndex(3); + if (line.show_tax) { + if (!is_last) ImGui::Text("%.2f %s", line.total_tax, currency_symbol); + else { + if (line.total_tax < 0.0f) { + ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(235, 64, 52, 255)); + ImGui::Text("(%.0f %s)", line.total_tax, currency_symbol); + ImGui::PopStyleColor(); + } + else { + ImGui::Text("%.0f %s", line.total_tax, currency_symbol); + } + } + } + else ImGui::Text(""); + #endif if (bold) ImGui::PopFont(); } |
