From 205e98973bfc69b1e3879eda49b2a3e1ed704a84 Mon Sep 17 00:00:00 2001 From: Weyoune Date: Mon, 16 Nov 2026 13:32:45 +0100 Subject: [PATCH] A running loan can be changed and repaid: the credit read states what a booking costs at once The read of a loan carries charge: the fees and, for a running loan of the bank, the interest adjustment that commit_bank_credit books. With it the page offers the fields of a running loan as well; a backend that does not state the charge keeps them closed. Co-Authored-By: Claude Fable 5.2 --- src/modern/app/modern_session.cpp | 3 +++ src/modern/ui/engine_dto.cpp | 4 +++- src/modern/ui/engine_finance.inc | 12 +++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/modern/app/modern_session.cpp b/src/modern/app/modern_session.cpp index d19cf7b..fedf283 100644 --- a/src/modern/app/modern_session.cpp +++ b/src/modern/app/modern_session.cpp @@ -9471,7 +9471,10 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co for (uint32_t v : credit.saved) saved.push_back(int64_t(v)); return modern::ui_snapshot(g_, context, request_id, O{{"kind", "credit"}, {"lenderId", counterparty == 0 ? cli::Json("bank") : cli::Json(modern::ui_manager_id(g_, counterparty - 1))}, + // "charge" is what a booking of this draft costs at once: the fees and, for a running loan of + // the bank, the interest adjustment (commit_bank_credit); a fellow manager charges nothing {"saved", std::move(saved)}, {"fields", std::move(fields)}, {"fees", modern::ui_money(draft.fees)}, + {"charge", modern::ui_money(counterparty ? 0 : int32_t(int64_t(draft.fees) + draft.interest_adjustment))}, {"refund", modern::ui_money(draft.refund)}, {"principalPaid", modern::ui_money(draft.principal_paid)}, {"note", "Werte der Felder in ganzen Euro bzw. Monaten wie im Original-Dialog"}}); } diff --git a/src/modern/ui/engine_dto.cpp b/src/modern/ui/engine_dto.cpp index 4a732b6..f349fc3 100644 --- a/src/modern/ui/engine_dto.cpp +++ b/src/modern/ui/engine_dto.cpp @@ -410,11 +410,13 @@ Json engine_credit_projection(const Json &bundle, const Json &read) { } } for (const auto *key : {"fees", "refund", "principalPaid"}) require(engine_money_minor(data.at(key)) >= 0, "Ungültige Kreditkosten."); + // what a booking costs at once; a backend that does not state it cannot change a running loan + if (data.contains("charge")) (void)engine_money_minor(data.at("charge")); return data; } Json engine_credit_command(const Json &bundle, const Json &read, const Json &edits, const std::string &request_id) { const auto credit = engine_credit_projection(bundle, read); - require(credit.at("saved")[0] == 0, "Für Änderungen laufender Kredite fehlt noch die vollständige Gebührenvorschau."); + require(credit.at("saved")[0] == 0 || credit.contains("charge"), "Für Änderungen laufender Kredite fehlt die vollständige Gebührenvorschau."); require(edits.is_array() && !edits.empty() && edits.size() <= 64, "Keine gültigen Kreditänderungen."); for (const auto &e : edits) { require(e.is_object() && e.size() == 2, "Ungültige Kreditänderung."); diff --git a/src/modern/ui/engine_finance.inc b/src/modern/ui/engine_finance.inc index 81153ac..4a9b285 100644 --- a/src/modern/ui/engine_finance.inc +++ b/src/modern/ui/engine_finance.inc @@ -62,7 +62,7 @@ bool App::engine_bank_action(const std::string &action, Rml::Element *target) { if (action == "engine-credit-apply") { const auto data = engine_credit_projection(engine_data_, engine_credit_); const auto command = engine_credit_command(engine_data_, engine_credit_, engine_credit_edits_, editor::new_id("request:ui-")); - std::string text = "Kreditänderungen verbindlich buchen? Gebühren: " + engine_price(data.at("fees")) + + std::string text = "Kreditänderungen verbindlich buchen? Gebühren: " + engine_price(data.at(data.contains("charge") ? "charge" : "fees")) + ". Erstattung: " + engine_price(data.at("refund")) + "."; for (const auto &f : data.at("fields")) text += " " + engine_text(f.at("label")) + ": " + number(f.at("value").get()) + ((f.at("field") == 3 || f.at("field") == 4) ? " Monate." : " €. "); confirmation(text, [this, command] { focus_after_render_ = "window-close"; engine_finance_submit(command); }); return true; @@ -75,7 +75,8 @@ bool App::engine_bank_action(const std::string &action, Rml::Element *target) { if (action == "engine-credit-edit") { const auto index = target->GetAttribute("data-id", -1); const auto credit = engine_credit_projection(engine_data_, engine_credit_); - if (credit.at("saved")[0] != 0) return true; + // a running loan is changed only where the backend states what the change costs at once + if (credit.at("saved")[0] != 0 && !credit.contains("charge")) return true; if (index < 0 || index > 7 || credit.at("fields")[size_t(index)].at("editable") != true) return true; const auto f = credit.at("fields")[size_t(index)]; request.title = engine_text(f.at("label")); request.unit = index == 3 || index == 4 ? "Monate" : "€"; @@ -149,6 +150,7 @@ std::string App::engine_credit_view() { }; // the loan as the bank states it: every figure a line; what may be changed is a button out += "
" + pg_kicker(fellow ? "Kredit von " + lender_name : std::string("Kredit")); + const bool running = data.at("saved")[0] != 0, open = !running || data.contains("charge"); int64_t total = 0, paid = 0; for (size_t i = 0; i < 8; ++i) { const auto &f = data.at("fields")[i]; const auto value = f.at("value").get(); @@ -156,18 +158,18 @@ std::string App::engine_credit_view() { if (i == 5) paid = value; const auto text = i == 3 || i == 4 ? number(value) + " Monate" : money(value * 100, {{"code", "EUR"}, {"minor_units", 2}}); out += "
" + esc(calm(engine_text(f.at("label")))) + ""; - if (data.at("saved")[0] == 0 && f.at("editable") == true) out += pg_button("engine-credit-edit", esc(text), "bk-edit", "id=\"engine-credit-" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) + "\""); + if (open && f.at("editable") == true) out += pg_button("engine-credit-edit", esc(text), "bk-edit", "id=\"engine-credit-" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) + "\""); else out += "" + esc(text) + ""; out += "
"; } out += "
"; - for (const auto &[label, key] : std::array, 3>{{{"Gebühren", "fees"}, {"Erstattung", "refund"}, {"Bereits getilgt", "principalPaid"}}}) + for (const auto &[label, key] : std::array, 3>{{{"Gebühren", data.contains("charge") ? "charge" : "fees"}, {"Erstattung", "refund"}, {"Bereits getilgt", "principalPaid"}}}) out += "
" + esc(engine_price(data.at(key))) + "" + label + "
"; // how much of the whole sum is paid back const double done = total > 0 ? std::clamp(double(paid) * 100.0 / double(total), 0.0, 100.0) : 0; out += "
Zurückgezahlt" + (total > 0 ? std::to_string(int(std::lround(done))) + " %" : std::string("kein Kredit")) + "
" + pg_bar(done, "sage") + "
" + - std::string(data.at("saved")[0] != 0 ? "" : fellow ? "Ohne Gebühren. Die Summe geht vom Konto des Mitspielers ab, die Raten fließen an ihn. Gebucht wird erst nach deiner Bestätigung; er wird nicht gefragt." : "Die Bank berechnet Laufzeit, Raten und Gebühren. Gebucht wird erst nach deiner Bestätigung.") + std::string(data.at("saved")[0] == 0 ? "" : "Laufender Kredit · Änderungen folgen mit vollständiger Gebührenvorschau.") + "
"; + std::string(running ? (open ? "Laufender Kredit: Summe, Laufzeit und Rückzahlung lassen sich ändern. " + std::string(fellow ? "Der Mitspieler berechnet nichts." : "Die Bank berechnet dafür Gebühren und gleicht die Zinsen aus.") + " Gebucht wird erst nach deiner Bestätigung." : "") : fellow ? "Ohne Gebühren. Die Summe geht vom Konto des Mitspielers ab, die Raten fließen an ihn. Gebucht wird erst nach deiner Bestätigung; er wird nicht gefragt." : "Die Bank berechnet Laufzeit, Raten und Gebühren. Gebucht wird erst nach deiner Bestätigung.") + std::string(open ? "" : "Laufender Kredit · Änderungen folgen mit vollständiger Gebührenvorschau.") + ""; out += "
" + pg_button("engine-credit-reset", "Zurücksetzen", "block", "id=\"engine-credit-reset\"") + pg_button("engine-credit-apply", "Verbindlich buchen", "primary block", "id=\"engine-credit-apply\" " + std::string(engine_credit_edits_.empty() ? "disabled=\"disabled\"" : "")) + "
"; return out;