Player12
An open source football management simulator
Loading...
Searching...
No Matches
Finances Class Reference

A club's balance, budgets and dated transaction ledger. More...

#include <finances.h>

Public Member Functions

 Finances (std::int64_t opening_balance, GameDateValue opening_date=GameDateValue(2025, 7, 2))
 Creates the finances with an opening-balance transaction.
 
void record (const GameDateValue &date, FinanceCategory category, std::int64_t amount)
 Records a dated transaction and updates the balance.
 
bool revertLastTransaction ()
 
void addBalance (std::int64_t amount)
 Owner investment dated at the newest transaction.
 
std::int64_t getBalance () const noexcept
 Current cash.
 
std::int64_t getTransferBudget () const noexcept
 Remaining transfer allowance for this season.
 
void setTransferBudget (std::int64_t budget)
 Sets the transfer allowance.
 
std::int64_t getWageBudget () const noexcept
 Weekly wage allowance (cap on the total weekly payroll).
 
void setWageBudget (std::int64_t weekly_budget)
 Sets the weekly wage allowance.
 
bool moveTransferToWageBudget (std::int64_t transfer_amount, std::int64_t current_weekly_wages)
 Moves money between the two budgets at 52 weeks per season.
 
const std::vector< FinanceTransaction > & getLedger () const noexcept
 All transactions in recording order (chronological).
 
std::int64_t ledgerTotal () const
 Sum of all ledger amounts (equals the balance).
 
std::int64_t balanceAt (const GameDateValue &date) const
 Balance from the transactions dated on or before date.
 
FinanceSummary summarize (const GameDateValue &from, const GameDateValue &to) const
 Totals of the transactions dated in [from, to].
 
int64_t getCurrentWageSpending (const GameData &gamedata, const Team &team) const
 Gets the current total wage spending of the team.
 
void restoreLedger (std::vector< FinanceTransaction > ledger)
 
std::span< const FinanceTransaction > pendingTransactions () const
 
std::size_t persistedCount () const noexcept
 
void markPersisted () noexcept
 

Private Attributes

std::int64_t balance = 0
 
std::int64_t transfer_budget = 0
 
std::int64_t wage_budget = 0
 
std::vector< FinanceTransaction > ledger
 
std::size_t persisted = 0
 

Detailed Description

A club's balance, budgets and dated transaction ledger.

Every balance change is recorded as a transaction, so the balance always equals the sum of the ledger. The transfer budget and the weekly wage budget are separate allowances set by the board each season.

Constructor & Destructor Documentation

◆ Finances()

Finances::Finances ( std::int64_t  opening_balance,
GameDateValue  opening_date = GameDateValue(2025, 7, 2) 
)
explicit

Creates the finances with an opening-balance transaction.

Parameters
opening_balanceInitial cash.
opening_dateDate of the opening transaction.

Member Function Documentation

◆ addBalance()

void Finances::addBalance ( std::int64_t  amount)

Owner investment dated at the newest transaction.

The funds are unrestricted: they raise the transfer budget by the full amount and the weekly wage budget by one season's worth (amount / 52).

◆ balanceAt()

std::int64_t Finances::balanceAt ( const GameDateValue &  date) const

Balance from the transactions dated on or before date.

◆ getBalance()

std::int64_t Finances::getBalance ( ) const
noexcept

Current cash.

◆ getCurrentWageSpending()

int64_t Finances::getCurrentWageSpending ( const GameData &  gamedata,
const Team &  team 
) const

Gets the current total wage spending of the team.

Returns
The current weekly wage spending.

◆ getLedger()

const std::vector< FinanceTransaction > & Finances::getLedger ( ) const
noexcept

All transactions in recording order (chronological).

◆ getTransferBudget()

std::int64_t Finances::getTransferBudget ( ) const
noexcept

Remaining transfer allowance for this season.

◆ getWageBudget()

std::int64_t Finances::getWageBudget ( ) const
noexcept

Weekly wage allowance (cap on the total weekly payroll).

◆ ledgerTotal()

std::int64_t Finances::ledgerTotal ( ) const

Sum of all ledger amounts (equals the balance).

◆ markPersisted()

void Finances::markPersisted ( )
noexcept

Marks every transaction as written.

◆ moveTransferToWageBudget()

bool Finances::moveTransferToWageBudget ( std::int64_t  transfer_amount,
std::int64_t  current_weekly_wages 
)

Moves money between the two budgets at 52 weeks per season.

Parameters
transfer_amountPositive moves transfer budget into weekly wages, negative moves unused weekly wage room back into the transfer budget.
current_weekly_wagesPayroll that the wage budget must cover.
Returns
False when a budget would drop below its floor.

◆ pendingTransactions()

std::span< const FinanceTransaction > Finances::pendingTransactions ( ) const

Transactions not yet written to the database.

◆ persistedCount()

std::size_t Finances::persistedCount ( ) const
noexcept

Index of the first pending transaction.

◆ record()

void Finances::record ( const GameDateValue &  date,
FinanceCategory  category,
std::int64_t  amount 
)

Records a dated transaction and updates the balance.

Fees paid reduce the transfer budget; a share of fees received is returned to it.

◆ restoreLedger()

void Finances::restoreLedger ( std::vector< FinanceTransaction >  ledger)

Replaces the ledger with persisted rows; the balance follows it.

◆ revertLastTransaction()

bool Finances::revertLastTransaction ( )

Removes the newest transaction and undoes its effects.

◆ setTransferBudget()

void Finances::setTransferBudget ( std::int64_t  budget)

Sets the transfer allowance.

◆ setWageBudget()

void Finances::setWageBudget ( std::int64_t  weekly_budget)

Sets the weekly wage allowance.

◆ summarize()

FinanceSummary Finances::summarize ( const GameDateValue &  from,
const GameDateValue &  to 
) const

Totals of the transactions dated in [from, to].

Member Data Documentation

◆ balance

std::int64_t Finances::balance = 0
private

◆ ledger

std::vector<FinanceTransaction> Finances::ledger
private

◆ persisted

std::size_t Finances::persisted = 0
private

◆ transfer_budget

std::int64_t Finances::transfer_budget = 0
private

◆ wage_budget

std::int64_t Finances::wage_budget = 0
private

The documentation for this class was generated from the following files: