summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2025-10-10 23:11:18 +0200
committerAldrik Ramaekers <aldrikboy@gmail.com>2025-10-10 23:11:18 +0200
commitcf5dfa405fa3d9b480794f7f2c32e325fdfd134c (patch)
tree7dbfdfe271a95ddc9bdcfc73e3c94bd0361ad012 /src/ui
parentd976c1227f367a4547a004597b8d360a8958eba9 (diff)
tax statement UI
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/ui_main.cpp6
-rw-r--r--src/ui/ui_tax.cpp111
2 files changed, 114 insertions, 3 deletions
diff --git a/src/ui/ui_main.cpp b/src/ui/ui_main.cpp
index 9e6aeb8..cf30840 100644
--- a/src/ui/ui_main.cpp
+++ b/src/ui/ui_main.cpp
@@ -28,7 +28,7 @@ void (*drawcalls[ui::main_state::UI_END])(void) = {
ui::draw_expenses,
ui::draw_contacts,
ui::draw_earnings,
- 0,
+ ui::draw_tax_report,
ui::draw_projects,
ui::draw_settings,
ui::draw_log,
@@ -39,7 +39,7 @@ void (*setupcalls[ui::main_state::UI_END])(void) = {
ui::setup_expenses,
ui::setup_contacts,
ui::setup_earnings,
- 0,
+ ui::setup_tax_report,
ui::setup_projects,
ui::setup_settings,
0,
@@ -50,7 +50,7 @@ void (*destroycalls[ui::main_state::UI_END])(void) = {
ui::destroy_expenses,
0,
ui::destroy_earnings,
- 0,
+ ui::destroy_tax_report,
0,
ui::destroy_settings,
0,
diff --git a/src/ui/ui_tax.cpp b/src/ui/ui_tax.cpp
new file mode 100644
index 0000000..37eeaee
--- /dev/null
+++ b/src/ui/ui_tax.cpp
@@ -0,0 +1,111 @@
+/*
+* Copyright (c) 2025 Aldrik Ramaekers <aldrik.ramaekers@gmail.com>
+*
+* Permission to use, copy, modify, and/or distribute this software for any
+* purpose with or without fee is hereby granted, provided that the above
+* copyright notice and this permission notice appear in all copies.
+*
+* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+
+#include "ui.hpp"
+#include "imgui.h"
+#include "memops.hpp"
+#include "strops.hpp"
+#include "locales.hpp"
+#include "administration.hpp"
+
+tax_statement* statement = 0;
+
+void ui::setup_tax_report()
+{
+ statement = (tax_statement*)memops::alloc(sizeof(tax_statement));
+ administration::create_tax_statement(statement);
+}
+
+void ui::destroy_tax_report()
+{
+ memops::unalloc(statement);
+}
+
+void ui::draw_tax_report()
+{
+ static s32 current_page = 0;
+ s32 max_page = statement->report_count;
+
+ if (current_page >= max_page-1) current_page = max_page-1;
+ if (current_page < 0) current_page = 0;
+
+ bool enable_prev = current_page > 0;
+ if (!enable_prev) ImGui::BeginDisabled();
+ if (ImGui::Button(locale::get("ui.prev")) && current_page > 0) current_page--;
+ if (!enable_prev) ImGui::EndDisabled();
+
+ ImGui::SameLine();
+ ImGui::Text("(%d/%d)", current_page+1, max_page);
+
+ ImGui::SameLine();
+ bool enable_next = current_page < max_page-1;
+ if (!enable_next) ImGui::BeginDisabled();
+ if (ImGui::Button(locale::get("ui.next")) && current_page < max_page-1) current_page++;
+ if (!enable_next) ImGui::EndDisabled();
+
+ ImGui::Spacing();
+
+ char* currency_symbol = administration::get_currency_symbol_for_currency(administration::get_default_currency());
+ tax_report report = statement->reports[current_page];
+
+ if (ImGui::BeginTable("QuarterlyTaxTable", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Hideable))
+ {
+ ImGui::PushFont(fontBold);
+ ImGui::TableSetupColumn("##desc", ImGuiTableColumnFlags_WidthStretch);
+ ImGui::TableSetupColumn("##names", ImGuiTableColumnFlags_WidthFixed, 150);
+ ImGui::TableSetupColumn(report.quarter_str, ImGuiTableColumnFlags_WidthFixed, 150);
+ ImGui::TableSetupColumn("##tax", ImGuiTableColumnFlags_WidthFixed, 150);
+
+ ImGui::TableHeadersRow();
+ ImGui::PopFont();
+
+ for (u32 x = 0; x < report.line_count; x++)
+ {
+ tax_line line = report.lines[x];
+ bool is_last = x == (report.line_count-1);
+ bool bold = is_last || strops::equals(line.tax_category, "");
+
+ if (bold) ImGui::PushFont(fontBold);
+
+ ImGui::TableNextRow();
+ ImGui::TableSetColumnIndex(0); ImGui::Text("%s", locale::get(line.tax_description));
+ ImGui::TableSetColumnIndex(1); ImGui::Text("%s", locale::get(line.tax_category));
+
+ if (!strops::equals(line.tax_category, "")) {
+ ImGui::TableSetColumnIndex(2); ImGui::Text("%.2f %s", line.total_net, currency_symbol);
+
+
+ ImGui::TableSetColumnIndex(3);
+ if (!is_last) ImGui::Text("%.2f %s", line.total_tax, currency_symbol);
+ else {
+ if (line.total_tax < 0.0f) {
+ ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(235, 64, 52, 255));
+ ImGui::Text("(%.0f %s)", line.total_tax, currency_symbol);
+ ImGui::PopStyleColor();
+ }
+ else {
+ ImGui::Text("%.0f %s", line.total_tax, currency_symbol);
+ }
+ }
+ }
+
+ if (bold) ImGui::PopFont();
+ }
+
+ ImGui::EndTable();
+ }
+} \ No newline at end of file