P05-02: 全費目と資金区分:表金・裏金、維持費未払い、仕入れ、人件費、元本、利息、税の帳簿への接続(原 P05-02 の完了の条件)

This commit is contained in:
Agent Control Runner
2026-10-23 19:42:50 +09:00
parent 37deb6e877
commit d65e3da9f3
6 changed files with 370 additions and 11 deletions
+38 -4
View File
@@ -15,6 +15,8 @@ const STARTER_MANA_OUTPUT := 100
const STARTER_MANA_SOURCE := &"world_tree.mana_source"
const STARTER_MANA_BUS := &"world_tree.mana_bus"
const PLAYER_CASH_ACCOUNT := &"PLAYER_CASH"
## The settlement.funds report definition (see _daily_fund_report).
const FUND_REPORT_VERSION := 2
const CONSTRUCTION_EXPENSE_ACCOUNT := &"CONSTRUCTION_EXPENSE"
const OPERATING_EXPENSE_ACCOUNT := &"OPERATING_EXPENSE"
const AUTHORITY_FINE_ACCOUNT := &"AUTHORITY_FINE_EXPENSE"
@@ -3604,8 +3606,18 @@ func _operations_payroll_crosslinks_are_valid(
elif upkeep_debt != 0:
return false
var finance_arrears := 0
# A saved report is checked by the definition it was written with: without
# the mark it is version 1; any other mark is not a report this game wrote.
var fund_version := FUND_REPORT_VERSION
if summary_settlement.get(&"funds", null) is Dictionary:
var saved_funds: Dictionary = summary_settlement[&"funds"]
var mark: Variant = saved_funds.get(&"fund_report_version", saved_funds.get("fund_report_version", null))
if mark == null:
fund_version = 1
elif typeof(mark) != TYPE_INT or int(mark) != FUND_REPORT_VERSION:
return false
var expected_funds := _daily_fund_report(economy, day, coordinator.get_financial_period_start(day),
coordinator.get_daily_close_minute(day))
coordinator.get_daily_close_minute(day), fund_version)
if expected_funds.is_empty():
return false
if summary_settlement.has(&"funds"):
@@ -3776,9 +3788,15 @@ func _post_daily_finance_charge(day: int, boundary_minute: int, new_amount: int,
## The fund side of a closed day, derived only from the ledger, so the live close
## and a restored save produce the same report.
func _daily_fund_report(economy: EconomyService, day: int, period_start: int, boundary_minute: int) -> Dictionary:
if economy == null or day <= 0 or period_start < 0 or boundary_minute <= period_start:
## and a restored save produce the same report. Version 2 (marked in the report):
## back_top_up is every top-up of the business day, the operation-time purchases
## and repayments and the legacy 00:00 upkeep as well as the close's own. A report
## without the mark is version 1, written while back_top_up counted only the
## close's own top-up; a restore checks it by that definition, not a looser one.
func _daily_fund_report(economy: EconomyService, day: int, period_start: int, boundary_minute: int,
version := FUND_REPORT_VERSION) -> Dictionary:
if economy == null or day <= 0 or period_start < 0 or boundary_minute <= period_start \
or version not in [1, FUND_REPORT_VERSION]:
return {}
var report := {
&"revenue_front": 0, &"revenue_back": 0, &"back_top_up": 0,
@@ -3811,6 +3829,19 @@ func _daily_fund_report(economy: EconomyService, day: int, period_start: int, bo
report[StringName(String(field) + "_paid")] = int(report[StringName(String(field) + "_paid")]) + entry.amount
else:
return {}
if version == FUND_REPORT_VERSION:
# The closes are keyed; the previous day's close is posted at period_start.
var closes := {}
for close_day: int in [day - 1, day]:
var close := economy.get_transaction_id_for_idempotency_key(StringName("finance.back_top_up.day.%08d" % close_day))
if not close.is_empty():
closes[close] = true
for entry: LedgerEntry in economy.get_entries():
if entry.category == FinancePolicy.TOP_UP_CATEGORY and entry.absolute_minute >= period_start \
and entry.absolute_minute < boundary_minute and not closes.has(entry.transaction_id):
report[&"back_top_up"] = int(report[&"back_top_up"]) + entry.amount
postings = true
report[&"fund_report_version"] = FUND_REPORT_VERSION
report[&"rank_tax_arrears"] = _payable_arrears_through(economy, FinancePolicy.RANK_TAX_PAYABLE, boundary_minute)
report[&"loan_interest_arrears"] = _payable_arrears_through(economy, FinancePolicy.LOAN_INTEREST_PAYABLE, boundary_minute)
report[&"has_finance_postings"] = postings
@@ -12155,6 +12186,9 @@ func _apply_service_transaction(
if service.price_snapshot > 0:
var payer_account := _guest_wallet_account(request.guest_ids[0])
var revenue_account := _facility_revenue_account(facility.instance_id)
# Only a registered definition with a hidden-service tag routes the sale to the
# hidden fund. A facility whose definition cannot be read keeps the existing
# front-fund behaviour (disclosed in execution/p05-02/REPAIR_02.md).
var sale_definition := definition_registry.get_facility(facility.definition_id)
var sale_fund := FinancePolicy.BACK_CASH \
if sale_definition != null and FinancePolicy.is_back_fund_service(sale_definition.tags) else PLAYER_CASH_ACCOUNT