summaryrefslogtreecommitdiff
path: root/src/administration_writer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/administration_writer.cpp')
-rw-r--r--src/administration_writer.cpp70
1 files changed, 35 insertions, 35 deletions
diff --git a/src/administration_writer.cpp b/src/administration_writer.cpp
index d19fb51..119f4b4 100644
--- a/src/administration_writer.cpp
+++ b/src/administration_writer.cpp
@@ -34,9 +34,9 @@ static void on_contact_changed_changed(contact* contact)
administration_writer_save_contact_blocking(*contact);
}
-static void on_taxbracket_changed_changed(country_tax_bracket* bracket)
+static void on_taxrate_changed_changed(tax_rate* rate)
{
- administration_writer_save_tax_bracket_blocking(*bracket);
+ administration_writer_save_tax_rate_blocking(*rate);
}
static void on_costcenter_changed_changed(cost_center* cost_center)
@@ -55,7 +55,7 @@ bool administration_writer_create()
administration_set_data_deleted_event_callback(on_administration_data_deleted);
administration_set_invoice_changed_event_callback(on_invoice_changed);
administration_set_contact_changed_event_callback(on_contact_changed_changed);
- administration_set_taxbracket_changed_event_callback(on_taxbracket_changed_changed);
+ administration_set_taxrate_changed_event_callback(on_taxrate_changed_changed);
administration_set_costcenter_changed_event_callback(on_costcenter_changed_changed);
administration_set_project_changed_event_callback(on_project_changed_changed);
@@ -292,27 +292,27 @@ bool administration_writer_save_invoice_blocking(invoice inv)
// Tax breakdown
strops_replace_float(file_content, buf_length, "{{TOTAL_TAX_AMOUNT}}", inv.tax, 2);
{ // Create tax subtotal list.
- country_tax_bracket* tax_bracket_buffer = (country_tax_bracket*)malloc(sizeof(country_tax_bracket)*administration_billing_item_count(&inv));
- u32 tax_bracket_count = administration_invoice_get_tax_brackets(&inv, tax_bracket_buffer);
+ tax_rate* tax_rate_buffer = (tax_rate*)malloc(sizeof(tax_rate)*administration_billing_item_count(&inv));
+ u32 tax_rate_count = administration_invoice_get_tax_rates(&inv, tax_rate_buffer);
- u32 tax_subtotal_list_buffer_size = (u32)strlen(peppol_invoice_tax_subtotal_template) * 2 * tax_bracket_count; // Ballpark list size.
+ u32 tax_subtotal_list_buffer_size = (u32)strlen(peppol_invoice_tax_subtotal_template) * 2 * tax_rate_count; // Ballpark list size.
char* tax_subtotal_list_buffer = (char*)malloc(tax_subtotal_list_buffer_size);
memset(tax_subtotal_list_buffer, 0, tax_subtotal_list_buffer_size);
u32 tax_subtotal_list_buffer_cursor = 0;
- for (u32 i = 0; i < tax_bracket_count; i++)
+ for (u32 i = 0; i < tax_rate_count; i++)
{
int tax_entry_buf_length = 0;
char* tax_entry_file_content = administration_writer_copy_template(peppol_invoice_tax_subtotal_template, &tax_entry_buf_length);
tax_subtotal subtotal;
- administration_invoice_get_subtotal_for_tax_bracket(&inv, tax_bracket_buffer[i], &subtotal);
+ administration_invoice_get_subtotal_for_tax_rate(&inv, tax_rate_buffer[i], &subtotal);
strops_replace(tax_entry_file_content, tax_entry_buf_length, "{{CURRENCY}}", inv.currency);
strops_replace_float(tax_entry_file_content, tax_entry_buf_length, "{{TAXABLE_AMOUNT}}", subtotal.net, 2);
strops_replace_float(tax_entry_file_content, tax_entry_buf_length, "{{TAX_AMOUNT}}", subtotal.tax, 2);
- strops_replace(tax_entry_file_content, tax_entry_buf_length, "{{TAX_CATEGORY}}", tax_bracket_buffer[i].category_code);
- strops_replace_float(tax_entry_file_content, tax_entry_buf_length, "{{TAX_PERCENT}}", tax_bracket_buffer[i].rate, 2);
+ strops_replace(tax_entry_file_content, tax_entry_buf_length, "{{TAX_CATEGORY}}", tax_rate_buffer[i].category_code);
+ strops_replace_float(tax_entry_file_content, tax_entry_buf_length, "{{TAX_PERCENT}}", tax_rate_buffer[i].rate, 2);
u32 content_len = (u32)strlen(tax_entry_file_content);
memcpy(tax_subtotal_list_buffer+tax_subtotal_list_buffer_cursor, tax_entry_file_content, content_len);
@@ -324,7 +324,7 @@ bool administration_writer_save_invoice_blocking(invoice inv)
strops_replace(file_content, buf_length, "{{TAX_SUBTOTAL_LIST}}", tax_subtotal_list_buffer);
free(tax_subtotal_list_buffer);
- free(tax_bracket_buffer);
+ free(tax_rate_buffer);
}
// Totals
@@ -349,19 +349,19 @@ bool administration_writer_save_invoice_blocking(invoice inv)
char* billing_item_file_content = administration_writer_copy_template(peppol_invoice_line_template, &billing_item_buf_length);
billing_item bi = billing_item_buffer[i];
- country_tax_bracket bracket;
- administration_tax_bracket_get_by_id(&bracket, bi.tax_bracket_id);
+ tax_rate rate;
+ administration_tax_rate_get_by_id(&rate, bi.tax_rate_id);
strops_replace(billing_item_file_content, billing_item_buf_length, "{{CURRENCY}}", inv.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, "{{ITEM_NAME}}", bi.description);
- strops_replace(billing_item_file_content, billing_item_buf_length, "{{LINE_TAX_CATEGORY}}", bracket.category_code);
- strops_replace_float(billing_item_file_content, billing_item_buf_length, "{{LINE_TAX_PERCENT}}", bracket.rate, 2);
+ strops_replace(billing_item_file_content, billing_item_buf_length, "{{LINE_TAX_CATEGORY}}", rate.category_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);
strops_replace_float(billing_item_file_content, billing_item_buf_length, "{{UNIT_PRICE}}", bi.net_per_item, 2); // unit price before discount
strops_replace(billing_item_file_content, billing_item_buf_length, "{{UNIT_CODE}}", bi.amount_is_percentage ? "%" : "X");
- strops_replace(billing_item_file_content, billing_item_buf_length, "{{TAX_BRACKET_ID}}", bi.tax_bracket_id);
+ strops_replace(billing_item_file_content, billing_item_buf_length, "{{TAX_BRACKET_ID}}", bi.tax_rate_id);
if (bi.discount_is_percentage) {
strops_replace(billing_item_file_content, billing_item_buf_length, "{{ALLOWANCE_IS_PERCENTAGE}}",
@@ -523,24 +523,24 @@ bool administration_writer_save_all_cost_centers_blocking()
}
/////////////////////////////
-//// Tax brackets
+//// Tax rates
/////////////////////////////
-bool administration_writer_save_tax_bracket_blocking(country_tax_bracket bracket)
+bool administration_writer_save_tax_rate_blocking(tax_rate rate)
{
STOPWATCH_START;
bool result = 1;
int buf_length = 0;
- char* file_content = administration_writer_copy_template(taxbracket_save_template, &buf_length);
+ char* file_content = administration_writer_copy_template(taxrate_save_template, &buf_length);
- strops_replace(file_content, buf_length, "{{TAXBRACKET_ID}}", bracket.id);
- strops_replace(file_content, buf_length, "{{TAXBRACKET_COUNTRY}}", bracket.country_code);
- strops_replace_float(file_content, buf_length, "{{TAXBRACKET_RATE}}", bracket.rate, 2);
- strops_replace(file_content, buf_length, "{{TAXBRACKET_CATEGORY}}", bracket.category_code);
+ strops_replace(file_content, buf_length, "{{TAXBRACKET_ID}}", rate.id);
+ strops_replace(file_content, buf_length, "{{TAXBRACKET_COUNTRY}}", rate.country_code);
+ strops_replace_float(file_content, buf_length, "{{TAXBRACKET_RATE}}", rate.rate, 2);
+ strops_replace(file_content, buf_length, "{{TAXBRACKET_CATEGORY}}", rate.category_code);
//// Write to Disk.
char final_path[50];
- snprintf(final_path, 50, "%s.xml", bracket.id);
+ snprintf(final_path, 50, "%s.xml", rate.id);
int final_length = (int)strlen(file_content);
if (!xml_parse_document((uint8_t*)file_content, final_length)) result = 0;
@@ -548,26 +548,26 @@ bool administration_writer_save_tax_bracket_blocking(country_tax_bracket bracket
free(file_content);
- log_add("Saved tax bracket '%s/%.1f' in %.3fms.", bracket.country_code, bracket.rate, STOPWATCH_TIME);
+ log_add("Saved tax rate '%s/%.1f' in %.3fms.", rate.country_code, rate.rate, STOPWATCH_TIME);
return result;
}
-bool administration_writer_save_all_tax_brackets_blocking()
+bool administration_writer_save_all_tax_rates_blocking()
{
//// Get all data.
- u32 num_brackets = administration_tax_bracket_count();
- u32 buffer_size = sizeof(country_tax_bracket) * num_brackets;
- country_tax_bracket* bracket_buffer = (country_tax_bracket*)malloc(buffer_size);
- num_brackets = administration_tax_bracket_get_all(bracket_buffer);
+ u32 num_rates = administration_tax_rate_count();
+ u32 buffer_size = sizeof(tax_rate) * num_rates;
+ tax_rate* rate_buffer = (tax_rate*)malloc(buffer_size);
+ num_rates = administration_tax_rate_get_all(rate_buffer);
bool result = 1;
- for (u32 i = 0; i < num_brackets; i++) {
- country_tax_bracket c = bracket_buffer[i];
- if (!administration_writer_save_tax_bracket_blocking(c)) result = 0;
+ for (u32 i = 0; i < num_rates; i++) {
+ tax_rate c = rate_buffer[i];
+ if (!administration_writer_save_tax_rate_blocking(c)) result = 0;
}
- free(bracket_buffer);
+ free(rate_buffer);
return result;
}
@@ -671,7 +671,7 @@ static int administration_writer_write_all_t(void *arg) {
if (!administration_writer_save_all_invoices_blocking()) result = 0;
if (!administration_writer_save_all_projects_blocking()) result = 0;
if (!administration_writer_save_all_administration_info_blocking()) result = 0;
- if (!administration_writer_save_all_tax_brackets_blocking()) result = 0;
+ if (!administration_writer_save_all_tax_rates_blocking()) result = 0;
if (!administration_writer_save_all_cost_centers_blocking()) result = 0;
if (!administration_writer_save_all_contacts_blocking()) result = 0;