diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/administration.cpp | 2 | ||||
| -rw-r--r-- | src/administration_writer.cpp | 9 | ||||
| -rw-r--r-- | src/log.cpp | 27 | ||||
| -rw-r--r-- | src/ui/ui_earnings.cpp | 5 | ||||
| -rw-r--r-- | src/ui/ui_expenses.cpp | 15 | ||||
| -rw-r--r-- | src/ui/ui_invoices.cpp | 15 |
6 files changed, 71 insertions, 2 deletions
diff --git a/src/administration.cpp b/src/administration.cpp index f8cbdb3..bbc9a65 100644 --- a/src/administration.cpp +++ b/src/administration.cpp @@ -563,6 +563,7 @@ void administration_create_income_statement(income_statement* statement) quarter.uncategorized_revenue = 0.0f; quarter.uncategorized_taxes = 0.0f; quarter.report_count = 0; + quarter.is_empty = 1; snprintf(quarter.quarter_str, MAX_LEN_SHORT_DESC, "%dQ%d", quarter.quarter+1, quarter.year); project_count = administration_project_count(); @@ -617,6 +618,7 @@ void administration_create_income_statement(income_statement* statement) quarterly_report* quarter = &statement->quarters[report_index]; assert(yy == quarter->year && qq == quarter->quarter); + quarter->is_empty = 0; if (strcmp(inv->project_id, "") == 0) { if (inv->is_outgoing) { diff --git a/src/administration_writer.cpp b/src/administration_writer.cpp index d9c9c31..c97a828 100644 --- a/src/administration_writer.cpp +++ b/src/administration_writer.cpp @@ -5,6 +5,7 @@ #include <stdlib.h> #include <threads.h> +#include "log.hpp" #include "ui.hpp" #include "strops.hpp" #include "administration_writer.hpp" @@ -170,7 +171,7 @@ static char* administration_writer_get_eas_scheme_for_address(address addr) bool administration_writer_save_invoice_blocking(invoice inv) { bool result = 1; - int buf_length = 15000; // Ballpark file content size. + int buf_length = 150000; // Ballpark file content size. char* file_content = (char*)malloc(buf_length); memset(file_content, 0, buf_length); memcpy(file_content, peppol_invoice_template, strlen(peppol_invoice_template)); @@ -218,6 +219,7 @@ bool administration_writer_save_invoice_blocking(invoice inv) u32 tax_subtotal_list_buffer_size = (u32)strlen(peppol_invoice_tax_subtotal_template) * 2 * tax_bracket_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++) @@ -260,6 +262,7 @@ bool administration_writer_save_invoice_blocking(invoice inv) u32 billing_item_list_buffer_size = (u32)strlen(peppol_invoice_line_template) * 2 * billing_item_count; // Ballpark list size. char* billing_item_list_buffer = (char*)malloc(billing_item_list_buffer_size); + memset(billing_item_list_buffer, 0, billing_item_list_buffer_size); u32 billing_item_list_buffer_cursor = 0; for (u32 i = 0; i < billing_item_count; i++) @@ -304,11 +307,13 @@ bool administration_writer_save_invoice_blocking(invoice inv) snprintf(final_path, 50, "%s.xml", inv.id); int final_length = (int)strlen(file_content); - printf(file_content); if (!xml_parse_document((uint8_t*)file_content, final_length)) result = 0; else if (!administration_writer_write_to_zip(final_path, file_content, final_length)) result = 0; free(file_content); + + log_add(ImGui::GetTime(), "Saved file."); + return result; } diff --git a/src/log.cpp b/src/log.cpp new file mode 100644 index 0000000..960ee85 --- /dev/null +++ b/src/log.cpp @@ -0,0 +1,27 @@ +#include <stdio.h> +#include <stdarg.h> + +#include "log.hpp" + +log g_log = {0}; + +void log_add(double timestamp, const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + vsnprintf(g_log.history[g_log.write_cursor], MAX_LEN_LOG_TXT, fmt, args); + va_end(args); + + char tmp[MAX_LEN_LOG_TXT]; + snprintf(tmp, MAX_LEN_LOG_TXT, "[%.3f] %s", timestamp, g_log.history[g_log.write_cursor]); + tmp[MAX_LEN_LOG_TXT-1] = 0; + memcpy(g_log.history[g_log.write_cursor], tmp, MAX_LEN_LOG_TXT); + + printf(g_log.history[g_log.write_cursor]); + + g_log.write_cursor++; + if (g_log.write_cursor >= MAX_LEN_LOG_HISTORY) g_log.write_cursor = 0; + + g_log.history_length++; + if (g_log.history_length > MAX_LEN_LOG_HISTORY) g_log.history_length = MAX_LEN_LOG_HISTORY; +} diff --git a/src/ui/ui_earnings.cpp b/src/ui/ui_earnings.cpp index 4f545d2..aed31f4 100644 --- a/src/ui/ui_earnings.cpp +++ b/src/ui/ui_earnings.cpp @@ -58,6 +58,11 @@ void ui_draw_earnings() ImGui::TableSetupColumn(statement->quarters[quarter_start+q].quarter_str, ImGuiTableColumnFlags_WidthStretch); } + if (statement->quarters[quarter_start].is_empty) ImGui::TableSetColumnEnabled(1, false); else ImGui::TableSetColumnEnabled(1, true); + if (statement->quarters[quarter_start+1].is_empty) ImGui::TableSetColumnEnabled(2, false); else ImGui::TableSetColumnEnabled(2, true); + if (statement->quarters[quarter_start+2].is_empty) ImGui::TableSetColumnEnabled(3, false); else ImGui::TableSetColumnEnabled(3, true); + if (statement->quarters[quarter_start+3].is_empty) ImGui::TableSetColumnEnabled(4, false); else ImGui::TableSetColumnEnabled(4, true); + ImGui::TableHeadersRow(); ImGui::PopFont(); diff --git a/src/ui/ui_expenses.cpp b/src/ui/ui_expenses.cpp index ab47e26..eb8d8c1 100644 --- a/src/ui/ui_expenses.cpp +++ b/src/ui/ui_expenses.cpp @@ -9,6 +9,7 @@ #include "ui.hpp" #include "imgui.h" #include "administration.hpp" +#include "administration_writer.hpp" #include "locales.hpp" static view_state current_view_state = view_state::LIST; @@ -466,6 +467,13 @@ static void ui_draw_expense_update() ImGui::Spacing(); if (ImGui::Button(localize("form.save"))) { administration_invoice_update(&active_invoice); + if (administration_writer_save_invoice_blocking(active_invoice)) { + ui_set_status(localize("status.saved")); + } + else { + ui_set_status_error(localize("status.saveFailed")); + } + current_view_state = view_state::LIST; ui_destroy_expenses(); @@ -489,6 +497,13 @@ static void ui_draw_expense_create() ImGui::Spacing(); if (ImGui::Button(localize("form.save"))) { administration_invoice_add(&active_invoice); + if (administration_writer_save_invoice_blocking(active_invoice)) { + ui_set_status(localize("status.saved")); + } + else { + ui_set_status_error(localize("status.saveFailed")); + } + current_view_state = view_state::LIST; ui_destroy_expenses(); diff --git a/src/ui/ui_invoices.cpp b/src/ui/ui_invoices.cpp index 9d6f8a2..fd748c8 100644 --- a/src/ui/ui_invoices.cpp +++ b/src/ui/ui_invoices.cpp @@ -9,6 +9,7 @@ #include "ui.hpp" #include "imgui.h" #include "administration.hpp" +#include "administration_writer.hpp" #include "locales.hpp" @@ -499,6 +500,13 @@ static void ui_draw_invoice_update() ImGui::Spacing(); if (ImGui::Button(localize("form.save"))) { administration_invoice_update(&active_invoice); + if (administration_writer_save_invoice_blocking(active_invoice)) { + ui_set_status(localize("status.saved")); + } + else { + ui_set_status_error(localize("status.saveFailed")); + } + current_view_state = view_state::LIST; ui_destroy_invoices(); @@ -522,6 +530,13 @@ static void ui_draw_invoice_create() ImGui::Spacing(); if (ImGui::Button(localize("form.save"))) { administration_invoice_add(&active_invoice); + if (administration_writer_save_invoice_blocking(active_invoice)) { + ui_set_status(localize("status.saved")); + } + else { + ui_set_status_error(localize("status.saveFailed")); + } + current_view_state = view_state::LIST; ui_destroy_invoices(); |
