summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/administration_writer.cpp51
1 files changed, 50 insertions, 1 deletions
diff --git a/src/administration_writer.cpp b/src/administration_writer.cpp
index 26e26c8..4722f7c 100644
--- a/src/administration_writer.cpp
+++ b/src/administration_writer.cpp
@@ -227,6 +227,53 @@ static char* administration_writer_get_eas_scheme_for_address(address addr)
return NULL; // Unknown country code
}
+bool isEmptyTag(const char *start, const char *end) {
+ const char *ptr = start;
+ while (ptr < end) {
+ if (*ptr != ' ' && *ptr != '\n' && *ptr != '\t') {
+ return false;
+ }
+ ptr++;
+ }
+ return true;
+}
+
+void _remove_empty_xml_tags(char* file_content, int depth)
+{
+ for (int i = 0; i < depth; i++)
+ {
+ char *read = file_content;
+ char *write = file_content;
+
+ while (*read) {
+ if (*read == '<') {
+ char *tagStart = read;
+ if (*(tagStart+1) != '/') {
+ char *tagEnd = strchr(tagStart, '>');
+ if (!tagEnd) break; // malformed XML
+
+ char *nextTagStart = strchr(tagEnd, '<');
+ if (*(nextTagStart+1) == '/')
+ {
+ // Check for empty tag <tag></tag>
+ char *closeTagStart = strstr(tagEnd + 1, "</");
+ if (closeTagStart && isEmptyTag(tagEnd + 1, closeTagStart)) {
+ char *closeTagEnd = strchr(closeTagStart, '>');
+ if (closeTagEnd) {
+ read = closeTagEnd + 1; // skip entire empty tag
+ continue;
+ }
+ }
+ }
+ }
+ }
+
+ *write++ = *read++;
+ }
+ *write = '\0'; // terminate the modified string
+ }
+}
+
bool administration_writer_save_invoice_blocking(invoice inv)
{
STOPWATCH_START;
@@ -375,7 +422,7 @@ bool administration_writer_save_invoice_blocking(invoice inv)
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, "{{CURRENCY}}", bi.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}}", rate.category_code);
@@ -420,6 +467,8 @@ bool administration_writer_save_invoice_blocking(invoice inv)
strftime(date_buffer, sizeof(date_buffer), "%Y-%m-%d", tm_info);
strops_replace(file_content, buf_length, "{{DUE_DATE}}", date_buffer);
+ _remove_empty_xml_tags(file_content, 5);
+
//// Write to Disk.
char final_path[50];
snprintf(final_path, 50, "%s.xml", inv.id);