Add todo, uncomment cache line. Expand count

This commit is contained in:
James Cole
2020-02-09 10:06:38 +01:00
parent ccb1f56573
commit 8fb72fe697
2 changed files with 44 additions and 39 deletions

View File

@@ -398,7 +398,8 @@ class BudgetController extends Controller
/** /**
* Shows a budget list with spent/left/overspent. * 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 * @return JsonResponse
* *
@@ -413,7 +414,7 @@ class BudgetController extends Controller
$cache->addProperty($end); $cache->addProperty($end);
$cache->addProperty('chart.budget.frontpage'); $cache->addProperty('chart.budget.frontpage');
if ($cache->has()) { if ($cache->has()) {
//return response()->json($cache->get()); // @codeCoverageIgnore return response()->json($cache->get()); // @codeCoverageIgnore
} }
$budgets = $this->repository->getActiveBudgets(); $budgets = $this->repository->getActiveBudgets();
$chartData = [ $chartData = [

View File

@@ -32,6 +32,7 @@ use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\CurrencyExchangeRate; use FireflyIII\Models\CurrencyExchangeRate;
use FireflyIII\Models\Preference; use FireflyIII\Models\Preference;
use FireflyIII\Models\RecurrenceTransaction; use FireflyIII\Models\RecurrenceTransaction;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Services\Internal\Destroy\CurrencyDestroyService; use FireflyIII\Services\Internal\Destroy\CurrencyDestroyService;
@@ -66,7 +67,11 @@ class CurrencyRepository implements CurrencyRepositoryInterface
*/ */
public function countJournals(TransactionCurrency $currency): int 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;
} }
@@ -393,16 +398,6 @@ class CurrencyRepository implements CurrencyRepositoryInterface
return TransactionCurrency::orderBy('code', 'ASC')->get(); return TransactionCurrency::orderBy('code', 'ASC')->get();
} }
/**
* @return Collection
*/
public function getEnabled(): Collection
{
return TransactionCurrency::where('enabled',true)->orderBy('code', 'ASC')->get();
}
/** /**
* @param array $ids * @param array $ids
* *
@@ -428,6 +423,14 @@ class CurrencyRepository implements CurrencyRepositoryInterface
return $preferred; return $preferred;
} }
/**
* @return Collection
*/
public function getEnabled(): Collection
{
return TransactionCurrency::where('enabled', true)->orderBy('code', 'ASC')->get();
}
/** /**
* Get currency exchange rate. * Get currency exchange rate.
* *
@@ -479,6 +482,21 @@ class CurrencyRepository implements CurrencyRepositoryInterface
)->get(); )->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 * @param User $user
*/ */
@@ -519,18 +537,4 @@ class CurrencyRepository implements CurrencyRepositoryInterface
return $service->update($currency, $data); 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();
}
} }