diff options
| author | Aldrik Ramaekers <aldrik@mailbox.org> | 2026-01-03 11:03:50 +0100 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrik@mailbox.org> | 2026-01-03 11:03:50 +0100 |
| commit | 83a9739b3aff75cf767db687bd531fa5283e0e72 (patch) | |
| tree | adf130cb7728a4358062a040f6322ecc236d0e6b /src/administration_writer.cpp | |
| parent | 2218ef68056ebc5a3a416e2dd7e8e020fba60a4f (diff) | |
move invoice status to invoice extras struct. implement r/w
Diffstat (limited to 'src/administration_writer.cpp')
| -rw-r--r-- | src/administration_writer.cpp | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/src/administration_writer.cpp b/src/administration_writer.cpp index 8304e5c..3191be7 100644 --- a/src/administration_writer.cpp +++ b/src/administration_writer.cpp @@ -240,7 +240,7 @@ void administration_writer::destroy() static char* copy_template(const char* template_str, int* buf_size) { size_t template_size = strops::length(template_str); - size_t buf_length = template_size*5; // Ballpark file content size. + size_t buf_length = template_size*5; // Ballpark file content size. // @TODO char* file_content = (char*)memops::alloc(buf_length); memops::zero(file_content, buf_length); memops::copy(file_content, template_str, template_size); @@ -504,12 +504,40 @@ static void _add_document_to_zip(invoice* inv) } } +bool _save_invoice_extras(invoice inv) +{ + STOPWATCH_START; + + bool result = 1; + int buf_length = 0; + char* file_content = copy_template(file_template::invoice_extras_template, &buf_length); + + strops::replace_int32(file_content, buf_length, "{{INVOICE_STATUS}}", (s32)inv.extras.status); + + //// Write to Disk. + char final_path[50]; + strops::format(final_path, 50, "EXTRAS/%s.xml", inv.sequential_number); + + int final_length = (int)strops::length(file_content); + if (!xml_string_is_valid((uint8_t*)file_content, final_length)) result = 0; + else if (!write_to_zip(final_path, file_content, final_length)) result = 0; + + memops::unalloc(file_content); + + if (result) logger::info("Saved invoice extras for '%s' in %.3fms.", inv.sequential_number, STOPWATCH_TIME); + else logger::error("Failed to save invoice extras for '%s'.", inv.sequential_number); + + return result; +} + bool administration_writer::save_invoice_blocking(invoice inv) { + _save_invoice_extras(inv); + STOPWATCH_START; bool result = 1; - int buf_length = 150000; // Ballpark file content size. + int buf_length = 150000; // Ballpark file content size. // @TODO char* file_content = (char*)memops::alloc(buf_length); memops::zero(file_content, buf_length); memops::copy(file_content, file_template::peppol_invoice_template, strops::length(file_template::peppol_invoice_template)); @@ -526,7 +554,7 @@ bool administration_writer::save_invoice_blocking(invoice inv) strops::replace(file_content, buf_length, "{{COST_CENTER_ID}}", inv.cost_center_id); strops::replace(file_content, buf_length, "{{INVOICE_DOCUMENT_COPY}}", inv.document.copy_path); strops::replace(file_content, buf_length, "{{INVOICE_DOCUMENT_ORIG}}", inv.document.original_path); - strops::replace_int32(file_content, buf_length, "{{INVOICE_STATUS}}", (s32)inv.status); + //strops::replace_int32(file_content, buf_length, "{{INVOICE_STATUS}}", (s32)inv.status); // Supplier data strops::replace(file_content, buf_length, "{{SUPPLIER_ENDPOINT_SCHEME}}", get_eas_scheme_for_contact(inv.supplier)); @@ -587,7 +615,7 @@ bool administration_writer::save_invoice_blocking(invoice inv) tax_rate* tax_rate_buffer = (tax_rate*)memops::alloc(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)strops::length(file_template::peppol_invoice_tax_subtotal_template) * 2 * tax_rate_count; // Ballpark list size. + u32 tax_subtotal_list_buffer_size = (u32)strops::length(file_template::peppol_invoice_tax_subtotal_template) * 2 * tax_rate_count; // Ballpark list size. // @TODO char* tax_subtotal_list_buffer = (char*)memops::alloc(tax_subtotal_list_buffer_size); memops::zero(tax_subtotal_list_buffer, tax_subtotal_list_buffer_size); u32 tax_subtotal_list_buffer_cursor = 0; @@ -631,7 +659,7 @@ bool administration_writer::save_invoice_blocking(invoice inv) billing_item* billing_item_buffer = (billing_item*)memops::alloc(sizeof(billing_item) * administration::billing_item_count(&inv)); u32 billing_item_count = administration::billing_item_get_all_for_invoice(&inv, billing_item_buffer); - u32 billing_item_list_buffer_size = (u32)strops::length(file_template::peppol_invoice_line_template) * 2 * billing_item_count; // Ballpark list size. + u32 billing_item_list_buffer_size = (u32)strops::length(file_template::peppol_invoice_line_template) * 2 * billing_item_count; // Ballpark list size. // @TODO char* billing_item_list_buffer = (char*)memops::alloc(billing_item_list_buffer_size); memops::zero(billing_item_list_buffer, billing_item_list_buffer_size); u32 billing_item_list_buffer_cursor = 0; |
