// SPDX-License-Identifier: GPL-3.0-only
// The balance sheet as a page of the notebook: the season's sums as figures, income against
// costs as one bar, then every position with its share of its side. "Zukunft" plans the
// coming year's costs; the simulation is a what-if calculation of its own.
std::string App::render_balance() {
const auto rows = balance_rows();
if (!rows.value("ok", false)) throw editor::Error("Die Bilanzdaten sind ungültig.");
std::string out = "
", status;
if (balance_sim_) {
out += render_balance_simulation();
status = "Reine Rechnung – nichts wird gespeichert.";
} else if (balance_future_) {
out += "
Ausgabenplanung
Geplante Ausgaben für die nächsten zwölf Monate. Ein Betrag öffnet das Zahlenfeld.";
int i = 0;
for (const auto &row : rows.at("plan")) {
const auto name = row.at("name").get
();
out += "" + esc(name) + "" +
pg_button("balance-plan", esc(number(row.at("amount").get() / (engine_mode_?100:finance_currency_factor(*world_)))) + " " + esc(engine_mode_ ? "€" : money_unit()),
"amount-trigger", "id=\"balance-plan-" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) + "\" aria-label=\"" + esc(name + " in " + (engine_mode_?"Euro":money_unit() == "€" ? "Euro" : money_unit())) + "\" " +
std::string(engine_mode_&&row.at("editable")!=true?"disabled":"")) + "
";
++i;
}
out += "" + pg_stat("Geplante Ausgaben", esc(balance_cash(rows.at("plan_total").get())), "Summe für zwölf Monate") +
"
" + pg_stat("Kontostand", esc(balance_cash(rows.at("cash").get())), "heute") + "
";
status = "Planung für zwölf Monate.";
} else {
int64_t sums[2] = {0, 0};
{
int side = 0;
for (const auto &kind : {std::string("income"), std::string("costs")}) {
for (const auto &row : rows.at(kind)) sums[side] += std::max
(0, row.at("amount").get());
++side;
}
}
const int64_t net = rows.at("balance").get();
out += "" + pg_stat("Einnahmen", esc(balance_cash(sums[0]))) + pg_stat("Ausgaben", esc(balance_cash(sums[1]))) +
pg_stat("Saldo der Saison", "" + esc(balance_cash(net)) + "") + pg_stat("Kontostand", esc(balance_cash(rows.at("cash").get()))) +
pg_stat("Zuschauerschnitt", esc(number(rows.at("attendance_average").get())), "je Heimspiel") + "
";
// income against costs as one bar
const double whole = double(std::max(1, sums[0] + sums[1]));
out += "Einnahmen " + scalar(std::round(sums[0] * 100.0 / whole)) +
" %
Ausgaben " + scalar(std::round(sums[1] * 100.0 / whole)) + " %
";
int index = 0;
for (const auto &kind : {std::string("income"), std::string("costs")}) {
const int64_t sum = std::max
(1, sums[index]);
out += "" +
(kind == "income" ? "Einnahmen" : "Ausgaben") + "
" + esc(balance_cash(sums[index])) + "";
for (const auto &row : rows.at(kind)) {
const int64_t amount = row.at("amount").get();
const double part = std::clamp(double(std::max(0, amount)) * 100.0 / double(sum), 0.0, 100.0);
out += "" + esc(row.at("name").get()) +
"" + pg_bar(part, kind == "income" ? "sage" : "") + "" +
scalar(std::round(part)) + " %" + esc(balance_cash(amount)) + "
";
}
out += "";
++index;
}
out += " " + esc(number(rows.at("league_home_games").get()) + " Liga-Heimspiele · " + number(rows.at("other_home_games").get()) +
" sonstige Heimspiele · Eintrittspreis " + balance_cash(rows.at("ticket").get())) + "";
status = "Gebuchte Saisonwerte.";
}
// the foot: the two views, the simulation, what the engine last said
out += " ";
}