Contracts: club and wage bill, the squad as a table, the negotiation as a note on the dimmed book. Surroundings: six cards with their stars, pictures and costs, the monthly sum in the page's title. Balance: figures, income against costs, the plan for the coming year, and the what-if calculation in the notebook's inks. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
77 lines
6.6 KiB
C++
77 lines
6.6 KiB
C++
// 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 = "<div class=\"pg-page balance-native\">", status;
|
||
if (balance_sim_) {
|
||
out += render_balance_simulation();
|
||
status = "Reine Rechnung – nichts wird gespeichert.";
|
||
} else if (balance_future_) {
|
||
out += "<div class=\"pg-body\"><section class=\"pg-panel pg-col pg-grow\" style=\"" + pg_css("gap:4px;") + "\"><h2 class=\"pg-h\">Ausgabenplanung</h2><span class=\"pg-mut\" style=\"display:block;margin-bottom:" + pg(6) +
|
||
";\">Geplante Ausgaben für die nächsten zwölf Monate. Ein Betrag öffnet das Zahlenfeld.</span><div class=\"pg-tbody\">";
|
||
int i = 0;
|
||
for (const auto &row : rows.at("plan")) {
|
||
const auto name = row.at("name").get<std::string>();
|
||
out += "<div class=\"pg-tr\" style=\"height:" + pg(44) + ";justify-content:space-between;\"><span style=\"display:block;font-size:" + pg(15) + ";\">" + esc(name) + "</span>" +
|
||
pg_button("balance-plan", esc(number(row.at("amount").get<int64_t>() / (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":"")) + "</div>";
|
||
++i;
|
||
}
|
||
out += "</div></section><div class=\"pg-col\" style=\"width:" + pg(400) + ";\"><div style=\"display:flex;\">" + pg_stat("Geplante Ausgaben", esc(balance_cash(rows.at("plan_total").get<int64_t>())), "Summe für zwölf Monate") +
|
||
"</div><div style=\"display:flex;\">" + pg_stat("Kontostand", esc(balance_cash(rows.at("cash").get<int64_t>())), "heute") + "</div></div></div>";
|
||
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<int64_t>(0, row.at("amount").get<int64_t>());
|
||
++side;
|
||
}
|
||
}
|
||
const int64_t net = rows.at("balance").get<int64_t>();
|
||
out += "<div class=\"pg-row\" style=\"" + pg_css("gap:8px;align-items:stretch;") + "\">" + pg_stat("Einnahmen", esc(balance_cash(sums[0]))) + pg_stat("Ausgaben", esc(balance_cash(sums[1]))) +
|
||
pg_stat("Saldo der Saison", "<span class=\"" + std::string(net < 0 ? "balance-loss" : "balance-gain") + "\">" + esc(balance_cash(net)) + "</span>") + pg_stat("Kontostand", esc(balance_cash(rows.at("cash").get<int64_t>()))) +
|
||
pg_stat("Zuschauerschnitt", esc(number(rows.at("attendance_average").get<int64_t>())), "je Heimspiel") + "</div>";
|
||
// income against costs as one bar
|
||
const double whole = double(std::max<int64_t>(1, sums[0] + sums[1]));
|
||
out += "<div class=\"balance-scale\"><div class=\"in\" style=\"width:" + scalar(sums[0] * 100.0 / whole) + "%;\"><span>Einnahmen " + scalar(std::round(sums[0] * 100.0 / whole)) +
|
||
" %</span></div><div class=\"out\" style=\"width:" + scalar(sums[1] * 100.0 / whole) + "%;\"><span>Ausgaben " + scalar(std::round(sums[1] * 100.0 / whole)) + " %</span></div></div><div class=\"pg-body\">";
|
||
int index = 0;
|
||
for (const auto &kind : {std::string("income"), std::string("costs")}) {
|
||
const int64_t sum = std::max<int64_t>(1, sums[index]);
|
||
out += "<section class=\"pg-panel pg-col pg-grow " + kind + "\" style=\"" + pg_css("gap:4px;padding:10px 14px;") + "\"><div class=\"pg-row\" style=\"justify-content:space-between;\"><h2 class=\"pg-h\">" +
|
||
(kind == "income" ? "Einnahmen" : "Ausgaben") + "</h2><strong class=\"pg-h\">" + esc(balance_cash(sums[index])) + "</strong></div>";
|
||
for (const auto &row : rows.at(kind)) {
|
||
const int64_t amount = row.at("amount").get<int64_t>();
|
||
const double part = std::clamp(double(std::max<int64_t>(0, amount)) * 100.0 / double(sum), 0.0, 100.0);
|
||
out += "<div class=\"pg-row balance-row" + std::string(amount ? "" : " none") + "\" style=\"" + pg_css("gap:10px;min-height:30px;") + "\"><span class=\"pg-grow pg-nowrap\" style=\"display:block;\">" + esc(row.at("name").get<std::string>()) +
|
||
"</span><span style=\"display:block;flex:none;width:" + pg(110) + ";\">" + pg_bar(part, kind == "income" ? "sage" : "") + "</span><span class=\"pg-mut pg-r\" style=\"display:block;flex:none;width:" + pg(44) + ";\">" +
|
||
scalar(std::round(part)) + " %</span><strong class=\"pg-r\" style=\"display:block;flex:none;width:" + pg(150) + ";\">" + esc(balance_cash(amount)) + "</strong></div>";
|
||
}
|
||
out += "</section>";
|
||
++index;
|
||
}
|
||
out += "</div><span class=\"pg-mut\" style=\"display:block;flex:none;\">" + esc(number(rows.at("league_home_games").get<int64_t>()) + " Liga-Heimspiele · " + number(rows.at("other_home_games").get<int64_t>()) +
|
||
" sonstige Heimspiele · Eintrittspreis " + balance_cash(rows.at("ticket").get<int64_t>())) + "</span>";
|
||
status = "Gebuchte Saisonwerte.";
|
||
}
|
||
// the foot: the two views, the simulation, what the engine last said
|
||
out += "<nav class=\"pg-foot\">";
|
||
if (!balance_sim_)
|
||
// the view that is shown is marked; the other one switches
|
||
for (int view = 0; view < 2; ++view) {
|
||
const bool shown = (view == 1) == balance_future_;
|
||
out += std::string(view ? "" : "<div class=\"pg-seg\">") + btn("balance-toggle", "<span>" + std::string(view ? "Zukunft" : "Aktuell") + "</span>", std::string(view ? "" : "first ") + (shown ? "on" : ""),
|
||
shown ? std::string("style=\"pointer-events:none;\" aria-pressed=\"true\"") : std::string("id=\"balance-toggle\" aria-pressed=\"false\" aria-label=\"Zwischen aktueller Bilanz und Zukunftsplanung wechseln\"")) + (view ? "</div>" : "");
|
||
}
|
||
out += pg_button("balance-sim", balance_sim_ ? "Zurück zur Bilanz" : "Simulation", balance_sim_ ? "primary" : "", "id=\"balance-sim\"") + "<span class=\"pg-sp\"></span>";
|
||
if (engine_mode_) out += "<span class=\"pg-status\" id=\"balance-engine-feedback\">" + esc(engine_busy_ ? engine_operation_ : !engine_balance_feedback_.empty() ? engine_balance_feedback_ : status) + "</span>";
|
||
else out += pg_status(status);
|
||
return out + "</nav></div>";
|
||
}
|