summaryrefslogtreecommitdiff
path: root/src/countries/nl.cpp
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2025-10-10 22:03:05 +0200
committerAldrik Ramaekers <aldrikboy@gmail.com>2025-10-10 22:03:05 +0200
commitd976c1227f367a4547a004597b8d360a8958eba9 (patch)
tree891b89263176375f058598b629b145177531a54a /src/countries/nl.cpp
parent1c53bd3ac83cc7a985983ac656bc2599276808a4 (diff)
working on NL tax reports
Diffstat (limited to 'src/countries/nl.cpp')
-rw-r--r--src/countries/nl.cpp125
1 files changed, 102 insertions, 23 deletions
diff --git a/src/countries/nl.cpp b/src/countries/nl.cpp
index 85005d6..9c8a20b 100644
--- a/src/countries/nl.cpp
+++ b/src/countries/nl.cpp
@@ -14,7 +14,10 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <math.h>
+
#include "countries.hpp"
+#include "strops.hpp"
time_t _nl_get_default_invoice_expire_duration()
{
@@ -44,7 +47,7 @@ void _nl_fill_tax_report_with_categories(tax_report* report)
report->lines[report->line_count++] = tax_line {"Total", 0.0f, 0.0f};
}
-char* _nl_get_tax_category_for_billing_item(invoice* inv, billing_item* item)
+bool _nl_add_billing_item_to_tax_report(tax_report* report, invoice* inv, billing_item* item)
{
// https://goedestartbelastingdienst.nl/wiki/view/7494ecb4-f6d2-4f85-a200-5a3ee5d45b75/btw-aangifte-het-invullen-van-de-verschillende-rubrieken
@@ -52,43 +55,117 @@ char* _nl_get_tax_category_for_billing_item(invoice* inv, billing_item* item)
a_err err = administration::tax_rate_get_by_id(&rate, item->tax_rate_id);
if (err != A_ERR_SUCCESS) return 0;
-
- /*
- We moeten 5a ook nog berekenen, dus misschien tax_report meegeven en hier alles doen wat nodig is?
- we moeten ook nog het uiteindelijke bedrag uitregenen 5a-5b dus dat moet ook hier gebeuren.
-
- */
-
- // Outgoing = 1 + 3
if (inv->is_outgoing) {
+ tax_line* a5 = administration::get_tax_line_from_report(report, "5a"); // Total owed.
+
if (strops::equals(inv->customer.address.country_code, "NL"))
{
- if (rate.rate == 21.0f) return "1a";
- else if (rate.rate == 9.0f) return "1b";
+ 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;
+
+ a5->total_tax += item->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;
+
+ a5->total_tax += item->tax;
+ }
// TODO 1c
- else if (rate.rate > 0.0f) return "1d";
- else if (rate.rate == 0.0f) return "1e";
+ 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;
+
+ a5->total_tax += item->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;
+
+ a5->total_tax += item->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;
+ // Tax is paid to country of customer.
+ }
+ else {
+ tax_line* tl = administration::get_tax_line_from_report(report, "3b");
+ tl->total_net += item->net;
+ // Tax is paid to country of customer.
}
- else if (!country::is_EU(inv->customer.address.country_code)) return "3a";
- else return "3b";
// TODO 3c
}
-
- // Incomming = 2 + 4 + 5
else {
+ tax_line* a5 = administration::get_tax_line_from_report(report, "5a"); // Total owed.
+ tax_line* b5 = administration::get_tax_line_from_report(report, "5b"); // Input tax.
if (strops::equals(inv->customer.address.country_code, "NL")) {
- if (strops::equals(rate.category_code, "AE")) return "2a"; // NL reverse charge.
- else return "5b";
+
+ if (strops::equals(rate.category_code, "AE")) { // NL reverse charge.
+ tax_line* tl = administration::get_tax_line_from_report(report, "2a");
+
+ 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;
+ }
+ else {
+ b5->total_tax += item->tax;
+ }
+ }
+
+ if (!country::is_EU(inv->customer.address.country_code)) {
+ tax_line* tl = administration::get_tax_line_from_report(report, "4a");
+
+ 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;
}
+ else {
+ tax_line* tl = administration::get_tax_line_from_report(report, "4b");
+
+ tl->total_net += item->net;
+ tl->total_tax += item->net * 0.21f;
- if (!country::is_EU(inv->customer.address.country_code)) return "4a";
- else return "4b";
+ a5->total_tax += item->net * 0.21f;
+ b5->total_tax += item->net * 0.21f;
+ }
}
- return 0;
+ return 1;
+}
+
+float _nl_calculate_tax_report_final(tax_report* report)
+{
+ tax_line* a5 = administration::get_tax_line_from_report(report, "5a"); // Total owed.
+ tax_line* b5 = administration::get_tax_line_from_report(report, "5b"); // Input tax.
+ tax_line* total = administration::get_tax_line_from_report(report, "Total");
+
+ total->total_tax = a5->total_tax - b5->total_tax;
+ return (float)ceil(total->total_tax);
+}
+
+time_t _nl_get_invoice_date_to_use_for_tax_report(invoice* inv)
+{
+ if (!inv->is_outgoing) { // Intra-Community services need to be reported in the quarter the service was delivered.
+ if (administration::invoice_has_intra_community_services(inv)) {
+ return inv->delivered_at;
+ }
+ }
+
+ return inv->issued_at;
}
country_impl _nl_country_impl = {
@@ -96,5 +173,7 @@ country_impl _nl_country_impl = {
true,
_nl_get_default_invoice_expire_duration,
_nl_fill_tax_report_with_categories,
- _nl_get_tax_category_for_billing_item,
+ _nl_add_billing_item_to_tax_report,
+ _nl_calculate_tax_report_final,
+ _nl_get_invoice_date_to_use_for_tax_report,
}; \ No newline at end of file