/* * Copyright (c) 2025 Aldrik Ramaekers * * 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, 60); ImGui::TableSetupColumn(report.quarter_str, ImGuiTableColumnFlags_WidthFixed, 120); ImGui::TableSetupColumn("##tax", ImGuiTableColumnFlags_WidthFixed, 120); 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 0 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); } } } #else ImGui::TableSetColumnIndex(2); if (line.show_net) ImGui::Text("%.2f %s", line.total_net, currency_symbol); else ImGui::Text(""); ImGui::TableSetColumnIndex(3); if (line.show_tax) { 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); } } } else ImGui::Text(""); #endif if (bold) ImGui::PopFont(); } ImGui::EndTable(); } }