mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-25 16:31:15 -06:00
Add todo, uncomment cache line. Expand count
This commit is contained in:
parent
ccb1f56573
commit
8fb72fe697
@ -398,7 +398,8 @@ class BudgetController extends Controller
|
||||
/**
|
||||
* Shows a budget list with spent/left/overspent.
|
||||
*
|
||||
* TODO this chart is not multi-currency aware.
|
||||
* TODO there are cases when this chart hides expenses: when budget has limits
|
||||
* and limits are found and used, but the expense is in another currency.
|
||||
*
|
||||
* @return JsonResponse
|
||||
*
|
||||
@ -413,7 +414,7 @@ class BudgetController extends Controller
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('chart.budget.frontpage');
|
||||
if ($cache->has()) {
|
||||
//return response()->json($cache->get()); // @codeCoverageIgnore
|
||||
return response()->json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
$budgets = $this->repository->getActiveBudgets();
|
||||
$chartData = [
|
||||
|
@ -32,6 +32,7 @@ use FireflyIII\Models\BudgetLimit;
|
||||
use FireflyIII\Models\CurrencyExchangeRate;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Models\RecurrenceTransaction;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\Services\Internal\Destroy\CurrencyDestroyService;
|
||||
@ -66,7 +67,11 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
*/
|
||||
public function countJournals(TransactionCurrency $currency): int
|
||||
{
|
||||
return $currency->transactions()->whereNull('deleted_at')->count() + $currency->transactionJournals()->whereNull('deleted_at')->count();
|
||||
$count = $currency->transactions()->whereNull('deleted_at')->count() + $currency->transactionJournals()->whereNull('deleted_at')->count();
|
||||
// also count foreign:
|
||||
$count += Transaction::where('foreign_currency_id', $currency->id)->count();
|
||||
|
||||
return $count;
|
||||
|
||||
}
|
||||
|
||||
@ -165,14 +170,14 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
return 'current_default';
|
||||
}
|
||||
|
||||
// // is the default currency for the system
|
||||
// $defaultSystemCode = config('firefly.default_currency', 'EUR');
|
||||
// $result = $currency->code === $defaultSystemCode;
|
||||
// if (true === $result) {
|
||||
// Log::info('Is the default currency of the SYSTEM, return true.');
|
||||
//
|
||||
// return 'system_fallback';
|
||||
// }
|
||||
// // is the default currency for the system
|
||||
// $defaultSystemCode = config('firefly.default_currency', 'EUR');
|
||||
// $result = $currency->code === $defaultSystemCode;
|
||||
// if (true === $result) {
|
||||
// Log::info('Is the default currency of the SYSTEM, return true.');
|
||||
//
|
||||
// return 'system_fallback';
|
||||
// }
|
||||
Log::debug('Currency is not used, return false.');
|
||||
|
||||
return null;
|
||||
@ -312,7 +317,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
/**
|
||||
* Find by object, ID or code. Returns user default or system default.
|
||||
*
|
||||
* @param int|null $currencyId
|
||||
* @param int|null $currencyId
|
||||
* @param string|null $currencyCode
|
||||
*
|
||||
* @return TransactionCurrency|null
|
||||
@ -342,7 +347,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
/**
|
||||
* Find by object, ID or code. Returns NULL if nothing found.
|
||||
*
|
||||
* @param int|null $currencyId
|
||||
* @param int|null $currencyId
|
||||
* @param string|null $currencyCode
|
||||
*
|
||||
* @return TransactionCurrency|null
|
||||
@ -393,16 +398,6 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
return TransactionCurrency::orderBy('code', 'ASC')->get();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getEnabled(): Collection
|
||||
{
|
||||
return TransactionCurrency::where('enabled',true)->orderBy('code', 'ASC')->get();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $ids
|
||||
*
|
||||
@ -428,12 +423,20 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
return $preferred;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getEnabled(): Collection
|
||||
{
|
||||
return TransactionCurrency::where('enabled', true)->orderBy('code', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get currency exchange rate.
|
||||
*
|
||||
* @param TransactionCurrency $fromCurrency
|
||||
* @param TransactionCurrency $toCurrency
|
||||
* @param Carbon $date
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return CurrencyExchangeRate|null
|
||||
*/
|
||||
@ -479,6 +482,21 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $search
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchCurrency(string $search): Collection
|
||||
{
|
||||
$query = TransactionCurrency::where('enabled', 1);
|
||||
if ('' !== $search) {
|
||||
$query->where('name', 'LIKE', sprintf('%%%s%%', $search));
|
||||
}
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
@ -508,7 +526,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return TransactionCurrency
|
||||
*/
|
||||
@ -519,18 +537,4 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
|
||||
return $service->update($currency, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $search
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchCurrency(string $search): Collection
|
||||
{
|
||||
$query = TransactionCurrency::where('enabled', 1);
|
||||
if ('' !== $search) {
|
||||
$query->where('name', 'LIKE', sprintf('%%%s%%', $search));
|
||||
}
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user