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 <noreply@anthropic.com>
This commit is contained in:
1 parent
28f86c169e
commit
205e98973b
3 files changed
+13
-6
No files matched your search
@@ -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"}});
|
||||
}
|
||||
|
||||
@@ -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.");
|
||||
|
||||
@@ -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<int64_t>()) + ((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<int>("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 += "<div class=\"pg-panel pg-col pg-grow\" style=\"" + pg_css("gap:4px;padding:12px 16px;") + "\">" + 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<int64_t>();
|
||||
@@ -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 += "<div class=\"pg-kv bk-credit-line\"><span>" + esc(calm(engine_text(f.at("label")))) + "</span>";
|
||||
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 += "<strong>" + esc(text) + "</strong>";
|
||||
out += "</div>";
|
||||
}
|
||||
out += "<div class=\"bk-tiles\" style=\"margin-top:" + pg(8) + ";\">";
|
||||
for (const auto &[label, key] : std::array<std::pair<const char *, const char *>, 3>{{{"Gebühren", "fees"}, {"Erstattung", "refund"}, {"Bereits getilgt", "principalPaid"}}})
|
||||
for (const auto &[label, key] : std::array<std::pair<const char *, const char *>, 3>{{{"Gebühren", data.contains("charge") ? "charge" : "fees"}, {"Erstattung", "refund"}, {"Bereits getilgt", "principalPaid"}}})
|
||||
out += "<div class=\"bk-tile\"><strong>" + esc(engine_price(data.at(key))) + "</strong><span>" + label + "</span></div>";
|
||||
// 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 += "</div><div class=\"bk-part\"><div class=\"pg-row\" style=\"justify-content:space-between;\"><span>Zurückgezahlt</span><strong>" + (total > 0 ? std::to_string(int(std::lround(done))) + " %" : std::string("kein Kredit")) +
|
||||
"</strong></div>" + pg_bar(done, "sage") + "</div><span class=\"pg-sp\"></span><span class=\"pg-mut\" style=\"display:block;\">" +
|
||||
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.") + "</span></div>";
|
||||
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.") + "</span></div>";
|
||||
out += "<div class=\"pg-row\" style=\"" + pg_css("gap:8px;") + "\">" + 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\"" : "")) + "</div>";
|
||||
return out;
|
||||
|
||||
Reference in new issue
Block a user