Catch some amounts

This commit is contained in:
James Cole
2023-12-29 19:59:19 +01:00
parent e47110607c
commit 33b95b9371
20 changed files with 161 additions and 154 deletions

View File

@@ -62,7 +62,7 @@ class Request extends FormRequest
return [ return [
'currency_id' => 'numeric|exists:transaction_currencies,id', 'currency_id' => 'numeric|exists:transaction_currencies,id',
'currency_code' => 'min:3|max:51|exists:transaction_currencies,code', 'currency_code' => 'min:3|max:51|exists:transaction_currencies,code',
'amount' => 'numeric|gt:0', 'amount' => 'numeric|gt:0|max:1000000000',
'start' => 'date', 'start' => 'date',
'end' => 'date', 'end' => 'date',
]; ];

View File

@@ -72,8 +72,8 @@ class StoreRequest extends FormRequest
{ {
return [ return [
'name' => 'between:1,255|uniqueObjectForUser:bills,name', 'name' => 'between:1,255|uniqueObjectForUser:bills,name',
'amount_min' => 'numeric|gt:0|required', 'amount_min' => 'numeric|gt:0|required|max:1000000000',
'amount_max' => 'numeric|gt:0|required', 'amount_max' => 'numeric|gt:0|required|max:1000000000',
'currency_id' => 'numeric|exists:transaction_currencies,id', 'currency_id' => 'numeric|exists:transaction_currencies,id',
'currency_code' => 'min:3|max:51|exists:transaction_currencies,code', 'currency_code' => 'min:3|max:51|exists:transaction_currencies,code',
'date' => 'date|required', 'date' => 'date|required',

View File

@@ -75,8 +75,8 @@ class UpdateRequest extends FormRequest
return [ return [
'name' => sprintf('between:1,255|uniqueObjectForUser:bills,name,%d', $bill->id), 'name' => sprintf('between:1,255|uniqueObjectForUser:bills,name,%d', $bill->id),
'amount_min' => 'numeric|gt:0', 'amount_min' => 'numeric|gt:0|max:1000000000',
'amount_max' => 'numeric|gt:0', 'amount_max' => 'numeric|gt:0|max:1000000000',
'currency_id' => 'numeric|exists:transaction_currencies,id', 'currency_id' => 'numeric|exists:transaction_currencies,id',
'currency_code' => 'min:3|max:51|exists:transaction_currencies,code', 'currency_code' => 'min:3|max:51|exists:transaction_currencies,code',
'date' => 'date', 'date' => 'date',

View File

@@ -57,7 +57,7 @@ class StoreRequest extends FormRequest
return [ return [
'start' => 'required|before:end|date', 'start' => 'required|before:end|date',
'end' => 'required|after:start|date', 'end' => 'required|after:start|date',
'amount' => 'required|gt:0', 'amount' => 'required|gt:0|max:1000000000',
'currency_id' => 'numeric|exists:transaction_currencies,id', 'currency_id' => 'numeric|exists:transaction_currencies,id',
'currency_code' => 'min:3|max:51|exists:transaction_currencies,code', 'currency_code' => 'min:3|max:51|exists:transaction_currencies,code',
]; ];

View File

@@ -61,7 +61,7 @@ class UpdateRequest extends FormRequest
return [ return [
'start' => 'date', 'start' => 'date',
'end' => 'date', 'end' => 'date',
'amount' => 'gt:0', 'amount' => 'gt:0|max:1000000000',
'currency_id' => 'numeric|exists:transaction_currencies,id', 'currency_id' => 'numeric|exists:transaction_currencies,id',
'currency_code' => 'min:3|max:51|exists:transaction_currencies,code', 'currency_code' => 'min:3|max:51|exists:transaction_currencies,code',
]; ];

View File

@@ -116,7 +116,7 @@ class UpdateRequest extends FormRequest
// amount // amount
'transactions.*.amount' => 'numeric|gt:0|max:100000000000', 'transactions.*.amount' => 'numeric|gt:0|max:100000000000',
'transactions.*.foreign_amount' => 'nullable|numeric|gte:0', 'transactions.*.foreign_amount' => 'nullable|numeric|gte:0|max:1000000000',
// description // description
'transactions.*.description' => 'nullable|between:1,1000', 'transactions.*.description' => 'nullable|between:1,1000',

View File

@@ -134,10 +134,10 @@ class AccountController extends Controller
'currency_decimal_places' => $currency->decimal_places, 'currency_decimal_places' => $currency->decimal_places,
// the default currency of the user (could be the same!) // the default currency of the user (could be the same!)
'native_id' => (string)$default->id, 'native_currency_id' => (string)$default->id,
'native_code' => $default->code, 'native_currency_code' => $default->code,
'native_symbol' => $default->symbol, 'native_currency_symbol' => $default->symbol,
'native_decimal_places' => $default->decimal_places, 'native_currency_decimal_places' => $default->decimal_places,
'start' => $start->toAtomString(), 'start' => $start->toAtomString(),
'end' => $end->toAtomString(), 'end' => $end->toAtomString(),
'period' => '1D', 'period' => '1D',

View File

@@ -127,24 +127,24 @@ class BudgetController extends Controller
$return = []; $return = [];
foreach ($rows as $row) { foreach ($rows as $row) {
$current = [ $current = [
'label' => $budget->name, 'label' => $budget->name,
'currency_id' => (string)$row['currency_id'], 'currency_id' => (string) $row['currency_id'],
'currency_code' => $row['currency_code'], 'currency_code' => $row['currency_code'],
'currency_name' => $row['currency_name'], 'currency_name' => $row['currency_name'],
'currency_decimal_places' => $row['currency_decimal_places'], 'currency_decimal_places' => $row['currency_decimal_places'],
'native_id' => (string)$row['native_id'], 'native_currency_id' => (string) $row['native_currency_id'],
'native_code' => $row['native_code'], 'native_currency_code' => $row['native_currency_code'],
'native_name' => $row['native_name'], 'native_currency_name' => $row['native_currency_name'],
'native_decimal_places' => $row['native_decimal_places'], 'native_currency_decimal_places' => $row['native_currency_decimal_places'],
'period' => null, 'period' => null,
'start' => $row['start'], 'start' => $row['start'],
'end' => $row['end'], 'end' => $row['end'],
'entries' => [ 'entries' => [
'spent' => $row['spent'], 'spent' => $row['spent'],
'left' => $row['left'], 'left' => $row['left'],
'overspent' => $row['overspent'], 'overspent' => $row['overspent'],
], ],
'native_entries' => [ 'native_entries' => [
'spent' => $row['native_spent'], 'spent' => $row['native_spent'],
'left' => $row['native_left'], 'left' => $row['native_left'],
'overspent' => $row['native_overspent'], 'overspent' => $row['native_overspent'],
@@ -170,7 +170,8 @@ class BudgetController extends Controller
} }
/** /**
* Shared between the "noBudgetLimits" function and "processLimit". Will take a single set of expenses and return its info. * Shared between the "noBudgetLimits" function and "processLimit". Will take a single set of expenses and return
* its info.
* *
* @param array<int, array<int, string>> $array * @param array<int, array<int, string>> $array
* *
@@ -192,24 +193,24 @@ class BudgetController extends Controller
foreach ($array as $currencyId => $block) { foreach ($array as $currencyId => $block) {
$this->currencies[$currencyId] ??= TransactionCurrency::find($currencyId); $this->currencies[$currencyId] ??= TransactionCurrency::find($currencyId);
$return[$currencyId] ??= [ $return[$currencyId] ??= [
'currency_id' => (string)$currencyId, 'currency_id' => (string) $currencyId,
'currency_code' => $block['currency_code'], 'currency_code' => $block['currency_code'],
'currency_name' => $block['currency_name'], 'currency_name' => $block['currency_name'],
'currency_symbol' => $block['currency_symbol'], 'currency_symbol' => $block['currency_symbol'],
'currency_decimal_places' => (int)$block['currency_decimal_places'], 'currency_decimal_places' => (int) $block['currency_decimal_places'],
'native_id' => (string)$this->currency->id, 'native_currency_id' => (string) $this->currency->id,
'native_code' => $this->currency->code, 'native_currency_code' => $this->currency->code,
'native_name' => $this->currency->name, 'native_currency_name' => $this->currency->name,
'native_symbol' => $this->currency->symbol, 'native_currency_symbol' => $this->currency->symbol,
'native_decimal_places' => $this->currency->decimal_places, 'native_currency_decimal_places' => $this->currency->decimal_places,
'start' => $start->toAtomString(), 'start' => $start->toAtomString(),
'end' => $end->toAtomString(), 'end' => $end->toAtomString(),
'spent' => '0', 'spent' => '0',
'native_spent' => '0', 'native_spent' => '0',
'left' => '0', 'left' => '0',
'native_left' => '0', 'native_left' => '0',
'overspent' => '0', 'overspent' => '0',
'native_overspent' => '0', 'native_overspent' => '0',
]; ];
$currentBudgetArray = $block['budgets'][$budgetId]; $currentBudgetArray = $block['budgets'][$budgetId];

View File

@@ -118,11 +118,11 @@ class CategoryController extends Controller
'currency_name' => $currency->name, 'currency_name' => $currency->name,
'currency_symbol' => $currency->symbol, 'currency_symbol' => $currency->symbol,
'currency_decimal_places' => $currency->decimal_places, 'currency_decimal_places' => $currency->decimal_places,
'native_id' => (string)$default->id, 'native_currency_id' => (string)$default->id,
'native_code' => $default->code, 'native_currency_code' => $default->code,
'native_name' => $default->name, 'native_currency_name' => $default->name,
'native_symbol' => $default->symbol, 'native_currency_symbol' => $default->symbol,
'native_decimal_places' => $default->decimal_places, 'native_currency_decimal_places' => $default->decimal_places,
'period' => null, 'period' => null,
'start' => $start->toAtomString(), 'start' => $start->toAtomString(),
'end' => $end->toAtomString(), 'end' => $end->toAtomString(),

View File

@@ -206,10 +206,10 @@ class BasicController extends Controller
$return[] = [ $return[] = [
'key' => 'bills-paid-in-native', 'key' => 'bills-paid-in-native',
'value' => $nativeAmount, 'value' => $nativeAmount,
'currency_id' => (string)$info['native_id'], 'currency_id' => (string)$info['native_currency_id'],
'currency_code' => $info['native_code'], 'currency_code' => $info['native_currency_code'],
'currency_symbol' => $info['native_symbol'], 'currency_symbol' => $info['native_currency_symbol'],
'currency_decimal_places' => $info['native_decimal_places'], 'currency_decimal_places' => $info['native_currency_decimal_places'],
]; ];
} }
@@ -230,10 +230,10 @@ class BasicController extends Controller
$return[] = [ $return[] = [
'key' => 'bills-unpaid-in-native', 'key' => 'bills-unpaid-in-native',
'value' => $nativeAmount, 'value' => $nativeAmount,
'currency_id' => (string)$info['native_id'], 'currency_id' => (string)$info['native_currency_id'],
'currency_code' => $info['native_code'], 'currency_code' => $info['native_currency_code'],
'currency_symbol' => $info['native_symbol'], 'currency_symbol' => $info['native_currency_symbol'],
'currency_decimal_places' => $info['native_decimal_places'], 'currency_decimal_places' => $info['native_currency_decimal_places'],
]; ];
} }

View File

@@ -34,6 +34,7 @@ use Illuminate\Http\JsonResponse;
*/ */
class TransactionController extends Controller class TransactionController extends Controller
{ {
public function list(ListRequest $request): JsonResponse public function list(ListRequest $request): JsonResponse
{ {
// collect transactions: // collect transactions:

View File

@@ -51,7 +51,7 @@ class NetWorth implements NetWorthInterface
private CurrencyRepositoryInterface $currencyRepos; private CurrencyRepositoryInterface $currencyRepos;
private User $user; private User $user;
private null|UserGroup $userGroup; private null | UserGroup $userGroup;
/** /**
* This method collects the user's net worth in ALL the user's currencies * This method collects the user's net worth in ALL the user's currencies
@@ -80,18 +80,18 @@ class NetWorth implements NetWorthInterface
// default "native" currency has everything twice, for consistency. // default "native" currency has everything twice, for consistency.
$netWorth = [ $netWorth = [
'native' => [ 'native' => [
'balance' => '0', 'balance' => '0',
'native_balance' => '0', 'native_balance' => '0',
'currency_id' => $default->id, 'currency_id' => $default->id,
'currency_code' => $default->code, 'currency_code' => $default->code,
'currency_name' => $default->name, 'currency_name' => $default->name,
'currency_symbol' => $default->symbol, 'currency_symbol' => $default->symbol,
'currency_decimal_places' => $default->decimal_places, 'currency_decimal_places' => $default->decimal_places,
'native_id' => $default->id, 'native_currency_id' => $default->id,
'native_code' => $default->code, 'native_currency_code' => $default->code,
'native_name' => $default->name, 'native_currency_name' => $default->name,
'native_symbol' => $default->symbol, 'native_currency_symbol' => $default->symbol,
'native_decimal_places' => $default->decimal_places, 'native_currency_decimal_places' => $default->decimal_places,
], ],
]; ];
$balances = app('steam')->balancesByAccountsConverted($accounts, $date); $balances = app('steam')->balancesByAccountsConverted($accounts, $date);
@@ -103,7 +103,7 @@ class NetWorth implements NetWorthInterface
if (null === $currency) { if (null === $currency) {
$currency = app('amount')->getDefaultCurrency(); $currency = app('amount')->getDefaultCurrency();
} }
$currencyId = $currency->id; $currencyCode = $currency->code;
$balance = '0'; $balance = '0';
$nativeBalance = '0'; $nativeBalance = '0';
if (array_key_exists($account->id, $balances)) { if (array_key_exists($account->id, $balances)) {
@@ -118,25 +118,25 @@ class NetWorth implements NetWorthInterface
$nativeVirtualBalance = $converter->convert($default, $currency, $account->created_at, $virtualBalance); $nativeVirtualBalance = $converter->convert($default, $currency, $account->created_at, $virtualBalance);
$nativeBalance = bcsub($nativeBalance, $nativeVirtualBalance); $nativeBalance = bcsub($nativeBalance, $nativeVirtualBalance);
} }
$netWorth[$currencyId] ??= [ $netWorth[$currencyCode] ??= [
'balance' => '0', 'balance' => '0',
'native_balance' => '0', 'native_balance' => '0',
'currency_id' => $currencyId, 'currency_id' => (string) $currency->id,
'currency_code' => $currency->code, 'currency_code' => $currency->code,
'currency_name' => $currency->name, 'currency_name' => $currency->name,
'currency_symbol' => $currency->symbol, 'currency_symbol' => $currency->symbol,
'currency_decimal_places' => $currency->decimal_places, 'currency_decimal_places' => $currency->decimal_places,
'native_id' => $default->id, 'native_currency_id' => (string) $default->id,
'native_code' => $default->code, 'native_currency_code' => $default->code,
'native_name' => $default->name, 'native_currency_name' => $default->name,
'native_symbol' => $default->symbol, 'native_currency_symbol' => $default->symbol,
'native_decimal_places' => $default->decimal_places, 'native_currency_decimal_places' => $default->decimal_places,
]; ];
$netWorth[$currencyId]['balance'] = bcadd($balance, $netWorth[$currencyId]['balance']); $netWorth[$currencyCode]['balance'] = bcadd($balance, $netWorth[$currencyCode]['balance']);
$netWorth[$currencyId]['native_balance'] = bcadd($nativeBalance, $netWorth[$currencyId]['native_balance']); $netWorth[$currencyCode]['native_balance'] = bcadd($nativeBalance, $netWorth[$currencyCode]['native_balance']);
$netWorth['native']['balance'] = bcadd($nativeBalance, $netWorth['native']['balance']); $netWorth['native']['balance'] = bcadd($nativeBalance, $netWorth['native']['balance']);
$netWorth['native']['native_balance'] = bcadd($nativeBalance, $netWorth['native']['native_balance']); $netWorth['native']['native_balance'] = bcadd($nativeBalance, $netWorth['native']['native_balance']);
} }
$cache->store($netWorth); $cache->store($netWorth);
$converter->summarize(); $converter->summarize();
@@ -144,7 +144,7 @@ class NetWorth implements NetWorthInterface
return $netWorth; return $netWorth;
} }
public function setUser(null|Authenticatable|User $user): void public function setUser(null | Authenticatable | User $user): void
{ {
if (!$user instanceof User) { if (!$user instanceof User) {
return; return;
@@ -189,7 +189,7 @@ class NetWorth implements NetWorthInterface
} }
$return[$currency->id] ??= [ $return[$currency->id] ??= [
'id' => (string)$currency->id, 'id' => (string) $currency->id,
'name' => $currency->name, 'name' => $currency->name,
'symbol' => $currency->symbol, 'symbol' => $currency->symbol,
'code' => $currency->code, 'code' => $currency->code,
@@ -202,7 +202,7 @@ class NetWorth implements NetWorthInterface
return $return; return $return;
} }
private function getRepository(): AccountRepositoryInterface|AdminAccountRepositoryInterface private function getRepository(): AccountRepositoryInterface | AdminAccountRepositoryInterface
{ {
if (null === $this->userGroup) { if (null === $this->userGroup) {
return $this->accountRepository; return $this->accountRepository;
@@ -220,7 +220,7 @@ class NetWorth implements NetWorthInterface
/** @var Account $account */ /** @var Account $account */
foreach ($accounts as $account) { foreach ($accounts as $account) {
if (1 === (int)$this->getRepository()->getMetaValue($account, 'include_net_worth')) { if (1 === (int) $this->getRepository()->getMetaValue($account, 'include_net_worth')) {
$filtered->push($account); $filtered->push($account);
} }
} }

View File

@@ -86,11 +86,11 @@ class BillRepository implements BillRepositoryInterface
'currency_symbol' => $currency->symbol, 'currency_symbol' => $currency->symbol,
'currency_code' => $currency->code, 'currency_code' => $currency->code,
'currency_decimal_places' => $currency->decimal_places, 'currency_decimal_places' => $currency->decimal_places,
'native_id' => (string)$default->id, 'native_currency_id' => (string)$default->id,
'native_name' => $default->name, 'native_currency_name' => $default->name,
'native_symbol' => $default->symbol, 'native_currency_symbol' => $default->symbol,
'native_code' => $default->code, 'native_currency_code' => $default->code,
'native_decimal_places' => $default->decimal_places, 'native_currency_decimal_places' => $default->decimal_places,
'sum' => '0', 'sum' => '0',
'native_sum' => '0', 'native_sum' => '0',
]; ];
@@ -159,11 +159,11 @@ class BillRepository implements BillRepositoryInterface
'currency_symbol' => $currency->symbol, 'currency_symbol' => $currency->symbol,
'currency_code' => $currency->code, 'currency_code' => $currency->code,
'currency_decimal_places' => $currency->decimal_places, 'currency_decimal_places' => $currency->decimal_places,
'native_id' => (string)$default->id, 'native_currency_id' => (string)$default->id,
'native_name' => $default->name, 'native_currency_name' => $default->name,
'native_symbol' => $default->symbol, 'native_currency_symbol' => $default->symbol,
'native_code' => $default->code, 'native_currency_code' => $default->code,
'native_decimal_places' => $default->decimal_places, 'native_currency_decimal_places' => $default->decimal_places,
'sum' => '0', 'sum' => '0',
'native_sum' => '0', 'native_sum' => '0',
]; ];

View File

@@ -44,26 +44,25 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
$converter = new ExchangeRateConverter(); $converter = new ExchangeRateConverter();
$default = app('amount')->getDefaultCurrency(); $default = app('amount')->getDefaultCurrency();
$availableBudgets = $this->userGroup->availableBudgets() $availableBudgets = $this->userGroup->availableBudgets()
->where('start_date', $start->format('Y-m-d')) ->where('start_date', $start->format('Y-m-d'))
->where('end_date', $end->format('Y-m-d'))->get() ->where('end_date', $end->format('Y-m-d'))->get();
;
/** @var AvailableBudget $availableBudget */ /** @var AvailableBudget $availableBudget */
foreach ($availableBudgets as $availableBudget) { foreach ($availableBudgets as $availableBudget) {
$currencyId = $availableBudget->transaction_currency_id; $currencyId = $availableBudget->transaction_currency_id;
$return[$currencyId] ??= [ $return[$currencyId] ??= [
'currency_id' => $currencyId, 'currency_id' => $currencyId,
'currency_code' => $availableBudget->transactionCurrency->code, 'currency_code' => $availableBudget->transactionCurrency->code,
'currency_symbol' => $availableBudget->transactionCurrency->symbol, 'currency_symbol' => $availableBudget->transactionCurrency->symbol,
'currency_name' => $availableBudget->transactionCurrency->name, 'currency_name' => $availableBudget->transactionCurrency->name,
'currency_decimal_places' => $availableBudget->transactionCurrency->decimal_places, 'currency_decimal_places' => $availableBudget->transactionCurrency->decimal_places,
'native_id' => $default->id, 'native_currency_id' => $default->id,
'native_code' => $default->code, 'native_currency_code' => $default->code,
'native_symbol' => $default->symbol, 'native_currency_symbol' => $default->symbol,
'native_name' => $default->name, 'native_currency_name' => $default->name,
'native_decimal_places' => $default->decimal_places, 'native_currency_decimal_places' => $default->decimal_places,
'amount' => '0', 'amount' => '0',
'native_amount' => '0', 'native_amount' => '0',
]; ];
$nativeAmount = $converter->convert($availableBudget->transactionCurrency, $default, $availableBudget->start_date, $availableBudget->amount); $nativeAmount = $converter->convert($availableBudget->transactionCurrency, $default, $availableBudget->start_date, $availableBudget->amount);
$return[$currencyId]['amount'] = bcadd($return[$currencyId]['amount'], $availableBudget->amount); $return[$currencyId]['amount'] = bcadd($return[$currencyId]['amount'], $availableBudget->amount);

View File

@@ -62,10 +62,10 @@ class AccountBalanceGrouped
'currency_symbol' => $currency['currency_symbol'], 'currency_symbol' => $currency['currency_symbol'],
'currency_code' => $currency['currency_code'], 'currency_code' => $currency['currency_code'],
'currency_decimal_places' => $currency['currency_decimal_places'], 'currency_decimal_places' => $currency['currency_decimal_places'],
'native_id' => (string)$currency['native_id'], 'native_currency_id' => (string)$currency['native_currency_id'],
'native_symbol' => $currency['native_symbol'], 'native_currency_symbol' => $currency['native_currency_symbol'],
'native_code' => $currency['native_code'], 'native_currency_code' => $currency['native_currency_code'],
'native_decimal_places' => $currency['native_decimal_places'], 'native_currency_decimal_places' => $currency['native_currency_decimal_places'],
'start' => $this->start->toAtomString(), 'start' => $this->start->toAtomString(),
'end' => $this->end->toAtomString(), 'end' => $this->end->toAtomString(),
'period' => $this->preferredRange, 'period' => $this->preferredRange,
@@ -78,10 +78,10 @@ class AccountBalanceGrouped
'currency_symbol' => $currency['currency_symbol'], 'currency_symbol' => $currency['currency_symbol'],
'currency_code' => $currency['currency_code'], 'currency_code' => $currency['currency_code'],
'currency_decimal_places' => $currency['currency_decimal_places'], 'currency_decimal_places' => $currency['currency_decimal_places'],
'native_id' => (string)$currency['native_id'], 'native_currency_id' => (string)$currency['native_currency_id'],
'native_symbol' => $currency['native_symbol'], 'native_currency_symbol' => $currency['native_currency_symbol'],
'native_code' => $currency['native_code'], 'native_currency_code' => $currency['native_currency_code'],
'native_decimal_places' => $currency['native_decimal_places'], 'native_currency_decimal_places' => $currency['native_currency_decimal_places'],
'start' => $this->start->toAtomString(), 'start' => $this->start->toAtomString(),
'end' => $this->end->toAtomString(), 'end' => $this->end->toAtomString(),
'period' => $this->preferredRange, 'period' => $this->preferredRange,
@@ -138,10 +138,10 @@ class AccountBalanceGrouped
'currency_name' => $journal['currency_name'], 'currency_name' => $journal['currency_name'],
'currency_decimal_places' => $journal['currency_decimal_places'], 'currency_decimal_places' => $journal['currency_decimal_places'],
// native currency info (could be the same) // native currency info (could be the same)
'native_id' => (string)$this->default->id, 'native_currency_id' => (string)$this->default->id,
'native_code' => $this->default->code, 'native_currency_code' => $this->default->code,
'native_symbol' => $this->default->symbol, 'native_currency_symbol' => $this->default->symbol,
'native_decimal_places' => $this->default->decimal_places, 'native_currency_decimal_places' => $this->default->decimal_places,
]; ];
// set the array (in monetary info) with spent/earned in this $period, if it does not exist. // set the array (in monetary info) with spent/earned in this $period, if it does not exist.
@@ -214,11 +214,11 @@ class AccountBalanceGrouped
'currency_code' => $default->code, 'currency_code' => $default->code,
'currency_name' => $default->name, 'currency_name' => $default->name,
'currency_decimal_places' => $default->decimal_places, 'currency_decimal_places' => $default->decimal_places,
'native_id' => (string)$defaultCurrencyId, 'native_currency_id' => (string)$defaultCurrencyId,
'native_symbol' => $default->symbol, 'native_currency_symbol' => $default->symbol,
'native_code' => $default->code, 'native_currency_code' => $default->code,
'native_name' => $default->name, 'native_currency_name' => $default->name,
'native_decimal_places' => $default->decimal_places, 'native_currency_decimal_places' => $default->decimal_places,
]; ];
} }

View File

@@ -50,8 +50,8 @@ trait CleansChartData
if (array_key_exists('currency_id', $array)) { if (array_key_exists('currency_id', $array)) {
$array['currency_id'] = (string)$array['currency_id']; $array['currency_id'] = (string)$array['currency_id'];
} }
if (array_key_exists('native_id', $array)) { if (array_key_exists('native_currency_id', $array)) {
$array['native_id'] = (string)$array['native_id']; $array['native_currency_id'] = (string)$array['native_currency_id'];
} }
if (!array_key_exists('start', $array)) { if (!array_key_exists('start', $array)) {
throw new FireflyException(sprintf('Data-set "%s" is missing the "start"-variable.', $index)); throw new FireflyException(sprintf('Data-set "%s" is missing the "start"-variable.', $index));

View File

@@ -58,10 +58,10 @@ trait ConvertsExchangeRates
$native = app('amount')->getDefaultCurrency(); $native = app('amount')->getDefaultCurrency();
$currency = $this->getCurrency((int)$set['currency_id']); $currency = $this->getCurrency((int)$set['currency_id']);
if ($native->id === $currency->id) { if ($native->id === $currency->id) {
$set['native_id'] = (string)$currency->id; $set['native_currency_id'] = (string)$currency->id;
$set['native_code'] = $currency->code; $set['native_currency_code'] = $currency->code;
$set['native_symbol'] = $currency->symbol; $set['native_currency_symbol'] = $currency->symbol;
$set['native_decimal_places'] = $currency->decimal_places; $set['native_currency_decimal_places'] = $currency->decimal_places;
return $set; return $set;
} }
@@ -112,20 +112,20 @@ trait ConvertsExchangeRates
$amount = $this->convertAmount($entry['sum'], $currency, $native); $amount = $this->convertAmount($entry['sum'], $currency, $native);
$entry['converted'] = true; $entry['converted'] = true;
$entry['native_sum'] = $amount; $entry['native_sum'] = $amount;
$entry['native_id'] = (string)$native->id; $entry['native_currency_id'] = (string)$native->id;
$entry['native_name'] = $native->name; $entry['native_currency_name'] = $native->name;
$entry['native_symbol'] = $native->symbol; $entry['native_currency_symbol'] = $native->symbol;
$entry['native_code'] = $native->code; $entry['native_currency_code'] = $native->code;
$entry['native_decimal_places'] = $native->decimal_places; $entry['native_currency_decimal_places'] = $native->decimal_places;
} }
if ($currency->id === $native->id) { if ($currency->id === $native->id) {
$entry['converted'] = false; $entry['converted'] = false;
$entry['native_sum'] = $entry['sum']; $entry['native_sum'] = $entry['sum'];
$entry['native_id'] = (string)$native->id; $entry['native_currency_id'] = (string)$native->id;
$entry['native_name'] = $native->name; $entry['native_currency_name'] = $native->name;
$entry['native_symbol'] = $native->symbol; $entry['native_currency_symbol'] = $native->symbol;
$entry['native_code'] = $native->code; $entry['native_currency_code'] = $native->code;
$entry['native_decimal_places'] = $native->decimal_places; $entry['native_currency_decimal_places'] = $native->decimal_places;
} }
$return[] = $entry; $return[] = $entry;
} }

View File

@@ -139,7 +139,7 @@ class AccountTransformer extends AbstractTransformer
// balance: // balance:
'current_balance' => $balance, 'current_balance' => $balance,
'native_current_balance' => $nativeBalance, 'native_current_balance' => $nativeBalance,
'current_balance_date' => $this->getDate(), 'current_balance_date' => $this->getDate()->endOfDay()->toAtomString(),
// more meta // more meta

View File

@@ -223,7 +223,6 @@ class TransactionGroupTransformer extends AbstractTransformer
'recurrence_id' => $meta['recurrence_id'], 'recurrence_id' => $meta['recurrence_id'],
'recurrence_total' => $meta['recurrence_total'], 'recurrence_total' => $meta['recurrence_total'],
'recurrence_count' => $meta['recurrence_count'], 'recurrence_count' => $meta['recurrence_count'],
'bunq_payment_id' => $meta['bunq_payment_id'],
'external_url' => $meta['external_url'], 'external_url' => $meta['external_url'],
'import_hash_v2' => $meta['import_hash_v2'], 'import_hash_v2' => $meta['import_hash_v2'],
'sepa_cc' => $meta['sepa_cc'], 'sepa_cc' => $meta['sepa_cc'],

View File

@@ -34,7 +34,9 @@ Route::group(
Route::get('basic', ['uses' => 'BasicController@basic', 'as' => 'basic']); Route::get('basic', ['uses' => 'BasicController@basic', 'as' => 'basic']);
} }
); );
// V2 API route for TransactionList API endpoints // V2 API route for all kinds of Transaction lists.
// A lot of endpoints involve transactions. So any time Firefly III needs to list transactions
// it's coming from these endpoints.
Route::group( Route::group(
[ [
'namespace' => 'FireflyIII\Api\V2\Controllers\Transaction\List', 'namespace' => 'FireflyIII\Api\V2\Controllers\Transaction\List',
@@ -42,7 +44,11 @@ Route::group(
'as' => 'api.v2.', 'as' => 'api.v2.',
], ],
static function (): void { static function (): void {
// basic list
Route::get('transactions', ['uses' => 'TransactionController@list', 'as' => 'transactions.list']); Route::get('transactions', ['uses' => 'TransactionController@list', 'as' => 'transactions.list']);
// list by parent or related object.
// note how the check is done on the user group, not the user itself.
Route::get('accounts/{userGroupAccount}/transactions', ['uses' => 'AccountController@list', 'as' => 'accounts.transactions']); Route::get('accounts/{userGroupAccount}/transactions', ['uses' => 'AccountController@list', 'as' => 'accounts.transactions']);
} }
); );
@@ -152,6 +158,7 @@ Route::group(
); );
// V2 API route for budgets and budget limits: // V2 API route for budgets and budget limits:
// TODO Validate from here down.
Route::group( Route::group(
[ [
'namespace' => 'FireflyIII\Api\V2\Controllers\Model', 'namespace' => 'FireflyIII\Api\V2\Controllers\Model',