mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 02:36:28 +00:00 
			
		
		
		
	Fix overview, skip chart for now.
This commit is contained in:
		| @@ -29,10 +29,12 @@ use FireflyIII\Http\Controllers\Controller; | ||||
| use FireflyIII\Models\Account; | ||||
| use FireflyIII\Models\TransactionCurrency; | ||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||
| use FireflyIII\Support\Facades\Steam; | ||||
| use FireflyIII\Support\Http\Controllers\BasicDataSupport; | ||||
| use Illuminate\Contracts\View\Factory; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Pagination\LengthAwarePaginator; | ||||
| use Illuminate\Support\Facades\Log; | ||||
| use Illuminate\View\View; | ||||
| 
 | ||||
| /** | ||||
| @@ -71,22 +73,22 @@ class IndexController extends Controller | ||||
|      *                                              */ | ||||
|     public function inactive(Request $request, string $objectType) | ||||
|     { | ||||
|         $inactivePage  = true; | ||||
|         $subTitle      = (string) trans(sprintf('firefly.%s_accounts_inactive', $objectType)); | ||||
|         $subTitleIcon  = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType)); | ||||
|         $types         = config(sprintf('firefly.accountTypesByIdentifier.%s', $objectType)); | ||||
|         $collection    = $this->repository->getInactiveAccountsByType($types); | ||||
|         $total         = $collection->count(); | ||||
|         $page          = 0 === (int) $request->get('page') ? 1 : (int) $request->get('page'); | ||||
|         $pageSize      = (int) app('preferences')->get('listPageSize', 50)->data; | ||||
|         $accounts      = $collection->slice(($page - 1) * $pageSize, $pageSize); | ||||
|         $inactivePage = true; | ||||
|         $subTitle     = (string) trans(sprintf('firefly.%s_accounts_inactive', $objectType)); | ||||
|         $subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType)); | ||||
|         $types        = config(sprintf('firefly.accountTypesByIdentifier.%s', $objectType)); | ||||
|         $collection   = $this->repository->getInactiveAccountsByType($types); | ||||
|         $total        = $collection->count(); | ||||
|         $page         = 0 === (int) $request->get('page') ? 1 : (int) $request->get('page'); | ||||
|         $pageSize     = (int) app('preferences')->get('listPageSize', 50)->data; | ||||
|         $accounts     = $collection->slice(($page - 1) * $pageSize, $pageSize); | ||||
|         unset($collection); | ||||
| 
 | ||||
|         /** @var Carbon $start */ | ||||
|         $start         = clone session('start', today(config('app.timezone'))->startOfMonth()); | ||||
|         $start = clone session('start', today(config('app.timezone'))->startOfMonth()); | ||||
| 
 | ||||
|         /** @var Carbon $end */ | ||||
|         $end           = clone session('end', today(config('app.timezone'))->endOfMonth()); | ||||
|         $end = clone session('end', today(config('app.timezone'))->endOfMonth()); | ||||
|         $start->subDay(); | ||||
| 
 | ||||
|         $ids           = $accounts->pluck('id')->toArray(); | ||||
| @@ -99,8 +101,8 @@ class IndexController extends Controller | ||||
|             function (Account $account) use ($activities, $startBalances, $endBalances): void { | ||||
|                 $currency                   = $this->repository->getAccountCurrency($account); | ||||
|                 $account->lastActivityDate  = $this->isInArrayDate($activities, $account->id); | ||||
|                 $account->startBalances     = $this->getBalance($account, $currency, $startBalances); | ||||
|                 $account->endBalances       = $this->getBalance($account, $currency, $endBalances); | ||||
|                 $account->startBalances     = Steam::filterAccountBalance($startBalances[$account->id] ?? [], $account, $this->convertToNative, $currency); | ||||
|                 $account->endBalances       = Steam::filterAccountBalance($endBalances[$account->id] ?? [], $account, $this->convertToNative, $currency); | ||||
|                 $account->differences       = $this->subtract($account->startBalances, $account->endBalances); | ||||
|                 $account->interest          = app('steam')->bcround($this->repository->getMetaValue($account, 'interest'), 4); | ||||
|                 $account->interestPeriod    = (string) trans(sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period'))); | ||||
| @@ -111,7 +113,7 @@ class IndexController extends Controller | ||||
|         ); | ||||
| 
 | ||||
|         // make paginator:
 | ||||
|         $accounts      = new LengthAwarePaginator($accounts, $total, $pageSize, $page); | ||||
|         $accounts = new LengthAwarePaginator($accounts, $total, $pageSize, $page); | ||||
|         $accounts->setPath(route('accounts.inactive.index', [$objectType])); | ||||
| 
 | ||||
|         return view('accounts.index', compact('objectType', 'inactivePage', 'subTitleIcon', 'subTitle', 'page', 'accounts')); | ||||
| @@ -127,9 +129,9 @@ class IndexController extends Controller | ||||
|     public function index(Request $request, string $objectType) | ||||
|     { | ||||
|         app('log')->debug(sprintf('Now at %s', __METHOD__)); | ||||
|         $subTitle      = (string) trans(sprintf('firefly.%s_accounts', $objectType)); | ||||
|         $subTitleIcon  = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType)); | ||||
|         $types         = config(sprintf('firefly.accountTypesByIdentifier.%s', $objectType)); | ||||
|         $subTitle     = (string) trans(sprintf('firefly.%s_accounts', $objectType)); | ||||
|         $subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType)); | ||||
|         $types        = config(sprintf('firefly.accountTypesByIdentifier.%s', $objectType)); | ||||
| 
 | ||||
|         $this->repository->resetAccountOrder(); | ||||
| 
 | ||||
| @@ -145,10 +147,10 @@ class IndexController extends Controller | ||||
|         unset($collection); | ||||
| 
 | ||||
|         /** @var Carbon $start */ | ||||
|         $start         = clone session('start', today(config('app.timezone'))->startOfMonth()); | ||||
|         $start = clone session('start', today(config('app.timezone'))->startOfMonth()); | ||||
| 
 | ||||
|         /** @var Carbon $end */ | ||||
|         $end           = clone session('end', today(config('app.timezone'))->endOfMonth()); | ||||
|         $end = clone session('end', today(config('app.timezone'))->endOfMonth()); | ||||
|         $start->subDay(); | ||||
| 
 | ||||
|         $ids           = $accounts->pluck('id')->toArray(); | ||||
| @@ -159,12 +161,12 @@ class IndexController extends Controller | ||||
| 
 | ||||
|         $accounts->each( | ||||
|             function (Account $account) use ($activities, $startBalances, $endBalances): void { | ||||
|                 $interest                     = (string) $this->repository->getMetaValue($account, 'interest'); | ||||
|                 $interest                     = '' === $interest ? '0' : $interest; | ||||
|                 $currency                     = $this->repository->getAccountCurrency($account); | ||||
|                 $interest = (string) $this->repository->getMetaValue($account, 'interest'); | ||||
|                 $interest = '' === $interest ? '0' : $interest; | ||||
|                 $currency = $this->repository->getAccountCurrency($account); | ||||
| 
 | ||||
|                 $account->startBalances       = $this->getBalance($account, $currency, $startBalances); | ||||
|                 $account->endBalances         = $this->getBalance($account, $currency, $endBalances); | ||||
|                 $account->startBalances     = Steam::filterAccountBalance($startBalances[$account->id] ?? [], $account, $this->convertToNative, $currency); | ||||
|                 $account->endBalances       = Steam::filterAccountBalance($endBalances[$account->id] ?? [], $account, $this->convertToNative, $currency); | ||||
|                 $account->differences         = $this->subtract($account->startBalances, $account->endBalances); | ||||
|                 $account->lastActivityDate    = $this->isInArrayDate($activities, $account->id); | ||||
|                 $account->interest            = app('steam')->bcround($interest, 4); | ||||
| @@ -175,7 +177,7 @@ class IndexController extends Controller | ||||
|                 $account->location            = $this->repository->getLocation($account); | ||||
|                 $account->liability_direction = $this->repository->getMetaValue($account, 'liability_direction'); | ||||
|                 $account->current_debt        = $this->repository->getMetaValue($account, 'current_debt') ?? '-'; | ||||
|                 $account->currency            = $currency; | ||||
|                 $account->currency            = $currency ?? $this->defaultCurrency; | ||||
|                 $account->iban                = implode(' ', str_split((string) $account->iban, 4)); | ||||
| 
 | ||||
| 
 | ||||
| @@ -185,7 +187,7 @@ class IndexController extends Controller | ||||
|         app('log')->debug(sprintf('Count of accounts before LAP: %d', $accounts->count())); | ||||
| 
 | ||||
|         /** @var LengthAwarePaginator $accounts */ | ||||
|         $accounts      = new LengthAwarePaginator($accounts, $total, $pageSize, $page); | ||||
|         $accounts = new LengthAwarePaginator($accounts, $total, $pageSize, $page); | ||||
|         $accounts->setPath(route('accounts.index', [$objectType])); | ||||
| 
 | ||||
|         app('log')->debug(sprintf('Count of accounts after LAP (1): %d', $accounts->count())); | ||||
| @@ -194,22 +196,6 @@ class IndexController extends Controller | ||||
|         return view('accounts.index', compact('objectType', 'inactiveCount', 'subTitleIcon', 'subTitle', 'page', 'accounts')); | ||||
|     } | ||||
| 
 | ||||
|     private function getBalance(Account $account, ?TransactionCurrency $currency, array $balances): array | ||||
|     { | ||||
|         if (!array_key_exists($account->id, $balances)) { | ||||
|             return []; | ||||
|         } | ||||
|         $set = $balances[$account->id]; | ||||
| 
 | ||||
|         if ($this->convertToNative && $this->defaultCurrency->id === $currency?->id) { | ||||
|             unset($set['native_balance'], $set[$this->defaultCurrency->code]); | ||||
|         } | ||||
|         if ($this->convertToNative && null !== $currency && $this->defaultCurrency->id !== $currency->id) { | ||||
|             unset($set['balance']); | ||||
|         } | ||||
| 
 | ||||
|         return $set; | ||||
|     } | ||||
| 
 | ||||
|     private function subtract(array $startBalances, array $endBalances) | ||||
|     { | ||||
|   | ||||
| @@ -30,6 +30,7 @@ use FireflyIII\Helpers\Collector\GroupCollectorInterface; | ||||
| use FireflyIII\Http\Controllers\Controller; | ||||
| use FireflyIII\Models\Account; | ||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||
| use FireflyIII\Support\Facades\Amount; | ||||
| use FireflyIII\Support\Facades\Steam; | ||||
| use FireflyIII\Support\Http\Controllers\PeriodOverview; | ||||
| use Illuminate\Contracts\View\Factory; | ||||
| @@ -90,7 +91,7 @@ class ShowController extends Controller | ||||
|         // @var Carbon $end
 | ||||
|         $end   ??= session('end'); | ||||
| 
 | ||||
|         if ($end < $start) { | ||||
|         if ($end->lt($start)) { | ||||
|             [$start, $end] = [$end, $start]; | ||||
|         } | ||||
|         $location         = $this->repository->getLocation($account); | ||||
| @@ -99,7 +100,8 @@ class ShowController extends Controller | ||||
|         $subTitleIcon     = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type)); | ||||
|         $page             = (int) $request->get('page'); | ||||
|         $pageSize         = (int) app('preferences')->get('listPageSize', 50)->data; | ||||
|         $currency         = $this->repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency(); | ||||
|         $accountCurrency = $this->repository->getAccountCurrency($account); | ||||
|         $currency         = $accountCurrency ?? Amount::getDefaultCurrency(); | ||||
|         $fStart           = $start->isoFormat($this->monthAndDayFormat); | ||||
|         $fEnd             = $end->isoFormat($this->monthAndDayFormat); | ||||
|         $subTitle         = (string) trans('firefly.journals_in_period_for_account', ['name' => $account->name, 'start' => $fStart, 'end' => $fEnd]); | ||||
| @@ -129,7 +131,7 @@ class ShowController extends Controller | ||||
| 
 | ||||
|         $groups->setPath(route('accounts.show', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')])); | ||||
|         $showAll          = false; | ||||
|         $balance          = Steam::finalAccountBalance($account, $end)['balance'] ?? '0'; // TODO fix me
 | ||||
|         $balances          = Steam::filterAccountBalance(Steam::finalAccountBalance($account, $end), $account, $this->convertToNative, $accountCurrency); | ||||
| 
 | ||||
|         return view( | ||||
|             'accounts.show', | ||||
| @@ -148,7 +150,7 @@ class ShowController extends Controller | ||||
|                 'end', | ||||
|                 'chartUrl', | ||||
|                 'location', | ||||
|                 'balance' | ||||
|                 'balances' | ||||
|             ) | ||||
|         ); | ||||
|     } | ||||
| @@ -175,7 +177,7 @@ class ShowController extends Controller | ||||
|         $subTitleIcon = config('firefly.subIconsByIdentifier.'.$account->accountType->type); | ||||
|         $page         = (int) $request->get('page'); | ||||
|         $pageSize     = (int) app('preferences')->get('listPageSize', 50)->data; | ||||
|         $currency     = $this->repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency(); | ||||
|         $currency     = $this->repository->getAccountCurrency($account) ?? Amount::getDefaultCurrency(); | ||||
|         $subTitle     = (string) trans('firefly.all_journals_for_account', ['name' => $account->name]); | ||||
|         $periods      = new Collection(); | ||||
| 
 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user