mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-24 06:43:23 +00:00
Add todo, uncomment cache line. Expand count
This commit is contained in:
@@ -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 = [
|
||||||
|
@@ -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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,14 +170,14 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
|||||||
return 'current_default';
|
return 'current_default';
|
||||||
}
|
}
|
||||||
|
|
||||||
// // is the default currency for the system
|
// // is the default currency for the system
|
||||||
// $defaultSystemCode = config('firefly.default_currency', 'EUR');
|
// $defaultSystemCode = config('firefly.default_currency', 'EUR');
|
||||||
// $result = $currency->code === $defaultSystemCode;
|
// $result = $currency->code === $defaultSystemCode;
|
||||||
// if (true === $result) {
|
// if (true === $result) {
|
||||||
// Log::info('Is the default currency of the SYSTEM, return true.');
|
// Log::info('Is the default currency of the SYSTEM, return true.');
|
||||||
//
|
//
|
||||||
// return 'system_fallback';
|
// return 'system_fallback';
|
||||||
// }
|
// }
|
||||||
Log::debug('Currency is not used, return false.');
|
Log::debug('Currency is not used, return false.');
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -312,7 +317,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
|||||||
/**
|
/**
|
||||||
* Find by object, ID or code. Returns user default or system default.
|
* Find by object, ID or code. Returns user default or system default.
|
||||||
*
|
*
|
||||||
* @param int|null $currencyId
|
* @param int|null $currencyId
|
||||||
* @param string|null $currencyCode
|
* @param string|null $currencyCode
|
||||||
*
|
*
|
||||||
* @return TransactionCurrency|null
|
* @return TransactionCurrency|null
|
||||||
@@ -342,7 +347,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
|||||||
/**
|
/**
|
||||||
* Find by object, ID or code. Returns NULL if nothing found.
|
* Find by object, ID or code. Returns NULL if nothing found.
|
||||||
*
|
*
|
||||||
* @param int|null $currencyId
|
* @param int|null $currencyId
|
||||||
* @param string|null $currencyCode
|
* @param string|null $currencyCode
|
||||||
*
|
*
|
||||||
* @return TransactionCurrency|null
|
* @return TransactionCurrency|null
|
||||||
@@ -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,12 +423,20 @@ 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.
|
||||||
*
|
*
|
||||||
* @param TransactionCurrency $fromCurrency
|
* @param TransactionCurrency $fromCurrency
|
||||||
* @param TransactionCurrency $toCurrency
|
* @param TransactionCurrency $toCurrency
|
||||||
* @param Carbon $date
|
* @param Carbon $date
|
||||||
*
|
*
|
||||||
* @return CurrencyExchangeRate|null
|
* @return CurrencyExchangeRate|null
|
||||||
*/
|
*/
|
||||||
@@ -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
|
||||||
*/
|
*/
|
||||||
@@ -508,7 +526,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionCurrency $currency
|
* @param TransactionCurrency $currency
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
* @return TransactionCurrency
|
* @return TransactionCurrency
|
||||||
*/
|
*/
|
||||||
@@ -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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user