diff options
| author | Aldrik Ramaekers <aldrikboy@gmail.com> | 2025-09-07 08:39:01 +0200 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrikboy@gmail.com> | 2025-09-07 08:39:01 +0200 |
| commit | 026e38982f5388cede0cd7ebad2ea7571d1d57ed (patch) | |
| tree | 5d164c41bec4f0589e991740c1e0050fe746501a /src/ui | |
| parent | 17e035839a19a8b10d329c28ccaa44ff608d3a33 (diff) | |
income statement generation
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/ui_earnings.cpp | 151 | ||||
| -rw-r--r-- | src/ui/ui_expenses.cpp | 2 | ||||
| -rw-r--r-- | src/ui/ui_invoices.cpp | 11 | ||||
| -rw-r--r-- | src/ui/ui_main.cpp | 8 |
4 files changed, 166 insertions, 6 deletions
diff --git a/src/ui/ui_earnings.cpp b/src/ui/ui_earnings.cpp new file mode 100644 index 0000000..81e31b5 --- /dev/null +++ b/src/ui/ui_earnings.cpp @@ -0,0 +1,151 @@ +#include <stdio.h> +#include <stdlib.h> + +#include "ui.hpp" +#include "imgui.h" +#include "administration.hpp" +#include "locales.hpp" + +income_statement* statement = 0; + +void ui_setup_earnings() +{ + statement = (income_statement*)malloc(sizeof(income_statement)); + administration_create_income_statement(statement); +} + +void ui_destroy_earnings() +{ + free(statement); +} + +void ui_draw_earnings() +{ + if (ImGui::BeginTable("QuarterlyResultsTable", 5, + ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit)) + { + ImGui::TableSetupColumn("##names"); + + int quarter_start = 0; + int quarter_count = 4; + + // Table header + for (int q = 0; q < quarter_count; q++) + { + ImGui::TableSetupColumn(statement->quarters[q].quarter_str, ImGuiTableColumnFlags_WidthStretch); + } + + ImGui::TableHeadersRow(); + + // Uncategorized income and expenses + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); ImGui::Text("(Uncategorized)"); + ImGui::TableSetColumnIndex(1); ImGui::Text(""); + ImGui::TableSetColumnIndex(2); ImGui::Text(""); + ImGui::TableSetColumnIndex(3); ImGui::Text(""); + ImGui::TableSetColumnIndex(4); ImGui::Text(""); + + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(" Revenue"); + ImGui::TableSetColumnIndex(1); ImGui::Text("%.2f", statement->quarters[quarter_start + 0].uncategorized_revenue); + ImGui::TableSetColumnIndex(2); ImGui::Text("%.2f", statement->quarters[quarter_start + 1].uncategorized_revenue); + ImGui::TableSetColumnIndex(3); ImGui::Text("%.2f", statement->quarters[quarter_start + 2].uncategorized_revenue); + ImGui::TableSetColumnIndex(4); ImGui::Text("%.2f", statement->quarters[quarter_start + 3].uncategorized_revenue); + + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(" Tax"); + ImGui::TableSetColumnIndex(1); ImGui::Text("%.2f", statement->quarters[quarter_start + 0].uncategorized_taxes); + ImGui::TableSetColumnIndex(2); ImGui::Text("%.2f", statement->quarters[quarter_start + 1].uncategorized_taxes); + ImGui::TableSetColumnIndex(3); ImGui::Text("%.2f", statement->quarters[quarter_start + 2].uncategorized_taxes); + ImGui::TableSetColumnIndex(4); ImGui::Text("%.2f", statement->quarters[quarter_start + 3].uncategorized_taxes); + + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(" Expenses"); + ImGui::TableSetColumnIndex(1); ImGui::Text("%.2f", statement->quarters[quarter_start + 0].uncategorized_expenses); + ImGui::TableSetColumnIndex(2); ImGui::Text("%.2f", statement->quarters[quarter_start + 1].uncategorized_expenses); + ImGui::TableSetColumnIndex(3); ImGui::Text("%.2f", statement->quarters[quarter_start + 2].uncategorized_expenses); + ImGui::TableSetColumnIndex(4); ImGui::Text("%.2f", statement->quarters[quarter_start + 3].uncategorized_expenses); + + quarterly_report default_quater = statement->quarters[0]; + for (u32 p = 0; p < default_quater.report_count; p++) + { + ImGui::TableNextRow(); + project_report* report = &default_quater.reports[p]; + ImGui::TableSetColumnIndex(0); ImGui::Text("(%s)", report->description); + ImGui::TableSetColumnIndex(1); ImGui::Text(""); + ImGui::TableSetColumnIndex(2); ImGui::Text(""); + ImGui::TableSetColumnIndex(3); ImGui::Text(""); + ImGui::TableSetColumnIndex(4); ImGui::Text(""); + + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(" Revenue"); + ImGui::TableSetColumnIndex(1); ImGui::Text("%.2f", statement->quarters[quarter_start + 0].reports[p].revenue); + ImGui::TableSetColumnIndex(2); ImGui::Text("%.2f", statement->quarters[quarter_start + 1].reports[p].revenue); + ImGui::TableSetColumnIndex(3); ImGui::Text("%.2f", statement->quarters[quarter_start + 2].reports[p].revenue); + ImGui::TableSetColumnIndex(4); ImGui::Text("%.2f", statement->quarters[quarter_start + 3].reports[p].revenue); + + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(" Tax"); + ImGui::TableSetColumnIndex(1); ImGui::Text("%.2f", statement->quarters[quarter_start + 0].reports[p].taxes); + ImGui::TableSetColumnIndex(2); ImGui::Text("%.2f", statement->quarters[quarter_start + 1].reports[p].taxes); + ImGui::TableSetColumnIndex(3); ImGui::Text("%.2f", statement->quarters[quarter_start + 2].reports[p].taxes); + ImGui::TableSetColumnIndex(4); ImGui::Text("%.2f", statement->quarters[quarter_start + 3].reports[p].taxes); + + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(" Expenses"); + ImGui::TableSetColumnIndex(1); ImGui::Text("%.2f", statement->quarters[quarter_start + 0].reports[p].expenses_total); + ImGui::TableSetColumnIndex(2); ImGui::Text("%.2f", statement->quarters[quarter_start + 1].reports[p].expenses_total); + ImGui::TableSetColumnIndex(3); ImGui::Text("%.2f", statement->quarters[quarter_start + 2].reports[p].expenses_total); + ImGui::TableSetColumnIndex(4); ImGui::Text("%.2f", statement->quarters[quarter_start + 3].reports[p].expenses_total); + + for (u32 e = 0; e < report->expense_count; e++) + { + ImGui::TableNextRow(); + project_expense* expense = &report->expenses[e]; + ImGui::TableSetColumnIndex(0); ImGui::Text(" %s", localize(expense->description)); + ImGui::TableSetColumnIndex(1); ImGui::Text("%.2f", statement->quarters[quarter_start + 0].reports[p].expenses[e].total); + ImGui::TableSetColumnIndex(2); ImGui::Text("%.2f", statement->quarters[quarter_start + 1].reports[p].expenses[e].total); + ImGui::TableSetColumnIndex(3); ImGui::Text("%.2f", statement->quarters[quarter_start + 2].reports[p].expenses[e].total); + ImGui::TableSetColumnIndex(4); ImGui::Text("%.2f", statement->quarters[quarter_start + 3].reports[p].expenses[e].total); + + + } + } + + /* + for (int i = 0; i < 1; i++) + { + quarterly_report quarter = statement->quarters[quarter_start + quarter_index]; + + for (u32 p = 0; p < quarter.report_count; p++) + { + ImGui::TableNextRow(); + project_report* report = &quarter.reports[p]; + ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(report->description); + ImGui::TableSetColumnIndex(1); ImGui::Text(""); + ImGui::TableSetColumnIndex(2); ImGui::Text(""); + ImGui::TableSetColumnIndex(3); ImGui::Text(""); + ImGui::TableSetColumnIndex(4); ImGui::Text(""); + + + // for (u32 e = 0; e < report->expense_count; e++) + // { + // project_expense* expense = &report->expenses[e]; + // ImGui::TableNextColumn(); ImGui::TextUnformatted(expense->description); + // } + } + }*/ + + // // Rows + // for (int i = 0; i < results_count; i++) + // { + // ImGui::TableNextRow(); + // ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(results[i].quarter); + // ImGui::TableSetColumnIndex(1); ImGui::TextUnformatted(results[i].revenue); + // ImGui::TableSetColumnIndex(2); ImGui::TextUnformatted(results[i].profit); + // ImGui::TableSetColumnIndex(3); ImGui::TextUnformatted(results[i].expenses); + // } + + ImGui::EndTable(); + } +}
\ No newline at end of file diff --git a/src/ui/ui_expenses.cpp b/src/ui/ui_expenses.cpp index 6d1b36c..ab47e26 100644 --- a/src/ui/ui_expenses.cpp +++ b/src/ui/ui_expenses.cpp @@ -343,7 +343,7 @@ static void ui_draw_expenses_list() invoice invoice_list[items_per_page]; u32 invoice_count = administration_invoice_get_partial_list_incomming(current_page, items_per_page, invoice_list); - u32 total_invoice_count = administation_invoice_get_incomming_count(); + u32 total_invoice_count = administration_invoice_get_incomming_count(); s32 max_page = (total_invoice_count + items_per_page - 1) / items_per_page; if (max_page == 0) max_page = 1; diff --git a/src/ui/ui_invoices.cpp b/src/ui/ui_invoices.cpp index 8cdf959..9d6f8a2 100644 --- a/src/ui/ui_invoices.cpp +++ b/src/ui/ui_invoices.cpp @@ -18,14 +18,17 @@ static invoice selected_for_removal = {0}; static country_tax_bracket* tax_bracket_list_buffer = 0; static billing_item* invoice_items_buffer = 0; +static project* project_list_buffer = 0; void ui_draw_address_form(address* buffer); void draw_contact_form_ex(contact* buffer, bool viewing_only = false, bool with_autocomplete = false, bool* on_autocomplete = 0); +void draw_project_selector(char* project_id, project* buffer); void ui_destroy_invoices() { free(tax_bracket_list_buffer); free(invoice_items_buffer); + free(project_list_buffer); } void ui_setup_invoices() @@ -38,6 +41,9 @@ void ui_setup_invoices() u32 invoice_items_count = MAX_BILLING_ITEMS; invoice_items_buffer = (billing_item*)malloc(sizeof(billing_item) * invoice_items_count); + + u32 project_count = administration_project_count(); + project_list_buffer = (project*) malloc(sizeof(project) * project_count); } void draw_tax_bracket_selector(char* tax_bracket_id, country_tax_bracket* buffer, char* country_code) @@ -328,6 +334,9 @@ static void draw_invoice_form(invoice* buffer, bool viewing_only = false) } ImGui::Separator(); + // 9. Project selection + draw_project_selector(buffer->project_id, project_list_buffer); + ImGui::Spacing(); ImGui::Spacing(); ImGui::Spacing(); @@ -364,7 +373,7 @@ static void ui_draw_invoices_list() invoice invoice_list[items_per_page]; u32 invoice_count = administration_invoice_get_partial_list_outgoing(current_page, items_per_page, invoice_list); - u32 total_invoice_count = administation_invoice_get_outgoing_count(); + u32 total_invoice_count = administration_invoice_get_outgoing_count(); s32 max_page = (total_invoice_count + items_per_page - 1) / items_per_page; if (max_page == 0) max_page = 1; diff --git a/src/ui/ui_main.cpp b/src/ui/ui_main.cpp index 33747f1..9ff965d 100644 --- a/src/ui/ui_main.cpp +++ b/src/ui/ui_main.cpp @@ -21,7 +21,7 @@ void (*drawcalls[dashboard_view_state::END])(void) = { ui_draw_invoices, ui_draw_expenses, ui_draw_contacts, - 0, + ui_draw_earnings, 0, ui_draw_projects, ui_draw_settings, @@ -31,7 +31,7 @@ void (*setupcalls[dashboard_view_state::END])(void) = { ui_setup_invoices, ui_setup_expenses, ui_setup_contacts, - 0, + ui_setup_earnings, 0, ui_setup_projects, ui_setup_settings, @@ -41,7 +41,7 @@ void (*destroycalls[dashboard_view_state::END])(void) = { ui_destroy_invoices, ui_destroy_expenses, 0, - 0, + ui_destroy_earnings, 0, 0, ui_destroy_settings, @@ -94,7 +94,7 @@ void ui_draw_main() if (ImGui::Button(localize("nav.expenses"), ImVec2(buttonWidth, 24))) set_dashboard_state(dashboard_view_state::EXPENSES); if (ImGui::Button(localize("nav.contacts"), ImVec2(buttonWidth, 24))) set_dashboard_state(dashboard_view_state::CONTACTS); - static bool reports_opened = false; + static bool reports_opened = true; if (ImGui::Button(localize("nav.reports"), ImVec2(buttonWidth, 24))) reports_opened = !reports_opened; if (reports_opened) { |
