summaryrefslogtreecommitdiff
path: root/src/administration.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/administration.cpp
parent1c53bd3ac83cc7a985983ac656bc2599276808a4 (diff)
working on NL tax reports
Diffstat (limited to 'src/administration.cpp')
-rw-r--r--src/administration.cpp70
1 files changed, 53 insertions, 17 deletions
diff --git a/src/administration.cpp b/src/administration.cpp
index 9adce55..0ad9684 100644
--- a/src/administration.cpp
+++ b/src/administration.cpp
@@ -78,7 +78,8 @@ static void create_default_tax_rates()
ADD_BRACKET("00", 0.0f, "Z"); // Zero rated goods
ADD_BRACKET("00", 0.0f, "G"); // Free export item, VAT not charged
ADD_BRACKET("00", 0.0f, "O"); // Services outside scope of tax
- ADD_BRACKET("00", 0.0f, "K"); // VAT exempt for EEA intra-community supply of goods and services
+ ADD_BRACKET("00", 0.0f, "K#G"); // VAT exempt for EEA intra-community supply of goods
+ ADD_BRACKET("00", 0.0f, "K#S"); // VAT exempt for EEA intra-community supply of services
// Austria
ADD_BRACKET("AT", 20.0f, "S");
@@ -502,16 +503,16 @@ void administration::create_tax_statement(tax_statement* statement)
u16 oldest_year;
u8 oldest_quarter;
time_t_to_quarter(oldest, &oldest_year, &oldest_quarter);
- oldest_quarter = 0;
+ //oldest_quarter = 0;
u16 youngest_year;
u8 youngest_quarter;
time_t_to_quarter(youngest, &youngest_year, &youngest_quarter);
- youngest_quarter = 3;
+ //youngest_quarter = 3;
u32 num_quarters = (youngest_quarter+1 + (youngest_year*4)) - (oldest_quarter + (oldest_year*4));
assert(num_quarters <= MAX_LEN_INCOME_STATEMENT_REPORT_QUARTERS);
- assert(num_quarters % 4 == 0);
+ //assert(num_quarters % 4 == 0);
// Generate quarters.
for (u32 i = 0; i < num_quarters; i++)
@@ -524,6 +525,8 @@ void administration::create_tax_statement(tax_statement* statement)
strops::format(quarter.quarter_str, MAX_LEN_SHORT_DESC, "%dQ%d", quarter.quarter+1, quarter.year);
country::fill_tax_report_with_categories(country_code, &quarter);
+
+ statement->reports[statement->quarter_count++] = quarter;
}
// Fill quarters.
@@ -533,7 +536,7 @@ void administration::create_tax_statement(tax_statement* statement)
u16 yy;
u8 qq;
- time_t_to_quarter(inv->issued_at, &yy, &qq);
+ time_t_to_quarter(country::get_invoice_date_to_use_for_tax_report(country_code, inv), &yy, &qq);
u32 report_index = (qq + (yy*4)) - (oldest_quarter + (oldest_year*4));
@@ -545,24 +548,30 @@ void administration::create_tax_statement(tax_statement* statement)
u32 invoice_items = administration::billing_item_get_all_for_invoice(inv, item_buffer);
for (u32 x = 0; x < invoice_items; x++)
{
- char* tax_category = country::get_tax_category_for_billing_item(country_code, inv, &item_buffer[x]);
- for (u32 t = 0; t < quarter->line_count; t++)
- {
- if (strops::equals(quarter->lines[t].tax_category, tax_category))
- {
- quarter->lines[t].total_net += inv->net;
- quarter->lines[t].total_tax += inv->tax;
- }
- }
+ bool success = country::add_billing_item_to_tax_report(country_code, quarter, inv, &item_buffer[x]);
+ if (!success) logger::error("Failed to add billing item to tax report: %s - %s.", inv->sequential_number, item_buffer[x].description);
+ }
+ country::calculate_tax_report_final(country_code, quarter);
- memops::unalloc(item_buffer);
- }
+ memops::unalloc(item_buffer);
}
-
+
memops::unalloc(invoice_buffer);
logger::info("Created tax statement in %.3fms.", STOPWATCH_TIME);
}
+tax_line* administration::get_tax_line_from_report(tax_report* quarter, char* category)
+{
+ for (u32 t = 0; t < quarter->line_count; t++)
+ {
+ if (strops::equals(quarter->lines[t].tax_category, category))
+ {
+ return &quarter->lines[t];
+ }
+ }
+ return 0;
+}
+
void administration::create_income_statement(income_statement* statement)
{
STOPWATCH_START;
@@ -1216,6 +1225,13 @@ a_err administration::tax_rate_get_by_shorthandle(tax_rate* buffer, char* handle
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);
@@ -1527,6 +1543,26 @@ static char* get_default_currency_for_country(char* country_code)
return "EUR";
}
+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);
+
+ return false;
+}
+
invoice administration::invoice_create_empty()
{
invoice result;