mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Various code cleanup and fixed alignments.
This commit is contained in:
@@ -78,7 +78,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
|
||||
public function findByName(string $name, array $types): ?Account
|
||||
{
|
||||
$query = $this->userGroup->accounts();
|
||||
$query = $this->userGroup->accounts();
|
||||
|
||||
if (0 !== count($types)) {
|
||||
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
|
||||
@@ -102,8 +102,8 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
|
||||
public function getAccountCurrency(Account $account): ?TransactionCurrency
|
||||
{
|
||||
$type = $account->accountType->type;
|
||||
$list = config('firefly.valid_currency_account_types');
|
||||
$type = $account->accountType->type;
|
||||
$list = config('firefly.valid_currency_account_types');
|
||||
|
||||
// return null if not in this list.
|
||||
if (!in_array($type, $list, true)) {
|
||||
|
@@ -81,18 +81,18 @@ class BillRepository implements BillRepositoryInterface
|
||||
$currencyId = $bill->transaction_currency_id;
|
||||
|
||||
$return[$currencyId] ??= [
|
||||
'currency_id' => (string)$currency->id,
|
||||
'currency_name' => $currency->name,
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_code' => $currency->code,
|
||||
'currency_decimal_places' => $currency->decimal_places,
|
||||
'currency_id' => (string)$currency->id,
|
||||
'currency_name' => $currency->name,
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_code' => $currency->code,
|
||||
'currency_decimal_places' => $currency->decimal_places,
|
||||
'native_currency_id' => (string)$default->id,
|
||||
'native_currency_name' => $default->name,
|
||||
'native_currency_symbol' => $default->symbol,
|
||||
'native_currency_code' => $default->code,
|
||||
'native_currency_decimal_places' => $default->decimal_places,
|
||||
'sum' => '0',
|
||||
'native_sum' => '0',
|
||||
'sum' => '0',
|
||||
'native_sum' => '0',
|
||||
];
|
||||
|
||||
/** @var TransactionJournal $transactionJournal */
|
||||
@@ -100,13 +100,13 @@ class BillRepository implements BillRepositoryInterface
|
||||
/** @var null|Transaction $sourceTransaction */
|
||||
$sourceTransaction = $transactionJournal->transactions()->where('amount', '<', 0)->first();
|
||||
if (null !== $sourceTransaction) {
|
||||
$amount = $sourceTransaction->amount;
|
||||
$amount = $sourceTransaction->amount;
|
||||
if ((int)$sourceTransaction->foreign_currency_id === $currency->id) {
|
||||
// use foreign amount instead!
|
||||
$amount = (string)$sourceTransaction->foreign_amount;
|
||||
}
|
||||
// convert to native currency
|
||||
$nativeAmount = $amount;
|
||||
$nativeAmount = $amount;
|
||||
if ($currencyId !== $default->id) {
|
||||
// get rate and convert.
|
||||
$nativeAmount = $converter->convert($currency, $default, $transactionJournal->date, $amount);
|
||||
@@ -153,19 +153,19 @@ class BillRepository implements BillRepositoryInterface
|
||||
$currencyId = $bill->transaction_currency_id;
|
||||
$average = bcdiv(bcadd($bill->amount_max, $bill->amount_min), '2');
|
||||
$nativeAverage = $converter->convert($currency, $default, $start, $average);
|
||||
$return[$currencyId] ??= [
|
||||
'currency_id' => (string)$currency->id,
|
||||
'currency_name' => $currency->name,
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_code' => $currency->code,
|
||||
'currency_decimal_places' => $currency->decimal_places,
|
||||
$return[$currencyId] ??= [
|
||||
'currency_id' => (string)$currency->id,
|
||||
'currency_name' => $currency->name,
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_code' => $currency->code,
|
||||
'currency_decimal_places' => $currency->decimal_places,
|
||||
'native_currency_id' => (string)$default->id,
|
||||
'native_currency_name' => $default->name,
|
||||
'native_currency_symbol' => $default->symbol,
|
||||
'native_currency_code' => $default->code,
|
||||
'native_currency_decimal_places' => $default->decimal_places,
|
||||
'sum' => '0',
|
||||
'native_sum' => '0',
|
||||
'sum' => '0',
|
||||
'native_sum' => '0',
|
||||
];
|
||||
$return[$currencyId]['sum'] = bcadd($return[$currencyId]['sum'], bcmul($average, (string)$total));
|
||||
$return[$currencyId]['native_sum'] = bcadd($return[$currencyId]['native_sum'], bcmul($nativeAverage, (string)$total));
|
||||
@@ -200,7 +200,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
|
||||
// app('log')->debug(sprintf('Currentstart (%s) has become %s.', $currentStart->format('Y-m-d'), $nextExpectedMatch->format('Y-m-d')));
|
||||
|
||||
$currentStart = clone $nextExpectedMatch;
|
||||
$currentStart = clone $nextExpectedMatch;
|
||||
}
|
||||
|
||||
return $set;
|
||||
|
@@ -51,7 +51,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
||||
/** @var AvailableBudget $availableBudget */
|
||||
foreach ($availableBudgets as $availableBudget) {
|
||||
$currencyId = $availableBudget->transaction_currency_id;
|
||||
$return[$currencyId] ??= [
|
||||
$return[$currencyId] ??= [
|
||||
'currency_id' => $currencyId,
|
||||
'currency_code' => $availableBudget->transactionCurrency->code,
|
||||
'currency_symbol' => $availableBudget->transactionCurrency->symbol,
|
||||
|
@@ -56,13 +56,13 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$collector->setBudgets($this->getBudgets());
|
||||
}
|
||||
$collector->withBudgetInformation()->withAccountInformation()->withCategoryInformation();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$budgetId = (int)$journal['budget_id'];
|
||||
$budgetName = (string)$journal['budget_name'];
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$budgetId = (int)$journal['budget_id'];
|
||||
$budgetName = (string)$journal['budget_name'];
|
||||
|
||||
// catch "no budget" entries.
|
||||
if (0 === $budgetId) {
|
||||
@@ -70,7 +70,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
}
|
||||
|
||||
// info about the currency:
|
||||
$array[$currencyId] ??= [
|
||||
$array[$currencyId] ??= [
|
||||
'budgets' => [],
|
||||
'currency_id' => $currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
@@ -88,8 +88,8 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
|
||||
// add journal to array:
|
||||
// only a subset of the fields.
|
||||
$journalId = (int)$journal['transaction_journal_id'];
|
||||
$final = [
|
||||
$journalId = (int)$journal['transaction_journal_id'];
|
||||
$final = [
|
||||
'amount' => app('steam')->negative($journal['amount']),
|
||||
'currency_id' => $journal['currency_id'],
|
||||
'foreign_amount' => null,
|
||||
|
@@ -62,7 +62,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
public function currencyInUseAt(TransactionCurrency $currency): ?string
|
||||
{
|
||||
app('log')->debug(sprintf('Now in currencyInUse() for #%d ("%s")', $currency->id, $currency->code));
|
||||
$countJournals = $this->countJournals($currency);
|
||||
$countJournals = $this->countJournals($currency);
|
||||
if ($countJournals > 0) {
|
||||
app('log')->info(sprintf('Count journals is %d, return true.', $countJournals));
|
||||
|
||||
@@ -77,7 +77,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
}
|
||||
|
||||
// is being used in accounts:
|
||||
$meta = AccountMeta::where('name', 'currency_id')->where('data', json_encode((string)$currency->id))->count();
|
||||
$meta = AccountMeta::where('name', 'currency_id')->where('data', json_encode((string)$currency->id))->count();
|
||||
if ($meta > 0) {
|
||||
app('log')->info(sprintf('Used in %d accounts as currency_id, return true. ', $meta));
|
||||
|
||||
@@ -85,7 +85,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
}
|
||||
|
||||
// is being used in bills:
|
||||
$bills = Bill::where('transaction_currency_id', $currency->id)->count();
|
||||
$bills = Bill::where('transaction_currency_id', $currency->id)->count();
|
||||
if ($bills > 0) {
|
||||
app('log')->info(sprintf('Used in %d bills as currency, return true. ', $bills));
|
||||
|
||||
@@ -103,7 +103,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
}
|
||||
|
||||
// is being used in accounts (as integer)
|
||||
$meta = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id')
|
||||
$meta = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id')
|
||||
->whereNull('accounts.deleted_at')
|
||||
->where('account_meta.name', 'currency_id')->where('account_meta.data', json_encode($currency->id))->count()
|
||||
;
|
||||
@@ -122,7 +122,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
}
|
||||
|
||||
// is being used in budget limits
|
||||
$budgetLimit = BudgetLimit::where('transaction_currency_id', $currency->id)->count();
|
||||
$budgetLimit = BudgetLimit::where('transaction_currency_id', $currency->id)->count();
|
||||
if ($budgetLimit > 0) {
|
||||
app('log')->info(sprintf('Used in %d budget limits as currency, return true. ', $budgetLimit));
|
||||
|
||||
@@ -130,7 +130,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
}
|
||||
|
||||
// is the default currency for the user or the system
|
||||
$count = $this->userGroup->currencies()->where('transaction_currencies.id', $currency->id)->wherePivot('group_default', 1)->count();
|
||||
$count = $this->userGroup->currencies()->where('transaction_currencies.id', $currency->id)->wherePivot('group_default', 1)->count();
|
||||
if ($count > 0) {
|
||||
app('log')->info('Is the default currency of the user, return true.');
|
||||
|
||||
@@ -138,7 +138,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
}
|
||||
|
||||
// is the default currency for the user or the system
|
||||
$count = $this->userGroup->currencies()->where('transaction_currencies.id', $currency->id)->wherePivot('group_default', 1)->count();
|
||||
$count = $this->userGroup->currencies()->where('transaction_currencies.id', $currency->id)->wherePivot('group_default', 1)->count();
|
||||
if ($count > 0) {
|
||||
app('log')->info('Is the default currency of the user group, return true.');
|
||||
|
||||
@@ -159,10 +159,10 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
$local = $this->get();
|
||||
|
||||
return $all->map(static function (TransactionCurrency $current) use ($local) {
|
||||
$hasId = $local->contains(static function (TransactionCurrency $entry) use ($current) {
|
||||
$hasId = $local->contains(static function (TransactionCurrency $entry) use ($current) {
|
||||
return $entry->id === $current->id;
|
||||
});
|
||||
$isDefault = $local->contains(static function (TransactionCurrency $entry) use ($current) {
|
||||
$isDefault = $local->contains(static function (TransactionCurrency $entry) use ($current) {
|
||||
return 1 === (int)$entry->pivot->group_default && $entry->id === $current->id;
|
||||
});
|
||||
$current->userGroupEnabled = $hasId;
|
||||
|
Reference in New Issue
Block a user