mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-06 14:12:15 +00:00
Code cleanup.
This commit is contained in:
@@ -46,12 +46,11 @@ class AccountBalanceGrouped
|
||||
|
||||
/**
|
||||
* Convert the given input to a chart compatible array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function convertToChartData(): array
|
||||
{
|
||||
$chartData = [];
|
||||
|
||||
// loop2: loop this data, make chart bars for each currency:
|
||||
/** @var array $currency */
|
||||
foreach ($this->data as $currency) {
|
||||
@@ -87,7 +86,6 @@ class AccountBalanceGrouped
|
||||
'period' => $this->preferredRange,
|
||||
'entries' => [],
|
||||
'native_entries' => [],
|
||||
|
||||
];
|
||||
// loop all possible periods between $start and $end, and add them to the correct dataset.
|
||||
$currentStart = clone $this->start;
|
||||
@@ -95,12 +93,12 @@ class AccountBalanceGrouped
|
||||
$key = $currentStart->format($this->carbonFormat);
|
||||
$label = $currentStart->toAtomString();
|
||||
// normal entries
|
||||
$income['entries'][$label] = app('steam')->bcround(($currency[$key]['earned'] ?? '0'), $currency['currency_decimal_places']);
|
||||
$expense['entries'][$label] = app('steam')->bcround(($currency[$key]['spent'] ?? '0'), $currency['currency_decimal_places']);
|
||||
$income['entries'][$label] = app('steam')->bcround($currency[$key]['earned'] ?? '0', $currency['currency_decimal_places']);
|
||||
$expense['entries'][$label] = app('steam')->bcround($currency[$key]['spent'] ?? '0', $currency['currency_decimal_places']);
|
||||
|
||||
// converted entries
|
||||
$income['native_entries'][$label] = app('steam')->bcround(($currency[$key]['native_earned'] ?? '0'), $currency['native_decimal_places']);
|
||||
$expense['native_entries'][$label] = app('steam')->bcround(($currency[$key]['native_spent'] ?? '0'), $currency['native_decimal_places']);
|
||||
$income['native_entries'][$label] = app('steam')->bcround($currency[$key]['native_earned'] ?? '0', $currency['native_decimal_places']);
|
||||
$expense['native_entries'][$label] = app('steam')->bcround($currency[$key]['native_spent'] ?? '0', $currency['native_decimal_places']);
|
||||
|
||||
// next loop
|
||||
$currentStart = app('navigation')->addPeriod($currentStart, $this->preferredRange, 0);
|
||||
@@ -109,18 +107,18 @@ class AccountBalanceGrouped
|
||||
$chartData[] = $income;
|
||||
$chartData[] = $expense;
|
||||
}
|
||||
|
||||
return $chartData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Group the given journals by currency and then by period.
|
||||
* If they are part of a set of accounts this basically means it's balance chart.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function groupByCurrencyAndPeriod(): void
|
||||
{
|
||||
$converter = new ExchangeRateConverter();
|
||||
|
||||
// loop. group by currency and by period.
|
||||
/** @var array $journal */
|
||||
foreach ($this->journals as $journal) {
|
||||
@@ -159,9 +157,8 @@ class AccountBalanceGrouped
|
||||
// transfer or reconcile or opening balance, and these accounts are the destination.
|
||||
if (
|
||||
TransactionType::DEPOSIT === $journal['transaction_type_type']
|
||||
||
|
||||
|
||||
(
|
||||
|| (
|
||||
(
|
||||
TransactionType::TRANSFER === $journal['transaction_type_type']
|
||||
|| TransactionType::RECONCILIATION === $journal['transaction_type_type']
|
||||
@@ -173,6 +170,7 @@ class AccountBalanceGrouped
|
||||
$key = 'earned';
|
||||
$amount = app('steam')->positive($journal['amount']);
|
||||
}
|
||||
|
||||
// get conversion rate
|
||||
try {
|
||||
$rate = $converter->getCurrencyRate($currency, $this->default, $journal['date']);
|
||||
@@ -195,29 +193,18 @@ class AccountBalanceGrouped
|
||||
$convertedKey = sprintf('native_%s', $key);
|
||||
$this->data[$currencyId][$period][$convertedKey] = bcadd($this->data[$currencyId][$period][$convertedKey], $amountConverted);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setAccounts(Collection $accounts): void
|
||||
{
|
||||
$this->accountIds = $accounts->pluck('id')->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $default
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefault(TransactionCurrency $default): void
|
||||
{
|
||||
$this->default = $default;
|
||||
$defaultCurrencyId = $default->id;
|
||||
$this->currencies = [$default->id => $default,]; // currency cache
|
||||
$this->currencies = [$default->id => $default]; // currency cache
|
||||
$this->data[$defaultCurrencyId] = [
|
||||
'currency_id' => (string)$defaultCurrencyId,
|
||||
'currency_symbol' => $default->symbol,
|
||||
@@ -232,47 +219,24 @@ class AccountBalanceGrouped
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setEnd(Carbon $end): void
|
||||
{
|
||||
$this->end = $end;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $journals
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setJournals(array $journals): void
|
||||
{
|
||||
$this->journals = $journals;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $preferredRange
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setPreferredRange(string $preferredRange): void
|
||||
{
|
||||
$this->preferredRange = $preferredRange;
|
||||
$this->carbonFormat = app('navigation')->preferredCarbonFormatByPeriod($preferredRange);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setStart(Carbon $start): void
|
||||
{
|
||||
$this->start = $start;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -27,17 +27,11 @@ use FireflyIII\Models\AccountType;
|
||||
|
||||
/**
|
||||
* Trait AccountFilter
|
||||
*
|
||||
|
||||
*/
|
||||
trait AccountFilter
|
||||
{
|
||||
/**
|
||||
* All the available types.
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function mapAccountTypes(string $type): array
|
||||
{
|
||||
@@ -56,11 +50,11 @@ trait AccountFilter
|
||||
AccountType::DEBT,
|
||||
AccountType::MORTGAGE,
|
||||
],
|
||||
'asset' => [AccountType::DEFAULT, AccountType::ASSET,],
|
||||
'cash' => [AccountType::CASH,],
|
||||
'expense' => [AccountType::EXPENSE, AccountType::BENEFICIARY,],
|
||||
'revenue' => [AccountType::REVENUE,],
|
||||
'special' => [AccountType::CASH, AccountType::INITIAL_BALANCE, AccountType::IMPORT, AccountType::RECONCILIATION,],
|
||||
'asset' => [AccountType::DEFAULT, AccountType::ASSET],
|
||||
'cash' => [AccountType::CASH],
|
||||
'expense' => [AccountType::EXPENSE, AccountType::BENEFICIARY],
|
||||
'revenue' => [AccountType::REVENUE],
|
||||
'special' => [AccountType::CASH, AccountType::INITIAL_BALANCE, AccountType::IMPORT, AccountType::RECONCILIATION],
|
||||
'hidden' => [AccountType::INITIAL_BALANCE, AccountType::IMPORT, AccountType::RECONCILIATION],
|
||||
'liability' => [AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD],
|
||||
'liabilities' => [AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD],
|
||||
|
||||
@@ -28,17 +28,11 @@ use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Trait ApiSupport
|
||||
*
|
||||
|
||||
*/
|
||||
trait ApiSupport
|
||||
{
|
||||
/**
|
||||
* Small helper function for the revenue and expense account charts.
|
||||
*
|
||||
* @param array $names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function expandNames(array $names): array
|
||||
{
|
||||
@@ -52,14 +46,11 @@ trait ApiSupport
|
||||
|
||||
/**
|
||||
* Small helper function for the revenue and expense account charts.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function extractNames(Collection $accounts): array
|
||||
{
|
||||
$return = [];
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
$return[$account->id] = $account->name;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
|
||||
/*
|
||||
* CleansChartData.php
|
||||
* Copyright (c) 2023 james@firefly-iii.org
|
||||
@@ -37,14 +36,12 @@ trait CleansChartData
|
||||
* "main" entry used in the V2 API chart endpoints. This loop makes sure
|
||||
* IDs are strings and other values are present (or missing).
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function clean(array $data): array
|
||||
{
|
||||
$return = [];
|
||||
|
||||
/**
|
||||
* @var mixed $index
|
||||
* @var array $array
|
||||
@@ -67,7 +64,7 @@ trait CleansChartData
|
||||
}
|
||||
$return[] = $array;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Support\Http\Api;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use DateTimeInterface;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
|
||||
/**
|
||||
@@ -36,9 +35,6 @@ trait ConvertsExchangeRates
|
||||
private ?bool $enabled = null;
|
||||
|
||||
/**
|
||||
* @param array $set
|
||||
*
|
||||
* @return array
|
||||
* @deprecated
|
||||
*/
|
||||
public function cerChartSet(array $set): array
|
||||
@@ -52,10 +48,12 @@ trait ConvertsExchangeRates
|
||||
$this->enabled = false;
|
||||
if (false === $this->enabled) {
|
||||
$set['converted'] = false;
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
$set['converted'] = true;
|
||||
|
||||
/** @var TransactionCurrency $native */
|
||||
$native = app('amount')->getDefaultCurrency();
|
||||
$currency = $this->getCurrency((int)$set['currency_id']);
|
||||
@@ -64,50 +62,24 @@ trait ConvertsExchangeRates
|
||||
$set['native_code'] = $currency->code;
|
||||
$set['native_symbol'] = $currency->symbol;
|
||||
$set['native_decimal_places'] = $currency->decimal_places;
|
||||
|
||||
return $set;
|
||||
}
|
||||
foreach ($set['entries'] as $date => $entry) {
|
||||
$carbon = Carbon::createFromFormat(DateTimeInterface::ATOM, $date);
|
||||
$carbon = Carbon::createFromFormat(\DateTimeInterface::ATOM, $date);
|
||||
$rate = $this->getRate($currency, $native, $carbon);
|
||||
$rate = '0' === $rate ? '1' : $rate;
|
||||
app('log')->debug(sprintf('bcmul("%s", "%s")', (string)$entry, $rate));
|
||||
$set['entries'][$date] = (float)bcmul((string)$entry, $rate);
|
||||
}
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @deprecated
|
||||
*/
|
||||
private function getPreference(): void
|
||||
{
|
||||
$this->enabled = config('cer.currency_conversion');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $currencyId
|
||||
*
|
||||
* @return TransactionCurrency
|
||||
* @deprecated
|
||||
*/
|
||||
private function getCurrency(int $currencyId): TransactionCurrency
|
||||
{
|
||||
$result = TransactionCurrency::find($currencyId);
|
||||
if (null === $result) {
|
||||
return app('amount')->getDefaultCurrency();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* For a sum of entries, get the exchange rate to the native currency of
|
||||
* the user.
|
||||
*
|
||||
* @param array $entries
|
||||
*
|
||||
* @return array
|
||||
* @deprecated
|
||||
*/
|
||||
public function cerSum(array $entries): array
|
||||
@@ -119,18 +91,20 @@ trait ConvertsExchangeRates
|
||||
// if false, return the same array without conversion info
|
||||
if (false === $this->enabled) {
|
||||
$return = [];
|
||||
|
||||
/** @var array $entry */
|
||||
foreach ($entries as $entry) {
|
||||
$entry['converted'] = false;
|
||||
$return[] = $entry;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/** @var TransactionCurrency $native */
|
||||
$native = app('amount')->getDefaultCurrency();
|
||||
$return = [];
|
||||
|
||||
/** @var array $entry */
|
||||
foreach ($entries as $entry) {
|
||||
$currency = $this->getCurrency((int)$entry['id']);
|
||||
@@ -155,17 +129,32 @@ trait ConvertsExchangeRates
|
||||
}
|
||||
$return[] = $entry;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $amount
|
||||
* @param TransactionCurrency $from
|
||||
* @param TransactionCurrency $to
|
||||
* @param Carbon|null $date
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
private function getPreference(): void
|
||||
{
|
||||
$this->enabled = config('cer.currency_conversion');
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
private function getCurrency(int $currencyId): TransactionCurrency
|
||||
{
|
||||
$result = TransactionCurrency::find($currencyId);
|
||||
if (null === $result) {
|
||||
return app('amount')->getDefaultCurrency();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
private function convertAmount(string $amount, TransactionCurrency $from, TransactionCurrency $to, ?Carbon $date = null): string
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
|
||||
/*
|
||||
* ExchangeRateConverter.php
|
||||
* Copyright (c) 2023 james@firefly-iii.org
|
||||
@@ -36,43 +35,29 @@ use FireflyIII\Support\CacheProperties;
|
||||
*/
|
||||
class ExchangeRateConverter
|
||||
{
|
||||
//use ConvertsExchangeRates;
|
||||
// use ConvertsExchangeRates;
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $from
|
||||
* @param TransactionCurrency $to
|
||||
* @param Carbon $date
|
||||
* @param string $amount
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function convert(TransactionCurrency $from, TransactionCurrency $to, Carbon $date, string $amount): string
|
||||
{
|
||||
$rate = $this->getCurrencyRate($from, $to, $date);
|
||||
|
||||
return bcmul($amount, $rate);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $from
|
||||
* @param TransactionCurrency $to
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function getCurrencyRate(TransactionCurrency $from, TransactionCurrency $to, Carbon $date): string
|
||||
{
|
||||
$rate = $this->getRate($from, $to, $date);
|
||||
|
||||
return '0' === $rate ? '1' : $rate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $from
|
||||
* @param TransactionCurrency $to
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function getRate(TransactionCurrency $from, TransactionCurrency $to, Carbon $date): string
|
||||
@@ -98,16 +83,10 @@ class ExchangeRateConverter
|
||||
}
|
||||
|
||||
$second = bcdiv('1', $second);
|
||||
|
||||
return bcmul($first, $second);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $from
|
||||
* @param int $to
|
||||
* @param string $date
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
private function getFromDB(int $from, int $to, string $date): ?string
|
||||
{
|
||||
$key = sprintf('cer-%d-%d-%s', $from, $to, $date);
|
||||
@@ -119,34 +98,31 @@ class ExchangeRateConverter
|
||||
if ('' === $rate) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $rate;
|
||||
}
|
||||
app('log')->debug(sprintf('Going to get rate #%d->#%d (%s) from DB.', $from, $to, $date));
|
||||
|
||||
/** @var CurrencyExchangeRate|null $result */
|
||||
/** @var null|CurrencyExchangeRate $result */
|
||||
$result = auth()->user()
|
||||
->currencyExchangeRates()
|
||||
->where('from_currency_id', $from)
|
||||
->where('to_currency_id', $to)
|
||||
->where('date', '<=', $date)
|
||||
->orderBy('date', 'DESC')
|
||||
->first();
|
||||
->currencyExchangeRates()
|
||||
->where('from_currency_id', $from)
|
||||
->where('to_currency_id', $to)
|
||||
->where('date', '<=', $date)
|
||||
->orderBy('date', 'DESC')
|
||||
->first()
|
||||
;
|
||||
$rate = (string)$result?->rate;
|
||||
$cache->store($rate);
|
||||
if ('' === $rate) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $rate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*
|
||||
*/
|
||||
private function getEuroRate(TransactionCurrency $currency, Carbon $date): string
|
||||
{
|
||||
@@ -164,23 +140,21 @@ class ExchangeRateConverter
|
||||
if (null !== $rate) {
|
||||
return bcdiv('1', $rate);
|
||||
// app('log')->debug(sprintf('Inverted rate for %s to EUR is %s.', $currency->code, $rate));
|
||||
//return $rate;
|
||||
// return $rate;
|
||||
}
|
||||
// grab backup values from config file:
|
||||
$backup = config(sprintf('cer.rates.%s', $currency->code));
|
||||
if (null !== $backup) {
|
||||
return bcdiv('1', (string)$backup);
|
||||
// app('log')->debug(sprintf('Backup rate for %s to EUR is %s.', $currency->code, $backup));
|
||||
//return $backup;
|
||||
// return $backup;
|
||||
}
|
||||
|
||||
// app('log')->debug(sprintf('No rate for %s to EUR.', $currency->code));
|
||||
return '0';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function getEuroId(): int
|
||||
@@ -195,6 +169,7 @@ class ExchangeRateConverter
|
||||
throw new FireflyException('Cannot find EUR in system, cannot do currency conversion.');
|
||||
}
|
||||
$cache->store($euro->id);
|
||||
|
||||
return $euro->id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,15 +25,14 @@ namespace FireflyIII\Support\Http\Api;
|
||||
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\UserGroups\Currency\CurrencyRepositoryInterface;
|
||||
use Log;
|
||||
|
||||
class SummaryBalanceGrouped
|
||||
{
|
||||
private const string SUM = 'sum';
|
||||
private TransactionCurrency $default;
|
||||
private array $amounts = [];
|
||||
private array $keys;
|
||||
private array $currencies;
|
||||
private const string SUM = 'sum';
|
||||
private CurrencyRepositoryInterface $currencyRepository;
|
||||
|
||||
public function __construct()
|
||||
@@ -45,14 +44,10 @@ class SummaryBalanceGrouped
|
||||
|
||||
/**
|
||||
* TODO remember to do -1 for deposits.
|
||||
*
|
||||
* @param array $journals
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function groupTransactions(string $key, array $journals): void
|
||||
{
|
||||
Log::debug(sprintf('Now in groupTransactions with key "%s" and %d journal(s)', $key, count($journals)));
|
||||
\Log::debug(sprintf('Now in groupTransactions with key "%s" and %d journal(s)', $key, count($journals)));
|
||||
$converter = new ExchangeRateConverter();
|
||||
$this->keys[] = $key;
|
||||
$multiplier = 'income' === $key ? '-1' : '1';
|
||||
@@ -81,18 +76,14 @@ class SummaryBalanceGrouped
|
||||
$this->amounts[self::SUM][$currencyId] = bcadd($this->amounts[self::SUM][$currencyId], $amount);
|
||||
$this->amounts[$key]['native'] = bcadd($this->amounts[$key]['native'], $nativeAmount);
|
||||
$this->amounts[self::SUM]['native'] = bcadd($this->amounts[self::SUM]['native'], $nativeAmount);
|
||||
|
||||
}
|
||||
app('log')->debug(sprintf('this->amounts[%s][native] is now %s', $key, $this->amounts[$key]['native']));
|
||||
app('log')->debug(sprintf('this->amounts[%s][native] is now %s', self::SUM, $this->amounts[$key]['native']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function groupData(): array
|
||||
{
|
||||
Log::debug('Now going to group data.');
|
||||
\Log::debug('Now going to group data.');
|
||||
$return = [];
|
||||
foreach ($this->keys as $key) {
|
||||
$title = match ($key) {
|
||||
@@ -138,6 +129,7 @@ class SummaryBalanceGrouped
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
@@ -145,6 +137,4 @@ class SummaryBalanceGrouped
|
||||
{
|
||||
$this->default = $default;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -27,17 +27,11 @@ use FireflyIII\Models\TransactionType;
|
||||
|
||||
/**
|
||||
* Trait TransactionFilter
|
||||
*
|
||||
|
||||
*/
|
||||
trait TransactionFilter
|
||||
{
|
||||
/**
|
||||
* All the types you can request.
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function mapTransactionTypes(string $type): array
|
||||
{
|
||||
@@ -49,27 +43,28 @@ trait TransactionFilter
|
||||
TransactionType::OPENING_BALANCE,
|
||||
TransactionType::RECONCILIATION,
|
||||
],
|
||||
'withdrawal' => [TransactionType::WITHDRAWAL,],
|
||||
'withdrawals' => [TransactionType::WITHDRAWAL,],
|
||||
'expense' => [TransactionType::WITHDRAWAL,],
|
||||
'expenses' => [TransactionType::WITHDRAWAL,],
|
||||
'income' => [TransactionType::DEPOSIT,],
|
||||
'deposit' => [TransactionType::DEPOSIT,],
|
||||
'deposits' => [TransactionType::DEPOSIT,],
|
||||
'transfer' => [TransactionType::TRANSFER,],
|
||||
'transfers' => [TransactionType::TRANSFER,],
|
||||
'opening_balance' => [TransactionType::OPENING_BALANCE,],
|
||||
'reconciliation' => [TransactionType::RECONCILIATION,],
|
||||
'reconciliations' => [TransactionType::RECONCILIATION,],
|
||||
'special' => [TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,],
|
||||
'specials' => [TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,],
|
||||
'default' => [TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER,],
|
||||
'withdrawal' => [TransactionType::WITHDRAWAL],
|
||||
'withdrawals' => [TransactionType::WITHDRAWAL],
|
||||
'expense' => [TransactionType::WITHDRAWAL],
|
||||
'expenses' => [TransactionType::WITHDRAWAL],
|
||||
'income' => [TransactionType::DEPOSIT],
|
||||
'deposit' => [TransactionType::DEPOSIT],
|
||||
'deposits' => [TransactionType::DEPOSIT],
|
||||
'transfer' => [TransactionType::TRANSFER],
|
||||
'transfers' => [TransactionType::TRANSFER],
|
||||
'opening_balance' => [TransactionType::OPENING_BALANCE],
|
||||
'reconciliation' => [TransactionType::RECONCILIATION],
|
||||
'reconciliations' => [TransactionType::RECONCILIATION],
|
||||
'special' => [TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION],
|
||||
'specials' => [TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION],
|
||||
'default' => [TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER],
|
||||
];
|
||||
$return = [];
|
||||
$parts = explode(',', $type);
|
||||
foreach ($parts as $part) {
|
||||
$return = array_merge($return, $types[$part] ?? $types['default']);
|
||||
}
|
||||
|
||||
return array_unique($return);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,32 +37,35 @@ trait ValidatesUserGroupTrait
|
||||
/**
|
||||
* This check does not validate which rights the user has, that comes later.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return UserGroup|null
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function validateUserGroup(Request $request): ?UserGroup
|
||||
{
|
||||
if (!auth()->check()) {
|
||||
app('log')->debug('validateUserGroup: user is not logged in, return NULL.');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
if (!$request->has('user_group_id')) {
|
||||
$group = $user->userGroup;
|
||||
app('log')->debug(sprintf('validateUserGroup: no user group submitted, return default group #%d.', $group?->id));
|
||||
|
||||
return $group;
|
||||
}
|
||||
$groupId = (int)$request->get('user_group_id');
|
||||
/** @var GroupMembership|null $membership */
|
||||
|
||||
/** @var null|GroupMembership $membership */
|
||||
$membership = $user->groupMemberships()->where('user_group_id', $groupId)->first();
|
||||
if (null === $membership) {
|
||||
app('log')->debug('validateUserGroup: user has no access to this group.');
|
||||
|
||||
throw new FireflyException((string)trans('validation.belongs_user_or_user_group'));
|
||||
}
|
||||
app('log')->debug(sprintf('validateUserGroup: user has role "%s" in group #%d.', $membership->userRole->title, $membership->userGroup->id));
|
||||
|
||||
return $membership->userGroup;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,22 +40,18 @@ use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Trait AugumentData
|
||||
*
|
||||
*/
|
||||
trait AugumentData
|
||||
{
|
||||
/**
|
||||
* Searches for the opposing account.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function combineAccounts(Collection $accounts): array // filter + group data
|
||||
{
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$combined = [];
|
||||
|
||||
/** @var Account $expenseAccount */
|
||||
foreach ($accounts as $expenseAccount) {
|
||||
$collection = new Collection();
|
||||
@@ -73,10 +69,6 @@ trait AugumentData
|
||||
|
||||
/**
|
||||
* Small helper function for the revenue and expense account charts.
|
||||
*
|
||||
* @param array $names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function expandNames(array $names): array
|
||||
{
|
||||
@@ -90,14 +82,11 @@ trait AugumentData
|
||||
|
||||
/**
|
||||
* Small helper function for the revenue and expense account charts.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function extractNames(Collection $accounts): array
|
||||
{
|
||||
$return = [];
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
$return[$account->id] = $account->name;
|
||||
@@ -108,10 +97,6 @@ trait AugumentData
|
||||
|
||||
/**
|
||||
* Get the account names belonging to a bunch of account ID's.
|
||||
*
|
||||
* @param array $accountIds
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getAccountNames(array $accountIds): array // extract info from array.
|
||||
{
|
||||
@@ -134,10 +119,6 @@ trait AugumentData
|
||||
|
||||
/**
|
||||
* Get the budget names from a set of budget ID's.
|
||||
*
|
||||
* @param array $budgetIds
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getBudgetNames(array $budgetIds): array // extract info from array.
|
||||
{
|
||||
@@ -158,10 +139,6 @@ trait AugumentData
|
||||
|
||||
/**
|
||||
* Get the category names from a set of category ID's. Small helper function for some of the charts.
|
||||
*
|
||||
* @param array $categoryIds
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getCategoryNames(array $categoryIds): array // extract info from array.
|
||||
{
|
||||
@@ -184,12 +161,6 @@ trait AugumentData
|
||||
|
||||
/**
|
||||
* Gets all budget limits for a budget.
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
protected function getLimits(Budget $budget, Carbon $start, Carbon $end): Collection // get data + augment with info
|
||||
{
|
||||
@@ -243,15 +214,12 @@ trait AugumentData
|
||||
|
||||
/**
|
||||
* Group set of transactions by name of opposing account.
|
||||
*
|
||||
* @param array $array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function groupByName(array $array): array // filter + group data
|
||||
{
|
||||
// group by opposing account name.
|
||||
$grouped = [];
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($array as $journal) {
|
||||
$name = '(no name)';
|
||||
@@ -271,13 +239,6 @@ trait AugumentData
|
||||
|
||||
/**
|
||||
* Spent in a period.
|
||||
*
|
||||
* @param Collection $assets
|
||||
* @param Collection $opposing
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function spentInPeriod(Collection $assets, Collection $opposing, Carbon $start, Carbon $end): array // get data + augment with info
|
||||
{
|
||||
|
||||
@@ -27,16 +27,12 @@ use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Trait BasicDataSupport
|
||||
*
|
||||
*/
|
||||
trait BasicDataSupport
|
||||
{
|
||||
/**
|
||||
* Find the ID in a given array. Return '0' if not there (amount).
|
||||
*
|
||||
* @param array $array
|
||||
* @param int $entryId
|
||||
*
|
||||
* @return null|mixed
|
||||
*/
|
||||
protected function isInArray(array $array, int $entryId)
|
||||
@@ -46,11 +42,6 @@ trait BasicDataSupport
|
||||
|
||||
/**
|
||||
* Find the ID in a given array. Return null if not there (amount).
|
||||
*
|
||||
* @param array $array
|
||||
* @param int $entryId
|
||||
*
|
||||
* @return null|Carbon
|
||||
*/
|
||||
protected function isInArrayDate(array $array, int $entryId): ?Carbon
|
||||
{
|
||||
|
||||
@@ -30,7 +30,6 @@ use FireflyIII\Models\Account;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Support\Collection;
|
||||
use JsonException;
|
||||
|
||||
/**
|
||||
* Trait ChartGeneration
|
||||
@@ -40,13 +39,8 @@ trait ChartGeneration
|
||||
/**
|
||||
* Shows an overview of the account balances for a set of accounts.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
* @throws JsonException
|
||||
* @throws \JsonException
|
||||
*/
|
||||
protected function accountBalanceChart(Collection $accounts, Carbon $start, Carbon $end): array // chart helper method.
|
||||
{
|
||||
@@ -61,6 +55,7 @@ trait ChartGeneration
|
||||
}
|
||||
app('log')->debug('Regenerate chart.account.account-balance-chart from scratch.');
|
||||
$locale = app('steam')->getLocale();
|
||||
|
||||
/** @var GeneratorInterface $generator */
|
||||
$generator = app(GeneratorInterface::class);
|
||||
|
||||
@@ -69,6 +64,7 @@ trait ChartGeneration
|
||||
|
||||
$default = app('amount')->getDefaultCurrency();
|
||||
$chartData = [];
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
// TODO we can use getAccountCurrency instead.
|
||||
|
||||
@@ -34,17 +34,11 @@ use phpseclib3\Crypt\RSA;
|
||||
|
||||
/**
|
||||
* Trait CreateStuff
|
||||
*
|
||||
*/
|
||||
trait CreateStuff
|
||||
{
|
||||
/**
|
||||
* Creates an asset account.
|
||||
*
|
||||
* @param NewUserFormRequest $request
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function createAssetAccount(NewUserFormRequest $request, TransactionCurrency $currency): bool // create stuff
|
||||
{
|
||||
@@ -70,11 +64,6 @@ trait CreateStuff
|
||||
|
||||
/**
|
||||
* Creates a cash wallet.
|
||||
*
|
||||
* @param TransactionCurrency $currency
|
||||
* @param string $language
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function createCashWalletAccount(TransactionCurrency $currency, string $language): bool // create stuff
|
||||
{
|
||||
@@ -122,12 +111,6 @@ trait CreateStuff
|
||||
|
||||
/**
|
||||
* Create a savings account.
|
||||
*
|
||||
* @param NewUserFormRequest $request
|
||||
* @param TransactionCurrency $currency
|
||||
* @param string $language
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function createSavingsAccount(NewUserFormRequest $request, TransactionCurrency $currency, string $language): bool // create stuff
|
||||
{
|
||||
@@ -152,10 +135,6 @@ trait CreateStuff
|
||||
|
||||
/**
|
||||
* Create a new user instance after a valid registration.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
protected function createUser(array $data): User // create object
|
||||
{
|
||||
|
||||
@@ -38,10 +38,6 @@ use Psr\Container\NotFoundExceptionInterface;
|
||||
trait CronRunner
|
||||
{
|
||||
/**
|
||||
* @param bool $force
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -51,6 +47,7 @@ trait CronRunner
|
||||
$billWarning = app(BillWarningCronjob::class);
|
||||
$billWarning->setForce($force);
|
||||
$billWarning->setDate($date);
|
||||
|
||||
try {
|
||||
$billWarning->fire();
|
||||
} catch (FireflyException $e) {
|
||||
@@ -70,18 +67,13 @@ trait CronRunner
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $force
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function exchangeRatesCronJob(bool $force, Carbon $date): array
|
||||
{
|
||||
/** @var ExchangeRatesCronjob $exchangeRates */
|
||||
$exchangeRates = app(ExchangeRatesCronjob::class);
|
||||
$exchangeRates->setForce($force);
|
||||
$exchangeRates->setDate($date);
|
||||
|
||||
try {
|
||||
$exchangeRates->fire();
|
||||
} catch (FireflyException $e) {
|
||||
@@ -101,18 +93,13 @@ trait CronRunner
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $force
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function runAutoBudget(bool $force, Carbon $date): array
|
||||
{
|
||||
/** @var AutoBudgetCronjob $autoBudget */
|
||||
$autoBudget = app(AutoBudgetCronjob::class);
|
||||
$autoBudget->setForce($force);
|
||||
$autoBudget->setDate($date);
|
||||
|
||||
try {
|
||||
$autoBudget->fire();
|
||||
} catch (FireflyException $e) {
|
||||
@@ -133,10 +120,6 @@ trait CronRunner
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $force
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -146,6 +129,7 @@ trait CronRunner
|
||||
$recurring = app(RecurringCronjob::class);
|
||||
$recurring->setForce($force);
|
||||
$recurring->setDate($date);
|
||||
|
||||
try {
|
||||
$recurring->fire();
|
||||
} catch (FireflyException $e) {
|
||||
|
||||
@@ -27,7 +27,6 @@ use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Trait DateCalculation
|
||||
*
|
||||
*/
|
||||
trait DateCalculation
|
||||
{
|
||||
@@ -37,11 +36,6 @@ trait DateCalculation
|
||||
*
|
||||
* If both are in the past OR both are in the future, simply return the number of days in the period with a minimum
|
||||
* of 1
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function activeDaysLeft(Carbon $start, Carbon $end): int
|
||||
{
|
||||
@@ -59,11 +53,6 @@ trait DateCalculation
|
||||
* Calculate the number of days passed between two dates. Will take the current moment into consideration.
|
||||
*
|
||||
* If both are in the past OR both are in the future, simply return the period between them with a minimum of 1
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function activeDaysPassed(Carbon $start, Carbon $end): int
|
||||
{
|
||||
@@ -77,12 +66,6 @@ trait DateCalculation
|
||||
return $difference;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function calculateStep(Carbon $start, Carbon $end): string
|
||||
{
|
||||
$step = '1D';
|
||||
@@ -103,16 +86,12 @@ trait DateCalculation
|
||||
/**
|
||||
* Get a list of the periods that will occur after this date. For example,
|
||||
* March 2018, April 2018, etc.
|
||||
*
|
||||
* @param Carbon $date
|
||||
* @param string $range
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getNextPeriods(Carbon $date, string $range): array
|
||||
{
|
||||
// select thing for next 12 periods:
|
||||
$loop = [];
|
||||
|
||||
/** @var Carbon $current */
|
||||
$current = app('navigation')->startOfPeriod($date, $range);
|
||||
$current = app('navigation')->endOfPeriod($current, $range);
|
||||
@@ -139,16 +118,12 @@ trait DateCalculation
|
||||
/**
|
||||
* Get a list of the periods that occurred before the start date. For example,
|
||||
* March 2018, February 2018, etc.
|
||||
*
|
||||
* @param Carbon $date
|
||||
* @param string $range
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getPreviousPeriods(Carbon $date, string $range): array
|
||||
{
|
||||
// select thing for last 12 periods:
|
||||
$loop = [];
|
||||
|
||||
/** @var Carbon $current */
|
||||
$current = app('navigation')->startOfPeriod($date, $range);
|
||||
$count = 0;
|
||||
|
||||
@@ -30,16 +30,11 @@ use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
/**
|
||||
* Trait GetConfigurationData
|
||||
*
|
||||
*/
|
||||
trait GetConfigurationData
|
||||
{
|
||||
/**
|
||||
* Some common combinations.
|
||||
*
|
||||
* @param int $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function errorReporting(int $value): string // get configuration
|
||||
{
|
||||
@@ -58,10 +53,6 @@ trait GetConfigurationData
|
||||
|
||||
/**
|
||||
* Get the basic steps from config.
|
||||
*
|
||||
* @param string $route
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getBasicSteps(string $route): array // get config values
|
||||
{
|
||||
@@ -73,7 +64,7 @@ trait GetConfigurationData
|
||||
$currentStep = $options;
|
||||
|
||||
// get the text:
|
||||
$currentStep['intro'] = (string)trans('intro.' . $route . '_' . $key);
|
||||
$currentStep['intro'] = (string)trans('intro.'.$route.'_'.$key);
|
||||
|
||||
// save in array:
|
||||
$steps[] = $currentStep;
|
||||
@@ -87,7 +78,6 @@ trait GetConfigurationData
|
||||
/**
|
||||
* Get config for date range.
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
@@ -95,10 +85,13 @@ trait GetConfigurationData
|
||||
protected function getDateRangeConfig(): array // get configuration + get preferences.
|
||||
{
|
||||
$viewRange = app('navigation')->getViewRange(false);
|
||||
|
||||
/** @var Carbon $start */
|
||||
$start = session('start');
|
||||
|
||||
/** @var Carbon $end */
|
||||
$end = session('end');
|
||||
|
||||
/** @var Carbon $first */
|
||||
$first = session('first');
|
||||
$title = sprintf('%s - %s', $start->isoFormat($this->monthAndDayFormat), $end->isoFormat($this->monthAndDayFormat));
|
||||
@@ -134,6 +127,7 @@ trait GetConfigurationData
|
||||
// today:
|
||||
/** @var Carbon $todayStart */
|
||||
$todayStart = app('navigation')->startOfPeriod($today, $viewRange);
|
||||
|
||||
/** @var Carbon $todayEnd */
|
||||
$todayEnd = app('navigation')->endOfPeriod($todayStart, $viewRange);
|
||||
if ($todayStart->ne($start) || $todayEnd->ne($end)) {
|
||||
@@ -181,12 +175,6 @@ trait GetConfigurationData
|
||||
|
||||
/**
|
||||
* Get specific info for special routes.
|
||||
*
|
||||
* @param string $route
|
||||
* @param string $specificPage
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
protected function getSpecificSteps(string $route, string $specificPage): array // get config values
|
||||
{
|
||||
@@ -196,13 +184,13 @@ trait GetConfigurationData
|
||||
// user is on page with specific instructions:
|
||||
if ('' !== $specificPage) {
|
||||
$routeKey = str_replace('.', '_', $route);
|
||||
$elements = config(sprintf('intro.%s', $routeKey . '_' . $specificPage));
|
||||
$elements = config(sprintf('intro.%s', $routeKey.'_'.$specificPage));
|
||||
if (is_array($elements) && count($elements) > 0) {
|
||||
foreach ($elements as $key => $options) {
|
||||
$currentStep = $options;
|
||||
|
||||
// get the text:
|
||||
$currentStep['intro'] = (string)trans('intro.' . $route . '_' . $specificPage . '_' . $key);
|
||||
$currentStep['intro'] = (string)trans('intro.'.$route.'_'.$specificPage.'_'.$key);
|
||||
|
||||
// save in array:
|
||||
$steps[] = $currentStep;
|
||||
@@ -214,9 +202,6 @@ trait GetConfigurationData
|
||||
return $steps;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function verifyRecurringCronJob(): void
|
||||
{
|
||||
$config = app('fireflyconfig')->get('last_rt_job', 0);
|
||||
|
||||
@@ -30,20 +30,15 @@ use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Trait ModelInformation
|
||||
*
|
||||
*/
|
||||
trait ModelInformation
|
||||
{
|
||||
/**
|
||||
* Get actions based on a bill.
|
||||
*
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function getActionsForBill(Bill $bill): array // get info and augument
|
||||
@@ -58,10 +53,11 @@ trait ModelInformation
|
||||
'count' => 1,
|
||||
]
|
||||
)->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->error(sprintf('Throwable was thrown in getActionsForBill(): %s', $e->getMessage()));
|
||||
app('log')->error($e->getTraceAsString());
|
||||
$result = 'Could not render view. See log files.';
|
||||
|
||||
throw new FireflyException($result, 0, $e);
|
||||
}
|
||||
|
||||
@@ -69,7 +65,6 @@ trait ModelInformation
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string[]
|
||||
*
|
||||
* @psalm-return array<int|null, string>
|
||||
@@ -78,11 +73,14 @@ trait ModelInformation
|
||||
{
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
|
||||
// types of liability:
|
||||
/** @var AccountType $debt */
|
||||
$debt = $repository->getAccountTypeByType(AccountType::DEBT);
|
||||
|
||||
/** @var AccountType $loan */
|
||||
$loan = $repository->getAccountTypeByType(AccountType::LOAN);
|
||||
|
||||
/** @var AccountType $mortgage */
|
||||
$mortgage = $repository->getAccountTypeByType(AccountType::MORTGAGE);
|
||||
$liabilityTypes = [
|
||||
@@ -95,9 +93,6 @@ trait ModelInformation
|
||||
return $liabilityTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getRoles(): array
|
||||
{
|
||||
$roles = [];
|
||||
@@ -111,9 +106,6 @@ trait ModelInformation
|
||||
/**
|
||||
* Create fake triggers to match the bill's properties
|
||||
*
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function getTriggersForBill(Bill $bill): array // get info and augument
|
||||
@@ -148,9 +140,10 @@ trait ModelInformation
|
||||
'triggers' => $triggers,
|
||||
]
|
||||
)->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->debug(sprintf('Throwable was thrown in getTriggersForBill(): %s', $e->getMessage()));
|
||||
app('log')->debug($e->getTraceAsString());
|
||||
|
||||
throw new FireflyException(sprintf('Could not render trigger: %s', $e->getMessage()), 0, $e);
|
||||
}
|
||||
if ('' !== $string) {
|
||||
@@ -162,9 +155,6 @@ trait ModelInformation
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function getTriggersForJournal(TransactionJournal $journal): array
|
||||
@@ -183,11 +173,13 @@ trait ModelInformation
|
||||
$journalTriggers = [];
|
||||
$values = [];
|
||||
$index = 0;
|
||||
|
||||
// amount, description, category, budget, tags, source, destination, notes, currency type
|
||||
//,type
|
||||
/** @var Transaction|null $source */
|
||||
// ,type
|
||||
/** @var null|Transaction $source */
|
||||
$source = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
/** @var Transaction|null $destination */
|
||||
|
||||
/** @var null|Transaction $destination */
|
||||
$destination = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
if (null === $destination || null === $source) {
|
||||
return $result;
|
||||
@@ -195,54 +187,55 @@ trait ModelInformation
|
||||
// type
|
||||
$journalTriggers[$index] = 'transaction_type';
|
||||
$values[$index] = $journal->transactionType->type;
|
||||
$index++;
|
||||
++$index;
|
||||
|
||||
// currency
|
||||
$journalTriggers[$index] = 'currency_is';
|
||||
$values[$index] = sprintf('%s (%s)', $journal->transactionCurrency?->name, $journal->transactionCurrency?->code);
|
||||
$index++;
|
||||
++$index;
|
||||
|
||||
// amount_exactly:
|
||||
$journalTriggers[$index] = 'amount_exactly';
|
||||
$values[$index] = $destination->amount;
|
||||
$index++;
|
||||
++$index;
|
||||
|
||||
// description_is:
|
||||
$journalTriggers[$index] = 'description_is';
|
||||
$values[$index] = $journal->description;
|
||||
$index++;
|
||||
++$index;
|
||||
|
||||
// from_account_is
|
||||
$journalTriggers[$index] = 'source_account_is';
|
||||
$values[$index] = $source->account->name;
|
||||
$index++;
|
||||
++$index;
|
||||
|
||||
// to_account_is
|
||||
$journalTriggers[$index] = 'destination_account_is';
|
||||
$values[$index] = $destination->account->name;
|
||||
$index++;
|
||||
++$index;
|
||||
|
||||
// category (if)
|
||||
$category = $journal->categories()->first();
|
||||
if (null !== $category) {
|
||||
$journalTriggers[$index] = 'category_is';
|
||||
$values[$index] = $category->name;
|
||||
$index++;
|
||||
++$index;
|
||||
}
|
||||
// budget (if)
|
||||
$budget = $journal->budgets()->first();
|
||||
if (null !== $budget) {
|
||||
$journalTriggers[$index] = 'budget_is';
|
||||
$values[$index] = $budget->name;
|
||||
$index++;
|
||||
++$index;
|
||||
}
|
||||
// tags (if)
|
||||
$tags = $journal->tags()->get();
|
||||
|
||||
/** @var Tag $tag */
|
||||
foreach ($tags as $tag) {
|
||||
$journalTriggers[$index] = 'tag_is';
|
||||
$values[$index] = $tag->tag;
|
||||
$index++;
|
||||
++$index;
|
||||
}
|
||||
// notes (if)
|
||||
$notes = $journal->notes()->first();
|
||||
@@ -261,15 +254,17 @@ trait ModelInformation
|
||||
'triggers' => $triggers,
|
||||
];
|
||||
$string = view('rules.partials.trigger', $renderInfo)->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->debug(sprintf('Throwable was thrown in getTriggersForJournal(): %s', $e->getMessage()));
|
||||
app('log')->debug($e->getTraceAsString());
|
||||
|
||||
throw new FireflyException(sprintf('Could not render trigger: %s', $e->getMessage()), 0, $e);
|
||||
}
|
||||
if ('' !== $string) {
|
||||
$result[] = $string;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,6 @@ use Psr\Container\NotFoundExceptionInterface;
|
||||
* amount: -1234 (str)
|
||||
* count: 23
|
||||
* ]
|
||||
*
|
||||
*/
|
||||
trait PeriodOverview
|
||||
{
|
||||
@@ -73,11 +72,6 @@ trait PeriodOverview
|
||||
* and for each period, the amount of money spent and earned. This is a complex operation which is cached for
|
||||
* performance reasons.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
@@ -96,6 +90,7 @@ trait PeriodOverview
|
||||
if ($cache->has()) {
|
||||
return $cache->get();
|
||||
}
|
||||
|
||||
/** @var array $dates */
|
||||
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
||||
$entries = [];
|
||||
@@ -133,140 +128,24 @@ trait PeriodOverview
|
||||
$transferredIn = $this->filterTransferredIn($account, $this->filterJournalsByDate($transferSet, $currentDate['start'], $currentDate['end']));
|
||||
$entries[]
|
||||
= [
|
||||
'title' => $title,
|
||||
'route' =>
|
||||
route('accounts.show', [$account->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
|
||||
'title' => $title,
|
||||
'route' => route('accounts.show', [$account->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
|
||||
|
||||
'total_transactions' => count($spent) + count($earned) + count($transferredAway) + count($transferredIn),
|
||||
'spent' => $this->groupByCurrency($spent),
|
||||
'earned' => $this->groupByCurrency($earned),
|
||||
'transferred_away' => $this->groupByCurrency($transferredAway),
|
||||
'transferred_in' => $this->groupByCurrency($transferredIn),
|
||||
];
|
||||
'total_transactions' => count($spent) + count($earned) + count($transferredAway) + count($transferredIn),
|
||||
'spent' => $this->groupByCurrency($spent),
|
||||
'earned' => $this->groupByCurrency($earned),
|
||||
'transferred_away' => $this->groupByCurrency($transferredAway),
|
||||
'transferred_in' => $this->groupByCurrency($transferredIn),
|
||||
];
|
||||
}
|
||||
$cache->store($entries);
|
||||
|
||||
return $entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter a list of journals by a set of dates, and then group them by currency.
|
||||
*
|
||||
* @param array $array
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function filterJournalsByDate(array $array, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$result = [];
|
||||
/** @var array $journal */
|
||||
foreach ($array as $journal) {
|
||||
if ($journal['date'] <= $end && $journal['date'] >= $start) {
|
||||
$result[] = $journal;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return only transactions where $account is the source.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param array $journals
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function filterTransferredAway(Account $account, array $journals): array
|
||||
{
|
||||
$return = [];
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
if ($account->id === (int)$journal['source_account_id']) {
|
||||
$return[] = $journal;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return only transactions where $account is the source.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param array $journals
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function filterTransferredIn(Account $account, array $journals): array
|
||||
{
|
||||
$return = [];
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
if ($account->id === (int)$journal['destination_account_id']) {
|
||||
$return[] = $journal;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $journals
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function groupByCurrency(array $journals): array
|
||||
{
|
||||
$return = [];
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$foreignCurrencyId = $journal['foreign_currency_id'];
|
||||
if (!array_key_exists($currencyId, $return)) {
|
||||
$return[$currencyId] = [
|
||||
'amount' => '0',
|
||||
'count' => 0,
|
||||
'currency_id' => $currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
'currency_code' => $journal['currency_code'],
|
||||
'currency_symbol' => $journal['currency_symbol'],
|
||||
'currency_decimal_places' => $journal['currency_decimal_places'],
|
||||
];
|
||||
}
|
||||
$return[$currencyId]['amount'] = bcadd($return[$currencyId]['amount'], $journal['amount'] ?? '0');
|
||||
$return[$currencyId]['count']++;
|
||||
|
||||
if (null !== $foreignCurrencyId && null !== $journal['foreign_amount']) {
|
||||
if (!array_key_exists($foreignCurrencyId, $return)) {
|
||||
$return[$foreignCurrencyId] = [
|
||||
'amount' => '0',
|
||||
'count' => 0,
|
||||
'currency_id' => (int)$foreignCurrencyId,
|
||||
'currency_name' => $journal['foreign_currency_name'],
|
||||
'currency_code' => $journal['foreign_currency_code'],
|
||||
'currency_symbol' => $journal['foreign_currency_symbol'],
|
||||
'currency_decimal_places' => $journal['foreign_currency_decimal_places'],
|
||||
];
|
||||
}
|
||||
$return[$foreignCurrencyId]['count']++;
|
||||
$return[$foreignCurrencyId]['amount'] = bcadd($return[$foreignCurrencyId]['amount'], $journal['foreign_amount']);
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overview for single category. Has been refactored recently.
|
||||
*
|
||||
* @param Category $category
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
@@ -287,6 +166,7 @@ trait PeriodOverview
|
||||
if ($cache->has()) {
|
||||
return $cache->get();
|
||||
}
|
||||
|
||||
/** @var array $dates */
|
||||
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
||||
$entries = [];
|
||||
@@ -321,17 +201,17 @@ trait PeriodOverview
|
||||
$title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);
|
||||
$entries[]
|
||||
= [
|
||||
'transactions' => 0,
|
||||
'title' => $title,
|
||||
'route' => route(
|
||||
'categories.show',
|
||||
[$category->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]
|
||||
),
|
||||
'total_transactions' => count($spent) + count($earned) + count($transferred),
|
||||
'spent' => $this->groupByCurrency($spent),
|
||||
'earned' => $this->groupByCurrency($earned),
|
||||
'transferred' => $this->groupByCurrency($transferred),
|
||||
];
|
||||
'transactions' => 0,
|
||||
'title' => $title,
|
||||
'route' => route(
|
||||
'categories.show',
|
||||
[$category->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]
|
||||
),
|
||||
'total_transactions' => count($spent) + count($earned) + count($transferred),
|
||||
'spent' => $this->groupByCurrency($spent),
|
||||
'earned' => $this->groupByCurrency($earned),
|
||||
'transferred' => $this->groupByCurrency($transferred),
|
||||
];
|
||||
}
|
||||
$cache->store($entries);
|
||||
|
||||
@@ -343,10 +223,6 @@ trait PeriodOverview
|
||||
*
|
||||
* This method has been refactored recently.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
@@ -369,6 +245,7 @@ trait PeriodOverview
|
||||
/** @var array $dates */
|
||||
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
||||
$entries = [];
|
||||
|
||||
// get all expenses without a budget.
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
@@ -380,14 +257,14 @@ trait PeriodOverview
|
||||
$title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);
|
||||
$entries[]
|
||||
= [
|
||||
'title' => $title,
|
||||
'route' => route('budgets.no-budget', [$currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
|
||||
'total_transactions' => count($set),
|
||||
'spent' => $this->groupByCurrency($set),
|
||||
'earned' => [],
|
||||
'transferred_away' => [],
|
||||
'transferred_in' => [],
|
||||
];
|
||||
'title' => $title,
|
||||
'route' => route('budgets.no-budget', [$currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
|
||||
'total_transactions' => count($set),
|
||||
'spent' => $this->groupByCurrency($set),
|
||||
'earned' => [],
|
||||
'transferred_away' => [],
|
||||
'transferred_in' => [],
|
||||
];
|
||||
}
|
||||
$cache->store($entries);
|
||||
|
||||
@@ -399,9 +276,6 @@ trait PeriodOverview
|
||||
*
|
||||
* Show period overview for no category view.
|
||||
*
|
||||
* @param Carbon $theDate
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
@@ -453,13 +327,13 @@ trait PeriodOverview
|
||||
$title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);
|
||||
$entries[]
|
||||
= [
|
||||
'title' => $title,
|
||||
'route' => route('categories.no-category', [$currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
|
||||
'total_transactions' => count($spent) + count($earned) + count($transferred),
|
||||
'spent' => $this->groupByCurrency($spent),
|
||||
'earned' => $this->groupByCurrency($earned),
|
||||
'transferred' => $this->groupByCurrency($transferred),
|
||||
];
|
||||
'title' => $title,
|
||||
'route' => route('categories.no-category', [$currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
|
||||
'total_transactions' => count($spent) + count($earned) + count($transferred),
|
||||
'spent' => $this->groupByCurrency($spent),
|
||||
'earned' => $this->groupByCurrency($earned),
|
||||
'transferred' => $this->groupByCurrency($transferred),
|
||||
];
|
||||
}
|
||||
app('log')->debug('End of loops');
|
||||
|
||||
@@ -469,11 +343,6 @@ trait PeriodOverview
|
||||
/**
|
||||
* This shows a period overview for a tag. It goes back in time and lists all relevant transactions and sums.
|
||||
*
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
@@ -492,6 +361,7 @@ trait PeriodOverview
|
||||
if ($cache->has()) {
|
||||
return $cache->get();
|
||||
}
|
||||
|
||||
/** @var array $dates */
|
||||
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
||||
$entries = [];
|
||||
@@ -527,28 +397,23 @@ trait PeriodOverview
|
||||
$title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);
|
||||
$entries[]
|
||||
= [
|
||||
'transactions' => 0,
|
||||
'title' => $title,
|
||||
'route' => route(
|
||||
'tags.show',
|
||||
[$tag->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]
|
||||
),
|
||||
'total_transactions' => count($spent) + count($earned) + count($transferred),
|
||||
'spent' => $this->groupByCurrency($spent),
|
||||
'earned' => $this->groupByCurrency($earned),
|
||||
'transferred' => $this->groupByCurrency($transferred),
|
||||
];
|
||||
'transactions' => 0,
|
||||
'title' => $title,
|
||||
'route' => route(
|
||||
'tags.show',
|
||||
[$tag->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]
|
||||
),
|
||||
'total_transactions' => count($spent) + count($earned) + count($transferred),
|
||||
'spent' => $this->groupByCurrency($spent),
|
||||
'earned' => $this->groupByCurrency($earned),
|
||||
'transferred' => $this->groupByCurrency($transferred),
|
||||
];
|
||||
}
|
||||
|
||||
return $entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $transactionType
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
@@ -568,6 +433,7 @@ trait PeriodOverview
|
||||
if ($cache->has()) {
|
||||
return $cache->get();
|
||||
}
|
||||
|
||||
/** @var array $dates */
|
||||
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
||||
$entries = [];
|
||||
@@ -595,16 +461,108 @@ trait PeriodOverview
|
||||
}
|
||||
$entries[]
|
||||
= [
|
||||
'title' => $title,
|
||||
'route' =>
|
||||
route('transactions.index', [$transactionType, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
|
||||
'total_transactions' => count($spent) + count($earned) + count($transferred),
|
||||
'spent' => $this->groupByCurrency($spent),
|
||||
'earned' => $this->groupByCurrency($earned),
|
||||
'transferred' => $this->groupByCurrency($transferred),
|
||||
];
|
||||
'title' => $title,
|
||||
'route' => route('transactions.index', [$transactionType, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
|
||||
'total_transactions' => count($spent) + count($earned) + count($transferred),
|
||||
'spent' => $this->groupByCurrency($spent),
|
||||
'earned' => $this->groupByCurrency($earned),
|
||||
'transferred' => $this->groupByCurrency($transferred),
|
||||
];
|
||||
}
|
||||
|
||||
return $entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter a list of journals by a set of dates, and then group them by currency.
|
||||
*/
|
||||
private function filterJournalsByDate(array $array, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$result = [];
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($array as $journal) {
|
||||
if ($journal['date'] <= $end && $journal['date'] >= $start) {
|
||||
$result[] = $journal;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return only transactions where $account is the source.
|
||||
*/
|
||||
private function filterTransferredAway(Account $account, array $journals): array
|
||||
{
|
||||
$return = [];
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
if ($account->id === (int)$journal['source_account_id']) {
|
||||
$return[] = $journal;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return only transactions where $account is the source.
|
||||
*/
|
||||
private function filterTransferredIn(Account $account, array $journals): array
|
||||
{
|
||||
$return = [];
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
if ($account->id === (int)$journal['destination_account_id']) {
|
||||
$return[] = $journal;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
private function groupByCurrency(array $journals): array
|
||||
{
|
||||
$return = [];
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$foreignCurrencyId = $journal['foreign_currency_id'];
|
||||
if (!array_key_exists($currencyId, $return)) {
|
||||
$return[$currencyId] = [
|
||||
'amount' => '0',
|
||||
'count' => 0,
|
||||
'currency_id' => $currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
'currency_code' => $journal['currency_code'],
|
||||
'currency_symbol' => $journal['currency_symbol'],
|
||||
'currency_decimal_places' => $journal['currency_decimal_places'],
|
||||
];
|
||||
}
|
||||
$return[$currencyId]['amount'] = bcadd($return[$currencyId]['amount'], $journal['amount'] ?? '0');
|
||||
++$return[$currencyId]['count'];
|
||||
|
||||
if (null !== $foreignCurrencyId && null !== $journal['foreign_amount']) {
|
||||
if (!array_key_exists($foreignCurrencyId, $return)) {
|
||||
$return[$foreignCurrencyId] = [
|
||||
'amount' => '0',
|
||||
'count' => 0,
|
||||
'currency_id' => (int)$foreignCurrencyId,
|
||||
'currency_name' => $journal['foreign_currency_name'],
|
||||
'currency_code' => $journal['foreign_currency_code'],
|
||||
'currency_symbol' => $journal['foreign_currency_symbol'],
|
||||
'currency_decimal_places' => $journal['foreign_currency_decimal_places'],
|
||||
];
|
||||
}
|
||||
++$return[$foreignCurrencyId]['count'];
|
||||
$return[$foreignCurrencyId]['amount'] = bcadd($return[$foreignCurrencyId]['amount'], $journal['foreign_amount']);
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,20 +36,15 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||
use FireflyIII\Support\Search\OperatorQuerySearch;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Trait RenderPartialViews
|
||||
*
|
||||
*/
|
||||
trait RenderPartialViews
|
||||
{
|
||||
/**
|
||||
* View for transactions in a budget for an account.
|
||||
*
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function budgetEntry(array $attributes): string // generate view for report.
|
||||
@@ -72,9 +67,10 @@ trait RenderPartialViews
|
||||
|
||||
try {
|
||||
$view = view('popup.report.balance-amount', compact('journals', 'budget', 'account'))->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->error(sprintf('Could not render: %s', $e->getMessage()));
|
||||
$view = 'Firefly III could not render the view. Please see the log files.';
|
||||
|
||||
throw new FireflyException($view, 0, $e);
|
||||
}
|
||||
|
||||
@@ -84,7 +80,6 @@ trait RenderPartialViews
|
||||
/**
|
||||
* Get options for budget report.
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function budgetReportOptions(): string // render a view
|
||||
@@ -95,9 +90,10 @@ trait RenderPartialViews
|
||||
|
||||
try {
|
||||
$result = view('reports.options.budget', compact('budgets'))->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->error(sprintf('Cannot render reports.options.tag: %s', $e->getMessage()));
|
||||
$result = 'Could not render view.';
|
||||
|
||||
throw new FireflyException($result, 0, $e);
|
||||
}
|
||||
|
||||
@@ -107,9 +103,6 @@ trait RenderPartialViews
|
||||
/**
|
||||
* View for spent in a single budget.
|
||||
*
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function budgetSpentAmount(array $attributes): string // generate view for report.
|
||||
@@ -128,9 +121,10 @@ trait RenderPartialViews
|
||||
|
||||
try {
|
||||
$view = view('popup.report.budget-spent-amount', compact('journals', 'budget'))->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->error(sprintf('Could not render: %s', $e->getMessage()));
|
||||
$view = 'Firefly III could not render the view. Please see the log files.';
|
||||
|
||||
throw new FireflyException($view, 0, $e);
|
||||
}
|
||||
|
||||
@@ -140,9 +134,6 @@ trait RenderPartialViews
|
||||
/**
|
||||
* View for transactions in a category.
|
||||
*
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function categoryEntry(array $attributes): string // generate view for report.
|
||||
@@ -157,9 +148,10 @@ trait RenderPartialViews
|
||||
|
||||
try {
|
||||
$view = view('popup.report.category-entry', compact('journals', 'category'))->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->error(sprintf('Could not render: %s', $e->getMessage()));
|
||||
$view = 'Firefly III could not render the view. Please see the log files.';
|
||||
|
||||
throw new FireflyException($view, 0, $e);
|
||||
}
|
||||
|
||||
@@ -169,7 +161,6 @@ trait RenderPartialViews
|
||||
/**
|
||||
* Get options for category report.
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function categoryReportOptions(): string // render a view
|
||||
@@ -180,9 +171,10 @@ trait RenderPartialViews
|
||||
|
||||
try {
|
||||
$result = view('reports.options.category', compact('categories'))->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->error(sprintf('Cannot render reports.options.category: %s', $e->getMessage()));
|
||||
$result = 'Could not render view.';
|
||||
|
||||
throw new FireflyException($result, 0, $e);
|
||||
}
|
||||
|
||||
@@ -192,7 +184,6 @@ trait RenderPartialViews
|
||||
/**
|
||||
* Get options for double report.
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function doubleReportOptions(): string // render a view
|
||||
@@ -220,12 +211,12 @@ trait RenderPartialViews
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$result = view('reports.options.double', compact('set'))->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->error(sprintf('Cannot render reports.options.tag: %s', $e->getMessage()));
|
||||
$result = 'Could not render view.';
|
||||
|
||||
throw new FireflyException($result, 0, $e);
|
||||
}
|
||||
|
||||
@@ -235,9 +226,6 @@ trait RenderPartialViews
|
||||
/**
|
||||
* Returns all the expenses that went to the given expense account.
|
||||
*
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function expenseEntry(array $attributes): string // generate view for report.
|
||||
@@ -258,9 +246,10 @@ trait RenderPartialViews
|
||||
|
||||
try {
|
||||
$view = view('popup.report.expense-entry', compact('journals', 'account'))->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->error(sprintf('Could not render: %s', $e->getMessage()));
|
||||
$view = 'Firefly III could not render the view. Please see the log files.';
|
||||
|
||||
throw new FireflyException($view, 0, $e);
|
||||
}
|
||||
|
||||
@@ -270,9 +259,6 @@ trait RenderPartialViews
|
||||
/**
|
||||
* Get current (from system) rule actions.
|
||||
*
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function getCurrentActions(Rule $rule): array // get info from object and present.
|
||||
@@ -281,9 +267,11 @@ trait RenderPartialViews
|
||||
$actions = [];
|
||||
// must be repos
|
||||
$currentActions = $rule->ruleActions()->orderBy('order', 'ASC')->get();
|
||||
|
||||
/** @var RuleAction $entry */
|
||||
foreach ($currentActions as $entry) {
|
||||
$count = ($index + 1);
|
||||
|
||||
try {
|
||||
$actions[] = view(
|
||||
'rules.partials.action',
|
||||
@@ -294,9 +282,10 @@ trait RenderPartialViews
|
||||
'count' => $count,
|
||||
]
|
||||
)->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->debug(sprintf('Throwable was thrown in getCurrentActions(): %s', $e->getMessage()));
|
||||
app('log')->error($e->getTraceAsString());
|
||||
|
||||
throw new FireflyException(sprintf('Could not render: %s', $e->getMessage()), 0, $e);
|
||||
}
|
||||
|
||||
@@ -309,9 +298,6 @@ trait RenderPartialViews
|
||||
/**
|
||||
* Get current (from DB) rule triggers.
|
||||
*
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function getCurrentTriggers(Rule $rule): array // get info from object and present.
|
||||
@@ -329,10 +315,12 @@ trait RenderPartialViews
|
||||
$renderedEntries = [];
|
||||
// must be repos
|
||||
$currentTriggers = $rule->ruleTriggers()->orderBy('order', 'ASC')->get();
|
||||
|
||||
/** @var RuleTrigger $entry */
|
||||
foreach ($currentTriggers as $entry) {
|
||||
if ('user_action' !== $entry->trigger_type) {
|
||||
$count = ($index + 1);
|
||||
|
||||
try {
|
||||
$rootOperator = OperatorQuerySearch::getRootOperator((string)$entry->trigger_type);
|
||||
if (str_starts_with($rootOperator, '-')) {
|
||||
@@ -349,9 +337,10 @@ trait RenderPartialViews
|
||||
'triggers' => $triggers,
|
||||
]
|
||||
)->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->debug(sprintf('Throwable was thrown in getCurrentTriggers(): %s', $e->getMessage()));
|
||||
app('log')->error($e->getTraceAsString());
|
||||
|
||||
throw new FireflyException(sprintf('Could not render: %s', $e->getMessage()), 0, $e);
|
||||
}
|
||||
|
||||
@@ -365,9 +354,6 @@ trait RenderPartialViews
|
||||
/**
|
||||
* Returns all the incomes that went to the given asset account.
|
||||
*
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function incomeEntry(array $attributes): string // generate view for report.
|
||||
@@ -387,9 +373,10 @@ trait RenderPartialViews
|
||||
|
||||
try {
|
||||
$view = view('popup.report.income-entry', compact('journals', 'account'))->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->error(sprintf('Could not render: %s', $e->getMessage()));
|
||||
$view = 'Firefly III could not render the view. Please see the log files.';
|
||||
|
||||
throw new FireflyException($view, 0, $e);
|
||||
}
|
||||
|
||||
@@ -399,16 +386,16 @@ trait RenderPartialViews
|
||||
/**
|
||||
* Get options for default report.
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function noReportOptions(): string // render a view
|
||||
{
|
||||
try {
|
||||
$result = view('reports.options.no-options')->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->error(sprintf('Cannot render reports.options.no-options: %s', $e->getMessage()));
|
||||
$result = 'Could not render view.';
|
||||
|
||||
throw new FireflyException($result, 0, $e);
|
||||
}
|
||||
|
||||
@@ -418,7 +405,6 @@ trait RenderPartialViews
|
||||
/**
|
||||
* Get options for tag report.
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function tagReportOptions(): string // render a view
|
||||
@@ -427,12 +413,12 @@ trait RenderPartialViews
|
||||
$repository = app(TagRepositoryInterface::class);
|
||||
$tags = $repository->get();
|
||||
|
||||
|
||||
try {
|
||||
$result = view('reports.options.tag', compact('tags'))->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->error(sprintf('Cannot render reports.options.tag: %s', $e->getMessage()));
|
||||
$result = 'Could not render view.';
|
||||
|
||||
throw new FireflyException($result, 0, $e);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,12 +25,10 @@ namespace FireflyIII\Support\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\ValidationException;
|
||||
use FireflyIII\Helpers\Help\HelpInterface;
|
||||
use FireflyIII\Http\Requests\RuleFormRequest;
|
||||
use FireflyIII\Http\Requests\TestRuleFormRequest;
|
||||
use FireflyIII\Support\Binder\AccountList;
|
||||
use FireflyIII\User;
|
||||
use Hash;
|
||||
use Illuminate\Contracts\Validation\Validator as ValidatorContract;
|
||||
use Illuminate\Routing\Route;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
@@ -40,14 +38,11 @@ use Route as RouteFacade;
|
||||
|
||||
/**
|
||||
* Trait RequestInformation
|
||||
*
|
||||
*/
|
||||
trait RequestInformation
|
||||
{
|
||||
/**
|
||||
* Get the domain of FF system.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
final protected function getDomain(): string // get request info
|
||||
{
|
||||
@@ -59,10 +54,6 @@ trait RequestInformation
|
||||
|
||||
/**
|
||||
* Get a list of triggers.
|
||||
*
|
||||
* @param TestRuleFormRequest $request
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
final protected function getValidTriggerList(TestRuleFormRequest $request): array // process input
|
||||
{
|
||||
@@ -80,13 +71,13 @@ trait RequestInformation
|
||||
$triggers[] = $current;
|
||||
}
|
||||
}
|
||||
|
||||
return $triggers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if user has seen demo.
|
||||
*
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -113,9 +104,6 @@ trait RequestInformation
|
||||
return $shownDemo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
final protected function getPageName(): string // get request info
|
||||
{
|
||||
return str_replace('.', '_', RouteFacade::currentRouteName());
|
||||
@@ -123,28 +111,23 @@ trait RequestInformation
|
||||
|
||||
/**
|
||||
* Get the specific name of a page for intro.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
final protected function getSpecificPageName(): string // get request info
|
||||
{
|
||||
/** @var string|null $param */
|
||||
/** @var null|string $param */
|
||||
$param = RouteFacade::current()->parameter('objectType');
|
||||
|
||||
return null === $param ? '' : sprintf('_%s', $param);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if date is outside session range.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
*/
|
||||
final protected function notInSessionRange(Carbon $date): bool // Validate a preference
|
||||
{
|
||||
/** @var Carbon $start */
|
||||
$start = session('start', today(config('app.timezone'))->startOfMonth());
|
||||
|
||||
/** @var Carbon $end */
|
||||
$end = session('end', today(config('app.timezone'))->endOfMonth());
|
||||
$result = false;
|
||||
@@ -161,10 +144,6 @@ trait RequestInformation
|
||||
|
||||
/**
|
||||
* Parses attributes from URL
|
||||
*
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
final protected function parseAttributes(array $attributes): array // parse input + return result
|
||||
{
|
||||
@@ -184,24 +163,17 @@ trait RequestInformation
|
||||
$date2->endOfDay();
|
||||
$attributes['endDate'] = $date2;
|
||||
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate users new password.
|
||||
*
|
||||
* @param User $user
|
||||
* @param string $current
|
||||
* @param string $new
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
final protected function validatePassword(User $user, string $current, string $new): bool //get request info
|
||||
final protected function validatePassword(User $user, string $current, string $new): bool // get request info
|
||||
{
|
||||
if (!Hash::check($current, $user->password)) {
|
||||
if (!\Hash::check($current, $user->password)) {
|
||||
throw new ValidationException((string)trans('firefly.invalid_current_password'));
|
||||
}
|
||||
|
||||
@@ -214,10 +186,6 @@ trait RequestInformation
|
||||
|
||||
/**
|
||||
* Get a validator for an incoming registration request.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return ValidatorContract
|
||||
*/
|
||||
final protected function validator(array $data): ValidatorContract
|
||||
{
|
||||
|
||||
@@ -27,18 +27,13 @@ use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
||||
use FireflyIII\Support\Search\OperatorQuerySearch;
|
||||
use Illuminate\Http\Request;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Trait RuleManagement
|
||||
*
|
||||
*/
|
||||
trait RuleManagement
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function getPreviousActions(Request $request): array
|
||||
@@ -58,12 +53,13 @@ trait RuleManagement
|
||||
'count' => $index + 1,
|
||||
]
|
||||
)->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->error(sprintf('Throwable was thrown in getPreviousActions(): %s', $e->getMessage()));
|
||||
app('log')->error($e->getTraceAsString());
|
||||
|
||||
throw new FireflyException(sprintf('Could not render: %s', $e->getMessage()), 0, $e);
|
||||
}
|
||||
$index++;
|
||||
++$index;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,9 +67,6 @@ trait RuleManagement
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function getPreviousTriggers(Request $request): array
|
||||
@@ -105,12 +98,13 @@ trait RuleManagement
|
||||
'triggers' => $triggers,
|
||||
]
|
||||
)->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->debug(sprintf('Throwable was thrown in getPreviousTriggers(): %s', $e->getMessage()));
|
||||
app('log')->error($e->getTraceAsString());
|
||||
|
||||
throw new FireflyException(sprintf('Could not render: %s', $e->getMessage()), 0, $e);
|
||||
}
|
||||
$index++;
|
||||
++$index;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,9 +112,6 @@ trait RuleManagement
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $submittedOperators
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function parseFromOperators(array $submittedOperators): array
|
||||
@@ -140,6 +131,7 @@ trait RuleManagement
|
||||
foreach ($submittedOperators as $operator) {
|
||||
$rootOperator = OperatorQuerySearch::getRootOperator($operator['type']);
|
||||
$needsContext = (bool)config(sprintf('search.operators.%s.needs_context', $rootOperator));
|
||||
|
||||
try {
|
||||
$renderedEntries[] = view(
|
||||
'rules.partials.trigger',
|
||||
@@ -152,20 +144,18 @@ trait RuleManagement
|
||||
'triggers' => $triggers,
|
||||
]
|
||||
)->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->debug(sprintf('Throwable was thrown in getPreviousTriggers(): %s', $e->getMessage()));
|
||||
app('log')->error($e->getTraceAsString());
|
||||
|
||||
throw new FireflyException(sprintf('Could not render: %s', $e->getMessage()), 0, $e);
|
||||
}
|
||||
$index++;
|
||||
++$index;
|
||||
}
|
||||
|
||||
return $renderedEntries;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function createDefaultRuleGroup(): void
|
||||
{
|
||||
/** @var RuleGroupRepositoryInterface $repository */
|
||||
|
||||
@@ -30,19 +30,11 @@ use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Trait TransactionCalculation
|
||||
*
|
||||
*/
|
||||
trait TransactionCalculation
|
||||
{
|
||||
/**
|
||||
* Get all expenses for a set of accounts.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Collection $opposing
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getExpensesForOpposing(Collection $accounts, Collection $opposing, Carbon $start, Carbon $end): array
|
||||
{
|
||||
@@ -51,23 +43,16 @@ trait TransactionCalculation
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setAccounts($total)
|
||||
->setRange($start, $end)
|
||||
->withAccountInformation()
|
||||
->setTypes([TransactionType::WITHDRAWAL]);
|
||||
->setRange($start, $end)
|
||||
->withAccountInformation()
|
||||
->setTypes([TransactionType::WITHDRAWAL])
|
||||
;
|
||||
|
||||
return $collector->getExtractedJournals();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all expenses by tags.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Collection $tags
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
protected function getExpensesForTags(Collection $accounts, Collection $tags, Carbon $start, Carbon $end): array
|
||||
{
|
||||
@@ -75,40 +60,28 @@ trait TransactionCalculation
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
||||
->setTags($tags)->withAccountInformation();
|
||||
->setTags($tags)->withAccountInformation()
|
||||
;
|
||||
|
||||
return $collector->getExtractedJournals();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function that collects expenses for the given budgets.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Collection $budgets
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getExpensesInBudgets(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end): array
|
||||
{
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
||||
->setBudgets($budgets)->withAccountInformation();
|
||||
->setBudgets($budgets)->withAccountInformation()
|
||||
;
|
||||
|
||||
return $collector->getExtractedJournals();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all expenses in a period for categories.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Collection $categories
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getExpensesInCategories(Collection $accounts, Collection $categories, Carbon $start, Carbon $end): array
|
||||
{
|
||||
@@ -119,44 +92,33 @@ trait TransactionCalculation
|
||||
->setRange($start, $end)
|
||||
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
||||
->setCategories($categories)
|
||||
->withAccountInformation();
|
||||
->withAccountInformation()
|
||||
;
|
||||
|
||||
return $collector->getExtractedJournals();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all income for a period and a bunch of categories.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Collection $categories
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getIncomeForCategories(Collection $accounts, Collection $categories, Carbon $start, Carbon $end): array
|
||||
{
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
|
||||
->setCategories($categories)->withAccountInformation();
|
||||
->setCategories($categories)->withAccountInformation()
|
||||
;
|
||||
|
||||
return $collector->getExtractedJournals();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the income for a set of accounts.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Collection $opposing
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getIncomeForOpposing(Collection $accounts, Collection $opposing, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$total = $accounts->merge($opposing);
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setAccounts($total)->setRange($start, $end)->withAccountInformation()->setTypes([TransactionType::DEPOSIT]);
|
||||
@@ -166,20 +128,14 @@ trait TransactionCalculation
|
||||
|
||||
/**
|
||||
* Get all income by tag.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Collection $tags
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getIncomeForTags(Collection $accounts, Collection $tags, Carbon $start, Carbon $end): array
|
||||
{
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
|
||||
->setTags($tags)->withAccountInformation();
|
||||
->setTags($tags)->withAccountInformation()
|
||||
;
|
||||
|
||||
return $collector->getExtractedJournals();
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ use Illuminate\Routing\Redirector;
|
||||
|
||||
/**
|
||||
* Trait UserNavigation
|
||||
*
|
||||
*/
|
||||
trait UserNavigation
|
||||
{
|
||||
@@ -45,10 +44,6 @@ trait UserNavigation
|
||||
* returned but instead the index (/) will be returned.
|
||||
* - If the remembered url contains "jscript/" the remembered url will not be returned but instead the index (/)
|
||||
* will be returned.
|
||||
*
|
||||
* @param string $identifier
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
final protected function getPreviousUrl(string $identifier): string
|
||||
{
|
||||
@@ -61,10 +56,6 @@ trait UserNavigation
|
||||
|
||||
/**
|
||||
* Will return false if you cant edit this account type.
|
||||
*
|
||||
* @param Account $account
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
final protected function isEditableAccount(Account $account): bool
|
||||
{
|
||||
@@ -74,14 +65,9 @@ trait UserNavigation
|
||||
return in_array($type, $editable, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionGroup $group
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
final protected function isEditableGroup(TransactionGroup $group): bool
|
||||
{
|
||||
/** @var TransactionJournal|null $journal */
|
||||
/** @var null|TransactionJournal $journal */
|
||||
$journal = $group->transactionJournals()->first();
|
||||
if (null === $journal) {
|
||||
return false;
|
||||
@@ -93,9 +79,7 @@ trait UserNavigation
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return RedirectResponse|Redirector
|
||||
* @return Redirector|RedirectResponse
|
||||
*/
|
||||
final protected function redirectAccountToAccount(Account $account)
|
||||
{
|
||||
@@ -103,7 +87,7 @@ trait UserNavigation
|
||||
if (AccountType::RECONCILIATION === $type || AccountType::INITIAL_BALANCE === $type || AccountType::LIABILITY_CREDIT === $type) {
|
||||
// reconciliation must be stored somewhere in this account's transactions.
|
||||
|
||||
/** @var Transaction|null $transaction */
|
||||
/** @var null|Transaction $transaction */
|
||||
$transaction = $account->transactions()->first();
|
||||
if (null === $transaction) {
|
||||
app('log')->error(sprintf('Account #%d has no transactions. Dont know where it belongs.', $account->id));
|
||||
@@ -112,7 +96,8 @@ trait UserNavigation
|
||||
return redirect(route('index'));
|
||||
}
|
||||
$journal = $transaction->transactionJournal;
|
||||
/** @var Transaction|null $other */
|
||||
|
||||
/** @var null|Transaction $other */
|
||||
$other = $journal->transactions()->where('id', '!=', $transaction->id)->first();
|
||||
if (null === $other) {
|
||||
app('log')->error(sprintf('Account #%d has no valid journals. Dont know where it belongs.', $account->id));
|
||||
@@ -128,13 +113,11 @@ trait UserNavigation
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionGroup $group
|
||||
*
|
||||
* @return RedirectResponse|Redirector
|
||||
* @return Redirector|RedirectResponse
|
||||
*/
|
||||
final protected function redirectGroupToAccount(TransactionGroup $group)
|
||||
{
|
||||
/** @var TransactionJournal|null $journal */
|
||||
/** @var null|TransactionJournal $journal */
|
||||
$journal = $group->transactionJournals()->first();
|
||||
if (null === $journal) {
|
||||
app('log')->error(sprintf('No journals in group #%d', $group->id));
|
||||
@@ -144,6 +127,7 @@ trait UserNavigation
|
||||
// prefer redirect to everything but expense and revenue:
|
||||
$transactions = $journal->transactions;
|
||||
$ignore = [AccountType::REVENUE, AccountType::EXPENSE, AccountType::RECONCILIATION, AccountType::INITIAL_BALANCE];
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$type = $transaction->account->accountType->type;
|
||||
@@ -155,11 +139,6 @@ trait UserNavigation
|
||||
return redirect(route('index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $identifier
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
final protected function rememberPreviousUrl(string $identifier): ?string
|
||||
{
|
||||
$return = app('steam')->getSafePreviousUrl();
|
||||
|
||||
Reference in New Issue
Block a user