mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 10:47:00 +00:00 
			
		
		
		
	Fix period overview for account
This commit is contained in:
		| @@ -31,9 +31,12 @@ use FireflyIII\Helpers\Collector\GroupCollectorInterface; | |||||||
| use FireflyIII\Models\Account; | use FireflyIII\Models\Account; | ||||||
| use FireflyIII\Models\Category; | use FireflyIII\Models\Category; | ||||||
| use FireflyIII\Models\Tag; | use FireflyIII\Models\Tag; | ||||||
|  | use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||||
| use FireflyIII\Repositories\Journal\JournalRepositoryInterface; | use FireflyIII\Repositories\Journal\JournalRepositoryInterface; | ||||||
| use FireflyIII\Support\CacheProperties; | use FireflyIII\Support\CacheProperties; | ||||||
|  | use FireflyIII\Support\Debug\Timer; | ||||||
| use Illuminate\Support\Collection; | use Illuminate\Support\Collection; | ||||||
|  | use Illuminate\Support\Facades\Log; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Trait PeriodOverview. |  * Trait PeriodOverview. | ||||||
| @@ -65,6 +68,7 @@ use Illuminate\Support\Collection; | |||||||
| trait PeriodOverview | trait PeriodOverview | ||||||
| { | { | ||||||
|     protected JournalRepositoryInterface $journalRepos; |     protected JournalRepositoryInterface $journalRepos; | ||||||
|  |     protected AccountRepositoryInterface $accountRepository; | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * This method returns "period entries", so nov-2015, dec-2015, etc etc (this depends on the users session range) |      * This method returns "period entries", so nov-2015, dec-2015, etc etc (this depends on the users session range) | ||||||
| @@ -75,11 +79,13 @@ trait PeriodOverview | |||||||
|      */ |      */ | ||||||
|     protected function getAccountPeriodOverview(Account $account, Carbon $start, Carbon $end): array |     protected function getAccountPeriodOverview(Account $account, Carbon $start, Carbon $end): array | ||||||
|     { |     { | ||||||
|         $range         = app('navigation')->getViewRange(true); |         Timer::start('account-period-total'); | ||||||
|  |         $this->accountRepository = app(AccountRepositoryInterface::class); | ||||||
|  |         $range                   = app('navigation')->getViewRange(true); | ||||||
|         [$start, $end] = $end < $start ? [$end, $start] : [$start, $end]; |         [$start, $end] = $end < $start ? [$end, $start] : [$start, $end]; | ||||||
| 
 | 
 | ||||||
|         // properties for cache
 |         // properties for cache
 | ||||||
|         $cache         = new CacheProperties(); |         $cache = new CacheProperties(); | ||||||
|         $cache->addProperty($start); |         $cache->addProperty($start); | ||||||
|         $cache->addProperty($end); |         $cache->addProperty($end); | ||||||
|         $cache->addProperty('account-show-period-entries'); |         $cache->addProperty('account-show-period-entries'); | ||||||
| @@ -89,56 +95,75 @@ trait PeriodOverview | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /** @var array $dates */ |         /** @var array $dates */ | ||||||
|         $dates         = app('navigation')->blockPeriods($start, $end, $range); |         $dates   = app('navigation')->blockPeriods($start, $end, $range); | ||||||
|         $entries       = []; |         $entries = []; | ||||||
| 
 | 
 | ||||||
|         // collect all expenses in this period:
 |         // run a custom query because doing this with the collector is MEGA slow.
 | ||||||
|         /** @var GroupCollectorInterface $collector */ |         $transactions = $this->accountRepository->periodCollection($account, $start, $end); | ||||||
|         $collector     = app(GroupCollectorInterface::class); |  | ||||||
|         $collector->setAccounts(new Collection([$account])); |  | ||||||
|         $collector->setRange($start, $end); |  | ||||||
|         $collector->setTypes([TransactionTypeEnum::DEPOSIT->value]); |  | ||||||
|         $earnedSet     = $collector->getExtractedJournals(); |  | ||||||
| 
 |  | ||||||
|         // collect all income in this period:
 |  | ||||||
|         /** @var GroupCollectorInterface $collector */ |  | ||||||
|         $collector     = app(GroupCollectorInterface::class); |  | ||||||
|         $collector->setAccounts(new Collection([$account])); |  | ||||||
|         $collector->setRange($start, $end); |  | ||||||
|         $collector->setTypes([TransactionTypeEnum::WITHDRAWAL->value]); |  | ||||||
|         $spentSet      = $collector->getExtractedJournals(); |  | ||||||
| 
 |  | ||||||
|         // collect all transfers in this period:
 |  | ||||||
|         /** @var GroupCollectorInterface $collector */ |  | ||||||
|         $collector     = app(GroupCollectorInterface::class); |  | ||||||
|         $collector->setAccounts(new Collection([$account])); |  | ||||||
|         $collector->setRange($start, $end); |  | ||||||
|         $collector->setTypes([TransactionTypeEnum::TRANSFER->value]); |  | ||||||
|         $transferSet   = $collector->getExtractedJournals(); |  | ||||||
| 
 | 
 | ||||||
|         // loop dates
 |         // loop dates
 | ||||||
|         foreach ($dates as $currentDate) { |         foreach ($dates as $currentDate) { | ||||||
|             $title           = app('navigation')->periodShow($currentDate['start'], $currentDate['period']); |             $title           = app('navigation')->periodShow($currentDate['start'], $currentDate['period']); | ||||||
|             $earned          = $this->filterJournalsByDate($earnedSet, $currentDate['start'], $currentDate['end']); |             [$transactions, $spent] = $this->filterTransactionsByType(TransactionTypeEnum::WITHDRAWAL, $transactions, $currentDate['start'], $currentDate['end']); | ||||||
|             $spent           = $this->filterJournalsByDate($spentSet, $currentDate['start'], $currentDate['end']); |             [$transactions, $earned] = $this->filterTransactionsByType(TransactionTypeEnum::DEPOSIT, $transactions, $currentDate['start'], $currentDate['end']); | ||||||
|             $transferredAway = $this->filterTransferredAway($account, $this->filterJournalsByDate($transferSet, $currentDate['start'], $currentDate['end'])); |             [$transactions, $transferredAway] = $this->filterTransfers('away',$transactions, $currentDate['start'], $currentDate['end']); | ||||||
|             $transferredIn   = $this->filterTransferredIn($account, $this->filterJournalsByDate($transferSet, $currentDate['start'], $currentDate['end'])); |             [$transactions, $transferredIn] = $this->filterTransfers('in',$transactions, $currentDate['start'], $currentDate['end']); | ||||||
|             $entries[] |             $entries[] | ||||||
|                              = [ |                 = [ | ||||||
|                                  'title'              => $title, |                 'title' => $title, | ||||||
|                                  'route'              => route('accounts.show', [$account->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]), |                 'route' => route('accounts.show', [$account->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]), | ||||||
| 
 |                 'total_transactions' => count($spent) + count($earned) + count($transferredAway) + count($transferredIn), | ||||||
|                                  'total_transactions' => count($spent) + count($earned) + count($transferredAway) + count($transferredIn), |                 'spent'              => $this->groupByCurrency($spent), | ||||||
|                                  'spent'              => $this->groupByCurrency($spent), |                 'earned'             => $this->groupByCurrency($earned), | ||||||
|                                  'earned'             => $this->groupByCurrency($earned), |                 'transferred_away'   => $this->groupByCurrency($transferredAway), | ||||||
|                                  'transferred_away'   => $this->groupByCurrency($transferredAway), |                 'transferred_in'     => $this->groupByCurrency($transferredIn), | ||||||
|                                  'transferred_in'     => $this->groupByCurrency($transferredIn), |             ]; | ||||||
|                              ]; |  | ||||||
|         } |         } | ||||||
|         $cache->store($entries); |         $cache->store($entries); | ||||||
|  |         Timer::stop('account-period-total'); | ||||||
| 
 | 
 | ||||||
|         return $entries; |         return $entries; | ||||||
|     } |     } | ||||||
|  |     private function filterTransfers(string $direction, array $transactions,  Carbon $start, Carbon $end): array | ||||||
|  |     { | ||||||
|  |         $result = []; | ||||||
|  |         /** | ||||||
|  |          * @var int   $index | ||||||
|  |          * @var array $item | ||||||
|  |          */ | ||||||
|  |         foreach ($transactions as $index => $item) { | ||||||
|  |             $date = Carbon::parse($item['date']); | ||||||
|  |             if ($date >= $start && $date <= $end) { | ||||||
|  |                 if ($direction === 'away' && bccomp($item['amount'], '0') === -1) { | ||||||
|  |                     $result[] = $item; | ||||||
|  |                     unset($transactions[$index]); | ||||||
|  |                 } | ||||||
|  |                 if ($direction === 'in' && bccomp($item['amount'], '0') === 1) { | ||||||
|  |                     $result[] = $item; | ||||||
|  |                     unset($transactions[$index]); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         return [$transactions, $result]; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private function filterTransactionsByType(TransactionTypeEnum $type, array $transactions, Carbon $start, Carbon $end): array | ||||||
|  |     { | ||||||
|  |         $result = []; | ||||||
|  |         /** | ||||||
|  |          * @var int   $index | ||||||
|  |          * @var array $item | ||||||
|  |          */ | ||||||
|  |         foreach ($transactions as $index => $item) { | ||||||
|  |             $date = Carbon::parse($item['date']); | ||||||
|  |             if($item['type'] === $type->value && $date >= $start && $date <= $end) { | ||||||
|  |                 $result[] = $item; | ||||||
|  |                 unset($transactions[$index]); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return [$transactions, $result]; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Filter a list of journals by a set of dates, and then group them by currency. |      * Filter a list of journals by a set of dates, and then group them by currency. | ||||||
| @@ -197,13 +222,13 @@ trait PeriodOverview | |||||||
| 
 | 
 | ||||||
|         /** @var array $journal */ |         /** @var array $journal */ | ||||||
|         foreach ($journals as $journal) { |         foreach ($journals as $journal) { | ||||||
|             $currencyId                    = (int) $journal['currency_id']; |             $currencyId            = (int) $journal['currency_id']; | ||||||
|             $currencyCode                  = $journal['currency_code']; |             $currencyCode          = $journal['currency_code']; | ||||||
|             $currencyName                  = $journal['currency_name']; |             $currencyName          = $journal['currency_name']; | ||||||
|             $currencySymbol                = $journal['currency_symbol']; |             $currencySymbol        = $journal['currency_symbol']; | ||||||
|             $currencyDecimalPlaces         = $journal['currency_decimal_places']; |             $currencyDecimalPlaces = $journal['currency_decimal_places']; | ||||||
|             $foreignCurrencyId             = $journal['foreign_currency_id']; |             $foreignCurrencyId     = $journal['foreign_currency_id']; | ||||||
|             $amount                        = $journal['amount'] ?? '0'; |             $amount                = $journal['amount'] ?? '0'; | ||||||
| 
 | 
 | ||||||
|             if ($this->convertToNative && $currencyId !== $this->defaultCurrency->id && $foreignCurrencyId !== $this->defaultCurrency->id) { |             if ($this->convertToNative && $currencyId !== $this->defaultCurrency->id && $foreignCurrencyId !== $this->defaultCurrency->id) { | ||||||
|                 $amount                = $journal['native_amount'] ?? '0'; |                 $amount                = $journal['native_amount'] ?? '0'; | ||||||
| @@ -246,11 +271,11 @@ trait PeriodOverview | |||||||
|      */ |      */ | ||||||
|     protected function getCategoryPeriodOverview(Category $category, Carbon $start, Carbon $end): array |     protected function getCategoryPeriodOverview(Category $category, Carbon $start, Carbon $end): array | ||||||
|     { |     { | ||||||
|         $range         = app('navigation')->getViewRange(true); |         $range = app('navigation')->getViewRange(true); | ||||||
|         [$start, $end] = $end < $start ? [$end, $start] : [$start, $end]; |         [$start, $end] = $end < $start ? [$end, $start] : [$start, $end]; | ||||||
| 
 | 
 | ||||||
|         // properties for entries with their amounts.
 |         // properties for entries with their amounts.
 | ||||||
|         $cache         = new CacheProperties(); |         $cache = new CacheProperties(); | ||||||
|         $cache->addProperty($start); |         $cache->addProperty($start); | ||||||
|         $cache->addProperty($end); |         $cache->addProperty($end); | ||||||
|         $cache->addProperty($range); |         $cache->addProperty($range); | ||||||
| @@ -262,32 +287,32 @@ trait PeriodOverview | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /** @var array $dates */ |         /** @var array $dates */ | ||||||
|         $dates         = app('navigation')->blockPeriods($start, $end, $range); |         $dates   = app('navigation')->blockPeriods($start, $end, $range); | ||||||
|         $entries       = []; |         $entries = []; | ||||||
| 
 | 
 | ||||||
|         // collect all expenses in this period:
 |         // collect all expenses in this period:
 | ||||||
|         /** @var GroupCollectorInterface $collector */ |         /** @var GroupCollectorInterface $collector */ | ||||||
|         $collector     = app(GroupCollectorInterface::class); |         $collector = app(GroupCollectorInterface::class); | ||||||
|         $collector->setCategory($category); |         $collector->setCategory($category); | ||||||
|         $collector->setRange($start, $end); |         $collector->setRange($start, $end); | ||||||
|         $collector->setTypes([TransactionTypeEnum::DEPOSIT->value]); |         $collector->setTypes([TransactionTypeEnum::DEPOSIT->value]); | ||||||
|         $earnedSet     = $collector->getExtractedJournals(); |         $earnedSet = $collector->getExtractedJournals(); | ||||||
| 
 | 
 | ||||||
|         // collect all income in this period:
 |         // collect all income in this period:
 | ||||||
|         /** @var GroupCollectorInterface $collector */ |         /** @var GroupCollectorInterface $collector */ | ||||||
|         $collector     = app(GroupCollectorInterface::class); |         $collector = app(GroupCollectorInterface::class); | ||||||
|         $collector->setCategory($category); |         $collector->setCategory($category); | ||||||
|         $collector->setRange($start, $end); |         $collector->setRange($start, $end); | ||||||
|         $collector->setTypes([TransactionTypeEnum::WITHDRAWAL->value]); |         $collector->setTypes([TransactionTypeEnum::WITHDRAWAL->value]); | ||||||
|         $spentSet      = $collector->getExtractedJournals(); |         $spentSet = $collector->getExtractedJournals(); | ||||||
| 
 | 
 | ||||||
|         // collect all transfers in this period:
 |         // collect all transfers in this period:
 | ||||||
|         /** @var GroupCollectorInterface $collector */ |         /** @var GroupCollectorInterface $collector */ | ||||||
|         $collector     = app(GroupCollectorInterface::class); |         $collector = app(GroupCollectorInterface::class); | ||||||
|         $collector->setCategory($category); |         $collector->setCategory($category); | ||||||
|         $collector->setRange($start, $end); |         $collector->setRange($start, $end); | ||||||
|         $collector->setTypes([TransactionTypeEnum::TRANSFER->value]); |         $collector->setTypes([TransactionTypeEnum::TRANSFER->value]); | ||||||
|         $transferSet   = $collector->getExtractedJournals(); |         $transferSet = $collector->getExtractedJournals(); | ||||||
|         foreach ($dates as $currentDate) { |         foreach ($dates as $currentDate) { | ||||||
|             $spent       = $this->filterJournalsByDate($spentSet, $currentDate['start'], $currentDate['end']); |             $spent       = $this->filterJournalsByDate($spentSet, $currentDate['start'], $currentDate['end']); | ||||||
|             $earned      = $this->filterJournalsByDate($earnedSet, $currentDate['start'], $currentDate['end']); |             $earned      = $this->filterJournalsByDate($earnedSet, $currentDate['start'], $currentDate['end']); | ||||||
| @@ -295,17 +320,17 @@ trait PeriodOverview | |||||||
|             $title       = app('navigation')->periodShow($currentDate['end'], $currentDate['period']); |             $title       = app('navigation')->periodShow($currentDate['end'], $currentDate['period']); | ||||||
|             $entries[] |             $entries[] | ||||||
|                          = [ |                          = [ | ||||||
|                              'transactions'       => 0, |                 'transactions'       => 0, | ||||||
|                              'title'              => $title, |                 'title'              => $title, | ||||||
|                              'route'              => route( |                 'route'              => route( | ||||||
|                                  'categories.show', |                     'categories.show', | ||||||
|                                  [$category->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')] |                     [$category->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')] | ||||||
|                              ), |                 ), | ||||||
|                              'total_transactions' => count($spent) + count($earned) + count($transferred), |                 'total_transactions' => count($spent) + count($earned) + count($transferred), | ||||||
|                              'spent'              => $this->groupByCurrency($spent), |                 'spent'              => $this->groupByCurrency($spent), | ||||||
|                              'earned'             => $this->groupByCurrency($earned), |                 'earned'             => $this->groupByCurrency($earned), | ||||||
|                              'transferred'        => $this->groupByCurrency($transferred), |                 'transferred'        => $this->groupByCurrency($transferred), | ||||||
|                          ]; |             ]; | ||||||
|         } |         } | ||||||
|         $cache->store($entries); |         $cache->store($entries); | ||||||
| 
 | 
 | ||||||
| @@ -321,11 +346,11 @@ trait PeriodOverview | |||||||
|      */ |      */ | ||||||
|     protected function getNoBudgetPeriodOverview(Carbon $start, Carbon $end): array |     protected function getNoBudgetPeriodOverview(Carbon $start, Carbon $end): array | ||||||
|     { |     { | ||||||
|         $range         = app('navigation')->getViewRange(true); |         $range = app('navigation')->getViewRange(true); | ||||||
| 
 | 
 | ||||||
|         [$start, $end] = $end < $start ? [$end, $start] : [$start, $end]; |         [$start, $end] = $end < $start ? [$end, $start] : [$start, $end]; | ||||||
| 
 | 
 | ||||||
|         $cache         = new CacheProperties(); |         $cache = new CacheProperties(); | ||||||
|         $cache->addProperty($start); |         $cache->addProperty($start); | ||||||
|         $cache->addProperty($end); |         $cache->addProperty($end); | ||||||
|         $cache->addProperty($this->convertToNative); |         $cache->addProperty($this->convertToNative); | ||||||
| @@ -336,28 +361,28 @@ trait PeriodOverview | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /** @var array $dates */ |         /** @var array $dates */ | ||||||
|         $dates         = app('navigation')->blockPeriods($start, $end, $range); |         $dates   = app('navigation')->blockPeriods($start, $end, $range); | ||||||
|         $entries       = []; |         $entries = []; | ||||||
| 
 | 
 | ||||||
|         // get all expenses without a budget.
 |         // get all expenses without a budget.
 | ||||||
|         /** @var GroupCollectorInterface $collector */ |         /** @var GroupCollectorInterface $collector */ | ||||||
|         $collector     = app(GroupCollectorInterface::class); |         $collector = app(GroupCollectorInterface::class); | ||||||
|         $collector->setRange($start, $end)->withoutBudget()->withAccountInformation()->setTypes([TransactionTypeEnum::WITHDRAWAL->value]); |         $collector->setRange($start, $end)->withoutBudget()->withAccountInformation()->setTypes([TransactionTypeEnum::WITHDRAWAL->value]); | ||||||
|         $journals      = $collector->getExtractedJournals(); |         $journals = $collector->getExtractedJournals(); | ||||||
| 
 | 
 | ||||||
|         foreach ($dates as $currentDate) { |         foreach ($dates as $currentDate) { | ||||||
|             $set   = $this->filterJournalsByDate($journals, $currentDate['start'], $currentDate['end']); |             $set   = $this->filterJournalsByDate($journals, $currentDate['start'], $currentDate['end']); | ||||||
|             $title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']); |             $title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']); | ||||||
|             $entries[] |             $entries[] | ||||||
|                    = [ |                    = [ | ||||||
|                        'title'              => $title, |                 'title'              => $title, | ||||||
|                        'route'              => route('budgets.no-budget', [$currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]), |                 'route'              => route('budgets.no-budget', [$currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]), | ||||||
|                        'total_transactions' => count($set), |                 'total_transactions' => count($set), | ||||||
|                        'spent'              => $this->groupByCurrency($set), |                 'spent'              => $this->groupByCurrency($set), | ||||||
|                        'earned'             => [], |                 'earned'             => [], | ||||||
|                        'transferred_away'   => [], |                 'transferred_away'   => [], | ||||||
|                        'transferred_in'     => [], |                 'transferred_in'     => [], | ||||||
|                    ]; |             ]; | ||||||
|         } |         } | ||||||
|         $cache->store($entries); |         $cache->store($entries); | ||||||
| 
 | 
 | ||||||
| @@ -374,38 +399,38 @@ trait PeriodOverview | |||||||
|     protected function getNoCategoryPeriodOverview(Carbon $theDate): array |     protected function getNoCategoryPeriodOverview(Carbon $theDate): array | ||||||
|     { |     { | ||||||
|         app('log')->debug(sprintf('Now in getNoCategoryPeriodOverview(%s)', $theDate->format('Y-m-d'))); |         app('log')->debug(sprintf('Now in getNoCategoryPeriodOverview(%s)', $theDate->format('Y-m-d'))); | ||||||
|         $range       = app('navigation')->getViewRange(true); |         $range = app('navigation')->getViewRange(true); | ||||||
|         $first       = $this->journalRepos->firstNull(); |         $first = $this->journalRepos->firstNull(); | ||||||
|         $start       = null === $first ? new Carbon() : $first->date; |         $start = null === $first ? new Carbon() : $first->date; | ||||||
|         $end         = clone $theDate; |         $end   = clone $theDate; | ||||||
|         $end         = app('navigation')->endOfPeriod($end, $range); |         $end   = app('navigation')->endOfPeriod($end, $range); | ||||||
| 
 | 
 | ||||||
|         app('log')->debug(sprintf('Start for getNoCategoryPeriodOverview() is %s', $start->format('Y-m-d'))); |         app('log')->debug(sprintf('Start for getNoCategoryPeriodOverview() is %s', $start->format('Y-m-d'))); | ||||||
|         app('log')->debug(sprintf('End for getNoCategoryPeriodOverview() is %s', $end->format('Y-m-d'))); |         app('log')->debug(sprintf('End for getNoCategoryPeriodOverview() is %s', $end->format('Y-m-d'))); | ||||||
| 
 | 
 | ||||||
|         // properties for cache
 |         // properties for cache
 | ||||||
|         $dates       = app('navigation')->blockPeriods($start, $end, $range); |         $dates   = app('navigation')->blockPeriods($start, $end, $range); | ||||||
|         $entries     = []; |         $entries = []; | ||||||
| 
 | 
 | ||||||
|         // collect all expenses in this period:
 |         // collect all expenses in this period:
 | ||||||
|         /** @var GroupCollectorInterface $collector */ |         /** @var GroupCollectorInterface $collector */ | ||||||
|         $collector   = app(GroupCollectorInterface::class); |         $collector = app(GroupCollectorInterface::class); | ||||||
|         $collector->withoutCategory(); |         $collector->withoutCategory(); | ||||||
|         $collector->setRange($start, $end); |         $collector->setRange($start, $end); | ||||||
|         $collector->setTypes([TransactionTypeEnum::DEPOSIT->value]); |         $collector->setTypes([TransactionTypeEnum::DEPOSIT->value]); | ||||||
|         $earnedSet   = $collector->getExtractedJournals(); |         $earnedSet = $collector->getExtractedJournals(); | ||||||
| 
 | 
 | ||||||
|         // collect all income in this period:
 |         // collect all income in this period:
 | ||||||
|         /** @var GroupCollectorInterface $collector */ |         /** @var GroupCollectorInterface $collector */ | ||||||
|         $collector   = app(GroupCollectorInterface::class); |         $collector = app(GroupCollectorInterface::class); | ||||||
|         $collector->withoutCategory(); |         $collector->withoutCategory(); | ||||||
|         $collector->setRange($start, $end); |         $collector->setRange($start, $end); | ||||||
|         $collector->setTypes([TransactionTypeEnum::WITHDRAWAL->value]); |         $collector->setTypes([TransactionTypeEnum::WITHDRAWAL->value]); | ||||||
|         $spentSet    = $collector->getExtractedJournals(); |         $spentSet = $collector->getExtractedJournals(); | ||||||
| 
 | 
 | ||||||
|         // collect all transfers in this period:
 |         // collect all transfers in this period:
 | ||||||
|         /** @var GroupCollectorInterface $collector */ |         /** @var GroupCollectorInterface $collector */ | ||||||
|         $collector   = app(GroupCollectorInterface::class); |         $collector = app(GroupCollectorInterface::class); | ||||||
|         $collector->withoutCategory(); |         $collector->withoutCategory(); | ||||||
|         $collector->setRange($start, $end); |         $collector->setRange($start, $end); | ||||||
|         $collector->setTypes([TransactionTypeEnum::TRANSFER->value]); |         $collector->setTypes([TransactionTypeEnum::TRANSFER->value]); | ||||||
| @@ -419,13 +444,13 @@ trait PeriodOverview | |||||||
|             $title       = app('navigation')->periodShow($currentDate['end'], $currentDate['period']); |             $title       = app('navigation')->periodShow($currentDate['end'], $currentDate['period']); | ||||||
|             $entries[] |             $entries[] | ||||||
|                          = [ |                          = [ | ||||||
|                              'title'              => $title, |                 'title'              => $title, | ||||||
|                              'route'              => route('categories.no-category', [$currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]), |                 'route'              => route('categories.no-category', [$currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]), | ||||||
|                              'total_transactions' => count($spent) + count($earned) + count($transferred), |                 'total_transactions' => count($spent) + count($earned) + count($transferred), | ||||||
|                              'spent'              => $this->groupByCurrency($spent), |                 'spent'              => $this->groupByCurrency($spent), | ||||||
|                              'earned'             => $this->groupByCurrency($earned), |                 'earned'             => $this->groupByCurrency($earned), | ||||||
|                              'transferred'        => $this->groupByCurrency($transferred), |                 'transferred'        => $this->groupByCurrency($transferred), | ||||||
|                          ]; |             ]; | ||||||
|         } |         } | ||||||
|         app('log')->debug('End of loops'); |         app('log')->debug('End of loops'); | ||||||
| 
 | 
 | ||||||
| @@ -439,11 +464,11 @@ trait PeriodOverview | |||||||
|      */ |      */ | ||||||
|     protected function getTagPeriodOverview(Tag $tag, Carbon $start, Carbon $end): array // period overview for tags.
 |     protected function getTagPeriodOverview(Tag $tag, Carbon $start, Carbon $end): array // period overview for tags.
 | ||||||
|     { |     { | ||||||
|         $range         = app('navigation')->getViewRange(true); |         $range = app('navigation')->getViewRange(true); | ||||||
|         [$start, $end] = $end < $start ? [$end, $start] : [$start, $end]; |         [$start, $end] = $end < $start ? [$end, $start] : [$start, $end]; | ||||||
| 
 | 
 | ||||||
|         // properties for cache
 |         // properties for cache
 | ||||||
|         $cache         = new CacheProperties(); |         $cache = new CacheProperties(); | ||||||
|         $cache->addProperty($start); |         $cache->addProperty($start); | ||||||
|         $cache->addProperty($end); |         $cache->addProperty($end); | ||||||
|         $cache->addProperty('tag-period-entries'); |         $cache->addProperty('tag-period-entries'); | ||||||
| @@ -453,37 +478,37 @@ trait PeriodOverview | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /** @var array $dates */ |         /** @var array $dates */ | ||||||
|         $dates         = app('navigation')->blockPeriods($start, $end, $range); |         $dates   = app('navigation')->blockPeriods($start, $end, $range); | ||||||
|         $entries       = []; |         $entries = []; | ||||||
| 
 | 
 | ||||||
|         // collect all expenses in this period:
 |         // collect all expenses in this period:
 | ||||||
|         /** @var GroupCollectorInterface $collector */ |         /** @var GroupCollectorInterface $collector */ | ||||||
|         $collector     = app(GroupCollectorInterface::class); |         $collector = app(GroupCollectorInterface::class); | ||||||
|         $collector->setTag($tag); |         $collector->setTag($tag); | ||||||
|         $collector->setRange($start, $end); |         $collector->setRange($start, $end); | ||||||
|         $collector->setTypes([TransactionTypeEnum::DEPOSIT->value]); |         $collector->setTypes([TransactionTypeEnum::DEPOSIT->value]); | ||||||
|         $earnedSet     = $collector->getExtractedJournals(); |         $earnedSet = $collector->getExtractedJournals(); | ||||||
| 
 | 
 | ||||||
|         // collect all income in this period:
 |         // collect all income in this period:
 | ||||||
|         /** @var GroupCollectorInterface $collector */ |         /** @var GroupCollectorInterface $collector */ | ||||||
|         $collector     = app(GroupCollectorInterface::class); |         $collector = app(GroupCollectorInterface::class); | ||||||
|         $collector->setTag($tag); |         $collector->setTag($tag); | ||||||
|         $collector->setRange($start, $end); |         $collector->setRange($start, $end); | ||||||
|         $collector->setTypes([TransactionTypeEnum::WITHDRAWAL->value]); |         $collector->setTypes([TransactionTypeEnum::WITHDRAWAL->value]); | ||||||
|         $spentSet      = $collector->getExtractedJournals(); |         $spentSet = $collector->getExtractedJournals(); | ||||||
| 
 | 
 | ||||||
|         // collect all transfers in this period:
 |         // collect all transfers in this period:
 | ||||||
|         /** @var GroupCollectorInterface $collector */ |         /** @var GroupCollectorInterface $collector */ | ||||||
|         $collector     = app(GroupCollectorInterface::class); |         $collector = app(GroupCollectorInterface::class); | ||||||
|         $collector->setTag($tag); |         $collector->setTag($tag); | ||||||
|         $collector->setRange($start, $end); |         $collector->setRange($start, $end); | ||||||
|         $collector->setTypes([TransactionTypeEnum::TRANSFER->value]); |         $collector->setTypes([TransactionTypeEnum::TRANSFER->value]); | ||||||
|         $transferSet   = $collector->getExtractedJournals(); |         $transferSet = $collector->getExtractedJournals(); | ||||||
| 
 | 
 | ||||||
|         // filer all of them:
 |         // filer all of them:
 | ||||||
|         $earnedSet     = $this->filterJournalsByTag($earnedSet, $tag); |         $earnedSet   = $this->filterJournalsByTag($earnedSet, $tag); | ||||||
|         $spentSet      = $this->filterJournalsByTag($spentSet, $tag); |         $spentSet    = $this->filterJournalsByTag($spentSet, $tag); | ||||||
|         $transferSet   = $this->filterJournalsByTag($transferSet, $tag); |         $transferSet = $this->filterJournalsByTag($transferSet, $tag); | ||||||
| 
 | 
 | ||||||
|         foreach ($dates as $currentDate) { |         foreach ($dates as $currentDate) { | ||||||
|             $spent       = $this->filterJournalsByDate($spentSet, $currentDate['start'], $currentDate['end']); |             $spent       = $this->filterJournalsByDate($spentSet, $currentDate['start'], $currentDate['end']); | ||||||
| @@ -492,17 +517,17 @@ trait PeriodOverview | |||||||
|             $title       = app('navigation')->periodShow($currentDate['end'], $currentDate['period']); |             $title       = app('navigation')->periodShow($currentDate['end'], $currentDate['period']); | ||||||
|             $entries[] |             $entries[] | ||||||
|                          = [ |                          = [ | ||||||
|                              'transactions'       => 0, |                 'transactions'       => 0, | ||||||
|                              'title'              => $title, |                 'title'              => $title, | ||||||
|                              'route'              => route( |                 'route'              => route( | ||||||
|                                  'tags.show', |                     'tags.show', | ||||||
|                                  [$tag->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')] |                     [$tag->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')] | ||||||
|                              ), |                 ), | ||||||
|                              'total_transactions' => count($spent) + count($earned) + count($transferred), |                 'total_transactions' => count($spent) + count($earned) + count($transferred), | ||||||
|                              'spent'              => $this->groupByCurrency($spent), |                 'spent'              => $this->groupByCurrency($spent), | ||||||
|                              'earned'             => $this->groupByCurrency($earned), |                 'earned'             => $this->groupByCurrency($earned), | ||||||
|                              'transferred'        => $this->groupByCurrency($transferred), |                 'transferred'        => $this->groupByCurrency($transferred), | ||||||
|                          ]; |             ]; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return $entries; |         return $entries; | ||||||
| @@ -512,7 +537,7 @@ trait PeriodOverview | |||||||
|     { |     { | ||||||
|         $return = []; |         $return = []; | ||||||
|         foreach ($set as $entry) { |         foreach ($set as $entry) { | ||||||
|             $found    = false; |             $found = false; | ||||||
| 
 | 
 | ||||||
|             /** @var array $localTag */ |             /** @var array $localTag */ | ||||||
|             foreach ($entry['tags'] as $localTag) { |             foreach ($entry['tags'] as $localTag) { | ||||||
| @@ -534,12 +559,12 @@ trait PeriodOverview | |||||||
|      */ |      */ | ||||||
|     protected function getTransactionPeriodOverview(string $transactionType, Carbon $start, Carbon $end): array |     protected function getTransactionPeriodOverview(string $transactionType, Carbon $start, Carbon $end): array | ||||||
|     { |     { | ||||||
|         $range         = app('navigation')->getViewRange(true); |         $range = app('navigation')->getViewRange(true); | ||||||
|         $types         = config(sprintf('firefly.transactionTypesByType.%s', $transactionType)); |         $types = config(sprintf('firefly.transactionTypesByType.%s', $transactionType)); | ||||||
|         [$start, $end] = $end < $start ? [$end, $start] : [$start, $end]; |         [$start, $end] = $end < $start ? [$end, $start] : [$start, $end]; | ||||||
| 
 | 
 | ||||||
|         // properties for cache
 |         // properties for cache
 | ||||||
|         $cache         = new CacheProperties(); |         $cache = new CacheProperties(); | ||||||
|         $cache->addProperty($start); |         $cache->addProperty($start); | ||||||
|         $cache->addProperty($end); |         $cache->addProperty($end); | ||||||
|         $cache->addProperty('transactions-period-entries'); |         $cache->addProperty('transactions-period-entries'); | ||||||
| @@ -549,13 +574,13 @@ trait PeriodOverview | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /** @var array $dates */ |         /** @var array $dates */ | ||||||
|         $dates         = app('navigation')->blockPeriods($start, $end, $range); |         $dates   = app('navigation')->blockPeriods($start, $end, $range); | ||||||
|         $entries       = []; |         $entries = []; | ||||||
| 
 | 
 | ||||||
|         // collect all journals in this period (regardless of type)
 |         // collect all journals in this period (regardless of type)
 | ||||||
|         $collector     = app(GroupCollectorInterface::class); |         $collector = app(GroupCollectorInterface::class); | ||||||
|         $collector->setTypes($types)->setRange($start, $end); |         $collector->setTypes($types)->setRange($start, $end); | ||||||
|         $genericSet    = $collector->getExtractedJournals(); |         $genericSet = $collector->getExtractedJournals(); | ||||||
| 
 | 
 | ||||||
|         foreach ($dates as $currentDate) { |         foreach ($dates as $currentDate) { | ||||||
|             $spent       = []; |             $spent       = []; | ||||||
| @@ -574,14 +599,14 @@ trait PeriodOverview | |||||||
|                 $transferred = $this->filterJournalsByDate($genericSet, $currentDate['start'], $currentDate['end']); |                 $transferred = $this->filterJournalsByDate($genericSet, $currentDate['start'], $currentDate['end']); | ||||||
|             } |             } | ||||||
|             $entries[] |             $entries[] | ||||||
|                          = [ |                 = [ | ||||||
|                              'title'              => $title, |                 'title'              => $title, | ||||||
|                              'route'              => route('transactions.index', [$transactionType, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]), |                 'route'              => route('transactions.index', [$transactionType, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]), | ||||||
|                              'total_transactions' => count($spent) + count($earned) + count($transferred), |                 'total_transactions' => count($spent) + count($earned) + count($transferred), | ||||||
|                              'spent'              => $this->groupByCurrency($spent), |                 'spent'              => $this->groupByCurrency($spent), | ||||||
|                              'earned'             => $this->groupByCurrency($earned), |                 'earned'             => $this->groupByCurrency($earned), | ||||||
|                              'transferred'        => $this->groupByCurrency($transferred), |                 'transferred'        => $this->groupByCurrency($transferred), | ||||||
|                          ]; |             ]; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return $entries; |         return $entries; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user