summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/README.rst2
-rw-r--r--include/administration.hpp1
-rw-r--r--include/administration_writer.hpp1
-rw-r--r--include/log.hpp15
-rw-r--r--src/administration.cpp2
-rw-r--r--src/administration_writer.cpp9
-rw-r--r--src/log.cpp27
-rw-r--r--src/ui/ui_earnings.cpp5
-rw-r--r--src/ui/ui_expenses.cpp15
-rw-r--r--src/ui/ui_invoices.cpp15
10 files changed, 89 insertions, 3 deletions
diff --git a/docs/README.rst b/docs/README.rst
index a432e92..4436a53 100644
--- a/docs/README.rst
+++ b/docs/README.rst
@@ -26,7 +26,7 @@ What OpenBooks **can** do:
What OpenBooks **can't** do:
- Intrastat reporting
-- Sustainability Reporting (CSRD)
+- OSS reporting
- PoS Fiscalization
- Automatically submit tax, audit or ICP reports
diff --git a/include/administration.hpp b/include/administration.hpp
index 67efb9c..e270475 100644
--- a/include/administration.hpp
+++ b/include/administration.hpp
@@ -297,6 +297,7 @@ typedef struct
project_report reports[MAX_LEN_QUARTERLY_REPORT_PROJECTS];
u16 year; // 00-99
u8 quarter; // 0-3
+ bool is_empty;
char quarter_str[MAX_LEN_SHORT_DESC];
} quarterly_report;
diff --git a/include/administration_writer.hpp b/include/administration_writer.hpp
index 0ebd8db..b46927f 100644
--- a/include/administration_writer.hpp
+++ b/include/administration_writer.hpp
@@ -12,5 +12,6 @@ bool administration_writer_save_project_blocking(project project);
bool administration_writer_save_cost_center_blocking(cost_center cost);
bool administration_writer_save_tax_bracket_blocking(country_tax_bracket bracket);
bool administration_writer_save_contact_blocking(contact c);
+bool administration_writer_save_invoice_blocking(invoice inv);
bool administration_writer_save_all_async(); \ No newline at end of file
diff --git a/include/log.hpp b/include/log.hpp
new file mode 100644
index 0000000..dcb2987
--- /dev/null
+++ b/include/log.hpp
@@ -0,0 +1,15 @@
+#pragma once
+
+#include "imgui.h"
+#include "config.hpp"
+
+#define MAX_LEN_LOG_HISTORY 256
+#define MAX_LEN_LOG_TXT 128
+
+typedef struct {
+ u32 write_cursor;
+ u32 history_length;
+ char history[MAX_LEN_LOG_HISTORY][MAX_LEN_LOG_TXT];
+} log;
+
+void log_add(double timestamp, const char* fmt, ...) IM_FMTARGS(2); \ No newline at end of file
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();