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.cpp34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/administration_writer.cpp b/src/administration_writer.cpp
index 4722f7c..e7d9e07 100644
--- a/src/administration_writer.cpp
+++ b/src/administration_writer.cpp
@@ -155,8 +155,13 @@ static bool administration_writer_write_to_zip(char* entry_to_replace, char* ori
/////////////////////////////
//// Invoices
/////////////////////////////
+
static char* administration_writer_get_eas_id_for_contact(contact contact)
{
+ if (contact.type == contact_type::CONTACT_CONSUMER) {
+ return "[CONSUMER]";
+ }
+
// https://docs.peppol.eu/poacc/billing/3.0/codelist/eas/
char* country_code = contact.address.country_code;
@@ -176,7 +181,6 @@ static char* administration_writer_get_eas_id_for_contact(contact contact)
if (strcmp(country_code, "LU") == 0) return contact.taxid; // Luxembourg
if (strcmp(country_code, "LV") == 0) return contact.taxid; // Latvia
if (strcmp(country_code, "MT") == 0) return contact.taxid; // Malta
- if (strcmp(country_code, "NL") == 0) return contact.taxid; // Netherlands
if (strcmp(country_code, "PL") == 0) return contact.taxid; // Poland
if (strcmp(country_code, "PT") == 0) return contact.taxid; // Portugal
if (strcmp(country_code, "RO") == 0) return contact.taxid; // Romania
@@ -185,6 +189,7 @@ static char* administration_writer_get_eas_id_for_contact(contact contact)
if (strcmp(country_code, "ES") == 0) return contact.taxid; // Spain
// Countries using business identification numbers.
+ if (strcmp(country_code, "NL") == 0) return contact.businessid; // Netherlands
if (strcmp(country_code, "SE") == 0) return contact.businessid; // Sweden
if (strcmp(country_code, "LT") == 0) return contact.businessid; // Lithuania
if (strcmp(country_code, "IT") == 0) return contact.businessid; // Italy
@@ -193,8 +198,14 @@ static char* administration_writer_get_eas_id_for_contact(contact contact)
return NULL; // Unknown country code
}
-static char* administration_writer_get_eas_scheme_for_address(address addr)
+static char* administration_writer_get_eas_scheme_for_contact(contact contact)
{
+ if (contact.type == contact_type::CONTACT_CONSUMER) {
+ return "0203"; // Hack
+ }
+
+ address addr = contact.address;
+
// https://docs.peppol.eu/poacc/billing/3.0/codelist/eas/
char* country_code = addr.country_code;
if (strcmp(country_code, "AT") == 0) return "9914"; // Austria
@@ -216,7 +227,7 @@ static char* administration_writer_get_eas_scheme_for_address(address addr)
if (strcmp(country_code, "LU") == 0) return "9938"; // Luxembourg
if (strcmp(country_code, "LV") == 0) return "9939"; // Latvia
if (strcmp(country_code, "MT") == 0) return "9943"; // Malta
- if (strcmp(country_code, "NL") == 0) return "9944"; // Netherlands
+ if (strcmp(country_code, "NL") == 0) return "0106"; // Netherlands
if (strcmp(country_code, "PL") == 0) return "9945"; // Poland
if (strcmp(country_code, "PT") == 0) return "9946"; // Portugal
if (strcmp(country_code, "RO") == 0) return "9947"; // Romania
@@ -309,7 +320,7 @@ bool administration_writer_save_invoice_blocking(invoice inv)
strops_replace(file_content, buf_length, "{{INVOICE_DOCUMENT}}", inv.document);
// Supplier data
- strops_replace(file_content, buf_length, "{{SUPPLIER_ENDPOINT_SCHEME}}", administration_writer_get_eas_scheme_for_address(inv.supplier.address));
+ strops_replace(file_content, buf_length, "{{SUPPLIER_ENDPOINT_SCHEME}}", administration_writer_get_eas_scheme_for_contact(inv.supplier));
strops_replace(file_content, buf_length, "{{SUPPLIER_ENDPOINT_ID}}", administration_writer_get_eas_id_for_contact(inv.supplier));
strops_replace(file_content, buf_length, "{{SUPPLIER_ID}}", inv.supplier.id);
strops_replace(file_content, buf_length, "{{SUPPLIER_NAME}}", inv.supplier.name);
@@ -326,7 +337,7 @@ bool administration_writer_save_invoice_blocking(invoice inv)
strops_replace(file_content, buf_length, "{{SUPPLIER_EMAIL}}", inv.supplier.email);
// Customer data
- strops_replace(file_content, buf_length, "{{CUSTOMER_ENDPOINT_SCHEME}}", administration_writer_get_eas_scheme_for_address(inv.customer.address));
+ strops_replace(file_content, buf_length, "{{CUSTOMER_ENDPOINT_SCHEME}}", administration_writer_get_eas_scheme_for_contact(inv.customer));
strops_replace(file_content, buf_length, "{{CUSTOMER_ENDPOINT_ID}}", administration_writer_get_eas_id_for_contact(inv.customer));
strops_replace(file_content, buf_length, "{{CUSTOMER_ID}}", inv.customer.id);
strops_replace(file_content, buf_length, "{{CUSTOMER_NAME}}", inv.customer.name);
@@ -431,19 +442,18 @@ bool administration_writer_save_invoice_blocking(invoice inv)
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_rate_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}}",
- "<cbc:MultiplierFactorNumeric>{{DISCOUNT_TOTAL_PERCENTAGE}}</cbc:MultiplierFactorNumeric>");
- strops_replace_float(billing_item_file_content, billing_item_buf_length, "{{DISCOUNT_TOTAL_PERCENTAGE}}", bi.allowance / (bi.net + bi.allowance), 2);
+ strops_replace_float(billing_item_file_content, billing_item_buf_length, "{{DISCOUNT_TOTAL_PERCENTAGE}}", (bi.allowance / (bi.net + bi.allowance)) * 100.0f, 2);
+ strops_replace_float(billing_item_file_content, billing_item_buf_length, "{{DISCOUNT_BASE_AMOUNT}}", bi.net + bi.allowance, 2); // Total net before discount.
}
else {
- strops_replace(billing_item_file_content, billing_item_buf_length, "{{ALLOWANCE_IS_PERCENTAGE}}", "");
+ strops_replace(billing_item_file_content, billing_item_buf_length, "{{DISCOUNT_TOTAL_PERCENTAGE}}", "");
+ strops_replace(billing_item_file_content, billing_item_buf_length, "{{DISCOUNT_BASE_AMOUNT}}", "");
}
strops_replace_float(billing_item_file_content, billing_item_buf_length, "{{DISCOUNT_TOTAL}}", bi.allowance, 2);
- strops_replace_float(billing_item_file_content, billing_item_buf_length, "{{DISCOUNT_BASE_AMOUNT}}", bi.net + bi.allowance, 2); // Total net before discount.
u32 content_len = (u32)strlen(billing_item_file_content);
memcpy(billing_item_list_buffer+billing_item_list_buffer_cursor, billing_item_file_content, content_len);