mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-20 00:20:03 +00:00
Big refactor to remove the deprecated transaction collector.
This commit is contained in:
@@ -24,12 +24,12 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Support\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
@@ -513,7 +513,7 @@ trait AugumentData
|
||||
// group by category ID:
|
||||
$grouped = [];
|
||||
/** @var array $journal */
|
||||
foreach($array as $journal) {
|
||||
foreach ($array as $journal) {
|
||||
$categoryId = (int)$journal['category_id'];
|
||||
$grouped[$categoryId] = $grouped[$categoryId] ?? '0';
|
||||
$grouped[$categoryId] = bcadd($journal['amount'], $grouped[$categoryId]);
|
||||
@@ -544,29 +544,27 @@ trait AugumentData
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* Group transactions by tag.
|
||||
*
|
||||
* @param Collection $set
|
||||
* @param array $array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function groupByTag(Collection $set): array // filter + group data
|
||||
protected function groupByTag(array $array): array // filter + group data
|
||||
{
|
||||
// group by category ID:
|
||||
$grouped = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($set as $transaction) {
|
||||
$journal = $transaction->transactionJournal;
|
||||
$journalTags = $journal->tags;
|
||||
/** @var Tag $journalTag */
|
||||
foreach ($journalTags as $journalTag) {
|
||||
$journalTagId = $journalTag->id;
|
||||
$grouped[$journalTagId] = $grouped[$journalTagId] ?? '0';
|
||||
$grouped[$journalTagId] = bcadd($transaction->transaction_amount, $grouped[$journalTagId]);
|
||||
/** @var array $journal */
|
||||
foreach ($array as $journal) {
|
||||
$tags = $journal['tags'] ?? [];
|
||||
/**
|
||||
* @var int $id
|
||||
* @var array $tag
|
||||
*/
|
||||
foreach ($tags as $id => $tag) {
|
||||
$grouped[$id] = $grouped[$id] ?? '0';
|
||||
$grouped[$id] = bcadd($journal['amount'], $grouped[$id]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -765,17 +763,10 @@ trait AugumentData
|
||||
protected function spentInPeriodWithout(Carbon $start, Carbon $end): string // get data + augment with info
|
||||
{
|
||||
// collector
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$types = [TransactionType::WITHDRAWAL];
|
||||
$collector->setAllAssetAccounts()->setTypes($types)->setRange($start, $end)->withoutBudget();
|
||||
$transactions = $collector->getTransactions();
|
||||
$sum = '0';
|
||||
/** @var Transaction $entry */
|
||||
foreach ($transactions as $entry) {
|
||||
$sum = bcadd($entry->transaction_amount, $sum);
|
||||
}
|
||||
|
||||
return $sum;
|
||||
$collector->setTypes($types)->setRange($start, $end)->withoutBudget();
|
||||
return $collector->getSum();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ trait GetConfigurationData
|
||||
$routeKey = str_replace('.', '_', $route);
|
||||
$elements = config(sprintf('intro.%s', $routeKey));
|
||||
$steps = [];
|
||||
if (\is_array($elements) && \count($elements) > 0) {
|
||||
if (\is_array($elements) && count($elements) > 0) {
|
||||
foreach ($elements as $key => $options) {
|
||||
$currentStep = $options;
|
||||
|
||||
@@ -79,7 +79,7 @@ trait GetConfigurationData
|
||||
$steps[] = $currentStep;
|
||||
}
|
||||
}
|
||||
Log::debug(sprintf('Total basic steps for %s is %d', $routeKey, \count($steps)));
|
||||
Log::debug(sprintf('Total basic steps for %s is %d', $routeKey, count($steps)));
|
||||
|
||||
return $steps;
|
||||
}
|
||||
@@ -188,7 +188,7 @@ trait GetConfigurationData
|
||||
if ('' !== $specificPage) {
|
||||
$routeKey = str_replace('.', '_', $route);
|
||||
$elements = config(sprintf('intro.%s', $routeKey . '_' . $specificPage));
|
||||
if (\is_array($elements) && \count($elements) > 0) {
|
||||
if (\is_array($elements) && count($elements) > 0) {
|
||||
foreach ($elements as $key => $options) {
|
||||
$currentStep = $options;
|
||||
|
||||
@@ -200,7 +200,7 @@ trait GetConfigurationData
|
||||
}
|
||||
}
|
||||
}
|
||||
Log::debug(sprintf('Total specific steps for route "%s" and page "%s" (routeKey is "%s") is %d', $route, $specificPage, $routeKey, \count($steps)));
|
||||
Log::debug(sprintf('Total specific steps for route "%s" and page "%s" (routeKey is "%s") is %d', $route, $specificPage, $routeKey, count($steps)));
|
||||
|
||||
return $steps;
|
||||
}
|
||||
|
||||
@@ -132,6 +132,7 @@ trait PeriodOverview
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
//$cache->store($entries);
|
||||
|
||||
return $entries;
|
||||
@@ -175,7 +176,6 @@ trait PeriodOverview
|
||||
*/
|
||||
protected function getCategoryPeriodOverview(Category $category, Carbon $date): Collection
|
||||
{
|
||||
throw new FireflyException('Is using collector.');
|
||||
/** @var JournalRepositoryInterface $journalRepository */
|
||||
$journalRepository = app(JournalRepositoryInterface::class);
|
||||
$range = app('preferences')->get('viewRange', '1M')->data;
|
||||
@@ -211,12 +211,12 @@ trait PeriodOverview
|
||||
$earned = $this->groupByCurrency($earned);
|
||||
|
||||
// amount transferred
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setRange($currentDate['start'], $currentDate['end'])->setCategory($category)
|
||||
->withOpposingAccount()->setTypes([TransactionType::TRANSFER]);
|
||||
$collector->removeFilter(InternalTransferFilter::class);
|
||||
$transferred = $this->groupByCurrency($collector->getTransactions());
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setRange($currentDate['start'], $currentDate['end'])->setCategory($category)
|
||||
->setTypes([TransactionType::TRANSFER]);
|
||||
$transferred = $this->groupByCurrency($collector->getExtractedJournals());
|
||||
|
||||
$title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);
|
||||
$entries->push(
|
||||
@@ -246,7 +246,6 @@ trait PeriodOverview
|
||||
*/
|
||||
protected function getNoBudgetPeriodOverview(Carbon $date): Collection
|
||||
{
|
||||
throw new FireflyException('Is using collector.');
|
||||
/** @var JournalRepositoryInterface $repository */
|
||||
$repository = app(JournalRepositoryInterface::class);
|
||||
$first = $repository->firstNull();
|
||||
@@ -271,15 +270,15 @@ trait PeriodOverview
|
||||
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
||||
$entries = new Collection;
|
||||
foreach ($dates as $currentDate) {
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setRange($currentDate['start'], $currentDate['end'])->withoutBudget()->withOpposingAccount()->setTypes(
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setRange($currentDate['start'], $currentDate['end'])->withoutBudget()->withAccountInformation()->setTypes(
|
||||
[TransactionType::WITHDRAWAL]
|
||||
);
|
||||
$set = $collector->getTransactions();
|
||||
$count = $set->count();
|
||||
$spent = $this->groupByCurrency($set);
|
||||
$title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$count = count($journals);
|
||||
$spent = $this->groupByCurrency($journals);
|
||||
$title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);
|
||||
$entries->push(
|
||||
[
|
||||
'transactions' => $count,
|
||||
@@ -308,7 +307,6 @@ trait PeriodOverview
|
||||
*/
|
||||
protected function getNoCategoryPeriodOverview(Carbon $theDate): Collection // period overview method.
|
||||
{
|
||||
throw new FireflyException('Is using collector.');
|
||||
Log::debug(sprintf('Now in getNoCategoryPeriodOverview(%s)', $theDate->format('Y-m-d')));
|
||||
$range = app('preferences')->get('viewRange', '1M')->data;
|
||||
$first = $this->journalRepos->firstNull();
|
||||
@@ -334,36 +332,34 @@ trait PeriodOverview
|
||||
foreach ($dates as $date) {
|
||||
|
||||
// count journals without category in this period:
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setRange($date['start'], $date['end'])->withoutCategory()
|
||||
->withOpposingAccount()->setTypes([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER]);
|
||||
$collector->removeFilter(InternalTransferFilter::class);
|
||||
$count = $collector->getTransactions()->count();
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setRange($date['start'], $date['end'])->withoutCategory()
|
||||
->setTypes([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER]);
|
||||
$count = count($collector->getExtractedJournals());
|
||||
|
||||
// amount transferred
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setRange($date['start'], $date['end'])->withoutCategory()
|
||||
->withOpposingAccount()->setTypes([TransactionType::TRANSFER]);
|
||||
$collector->removeFilter(InternalTransferFilter::class);
|
||||
$transferred = app('steam')->positive((string)$collector->getTransactions()->sum('transaction_amount'));
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setRange($date['start'], $date['end'])->withoutCategory()
|
||||
->setTypes([TransactionType::TRANSFER]);
|
||||
$transferred = app('steam')->positive((string)$collector->getSum());
|
||||
|
||||
// amount spent
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setRange($date['start'], $date['end'])->withoutCategory()->withOpposingAccount()->setTypes(
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setRange($date['start'], $date['end'])->withoutCategory()->setTypes(
|
||||
[TransactionType::WITHDRAWAL]
|
||||
);
|
||||
$spent = $collector->getTransactions()->sum('transaction_amount');
|
||||
$spent = $collector->getSum();
|
||||
|
||||
// amount earned
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setRange($date['start'], $date['end'])->withoutCategory()->withOpposingAccount()->setTypes(
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setRange($date['start'], $date['end'])->withoutCategory()->setTypes(
|
||||
[TransactionType::DEPOSIT]
|
||||
);
|
||||
$earned = $collector->getTransactions()->sum('transaction_amount');
|
||||
$earned = $collector->getSum();
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
$dateStr = $date['end']->format('Y-m-d');
|
||||
$dateName = app('navigation')->periodShow($date['end'], $date['period']);
|
||||
@@ -397,7 +393,6 @@ trait PeriodOverview
|
||||
*/
|
||||
protected function getTagPeriodOverview(Tag $tag, Carbon $date): Collection // period overview for tags.
|
||||
{
|
||||
throw new FireflyException('Is using collector.');
|
||||
/** @var TagRepositoryInterface $repository */
|
||||
$repository = app(TagRepositoryInterface::class);
|
||||
$range = app('preferences')->get('viewRange', '1M')->data;
|
||||
@@ -437,7 +432,7 @@ trait PeriodOverview
|
||||
|
||||
$entries->push(
|
||||
[
|
||||
'transactions' => $spentSet->count() + $earnedSet->count() + $transferredSet->count(),
|
||||
'transactions' => count($spentSet) + count($earnedSet) + count($transferredSet),
|
||||
'title' => $title,
|
||||
'spent' => $spent,
|
||||
'earned' => $earned,
|
||||
@@ -457,7 +452,6 @@ trait PeriodOverview
|
||||
* @param Carbon $endDate
|
||||
*
|
||||
* @return Collection
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function getTransactionPeriodOverview(string $transactionType, Carbon $endDate): Collection
|
||||
{
|
||||
|
||||
@@ -350,7 +350,6 @@ trait RenderPartialViews
|
||||
|
||||
/** @var PopupReportInterface $popupHelper */
|
||||
$popupHelper = app(PopupReportInterface::class);
|
||||
|
||||
$account = $accountRepository->findNull((int)$attributes['accountId']);
|
||||
|
||||
if (null === $account) {
|
||||
|
||||
@@ -139,7 +139,7 @@ trait RequestInformation
|
||||
$res = $transformer->transform($transaction);
|
||||
}
|
||||
|
||||
if (\count($res) > 0) {
|
||||
if (count($res) > 0) {
|
||||
$res['amount'] = app('steam')->positive((string)$res['amount']);
|
||||
$res['foreign_amount'] = app('steam')->positive((string)$res['foreign_amount']);
|
||||
$transactions[] = $res;
|
||||
@@ -162,7 +162,7 @@ trait RequestInformation
|
||||
*/
|
||||
protected function updateWithPrevious($array, $old): array // update object with new info
|
||||
{
|
||||
if (0 === \count($old) || !isset($old['transactions'])) {
|
||||
if (0 === count($old) || !isset($old['transactions'])) {
|
||||
return $array;
|
||||
}
|
||||
$old = $old['transactions'];
|
||||
@@ -318,7 +318,7 @@ trait RequestInformation
|
||||
|
||||
$shownDemo = true;
|
||||
// both must be array and either must be > 0
|
||||
if (count($intro) > 0 || \count($specialIntro) > 0) {
|
||||
if (count($intro) > 0 || count($specialIntro) > 0) {
|
||||
$shownDemo = app('preferences')->get($key, false)->data;
|
||||
Log::debug(sprintf('Check if user has already seen intro with key "%s". Result is %d', $key, $shownDemo));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user