mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-07 06:31:22 +00:00
Various code cleanup.
This commit is contained in:
@@ -81,7 +81,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
/** @var Collection $set */
|
||||
$set = $bill->transactionJournals()->after($start)->before($end)->get(['transaction_journals.*']);
|
||||
$currency = $bill->transactionCurrency;
|
||||
$currencyId = (int)$bill->transaction_currency_id;
|
||||
$currencyId = $bill->transaction_currency_id;
|
||||
|
||||
$return[$currencyId] = $return[$currencyId] ?? [
|
||||
'currency_id' => (string)$currency->id,
|
||||
@@ -103,18 +103,18 @@ class BillRepository implements BillRepositoryInterface
|
||||
/** @var Transaction|null $sourceTransaction */
|
||||
$sourceTransaction = $transactionJournal->transactions()->where('amount', '<', 0)->first();
|
||||
if (null !== $sourceTransaction) {
|
||||
$amount = (string)$sourceTransaction->amount;
|
||||
if ((int)$sourceTransaction->foreign_currency_id === (int)$currency->id) {
|
||||
$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;
|
||||
if ($currencyId !== (int)$default->id) {
|
||||
if ($currencyId !== $default->id) {
|
||||
// get rate and convert.
|
||||
$nativeAmount = $converter->convert($currency, $default, $transactionJournal->date, $amount);
|
||||
}
|
||||
if ((int)$sourceTransaction->foreign_currency_id === (int)$default->id) {
|
||||
if ((int)$sourceTransaction->foreign_currency_id === $default->id) {
|
||||
// ignore conversion, use foreign amount
|
||||
$nativeAmount = (string)$sourceTransaction->foreign_amount;
|
||||
}
|
||||
@@ -154,7 +154,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
|
||||
if ($total > 0) {
|
||||
$currency = $bill->transactionCurrency;
|
||||
$currencyId = (int)$bill->transaction_currency_id;
|
||||
$currencyId = $bill->transaction_currency_id;
|
||||
$average = bcdiv(bcadd($bill->amount_max, $bill->amount_min), '2');
|
||||
$nativeAverage = $converter->convert($currency, $default, $start, $average);
|
||||
$return[$currencyId] = $return[$currencyId] ?? [
|
||||
|
||||
@@ -53,7 +53,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
||||
->where('end_date', $end->format('Y-m-d'))->get();
|
||||
/** @var AvailableBudget $availableBudget */
|
||||
foreach ($availableBudgets as $availableBudget) {
|
||||
$currencyId = (int)$availableBudget->transaction_currency_id;
|
||||
$currencyId = $availableBudget->transaction_currency_id;
|
||||
$return[$currencyId] = $return[$currencyId] ?? [
|
||||
'currency_id' => $currencyId,
|
||||
'currency_code' => $availableBudget->transactionCurrency->code,
|
||||
|
||||
@@ -113,7 +113,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
// is being used in accounts (as integer)
|
||||
$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((int)$currency->id))->count();
|
||||
->where('account_meta.name', 'currency_id')->where('account_meta.data', json_encode($currency->id))->count();
|
||||
if ($meta > 0) {
|
||||
app('log')->info(sprintf('Used in %d accounts as currency_id, return true. ', $meta));
|
||||
|
||||
@@ -181,10 +181,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) {
|
||||
return (int)$entry->id === (int)$current->id;
|
||||
return $entry->id === $current->id;
|
||||
});
|
||||
$isDefault = $local->contains(static function (TransactionCurrency $entry) use ($current) {
|
||||
return 1 === (int)$entry->pivot->group_default && (int)$entry->id === (int)$current->id;
|
||||
return 1 === (int)$entry->pivot->group_default && $entry->id === $current->id;
|
||||
});
|
||||
$current->userEnabled = $hasId;
|
||||
$current->userDefault = $isDefault;
|
||||
|
||||
Reference in New Issue
Block a user